copy_from_user.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/assembler.h>
  18. /*
  19. * Copy from user space to a kernel buffer (alignment handled by the hardware)
  20. *
  21. * Parameters:
  22. * x0 - to
  23. * x1 - from
  24. * x2 - n
  25. * Returns:
  26. * x0 - bytes not copied
  27. */
  28. ENTRY(__copy_from_user)
  29. add x4, x1, x2 // upper user buffer boundary
  30. subs x2, x2, #8
  31. b.mi 2f
  32. 1:
  33. USER(9f, ldr x3, [x1], #8 )
  34. subs x2, x2, #8
  35. str x3, [x0], #8
  36. b.pl 1b
  37. 2: adds x2, x2, #4
  38. b.mi 3f
  39. USER(9f, ldr w3, [x1], #4 )
  40. sub x2, x2, #4
  41. str w3, [x0], #4
  42. 3: adds x2, x2, #2
  43. b.mi 4f
  44. USER(9f, ldrh w3, [x1], #2 )
  45. sub x2, x2, #2
  46. strh w3, [x0], #2
  47. 4: adds x2, x2, #1
  48. b.mi 5f
  49. USER(9f, ldrb w3, [x1] )
  50. strb w3, [x0]
  51. 5: mov x0, #0
  52. ret
  53. ENDPROC(__copy_from_user)
  54. .section .fixup,"ax"
  55. .align 2
  56. 9: sub x2, x4, x1
  57. mov x3, x2
  58. 10: strb wzr, [x0], #1 // zero remaining buffer space
  59. subs x3, x3, #1
  60. b.ne 10b
  61. mov x0, x2 // bytes not copied
  62. ret
  63. .previous