1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * arch/alpha/lib/stxcpy.S 4 * Contributed by Richard Henderson (rth@tamu. 5 * 6 * Copy a null-terminated string from SRC to D 7 * 8 * This is an internal routine used by strcpy, 9 * As such, it uses special linkage convention 10 * of these public functions more efficient. 11 * 12 * On input: 13 * t9 = return address 14 * a0 = DST 15 * a1 = SRC 16 * 17 * On output: 18 * t12 = bitmask (with one bit set) indic 19 * a0 = unaligned address of the last *w 20 * 21 * Furthermore, v0, a3-a5, t11, and t12 are un 22 */ 23 24 #include <asm/regdef.h> 25 26 .set noat 27 .set noreorder 28 29 .text 30 31 /* There is a problem with either gdb (as of 4 32 doesn't like putting the entry point for a 33 middle of the procedure descriptor. Work a 34 aligned copy in its own procedure descripto 35 36 .ent stxcpy_aligned 37 .align 3 38 stxcpy_aligned: 39 .frame sp, 0, t9 40 .prologue 0 41 42 /* On entry to this basic block: 43 t0 == the first destination word fo 44 t1 == the first source word. */ 45 46 /* Create the 1st output word and dete 47 lda t2, -1 # e1 : buil 48 mskqh t2, a1, t2 # e0 : de 49 mskqh t1, a1, t3 # e0 : 50 ornot t1, t2, t2 # .. e1 : 51 mskql t0, a1, t0 # e0 : asse 52 cmpbge zero, t2, t8 # .. e1 : bits 53 or t0, t3, t1 # e0 : 54 bne t8, $a_eos # .. e1 : 55 56 /* On entry to this basic block: 57 t0 == the first destination word fo 58 t1 == a source word not containing 59 60 $a_loop: 61 stq_u t1, 0(a0) # e0 : 62 addq a0, 8, a0 # .. e1 : 63 ldq_u t1, 0(a1) # e0 : 64 addq a1, 8, a1 # .. e1 : 65 cmpbge zero, t1, t8 # e0 (stall) 66 beq t8, $a_loop # .. e1 (zdb) 67 68 /* Take care of the final (partial) wo 69 On entry to this basic block we hav 70 t1 == the source word containing th 71 t8 == the cmpbge mask that found it 72 $a_eos: 73 negq t8, t6 # e0 : find 74 and t8, t6, t12 # e1 (stall) 75 76 /* For the sake of the cache, don't re 77 if we're not going to need it. */ 78 and t12, 0x80, t6 # e0 : 79 bne t6, 1f # .. e1 (zdb) 80 81 /* We're doing a partial word store an 82 our source and original destination 83 ldq_u t0, 0(a0) # e0 : 84 subq t12, 1, t6 # .. e1 : 85 zapnot t1, t6, t1 # e0 : clea 86 or t12, t6, t8 # .. e1 : 87 zap t0, t8, t0 # e0 : clea 88 or t0, t1, t1 # e1 : 89 90 1: stq_u t1, 0(a0) # e0 : 91 ret (t9) # .. e1 : 92 93 .end stxcpy_aligned 94 95 .align 3 96 .ent __stxcpy 97 .globl __stxcpy 98 __stxcpy: 99 .frame sp, 0, t9 100 .prologue 0 101 102 /* Are source and destination co-align 103 xor a0, a1, t0 # e0 : 104 unop # : 105 and t0, 7, t0 # e0 : 106 bne t0, $unaligned # .. e1 : 107 108 /* We are co-aligned; take care of a p 109 ldq_u t1, 0(a1) # e0 : load 110 and a0, 7, t0 # .. e1 : take 111 addq a1, 8, a1 # e0 112 beq t0, stxcpy_aligned # .. e 113 ldq_u t0, 0(a0) # e0 : 114 br stxcpy_aligned # .. e1 : 115 116 117 /* The source and destination are not co-align 118 and cope. We have to be very careful about 119 causing a SEGV. */ 120 121 .align 3 122 $u_head: 123 /* We know just enough now to be able 124 full source word. We can still fin 125 that prevents us from outputting th 126 127 On entry to this basic block: 128 t0 == the first dest word, for mask 129 t1 == the low bits of the first sou 130 t6 == bytemask that is -1 in dest w 131 132 ldq_u t2, 8(a1) # e0 : 133 addq a1, 8, a1 # .. e1 : 134 135 extql t1, a1, t1 # e0 : 136 extqh t2, a1, t4 # e0 : 137 mskql t0, a0, t0 # e0 : 138 or t1, t4, t1 # .. e1 : 139 mskqh t1, a0, t1 # e0 : 140 or t0, t1, t1 # e1 : 141 142 or t1, t6, t6 # e0 : 143 cmpbge zero, t6, t8 # .. e1 : 144 lda t6, -1 # e0 : for 145 bne t8, $u_final # .. e1 : 146 147 mskql t6, a1, t6 # e0 148 or t6, t2, t2 # e1 149 cmpbge zero, t2, t8 # e0 150 bne t8, $u_late_head_exit # .. e 151 152 /* Finally, we've got all the stupid l 153 of and we can set up to enter the m 154 155 stq_u t1, 0(a0) # e0 : stor 156 addq a0, 8, a0 # .. e1 : 157 extql t2, a1, t0 # e0 : posi 158 ldq_u t2, 8(a1) # .. e1 : read 159 addq a1, 8, a1 # e0 : 160 cmpbge zero, t2, t8 # .. e1 : 161 nop # e0 : 162 bne t8, $u_eos # .. e1 : 163 164 /* Unaligned copy main loop. In order 165 the loop is structured to detect ze 166 This has, unfortunately, effectivel 167 iteration out into the head and hal 168 prevent nastiness from accumulating 169 to run as fast as possible. 170 171 On entry to this basic block: 172 t0 == the shifted high-order bits f 173 t2 == the unshifted current source 174 175 We further know that t2 does not co 176 177 .align 3 178 $u_loop: 179 extqh t2, a1, t1 # e0 : extr 180 addq a1, 8, a1 # .. e1 : 181 extql t2, a1, t3 # e0 : extr 182 addq a0, 8, a0 # .. e1 : 183 or t0, t1, t1 # e0 : curr 184 ldq_u t2, 0(a1) # .. e1 : load 185 stq_u t1, -8(a0) # e0 : save 186 mov t3, t0 # .. e1 : 187 cmpbge zero, t2, t8 # e0 : test 188 beq t8, $u_loop # .. e1 : 189 190 /* We've found a zero somewhere in the 191 If it resides in the lower half, we 192 word to write out, and if it reside 193 have one full and one partial word 194 195 On entry to this basic block: 196 t0 == the shifted high-order bits f 197 t2 == the unshifted current source 198 $u_eos: 199 extqh t2, a1, t1 # e0 : 200 or t0, t1, t1 # e1 : firs 201 202 cmpbge zero, t1, t8 # e0 : is t 203 bne t8, $u_final # .. e1 (zdb) 204 205 $u_late_head_exit: 206 stq_u t1, 0(a0) # e0 : the 207 addq a0, 8, a0 # .. e1 : 208 extql t2, a1, t1 # e0 : 209 cmpbge zero, t1, t8 # .. e1 : 210 211 /* Take care of a final (probably part 212 On entry to this basic block: 213 t1 == assembled source word 214 t8 == cmpbge mask that found the nu 215 $u_final: 216 negq t8, t6 # e0 : isol 217 and t6, t8, t12 # e1 : 218 219 and t12, 0x80, t6 # e0 : avoi 220 bne t6, 1f # .. e1 (zdb) 221 222 ldq_u t0, 0(a0) # e0 : 223 subq t12, 1, t6 # .. e1 : 224 or t6, t12, t8 # e0 : 225 zapnot t1, t6, t1 # .. e1 : kill 226 zap t0, t8, t0 # e0 : kill 227 or t0, t1, t1 # e1 : 228 229 1: stq_u t1, 0(a0) # e0 : 230 ret (t9) # .. e1 : 231 232 /* Unaligned copy entry point. */ 233 .align 3 234 $unaligned: 235 236 ldq_u t1, 0(a1) # e0 : load 237 238 and a0, 7, t4 # .. e1 : find 239 and a1, 7, t5 # e0 : find 240 241 /* Conditionally load the first destin 242 with 0xff indicating that the desti 243 244 mov zero, t0 # .. e1 : 245 mov zero, t6 # e0 : 246 beq t4, 1f # .. e1 : 247 ldq_u t0, 0(a0) # e0 : 248 lda t6, -1 # .. e1 : 249 mskql t6, a0, t6 # e0 : 250 1: 251 subq a1, t4, a1 # .. e1 : sub 252 253 /* If source misalignment is larger th 254 extra startup checks to avoid SEGV. 255 256 cmplt t4, t5, t12 # e0 : 257 beq t12, $u_head # .. e1 (zdb) 258 259 lda t2, -1 # e1 : mask 260 mskqh t2, t5, t2 # e0 : 261 nop # e0 : 262 ornot t1, t2, t3 # .. e1 : 263 cmpbge zero, t3, t8 # e0 : is t 264 beq t8, $u_head # .. e1 (zdb) 265 266 /* At this point we've found a zero in 267 the source. We need to isolate the 268 it into the original destination da 269 that we'll need at least one byte o 270 271 ldq_u t0, 0(a0) # e0 : 272 273 negq t8, t6 # .. e1 : buil 274 and t6, t8, t12 # e0 : 275 and a1, 7, t5 # .. e1 : 276 subq t12, 1, t6 # e0 : 277 or t6, t12, t8 # e1 : 278 srl t12, t5, t12 # e0 : adju 279 280 zapnot t2, t8, t2 # .. e1 : prep 281 and t1, t2, t1 # e1 : to s 282 extql t2, a1, t2 # .. e0 : 283 extql t1, a1, t1 # e0 : 284 285 andnot t0, t2, t0 # .. e1 : zero 286 or t0, t1, t1 # e1 : and 287 stq_u t1, 0(a0) # .. e0 : 288 ret (t9) # e1 : 289 290 .end __stxcpy
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.