diff options
author | Jeff Garzik <jgarzik@pobox.com> | 2005-11-18 11:44:17 -0500 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-11-18 11:44:17 -0500 |
commit | f333b3f111e9db76109e304df8ee777ace7fbf86 (patch) | |
tree | ce9a74a7327020c48c80d278e1db5f12552f0fb0 /arch/powerpc/boot/string.S | |
parent | f4256e301d9800b1e0276404cb01b3ac85b51067 (diff) | |
parent | 79bfb0a98fdc73ed6a18469cef245cbf50a1d8bb (diff) |
Merge branch 'upstream'
Diffstat (limited to 'arch/powerpc/boot/string.S')
-rw-r--r-- | arch/powerpc/boot/string.S | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/arch/powerpc/boot/string.S b/arch/powerpc/boot/string.S new file mode 100644 index 000000000000..b1eeaed7db17 --- /dev/null +++ b/arch/powerpc/boot/string.S | |||
@@ -0,0 +1,216 @@ | |||
1 | /* | ||
2 | * Copyright (C) Paul Mackerras 1997. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * NOTE: this code runs in 32 bit mode and is packaged as ELF32. | ||
10 | */ | ||
11 | |||
12 | #include "ppc_asm.h" | ||
13 | |||
14 | .text | ||
15 | .globl strcpy | ||
16 | strcpy: | ||
17 | addi r5,r3,-1 | ||
18 | addi r4,r4,-1 | ||
19 | 1: lbzu r0,1(r4) | ||
20 | cmpwi 0,r0,0 | ||
21 | stbu r0,1(r5) | ||
22 | bne 1b | ||
23 | blr | ||
24 | |||
25 | .globl strncpy | ||
26 | strncpy: | ||
27 | cmpwi 0,r5,0 | ||
28 | beqlr | ||
29 | mtctr r5 | ||
30 | addi r6,r3,-1 | ||
31 | addi r4,r4,-1 | ||
32 | 1: lbzu r0,1(r4) | ||
33 | cmpwi 0,r0,0 | ||
34 | stbu r0,1(r6) | ||
35 | bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */ | ||
36 | blr | ||
37 | |||
38 | .globl strcat | ||
39 | strcat: | ||
40 | addi r5,r3,-1 | ||
41 | addi r4,r4,-1 | ||
42 | 1: lbzu r0,1(r5) | ||
43 | cmpwi 0,r0,0 | ||
44 | bne 1b | ||
45 | addi r5,r5,-1 | ||
46 | 1: lbzu r0,1(r4) | ||
47 | cmpwi 0,r0,0 | ||
48 | stbu r0,1(r5) | ||
49 | bne 1b | ||
50 | blr | ||
51 | |||
52 | .globl strcmp | ||
53 | strcmp: | ||
54 | addi r5,r3,-1 | ||
55 | addi r4,r4,-1 | ||
56 | 1: lbzu r3,1(r5) | ||
57 | cmpwi 1,r3,0 | ||
58 | lbzu r0,1(r4) | ||
59 | subf. r3,r0,r3 | ||
60 | beqlr 1 | ||
61 | beq 1b | ||
62 | blr | ||
63 | |||
64 | .globl strlen | ||
65 | strlen: | ||
66 | addi r4,r3,-1 | ||
67 | 1: lbzu r0,1(r4) | ||
68 | cmpwi 0,r0,0 | ||
69 | bne 1b | ||
70 | subf r3,r3,r4 | ||
71 | blr | ||
72 | |||
73 | .globl memset | ||
74 | memset: | ||
75 | rlwimi r4,r4,8,16,23 | ||
76 | rlwimi r4,r4,16,0,15 | ||
77 | addi r6,r3,-4 | ||
78 | cmplwi 0,r5,4 | ||
79 | blt 7f | ||
80 | stwu r4,4(r6) | ||
81 | beqlr | ||
82 | andi. r0,r6,3 | ||
83 | add r5,r0,r5 | ||
84 | subf r6,r0,r6 | ||
85 | rlwinm r0,r5,32-2,2,31 | ||
86 | mtctr r0 | ||
87 | bdz 6f | ||
88 | 1: stwu r4,4(r6) | ||
89 | bdnz 1b | ||
90 | 6: andi. r5,r5,3 | ||
91 | 7: cmpwi 0,r5,0 | ||
92 | beqlr | ||
93 | mtctr r5 | ||
94 | addi r6,r6,3 | ||
95 | 8: stbu r4,1(r6) | ||
96 | bdnz 8b | ||
97 | blr | ||
98 | |||
99 | .globl memmove | ||
100 | memmove: | ||
101 | cmplw 0,r3,r4 | ||
102 | bgt backwards_memcpy | ||
103 | /* fall through */ | ||
104 | |||
105 | .globl memcpy | ||
106 | memcpy: | ||
107 | rlwinm. r7,r5,32-3,3,31 /* r7 = r5 >> 3 */ | ||
108 | addi r6,r3,-4 | ||
109 | addi r4,r4,-4 | ||
110 | beq 2f /* if less than 8 bytes to do */ | ||
111 | andi. r0,r6,3 /* get dest word aligned */ | ||
112 | mtctr r7 | ||
113 | bne 5f | ||
114 | 1: lwz r7,4(r4) | ||
115 | lwzu r8,8(r4) | ||
116 | stw r7,4(r6) | ||
117 | stwu r8,8(r6) | ||
118 | bdnz 1b | ||
119 | andi. r5,r5,7 | ||
120 | 2: cmplwi 0,r5,4 | ||
121 | blt 3f | ||
122 | lwzu r0,4(r4) | ||
123 | addi r5,r5,-4 | ||
124 | stwu r0,4(r6) | ||
125 | 3: cmpwi 0,r5,0 | ||
126 | beqlr | ||
127 | mtctr r5 | ||
128 | addi r4,r4,3 | ||
129 | addi r6,r6,3 | ||
130 | 4: lbzu r0,1(r4) | ||
131 | stbu r0,1(r6) | ||
132 | bdnz 4b | ||
133 | blr | ||
134 | 5: subfic r0,r0,4 | ||
135 | mtctr r0 | ||
136 | 6: lbz r7,4(r4) | ||
137 | addi r4,r4,1 | ||
138 | stb r7,4(r6) | ||
139 | addi r6,r6,1 | ||
140 | bdnz 6b | ||
141 | subf r5,r0,r5 | ||
142 | rlwinm. r7,r5,32-3,3,31 | ||
143 | beq 2b | ||
144 | mtctr r7 | ||
145 | b 1b | ||
146 | |||
147 | .globl backwards_memcpy | ||
148 | backwards_memcpy: | ||
149 | rlwinm. r7,r5,32-3,3,31 /* r7 = r5 >> 3 */ | ||
150 | add r6,r3,r5 | ||
151 | add r4,r4,r5 | ||
152 | beq 2f | ||
153 | andi. r0,r6,3 | ||
154 | mtctr r7 | ||
155 | bne 5f | ||
156 | 1: lwz r7,-4(r4) | ||
157 | lwzu r8,-8(r4) | ||
158 | stw r7,-4(r6) | ||
159 | stwu r8,-8(r6) | ||
160 | bdnz 1b | ||
161 | andi. r5,r5,7 | ||
162 | 2: cmplwi 0,r5,4 | ||
163 | blt 3f | ||
164 | lwzu r0,-4(r4) | ||
165 | subi r5,r5,4 | ||
166 | stwu r0,-4(r6) | ||
167 | 3: cmpwi 0,r5,0 | ||
168 | beqlr | ||
169 | mtctr r5 | ||
170 | 4: lbzu r0,-1(r4) | ||
171 | stbu r0,-1(r6) | ||
172 | bdnz 4b | ||
173 | blr | ||
174 | 5: mtctr r0 | ||
175 | 6: lbzu r7,-1(r4) | ||
176 | stbu r7,-1(r6) | ||
177 | bdnz 6b | ||
178 | subf r5,r0,r5 | ||
179 | rlwinm. r7,r5,32-3,3,31 | ||
180 | beq 2b | ||
181 | mtctr r7 | ||
182 | b 1b | ||
183 | |||
184 | .globl memcmp | ||
185 | memcmp: | ||
186 | cmpwi 0,r5,0 | ||
187 | blelr | ||
188 | mtctr r5 | ||
189 | addi r6,r3,-1 | ||
190 | addi r4,r4,-1 | ||
191 | 1: lbzu r3,1(r6) | ||
192 | lbzu r0,1(r4) | ||
193 | subf. r3,r0,r3 | ||
194 | bdnzt 2,1b | ||
195 | blr | ||
196 | |||
197 | |||
198 | /* | ||
199 | * Flush the dcache and invalidate the icache for a range of addresses. | ||
200 | * | ||
201 | * flush_cache(addr, len) | ||
202 | */ | ||
203 | .global flush_cache | ||
204 | flush_cache: | ||
205 | addi 4,4,0x1f /* len = (len + 0x1f) / 0x20 */ | ||
206 | rlwinm. 4,4,27,5,31 | ||
207 | mtctr 4 | ||
208 | beqlr | ||
209 | 1: dcbf 0,3 | ||
210 | icbi 0,3 | ||
211 | addi 3,3,0x20 | ||
212 | bdnz 1b | ||
213 | sync | ||
214 | isync | ||
215 | blr | ||
216 | |||