Commit | Line | Data |
---|---|---|
14cf11af | 1 | /* |
14cf11af PM |
2 | * Kernel execution entry point code. |
3 | * | |
4 | * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org> | |
5 | * Initial PowerPC version. | |
6 | * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu> | |
7 | * Rewritten for PReP | |
8 | * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au> | |
9 | * Low-level exception handers, MMU support, and rewrite. | |
10 | * Copyright (c) 1997 Dan Malek <dmalek@jlc.net> | |
11 | * PowerPC 8xx modifications. | |
12 | * Copyright (c) 1998-1999 TiVo, Inc. | |
13 | * PowerPC 403GCX modifications. | |
14 | * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu> | |
15 | * PowerPC 403GCX/405GP modifications. | |
16 | * Copyright 2000 MontaVista Software Inc. | |
17 | * PPC405 modifications | |
18 | * PowerPC 403GCX/405GP modifications. | |
19 | * Author: MontaVista Software, Inc. | |
20 | * frank_rowand@mvista.com or source@mvista.com | |
21 | * debbie_chu@mvista.com | |
22 | * Copyright 2002-2005 MontaVista Software, Inc. | |
23 | * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org> | |
24 | * | |
25 | * This program is free software; you can redistribute it and/or modify it | |
26 | * under the terms of the GNU General Public License as published by the | |
27 | * Free Software Foundation; either version 2 of the License, or (at your | |
28 | * option) any later version. | |
29 | */ | |
30 | ||
e7039845 | 31 | #include <linux/init.h> |
14cf11af PM |
32 | #include <asm/processor.h> |
33 | #include <asm/page.h> | |
34 | #include <asm/mmu.h> | |
35 | #include <asm/pgtable.h> | |
14cf11af PM |
36 | #include <asm/cputable.h> |
37 | #include <asm/thread_info.h> | |
38 | #include <asm/ppc_asm.h> | |
39 | #include <asm/asm-offsets.h> | |
46f52210 | 40 | #include <asm/ptrace.h> |
e7f75ad0 | 41 | #include <asm/synch.h> |
14cf11af PM |
42 | #include "head_booke.h" |
43 | ||
44 | ||
45 | /* As with the other PowerPC ports, it is expected that when code | |
46 | * execution begins here, the following registers contain valid, yet | |
47 | * optional, information: | |
48 | * | |
49 | * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.) | |
50 | * r4 - Starting address of the init RAM disk | |
51 | * r5 - Ending address of the init RAM disk | |
52 | * r6 - Start of kernel command line string (e.g. "mem=128") | |
53 | * r7 - End of kernel command line string | |
54 | * | |
55 | */ | |
e7039845 | 56 | __HEAD |
748a7683 KG |
57 | _ENTRY(_stext); |
58 | _ENTRY(_start); | |
14cf11af PM |
59 | /* |
60 | * Reserve a word at a fixed location to store the address | |
61 | * of abatron_pteptrs | |
62 | */ | |
63 | nop | |
6dece0eb | 64 | mr r31,r3 /* save device tree ptr */ |
14cf11af PM |
65 | li r24,0 /* CPU number */ |
66 | ||
795033c3 | 67 | bl init_cpu_state |
14cf11af | 68 | |
14cf11af PM |
69 | /* |
70 | * This is where the main kernel code starts. | |
71 | */ | |
72 | ||
73 | /* ptr to current */ | |
74 | lis r2,init_task@h | |
75 | ori r2,r2,init_task@l | |
76 | ||
77 | /* ptr to current thread */ | |
78 | addi r4,r2,THREAD /* init task's THREAD */ | |
ee43eb78 | 79 | mtspr SPRN_SPRG_THREAD,r4 |
14cf11af PM |
80 | |
81 | /* stack */ | |
82 | lis r1,init_thread_union@h | |
83 | ori r1,r1,init_thread_union@l | |
84 | li r0,0 | |
85 | stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) | |
86 | ||
87 | bl early_init | |
88 | ||
0f890c8d | 89 | #ifdef CONFIG_DYNAMIC_MEMSTART |
9661534d | 90 | /* |
0f890c8d SP |
91 | * Mapping based, page aligned dynamic kernel loading. |
92 | * | |
9661534d DK |
93 | * r25 will contain RPN/ERPN for the start address of memory |
94 | * | |
95 | * Add the difference between KERNELBASE and PAGE_OFFSET to the | |
96 | * start of physical memory to get kernstart_addr. | |
97 | */ | |
98 | lis r3,kernstart_addr@ha | |
99 | la r3,kernstart_addr@l(r3) | |
100 | ||
101 | lis r4,KERNELBASE@h | |
102 | ori r4,r4,KERNELBASE@l | |
103 | lis r5,PAGE_OFFSET@h | |
104 | ori r5,r5,PAGE_OFFSET@l | |
105 | subf r4,r5,r4 | |
106 | ||
107 | rlwinm r6,r25,0,28,31 /* ERPN */ | |
108 | rlwinm r7,r25,0,0,3 /* RPN - assuming 256 MB page size */ | |
109 | add r7,r7,r4 | |
110 | ||
111 | stw r6,0(r3) | |
112 | stw r7,4(r3) | |
113 | #endif | |
114 | ||
14cf11af PM |
115 | /* |
116 | * Decide what sort of machine this is and initialize the MMU. | |
117 | */ | |
6dece0eb SW |
118 | li r3,0 |
119 | mr r4,r31 | |
14cf11af PM |
120 | bl machine_init |
121 | bl MMU_init | |
122 | ||
123 | /* Setup PTE pointers for the Abatron bdiGDB */ | |
124 | lis r6, swapper_pg_dir@h | |
125 | ori r6, r6, swapper_pg_dir@l | |
126 | lis r5, abatron_pteptrs@h | |
127 | ori r5, r5, abatron_pteptrs@l | |
128 | lis r4, KERNELBASE@h | |
129 | ori r4, r4, KERNELBASE@l | |
130 | stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */ | |
131 | stw r6, 0(r5) | |
132 | ||
029b8f66 DK |
133 | /* Clear the Machine Check Syndrome Register */ |
134 | li r0,0 | |
135 | mtspr SPRN_MCSR,r0 | |
136 | ||
14cf11af PM |
137 | /* Let's move on */ |
138 | lis r4,start_kernel@h | |
139 | ori r4,r4,start_kernel@l | |
140 | lis r3,MSR_KERNEL@h | |
141 | ori r3,r3,MSR_KERNEL@l | |
142 | mtspr SPRN_SRR0,r4 | |
143 | mtspr SPRN_SRR1,r3 | |
144 | rfi /* change context and jump to start_kernel */ | |
145 | ||
146 | /* | |
147 | * Interrupt vector entry code | |
148 | * | |
149 | * The Book E MMUs are always on so we don't need to handle | |
150 | * interrupts in real mode as with previous PPC processors. In | |
151 | * this case we handle interrupts in the kernel virtual address | |
152 | * space. | |
153 | * | |
154 | * Interrupt vectors are dynamically placed relative to the | |
155 | * interrupt prefix as determined by the address of interrupt_base. | |
156 | * The interrupt vectors offsets are programmed using the labels | |
157 | * for each interrupt vector entry. | |
158 | * | |
159 | * Interrupt vectors must be aligned on a 16 byte boundary. | |
160 | * We align on a 32 byte cache line boundary for good measure. | |
161 | */ | |
162 | ||
163 | interrupt_base: | |
164 | /* Critical Input Interrupt */ | |
dc1c1ca3 | 165 | CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception) |
14cf11af PM |
166 | |
167 | /* Machine Check Interrupt */ | |
dc1c1ca3 | 168 | CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception) |
47c0bd1a | 169 | MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception) |
14cf11af PM |
170 | |
171 | /* Data Storage Interrupt */ | |
1bc54c03 | 172 | DATA_STORAGE_EXCEPTION |
14cf11af | 173 | |
1bc54c03 | 174 | /* Instruction Storage Interrupt */ |
14cf11af PM |
175 | INSTRUCTION_STORAGE_EXCEPTION |
176 | ||
177 | /* External Input Interrupt */ | |
178 | EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE) | |
179 | ||
180 | /* Alignment Interrupt */ | |
181 | ALIGNMENT_EXCEPTION | |
182 | ||
183 | /* Program Interrupt */ | |
184 | PROGRAM_EXCEPTION | |
185 | ||
186 | /* Floating Point Unavailable Interrupt */ | |
187 | #ifdef CONFIG_PPC_FPU | |
188 | FP_UNAVAILABLE_EXCEPTION | |
189 | #else | |
dc1c1ca3 | 190 | EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE) |
14cf11af | 191 | #endif |
14cf11af PM |
192 | /* System Call Interrupt */ |
193 | START_EXCEPTION(SystemCall) | |
194 | NORMAL_EXCEPTION_PROLOG | |
195 | EXC_XFER_EE_LITE(0x0c00, DoSyscall) | |
196 | ||
25985edc | 197 | /* Auxiliary Processor Unavailable Interrupt */ |
dc1c1ca3 | 198 | EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE) |
14cf11af PM |
199 | |
200 | /* Decrementer Interrupt */ | |
201 | DECREMENTER_EXCEPTION | |
202 | ||
203 | /* Fixed Internal Timer Interrupt */ | |
204 | /* TODO: Add FIT support */ | |
dc1c1ca3 | 205 | EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE) |
14cf11af PM |
206 | |
207 | /* Watchdog Timer Interrupt */ | |
208 | /* TODO: Add watchdog support */ | |
209 | #ifdef CONFIG_BOOKE_WDT | |
210 | CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException) | |
211 | #else | |
dc1c1ca3 | 212 | CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception) |
14cf11af PM |
213 | #endif |
214 | ||
215 | /* Data TLB Error Interrupt */ | |
e7f75ad0 | 216 | START_EXCEPTION(DataTLBError44x) |
ee43eb78 BH |
217 | mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ |
218 | mtspr SPRN_SPRG_WSCRATCH1, r11 | |
219 | mtspr SPRN_SPRG_WSCRATCH2, r12 | |
220 | mtspr SPRN_SPRG_WSCRATCH3, r13 | |
14cf11af | 221 | mfcr r11 |
ee43eb78 | 222 | mtspr SPRN_SPRG_WSCRATCH4, r11 |
14cf11af PM |
223 | mfspr r10, SPRN_DEAR /* Get faulting address */ |
224 | ||
225 | /* If we are faulting a kernel address, we have to use the | |
226 | * kernel page tables. | |
227 | */ | |
8a13c4f9 | 228 | lis r11, PAGE_OFFSET@h |
14cf11af PM |
229 | cmplw r10, r11 |
230 | blt+ 3f | |
231 | lis r11, swapper_pg_dir@h | |
232 | ori r11, r11, swapper_pg_dir@l | |
233 | ||
234 | mfspr r12,SPRN_MMUCR | |
235 | rlwinm r12,r12,0,0,23 /* Clear TID */ | |
236 | ||
237 | b 4f | |
238 | ||
239 | /* Get the PGD for the current thread */ | |
240 | 3: | |
ee43eb78 | 241 | mfspr r11,SPRN_SPRG_THREAD |
14cf11af PM |
242 | lwz r11,PGDIR(r11) |
243 | ||
244 | /* Load PID into MMUCR TID */ | |
245 | mfspr r12,SPRN_MMUCR | |
246 | mfspr r13,SPRN_PID /* Get PID */ | |
247 | rlwimi r12,r13,0,24,31 /* Set TID */ | |
248 | ||
249 | 4: | |
250 | mtspr SPRN_MMUCR,r12 | |
251 | ||
1bc54c03 BH |
252 | /* Mask of required permission bits. Note that while we |
253 | * do copy ESR:ST to _PAGE_RW position as trying to write | |
254 | * to an RO page is pretty common, we don't do it with | |
255 | * _PAGE_DIRTY. We could do it, but it's a fairly rare | |
256 | * event so I'd rather take the overhead when it happens | |
257 | * rather than adding an instruction here. We should measure | |
258 | * whether the whole thing is worth it in the first place | |
259 | * as we could avoid loading SPRN_ESR completely in the first | |
260 | * place... | |
261 | * | |
262 | * TODO: Is it worth doing that mfspr & rlwimi in the first | |
263 | * place or can we save a couple of instructions here ? | |
264 | */ | |
265 | mfspr r12,SPRN_ESR | |
266 | li r13,_PAGE_PRESENT|_PAGE_ACCESSED | |
267 | rlwimi r13,r12,10,30,30 | |
268 | ||
269 | /* Load the PTE */ | |
ca9153a3 IY |
270 | /* Compute pgdir/pmd offset */ |
271 | rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 | |
14cf11af PM |
272 | lwzx r11, r12, r11 /* Get pgd/pmd entry */ |
273 | rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ | |
274 | beq 2f /* Bail if no table */ | |
275 | ||
ca9153a3 IY |
276 | /* Compute pte address */ |
277 | rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 | |
1bc54c03 BH |
278 | lwz r11, 0(r12) /* Get high word of pte entry */ |
279 | lwz r12, 4(r12) /* Get low word of pte entry */ | |
14cf11af | 280 | |
1bc54c03 BH |
281 | lis r10,tlb_44x_index@ha |
282 | ||
283 | andc. r13,r13,r12 /* Check permission */ | |
284 | ||
285 | /* Load the next available TLB index */ | |
286 | lwz r13,tlb_44x_index@l(r10) | |
287 | ||
288 | bne 2f /* Bail if permission mismach */ | |
289 | ||
290 | /* Increment, rollover, and store TLB index */ | |
291 | addi r13,r13,1 | |
292 | ||
293 | /* Compare with watermark (instruction gets patched) */ | |
294 | .globl tlb_44x_patch_hwater_D | |
295 | tlb_44x_patch_hwater_D: | |
296 | cmpwi 0,r13,1 /* reserve entries */ | |
297 | ble 5f | |
298 | li r13,0 | |
299 | 5: | |
300 | /* Store the next available TLB index */ | |
301 | stw r13,tlb_44x_index@l(r10) | |
302 | ||
303 | /* Re-load the faulting address */ | |
304 | mfspr r10,SPRN_DEAR | |
14cf11af PM |
305 | |
306 | /* Jump to common tlb load */ | |
e7f75ad0 | 307 | b finish_tlb_load_44x |
14cf11af PM |
308 | |
309 | 2: | |
310 | /* The bailout. Restore registers to pre-exception conditions | |
311 | * and call the heavyweights to help us out. | |
312 | */ | |
ee43eb78 | 313 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
14cf11af | 314 | mtcr r11 |
ee43eb78 BH |
315 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
316 | mfspr r12, SPRN_SPRG_RSCRATCH2 | |
317 | mfspr r11, SPRN_SPRG_RSCRATCH1 | |
318 | mfspr r10, SPRN_SPRG_RSCRATCH0 | |
1bc54c03 | 319 | b DataStorage |
14cf11af PM |
320 | |
321 | /* Instruction TLB Error Interrupt */ | |
322 | /* | |
323 | * Nearly the same as above, except we get our | |
324 | * information from different registers and bailout | |
325 | * to a different point. | |
326 | */ | |
e7f75ad0 | 327 | START_EXCEPTION(InstructionTLBError44x) |
ee43eb78 BH |
328 | mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ |
329 | mtspr SPRN_SPRG_WSCRATCH1, r11 | |
330 | mtspr SPRN_SPRG_WSCRATCH2, r12 | |
331 | mtspr SPRN_SPRG_WSCRATCH3, r13 | |
14cf11af | 332 | mfcr r11 |
ee43eb78 | 333 | mtspr SPRN_SPRG_WSCRATCH4, r11 |
14cf11af PM |
334 | mfspr r10, SPRN_SRR0 /* Get faulting address */ |
335 | ||
336 | /* If we are faulting a kernel address, we have to use the | |
337 | * kernel page tables. | |
338 | */ | |
8a13c4f9 | 339 | lis r11, PAGE_OFFSET@h |
14cf11af PM |
340 | cmplw r10, r11 |
341 | blt+ 3f | |
342 | lis r11, swapper_pg_dir@h | |
343 | ori r11, r11, swapper_pg_dir@l | |
344 | ||
345 | mfspr r12,SPRN_MMUCR | |
346 | rlwinm r12,r12,0,0,23 /* Clear TID */ | |
347 | ||
348 | b 4f | |
349 | ||
350 | /* Get the PGD for the current thread */ | |
351 | 3: | |
ee43eb78 | 352 | mfspr r11,SPRN_SPRG_THREAD |
14cf11af PM |
353 | lwz r11,PGDIR(r11) |
354 | ||
355 | /* Load PID into MMUCR TID */ | |
356 | mfspr r12,SPRN_MMUCR | |
357 | mfspr r13,SPRN_PID /* Get PID */ | |
358 | rlwimi r12,r13,0,24,31 /* Set TID */ | |
359 | ||
360 | 4: | |
361 | mtspr SPRN_MMUCR,r12 | |
362 | ||
1bc54c03 | 363 | /* Make up the required permissions */ |
ea3cc330 | 364 | li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC |
1bc54c03 | 365 | |
ca9153a3 IY |
366 | /* Compute pgdir/pmd offset */ |
367 | rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 | |
14cf11af PM |
368 | lwzx r11, r12, r11 /* Get pgd/pmd entry */ |
369 | rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ | |
370 | beq 2f /* Bail if no table */ | |
371 | ||
ca9153a3 IY |
372 | /* Compute pte address */ |
373 | rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 | |
1bc54c03 BH |
374 | lwz r11, 0(r12) /* Get high word of pte entry */ |
375 | lwz r12, 4(r12) /* Get low word of pte entry */ | |
14cf11af | 376 | |
1bc54c03 BH |
377 | lis r10,tlb_44x_index@ha |
378 | ||
379 | andc. r13,r13,r12 /* Check permission */ | |
380 | ||
381 | /* Load the next available TLB index */ | |
382 | lwz r13,tlb_44x_index@l(r10) | |
383 | ||
384 | bne 2f /* Bail if permission mismach */ | |
385 | ||
386 | /* Increment, rollover, and store TLB index */ | |
387 | addi r13,r13,1 | |
388 | ||
389 | /* Compare with watermark (instruction gets patched) */ | |
390 | .globl tlb_44x_patch_hwater_I | |
391 | tlb_44x_patch_hwater_I: | |
392 | cmpwi 0,r13,1 /* reserve entries */ | |
393 | ble 5f | |
394 | li r13,0 | |
395 | 5: | |
396 | /* Store the next available TLB index */ | |
397 | stw r13,tlb_44x_index@l(r10) | |
398 | ||
399 | /* Re-load the faulting address */ | |
400 | mfspr r10,SPRN_SRR0 | |
14cf11af PM |
401 | |
402 | /* Jump to common TLB load point */ | |
e7f75ad0 | 403 | b finish_tlb_load_44x |
14cf11af PM |
404 | |
405 | 2: | |
406 | /* The bailout. Restore registers to pre-exception conditions | |
407 | * and call the heavyweights to help us out. | |
408 | */ | |
ee43eb78 | 409 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
14cf11af | 410 | mtcr r11 |
ee43eb78 BH |
411 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
412 | mfspr r12, SPRN_SPRG_RSCRATCH2 | |
413 | mfspr r11, SPRN_SPRG_RSCRATCH1 | |
414 | mfspr r10, SPRN_SPRG_RSCRATCH0 | |
14cf11af PM |
415 | b InstructionStorage |
416 | ||
14cf11af | 417 | /* |
14cf11af PM |
418 | * Both the instruction and data TLB miss get to this |
419 | * point to load the TLB. | |
420 | * r10 - EA of fault | |
1bc54c03 BH |
421 | * r11 - PTE high word value |
422 | * r12 - PTE low word value | |
423 | * r13 - TLB index | |
14cf11af PM |
424 | * MMUCR - loaded with proper value when we get here |
425 | * Upon exit, we reload everything and RFI. | |
426 | */ | |
e7f75ad0 | 427 | finish_tlb_load_44x: |
1bc54c03 | 428 | /* Combine RPN & ERPN an write WS 0 */ |
ca9153a3 | 429 | rlwimi r11,r12,0,0,31-PAGE_SHIFT |
1bc54c03 | 430 | tlbwe r11,r13,PPC44x_TLB_XLAT |
14cf11af PM |
431 | |
432 | /* | |
1bc54c03 | 433 | * Create WS1. This is the faulting address (EPN), |
14cf11af PM |
434 | * page size, and valid flag. |
435 | */ | |
ca9153a3 IY |
436 | li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE |
437 | /* Insert valid and page size */ | |
438 | rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31 | |
1bc54c03 BH |
439 | tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */ |
440 | ||
441 | /* And WS 2 */ | |
442 | li r10,0xf85 /* Mask to apply from PTE */ | |
443 | rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ | |
444 | and r11,r12,r10 /* Mask PTE bits to keep */ | |
445 | andi. r10,r12,_PAGE_USER /* User page ? */ | |
446 | beq 1f /* nope, leave U bits empty */ | |
447 | rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ | |
448 | 1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */ | |
14cf11af PM |
449 | |
450 | /* Done...restore registers and get out of here. | |
451 | */ | |
ee43eb78 | 452 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
14cf11af | 453 | mtcr r11 |
ee43eb78 BH |
454 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
455 | mfspr r12, SPRN_SPRG_RSCRATCH2 | |
456 | mfspr r11, SPRN_SPRG_RSCRATCH1 | |
457 | mfspr r10, SPRN_SPRG_RSCRATCH0 | |
14cf11af PM |
458 | rfi /* Force context change */ |
459 | ||
e7f75ad0 DK |
460 | /* TLB error interrupts for 476 |
461 | */ | |
462 | #ifdef CONFIG_PPC_47x | |
463 | START_EXCEPTION(DataTLBError47x) | |
464 | mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */ | |
465 | mtspr SPRN_SPRG_WSCRATCH1,r11 | |
466 | mtspr SPRN_SPRG_WSCRATCH2,r12 | |
467 | mtspr SPRN_SPRG_WSCRATCH3,r13 | |
468 | mfcr r11 | |
469 | mtspr SPRN_SPRG_WSCRATCH4,r11 | |
470 | mfspr r10,SPRN_DEAR /* Get faulting address */ | |
471 | ||
472 | /* If we are faulting a kernel address, we have to use the | |
473 | * kernel page tables. | |
474 | */ | |
475 | lis r11,PAGE_OFFSET@h | |
476 | cmplw cr0,r10,r11 | |
477 | blt+ 3f | |
478 | lis r11,swapper_pg_dir@h | |
479 | ori r11,r11, swapper_pg_dir@l | |
480 | li r12,0 /* MMUCR = 0 */ | |
481 | b 4f | |
482 | ||
483 | /* Get the PGD for the current thread and setup MMUCR */ | |
484 | 3: mfspr r11,SPRN_SPRG3 | |
485 | lwz r11,PGDIR(r11) | |
486 | mfspr r12,SPRN_PID /* Get PID */ | |
487 | 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ | |
488 | ||
489 | /* Mask of required permission bits. Note that while we | |
490 | * do copy ESR:ST to _PAGE_RW position as trying to write | |
491 | * to an RO page is pretty common, we don't do it with | |
492 | * _PAGE_DIRTY. We could do it, but it's a fairly rare | |
493 | * event so I'd rather take the overhead when it happens | |
494 | * rather than adding an instruction here. We should measure | |
495 | * whether the whole thing is worth it in the first place | |
496 | * as we could avoid loading SPRN_ESR completely in the first | |
497 | * place... | |
498 | * | |
499 | * TODO: Is it worth doing that mfspr & rlwimi in the first | |
500 | * place or can we save a couple of instructions here ? | |
501 | */ | |
502 | mfspr r12,SPRN_ESR | |
503 | li r13,_PAGE_PRESENT|_PAGE_ACCESSED | |
504 | rlwimi r13,r12,10,30,30 | |
505 | ||
506 | /* Load the PTE */ | |
507 | /* Compute pgdir/pmd offset */ | |
508 | rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29 | |
509 | lwzx r11,r12,r11 /* Get pgd/pmd entry */ | |
510 | ||
511 | /* Word 0 is EPN,V,TS,DSIZ */ | |
512 | li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE | |
513 | rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/ | |
514 | li r12,0 | |
515 | tlbwe r10,r12,0 | |
516 | ||
517 | /* XXX can we do better ? Need to make sure tlbwe has established | |
518 | * latch V bit in MMUCR0 before the PTE is loaded further down */ | |
519 | #ifdef CONFIG_SMP | |
520 | isync | |
521 | #endif | |
522 | ||
523 | rlwinm. r12,r11,0,0,20 /* Extract pt base address */ | |
524 | /* Compute pte address */ | |
525 | rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28 | |
526 | beq 2f /* Bail if no table */ | |
527 | lwz r11,0(r12) /* Get high word of pte entry */ | |
528 | ||
529 | /* XXX can we do better ? maybe insert a known 0 bit from r11 into the | |
530 | * bottom of r12 to create a data dependency... We can also use r10 | |
531 | * as destination nowadays | |
532 | */ | |
533 | #ifdef CONFIG_SMP | |
534 | lwsync | |
535 | #endif | |
536 | lwz r12,4(r12) /* Get low word of pte entry */ | |
537 | ||
538 | andc. r13,r13,r12 /* Check permission */ | |
539 | ||
540 | /* Jump to common tlb load */ | |
541 | beq finish_tlb_load_47x | |
542 | ||
543 | 2: /* The bailout. Restore registers to pre-exception conditions | |
544 | * and call the heavyweights to help us out. | |
545 | */ | |
546 | mfspr r11,SPRN_SPRG_RSCRATCH4 | |
547 | mtcr r11 | |
548 | mfspr r13,SPRN_SPRG_RSCRATCH3 | |
549 | mfspr r12,SPRN_SPRG_RSCRATCH2 | |
550 | mfspr r11,SPRN_SPRG_RSCRATCH1 | |
551 | mfspr r10,SPRN_SPRG_RSCRATCH0 | |
552 | b DataStorage | |
553 | ||
554 | /* Instruction TLB Error Interrupt */ | |
555 | /* | |
556 | * Nearly the same as above, except we get our | |
557 | * information from different registers and bailout | |
558 | * to a different point. | |
559 | */ | |
560 | START_EXCEPTION(InstructionTLBError47x) | |
561 | mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */ | |
562 | mtspr SPRN_SPRG_WSCRATCH1,r11 | |
563 | mtspr SPRN_SPRG_WSCRATCH2,r12 | |
564 | mtspr SPRN_SPRG_WSCRATCH3,r13 | |
565 | mfcr r11 | |
566 | mtspr SPRN_SPRG_WSCRATCH4,r11 | |
567 | mfspr r10,SPRN_SRR0 /* Get faulting address */ | |
568 | ||
569 | /* If we are faulting a kernel address, we have to use the | |
570 | * kernel page tables. | |
571 | */ | |
572 | lis r11,PAGE_OFFSET@h | |
573 | cmplw cr0,r10,r11 | |
574 | blt+ 3f | |
575 | lis r11,swapper_pg_dir@h | |
576 | ori r11,r11, swapper_pg_dir@l | |
577 | li r12,0 /* MMUCR = 0 */ | |
578 | b 4f | |
579 | ||
580 | /* Get the PGD for the current thread and setup MMUCR */ | |
581 | 3: mfspr r11,SPRN_SPRG_THREAD | |
582 | lwz r11,PGDIR(r11) | |
583 | mfspr r12,SPRN_PID /* Get PID */ | |
584 | 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ | |
585 | ||
586 | /* Make up the required permissions */ | |
587 | li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC | |
588 | ||
589 | /* Load PTE */ | |
590 | /* Compute pgdir/pmd offset */ | |
591 | rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29 | |
592 | lwzx r11,r12,r11 /* Get pgd/pmd entry */ | |
593 | ||
594 | /* Word 0 is EPN,V,TS,DSIZ */ | |
595 | li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE | |
596 | rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/ | |
597 | li r12,0 | |
598 | tlbwe r10,r12,0 | |
599 | ||
600 | /* XXX can we do better ? Need to make sure tlbwe has established | |
601 | * latch V bit in MMUCR0 before the PTE is loaded further down */ | |
602 | #ifdef CONFIG_SMP | |
603 | isync | |
604 | #endif | |
605 | ||
606 | rlwinm. r12,r11,0,0,20 /* Extract pt base address */ | |
607 | /* Compute pte address */ | |
608 | rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28 | |
609 | beq 2f /* Bail if no table */ | |
610 | ||
611 | lwz r11,0(r12) /* Get high word of pte entry */ | |
612 | /* XXX can we do better ? maybe insert a known 0 bit from r11 into the | |
613 | * bottom of r12 to create a data dependency... We can also use r10 | |
614 | * as destination nowadays | |
615 | */ | |
616 | #ifdef CONFIG_SMP | |
617 | lwsync | |
618 | #endif | |
619 | lwz r12,4(r12) /* Get low word of pte entry */ | |
620 | ||
621 | andc. r13,r13,r12 /* Check permission */ | |
622 | ||
623 | /* Jump to common TLB load point */ | |
624 | beq finish_tlb_load_47x | |
625 | ||
626 | 2: /* The bailout. Restore registers to pre-exception conditions | |
627 | * and call the heavyweights to help us out. | |
628 | */ | |
629 | mfspr r11, SPRN_SPRG_RSCRATCH4 | |
630 | mtcr r11 | |
631 | mfspr r13, SPRN_SPRG_RSCRATCH3 | |
632 | mfspr r12, SPRN_SPRG_RSCRATCH2 | |
633 | mfspr r11, SPRN_SPRG_RSCRATCH1 | |
634 | mfspr r10, SPRN_SPRG_RSCRATCH0 | |
635 | b InstructionStorage | |
636 | ||
637 | /* | |
638 | * Both the instruction and data TLB miss get to this | |
639 | * point to load the TLB. | |
640 | * r10 - free to use | |
641 | * r11 - PTE high word value | |
642 | * r12 - PTE low word value | |
643 | * r13 - free to use | |
644 | * MMUCR - loaded with proper value when we get here | |
645 | * Upon exit, we reload everything and RFI. | |
646 | */ | |
647 | finish_tlb_load_47x: | |
648 | /* Combine RPN & ERPN an write WS 1 */ | |
649 | rlwimi r11,r12,0,0,31-PAGE_SHIFT | |
650 | tlbwe r11,r13,1 | |
651 | ||
652 | /* And make up word 2 */ | |
653 | li r10,0xf85 /* Mask to apply from PTE */ | |
654 | rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ | |
655 | and r11,r12,r10 /* Mask PTE bits to keep */ | |
656 | andi. r10,r12,_PAGE_USER /* User page ? */ | |
657 | beq 1f /* nope, leave U bits empty */ | |
658 | rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ | |
659 | 1: tlbwe r11,r13,2 | |
660 | ||
661 | /* Done...restore registers and get out of here. | |
662 | */ | |
663 | mfspr r11, SPRN_SPRG_RSCRATCH4 | |
664 | mtcr r11 | |
665 | mfspr r13, SPRN_SPRG_RSCRATCH3 | |
666 | mfspr r12, SPRN_SPRG_RSCRATCH2 | |
667 | mfspr r11, SPRN_SPRG_RSCRATCH1 | |
668 | mfspr r10, SPRN_SPRG_RSCRATCH0 | |
669 | rfi | |
670 | ||
671 | #endif /* CONFIG_PPC_47x */ | |
672 | ||
673 | /* Debug Interrupt */ | |
674 | /* | |
675 | * This statement needs to exist at the end of the IVPR | |
676 | * definition just in case you end up taking a debug | |
677 | * exception within another exception. | |
678 | */ | |
679 | DEBUG_CRIT_EXCEPTION | |
680 | ||
14cf11af PM |
681 | /* |
682 | * Global functions | |
683 | */ | |
684 | ||
47c0bd1a BH |
685 | /* |
686 | * Adjust the machine check IVOR on 440A cores | |
687 | */ | |
688 | _GLOBAL(__fixup_440A_mcheck) | |
689 | li r3,MachineCheckA@l | |
690 | mtspr SPRN_IVOR1,r3 | |
691 | sync | |
692 | blr | |
693 | ||
14cf11af PM |
694 | /* |
695 | * extern void giveup_altivec(struct task_struct *prev) | |
696 | * | |
697 | * The 44x core does not have an AltiVec unit. | |
698 | */ | |
699 | _GLOBAL(giveup_altivec) | |
700 | blr | |
701 | ||
702 | /* | |
703 | * extern void giveup_fpu(struct task_struct *prev) | |
704 | * | |
705 | * The 44x core does not have an FPU. | |
706 | */ | |
707 | #ifndef CONFIG_PPC_FPU | |
708 | _GLOBAL(giveup_fpu) | |
709 | blr | |
710 | #endif | |
711 | ||
14cf11af PM |
712 | _GLOBAL(set_context) |
713 | ||
714 | #ifdef CONFIG_BDI_SWITCH | |
715 | /* Context switch the PTE pointer for the Abatron BDI2000. | |
716 | * The PGDIR is the second parameter. | |
717 | */ | |
718 | lis r5, abatron_pteptrs@h | |
719 | ori r5, r5, abatron_pteptrs@l | |
720 | stw r4, 0x4(r5) | |
721 | #endif | |
722 | mtspr SPRN_PID,r3 | |
723 | isync /* Force context change */ | |
724 | blr | |
725 | ||
795033c3 DK |
726 | /* |
727 | * Init CPU state. This is called at boot time or for secondary CPUs | |
728 | * to setup initial TLB entries, setup IVORs, etc... | |
e7f75ad0 | 729 | * |
795033c3 DK |
730 | */ |
731 | _GLOBAL(init_cpu_state) | |
732 | mflr r22 | |
e7f75ad0 DK |
733 | #ifdef CONFIG_PPC_47x |
734 | /* We use the PVR to differenciate 44x cores from 476 */ | |
735 | mfspr r3,SPRN_PVR | |
736 | srwi r3,r3,16 | |
df777bd3 TB |
737 | cmplwi cr0,r3,PVR_476FPE@h |
738 | beq head_start_47x | |
e7f75ad0 DK |
739 | cmplwi cr0,r3,PVR_476@h |
740 | beq head_start_47x | |
b4e8c8dd TS |
741 | cmplwi cr0,r3,PVR_476_ISS@h |
742 | beq head_start_47x | |
e7f75ad0 DK |
743 | #endif /* CONFIG_PPC_47x */ |
744 | ||
795033c3 DK |
745 | /* |
746 | * In case the firmware didn't do it, we apply some workarounds | |
747 | * that are good for all 440 core variants here | |
748 | */ | |
749 | mfspr r3,SPRN_CCR0 | |
750 | rlwinm r3,r3,0,0,27 /* disable icache prefetch */ | |
751 | isync | |
752 | mtspr SPRN_CCR0,r3 | |
753 | isync | |
754 | sync | |
755 | ||
756 | /* | |
e7f75ad0 | 757 | * Set up the initial MMU state for 44x |
795033c3 DK |
758 | * |
759 | * We are still executing code at the virtual address | |
760 | * mappings set by the firmware for the base of RAM. | |
761 | * | |
762 | * We first invalidate all TLB entries but the one | |
763 | * we are running from. We then load the KERNELBASE | |
764 | * mappings so we can begin to use kernel addresses | |
765 | * natively and so the interrupt vector locations are | |
766 | * permanently pinned (necessary since Book E | |
767 | * implementations always have translation enabled). | |
768 | * | |
769 | * TODO: Use the known TLB entry we are running from to | |
770 | * determine which physical region we are located | |
771 | * in. This can be used to determine where in RAM | |
772 | * (on a shared CPU system) or PCI memory space | |
773 | * (on a DRAMless system) we are located. | |
774 | * For now, we assume a perfect world which means | |
775 | * we are located at the base of DRAM (physical 0). | |
776 | */ | |
777 | ||
778 | /* | |
779 | * Search TLB for entry that we are currently using. | |
780 | * Invalidate all entries but the one we are using. | |
781 | */ | |
782 | /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ | |
783 | mfspr r3,SPRN_PID /* Get PID */ | |
784 | mfmsr r4 /* Get MSR */ | |
785 | andi. r4,r4,MSR_IS@l /* TS=1? */ | |
786 | beq wmmucr /* If not, leave STS=0 */ | |
787 | oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */ | |
788 | wmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ | |
789 | sync | |
790 | ||
791 | bl invstr /* Find our address */ | |
792 | invstr: mflr r5 /* Make it accessible */ | |
793 | tlbsx r23,0,r5 /* Find entry we are in */ | |
794 | li r4,0 /* Start at TLB entry 0 */ | |
795 | li r3,0 /* Set PAGEID inval value */ | |
796 | 1: cmpw r23,r4 /* Is this our entry? */ | |
797 | beq skpinv /* If so, skip the inval */ | |
798 | tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */ | |
799 | skpinv: addi r4,r4,1 /* Increment */ | |
800 | cmpwi r4,64 /* Are we done? */ | |
801 | bne 1b /* If not, repeat */ | |
802 | isync /* If so, context change */ | |
803 | ||
804 | /* | |
805 | * Configure and load pinned entry into TLB slot 63. | |
806 | */ | |
23913245 SP |
807 | #ifdef CONFIG_DYNAMIC_MEMSTART |
808 | ||
809 | /* Read the XLAT entry for our current mapping */ | |
810 | tlbre r25,r23,PPC44x_TLB_XLAT | |
811 | ||
812 | lis r3,KERNELBASE@h | |
813 | ori r3,r3,KERNELBASE@l | |
814 | ||
815 | /* Use our current RPN entry */ | |
816 | mr r4,r25 | |
817 | #else | |
795033c3 DK |
818 | |
819 | lis r3,PAGE_OFFSET@h | |
820 | ori r3,r3,PAGE_OFFSET@l | |
821 | ||
822 | /* Kernel is at the base of RAM */ | |
823 | li r4, 0 /* Load the kernel physical address */ | |
23913245 | 824 | #endif |
795033c3 DK |
825 | |
826 | /* Load the kernel PID = 0 */ | |
827 | li r0,0 | |
828 | mtspr SPRN_PID,r0 | |
829 | sync | |
830 | ||
831 | /* Initialize MMUCR */ | |
832 | li r5,0 | |
833 | mtspr SPRN_MMUCR,r5 | |
834 | sync | |
835 | ||
836 | /* pageid fields */ | |
837 | clrrwi r3,r3,10 /* Mask off the effective page number */ | |
838 | ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M | |
839 | ||
840 | /* xlat fields */ | |
841 | clrrwi r4,r4,10 /* Mask off the real page number */ | |
842 | /* ERPN is 0 for first 4GB page */ | |
843 | ||
844 | /* attrib fields */ | |
845 | /* Added guarded bit to protect against speculative loads/stores */ | |
846 | li r5,0 | |
847 | ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G) | |
848 | ||
849 | li r0,63 /* TLB slot 63 */ | |
850 | ||
851 | tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */ | |
852 | tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */ | |
853 | tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */ | |
854 | ||
855 | /* Force context change */ | |
856 | mfmsr r0 | |
857 | mtspr SPRN_SRR1, r0 | |
858 | lis r0,3f@h | |
859 | ori r0,r0,3f@l | |
860 | mtspr SPRN_SRR0,r0 | |
861 | sync | |
862 | rfi | |
863 | ||
864 | /* If necessary, invalidate original entry we used */ | |
865 | 3: cmpwi r23,63 | |
866 | beq 4f | |
867 | li r6,0 | |
868 | tlbwe r6,r23,PPC44x_TLB_PAGEID | |
869 | isync | |
870 | ||
871 | 4: | |
872 | #ifdef CONFIG_PPC_EARLY_DEBUG_44x | |
873 | /* Add UART mapping for early debug. */ | |
874 | ||
875 | /* pageid fields */ | |
876 | lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h | |
877 | ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K | |
878 | ||
879 | /* xlat fields */ | |
880 | lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h | |
881 | ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH | |
882 | ||
883 | /* attrib fields */ | |
884 | li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G) | |
885 | li r0,62 /* TLB slot 0 */ | |
886 | ||
887 | tlbwe r3,r0,PPC44x_TLB_PAGEID | |
888 | tlbwe r4,r0,PPC44x_TLB_XLAT | |
889 | tlbwe r5,r0,PPC44x_TLB_ATTRIB | |
890 | ||
891 | /* Force context change */ | |
892 | isync | |
893 | #endif /* CONFIG_PPC_EARLY_DEBUG_44x */ | |
894 | ||
895 | /* Establish the interrupt vector offsets */ | |
896 | SET_IVOR(0, CriticalInput); | |
897 | SET_IVOR(1, MachineCheck); | |
898 | SET_IVOR(2, DataStorage); | |
899 | SET_IVOR(3, InstructionStorage); | |
900 | SET_IVOR(4, ExternalInput); | |
901 | SET_IVOR(5, Alignment); | |
902 | SET_IVOR(6, Program); | |
903 | SET_IVOR(7, FloatingPointUnavailable); | |
904 | SET_IVOR(8, SystemCall); | |
905 | SET_IVOR(9, AuxillaryProcessorUnavailable); | |
906 | SET_IVOR(10, Decrementer); | |
907 | SET_IVOR(11, FixedIntervalTimer); | |
908 | SET_IVOR(12, WatchdogTimer); | |
e7f75ad0 DK |
909 | SET_IVOR(13, DataTLBError44x); |
910 | SET_IVOR(14, InstructionTLBError44x); | |
795033c3 DK |
911 | SET_IVOR(15, DebugCrit); |
912 | ||
e7f75ad0 DK |
913 | b head_start_common |
914 | ||
915 | ||
916 | #ifdef CONFIG_PPC_47x | |
917 | ||
918 | #ifdef CONFIG_SMP | |
919 | ||
920 | /* Entry point for secondary 47x processors */ | |
921 | _GLOBAL(start_secondary_47x) | |
922 | mr r24,r3 /* CPU number */ | |
923 | ||
924 | bl init_cpu_state | |
925 | ||
926 | /* Now we need to bolt the rest of kernel memory which | |
927 | * is done in C code. We must be careful because our task | |
928 | * struct or our stack can (and will probably) be out | |
929 | * of reach of the initial 256M TLB entry, so we use a | |
930 | * small temporary stack in .bss for that. This works | |
931 | * because only one CPU at a time can be in this code | |
932 | */ | |
933 | lis r1,temp_boot_stack@h | |
934 | ori r1,r1,temp_boot_stack@l | |
935 | addi r1,r1,1024-STACK_FRAME_OVERHEAD | |
936 | li r0,0 | |
937 | stw r0,0(r1) | |
938 | bl mmu_init_secondary | |
939 | ||
940 | /* Now we can get our task struct and real stack pointer */ | |
941 | ||
942 | /* Get current_thread_info and current */ | |
943 | lis r1,secondary_ti@ha | |
944 | lwz r1,secondary_ti@l(r1) | |
945 | lwz r2,TI_TASK(r1) | |
946 | ||
947 | /* Current stack pointer */ | |
948 | addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD | |
949 | li r0,0 | |
950 | stw r0,0(r1) | |
951 | ||
952 | /* Kernel stack for exception entry in SPRG3 */ | |
953 | addi r4,r2,THREAD /* init task's THREAD */ | |
954 | mtspr SPRN_SPRG3,r4 | |
955 | ||
956 | b start_secondary | |
957 | ||
958 | #endif /* CONFIG_SMP */ | |
959 | ||
960 | /* | |
961 | * Set up the initial MMU state for 44x | |
962 | * | |
963 | * We are still executing code at the virtual address | |
964 | * mappings set by the firmware for the base of RAM. | |
965 | */ | |
966 | ||
967 | head_start_47x: | |
968 | /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ | |
969 | mfspr r3,SPRN_PID /* Get PID */ | |
970 | mfmsr r4 /* Get MSR */ | |
971 | andi. r4,r4,MSR_IS@l /* TS=1? */ | |
972 | beq 1f /* If not, leave STS=0 */ | |
973 | oris r3,r3,PPC47x_MMUCR_STS@h /* Set STS=1 */ | |
974 | 1: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ | |
975 | sync | |
976 | ||
977 | /* Find the entry we are running from */ | |
978 | bl 1f | |
979 | 1: mflr r23 | |
980 | tlbsx r23,0,r23 | |
981 | tlbre r24,r23,0 | |
982 | tlbre r25,r23,1 | |
983 | tlbre r26,r23,2 | |
984 | ||
985 | /* | |
986 | * Cleanup time | |
987 | */ | |
988 | ||
989 | /* Initialize MMUCR */ | |
990 | li r5,0 | |
991 | mtspr SPRN_MMUCR,r5 | |
992 | sync | |
993 | ||
994 | clear_all_utlb_entries: | |
995 | ||
996 | #; Set initial values. | |
997 | ||
998 | addis r3,0,0x8000 | |
999 | addi r4,0,0 | |
1000 | addi r5,0,0 | |
1001 | b clear_utlb_entry | |
1002 | ||
1003 | #; Align the loop to speed things up. | |
1004 | ||
1005 | .align 6 | |
1006 | ||
1007 | clear_utlb_entry: | |
1008 | ||
1009 | tlbwe r4,r3,0 | |
1010 | tlbwe r5,r3,1 | |
1011 | tlbwe r5,r3,2 | |
1012 | addis r3,r3,0x2000 | |
1013 | cmpwi r3,0 | |
1014 | bne clear_utlb_entry | |
1015 | addis r3,0,0x8000 | |
1016 | addis r4,r4,0x100 | |
1017 | cmpwi r4,0 | |
1018 | bne clear_utlb_entry | |
1019 | ||
1020 | #; Restore original entry. | |
1021 | ||
1022 | oris r23,r23,0x8000 /* specify the way */ | |
1023 | tlbwe r24,r23,0 | |
1024 | tlbwe r25,r23,1 | |
1025 | tlbwe r26,r23,2 | |
1026 | ||
1027 | /* | |
1028 | * Configure and load pinned entry into TLB for the kernel core | |
1029 | */ | |
1030 | ||
1031 | lis r3,PAGE_OFFSET@h | |
1032 | ori r3,r3,PAGE_OFFSET@l | |
1033 | ||
e7f75ad0 DK |
1034 | /* Load the kernel PID = 0 */ |
1035 | li r0,0 | |
1036 | mtspr SPRN_PID,r0 | |
1037 | sync | |
1038 | ||
1039 | /* Word 0 */ | |
1040 | clrrwi r3,r3,12 /* Mask off the effective page number */ | |
1041 | ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M | |
1042 | ||
9661534d DK |
1043 | /* Word 1 - use r25. RPN is the same as the original entry */ |
1044 | ||
e7f75ad0 DK |
1045 | /* Word 2 */ |
1046 | li r5,0 | |
1047 | ori r5,r5,PPC47x_TLB2_S_RWX | |
1048 | #ifdef CONFIG_SMP | |
1049 | ori r5,r5,PPC47x_TLB2_M | |
1050 | #endif | |
1051 | ||
1052 | /* We write to way 0 and bolted 0 */ | |
1053 | lis r0,0x8800 | |
1054 | tlbwe r3,r0,0 | |
9661534d | 1055 | tlbwe r25,r0,1 |
e7f75ad0 DK |
1056 | tlbwe r5,r0,2 |
1057 | ||
1058 | /* | |
1059 | * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix | |
1060 | * them up later | |
1061 | */ | |
1062 | LOAD_REG_IMMEDIATE(r3, 0x9abcdef0) | |
1063 | mtspr SPRN_SSPCR,r3 | |
1064 | mtspr SPRN_USPCR,r3 | |
1065 | LOAD_REG_IMMEDIATE(r3, 0x12345670) | |
1066 | mtspr SPRN_ISPCR,r3 | |
1067 | ||
1068 | /* Force context change */ | |
1069 | mfmsr r0 | |
1070 | mtspr SPRN_SRR1, r0 | |
1071 | lis r0,3f@h | |
1072 | ori r0,r0,3f@l | |
1073 | mtspr SPRN_SRR0,r0 | |
1074 | sync | |
1075 | rfi | |
1076 | ||
1077 | /* Invalidate original entry we used */ | |
1078 | 3: | |
1079 | rlwinm r24,r24,0,21,19 /* clear the "valid" bit */ | |
1080 | tlbwe r24,r23,0 | |
1081 | addi r24,0,0 | |
1082 | tlbwe r24,r23,1 | |
1083 | tlbwe r24,r23,2 | |
1084 | isync /* Clear out the shadow TLB entries */ | |
1085 | ||
1086 | #ifdef CONFIG_PPC_EARLY_DEBUG_44x | |
1087 | /* Add UART mapping for early debug. */ | |
1088 | ||
1089 | /* Word 0 */ | |
1090 | lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h | |
1091 | ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M | |
1092 | ||
1093 | /* Word 1 */ | |
1094 | lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h | |
1095 | ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH | |
1096 | ||
1097 | /* Word 2 */ | |
1098 | li r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG) | |
1099 | ||
1100 | /* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same | |
1101 | * congruence class as the kernel, we need to make sure of it at | |
1102 | * some point | |
1103 | */ | |
1104 | lis r0,0x8d00 | |
1105 | tlbwe r3,r0,0 | |
1106 | tlbwe r4,r0,1 | |
1107 | tlbwe r5,r0,2 | |
1108 | ||
1109 | /* Force context change */ | |
1110 | isync | |
1111 | #endif /* CONFIG_PPC_EARLY_DEBUG_44x */ | |
1112 | ||
1113 | /* Establish the interrupt vector offsets */ | |
1114 | SET_IVOR(0, CriticalInput); | |
1115 | SET_IVOR(1, MachineCheckA); | |
1116 | SET_IVOR(2, DataStorage); | |
1117 | SET_IVOR(3, InstructionStorage); | |
1118 | SET_IVOR(4, ExternalInput); | |
1119 | SET_IVOR(5, Alignment); | |
1120 | SET_IVOR(6, Program); | |
1121 | SET_IVOR(7, FloatingPointUnavailable); | |
1122 | SET_IVOR(8, SystemCall); | |
1123 | SET_IVOR(9, AuxillaryProcessorUnavailable); | |
1124 | SET_IVOR(10, Decrementer); | |
1125 | SET_IVOR(11, FixedIntervalTimer); | |
1126 | SET_IVOR(12, WatchdogTimer); | |
1127 | SET_IVOR(13, DataTLBError47x); | |
1128 | SET_IVOR(14, InstructionTLBError47x); | |
1129 | SET_IVOR(15, DebugCrit); | |
1130 | ||
1131 | /* We configure icbi to invalidate 128 bytes at a time since the | |
1132 | * current 32-bit kernel code isn't too happy with icache != dcache | |
1133 | * block size | |
1134 | */ | |
1135 | mfspr r3,SPRN_CCR0 | |
1136 | oris r3,r3,0x0020 | |
1137 | mtspr SPRN_CCR0,r3 | |
1138 | isync | |
1139 | ||
1140 | #endif /* CONFIG_PPC_47x */ | |
1141 | ||
1142 | /* | |
1143 | * Here we are back to code that is common between 44x and 47x | |
1144 | * | |
1145 | * We proceed to further kernel initialization and return to the | |
1146 | * main kernel entry | |
1147 | */ | |
1148 | head_start_common: | |
795033c3 DK |
1149 | /* Establish the interrupt vector base */ |
1150 | lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */ | |
1151 | mtspr SPRN_IVPR,r4 | |
1152 | ||
9661534d DK |
1153 | /* |
1154 | * If the kernel was loaded at a non-zero 256 MB page, we need to | |
1155 | * mask off the most significant 4 bits to get the relative address | |
1156 | * from the start of physical memory | |
1157 | */ | |
1158 | rlwinm r22,r22,0,4,31 | |
1159 | addis r22,r22,PAGE_OFFSET@h | |
795033c3 | 1160 | mtlr r22 |
e7f75ad0 | 1161 | isync |
795033c3 DK |
1162 | blr |
1163 | ||
14cf11af PM |
1164 | /* |
1165 | * We put a few things here that have to be page-aligned. This stuff | |
1166 | * goes at the beginning of the data segment, which is page-aligned. | |
1167 | */ | |
1168 | .data | |
ca9153a3 | 1169 | .align PAGE_SHIFT |
ea703ce2 KG |
1170 | .globl sdata |
1171 | sdata: | |
1172 | .globl empty_zero_page | |
1173 | empty_zero_page: | |
ca9153a3 | 1174 | .space PAGE_SIZE |
14cf11af PM |
1175 | |
1176 | /* | |
1177 | * To support >32-bit physical addresses, we use an 8KB pgdir. | |
1178 | */ | |
ea703ce2 KG |
1179 | .globl swapper_pg_dir |
1180 | swapper_pg_dir: | |
bee86f14 | 1181 | .space PGD_TABLE_SIZE |
14cf11af | 1182 | |
14cf11af PM |
1183 | /* |
1184 | * Room for two PTE pointers, usually the kernel and current user pointers | |
1185 | * to their respective root page table. | |
1186 | */ | |
1187 | abatron_pteptrs: | |
1188 | .space 8 | |
e7f75ad0 DK |
1189 | |
1190 | #ifdef CONFIG_SMP | |
1191 | .align 12 | |
1192 | temp_boot_stack: | |
1193 | .space 1024 | |
1194 | #endif /* CONFIG_SMP */ |