]>
Commit | Line | Data |
---|---|---|
55e303ae A |
1 | /* |
2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
ff6e181a A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
55e303ae | 12 | * |
ff6e181a A |
13 | * The Original Code and all software distributed under the License are |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
55e303ae A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
ff6e181a A |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
55e303ae A |
20 | * |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | #define ASSEMBLER | |
25 | #include <sys/appleapiopts.h> | |
26 | #include <ppc/asm.h> | |
27 | #include <machine/cpu_capabilities.h> | |
28 | #include <machine/commpage.h> | |
29 | ||
30 | .text | |
31 | .align 2 | |
91447636 A |
32 | /* |
33 | * WARNING: this code is written for 32-bit mode, and ported by the kernel if necessary | |
34 | * to 64-bit mode for use in the 64-bit commpage. This "port" consists of the following | |
35 | * simple transformations: | |
36 | * - all word compares are changed to doubleword | |
37 | * - all "srwi[.]" opcodes are changed to "srdi[.]" | |
38 | * Nothing else is done. For this to work, the following rules must be | |
39 | * carefully followed: | |
40 | * - do not use carry or overflow | |
41 | * - only use record mode if you are sure the results are mode-invariant | |
42 | * for example, all "andi." and almost all "rlwinm." are fine | |
43 | * - do not use "slwi", "slw", or "srw" | |
44 | * An imaginative programmer could break the porting model in other ways, but the above | |
45 | * are the most likely problem areas. It is perhaps surprising how well in practice | |
46 | * this simple method works. | |
47 | */ | |
55e303ae | 48 | |
91447636 A |
49 | // ********************** |
50 | // * B Z E R O _ 1 2 8 * | |
51 | // ********************** | |
55e303ae A |
52 | // |
53 | // For 64-bit processors with a 128-byte cache line. | |
54 | // | |
55 | // Register use: | |
56 | // r0 = zero | |
57 | // r3 = original ptr, not changed since memset returns it | |
58 | // r4 = count of bytes to set | |
59 | // r9 = working operand ptr | |
91447636 | 60 | // WARNING: We do not touch r2 and r10-r12, which some callers depend on. |
55e303ae A |
61 | |
62 | .align 5 | |
63 | bzero_128: // void bzero(void *b, size_t len); | |
64 | cmplwi cr7,r4,128 // too short for DCBZ128? | |
65 | li r0,0 // get a 0 | |
66 | neg r5,r3 // start to compute #bytes to align | |
67 | mr r9,r3 // make copy of operand ptr (can't change r3) | |
68 | blt cr7,Ltail // length < 128, too short for DCBZ | |
69 | ||
70 | // At least 128 bytes long, so compute alignment and #cache blocks. | |
71 | ||
72 | andi. r5,r5,0x7F // r5 <- #bytes to 128-byte align | |
73 | sub r4,r4,r5 // adjust length | |
74 | srwi r8,r4,7 // r8 <- 128-byte chunks | |
75 | rlwinm r4,r4,0,0x7F // mask length down to remaining bytes | |
76 | mtctr r8 // set up loop count | |
77 | beq Ldcbz // skip if already aligned (r8!=0) | |
78 | ||
79 | // 128-byte align | |
80 | ||
81 | mtcrf 0x01,r5 // start to move #bytes to align to cr6 and cr7 | |
82 | cmpwi cr1,r8,0 // any 128-byte cache lines to 0? | |
83 | mtcrf 0x02,r5 | |
84 | ||
85 | bf 31,1f // byte? | |
86 | stb r0,0(r9) | |
87 | addi r9,r9,1 | |
88 | 1: | |
89 | bf 30,2f // halfword? | |
90 | sth r0,0(r9) | |
91 | addi r9,r9,2 | |
92 | 2: | |
93 | bf 29,3f // word? | |
94 | stw r0,0(r9) | |
95 | addi r9,r9,4 | |
96 | 3: | |
97 | bf 28,4f // doubleword? | |
98 | std r0,0(r9) | |
99 | addi r9,r9,8 | |
100 | 4: | |
101 | bf 27,5f // quadword? | |
102 | std r0,0(r9) | |
103 | std r0,8(r9) | |
104 | addi r9,r9,16 | |
105 | 5: | |
106 | bf 26,6f // 32-byte chunk? | |
107 | std r0,0(r9) | |
108 | std r0,8(r9) | |
109 | std r0,16(r9) | |
110 | std r0,24(r9) | |
111 | addi r9,r9,32 | |
112 | 6: | |
113 | bf 25,7f // 64-byte chunk? | |
114 | std r0,0(r9) | |
115 | std r0,8(r9) | |
116 | std r0,16(r9) | |
117 | std r0,24(r9) | |
118 | std r0,32(r9) | |
119 | std r0,40(r9) | |
120 | std r0,48(r9) | |
121 | std r0,56(r9) | |
122 | addi r9,r9,64 | |
123 | 7: | |
124 | beq cr1,Ltail // no chunks to dcbz128 | |
125 | ||
126 | // Loop doing 128-byte version of DCBZ instruction. | |
127 | // NB: if the memory is cache-inhibited, the kernel will clear cr7 | |
128 | // when it emulates the alignment exception. Eventually, we may want | |
129 | // to check for this case. | |
130 | ||
131 | Ldcbz: | |
132 | dcbz128 0,r9 // zero another 32 bytes | |
133 | addi r9,r9,128 | |
134 | bdnz Ldcbz | |
135 | ||
136 | // Store trailing bytes. | |
137 | // r0 = 0 | |
138 | // r4 = count | |
139 | // r9 = ptr | |
140 | ||
141 | Ltail: | |
142 | srwi. r5,r4,4 // r5 <- 16-byte chunks to 0 | |
143 | mtcrf 0x01,r4 // remaining byte count to cr7 | |
144 | mtctr r5 | |
145 | beq 2f // skip if no 16-byte chunks | |
146 | 1: // loop over 16-byte chunks | |
147 | std r0,0(r9) | |
148 | std r0,8(r9) | |
149 | addi r9,r9,16 | |
150 | bdnz 1b | |
151 | 2: | |
152 | bf 28,4f // 8-byte chunk? | |
153 | std r0,0(r9) | |
154 | addi r9,r9,8 | |
155 | 4: | |
156 | bf 29,5f // word? | |
157 | stw r0,0(r9) | |
158 | addi r9,r9,4 | |
159 | 5: | |
160 | bf 30,6f // halfword? | |
161 | sth r0,0(r9) | |
162 | addi r9,r9,2 | |
163 | 6: | |
164 | bflr 31 // byte? | |
165 | stb r0,0(r9) | |
166 | blr | |
167 | ||
91447636 A |
168 | COMMPAGE_DESCRIPTOR(bzero_128,_COMM_PAGE_BZERO,kCache128+k64Bit,0, \ |
169 | kCommPageMTCRF+kCommPageBoth+kPort32to64) |