1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * arch/alpha/lib/ev6-copy_user.S 4 * 5 * 21264 version contributed by Rick Gorton <ri 6 * 7 * Copy to/from user space, handling exception 8 * isn't exactly pretty. 9 * 10 * This is essentially the same as "memcpy()", 11 * Notably, we have to make sure that $0 is al 12 * contains the right "bytes left to copy" val 13 * only _after_ a successful copy). There is a 14 * exception setup stuff.. 15 * 16 * Much of the information about 21264 schedul 17 * Compiler Writer's Guide for the Alpha 18 * abbreviated as 'CWG' in other comments 19 * ftp.digital.com/pub/Digital/info/semic 20 * Scheduling notation: 21 * E - either cluster 22 * U - upper subcluster; U0 - subcl 23 * L - lower subcluster; L0 - subcl 24 */ 25 26 #include <linux/export.h> 27 /* Allow an exception for an insn; exit if we 28 #define EXI(x,y...) \ 29 99: x,##y; \ 30 .section __ex_table,"a"; \ 31 .long 99b - .; \ 32 lda $31, $exitin-99b($31); \ 33 .previous 34 35 #define EXO(x,y...) \ 36 99: x,##y; \ 37 .section __ex_table,"a"; \ 38 .long 99b - .; \ 39 lda $31, $exitout-99b($31); \ 40 .previous 41 42 .set noat 43 .align 4 44 .globl __copy_user 45 .ent __copy_user 46 # Pipeline inf 47 __copy_user: 48 .prologue 0 49 mov $18, $0 # .. .. .. E 50 subq $18, 32, $1 # .. .. E. .. 51 nop # .. E .. .. 52 beq $18, $zerolength # U .. .. .. 53 54 and $16,7,$3 # .. .. .. E 55 ble $1, $onebyteloop # .. .. U .. 56 beq $3, $destaligned # .. U .. .. 57 subq $3, 8, $3 # E .. .. .. 58 /* 59 * The fetcher stall also hides the 1 cycle cr 60 * This loop aligns the destination a byte at 61 * We know we have at least one trip through t 62 */ 63 $aligndest: 64 EXI( ldbu $1,0($17) ) # .. .. .. L 65 addq $16,1,$16 # .. .. E .. 66 addq $3,1,$3 # .. E .. .. 67 nop # E .. .. .. 68 69 /* 70 * the -1 is to compensate for the inc($16) do 71 * which allows us zero dependencies within ei 72 */ 73 EXO( stb $1,-1($16) ) # .. .. .. L 74 addq $17,1,$17 # .. .. E .. 75 subq $0,1,$0 # .. E .. .. 76 bne $3, $aligndest # U .. .. .. 77 78 /* 79 * If we fell through into here, we have a min 80 * If we arrived via branch, we have a minimum 81 */ 82 $destaligned: 83 and $17,7,$1 # .. .. .. E 84 bic $0,7,$4 # .. .. E .. 85 EXI( ldq_u $3,0($17) ) # .. L .. .. 86 beq $1,$quadaligned # U .. .. .. 87 88 /* 89 * In the worst case, we've just executed an l 90 * and we'll repeat it once if we take the bra 91 */ 92 93 /* Misaligned quadword loop - not unrolled. L 94 $misquad: 95 EXI( ldq_u $2,8($17) ) # .. .. .. L 96 subq $4,8,$4 # .. .. E .. 97 extql $3,$17,$3 # .. U .. .. 98 extqh $2,$17,$1 # U .. .. .. 99 100 bis $3,$1,$1 # .. .. .. E 101 EXO( stq $1,0($16) ) # .. .. L .. 102 addq $17,8,$17 # .. E .. .. 103 subq $0,8,$0 # E .. .. .. 104 105 addq $16,8,$16 # .. .. .. E 106 bis $2,$2,$3 # .. .. E .. 107 nop # .. E .. .. 108 bne $4,$misquad # U .. .. .. 109 110 nop # .. .. .. E 111 nop # .. .. E .. 112 nop # .. E .. .. 113 beq $0,$zerolength # U .. .. .. 114 115 /* We know we have at least one trip through t 116 EXI ( ldbu $2,0($17) ) # .. .. .. L 117 addq $16,1,$16 # .. .. E .. 118 nop # .. E .. .. 119 br $31, $dirtyentry # L0 .. .. .. 120 /* Do the trailing byte loop load, then hop in 121 122 /* 123 * A minimum of (33 - 7) bytes to do a quad at 124 * Based upon the usage context, it's worth th 125 * $0 - number of bytes to be moved 126 * $4 - number of bytes to move as quadwords 127 * $16 is current destination address 128 * $17 is current source address 129 */ 130 $quadaligned: 131 subq $4, 32, $2 # .. .. .. E 132 nop # .. .. E .. 133 nop # .. E .. .. 134 blt $2, $onequad # U .. .. .. 135 136 /* 137 * There is a significant assumption here that 138 * addresses differ by more than 32 bytes. In 139 * sparsity of registers further bounds this t 140 * But if this isn't met, then the output resu 141 * Furthermore, due to a lack of available reg 142 * unroll this to be an 8x loop (which would e 143 * instruction memory hint instruction). 144 */ 145 $unroll4: 146 EXI( ldq $1,0($17) ) # .. .. .. L 147 EXI( ldq $2,8($17) ) # .. .. L .. 148 subq $4,32,$4 # .. E .. .. 149 nop # E .. .. .. 150 151 addq $17,16,$17 # .. .. .. E 152 EXO( stq $1,0($16) ) # .. .. L .. 153 EXO( stq $2,8($16) ) # .. L .. .. 154 subq $0,16,$0 # E .. .. .. 155 156 addq $16,16,$16 # .. .. .. E 157 EXI( ldq $1,0($17) ) # .. .. L .. 158 EXI( ldq $2,8($17) ) # .. L .. .. 159 subq $4, 32, $3 # E .. .. .. 160 161 EXO( stq $1,0($16) ) # .. .. .. L 162 EXO( stq $2,8($16) ) # .. .. L .. 163 subq $0,16,$0 # .. E .. .. 164 addq $17,16,$17 # E .. .. .. 165 166 nop # .. .. .. E 167 nop # .. .. E .. 168 addq $16,16,$16 # .. E .. .. 169 bgt $3,$unroll4 # U .. .. .. 170 171 nop 172 nop 173 nop 174 beq $4, $noquads 175 176 $onequad: 177 EXI( ldq $1,0($17) ) 178 subq $4,8,$4 179 addq $17,8,$17 180 nop 181 182 EXO( stq $1,0($16) ) 183 subq $0,8,$0 184 addq $16,8,$16 185 bne $4,$onequad 186 187 $noquads: 188 nop 189 nop 190 nop 191 beq $0,$zerolength 192 193 /* 194 * For small copies (or the tail of a larger c 195 * There's no point in doing a lot of complex 196 * to quadword stuff for a small amount of dat 197 * $0 - remaining number of bytes left to 198 * $16 - current dest addr 199 * $17 - current source addr 200 */ 201 202 $onebyteloop: 203 EXI ( ldbu $2,0($17) ) # .. .. .. L 204 addq $16,1,$16 # .. .. E .. 205 nop # .. E .. .. 206 nop # E .. .. .. 207 208 $dirtyentry: 209 /* 210 * the -1 is to compensate for the inc($16) do 211 * which allows us zero dependencies within ei 212 */ 213 EXO ( stb $2,-1($16) ) # .. .. .. L 214 addq $17,1,$17 # .. .. E .. 215 subq $0,1,$0 # .. E .. .. 216 bgt $0,$onebyteloop # U .. .. .. 217 218 $zerolength: 219 $exitin: 220 $exitout: # Destination 221 nop # .. .. .. E 222 nop # .. .. E .. 223 nop # .. E .. .. 224 ret $31,($26),1 # L0 .. .. .. 225 226 .end __copy_user 227 EXPORT_SYMBOL(__copy_user)
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.