copy_from_user.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * linux/arch/unicore32/lib/copy_from_user.S
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  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. .macro ldr1w ptr reg abort
  34. ldrusr \reg, \ptr, 4, abort=\abort
  35. .endm
  36. .macro ldr4w ptr reg1 reg2 reg3 reg4 abort
  37. 100: ldm.w (\reg1, \reg2, \reg3, \reg4), [\ptr]+
  38. .pushsection __ex_table, "a"
  39. .align 3
  40. .long 100b, \abort
  41. .popsection
  42. .endm
  43. .macro ldr8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  44. 100: ldm.w (\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8), [\ptr]+
  45. .pushsection __ex_table, "a"
  46. .align 3
  47. .long 100b, \abort
  48. .popsection
  49. .endm
  50. .macro ldr1b ptr reg cond=al abort
  51. ldrusr \reg, \ptr, 1, \cond, abort=\abort
  52. .endm
  53. .macro str1w ptr reg abort
  54. stw.w \reg, [\ptr]+, #4
  55. .endm
  56. .macro str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  57. stm.w (\reg1, \reg2, \reg3, \reg4, \reg5, \reg6, \reg7, \reg8), [\ptr]+
  58. .endm
  59. .macro str1b ptr reg cond=al abort
  60. .ifnc \cond, al
  61. b\cond 201f
  62. b 202f
  63. .endif
  64. 201: stb.w \reg, [\ptr]+, #1
  65. 202:
  66. .endm
  67. .macro enter
  68. mov r3, #0
  69. stm.w (r0, r2, r3), [sp-]
  70. .endm
  71. .macro exit
  72. add sp, sp, #8
  73. ldm.w (r0), [sp]+
  74. mov pc, lr
  75. .endm
  76. .text
  77. ENTRY(__copy_from_user)
  78. #include "copy_template.S"
  79. ENDPROC(__copy_from_user)
  80. .pushsection .fixup,"ax"
  81. .align 0
  82. copy_abort_preamble
  83. ldm.w (r1, r2), [sp]+
  84. sub r3, r0, r1
  85. rsub r2, r3, r2
  86. stw r2, [sp]
  87. mov r1, #0
  88. b.l memset
  89. ldw.w r0, [sp]+, #4
  90. copy_abort_end
  91. .popsection