ev6-copy_user.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * arch/alpha/lib/ev6-copy_user.S
  4. *
  5. * 21264 version contributed by Rick Gorton <[email protected]>
  6. *
  7. * Copy to/from user space, handling exceptions as we go.. This
  8. * isn't exactly pretty.
  9. *
  10. * This is essentially the same as "memcpy()", but with a few twists.
  11. * Notably, we have to make sure that $0 is always up-to-date and
  12. * contains the right "bytes left to copy" value (and that it is updated
  13. * only _after_ a successful copy). There is also some rather minor
  14. * exception setup stuff..
  15. *
  16. * Much of the information about 21264 scheduling/coding comes from:
  17. * Compiler Writer's Guide for the Alpha 21264
  18. * abbreviated as 'CWG' in other comments here
  19. * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
  20. * Scheduling notation:
  21. * E - either cluster
  22. * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1
  23. * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1
  24. */
  25. #include <asm/export.h>
  26. /* Allow an exception for an insn; exit if we get one. */
  27. #define EXI(x,y...) \
  28. 99: x,##y; \
  29. .section __ex_table,"a"; \
  30. .long 99b - .; \
  31. lda $31, $exitin-99b($31); \
  32. .previous
  33. #define EXO(x,y...) \
  34. 99: x,##y; \
  35. .section __ex_table,"a"; \
  36. .long 99b - .; \
  37. lda $31, $exitout-99b($31); \
  38. .previous
  39. .set noat
  40. .align 4
  41. .globl __copy_user
  42. .ent __copy_user
  43. # Pipeline info: Slotting & Comments
  44. __copy_user:
  45. .prologue 0
  46. mov $18, $0 # .. .. .. E
  47. subq $18, 32, $1 # .. .. E. .. : Is this going to be a small copy?
  48. nop # .. E .. ..
  49. beq $18, $zerolength # U .. .. .. : U L U L
  50. and $16,7,$3 # .. .. .. E : is leading dest misalignment
  51. ble $1, $onebyteloop # .. .. U .. : 1st branch : small amount of data
  52. beq $3, $destaligned # .. U .. .. : 2nd (one cycle fetcher stall)
  53. subq $3, 8, $3 # E .. .. .. : L U U L : trip counter
  54. /*
  55. * The fetcher stall also hides the 1 cycle cross-cluster stall for $3 (L --> U)
  56. * This loop aligns the destination a byte at a time
  57. * We know we have at least one trip through this loop
  58. */
  59. $aligndest:
  60. EXI( ldbu $1,0($17) ) # .. .. .. L : Keep loads separate from stores
  61. addq $16,1,$16 # .. .. E .. : Section 3.8 in the CWG
  62. addq $3,1,$3 # .. E .. .. :
  63. nop # E .. .. .. : U L U L
  64. /*
  65. * the -1 is to compensate for the inc($16) done in a previous quadpack
  66. * which allows us zero dependencies within either quadpack in the loop
  67. */
  68. EXO( stb $1,-1($16) ) # .. .. .. L :
  69. addq $17,1,$17 # .. .. E .. : Section 3.8 in the CWG
  70. subq $0,1,$0 # .. E .. .. :
  71. bne $3, $aligndest # U .. .. .. : U L U L
  72. /*
  73. * If we fell through into here, we have a minimum of 33 - 7 bytes
  74. * If we arrived via branch, we have a minimum of 32 bytes
  75. */
  76. $destaligned:
  77. and $17,7,$1 # .. .. .. E : Check _current_ source alignment
  78. bic $0,7,$4 # .. .. E .. : number bytes as a quadword loop
  79. EXI( ldq_u $3,0($17) ) # .. L .. .. : Forward fetch for fallthrough code
  80. beq $1,$quadaligned # U .. .. .. : U L U L
  81. /*
  82. * In the worst case, we've just executed an ldq_u here from 0($17)
  83. * and we'll repeat it once if we take the branch
  84. */
  85. /* Misaligned quadword loop - not unrolled. Leave it that way. */
  86. $misquad:
  87. EXI( ldq_u $2,8($17) ) # .. .. .. L :
  88. subq $4,8,$4 # .. .. E .. :
  89. extql $3,$17,$3 # .. U .. .. :
  90. extqh $2,$17,$1 # U .. .. .. : U U L L
  91. bis $3,$1,$1 # .. .. .. E :
  92. EXO( stq $1,0($16) ) # .. .. L .. :
  93. addq $17,8,$17 # .. E .. .. :
  94. subq $0,8,$0 # E .. .. .. : U L L U
  95. addq $16,8,$16 # .. .. .. E :
  96. bis $2,$2,$3 # .. .. E .. :
  97. nop # .. E .. .. :
  98. bne $4,$misquad # U .. .. .. : U L U L
  99. nop # .. .. .. E
  100. nop # .. .. E ..
  101. nop # .. E .. ..
  102. beq $0,$zerolength # U .. .. .. : U L U L
  103. /* We know we have at least one trip through the byte loop */
  104. EXI ( ldbu $2,0($17) ) # .. .. .. L : No loads in the same quad
  105. addq $16,1,$16 # .. .. E .. : as the store (Section 3.8 in CWG)
  106. nop # .. E .. .. :
  107. br $31, $dirtyentry # L0 .. .. .. : L U U L
  108. /* Do the trailing byte loop load, then hop into the store part of the loop */
  109. /*
  110. * A minimum of (33 - 7) bytes to do a quad at a time.
  111. * Based upon the usage context, it's worth the effort to unroll this loop
  112. * $0 - number of bytes to be moved
  113. * $4 - number of bytes to move as quadwords
  114. * $16 is current destination address
  115. * $17 is current source address
  116. */
  117. $quadaligned:
  118. subq $4, 32, $2 # .. .. .. E : do not unroll for small stuff
  119. nop # .. .. E ..
  120. nop # .. E .. ..
  121. blt $2, $onequad # U .. .. .. : U L U L
  122. /*
  123. * There is a significant assumption here that the source and destination
  124. * addresses differ by more than 32 bytes. In this particular case, a
  125. * sparsity of registers further bounds this to be a minimum of 8 bytes.
  126. * But if this isn't met, then the output result will be incorrect.
  127. * Furthermore, due to a lack of available registers, we really can't
  128. * unroll this to be an 8x loop (which would enable us to use the wh64
  129. * instruction memory hint instruction).
  130. */
  131. $unroll4:
  132. EXI( ldq $1,0($17) ) # .. .. .. L
  133. EXI( ldq $2,8($17) ) # .. .. L ..
  134. subq $4,32,$4 # .. E .. ..
  135. nop # E .. .. .. : U U L L
  136. addq $17,16,$17 # .. .. .. E
  137. EXO( stq $1,0($16) ) # .. .. L ..
  138. EXO( stq $2,8($16) ) # .. L .. ..
  139. subq $0,16,$0 # E .. .. .. : U L L U
  140. addq $16,16,$16 # .. .. .. E
  141. EXI( ldq $1,0($17) ) # .. .. L ..
  142. EXI( ldq $2,8($17) ) # .. L .. ..
  143. subq $4, 32, $3 # E .. .. .. : U U L L : is there enough for another trip?
  144. EXO( stq $1,0($16) ) # .. .. .. L
  145. EXO( stq $2,8($16) ) # .. .. L ..
  146. subq $0,16,$0 # .. E .. ..
  147. addq $17,16,$17 # E .. .. .. : U L L U
  148. nop # .. .. .. E
  149. nop # .. .. E ..
  150. addq $16,16,$16 # .. E .. ..
  151. bgt $3,$unroll4 # U .. .. .. : U L U L
  152. nop
  153. nop
  154. nop
  155. beq $4, $noquads
  156. $onequad:
  157. EXI( ldq $1,0($17) )
  158. subq $4,8,$4
  159. addq $17,8,$17
  160. nop
  161. EXO( stq $1,0($16) )
  162. subq $0,8,$0
  163. addq $16,8,$16
  164. bne $4,$onequad
  165. $noquads:
  166. nop
  167. nop
  168. nop
  169. beq $0,$zerolength
  170. /*
  171. * For small copies (or the tail of a larger copy), do a very simple byte loop.
  172. * There's no point in doing a lot of complex alignment calculations to try to
  173. * to quadword stuff for a small amount of data.
  174. * $0 - remaining number of bytes left to copy
  175. * $16 - current dest addr
  176. * $17 - current source addr
  177. */
  178. $onebyteloop:
  179. EXI ( ldbu $2,0($17) ) # .. .. .. L : No loads in the same quad
  180. addq $16,1,$16 # .. .. E .. : as the store (Section 3.8 in CWG)
  181. nop # .. E .. .. :
  182. nop # E .. .. .. : U L U L
  183. $dirtyentry:
  184. /*
  185. * the -1 is to compensate for the inc($16) done in a previous quadpack
  186. * which allows us zero dependencies within either quadpack in the loop
  187. */
  188. EXO ( stb $2,-1($16) ) # .. .. .. L :
  189. addq $17,1,$17 # .. .. E .. : quadpack as the load
  190. subq $0,1,$0 # .. E .. .. : change count _after_ copy
  191. bgt $0,$onebyteloop # U .. .. .. : U L U L
  192. $zerolength:
  193. $exitin:
  194. $exitout: # Destination for exception recovery(?)
  195. nop # .. .. .. E
  196. nop # .. .. E ..
  197. nop # .. E .. ..
  198. ret $31,($26),1 # L0 .. .. .. : L U L U
  199. .end __copy_user
  200. EXPORT_SYMBOL(__copy_user)