copy_to_user.S 1.7 KB

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