2002-03-06 18:43:18 +08:00
|
|
|
! Entry: arg0: destination
|
|
|
|
! arg1: source
|
|
|
|
! Exit: result: destination
|
|
|
|
!
|
|
|
|
! SH5 code Copyright 2002 SuperH Ltd.
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
#include "asm.h"
|
|
|
|
|
|
|
|
ENTRY(strcpy)
|
2002-03-06 18:43:18 +08:00
|
|
|
|
|
|
|
#if __SHMEDIA__
|
|
|
|
|
|
|
|
pta/l shortstring,tr1
|
|
|
|
ldlo.q r3,0,r4
|
|
|
|
ptabs r18,tr4
|
|
|
|
shlli r3,3,r7
|
2002-05-17 01:29:15 +08:00
|
|
|
addi r2, 8, r0
|
2002-03-06 18:43:18 +08:00
|
|
|
mcmpeq.b r4,r63,r6
|
|
|
|
SHHI r6,r7,r6
|
|
|
|
bnei/u r6,0,tr1 // shortstring
|
|
|
|
pta/l no_lddst, tr2
|
|
|
|
ori r3,-8,r23
|
|
|
|
sub r2, r23, r0
|
|
|
|
sub r3, r2, r21
|
|
|
|
addi r21, 8, r20
|
|
|
|
ldx.q r0, r21, r5
|
|
|
|
pta/l loop, tr0
|
|
|
|
ori r2,-8,r22
|
|
|
|
mcmpeq.b r5, r63, r6
|
2002-06-14 02:25:19 +08:00
|
|
|
bgt/u r22, r23, tr2 // no_lddst
|
2002-03-06 18:43:18 +08:00
|
|
|
|
2002-06-14 02:25:19 +08:00
|
|
|
// r22 < r23 : Need to do a load from the destination.
|
|
|
|
// r22 == r23 : Doesn't actually need to load from destination,
|
|
|
|
// but still can be handled here.
|
2002-03-06 18:43:18 +08:00
|
|
|
ldlo.q r2, 0, r9
|
|
|
|
movi -1, r8
|
|
|
|
SHLO r8, r7, r8
|
|
|
|
mcmv r4, r8, r9
|
|
|
|
stlo.q r2, 0, r9
|
|
|
|
beqi/l r6, 0, tr0 // loop
|
|
|
|
|
|
|
|
add r5, r63, r4
|
2002-05-17 01:29:15 +08:00
|
|
|
addi r0, 8, r0
|
2002-03-06 18:43:18 +08:00
|
|
|
blink tr1, r63 // shortstring
|
|
|
|
no_lddst:
|
2002-06-14 02:25:19 +08:00
|
|
|
// r22 > r23: note that for r22 == r23 the sthi.q would clobber
|
|
|
|
// bytes before the destination region.
|
2002-03-06 18:43:18 +08:00
|
|
|
stlo.q r2, 0, r4
|
|
|
|
SHHI r4, r7, r4
|
|
|
|
sthi.q r0, -1, r4
|
|
|
|
beqi/l r6, 0, tr0 // loop
|
|
|
|
|
|
|
|
add r5, r63, r4
|
2002-05-17 01:29:15 +08:00
|
|
|
addi r0, 8, r0
|
2002-03-06 18:43:18 +08:00
|
|
|
shortstring:
|
2002-05-17 00:16:14 +08:00
|
|
|
#ifndef __LITTLE_ENDIAN__
|
2002-03-06 18:43:18 +08:00
|
|
|
pta/l shortstring2,tr1
|
|
|
|
byterev r4,r4
|
|
|
|
#endif
|
|
|
|
shortstring2:
|
2002-05-17 01:29:15 +08:00
|
|
|
st.b r0,-8,r4
|
2002-03-06 18:43:18 +08:00
|
|
|
andi r4,0xff,r5
|
|
|
|
shlri r4,8,r4
|
|
|
|
addi r0,1,r0
|
|
|
|
bnei/l r5,0,tr1
|
|
|
|
blink tr4,r63 // return
|
|
|
|
|
|
|
|
.balign 8
|
|
|
|
loop:
|
|
|
|
stlo.q r0, 0, r5
|
|
|
|
ldx.q r0, r20, r4
|
|
|
|
addi r0, 16, r0
|
|
|
|
sthi.q r0, -9, r5
|
|
|
|
mcmpeq.b r4, r63, r6
|
|
|
|
bnei/u r6, 0, tr1 // shortstring
|
|
|
|
ldx.q r0, r21, r5
|
|
|
|
stlo.q r0, -8, r4
|
|
|
|
sthi.q r0, -1, r4
|
|
|
|
mcmpeq.b r5, r63, r6
|
|
|
|
beqi/l r6, 0, tr0 // loop
|
|
|
|
|
|
|
|
add r5, r63, r4
|
2002-05-17 01:29:15 +08:00
|
|
|
addi r0, 8, r0
|
2002-03-06 18:43:18 +08:00
|
|
|
blink tr1, r63 // shortstring
|
|
|
|
|
|
|
|
#else /* ! __SHMEDIA__, i.e. SH 1..4 / SHcompact */
|
|
|
|
|
|
|
|
#ifdef __SH5__
|
|
|
|
#define DST r2
|
|
|
|
#define SRC r3
|
|
|
|
#define TMP r4
|
|
|
|
#define RESULT R2
|
|
|
|
! r0,r1,r3,r4: clobbered
|
|
|
|
#else
|
|
|
|
#define DST r4
|
|
|
|
#define SRC r5
|
|
|
|
#define TMP r2
|
|
|
|
#define RESULT r0
|
|
|
|
! r1-r2,r5: clobbered
|
|
|
|
#endif
|
|
|
|
mov DST,r0
|
|
|
|
or SRC,r0
|
2000-02-18 03:39:52 +08:00
|
|
|
tst #3,r0
|
2002-03-06 18:43:18 +08:00
|
|
|
SL(bf, L_setup_char_loop, mov DST,r0)
|
|
|
|
mov.l @SRC+,r1
|
|
|
|
mov #0,TMP
|
|
|
|
cmp/str TMP,r1
|
|
|
|
SL(bt, Longword_loop_end, sub SRC,r0)
|
2000-02-18 03:39:52 +08:00
|
|
|
.align 2
|
|
|
|
Longword_loop:
|
2002-03-06 18:43:18 +08:00
|
|
|
mov.l r1,@(r0,SRC)
|
|
|
|
mov.l @SRC+,r1
|
|
|
|
cmp/str TMP,r1
|
2000-02-18 03:39:52 +08:00
|
|
|
bt Longword_loop_end
|
2002-03-06 18:43:18 +08:00
|
|
|
mov.l r1,@(r0,SRC)
|
|
|
|
mov.l @SRC+,r1
|
|
|
|
cmp/str TMP,r1
|
2000-02-18 03:39:52 +08:00
|
|
|
bf Longword_loop
|
|
|
|
Longword_loop_end:
|
2002-03-06 18:43:18 +08:00
|
|
|
add #-4,SRC
|
2000-02-18 03:39:52 +08:00
|
|
|
add #3,r0
|
|
|
|
.align 2
|
|
|
|
L_char_loop:
|
2002-03-06 18:43:18 +08:00
|
|
|
mov.b @SRC+,r1
|
2000-02-18 03:39:52 +08:00
|
|
|
L_char_loop_start:
|
|
|
|
tst r1,r1
|
2002-03-06 18:43:18 +08:00
|
|
|
SL(bf, L_char_loop, mov.b r1,@(r0,SRC))
|
2000-02-18 03:39:52 +08:00
|
|
|
rts
|
2002-03-06 18:43:18 +08:00
|
|
|
mov DST,RESULT
|
2000-02-18 03:39:52 +08:00
|
|
|
L_setup_char_loop:
|
2002-03-06 18:43:18 +08:00
|
|
|
mov.b @SRC+,r1
|
2000-02-18 03:39:52 +08:00
|
|
|
bra L_char_loop_start
|
2002-03-06 18:43:18 +08:00
|
|
|
sub SRC,r0
|
|
|
|
#endif /* ! __SHMEDIA__ */
|