copy_from_user.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * linux/arch/arm/lib/copy_from_user.S
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: Sep 29, 2005
  6. * Copyright: MontaVista Software, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/linkage.h>
  13. #include <asm/assembler.h>
  14. #include <asm/unwind.h>
  15. /*
  16. * Prototype:
  17. *
  18. * size_t arm_copy_from_user(void *to, const void *from, size_t n)
  19. *
  20. * Purpose:
  21. *
  22. * copy a block to kernel memory from user memory
  23. *
  24. * Params:
  25. *
  26. * to = kernel memory
  27. * from = user memory
  28. * n = number of bytes to copy
  29. *
  30. * Return value:
  31. *
  32. * Number of bytes NOT copied.
  33. */
  34. #ifndef CONFIG_THUMB2_KERNEL
  35. #define LDR1W_SHIFT 0
  36. #else
  37. #define LDR1W_SHIFT 1
  38. #endif
  39. #define STR1W_SHIFT 0
  40. .macro ldr1w ptr reg abort
  41. ldrusr \reg, \ptr, 4, abort=\abort
  42. .endm
  43. .macro ldr4w ptr reg1 reg2 reg3 reg4 abort
  44. ldr1w \ptr, \reg1, \abort
  45. ldr1w \ptr, \reg2, \abort
  46. ldr1w \ptr, \reg3, \abort
  47. ldr1w \ptr, \reg4, \abort
  48. .endm
  49. .macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  50. ldr4w \ptr, \reg1, \reg2, \reg3, \reg4, \abort
  51. ldr4w \ptr, \reg5, \reg6, \reg7, \reg8, \abort
  52. .endm
  53. .macro ldr1b ptr reg cond=al abort
  54. ldrusr \reg, \ptr, 1, \cond, abort=\abort
  55. .endm
  56. .macro str1w ptr reg abort
  57. W(str) \reg, [\ptr], #4
  58. .endm
  59. .macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  60. stmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
  61. .endm
  62. .macro str1b ptr reg cond=al abort
  63. str\cond\()b \reg, [\ptr], #1
  64. .endm
  65. .macro enter reg1 reg2
  66. mov r3, #0
  67. stmdb sp!, {r0, r2, r3, \reg1, \reg2}
  68. .endm
  69. .macro usave reg1 reg2
  70. UNWIND( .save {r0, r2, r3, \reg1, \reg2} )
  71. .endm
  72. .macro exit reg1 reg2
  73. add sp, sp, #8
  74. ldmfd sp!, {r0, \reg1, \reg2}
  75. .endm
  76. .text
  77. ENTRY(arm_copy_from_user)
  78. #include "copy_template.S"
  79. ENDPROC(arm_copy_from_user)
  80. .pushsection .fixup,"ax"
  81. .align 0
  82. copy_abort_preamble
  83. ldmfd sp!, {r1, r2, r3}
  84. sub r0, r0, r1
  85. rsb r0, r0, r2
  86. copy_abort_end
  87. .popsection