clear_user.S 1.2 KB

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