copy_template.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * linux/arch/arm/lib/copy_template.s
  3. *
  4. * Code template for optimized memory copy functions
  5. *
  6. * Author: Nicolas Pitre
  7. * Created: Sep 28, 2005
  8. * Copyright: MontaVista Software, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. /*
  15. * Theory of operation
  16. * -------------------
  17. *
  18. * This file provides the core code for a forward memory copy used in
  19. * the implementation of memcopy(), copy_to_user() and copy_from_user().
  20. *
  21. * The including file must define the following accessor macros
  22. * according to the need of the given function:
  23. *
  24. * ldr1w ptr reg abort
  25. *
  26. * This loads one word from 'ptr', stores it in 'reg' and increments
  27. * 'ptr' to the next word. The 'abort' argument is used for fixup tables.
  28. *
  29. * ldr4w ptr reg1 reg2 reg3 reg4 abort
  30. * ldr8w ptr, reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  31. *
  32. * This loads four or eight words starting from 'ptr', stores them
  33. * in provided registers and increments 'ptr' past those words.
  34. * The'abort' argument is used for fixup tables.
  35. *
  36. * ldr1b ptr reg cond abort
  37. *
  38. * Similar to ldr1w, but it loads a byte and increments 'ptr' one byte.
  39. * It also must apply the condition code if provided, otherwise the
  40. * "al" condition is assumed by default.
  41. *
  42. * str1w ptr reg abort
  43. * str8w ptr reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 abort
  44. * str1b ptr reg cond abort
  45. *
  46. * Same as their ldr* counterparts, but data is stored to 'ptr' location
  47. * rather than being loaded.
  48. *
  49. * enter reg1 reg2
  50. *
  51. * Preserve the provided registers on the stack plus any additional
  52. * data as needed by the implementation including this code. Called
  53. * upon code entry.
  54. *
  55. * exit reg1 reg2
  56. *
  57. * Restore registers with the values previously saved with the
  58. * 'preserv' macro. Called upon code termination.
  59. */
  60. enter r4, lr
  61. subs r2, r2, #4
  62. blt 8f
  63. ands ip, r0, #3
  64. PLD( pld [r1, #0] )
  65. bne 9f
  66. ands ip, r1, #3
  67. bne 10f
  68. 1: subs r2, r2, #(28)
  69. stmfd sp!, {r5 - r8}
  70. blt 5f
  71. CALGN( ands ip, r0, #31 )
  72. CALGN( rsb r3, ip, #32 )
  73. CALGN( sbcnes r4, r3, r2 ) @ C is always set here
  74. CALGN( bcs 2f )
  75. CALGN( adr r4, 6f )
  76. CALGN( subs r2, r2, r3 ) @ C gets set
  77. CALGN( add pc, r4, ip )
  78. PLD( pld [r1, #0] )
  79. 2: PLD( subs r2, r2, #96 )
  80. PLD( pld [r1, #28] )
  81. PLD( blt 4f )
  82. PLD( pld [r1, #60] )
  83. PLD( pld [r1, #92] )
  84. 3: PLD( pld [r1, #124] )
  85. 4: ldr8w r1, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f
  86. subs r2, r2, #32
  87. str8w r0, r3, r4, r5, r6, r7, r8, ip, lr, abort=20f
  88. bge 3b
  89. PLD( cmn r2, #96 )
  90. PLD( bge 4b )
  91. 5: ands ip, r2, #28
  92. rsb ip, ip, #32
  93. addne pc, pc, ip @ C is always clear here
  94. b 7f
  95. 6: nop
  96. ldr1w r1, r3, abort=20f
  97. ldr1w r1, r4, abort=20f
  98. ldr1w r1, r5, abort=20f
  99. ldr1w r1, r6, abort=20f
  100. ldr1w r1, r7, abort=20f
  101. ldr1w r1, r8, abort=20f
  102. ldr1w r1, lr, abort=20f
  103. add pc, pc, ip
  104. nop
  105. nop
  106. str1w r0, r3, abort=20f
  107. str1w r0, r4, abort=20f
  108. str1w r0, r5, abort=20f
  109. str1w r0, r6, abort=20f
  110. str1w r0, r7, abort=20f
  111. str1w r0, r8, abort=20f
  112. str1w r0, lr, abort=20f
  113. CALGN( bcs 2b )
  114. 7: ldmfd sp!, {r5 - r8}
  115. 8: movs r2, r2, lsl #31
  116. ldr1b r1, r3, ne, abort=21f
  117. ldr1b r1, r4, cs, abort=21f
  118. ldr1b r1, ip, cs, abort=21f
  119. str1b r0, r3, ne, abort=21f
  120. str1b r0, r4, cs, abort=21f
  121. str1b r0, ip, cs, abort=21f
  122. exit r4, pc
  123. 9: rsb ip, ip, #4
  124. cmp ip, #2
  125. ldr1b r1, r3, gt, abort=21f
  126. ldr1b r1, r4, ge, abort=21f
  127. ldr1b r1, lr, abort=21f
  128. str1b r0, r3, gt, abort=21f
  129. str1b r0, r4, ge, abort=21f
  130. subs r2, r2, ip
  131. str1b r0, lr, abort=21f
  132. blt 8b
  133. ands ip, r1, #3
  134. beq 1b
  135. 10: bic r1, r1, #3
  136. cmp ip, #2
  137. ldr1w r1, lr, abort=21f
  138. beq 17f
  139. bgt 18f
  140. .macro forward_copy_shift pull push
  141. subs r2, r2, #28
  142. blt 14f
  143. CALGN( ands ip, r0, #31 )
  144. CALGN( rsb ip, ip, #32 )
  145. CALGN( sbcnes r4, ip, r2 ) @ C is always set here
  146. CALGN( subcc r2, r2, ip )
  147. CALGN( bcc 15f )
  148. 11: stmfd sp!, {r5 - r9}
  149. PLD( pld [r1, #0] )
  150. PLD( subs r2, r2, #96 )
  151. PLD( pld [r1, #28] )
  152. PLD( blt 13f )
  153. PLD( pld [r1, #60] )
  154. PLD( pld [r1, #92] )
  155. 12: PLD( pld [r1, #124] )
  156. 13: ldr4w r1, r4, r5, r6, r7, abort=19f
  157. mov r3, lr, pull #\pull
  158. subs r2, r2, #32
  159. ldr4w r1, r8, r9, ip, lr, abort=19f
  160. orr r3, r3, r4, push #\push
  161. mov r4, r4, pull #\pull
  162. orr r4, r4, r5, push #\push
  163. mov r5, r5, pull #\pull
  164. orr r5, r5, r6, push #\push
  165. mov r6, r6, pull #\pull
  166. orr r6, r6, r7, push #\push
  167. mov r7, r7, pull #\pull
  168. orr r7, r7, r8, push #\push
  169. mov r8, r8, pull #\pull
  170. orr r8, r8, r9, push #\push
  171. mov r9, r9, pull #\pull
  172. orr r9, r9, ip, push #\push
  173. mov ip, ip, pull #\pull
  174. orr ip, ip, lr, push #\push
  175. str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, , abort=19f
  176. bge 12b
  177. PLD( cmn r2, #96 )
  178. PLD( bge 13b )
  179. ldmfd sp!, {r5 - r9}
  180. 14: ands ip, r2, #28
  181. beq 16f
  182. 15: mov r3, lr, pull #\pull
  183. ldr1w r1, lr, abort=21f
  184. subs ip, ip, #4
  185. orr r3, r3, lr, push #\push
  186. str1w r0, r3, abort=21f
  187. bgt 15b
  188. CALGN( cmp r2, #0 )
  189. CALGN( bge 11b )
  190. 16: sub r1, r1, #(\push / 8)
  191. b 8b
  192. .endm
  193. forward_copy_shift pull=8 push=24
  194. 17: forward_copy_shift pull=16 push=16
  195. 18: forward_copy_shift pull=24 push=8
  196. /*
  197. * Abort preamble and completion macros.
  198. * If a fixup handler is required then those macros must surround it.
  199. * It is assumed that the fixup code will handle the private part of
  200. * the exit macro.
  201. */
  202. .macro copy_abort_preamble
  203. 19: ldmfd sp!, {r5 - r9}
  204. b 21f
  205. 20: ldmfd sp!, {r5 - r8}
  206. 21:
  207. .endm
  208. .macro copy_abort_end
  209. ldmfd sp!, {r4, pc}
  210. .endm