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