1 | /* |
---|
2 | Copyright (c) 2013 Andes Technology Corporation. |
---|
3 | All rights reserved. |
---|
4 | |
---|
5 | Redistribution and use in source and binary forms, with or without |
---|
6 | modification, are permitted provided that the following conditions are met: |
---|
7 | |
---|
8 | Redistributions of source code must retain the above copyright |
---|
9 | notice, this list of conditions and the following disclaimer. |
---|
10 | |
---|
11 | Redistributions in binary form must reproduce the above copyright |
---|
12 | notice, this list of conditions and the following disclaimer in the |
---|
13 | documentation and/or other materials provided with the distribution. |
---|
14 | |
---|
15 | The name of the company may not be used to endorse or promote |
---|
16 | products derived from this software without specific prior written |
---|
17 | permission. |
---|
18 | |
---|
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
22 | DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY |
---|
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
29 | |
---|
30 | |
---|
31 | Function: |
---|
32 | strcpy - copy a string. |
---|
33 | Syntax: |
---|
34 | char *strcpy(char *dest, const char *src); |
---|
35 | Description: |
---|
36 | This function copies the string pointed to by src into the array |
---|
37 | point to by dest (include the teminating null character). |
---|
38 | Return value: |
---|
39 | strcpy returns the dest as given. |
---|
40 | */ |
---|
41 | .text |
---|
42 | .align 2 |
---|
43 | .globl strcpy |
---|
44 | .type strcpy, @function |
---|
45 | strcpy: |
---|
46 | move $r3, $r0 /* Keep r0 as reture value. */ |
---|
47 | /* If SRC or DEST is unaligned, then copy bytes. */ |
---|
48 | or $r2, $r1, $r0 |
---|
49 | andi $r2, $r2, #3 |
---|
50 | bnez $r2, .Lbyte_mode |
---|
51 | |
---|
52 | .Lword_mode: |
---|
53 | /* SRC and DEST are both "long int" aligned, try to do "long int" |
---|
54 | sized copies. */ |
---|
55 | /* #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) |
---|
56 | DETECTNULL returns nonzero if (long)X contains a NULL byte. */ |
---|
57 | lwi $r2, [$r1+(0)] /* r2 is X */ |
---|
58 | sethi $r4, hi20(0xFEFEFEFF) |
---|
59 | ori $r4, $r4, lo12(0xFEFEFEFF) |
---|
60 | add $r4, $r2, $r4 /* r4 = ((X) - 0x01010101) */ |
---|
61 | nor $r5, $r2, $r2 /* r5 = ~(X) */ |
---|
62 | and $r4, $r5, $r4 /* r4 = ~(X) & ((X) - 0x01010101) */ |
---|
63 | sethi $r5, hi20(0x80808080) |
---|
64 | ori $r5, $r5, lo12(0x80808080) |
---|
65 | and $r4, $r4, $r5 /* r4 = r4 & 0x80808080 */ |
---|
66 | bnez $r4, .Lbyte_mode /* Contains a NULL byte. */ |
---|
67 | swi.bi $r2, [$r3], #4 |
---|
68 | addi $r1, $r1, #4 |
---|
69 | b .Lword_mode |
---|
70 | |
---|
71 | .Lbyte_mode: |
---|
72 | lbi.bi $r4, [$r1], #1 /* r4 <- *src++ */ |
---|
73 | sbi.bi $r4, [$r3], #1 /* r4 -> *dest++ */ |
---|
74 | bnez $r4, .Lbyte_mode |
---|
75 | ret |
---|
76 | .size strcpy, .-strcpy |
---|