| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* Cloned and hacked for uClibc by Paul Mundt, December 2003 */ | 
 | 2 | /* Modified by SuperH, Inc. September 2003 */ | 
 | 3 | ! Entry: arg0: destination | 
 | 4 | !        arg1: source | 
 | 5 | ! Exit:  result: destination | 
 | 6 | ! | 
 | 7 | ! SH5 code Copyright 2002 SuperH Ltd. | 
 | 8 |  | 
 | 9 | #include <features.h> | 
 | 10 | #include <endian.h> | 
 | 11 |  | 
 | 12 | #if __BYTE_ORDER == __LITTLE_ENDIAN | 
 | 13 | #define SHHI shlld | 
 | 14 | #define SHLO shlrd | 
 | 15 | #else | 
 | 16 | #define SHHI shlrd | 
 | 17 | #define SHLO shlld | 
 | 18 | #endif | 
 | 19 |  | 
 | 20 | 	.section .text..SHmedia32,"ax" | 
 | 21 | 	.globl	strcpy | 
 | 22 | 	.type	strcpy, @function | 
 | 23 | 	.align 5 | 
 | 24 |  | 
 | 25 | strcpy: | 
 | 26 |  | 
 | 27 | 	pta/l shortstring,tr1 | 
 | 28 | 	ldlo.q r3,0,r4 | 
 | 29 | 	ptabs r18,tr4 | 
 | 30 | 	shlli r3,3,r7 | 
 | 31 | 	addi r2, 8, r0 | 
 | 32 | 	mcmpeq.b r4,r63,r6 | 
 | 33 | 	SHHI r6,r7,r6 | 
 | 34 | 	bnei/u r6,0,tr1 /* shortstring */ | 
 | 35 | 	pta/l no_lddst, tr2 | 
 | 36 | 	ori r3,-8,r23 | 
 | 37 | 	sub r2, r23, r0 | 
 | 38 | 	sub r3, r2, r21 | 
 | 39 | 	addi r21, 8, r20 | 
 | 40 | 	ldx.q r0, r21, r5 | 
 | 41 | 	pta/l loop, tr0 | 
 | 42 | 	ori r2,-8,r22 | 
 | 43 | 	mcmpeq.b r5, r63, r6 | 
 | 44 | 	bgt/u r22, r23, tr2 /* no_lddst */ | 
 | 45 |  | 
 | 46 | 	/* r22 < r23 :  Need to do a load from the destination. */ | 
 | 47 | 	/* r22 == r23 : Doesn't actually need to load from destination, */ | 
 | 48 | 	/*              but still can be handled here. */ | 
 | 49 | 	ldlo.q r2, 0, r9 | 
 | 50 | 	movi -1, r8 | 
 | 51 | 	SHLO r8, r7, r8 | 
 | 52 | 	mcmv r4, r8, r9 | 
 | 53 | 	stlo.q r2, 0, r9 | 
 | 54 | 	beqi/l r6, 0, tr0 /* loop */ | 
 | 55 |  | 
 | 56 | 	add r5, r63, r4 | 
 | 57 | 	addi r0, 8, r0 | 
 | 58 | 	blink tr1, r63 /* shortstring */ | 
 | 59 | no_lddst: | 
 | 60 | 	/* r22 > r23: note that for r22 == r23 the sthi.q would clobber */ | 
 | 61 | 	/*            bytes before the destination region. */ | 
 | 62 | 	stlo.q r2, 0, r4 | 
 | 63 | 	SHHI r4, r7, r4 | 
 | 64 | 	sthi.q r0, -1, r4 | 
 | 65 | 	beqi/l r6, 0, tr0 /* loop */ | 
 | 66 |  | 
 | 67 | 	add r5, r63, r4 | 
 | 68 | 	addi r0, 8, r0 | 
 | 69 | shortstring: | 
 | 70 | #if __BYTE_ORDER != __LITTLE_ENDIAN | 
 | 71 | 	pta/l shortstring2,tr1 | 
 | 72 | 	byterev r4,r4 | 
 | 73 | #endif | 
 | 74 | shortstring2: | 
 | 75 | 	st.b r0,-8,r4 | 
 | 76 | 	andi r4,0xff,r5 | 
 | 77 | 	shlri r4,8,r4 | 
 | 78 | 	addi r0,1,r0 | 
 | 79 | 	bnei/l r5,0,tr1 | 
 | 80 | 	blink tr4,r63 /* return */ | 
 | 81 | 	 | 
 | 82 | 	.balign 8 | 
 | 83 | loop: | 
 | 84 | 	stlo.q r0, 0, r5 | 
 | 85 | 	ldx.q r0, r20, r4 | 
 | 86 | 	addi r0, 16, r0 | 
 | 87 | 	sthi.q r0, -9, r5 | 
 | 88 | 	mcmpeq.b r4, r63, r6 | 
 | 89 | 	bnei/u r6, 0, tr1 /* shortstring */ | 
 | 90 | 	ldx.q r0, r21, r5 | 
 | 91 | 	stlo.q r0, -8, r4 | 
 | 92 | 	sthi.q r0, -1, r4 | 
 | 93 | 	mcmpeq.b r5, r63, r6 | 
 | 94 | 	beqi/l r6, 0, tr0 /* loop */ | 
 | 95 |  | 
 | 96 | 	add r5, r63, r4 | 
 | 97 | 	addi r0, 8, r0 | 
 | 98 | 	blink tr1, r63 /* shortstring */ | 
 | 99 |  | 
 | 100 | 	.size	strcpy,.-strcpy | 
 | 101 |  | 
 | 102 | libc_hidden_def(strcpy) |