blob: 5d1cad3ce6d601aa474ae9c9b8ef4c76a785912e [file] [log] [blame]
Catalin Marinas0aea86a2012-03-05 11:49:32 +00001/*
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>
James Morse338d4f42015-07-22 19:05:54 +010019
20#include <asm/alternative.h>
Catalin Marinas0aea86a2012-03-05 11:49:32 +000021#include <asm/assembler.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 .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 */
35ENTRY(__clear_user)
James Morse70544192016-02-05 14:58:50 +000036ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_ALT_PAN_NOT_UAO, \
James Morse338d4f42015-07-22 19:05:54 +010037 CONFIG_ARM64_PAN)
Catalin Marinas0aea86a2012-03-05 11:49:32 +000038 mov x2, x1 // save the size for fixup return
39 subs x1, x1, #8
40 b.mi 2f
411:
James Morse57f49592016-02-05 14:58:48 +000042uao_user_alternative 9f, str, sttr, xzr, x0, 8
Catalin Marinas0aea86a2012-03-05 11:49:32 +000043 subs x1, x1, #8
44 b.pl 1b
452: adds x1, x1, #4
46 b.mi 3f
James Morse57f49592016-02-05 14:58:48 +000047uao_user_alternative 9f, str, sttr, wzr, x0, 4
Catalin Marinas0aea86a2012-03-05 11:49:32 +000048 sub x1, x1, #4
493: adds x1, x1, #2
50 b.mi 4f
James Morse57f49592016-02-05 14:58:48 +000051uao_user_alternative 9f, strh, sttrh, wzr, x0, 2
Catalin Marinas0aea86a2012-03-05 11:49:32 +000052 sub x1, x1, #2
534: adds x1, x1, #1
54 b.mi 5f
James Morse57f49592016-02-05 14:58:48 +000055uao_user_alternative 9f, strb, sttrb, wzr, x0, 0
Catalin Marinas0aea86a2012-03-05 11:49:32 +0000565: mov x0, #0
James Morse70544192016-02-05 14:58:50 +000057ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_ALT_PAN_NOT_UAO, \
James Morse338d4f42015-07-22 19:05:54 +010058 CONFIG_ARM64_PAN)
Catalin Marinas0aea86a2012-03-05 11:49:32 +000059 ret
60ENDPROC(__clear_user)
61
62 .section .fixup,"ax"
63 .align 2
649: mov x0, x2 // return the original size
65 ret
66 .previous