aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/boot/string.S
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/boot/string.S')
-rw-r--r--arch/powerpc/boot/string.S216
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
16strcpy:
17 addi r5,r3,-1
18 addi r4,r4,-1
191: lbzu r0,1(r4)
20 cmpwi 0,r0,0
21 stbu r0,1(r5)
22 bne 1b
23 blr
24
25 .globl strncpy
26strncpy:
27 cmpwi 0,r5,0
28 beqlr
29 mtctr r5
30 addi r6,r3,-1
31 addi r4,r4,-1
321: 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
39strcat:
40 addi r5,r3,-1
41 addi r4,r4,-1
421: lbzu r0,1(r5)
43 cmpwi 0,r0,0
44 bne 1b
45 addi r5,r5,-1
461: lbzu r0,1(r4)
47 cmpwi 0,r0,0
48 stbu r0,1(r5)
49 bne 1b
50 blr
51
52 .globl strcmp
53strcmp:
54 addi r5,r3,-1
55 addi r4,r4,-1
561: 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
65strlen:
66 addi r4,r3,-1
671: lbzu r0,1(r4)
68 cmpwi 0,r0,0
69 bne 1b
70 subf r3,r3,r4
71 blr
72
73 .globl memset
74memset:
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
881: stwu r4,4(r6)
89 bdnz 1b
906: andi. r5,r5,3
917: cmpwi 0,r5,0
92 beqlr
93 mtctr r5
94 addi r6,r6,3
958: stbu r4,1(r6)
96 bdnz 8b
97 blr
98
99 .globl memmove
100memmove:
101 cmplw 0,r3,r4
102 bgt backwards_memcpy
103 /* fall through */
104
105 .globl memcpy
106memcpy:
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
1141: 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
1202: cmplwi 0,r5,4
121 blt 3f
122 lwzu r0,4(r4)
123 addi r5,r5,-4
124 stwu r0,4(r6)
1253: cmpwi 0,r5,0
126 beqlr
127 mtctr r5
128 addi r4,r4,3
129 addi r6,r6,3
1304: lbzu r0,1(r4)
131 stbu r0,1(r6)
132 bdnz 4b
133 blr
1345: subfic r0,r0,4
135 mtctr r0
1366: 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
148backwards_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
1561: 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
1622: cmplwi 0,r5,4
163 blt 3f
164 lwzu r0,-4(r4)
165 subi r5,r5,4
166 stwu r0,-4(r6)
1673: cmpwi 0,r5,0
168 beqlr
169 mtctr r5
1704: lbzu r0,-1(r4)
171 stbu r0,-1(r6)
172 bdnz 4b
173 blr
1745: mtctr r0
1756: 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
185memcmp:
186 cmpwi 0,r5,0
187 blelr
188 mtctr r5
189 addi r6,r3,-1
190 addi r4,r4,-1
1911: 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
204flush_cache:
205 addi 4,4,0x1f /* len = (len + 0x1f) / 0x20 */
206 rlwinm. 4,4,27,5,31
207 mtctr 4
208 beqlr
2091: dcbf 0,3
210 icbi 0,3
211 addi 3,3,0x20
212 bdnz 1b
213 sync
214 isync
215 blr
216