clear_user.S 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2021 Arm Ltd.
  4. */
  5. #include <linux/linkage.h>
  6. #include <asm/asm-uaccess.h>
  7. .text
  8. /* Prototype: int __arch_clear_user(void *addr, size_t sz)
  9. * Purpose : clear some user memory
  10. * Params : addr - user memory address to clear
  11. * : sz - number of bytes to clear
  12. * Returns : number of bytes NOT cleared
  13. *
  14. * Alignment fixed up by hardware.
  15. */
  16. SYM_FUNC_START(__arch_clear_user)
  17. add x2, x0, x1
  18. #ifdef CONFIG_AS_HAS_MOPS
  19. .arch_extension mops
  20. alternative_if_not ARM64_HAS_MOPS
  21. b .Lno_mops
  22. alternative_else_nop_endif
  23. USER(9f, setpt [x0]!, x1!, xzr)
  24. USER(6f, setmt [x0]!, x1!, xzr)
  25. USER(6f, setet [x0]!, x1!, xzr)
  26. mov x0, #0
  27. ret
  28. .Lno_mops:
  29. #endif
  30. subs x1, x1, #8
  31. b.mi 2f
  32. 1: .p2align 4
  33. USER(9f, sttr xzr, [x0])
  34. add x0, x0, #8
  35. subs x1, x1, #8
  36. b.hi 1b
  37. USER(9f, sttr xzr, [x2, #-8])
  38. mov x0, #0
  39. ret
  40. 2: tbz x1, #2, 3f
  41. USER(9f, sttr wzr, [x0])
  42. USER(8f, sttr wzr, [x2, #-4])
  43. mov x0, #0
  44. ret
  45. 3: tbz x1, #1, 4f
  46. USER(9f, sttrh wzr, [x0])
  47. 4: tbz x1, #0, 5f
  48. USER(7f, sttrb wzr, [x2, #-1])
  49. 5: mov x0, #0
  50. ret
  51. // Exception fixups
  52. 6: b.cs 9f
  53. // Registers are in Option A format
  54. add x0, x0, x1
  55. b 9f
  56. 7: sub x0, x2, #5 // Adjust for faulting on the final byte...
  57. 8: add x0, x0, #4 // ...or the second word of the 4-7 byte case
  58. 9: sub x0, x2, x0
  59. ret
  60. SYM_FUNC_END(__arch_clear_user)
  61. EXPORT_SYMBOL(__arch_clear_user)