xref: /OK3568_Linux_fs/kernel/arch/nds32/lib/clear_user.S (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun// SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun// Copyright (C) 2005-2017 Andes Technology Corporation
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun#include <linux/linkage.h>
5*4882a593Smuzhiyun#include <asm/assembler.h>
6*4882a593Smuzhiyun#include <asm/errno.h>
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun/* Prototype: int __arch_clear_user(void *addr, size_t sz)
9*4882a593Smuzhiyun * Purpose  : clear some user memory
10*4882a593Smuzhiyun * Params   : addr - user memory address to clear
11*4882a593Smuzhiyun *          : sz   - number of bytes to clear
12*4882a593Smuzhiyun * Returns  : number of bytes NOT cleared
13*4882a593Smuzhiyun */
14*4882a593Smuzhiyun	.text
15*4882a593Smuzhiyun	.align	5
16*4882a593SmuzhiyunENTRY(__arch_clear_user)
17*4882a593Smuzhiyun	add	$r5, $r0, $r1
18*4882a593Smuzhiyun	beqz	$r1, clear_exit
19*4882a593Smuzhiyun	xor	$p1, $p1, $p1		! Use $p1=0 to clear mem
20*4882a593Smuzhiyun	srli	$p0, $r1, #2		! $p0 = number of word to clear
21*4882a593Smuzhiyun	andi	$r1, $r1, #3		! Bytes less than a word to copy
22*4882a593Smuzhiyun	beqz	$p0, byte_clear		! Only less than a word to clear
23*4882a593Smuzhiyunword_clear:
24*4882a593SmuzhiyunUSER(	smw.bim,$p1, [$r0], $p1)	! Clear the word
25*4882a593Smuzhiyun	addi	$p0, $p0, #-1		! Decrease word count
26*4882a593Smuzhiyun	bnez	$p0, word_clear		! Continue looping to clear all words
27*4882a593Smuzhiyun	beqz	$r1, clear_exit		! No left bytes to copy
28*4882a593Smuzhiyunbyte_clear:
29*4882a593SmuzhiyunUSER(	sbi.bi,	$p1, [$r0], #1)		! Clear the byte
30*4882a593Smuzhiyun	addi	$r1, $r1, #-1		! Decrease byte count
31*4882a593Smuzhiyun	bnez	$r1, byte_clear		! Continue looping to clear all left bytes
32*4882a593Smuzhiyunclear_exit:
33*4882a593Smuzhiyun	move	$r0, $r1		! Set return value
34*4882a593Smuzhiyun	ret
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun	.section .fixup,"ax"
37*4882a593Smuzhiyun	.align	0
38*4882a593Smuzhiyun9001:
39*4882a593Smuzhiyun	sub	$r0, $r5, $r0		! Bytes left to copy
40*4882a593Smuzhiyun	ret
41*4882a593Smuzhiyun	.previous
42*4882a593SmuzhiyunENDPROC(__arch_clear_user)
43