copy_in_user.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copy from user space to user space
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/linkage.h>
  19. #include <asm/alternative.h>
  20. #include <asm/assembler.h>
  21. #include <asm/cpufeature.h>
  22. #include <asm/sysreg.h>
  23. /*
  24. * Copy from user space to user space (alignment handled by the hardware)
  25. *
  26. * Parameters:
  27. * x0 - to
  28. * x1 - from
  29. * x2 - n
  30. * Returns:
  31. * x0 - bytes not copied
  32. */
  33. ENTRY(__copy_in_user)
  34. ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \
  35. CONFIG_ARM64_PAN)
  36. add x5, x0, x2 // upper user buffer boundary
  37. subs x2, x2, #16
  38. b.mi 1f
  39. 0:
  40. USER(9f, ldp x3, x4, [x1], #16)
  41. subs x2, x2, #16
  42. USER(9f, stp x3, x4, [x0], #16)
  43. b.pl 0b
  44. 1: adds x2, x2, #8
  45. b.mi 2f
  46. USER(9f, ldr x3, [x1], #8 )
  47. sub x2, x2, #8
  48. USER(9f, str x3, [x0], #8 )
  49. 2: adds x2, x2, #4
  50. b.mi 3f
  51. USER(9f, ldr w3, [x1], #4 )
  52. sub x2, x2, #4
  53. USER(9f, str w3, [x0], #4 )
  54. 3: adds x2, x2, #2
  55. b.mi 4f
  56. USER(9f, ldrh w3, [x1], #2 )
  57. sub x2, x2, #2
  58. USER(9f, strh w3, [x0], #2 )
  59. 4: adds x2, x2, #1
  60. b.mi 5f
  61. USER(9f, ldrb w3, [x1] )
  62. USER(9f, strb w3, [x0] )
  63. 5: mov x0, #0
  64. ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_HAS_PAN, \
  65. CONFIG_ARM64_PAN)
  66. ret
  67. ENDPROC(__copy_in_user)
  68. .section .fixup,"ax"
  69. .align 2
  70. 9: sub x0, x5, x0 // bytes not copied
  71. ret
  72. .previous