copy_from_user.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. /*
  15. * Prototype:
  16. *
  17. * size_t __copy_from_user(void *to, const void *from, size_t n)
  18. *
  19. * Purpose:
  20. *
  21. * copy a block to kernel memory from user memory
  22. *
  23. * Params:
  24. *
  25. * to = kernel memory
  26. * from = user memory
  27. * n = number of bytes to copy
  28. *
  29. * Return value:
  30. *
  31. * Number of bytes NOT copied.
  32. */
  33. #ifndef CONFIG_THUMB2_KERNEL
  34. #define LDR1W_SHIFT 0
  35. #else
  36. #define LDR1W_SHIFT 1
  37. #endif
  38. #define STR1W_SHIFT 0
  39. .macro ldr1w ptr reg abort
  40. ldrusr \reg, \ptr, 4, abort=\abort
  41. .endm
  42. .macro ldr4w ptr reg1 reg2 reg3 reg4 abort
  43. ldr1w \ptr, \reg1, \abort
  44. ldr1w \ptr, \reg2, \abort
  45. ldr1w \ptr, \reg3, \abort
  46. ldr1w \ptr, \reg4, \abort
  47. .endm
  48. .macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  49. ldr4w \ptr, \reg1, \reg2, \reg3, \reg4, \abort
  50. ldr4w \ptr, \reg5, \reg6, \reg7, \reg8, \abort
  51. .endm
  52. .macro ldr1b ptr reg cond=al abort
  53. ldrusr \reg, \ptr, 1, \cond, abort=\abort
  54. .endm
  55. .macro str1w ptr reg abort
  56. W(str) \reg, [\ptr], #4
  57. .endm
  58. .macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  59. stmia \ptr!, {\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8}
  60. .endm
  61. .macro str1b ptr reg cond=al abort
  62. str\cond\()b \reg, [\ptr], #1
  63. .endm
  64. .macro enter reg1 reg2
  65. mov r3, #0
  66. stmdb sp!, {r0, r2, r3, \reg1, \reg2}
  67. .endm
  68. .macro exit reg1 reg2
  69. add sp, sp, #8
  70. ldmfd sp!, {r0, \reg1, \reg2}
  71. .endm
  72. .text
  73. ENTRY(__copy_from_user)
  74. #include "copy_template.S"
  75. ENDPROC(__copy_from_user)
  76. .pushsection .fixup,"ax"
  77. .align 0
  78. copy_abort_preamble
  79. ldmfd sp!, {r1, r2}
  80. sub r3, r0, r1
  81. rsb r1, r3, r2
  82. str r1, [sp]
  83. bl __memzero
  84. ldr r0, [sp], #4
  85. copy_abort_end
  86. .popsection