copy_to_user.S 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 to user space from 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_to_user)
  29. add x4, x0, x2 // upper user buffer boundary
  30. subs x2, x2, #8
  31. b.mi 2f
  32. 1:
  33. ldr x3, [x1], #8
  34. subs x2, x2, #8
  35. USER(9f, str x3, [x0], #8 )
  36. b.pl 1b
  37. 2: adds x2, x2, #4
  38. b.mi 3f
  39. ldr w3, [x1], #4
  40. sub x2, x2, #4
  41. USER(9f, str w3, [x0], #4 )
  42. 3: adds x2, x2, #2
  43. b.mi 4f
  44. ldrh w3, [x1], #2
  45. sub x2, x2, #2
  46. USER(9f, strh w3, [x0], #2 )
  47. 4: adds x2, x2, #1
  48. b.mi 5f
  49. ldrb w3, [x1]
  50. USER(9f, strb w3, [x0] )
  51. 5: mov x0, #0
  52. ret
  53. ENDPROC(__copy_to_user)
  54. .section .fixup,"ax"
  55. .align 2
  56. 9: sub x0, x4, x0 // bytes not copied
  57. ret
  58. .previous