blob: 4fd67ea03bb054d44e579426def0051429579920 [file] [log] [blame]
Catalin Marinas0aea86a2012-03-05 11:49:32 +00001/*
2 * Copyright (C) 2012 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/linkage.h>
James Morse338d4f42015-07-22 19:05:54 +010018
19#include <asm/alternative.h>
Catalin Marinas0aea86a2012-03-05 11:49:32 +000020#include <asm/assembler.h>
Feng Kan40426882015-09-23 11:55:39 -070021#include <asm/cache.h>
James Morse338d4f42015-07-22 19:05:54 +010022#include <asm/cpufeature.h>
23#include <asm/sysreg.h>
Catalin Marinas0aea86a2012-03-05 11:49:32 +000024
25/*
26 * Copy from user space to a kernel buffer (alignment handled by the hardware)
27 *
28 * Parameters:
29 * x0 - to
30 * x1 - from
31 * x2 - n
32 * Returns:
33 * x0 - bytes not copied
34 */
Feng Kan40426882015-09-23 11:55:39 -070035
36 .macro ldrb1 ptr, regB, val
James Morse57f49592016-02-05 14:58:48 +000037 uao_user_alternative 9998f, ldrb, ldtrb, \ptr, \regB, \val
Feng Kan40426882015-09-23 11:55:39 -070038 .endm
39
40 .macro strb1 ptr, regB, val
41 strb \ptr, [\regB], \val
42 .endm
43
44 .macro ldrh1 ptr, regB, val
James Morse57f49592016-02-05 14:58:48 +000045 uao_user_alternative 9998f, ldrh, ldtrh, \ptr, \regB, \val
Feng Kan40426882015-09-23 11:55:39 -070046 .endm
47
48 .macro strh1 ptr, regB, val
49 strh \ptr, [\regB], \val
50 .endm
51
52 .macro ldr1 ptr, regB, val
James Morse57f49592016-02-05 14:58:48 +000053 uao_user_alternative 9998f, ldr, ldtr, \ptr, \regB, \val
Feng Kan40426882015-09-23 11:55:39 -070054 .endm
55
56 .macro str1 ptr, regB, val
57 str \ptr, [\regB], \val
58 .endm
59
60 .macro ldp1 ptr, regB, regC, val
James Morse57f49592016-02-05 14:58:48 +000061 uao_ldp 9998f, \ptr, \regB, \regC, \val
Feng Kan40426882015-09-23 11:55:39 -070062 .endm
63
64 .macro stp1 ptr, regB, regC, val
65 stp \ptr, \regB, [\regC], \val
66 .endm
67
68end .req x5
Yang Shibffe1baff2016-06-08 14:40:56 -070069ENTRY(__arch_copy_from_user)
James Morse70544192016-02-05 14:58:50 +000070ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_ALT_PAN_NOT_UAO, \
James Morse338d4f42015-07-22 19:05:54 +010071 CONFIG_ARM64_PAN)
Feng Kan40426882015-09-23 11:55:39 -070072 add end, x0, x2
73#include "copy_template.S"
James Morse70544192016-02-05 14:58:50 +000074ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_ALT_PAN_NOT_UAO, \
James Morse338d4f42015-07-22 19:05:54 +010075 CONFIG_ARM64_PAN)
Feng Kan40426882015-09-23 11:55:39 -070076 mov x0, #0 // Nothing to copy
Catalin Marinas0aea86a2012-03-05 11:49:32 +000077 ret
Yang Shibffe1baff2016-06-08 14:40:56 -070078ENDPROC(__arch_copy_from_user)
Catalin Marinas0aea86a2012-03-05 11:49:32 +000079
80 .section .fixup,"ax"
81 .align 2
Al Viro4855bd22016-09-10 16:50:00 -0400829998: sub x0, end, dst // bytes not copied
Catalin Marinas0aea86a2012-03-05 11:49:32 +000083 ret
84 .previous