source: trunk/libs/newlib/src/newlib/libc/machine/sh/strcpy.S @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.5 KB
Line 
1! Entry: arg0: destination
2!        arg1: source
3! Exit:  result: destination
4!
5! SH5 code Copyright 2002 SuperH Ltd.
6
7#include "asm.h"
8
9ENTRY(strcpy)
10
11#if __SHMEDIA__
12
13        pta/l shortstring,tr1
14        ldlo.q r3,0,r4
15        ptabs r18,tr4
16        shlli r3,3,r7
17        addi r2, 8, r0
18        mcmpeq.b r4,r63,r6
19        SHHI r6,r7,r6
20        bnei/u r6,0,tr1 // shortstring
21        pta/l no_lddst, tr2
22        ori r3,-8,r23
23        sub r2, r23, r0
24        sub r3, r2, r21
25        addi r21, 8, r20
26        ldx.q r0, r21, r5
27        pta/l loop, tr0
28        ori r2,-8,r22
29        mcmpeq.b r5, r63, r6
30        bgt/u r22, r23, tr2 // no_lddst
31
32        // r22 < r23 :  Need to do a load from the destination.
33        // r22 == r23 : Doesn't actually need to load from destination,
34        //              but still can be handled here.
35        ldlo.q r2, 0, r9
36        movi -1, r8
37        SHLO r8, r7, r8
38        mcmv r4, r8, r9
39        stlo.q r2, 0, r9
40        beqi/l r6, 0, tr0 // loop
41
42        add r5, r63, r4
43        addi r0, 8, r0
44        blink tr1, r63 // shortstring
45no_lddst:
46        // r22 > r23: note that for r22 == r23 the sthi.q would clobber
47        //            bytes before the destination region.
48        stlo.q r2, 0, r4
49        SHHI r4, r7, r4
50        sthi.q r0, -1, r4
51        beqi/l r6, 0, tr0 // loop
52
53        add r5, r63, r4
54        addi r0, 8, r0
55shortstring:
56#ifndef __LITTLE_ENDIAN__
57        pta/l shortstring2,tr1
58        byterev r4,r4
59#endif
60shortstring2:
61        st.b r0,-8,r4
62        andi r4,0xff,r5
63        shlri r4,8,r4
64        addi r0,1,r0
65        bnei/l r5,0,tr1
66        blink tr4,r63 // return
67       
68        .balign 8
69loop:
70        stlo.q r0, 0, r5
71        ldx.q r0, r20, r4
72        addi r0, 16, r0
73        sthi.q r0, -9, r5
74        mcmpeq.b r4, r63, r6
75        bnei/u r6, 0, tr1 // shortstring
76        ldx.q r0, r21, r5
77        stlo.q r0, -8, r4
78        sthi.q r0, -1, r4
79        mcmpeq.b r5, r63, r6
80        beqi/l r6, 0, tr0 // loop
81
82        add r5, r63, r4
83        addi r0, 8, r0
84        blink tr1, r63 // shortstring
85
86#else /* ! __SHMEDIA__, i.e. SH 1..4 / SHcompact */
87
88#ifdef __SH5__
89#define DST r2
90#define SRC r3
91#define TMP r4
92#define RESULT R2
93!        r0,r1,r3,r4: clobbered
94#else
95#define DST r4
96#define SRC r5
97#define TMP r2
98#define RESULT r0
99!        r1-r2,r5: clobbered
100#endif
101        mov     DST,r0
102        or      SRC,r0
103        tst     #3,r0
104        SL(bf, L_setup_char_loop, mov DST,r0)
105        mov.l   @SRC+,r1
106        mov     #0,TMP
107        cmp/str TMP,r1
108        SL(bt, Longword_loop_end, sub SRC,r0)
109        .align  2
110Longword_loop:
111        mov.l   r1,@(r0,SRC)
112        mov.l   @SRC+,r1
113        cmp/str TMP,r1
114        bt      Longword_loop_end
115        mov.l   r1,@(r0,SRC)
116        mov.l   @SRC+,r1
117        cmp/str TMP,r1
118        bf      Longword_loop
119Longword_loop_end:
120        add     #-4,SRC
121        add     #3,r0
122        .align  2
123L_char_loop:
124        mov.b   @SRC+,r1
125L_char_loop_start:
126        tst     r1,r1
127        SL(bf, L_char_loop, mov.b r1,@(r0,SRC))
128        rts
129        mov DST,RESULT
130L_setup_char_loop:
131        mov.b   @SRC+,r1
132        bra L_char_loop_start
133        sub SRC,r0
134#endif /* ! __SHMEDIA__ */
Note: See TracBrowser for help on using the repository browser.