Rev 1214 | Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1214 | Rev 1216 | ||
---|---|---|---|
1 | # |
1 | # |
2 | # Copyright (C) 2006 Martin Decky |
2 | # Copyright (C) 2006 Martin Decky |
3 | # All rights reserved. |
3 | # All rights reserved. |
4 | # |
4 | # |
5 | # Redistribution and use in source and binary forms, with or without |
5 | # Redistribution and use in source and binary forms, with or without |
6 | # modification, are permitted provided that the following conditions |
6 | # modification, are permitted provided that the following conditions |
7 | # are met: |
7 | # are met: |
8 | # |
8 | # |
9 | # - Redistributions of source code must retain the above copyright |
9 | # - Redistributions of source code must retain the above copyright |
10 | # notice, this list of conditions and the following disclaimer. |
10 | # notice, this list of conditions and the following disclaimer. |
11 | # - Redistributions in binary form must reproduce the above copyright |
11 | # - Redistributions in binary form must reproduce the above copyright |
12 | # notice, this list of conditions and the following disclaimer in the |
12 | # notice, this list of conditions and the following disclaimer in the |
13 | # documentation and/or other materials provided with the distribution. |
13 | # documentation and/or other materials provided with the distribution. |
14 | # - The name of the author may not be used to endorse or promote products |
14 | # - The name of the author may not be used to endorse or promote products |
15 | # derived from this software without specific prior written permission. |
15 | # derived from this software without specific prior written permission. |
16 | # |
16 | # |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | # |
27 | # |
28 | 28 | ||
29 | #include "asm.h" |
29 | #include "asm.h" |
30 | #include "regname.h" |
30 | #include "regname.h" |
31 | 31 | ||
32 | .text |
32 | .text |
33 | 33 | ||
34 | .global halt |
34 | .global halt |
35 | .global memcpy |
35 | .global memcpy |
36 | .global jump_to_kernel |
36 | .global jump_to_kernel |
37 | 37 | ||
38 | halt: |
38 | halt: |
39 | b halt |
39 | b halt |
40 | 40 | ||
41 | memcpy: |
41 | memcpy: |
42 | srwi. r7, r5, 3 |
42 | srwi. r7, r5, 3 |
43 | addi r6, r3, -4 |
43 | addi r6, r3, -4 |
44 | addi r4, r4, -4 |
44 | addi r4, r4, -4 |
45 | beq 2f |
45 | beq 2f |
46 | 46 | ||
47 | andi. r0, r6, 3 |
47 | andi. r0, r6, 3 |
48 | mtctr r7 |
48 | mtctr r7 |
49 | bne 5f |
49 | bne 5f |
50 | 50 | ||
51 | 1: |
51 | 1: |
52 | 52 | ||
53 | lwz r7, 4(r4) |
53 | lwz r7, 4(r4) |
54 | lwzu r8, 8(r4) |
54 | lwzu r8, 8(r4) |
55 | stw r7, 4(r6) |
55 | stw r7, 4(r6) |
56 | stwu r8, 8(r6) |
56 | stwu r8, 8(r6) |
57 | bdnz 1b |
57 | bdnz 1b |
58 | 58 | ||
59 | andi. r5, r5, 7 |
59 | andi. r5, r5, 7 |
60 | 60 | ||
61 | 2: |
61 | 2: |
62 | 62 | ||
63 | cmplwi 0, r5, 4 |
63 | cmplwi 0, r5, 4 |
64 | blt 3f |
64 | blt 3f |
65 | 65 | ||
66 | lwzu r0, 4(r4) |
66 | lwzu r0, 4(r4) |
67 | addi r5, r5, -4 |
67 | addi r5, r5, -4 |
68 | stwu r0, 4(r6) |
68 | stwu r0, 4(r6) |
69 | 69 | ||
70 | 3: |
70 | 3: |
71 | 71 | ||
72 | cmpwi 0, r5, 0 |
72 | cmpwi 0, r5, 0 |
73 | beqlr |
73 | beqlr |
74 | mtctr r5 |
74 | mtctr r5 |
75 | addi r4, r4, 3 |
75 | addi r4, r4, 3 |
76 | addi r6, r6, 3 |
76 | addi r6, r6, 3 |
77 | 77 | ||
78 | 4: |
78 | 4: |
79 | 79 | ||
80 | lbzu r0, 1(r4) |
80 | lbzu r0, 1(r4) |
81 | stbu r0, 1(r6) |
81 | stbu r0, 1(r6) |
82 | bdnz 4b |
82 | bdnz 4b |
83 | blr |
83 | blr |
84 | 84 | ||
85 | 5: |
85 | 5: |
86 | 86 | ||
87 | subfic r0, r0, 4 |
87 | subfic r0, r0, 4 |
88 | mtctr r0 |
88 | mtctr r0 |
89 | 89 | ||
90 | 6: |
90 | 6: |
91 | 91 | ||
92 | lbz r7, 4(r4) |
92 | lbz r7, 4(r4) |
93 | addi r4, r4, 1 |
93 | addi r4, r4, 1 |
94 | stb r7, 4(r6) |
94 | stb r7, 4(r6) |
95 | addi r6, r6, 1 |
95 | addi r6, r6, 1 |
96 | bdnz 6b |
96 | bdnz 6b |
97 | subf r5, r0, r5 |
97 | subf r5, r0, r5 |
98 | rlwinm. r7, r5, 32-3, 3, 31 |
98 | rlwinm. r7, r5, 32-3, 3, 31 |
99 | beq 2b |
99 | beq 2b |
100 | mtctr r7 |
100 | mtctr r7 |
101 | b 1b |
101 | b 1b |
102 | 102 | ||
103 | 103 | ||
104 | jump_to_kernel: |
104 | jump_to_kernel: |
105 | 105 | ||
106 | # r3 = bootinfo (pa) |
106 | # r3 = bootinfo (pa) |
107 | # r4 = bootinfo_size |
107 | # r4 = bootinfo_size |
108 | # r5 = trans (pa) |
108 | # r5 = trans (pa) |
109 | # r6 = kernel size |
109 | # r6 = kernel size |
110 | # r7 = framebuffer (pa) |
110 | # r7 = framebuffer (pa) |
111 | # r8 = real_mode (pa) |
111 | # r8 = real_mode (pa) |
112 | 112 | ||
- | 113 | # disable interrupts |
|
- | 114 | ||
- | 115 | mfmsr r31 |
|
- | 116 | rlwinm r31, r31, 0, 17, 15 |
|
- | 117 | mtmsr r31 |
|
- | 118 | ||
- | 119 | # set real_mode meeting point address |
|
- | 120 | ||
113 | mtspr srr0, r8 |
121 | mtspr srr0, r8 |
114 | 122 | ||
115 | # jumps to real_mode |
123 | # jumps to real_mode |
116 | 124 | ||
117 | mfmsr r31 |
125 | mfmsr r31 |
118 | lis r30, ~0@h |
126 | lis r30, ~0@h |
119 | ori r30, r30, ~(msr_ir | msr_dr)@l |
127 | ori r30, r30, ~(msr_ir | msr_dr)@l |
120 | and r31, r31, r30 |
128 | and r31, r31, r30 |
121 | mtspr srr1, r31 |
129 | mtspr srr1, r31 |
122 | 130 | ||
123 | sync |
131 | sync |
124 | isync |
132 | isync |
125 | rfi |
133 | rfi |
126 | 134 | ||
127 | .section REALMODE, "ax" |
135 | .section REALMODE, "ax" |
128 | .align PAGE_WIDTH |
136 | .align PAGE_WIDTH |
129 | .global real_mode |
137 | .global real_mode |
130 | 138 | ||
131 | real_mode: |
139 | real_mode: |
132 | 140 | ||
133 | # copy kernel to proper location |
141 | # copy kernel to proper location |
134 | # |
142 | # |
135 | # r5 = trans (pa) |
143 | # r5 = trans (pa) |
136 | # r6 = kernel size |
144 | # r6 = kernel size |
137 | # r7 = framebuffer (pa) |
145 | # r7 = framebuffer (pa) |
138 | 146 | ||
139 | li r31, PAGE_SIZE >> 2 |
147 | li r31, PAGE_SIZE >> 2 |
140 | li r30, 0 |
148 | li r30, 0 |
141 | 149 | ||
142 | page_copy: |
150 | page_copy: |
143 | 151 | ||
144 | cmpwi r6, 0 |
152 | cmpwi r6, 0 |
145 | beq copy_end |
153 | beq copy_end |
146 | 154 | ||
147 | # copy page |
155 | # copy page |
148 | 156 | ||
149 | mtctr r31 |
157 | mtctr r31 |
150 | lwz r29, 0(r5) |
158 | lwz r29, 0(r5) |
151 | 159 | ||
152 | copy_loop: |
160 | copy_loop: |
153 | 161 | ||
154 | lwz r28, 0(r29) |
162 | lwz r28, 0(r29) |
155 | stw r28, 0(r30) |
163 | stw r28, 0(r30) |
156 | 164 | ||
157 | addi r29, r29, 4 |
165 | addi r29, r29, 4 |
158 | addi r30, r30, 4 |
166 | addi r30, r30, 4 |
159 | subi r6, r6, 4 |
167 | subi r6, r6, 4 |
160 | 168 | ||
161 | cmpwi r6, 0 |
169 | cmpwi r6, 0 |
162 | beq copy_end |
170 | beq copy_end |
163 | 171 | ||
164 | bdnz copy_loop |
172 | bdnz copy_loop |
165 | 173 | ||
166 | addi r5, r5, 4 |
174 | addi r5, r5, 4 |
167 | b page_copy |
175 | b page_copy |
168 | 176 | ||
169 | copy_end: |
177 | copy_end: |
170 | 178 | ||
171 | # initially fill segment registers |
179 | # initially fill segment registers |
172 | 180 | ||
173 | li r31, 16 |
181 | li r31, 16 |
174 | mtctr r31 |
182 | mtctr r31 |
175 | li r31, 0 |
183 | li r31, 0 |
176 | li r30, 0x2000 |
184 | li r30, 0x2000 |
177 | 185 | ||
178 | seg_fill: |
186 | seg_fill: |
179 | 187 | ||
180 | mtsrin r30, r31 |
188 | mtsrin r30, r31 |
181 | addi r30, r30, 0x111 |
189 | addi r30, r30, 0x111 |
182 | addis r31, r31, 0x1000 # move to next SR |
190 | addis r31, r31, 0x1000 # move to next SR |
183 | 191 | ||
184 | bdnz seg_fill |
192 | bdnz seg_fill |
185 | 193 | ||
186 | # invalidate block address translation registers |
194 | # invalidate block address translation registers |
187 | 195 | ||
188 | mtspr ibat0u, r30 |
196 | mtspr ibat0u, r30 |
189 | mtspr ibat0l, r30 |
197 | mtspr ibat0l, r30 |
190 | 198 | ||
191 | mtspr ibat1u, r30 |
199 | mtspr ibat1u, r30 |
192 | mtspr ibat1l, r30 |
200 | mtspr ibat1l, r30 |
193 | 201 | ||
194 | mtspr ibat2u, r30 |
202 | mtspr ibat2u, r30 |
195 | mtspr ibat2l, r30 |
203 | mtspr ibat2l, r30 |
196 | 204 | ||
197 | mtspr ibat3u, r30 |
205 | mtspr ibat3u, r30 |
198 | mtspr ibat3l, r30 |
206 | mtspr ibat3l, r30 |
199 | 207 | ||
200 | mtspr dbat0u, r30 |
208 | mtspr dbat0u, r30 |
201 | mtspr dbat0l, r30 |
209 | mtspr dbat0l, r30 |
202 | 210 | ||
203 | mtspr dbat1u, r30 |
211 | mtspr dbat1u, r30 |
204 | mtspr dbat1l, r30 |
212 | mtspr dbat1l, r30 |
205 | 213 | ||
206 | mtspr dbat2u, r30 |
214 | mtspr dbat2u, r30 |
207 | mtspr dbat2l, r30 |
215 | mtspr dbat2l, r30 |
208 | 216 | ||
209 | mtspr dbat3u, r30 |
217 | mtspr dbat3u, r30 |
210 | mtspr dbat3l, r30 |
218 | mtspr dbat3l, r30 |
211 | 219 | ||
212 | # create identity mapping |
220 | # create identity mapping |
213 | 221 | ||
214 | # FIXME: map exactly the size of RAM |
222 | # FIXME: map exactly the size of RAM |
215 | 223 | ||
216 | lis r31, 0x8000 |
224 | lis r31, 0x8000 |
217 | ori r31, r31, 0x0ffe |
225 | ori r31, r31, 0x0ffe |
218 | 226 | ||
219 | lis r30, 0x0000 |
227 | lis r30, 0x0000 |
220 | ori r30, r30, 0x0002 |
228 | ori r30, r30, 0x0002 |
221 | 229 | ||
222 | mtspr ibat0u, r31 |
230 | mtspr ibat0u, r31 |
223 | mtspr ibat0l, r30 |
231 | mtspr ibat0l, r30 |
224 | 232 | ||
225 | mtspr dbat0u, r31 |
233 | mtspr dbat0u, r31 |
226 | mtspr dbat0l, r30 |
234 | mtspr dbat0l, r30 |
227 | 235 | ||
228 | # FIXME: temporal framebuffer mapping |
236 | # FIXME: temporal framebuffer mapping |
229 | 237 | ||
230 | lis r31, 0xf000 |
238 | lis r31, 0xf000 |
231 | ori r31, r31, 0x0ffe |
239 | ori r31, r31, 0x0ffe |
232 | 240 | ||
233 | mr r30, r7 |
241 | mr r30, r7 |
234 | ori r30, r30, 0x0002 |
242 | ori r30, r30, 0x0002 |
235 | 243 | ||
236 | mtspr dbat1u, r31 |
244 | mtspr dbat1u, r31 |
237 | mtspr dbat1l, r30 |
245 | mtspr dbat1l, r30 |
238 | 246 | ||
239 | tlbia |
247 | tlbia |
240 | 248 | ||
241 | # start the kernel |
249 | # start the kernel |
242 | # |
250 | # |
243 | # r3 = bootinfo (pa) |
251 | # r3 = bootinfo (pa) |
244 | 252 | ||
245 | lis r31, KERNEL_START_ADDR@ha |
253 | lis r31, KERNEL_START_ADDR@ha |
246 | addi r31, r31, KERNEL_START_ADDR@l |
254 | addi r31, r31, KERNEL_START_ADDR@l |
247 | 255 | ||
248 | mtspr srr0, r31 |
256 | mtspr srr0, r31 |
249 | 257 | ||
250 | mfmsr r31 |
258 | mfmsr r31 |
251 | ori r31, r31, (msr_ir | msr_dr)@l |
259 | ori r31, r31, (msr_ir | msr_dr)@l |
252 | mtspr srr1, r31 |
260 | mtspr srr1, r31 |
253 | 261 | ||
254 | sync |
262 | sync |
255 | isync |
263 | isync |
256 | rfi |
264 | rfi |
257 | 265 | ||
258 | .align PAGE_WIDTH |
266 | .align PAGE_WIDTH |
259 | .global trans |
267 | .global trans |
260 | trans: |
268 | trans: |
261 | .space (TRANS_SIZE * TRANS_ITEM_SIZE) |
269 | .space (TRANS_SIZE * TRANS_ITEM_SIZE) |
262 | 270 |