xref: /openbmc/linux/arch/arm64/lib/clear_user.S (revision 56c08ec5)
10aea86a2SCatalin Marinas/*
20aea86a2SCatalin Marinas * Based on arch/arm/lib/clear_user.S
30aea86a2SCatalin Marinas *
40aea86a2SCatalin Marinas * Copyright (C) 2012 ARM Ltd.
50aea86a2SCatalin Marinas *
60aea86a2SCatalin Marinas * This program is free software; you can redistribute it and/or modify
70aea86a2SCatalin Marinas * it under the terms of the GNU General Public License version 2 as
80aea86a2SCatalin Marinas * published by the Free Software Foundation.
90aea86a2SCatalin Marinas *
100aea86a2SCatalin Marinas * This program is distributed in the hope that it will be useful,
110aea86a2SCatalin Marinas * but WITHOUT ANY WARRANTY; without even the implied warranty of
120aea86a2SCatalin Marinas * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
130aea86a2SCatalin Marinas * GNU General Public License for more details.
140aea86a2SCatalin Marinas *
150aea86a2SCatalin Marinas * You should have received a copy of the GNU General Public License
160aea86a2SCatalin Marinas * along with this program.  If not, see <http://www.gnu.org/licenses/>.
170aea86a2SCatalin Marinas */
180aea86a2SCatalin Marinas#include <linux/linkage.h>
19338d4f49SJames Morse
20b4b8664dSAl Viro#include <asm/asm-uaccess.h>
2156c08ec5SMark Rutland#include <asm/assembler.h>
220aea86a2SCatalin Marinas
230aea86a2SCatalin Marinas	.text
240aea86a2SCatalin Marinas
25f71c2ffcSWill Deacon/* Prototype: int __arch_clear_user(void *addr, size_t sz)
260aea86a2SCatalin Marinas * Purpose  : clear some user memory
270aea86a2SCatalin Marinas * Params   : addr - user memory address to clear
280aea86a2SCatalin Marinas *          : sz   - number of bytes to clear
290aea86a2SCatalin Marinas * Returns  : number of bytes NOT cleared
300aea86a2SCatalin Marinas *
310aea86a2SCatalin Marinas * Alignment fixed up by hardware.
320aea86a2SCatalin Marinas */
33f71c2ffcSWill DeaconENTRY(__arch_clear_user)
3427a921e7SWill Deacon	uaccess_enable_not_uao x2, x3, x4
350aea86a2SCatalin Marinas	mov	x2, x1			// save the size for fixup return
360aea86a2SCatalin Marinas	subs	x1, x1, #8
370aea86a2SCatalin Marinas	b.mi	2f
380aea86a2SCatalin Marinas1:
3957f4959bSJames Morseuao_user_alternative 9f, str, sttr, xzr, x0, 8
400aea86a2SCatalin Marinas	subs	x1, x1, #8
410aea86a2SCatalin Marinas	b.pl	1b
420aea86a2SCatalin Marinas2:	adds	x1, x1, #4
430aea86a2SCatalin Marinas	b.mi	3f
4457f4959bSJames Morseuao_user_alternative 9f, str, sttr, wzr, x0, 4
450aea86a2SCatalin Marinas	sub	x1, x1, #4
460aea86a2SCatalin Marinas3:	adds	x1, x1, #2
470aea86a2SCatalin Marinas	b.mi	4f
4857f4959bSJames Morseuao_user_alternative 9f, strh, sttrh, wzr, x0, 2
490aea86a2SCatalin Marinas	sub	x1, x1, #2
500aea86a2SCatalin Marinas4:	adds	x1, x1, #1
510aea86a2SCatalin Marinas	b.mi	5f
5257f4959bSJames Morseuao_user_alternative 9f, strb, sttrb, wzr, x0, 0
530aea86a2SCatalin Marinas5:	mov	x0, #0
546b88a32cSCatalin Marinas	uaccess_disable_not_uao x2, x3
550aea86a2SCatalin Marinas	ret
56f71c2ffcSWill DeaconENDPROC(__arch_clear_user)
5756c08ec5SMark RutlandEXPORT_SYMBOL(__arch_clear_user)
580aea86a2SCatalin Marinas
590aea86a2SCatalin Marinas	.section .fixup,"ax"
600aea86a2SCatalin Marinas	.align	2
610aea86a2SCatalin Marinas9:	mov	x0, x2			// return the original size
620aea86a2SCatalin Marinas	ret
630aea86a2SCatalin Marinas	.previous
64