2 * arch/alpha/lib/ev6-copy_user.S
4 * 21264 version contributed by Rick Gorton <rick.gorton@alpha-processor.com>
6 * Copy to/from user space, handling exceptions as we go.. This
7 * isn't exactly pretty.
9 * This is essentially the same as "memcpy()", but with a few twists.
10 * Notably, we have to make sure that $0 is always up-to-date and
11 * contains the right "bytes left to copy" value (and that it is updated
12 * only _after_ a successful copy). There is also some rather minor
13 * exception setup stuff..
15 * Much of the information about 21264 scheduling/coding comes from:
16 * Compiler Writer's Guide for the Alpha 21264
17 * abbreviated as 'CWG' in other comments here
18 * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
19 * Scheduling notation:
21 * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1
22 * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1
25 #include <asm/export.h>
26 /* Allow an exception for an insn; exit if we get one. */
29 .section __ex_table,"a"; \
31 lda $31, $exitin-99b($31); \
36 .section __ex_table,"a"; \
38 lda $31, $exitout-99b($31); \
45 # Pipeline info: Slotting & Comments
48 mov $18, $0 # .. .. .. E
49 subq $18, 32, $1 # .. .. E. .. : Is this going to be a small copy?
51 beq $18, $zerolength # U .. .. .. : U L U L
53 and $16,7,$3 # .. .. .. E : is leading dest misalignment
54 ble $1, $onebyteloop # .. .. U .. : 1st branch : small amount of data
55 beq $3, $destaligned # .. U .. .. : 2nd (one cycle fetcher stall)
56 subq $3, 8, $3 # E .. .. .. : L U U L : trip counter
58 * The fetcher stall also hides the 1 cycle cross-cluster stall for $3 (L --> U)
59 * This loop aligns the destination a byte at a time
60 * We know we have at least one trip through this loop
63 EXI( ldbu $1,0($17) ) # .. .. .. L : Keep loads separate from stores
64 addq $16,1,$16 # .. .. E .. : Section 3.8 in the CWG
65 addq $3,1,$3 # .. E .. .. :
66 nop # E .. .. .. : U L U L
69 * the -1 is to compensate for the inc($16) done in a previous quadpack
70 * which allows us zero dependencies within either quadpack in the loop
72 EXO( stb $1,-1($16) ) # .. .. .. L :
73 addq $17,1,$17 # .. .. E .. : Section 3.8 in the CWG
74 subq $0,1,$0 # .. E .. .. :
75 bne $3, $aligndest # U .. .. .. : U L U L
78 * If we fell through into here, we have a minimum of 33 - 7 bytes
79 * If we arrived via branch, we have a minimum of 32 bytes
82 and $17,7,$1 # .. .. .. E : Check _current_ source alignment
83 bic $0,7,$4 # .. .. E .. : number bytes as a quadword loop
84 EXI( ldq_u $3,0($17) ) # .. L .. .. : Forward fetch for fallthrough code
85 beq $1,$quadaligned # U .. .. .. : U L U L
88 * In the worst case, we've just executed an ldq_u here from 0($17)
89 * and we'll repeat it once if we take the branch
92 /* Misaligned quadword loop - not unrolled. Leave it that way. */
94 EXI( ldq_u $2,8($17) ) # .. .. .. L :
95 subq $4,8,$4 # .. .. E .. :
96 extql $3,$17,$3 # .. U .. .. :
97 extqh $2,$17,$1 # U .. .. .. : U U L L
99 bis $3,$1,$1 # .. .. .. E :
100 EXO( stq $1,0($16) ) # .. .. L .. :
101 addq $17,8,$17 # .. E .. .. :
102 subq $0,8,$0 # E .. .. .. : U L L U
104 addq $16,8,$16 # .. .. .. E :
105 bis $2,$2,$3 # .. .. E .. :
107 bne $4,$misquad # U .. .. .. : U L U L
112 beq $0,$zerolength # U .. .. .. : U L U L
114 /* We know we have at least one trip through the byte loop */
115 EXI ( ldbu $2,0($17) ) # .. .. .. L : No loads in the same quad
116 addq $16,1,$16 # .. .. E .. : as the store (Section 3.8 in CWG)
118 br $31, $dirtyentry # L0 .. .. .. : L U U L
119 /* Do the trailing byte loop load, then hop into the store part of the loop */
122 * A minimum of (33 - 7) bytes to do a quad at a time.
123 * Based upon the usage context, it's worth the effort to unroll this loop
124 * $0 - number of bytes to be moved
125 * $4 - number of bytes to move as quadwords
126 * $16 is current destination address
127 * $17 is current source address
130 subq $4, 32, $2 # .. .. .. E : do not unroll for small stuff
133 blt $2, $onequad # U .. .. .. : U L U L
136 * There is a significant assumption here that the source and destination
137 * addresses differ by more than 32 bytes. In this particular case, a
138 * sparsity of registers further bounds this to be a minimum of 8 bytes.
139 * But if this isn't met, then the output result will be incorrect.
140 * Furthermore, due to a lack of available registers, we really can't
141 * unroll this to be an 8x loop (which would enable us to use the wh64
142 * instruction memory hint instruction).
145 EXI( ldq $1,0($17) ) # .. .. .. L
146 EXI( ldq $2,8($17) ) # .. .. L ..
147 subq $4,32,$4 # .. E .. ..
148 nop # E .. .. .. : U U L L
150 addq $17,16,$17 # .. .. .. E
151 EXO( stq $1,0($16) ) # .. .. L ..
152 EXO( stq $2,8($16) ) # .. L .. ..
153 subq $0,16,$0 # E .. .. .. : U L L U
155 addq $16,16,$16 # .. .. .. E
156 EXI( ldq $1,0($17) ) # .. .. L ..
157 EXI( ldq $2,8($17) ) # .. L .. ..
158 subq $4, 32, $3 # E .. .. .. : U U L L : is there enough for another trip?
160 EXO( stq $1,0($16) ) # .. .. .. L
161 EXO( stq $2,8($16) ) # .. .. L ..
162 subq $0,16,$0 # .. E .. ..
163 addq $17,16,$17 # E .. .. .. : U L L U
167 addq $16,16,$16 # .. E .. ..
168 bgt $3,$unroll4 # U .. .. .. : U L U L
193 * For small copies (or the tail of a larger copy), do a very simple byte loop.
194 * There's no point in doing a lot of complex alignment calculations to try to
195 * to quadword stuff for a small amount of data.
196 * $0 - remaining number of bytes left to copy
197 * $16 - current dest addr
198 * $17 - current source addr
202 EXI ( ldbu $2,0($17) ) # .. .. .. L : No loads in the same quad
203 addq $16,1,$16 # .. .. E .. : as the store (Section 3.8 in CWG)
205 nop # E .. .. .. : U L U L
209 * the -1 is to compensate for the inc($16) done in a previous quadpack
210 * which allows us zero dependencies within either quadpack in the loop
212 EXO ( stb $2,-1($16) ) # .. .. .. L :
213 addq $17,1,$17 # .. .. E .. : quadpack as the load
214 subq $0,1,$0 # .. E .. .. : change count _after_ copy
215 bgt $0,$onebyteloop # U .. .. .. : U L U L
219 $exitout: # Destination for exception recovery(?)
223 ret $31,($26),1 # L0 .. .. .. : L U L U
226 EXPORT_SYMBOL(__copy_user)