1/* 2 * arch/alpha/lib/ev6-copy_user.S 3 * 4 * 21264 version contributed by Rick Gorton <rick.gorton@alpha-processor.com> 5 * 6 * Copy to/from user space, handling exceptions as we go.. This 7 * isn't exactly pretty. 8 * 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.. 14 * 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: 20 * E - either cluster 21 * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1 22 * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 23 */ 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 34#define EXO(x,y...) \ 35 99: x,##y; \ 36 .section __ex_table,"a"; \ 37 .long 99b - .; \ 38 lda $31, $exitout-99b($31); \ 39 .previous 40 41 .set noat 42 .align 4 43 .globl __copy_user 44 .ent __copy_user 45 # Pipeline info: Slotting & Comments 46__copy_user: 47 .prologue 0 48 mov $18, $0 # .. .. .. E 49 subq $18, 32, $1 # .. .. E. .. : Is this going to be a small copy? 50 nop # .. E .. .. 51 beq $18, $zerolength # U .. .. .. : U L U L 52 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 57/* 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 61 */ 62$aligndest: 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 67 68/* 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 71 */ 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 76 77/* 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 80 */ 81$destaligned: 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 86 87/* 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 90 */ 91 92/* Misaligned quadword loop - not unrolled. Leave it that way. */ 93$misquad: 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 98 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 103 104 addq $16,8,$16 # .. .. .. E : 105 bis $2,$2,$3 # .. .. E .. : 106 nop # .. E .. .. : 107 bne $4,$misquad # U .. .. .. : U L U L 108 109 nop # .. .. .. E 110 nop # .. .. E .. 111 nop # .. E .. .. 112 beq $0,$zerolength # U .. .. .. : U L U L 113 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) 117 nop # .. E .. .. : 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 */ 120 121/* 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 128 */ 129$quadaligned: 130 subq $4, 32, $2 # .. .. .. E : do not unroll for small stuff 131 nop # .. .. E .. 132 nop # .. E .. .. 133 blt $2, $onequad # U .. .. .. : U L U L 134 135/* 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). 143 */ 144$unroll4: 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 149 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 154 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? 159 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 164 165 nop # .. .. .. E 166 nop # .. .. E .. 167 addq $16,16,$16 # .. E .. .. 168 bgt $3,$unroll4 # U .. .. .. : U L U L 169 170 nop 171 nop 172 nop 173 beq $4, $noquads 174 175$onequad: 176 EXI( ldq $1,0($17) ) 177 subq $4,8,$4 178 addq $17,8,$17 179 nop 180 181 EXO( stq $1,0($16) ) 182 subq $0,8,$0 183 addq $16,8,$16 184 bne $4,$onequad 185 186$noquads: 187 nop 188 nop 189 nop 190 beq $0,$zerolength 191 192/* 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 199 */ 200 201$onebyteloop: 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) 204 nop # .. E .. .. : 205 nop # E .. .. .. : U L U L 206 207$dirtyentry: 208/* 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 211 */ 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 216 217$zerolength: 218$exitin: 219$exitout: # Destination for exception recovery(?) 220 nop # .. .. .. E 221 nop # .. .. E .. 222 nop # .. E .. .. 223 ret $31,($26),1 # L0 .. .. .. : L U L U 224 225 .end __copy_user 226 EXPORT_SYMBOL(__copy_user) 227