copy_from_user.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 from user space to 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_from_user)
  32. ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_HAS_PAN, \
  33. CONFIG_ARM64_PAN)
  34. add x5, x1, x2 // upper user buffer boundary
  35. subs x2, x2, #16
  36. b.mi 1f
  37. 0:
  38. USER(9f, ldp x3, x4, [x1], #16)
  39. subs x2, x2, #16
  40. stp x3, x4, [x0], #16
  41. b.pl 0b
  42. 1: adds x2, x2, #8
  43. b.mi 2f
  44. USER(9f, ldr x3, [x1], #8 )
  45. sub x2, x2, #8
  46. str x3, [x0], #8
  47. 2: adds x2, x2, #4
  48. b.mi 3f
  49. USER(9f, ldr w3, [x1], #4 )
  50. sub x2, x2, #4
  51. str w3, [x0], #4
  52. 3: adds x2, x2, #2
  53. b.mi 4f
  54. USER(9f, ldrh w3, [x1], #2 )
  55. sub x2, x2, #2
  56. strh w3, [x0], #2
  57. 4: adds x2, x2, #1
  58. b.mi 5f
  59. USER(9f, ldrb w3, [x1] )
  60. 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_from_user)
  66. .section .fixup,"ax"
  67. .align 2
  68. 9: sub x2, x5, x1
  69. mov x3, x2
  70. 10: strb wzr, [x0], #1 // zero remaining buffer space
  71. subs x3, x3, #1
  72. b.ne 10b
  73. mov x0, x2 // bytes not copied
  74. ret
  75. .previous