xref: /openbmc/linux/arch/arm64/lib/clear_user.S (revision c8ec3743)
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>
19
20#include <asm/asm-uaccess.h>
21#include <asm/assembler.h>
22
23	.text
24
25/* Prototype: int __arch_clear_user(void *addr, size_t sz)
26 * Purpose  : clear some user memory
27 * Params   : addr - user memory address to clear
28 *          : sz   - number of bytes to clear
29 * Returns  : number of bytes NOT cleared
30 *
31 * Alignment fixed up by hardware.
32 */
33ENTRY(__arch_clear_user)
34	uaccess_enable_not_uao x2, x3, x4
35	mov	x2, x1			// save the size for fixup return
36	subs	x1, x1, #8
37	b.mi	2f
381:
39uao_user_alternative 9f, str, sttr, xzr, x0, 8
40	subs	x1, x1, #8
41	b.pl	1b
422:	adds	x1, x1, #4
43	b.mi	3f
44uao_user_alternative 9f, str, sttr, wzr, x0, 4
45	sub	x1, x1, #4
463:	adds	x1, x1, #2
47	b.mi	4f
48uao_user_alternative 9f, strh, sttrh, wzr, x0, 2
49	sub	x1, x1, #2
504:	adds	x1, x1, #1
51	b.mi	5f
52uao_user_alternative 9f, strb, sttrb, wzr, x0, 0
535:	mov	x0, #0
54	uaccess_disable_not_uao x2, x3
55	ret
56ENDPROC(__arch_clear_user)
57EXPORT_SYMBOL(__arch_clear_user)
58
59	.section .fixup,"ax"
60	.align	2
619:	mov	x0, x2			// return the original size
62	ret
63	.previous
64