Commit | Line | Data |
---|---|---|
0aea86a2 CM |
1 | /* |
2 | * Based on arch/arm/lib/clear_user.S | |
3 | * | |
4 | * Copyright (C) 2012 ARM Ltd. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | #include <linux/linkage.h> | |
338d4f49 JM |
19 | |
20 | #include <asm/alternative.h> | |
0aea86a2 | 21 | #include <asm/assembler.h> |
338d4f49 JM |
22 | #include <asm/cpufeature.h> |
23 | #include <asm/sysreg.h> | |
0aea86a2 CM |
24 | |
25 | .text | |
26 | ||
27 | /* Prototype: int __clear_user(void *addr, size_t sz) | |
28 | * Purpose : clear some user memory | |
29 | * Params : addr - user memory address to clear | |
30 | * : sz - number of bytes to clear | |
31 | * Returns : number of bytes NOT cleared | |
32 | * | |
33 | * Alignment fixed up by hardware. | |
34 | */ | |
35 | ENTRY(__clear_user) | |
338d4f49 JM |
36 | ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \ |
37 | CONFIG_ARM64_PAN) | |
0aea86a2 CM |
38 | mov x2, x1 // save the size for fixup return |
39 | subs x1, x1, #8 | |
40 | b.mi 2f | |
41 | 1: | |
42 | USER(9f, str xzr, [x0], #8 ) | |
43 | subs x1, x1, #8 | |
44 | b.pl 1b | |
45 | 2: adds x1, x1, #4 | |
46 | b.mi 3f | |
47 | USER(9f, str wzr, [x0], #4 ) | |
48 | sub x1, x1, #4 | |
49 | 3: adds x1, x1, #2 | |
50 | b.mi 4f | |
51 | USER(9f, strh wzr, [x0], #2 ) | |
52 | sub x1, x1, #2 | |
53 | 4: adds x1, x1, #1 | |
54 | b.mi 5f | |
97fc1543 | 55 | USER(9f, strb wzr, [x0] ) |
0aea86a2 | 56 | 5: mov x0, #0 |
338d4f49 JM |
57 | ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_HAS_PAN, \ |
58 | CONFIG_ARM64_PAN) | |
0aea86a2 CM |
59 | ret |
60 | ENDPROC(__clear_user) | |
61 | ||
62 | .section .fixup,"ax" | |
63 | .align 2 | |
64 | 9: mov x0, x2 // return the original size | |
65 | ret | |
66 | .previous |