xref: /openbmc/linux/arch/arm64/lib/clear_user.S (revision 344323e0)
1caab277bSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-only */
20aea86a2SCatalin Marinas/*
3*344323e0SRobin Murphy * Copyright (C) 2021 Arm Ltd.
40aea86a2SCatalin Marinas */
5338d4f49SJames Morse
6*344323e0SRobin Murphy#include <linux/linkage.h>
756c08ec5SMark Rutland#include <asm/assembler.h>
80aea86a2SCatalin Marinas
90aea86a2SCatalin Marinas	.text
100aea86a2SCatalin Marinas
11f71c2ffcSWill Deacon/* Prototype: int __arch_clear_user(void *addr, size_t sz)
120aea86a2SCatalin Marinas * Purpose  : clear some user memory
130aea86a2SCatalin Marinas * Params   : addr - user memory address to clear
140aea86a2SCatalin Marinas *          : sz   - number of bytes to clear
150aea86a2SCatalin Marinas * Returns  : number of bytes NOT cleared
160aea86a2SCatalin Marinas *
170aea86a2SCatalin Marinas * Alignment fixed up by hardware.
180aea86a2SCatalin Marinas */
19*344323e0SRobin Murphy
20*344323e0SRobin Murphy	.p2align 4
21*344323e0SRobin Murphy	// Alignment is for the loop, but since the prologue (including BTI)
22*344323e0SRobin Murphy	// is also 16 bytes we can keep any padding outside the function
233ac0f452SMark BrownSYM_FUNC_START(__arch_clear_user)
24*344323e0SRobin Murphy	add	x2, x0, x1
250aea86a2SCatalin Marinas	subs	x1, x1, #8
260aea86a2SCatalin Marinas	b.mi	2f
270aea86a2SCatalin Marinas1:
28*344323e0SRobin MurphyUSER(9f, sttr	xzr, [x0])
29*344323e0SRobin Murphy	add	x0, x0, #8
300aea86a2SCatalin Marinas	subs	x1, x1, #8
31*344323e0SRobin Murphy	b.hi	1b
32*344323e0SRobin MurphyUSER(9f, sttr	xzr, [x2, #-8])
33*344323e0SRobin Murphy	mov	x0, #0
34*344323e0SRobin Murphy	ret
35*344323e0SRobin Murphy
36*344323e0SRobin Murphy2:	tbz	x1, #2, 3f
37*344323e0SRobin MurphyUSER(9f, sttr	wzr, [x0])
38*344323e0SRobin MurphyUSER(8f, sttr	wzr, [x2, #-4])
39*344323e0SRobin Murphy	mov	x0, #0
40*344323e0SRobin Murphy	ret
41*344323e0SRobin Murphy
42*344323e0SRobin Murphy3:	tbz	x1, #1, 4f
43*344323e0SRobin MurphyUSER(9f, sttrh	wzr, [x0])
44*344323e0SRobin Murphy4:	tbz	x1, #0, 5f
45*344323e0SRobin MurphyUSER(7f, sttrb	wzr, [x2, #-1])
460aea86a2SCatalin Marinas5:	mov	x0, #0
470aea86a2SCatalin Marinas	ret
483ac0f452SMark BrownSYM_FUNC_END(__arch_clear_user)
4956c08ec5SMark RutlandEXPORT_SYMBOL(__arch_clear_user)
500aea86a2SCatalin Marinas
510aea86a2SCatalin Marinas	.section .fixup,"ax"
520aea86a2SCatalin Marinas	.align	2
53*344323e0SRobin Murphy7:	sub	x0, x2, #5	// Adjust for faulting on the final byte...
54*344323e0SRobin Murphy8:	add	x0, x0, #4	// ...or the second word of the 4-7 byte case
55*344323e0SRobin Murphy9:	sub	x0, x2, x0
560aea86a2SCatalin Marinas	ret
570aea86a2SCatalin Marinas	.previous
58