copy_template.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * linux/arch/unicore32/lib/copy_template.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. /*
  13. * Theory of operation
  14. * -------------------
  15. *
  16. * This file provides the core code for a forward memory copy used in
  17. * the implementation of memcopy(), copy_to_user() and copy_from_user().
  18. *
  19. * The including file must define the following accessor macros
  20. * according to the need of the given function:
  21. *
  22. * ldr1w ptr reg abort
  23. *
  24. * This loads one word from 'ptr', stores it in 'reg' and increments
  25. * 'ptr' to the next word. The 'abort' argument is used for fixup tables.
  26. *
  27. * ldr4w ptr reg1 reg2 reg3 reg4 abort
  28. * ldr8w ptr, reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  29. *
  30. * This loads four or eight words starting from 'ptr', stores them
  31. * in provided registers and increments 'ptr' past those words.
  32. * The'abort' argument is used for fixup tables.
  33. *
  34. * ldr1b ptr reg cond abort
  35. *
  36. * Similar to ldr1w, but it loads a byte and increments 'ptr' one byte.
  37. * It also must apply the condition code if provided, otherwise the
  38. * "al" condition is assumed by default.
  39. *
  40. * str1w ptr reg abort
  41. * str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  42. * str1b ptr reg cond abort
  43. *
  44. * Same as their ldr* counterparts, but data is stored to 'ptr' location
  45. * rather than being loaded.
  46. *
  47. * enter
  48. *
  49. * Preserve the provided registers on the stack plus any additional
  50. * data as needed by the implementation including this code. Called
  51. * upon code entry.
  52. *
  53. * exit
  54. *
  55. * Restore registers with the values previously saved with the
  56. * 'preserv' macro. Called upon code termination.
  57. */
  58. enter
  59. sub.a r2, r2, #4
  60. bsl 8f
  61. and.a ip, r0, #3
  62. bne 9f
  63. and.a ip, r1, #3
  64. bne 10f
  65. 1: sub.a r2, r2, #(28)
  66. stm.w (r5 - r8), [sp-]
  67. bsl 5f
  68. 3:
  69. 4: ldr8w r1, r3, r4, r5, r6, r7, r8, r10, r11, abort=20f
  70. sub.a r2, r2, #32
  71. str8w r0, r3, r4, r5, r6, r7, r8, r10, r11, abort=20f
  72. beg 3b
  73. 5: and.a ip, r2, #28
  74. rsub ip, ip, #32
  75. beq 7f
  76. add pc, pc, ip @ C is always clear here
  77. nop
  78. ldr1w r1, r3, abort=20f
  79. ldr1w r1, r4, abort=20f
  80. ldr1w r1, r5, abort=20f
  81. ldr1w r1, r6, abort=20f
  82. ldr1w r1, r7, abort=20f
  83. ldr1w r1, r8, abort=20f
  84. ldr1w r1, r11, abort=20f
  85. add pc, pc, ip
  86. nop
  87. str1w r0, r3, abort=20f
  88. str1w r0, r4, abort=20f
  89. str1w r0, r5, abort=20f
  90. str1w r0, r6, abort=20f
  91. str1w r0, r7, abort=20f
  92. str1w r0, r8, abort=20f
  93. str1w r0, r11, abort=20f
  94. 7: ldm.w (r5 - r8), [sp]+
  95. 8: mov.a r2, r2 << #31
  96. ldr1b r1, r3, ne, abort=21f
  97. ldr1b r1, r4, ea, abort=21f
  98. ldr1b r1, r10, ea, abort=21f
  99. str1b r0, r3, ne, abort=21f
  100. str1b r0, r4, ea, abort=21f
  101. str1b r0, r10, ea, abort=21f
  102. exit
  103. 9: rsub ip, ip, #4
  104. csub.a ip, #2
  105. ldr1b r1, r3, sg, abort=21f
  106. ldr1b r1, r4, eg, abort=21f
  107. ldr1b r1, r11, abort=21f
  108. str1b r0, r3, sg, abort=21f
  109. str1b r0, r4, eg, abort=21f
  110. sub.a r2, r2, ip
  111. str1b r0, r11, abort=21f
  112. bsl 8b
  113. and.a ip, r1, #3
  114. beq 1b
  115. 10: andn r1, r1, #3
  116. csub.a ip, #2
  117. ldr1w r1, r11, abort=21f
  118. beq 17f
  119. bsg 18f
  120. .macro forward_copy_shift a b
  121. sub.a r2, r2, #28
  122. bsl 14f
  123. 11: stm.w (r5 - r9), [sp-]
  124. 12:
  125. ldr4w r1, r4, r5, r6, r7, abort=19f
  126. mov r3, r11 pull #\a
  127. sub.a r2, r2, #32
  128. ldr4w r1, r8, r9, r10, r11, abort=19f
  129. or r3, r3, r4 push #\b
  130. mov r4, r4 pull #\a
  131. or r4, r4, r5 push #\b
  132. mov r5, r5 pull #\a
  133. or r5, r5, r6 push #\b
  134. mov r6, r6 pull #\a
  135. or r6, r6, r7 push #\b
  136. mov r7, r7 pull #\a
  137. or r7, r7, r8 push #\b
  138. mov r8, r8 pull #\a
  139. or r8, r8, r9 push #\b
  140. mov r9, r9 pull #\a
  141. or r9, r9, r10 push #\b
  142. mov r10, r10 pull #\a
  143. or r10, r10, r11 push #\b
  144. str8w r0, r3, r4, r5, r6, r7, r8, r9, r10, , abort=19f
  145. beg 12b
  146. ldm.w (r5 - r9), [sp]+
  147. 14: and.a ip, r2, #28
  148. beq 16f
  149. 15: mov r3, r11 pull #\a
  150. ldr1w r1, r11, abort=21f
  151. sub.a ip, ip, #4
  152. or r3, r3, r11 push #\b
  153. str1w r0, r3, abort=21f
  154. bsg 15b
  155. 16: sub r1, r1, #(\b / 8)
  156. b 8b
  157. .endm
  158. forward_copy_shift a=8 b=24
  159. 17: forward_copy_shift a=16 b=16
  160. 18: forward_copy_shift a=24 b=8
  161. /*
  162. * Abort preamble and completion macros.
  163. * If a fixup handler is required then those macros must surround it.
  164. * It is assumed that the fixup code will handle the private part of
  165. * the exit macro.
  166. */
  167. .macro copy_abort_preamble
  168. 19: ldm.w (r5 - r9), [sp]+
  169. b 21f
  170. 299: .word 0 @ store lr
  171. @ to avoid function call in fixup
  172. 20: ldm.w (r5 - r8), [sp]+
  173. 21:
  174. adr r1, 299b
  175. stw lr, [r1]
  176. .endm
  177. .macro copy_abort_end
  178. adr lr, 299b
  179. ldw pc, [lr]
  180. .endm