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