| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: bzero.S,v 1.10 2011/01/19 02:47:01 matt Exp $ */ | | 1 | /* $NetBSD: bzero.S,v 1.11 2011/01/29 02:21:20 matt Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (C) 2001 Martin J. Laubach <mjl@NetBSD.org> | | 4 | * Copyright (C) 2001 Martin J. Laubach <mjl@NetBSD.org> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | | 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ | | 28 | */ |
29 | /*----------------------------------------------------------------------*/ | | 29 | /*----------------------------------------------------------------------*/ |
30 | | | 30 | |
31 | #include <machine/asm.h> | | 31 | #include <machine/asm.h> |
32 | | | 32 | |
33 | | | 33 | |
34 | #if defined(LIBC_SCCS) && !defined(lint) | | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | __RCSID("$NetBSD: bzero.S,v 1.10 2011/01/19 02:47:01 matt Exp $") | | 35 | __RCSID("$NetBSD: bzero.S,v 1.11 2011/01/29 02:21:20 matt Exp $") |
36 | #endif /* LIBC_SCCS && !lint */ | | 36 | #endif /* LIBC_SCCS && !lint */ |
37 | | | 37 | |
38 | #ifdef _KERNEL | | 38 | #ifdef _KERNEL |
39 | #include <assym.h> | | 39 | #include <assym.h> |
40 | #endif | | 40 | #endif |
41 | | | 41 | |
42 | #define USE_STSWX 0 /* don't. slower than trivial copy loop */ | | 42 | #define USE_STSWX 0 /* don't. slower than trivial copy loop */ |
43 | | | 43 | |
44 | /*----------------------------------------------------------------------*/ | | 44 | /*----------------------------------------------------------------------*/ |
45 | /* | | 45 | /* |
46 | void bzero(void *b %r3, size_t len %r4); | | 46 | void bzero(void *b %r3, size_t len %r4); |
47 | void * memset(void *b %r3, int c %r4, size_t len %r5); | | 47 | void * memset(void *b %r3, int c %r4, size_t len %r5); |
48 | */ | | 48 | */ |
| @@ -50,30 +50,30 @@ __RCSID("$NetBSD: bzero.S,v 1.10 2011/01 | | | @@ -50,30 +50,30 @@ __RCSID("$NetBSD: bzero.S,v 1.10 2011/01 |
50 | | | 50 | |
51 | #define r_dst %r3 | | 51 | #define r_dst %r3 |
52 | #define r_len %r4 | | 52 | #define r_len %r4 |
53 | #define r_val %r0 | | 53 | #define r_val %r0 |
54 | | | 54 | |
55 | .text | | 55 | .text |
56 | .align 4 | | 56 | .align 4 |
57 | ENTRY(bzero) | | 57 | ENTRY(bzero) |
58 | li r_val, 0 /* Value to stuff in */ | | 58 | li r_val, 0 /* Value to stuff in */ |
59 | b cb_memset | | 59 | b cb_memset |
60 | END(bzero) | | 60 | END(bzero) |
61 | | | 61 | |
62 | ENTRY(memset) | | 62 | ENTRY(memset) |
63 | cmplwi cr1, %r5, 0 | | 63 | cmplwi %cr1, %r5, 0 |
64 | mr. %r0, %r4 | | 64 | mr. %r0, %r4 |
65 | mr %r8, %r3 | | 65 | mr %r8, %r3 |
66 | beqlr- cr1 /* Nothing to do */ | | 66 | beqlr- %cr1 /* Nothing to do */ |
67 | | | 67 | |
68 | rlwimi %r0, %r4, 8, 16, 23 /* word extend fill value */ | | 68 | rlwimi %r0, %r4, 8, 16, 23 /* word extend fill value */ |
69 | rlwimi %r0, %r0, 16, 0, 15 | | 69 | rlwimi %r0, %r0, 16, 0, 15 |
70 | mr %r4, %r5 | | 70 | mr %r4, %r5 |
71 | bne- simple_fill /* =! 0, use trivial fill */ | | 71 | bne- simple_fill /* =! 0, use trivial fill */ |
72 | cb_memset: | | 72 | cb_memset: |
73 | | | 73 | |
74 | /*----------------------------------------------------------------------*/ | | 74 | /*----------------------------------------------------------------------*/ |
75 | #ifndef _KERNEL | | 75 | #ifndef _KERNEL |
76 | /* First find out cache line size */ | | 76 | /* First find out cache line size */ |
77 | mflr %r9 | | 77 | mflr %r9 |
78 | #ifdef PIC | | 78 | #ifdef PIC |
79 | PIC_GOTSETUP(%r10) | | 79 | PIC_GOTSETUP(%r10) |
| @@ -157,28 +157,28 @@ cb_memset: | | | @@ -157,28 +157,28 @@ cb_memset: |
157 | li %r8, 0 | | 157 | li %r8, 0 |
158 | bl PIC_PLT(_C_LABEL(sysctl)) | | 158 | bl PIC_PLT(_C_LABEL(sysctl)) |
159 | 1: | | 159 | 1: |
160 | lwz %r3, R3_SAVE(%r1) | | 160 | lwz %r3, R3_SAVE(%r1) |
161 | lwz %r4, R4_SAVE(%r1) | | 161 | lwz %r4, R4_SAVE(%r1) |
162 | lwz %r8, R8_SAVE(%r1) | | 162 | lwz %r8, R8_SAVE(%r1) |
163 | lwz %r0, R0_SAVE(%r1) | | 163 | lwz %r0, R0_SAVE(%r1) |
164 | lwz %r9, 4(%r31) | | 164 | lwz %r9, 4(%r31) |
165 | lwz %r31, R31_SAVE(%r1) | | 165 | lwz %r31, R31_SAVE(%r1) |
166 | #ifdef PIC | | 166 | #ifdef PIC |
167 | lwz %r30, R30_SAVE(%r1) | | 167 | lwz %r30, R30_SAVE(%r1) |
168 | #endif | | 168 | #endif |
169 | addi %r1, %r1, STKFRAME_SZ | | 169 | addi %r1, %r1, STKFRAME_SZ |
170 | lwz %r0, 4(%r1) | | 170 | lwz %r7, 4(%r1) |
171 | mtlr %r0 | | 171 | mtlr %r7 |
172 | | | 172 | |
173 | cntlzw %r6, %r9 /* compute shift value */ | | 173 | cntlzw %r6, %r9 /* compute shift value */ |
174 | li %r5, 31 | | 174 | li %r5, 31 |
175 | subf %r5, %r6, %r5 | | 175 | subf %r5, %r6, %r5 |
176 | | | 176 | |
177 | #ifdef PIC | | 177 | #ifdef PIC |
178 | mflr %r9 | | 178 | mflr %r9 |
179 | PIC_GOTSETUP(%r10) | | 179 | PIC_GOTSETUP(%r10) |
180 | mtlr %r9 | | 180 | mtlr %r9 |
181 | lwz %r6, cache_sh@got(%r10) | | 181 | lwz %r6, cache_sh@got(%r10) |
182 | stw %r5, 0(%r6) | | 182 | stw %r5, 0(%r6) |
183 | #else | | 183 | #else |
184 | lis %r6, cache_sh@ha | | 184 | lis %r6, cache_sh@ha |
| @@ -203,30 +203,30 @@ cb_cacheline_known: | | | @@ -203,30 +203,30 @@ cb_cacheline_known: |
203 | #ifdef MULTIPROCESSOR | | 203 | #ifdef MULTIPROCESSOR |
204 | mfsprg %r10, 0 /* Get cpu_info pointer */ | | 204 | mfsprg %r10, 0 /* Get cpu_info pointer */ |
205 | #else | | 205 | #else |
206 | lis %r10, cpu_info_store@ha | | 206 | lis %r10, cpu_info_store@ha |
207 | addi %r10, %r10, cpu_info_store@l | | 207 | addi %r10, %r10, cpu_info_store@l |
208 | #endif | | 208 | #endif |
209 | lwz %r9, CPU_CI+4(%r10) /* Load D$ line size */ | | 209 | lwz %r9, CPU_CI+4(%r10) /* Load D$ line size */ |
210 | cntlzw %r10, %r9 /* Calculate shift.. */ | | 210 | cntlzw %r10, %r9 /* Calculate shift.. */ |
211 | li %r6, 31 | | 211 | li %r6, 31 |
212 | subf %r10, %r10, %r6 | | 212 | subf %r10, %r10, %r6 |
213 | #endif /* _KERNEL */ | | 213 | #endif /* _KERNEL */ |
214 | /* Back in memory filling business */ | | 214 | /* Back in memory filling business */ |
215 | | | 215 | |
216 | cmplwi cr1, r_len, 0 /* Nothing to do? */ | | 216 | cmplwi %cr1, r_len, 0 /* Nothing to do? */ |
217 | add %r5, %r9, %r9 | | 217 | add %r5, %r9, %r9 |
218 | cmplw r_len, %r5 /* <= 2*CL bytes to move? */ | | 218 | cmplw r_len, %r5 /* <= 2*CL bytes to move? */ |
219 | beqlr- cr1 /* then do nothing */ | | 219 | beqlr- %cr1 /* then do nothing */ |
220 | | | 220 | |
221 | blt+ simple_fill /* a trivial fill routine */ | | 221 | blt+ simple_fill /* a trivial fill routine */ |
222 | | | 222 | |
223 | /* Word align the block, fill bytewise until dst even*/ | | 223 | /* Word align the block, fill bytewise until dst even*/ |
224 | | | 224 | |
225 | andi. %r5, r_dst, 0x03 | | 225 | andi. %r5, r_dst, 0x03 |
226 | li %r6, 4 | | 226 | li %r6, 4 |
227 | beq+ cb_aligned_w /* already aligned to word? */ | | 227 | beq+ cb_aligned_w /* already aligned to word? */ |
228 | | | 228 | |
229 | subf %r5, %r5, %r6 /* bytes to fill to align4 */ | | 229 | subf %r5, %r5, %r6 /* bytes to fill to align4 */ |
230 | #if USE_STSWX | | 230 | #if USE_STSWX |
231 | mtxer %r5 | | 231 | mtxer %r5 |
232 | stswx %r0, 0, r_dst | | 232 | stswx %r0, 0, r_dst |
| @@ -267,47 +267,47 @@ cb_aligned_cb: /* no need to check r_len | | | @@ -267,47 +267,47 @@ cb_aligned_cb: /* no need to check r_len |
267 | | | 267 | |
268 | srw. %r5, r_len, %r10 /* Number of cache blocks */ | | 268 | srw. %r5, r_len, %r10 /* Number of cache blocks */ |
269 | mtctr %r5 | | 269 | mtctr %r5 |
270 | beq cblocks_done | | 270 | beq cblocks_done |
271 | | | 271 | |
272 | slw %r5, %r5, %r10 | | 272 | slw %r5, %r5, %r10 |
273 | subf r_len, %r5, r_len | | 273 | subf r_len, %r5, r_len |
274 | | | 274 | |
275 | 1: dcbz 0, r_dst /* Clear blockwise */ | | 275 | 1: dcbz 0, r_dst /* Clear blockwise */ |
276 | add r_dst, r_dst, %r9 | | 276 | add r_dst, r_dst, %r9 |
277 | bdnz 1b | | 277 | bdnz 1b |
278 | | | 278 | |
279 | cblocks_done: /* still CL aligned, but less than CL bytes left */ | | 279 | cblocks_done: /* still CL aligned, but less than CL bytes left */ |
280 | cmplwi cr1, r_len, 0 | | 280 | cmplwi %cr1, r_len, 0 |
281 | cmplwi r_len, 8 | | 281 | cmplwi r_len, 8 |
282 | beq- cr1, sf_return | | 282 | beq- %cr1, sf_return |
283 | | | 283 | |
284 | blt- sf_bytewise /* <8 remaining? */ | | 284 | blt- sf_bytewise /* <8 remaining? */ |
285 | b sf_aligned_w | | 285 | b sf_aligned_w |
286 | | | 286 | |
287 | /*----------------------------------------------------------------------*/ | | 287 | /*----------------------------------------------------------------------*/ |
288 | wbzero: li r_val, 0 | | 288 | wbzero: li r_val, 0 |
289 | | | 289 | |
290 | cmplwi r_len, 0 | | 290 | cmplwi r_len, 0 |
291 | beqlr- /* Nothing to do */ | | 291 | beqlr- /* Nothing to do */ |
292 | | | 292 | |
293 | simple_fill: | | 293 | simple_fill: |
294 | #if USE_STSWX | | 294 | #if USE_STSWX |
295 | cmplwi cr1, r_len, 12 /* < 12 bytes to move? */ | | 295 | cmplwi %cr1, r_len, 12 /* < 12 bytes to move? */ |
296 | #else | | 296 | #else |
297 | cmplwi cr1, r_len, 8 /* < 8 bytes to move? */ | | 297 | cmplwi %cr1, r_len, 8 /* < 8 bytes to move? */ |
298 | #endif | | 298 | #endif |
299 | andi. %r5, r_dst, 0x03 /* bytes to fill to align4 */ | | 299 | andi. %r5, r_dst, 0x03 /* bytes to fill to align4 */ |
300 | blt cr1, sf_bytewise /* trivial byte mover */ | | 300 | blt %cr1, sf_bytewise /* trivial byte mover */ |
301 | | | 301 | |
302 | li %r6, 4 | | 302 | li %r6, 4 |
303 | subf %r5, %r5, %r6 | | 303 | subf %r5, %r5, %r6 |
304 | beq+ sf_aligned_w /* dest is word aligned */ | | 304 | beq+ sf_aligned_w /* dest is word aligned */ |
305 | | | 305 | |
306 | #if USE_STSWX | | 306 | #if USE_STSWX |
307 | mtxer %r5 | | 307 | mtxer %r5 |
308 | stswx %r0, 0, r_dst | | 308 | stswx %r0, 0, r_dst |
309 | add r_dst, %r5, r_dst | | 309 | add r_dst, %r5, r_dst |
310 | #else | | 310 | #else |
311 | mtctr %r5 /* nope, then fill bytewise */ | | 311 | mtctr %r5 /* nope, then fill bytewise */ |
312 | subi r_dst, r_dst, 1 /* until it is */ | | 312 | subi r_dst, r_dst, 1 /* until it is */ |
313 | 1: stbu r_val, 1(r_dst) | | 313 | 1: stbu r_val, 1(r_dst) |