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> | |
40 | #include "head_booke.h" | |
41 | ||
42 | ||
43 | /* As with the other PowerPC ports, it is expected that when code | |
44 | * execution begins here, the following registers contain valid, yet | |
45 | * optional, information: | |
46 | * | |
47 | * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.) | |
48 | * r4 - Starting address of the init RAM disk | |
49 | * r5 - Ending address of the init RAM disk | |
50 | * r6 - Start of kernel command line string (e.g. "mem=128") | |
51 | * r7 - End of kernel command line string | |
52 | * | |
53 | */ | |
e7039845 | 54 | __HEAD |
748a7683 KG |
55 | _ENTRY(_stext); |
56 | _ENTRY(_start); | |
14cf11af PM |
57 | /* |
58 | * Reserve a word at a fixed location to store the address | |
59 | * of abatron_pteptrs | |
60 | */ | |
61 | nop | |
62 | /* | |
63 | * Save parameters we are passed | |
64 | */ | |
65 | mr r31,r3 | |
66 | mr r30,r4 | |
67 | mr r29,r5 | |
68 | mr r28,r6 | |
69 | mr r27,r7 | |
70 | li r24,0 /* CPU number */ | |
71 | ||
795033c3 | 72 | bl init_cpu_state |
14cf11af | 73 | |
14cf11af PM |
74 | /* |
75 | * This is where the main kernel code starts. | |
76 | */ | |
77 | ||
78 | /* ptr to current */ | |
79 | lis r2,init_task@h | |
80 | ori r2,r2,init_task@l | |
81 | ||
82 | /* ptr to current thread */ | |
83 | addi r4,r2,THREAD /* init task's THREAD */ | |
ee43eb78 | 84 | mtspr SPRN_SPRG_THREAD,r4 |
14cf11af PM |
85 | |
86 | /* stack */ | |
87 | lis r1,init_thread_union@h | |
88 | ori r1,r1,init_thread_union@l | |
89 | li r0,0 | |
90 | stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) | |
91 | ||
92 | bl early_init | |
93 | ||
94 | /* | |
95 | * Decide what sort of machine this is and initialize the MMU. | |
96 | */ | |
97 | mr r3,r31 | |
98 | mr r4,r30 | |
99 | mr r5,r29 | |
100 | mr r6,r28 | |
101 | mr r7,r27 | |
102 | bl machine_init | |
103 | bl MMU_init | |
104 | ||
105 | /* Setup PTE pointers for the Abatron bdiGDB */ | |
106 | lis r6, swapper_pg_dir@h | |
107 | ori r6, r6, swapper_pg_dir@l | |
108 | lis r5, abatron_pteptrs@h | |
109 | ori r5, r5, abatron_pteptrs@l | |
110 | lis r4, KERNELBASE@h | |
111 | ori r4, r4, KERNELBASE@l | |
112 | stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */ | |
113 | stw r6, 0(r5) | |
114 | ||
115 | /* Let's move on */ | |
116 | lis r4,start_kernel@h | |
117 | ori r4,r4,start_kernel@l | |
118 | lis r3,MSR_KERNEL@h | |
119 | ori r3,r3,MSR_KERNEL@l | |
120 | mtspr SPRN_SRR0,r4 | |
121 | mtspr SPRN_SRR1,r3 | |
122 | rfi /* change context and jump to start_kernel */ | |
123 | ||
124 | /* | |
125 | * Interrupt vector entry code | |
126 | * | |
127 | * The Book E MMUs are always on so we don't need to handle | |
128 | * interrupts in real mode as with previous PPC processors. In | |
129 | * this case we handle interrupts in the kernel virtual address | |
130 | * space. | |
131 | * | |
132 | * Interrupt vectors are dynamically placed relative to the | |
133 | * interrupt prefix as determined by the address of interrupt_base. | |
134 | * The interrupt vectors offsets are programmed using the labels | |
135 | * for each interrupt vector entry. | |
136 | * | |
137 | * Interrupt vectors must be aligned on a 16 byte boundary. | |
138 | * We align on a 32 byte cache line boundary for good measure. | |
139 | */ | |
140 | ||
141 | interrupt_base: | |
142 | /* Critical Input Interrupt */ | |
dc1c1ca3 | 143 | CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception) |
14cf11af PM |
144 | |
145 | /* Machine Check Interrupt */ | |
dc1c1ca3 | 146 | CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception) |
47c0bd1a | 147 | MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception) |
14cf11af PM |
148 | |
149 | /* Data Storage Interrupt */ | |
1bc54c03 | 150 | DATA_STORAGE_EXCEPTION |
14cf11af | 151 | |
1bc54c03 | 152 | /* Instruction Storage Interrupt */ |
14cf11af PM |
153 | INSTRUCTION_STORAGE_EXCEPTION |
154 | ||
155 | /* External Input Interrupt */ | |
156 | EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE) | |
157 | ||
158 | /* Alignment Interrupt */ | |
159 | ALIGNMENT_EXCEPTION | |
160 | ||
161 | /* Program Interrupt */ | |
162 | PROGRAM_EXCEPTION | |
163 | ||
164 | /* Floating Point Unavailable Interrupt */ | |
165 | #ifdef CONFIG_PPC_FPU | |
166 | FP_UNAVAILABLE_EXCEPTION | |
167 | #else | |
dc1c1ca3 | 168 | EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE) |
14cf11af | 169 | #endif |
14cf11af PM |
170 | /* System Call Interrupt */ |
171 | START_EXCEPTION(SystemCall) | |
172 | NORMAL_EXCEPTION_PROLOG | |
173 | EXC_XFER_EE_LITE(0x0c00, DoSyscall) | |
174 | ||
175 | /* Auxillary Processor Unavailable Interrupt */ | |
dc1c1ca3 | 176 | EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE) |
14cf11af PM |
177 | |
178 | /* Decrementer Interrupt */ | |
179 | DECREMENTER_EXCEPTION | |
180 | ||
181 | /* Fixed Internal Timer Interrupt */ | |
182 | /* TODO: Add FIT support */ | |
dc1c1ca3 | 183 | EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE) |
14cf11af PM |
184 | |
185 | /* Watchdog Timer Interrupt */ | |
186 | /* TODO: Add watchdog support */ | |
187 | #ifdef CONFIG_BOOKE_WDT | |
188 | CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException) | |
189 | #else | |
dc1c1ca3 | 190 | CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception) |
14cf11af PM |
191 | #endif |
192 | ||
193 | /* Data TLB Error Interrupt */ | |
194 | START_EXCEPTION(DataTLBError) | |
ee43eb78 BH |
195 | mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ |
196 | mtspr SPRN_SPRG_WSCRATCH1, r11 | |
197 | mtspr SPRN_SPRG_WSCRATCH2, r12 | |
198 | mtspr SPRN_SPRG_WSCRATCH3, r13 | |
14cf11af | 199 | mfcr r11 |
ee43eb78 | 200 | mtspr SPRN_SPRG_WSCRATCH4, r11 |
14cf11af PM |
201 | mfspr r10, SPRN_DEAR /* Get faulting address */ |
202 | ||
203 | /* If we are faulting a kernel address, we have to use the | |
204 | * kernel page tables. | |
205 | */ | |
8a13c4f9 | 206 | lis r11, PAGE_OFFSET@h |
14cf11af PM |
207 | cmplw r10, r11 |
208 | blt+ 3f | |
209 | lis r11, swapper_pg_dir@h | |
210 | ori r11, r11, swapper_pg_dir@l | |
211 | ||
212 | mfspr r12,SPRN_MMUCR | |
213 | rlwinm r12,r12,0,0,23 /* Clear TID */ | |
214 | ||
215 | b 4f | |
216 | ||
217 | /* Get the PGD for the current thread */ | |
218 | 3: | |
ee43eb78 | 219 | mfspr r11,SPRN_SPRG_THREAD |
14cf11af PM |
220 | lwz r11,PGDIR(r11) |
221 | ||
222 | /* Load PID into MMUCR TID */ | |
223 | mfspr r12,SPRN_MMUCR | |
224 | mfspr r13,SPRN_PID /* Get PID */ | |
225 | rlwimi r12,r13,0,24,31 /* Set TID */ | |
226 | ||
227 | 4: | |
228 | mtspr SPRN_MMUCR,r12 | |
229 | ||
1bc54c03 BH |
230 | /* Mask of required permission bits. Note that while we |
231 | * do copy ESR:ST to _PAGE_RW position as trying to write | |
232 | * to an RO page is pretty common, we don't do it with | |
233 | * _PAGE_DIRTY. We could do it, but it's a fairly rare | |
234 | * event so I'd rather take the overhead when it happens | |
235 | * rather than adding an instruction here. We should measure | |
236 | * whether the whole thing is worth it in the first place | |
237 | * as we could avoid loading SPRN_ESR completely in the first | |
238 | * place... | |
239 | * | |
240 | * TODO: Is it worth doing that mfspr & rlwimi in the first | |
241 | * place or can we save a couple of instructions here ? | |
242 | */ | |
243 | mfspr r12,SPRN_ESR | |
244 | li r13,_PAGE_PRESENT|_PAGE_ACCESSED | |
245 | rlwimi r13,r12,10,30,30 | |
246 | ||
247 | /* Load the PTE */ | |
ca9153a3 IY |
248 | /* Compute pgdir/pmd offset */ |
249 | rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 | |
14cf11af PM |
250 | lwzx r11, r12, r11 /* Get pgd/pmd entry */ |
251 | rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ | |
252 | beq 2f /* Bail if no table */ | |
253 | ||
ca9153a3 IY |
254 | /* Compute pte address */ |
255 | rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 | |
1bc54c03 BH |
256 | lwz r11, 0(r12) /* Get high word of pte entry */ |
257 | lwz r12, 4(r12) /* Get low word of pte entry */ | |
14cf11af | 258 | |
1bc54c03 BH |
259 | lis r10,tlb_44x_index@ha |
260 | ||
261 | andc. r13,r13,r12 /* Check permission */ | |
262 | ||
263 | /* Load the next available TLB index */ | |
264 | lwz r13,tlb_44x_index@l(r10) | |
265 | ||
266 | bne 2f /* Bail if permission mismach */ | |
267 | ||
268 | /* Increment, rollover, and store TLB index */ | |
269 | addi r13,r13,1 | |
270 | ||
271 | /* Compare with watermark (instruction gets patched) */ | |
272 | .globl tlb_44x_patch_hwater_D | |
273 | tlb_44x_patch_hwater_D: | |
274 | cmpwi 0,r13,1 /* reserve entries */ | |
275 | ble 5f | |
276 | li r13,0 | |
277 | 5: | |
278 | /* Store the next available TLB index */ | |
279 | stw r13,tlb_44x_index@l(r10) | |
280 | ||
281 | /* Re-load the faulting address */ | |
282 | mfspr r10,SPRN_DEAR | |
14cf11af PM |
283 | |
284 | /* Jump to common tlb load */ | |
285 | b finish_tlb_load | |
286 | ||
287 | 2: | |
288 | /* The bailout. Restore registers to pre-exception conditions | |
289 | * and call the heavyweights to help us out. | |
290 | */ | |
ee43eb78 | 291 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
14cf11af | 292 | mtcr r11 |
ee43eb78 BH |
293 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
294 | mfspr r12, SPRN_SPRG_RSCRATCH2 | |
295 | mfspr r11, SPRN_SPRG_RSCRATCH1 | |
296 | mfspr r10, SPRN_SPRG_RSCRATCH0 | |
1bc54c03 | 297 | b DataStorage |
14cf11af PM |
298 | |
299 | /* Instruction TLB Error Interrupt */ | |
300 | /* | |
301 | * Nearly the same as above, except we get our | |
302 | * information from different registers and bailout | |
303 | * to a different point. | |
304 | */ | |
305 | START_EXCEPTION(InstructionTLBError) | |
ee43eb78 BH |
306 | mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ |
307 | mtspr SPRN_SPRG_WSCRATCH1, r11 | |
308 | mtspr SPRN_SPRG_WSCRATCH2, r12 | |
309 | mtspr SPRN_SPRG_WSCRATCH3, r13 | |
14cf11af | 310 | mfcr r11 |
ee43eb78 | 311 | mtspr SPRN_SPRG_WSCRATCH4, r11 |
14cf11af PM |
312 | mfspr r10, SPRN_SRR0 /* Get faulting address */ |
313 | ||
314 | /* If we are faulting a kernel address, we have to use the | |
315 | * kernel page tables. | |
316 | */ | |
8a13c4f9 | 317 | lis r11, PAGE_OFFSET@h |
14cf11af PM |
318 | cmplw r10, r11 |
319 | blt+ 3f | |
320 | lis r11, swapper_pg_dir@h | |
321 | ori r11, r11, swapper_pg_dir@l | |
322 | ||
323 | mfspr r12,SPRN_MMUCR | |
324 | rlwinm r12,r12,0,0,23 /* Clear TID */ | |
325 | ||
326 | b 4f | |
327 | ||
328 | /* Get the PGD for the current thread */ | |
329 | 3: | |
ee43eb78 | 330 | mfspr r11,SPRN_SPRG_THREAD |
14cf11af PM |
331 | lwz r11,PGDIR(r11) |
332 | ||
333 | /* Load PID into MMUCR TID */ | |
334 | mfspr r12,SPRN_MMUCR | |
335 | mfspr r13,SPRN_PID /* Get PID */ | |
336 | rlwimi r12,r13,0,24,31 /* Set TID */ | |
337 | ||
338 | 4: | |
339 | mtspr SPRN_MMUCR,r12 | |
340 | ||
1bc54c03 | 341 | /* Make up the required permissions */ |
ea3cc330 | 342 | li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC |
1bc54c03 | 343 | |
ca9153a3 IY |
344 | /* Compute pgdir/pmd offset */ |
345 | rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 | |
14cf11af PM |
346 | lwzx r11, r12, r11 /* Get pgd/pmd entry */ |
347 | rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ | |
348 | beq 2f /* Bail if no table */ | |
349 | ||
ca9153a3 IY |
350 | /* Compute pte address */ |
351 | rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 | |
1bc54c03 BH |
352 | lwz r11, 0(r12) /* Get high word of pte entry */ |
353 | lwz r12, 4(r12) /* Get low word of pte entry */ | |
14cf11af | 354 | |
1bc54c03 BH |
355 | lis r10,tlb_44x_index@ha |
356 | ||
357 | andc. r13,r13,r12 /* Check permission */ | |
358 | ||
359 | /* Load the next available TLB index */ | |
360 | lwz r13,tlb_44x_index@l(r10) | |
361 | ||
362 | bne 2f /* Bail if permission mismach */ | |
363 | ||
364 | /* Increment, rollover, and store TLB index */ | |
365 | addi r13,r13,1 | |
366 | ||
367 | /* Compare with watermark (instruction gets patched) */ | |
368 | .globl tlb_44x_patch_hwater_I | |
369 | tlb_44x_patch_hwater_I: | |
370 | cmpwi 0,r13,1 /* reserve entries */ | |
371 | ble 5f | |
372 | li r13,0 | |
373 | 5: | |
374 | /* Store the next available TLB index */ | |
375 | stw r13,tlb_44x_index@l(r10) | |
376 | ||
377 | /* Re-load the faulting address */ | |
378 | mfspr r10,SPRN_SRR0 | |
14cf11af PM |
379 | |
380 | /* Jump to common TLB load point */ | |
381 | b finish_tlb_load | |
382 | ||
383 | 2: | |
384 | /* The bailout. Restore registers to pre-exception conditions | |
385 | * and call the heavyweights to help us out. | |
386 | */ | |
ee43eb78 | 387 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
14cf11af | 388 | mtcr r11 |
ee43eb78 BH |
389 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
390 | mfspr r12, SPRN_SPRG_RSCRATCH2 | |
391 | mfspr r11, SPRN_SPRG_RSCRATCH1 | |
392 | mfspr r10, SPRN_SPRG_RSCRATCH0 | |
14cf11af PM |
393 | b InstructionStorage |
394 | ||
395 | /* Debug Interrupt */ | |
eb0cd5fd | 396 | DEBUG_CRIT_EXCEPTION |
14cf11af PM |
397 | |
398 | /* | |
399 | * Local functions | |
1bc54c03 | 400 | */ |
14cf11af PM |
401 | |
402 | /* | |
403 | ||
404 | * Both the instruction and data TLB miss get to this | |
405 | * point to load the TLB. | |
406 | * r10 - EA of fault | |
1bc54c03 BH |
407 | * r11 - PTE high word value |
408 | * r12 - PTE low word value | |
409 | * r13 - TLB index | |
14cf11af PM |
410 | * MMUCR - loaded with proper value when we get here |
411 | * Upon exit, we reload everything and RFI. | |
412 | */ | |
413 | finish_tlb_load: | |
1bc54c03 | 414 | /* Combine RPN & ERPN an write WS 0 */ |
ca9153a3 | 415 | rlwimi r11,r12,0,0,31-PAGE_SHIFT |
1bc54c03 | 416 | tlbwe r11,r13,PPC44x_TLB_XLAT |
14cf11af PM |
417 | |
418 | /* | |
1bc54c03 | 419 | * Create WS1. This is the faulting address (EPN), |
14cf11af PM |
420 | * page size, and valid flag. |
421 | */ | |
ca9153a3 IY |
422 | li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE |
423 | /* Insert valid and page size */ | |
424 | rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31 | |
1bc54c03 BH |
425 | tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */ |
426 | ||
427 | /* And WS 2 */ | |
428 | li r10,0xf85 /* Mask to apply from PTE */ | |
429 | rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ | |
430 | and r11,r12,r10 /* Mask PTE bits to keep */ | |
431 | andi. r10,r12,_PAGE_USER /* User page ? */ | |
432 | beq 1f /* nope, leave U bits empty */ | |
433 | rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ | |
434 | 1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */ | |
14cf11af PM |
435 | |
436 | /* Done...restore registers and get out of here. | |
437 | */ | |
ee43eb78 | 438 | mfspr r11, SPRN_SPRG_RSCRATCH4 |
14cf11af | 439 | mtcr r11 |
ee43eb78 BH |
440 | mfspr r13, SPRN_SPRG_RSCRATCH3 |
441 | mfspr r12, SPRN_SPRG_RSCRATCH2 | |
442 | mfspr r11, SPRN_SPRG_RSCRATCH1 | |
443 | mfspr r10, SPRN_SPRG_RSCRATCH0 | |
14cf11af PM |
444 | rfi /* Force context change */ |
445 | ||
446 | /* | |
447 | * Global functions | |
448 | */ | |
449 | ||
47c0bd1a BH |
450 | /* |
451 | * Adjust the machine check IVOR on 440A cores | |
452 | */ | |
453 | _GLOBAL(__fixup_440A_mcheck) | |
454 | li r3,MachineCheckA@l | |
455 | mtspr SPRN_IVOR1,r3 | |
456 | sync | |
457 | blr | |
458 | ||
14cf11af PM |
459 | /* |
460 | * extern void giveup_altivec(struct task_struct *prev) | |
461 | * | |
462 | * The 44x core does not have an AltiVec unit. | |
463 | */ | |
464 | _GLOBAL(giveup_altivec) | |
465 | blr | |
466 | ||
467 | /* | |
468 | * extern void giveup_fpu(struct task_struct *prev) | |
469 | * | |
470 | * The 44x core does not have an FPU. | |
471 | */ | |
472 | #ifndef CONFIG_PPC_FPU | |
473 | _GLOBAL(giveup_fpu) | |
474 | blr | |
475 | #endif | |
476 | ||
14cf11af PM |
477 | _GLOBAL(set_context) |
478 | ||
479 | #ifdef CONFIG_BDI_SWITCH | |
480 | /* Context switch the PTE pointer for the Abatron BDI2000. | |
481 | * The PGDIR is the second parameter. | |
482 | */ | |
483 | lis r5, abatron_pteptrs@h | |
484 | ori r5, r5, abatron_pteptrs@l | |
485 | stw r4, 0x4(r5) | |
486 | #endif | |
487 | mtspr SPRN_PID,r3 | |
488 | isync /* Force context change */ | |
489 | blr | |
490 | ||
795033c3 DK |
491 | /* |
492 | * Init CPU state. This is called at boot time or for secondary CPUs | |
493 | * to setup initial TLB entries, setup IVORs, etc... | |
494 | */ | |
495 | _GLOBAL(init_cpu_state) | |
496 | mflr r22 | |
497 | /* | |
498 | * In case the firmware didn't do it, we apply some workarounds | |
499 | * that are good for all 440 core variants here | |
500 | */ | |
501 | mfspr r3,SPRN_CCR0 | |
502 | rlwinm r3,r3,0,0,27 /* disable icache prefetch */ | |
503 | isync | |
504 | mtspr SPRN_CCR0,r3 | |
505 | isync | |
506 | sync | |
507 | ||
508 | /* | |
509 | * Set up the initial MMU state | |
510 | * | |
511 | * We are still executing code at the virtual address | |
512 | * mappings set by the firmware for the base of RAM. | |
513 | * | |
514 | * We first invalidate all TLB entries but the one | |
515 | * we are running from. We then load the KERNELBASE | |
516 | * mappings so we can begin to use kernel addresses | |
517 | * natively and so the interrupt vector locations are | |
518 | * permanently pinned (necessary since Book E | |
519 | * implementations always have translation enabled). | |
520 | * | |
521 | * TODO: Use the known TLB entry we are running from to | |
522 | * determine which physical region we are located | |
523 | * in. This can be used to determine where in RAM | |
524 | * (on a shared CPU system) or PCI memory space | |
525 | * (on a DRAMless system) we are located. | |
526 | * For now, we assume a perfect world which means | |
527 | * we are located at the base of DRAM (physical 0). | |
528 | */ | |
529 | ||
530 | /* | |
531 | * Search TLB for entry that we are currently using. | |
532 | * Invalidate all entries but the one we are using. | |
533 | */ | |
534 | /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ | |
535 | mfspr r3,SPRN_PID /* Get PID */ | |
536 | mfmsr r4 /* Get MSR */ | |
537 | andi. r4,r4,MSR_IS@l /* TS=1? */ | |
538 | beq wmmucr /* If not, leave STS=0 */ | |
539 | oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */ | |
540 | wmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ | |
541 | sync | |
542 | ||
543 | bl invstr /* Find our address */ | |
544 | invstr: mflr r5 /* Make it accessible */ | |
545 | tlbsx r23,0,r5 /* Find entry we are in */ | |
546 | li r4,0 /* Start at TLB entry 0 */ | |
547 | li r3,0 /* Set PAGEID inval value */ | |
548 | 1: cmpw r23,r4 /* Is this our entry? */ | |
549 | beq skpinv /* If so, skip the inval */ | |
550 | tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */ | |
551 | skpinv: addi r4,r4,1 /* Increment */ | |
552 | cmpwi r4,64 /* Are we done? */ | |
553 | bne 1b /* If not, repeat */ | |
554 | isync /* If so, context change */ | |
555 | ||
556 | /* | |
557 | * Configure and load pinned entry into TLB slot 63. | |
558 | */ | |
559 | ||
560 | lis r3,PAGE_OFFSET@h | |
561 | ori r3,r3,PAGE_OFFSET@l | |
562 | ||
563 | /* Kernel is at the base of RAM */ | |
564 | li r4, 0 /* Load the kernel physical address */ | |
565 | ||
566 | /* Load the kernel PID = 0 */ | |
567 | li r0,0 | |
568 | mtspr SPRN_PID,r0 | |
569 | sync | |
570 | ||
571 | /* Initialize MMUCR */ | |
572 | li r5,0 | |
573 | mtspr SPRN_MMUCR,r5 | |
574 | sync | |
575 | ||
576 | /* pageid fields */ | |
577 | clrrwi r3,r3,10 /* Mask off the effective page number */ | |
578 | ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M | |
579 | ||
580 | /* xlat fields */ | |
581 | clrrwi r4,r4,10 /* Mask off the real page number */ | |
582 | /* ERPN is 0 for first 4GB page */ | |
583 | ||
584 | /* attrib fields */ | |
585 | /* Added guarded bit to protect against speculative loads/stores */ | |
586 | li r5,0 | |
587 | ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G) | |
588 | ||
589 | li r0,63 /* TLB slot 63 */ | |
590 | ||
591 | tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */ | |
592 | tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */ | |
593 | tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */ | |
594 | ||
595 | /* Force context change */ | |
596 | mfmsr r0 | |
597 | mtspr SPRN_SRR1, r0 | |
598 | lis r0,3f@h | |
599 | ori r0,r0,3f@l | |
600 | mtspr SPRN_SRR0,r0 | |
601 | sync | |
602 | rfi | |
603 | ||
604 | /* If necessary, invalidate original entry we used */ | |
605 | 3: cmpwi r23,63 | |
606 | beq 4f | |
607 | li r6,0 | |
608 | tlbwe r6,r23,PPC44x_TLB_PAGEID | |
609 | isync | |
610 | ||
611 | 4: | |
612 | #ifdef CONFIG_PPC_EARLY_DEBUG_44x | |
613 | /* Add UART mapping for early debug. */ | |
614 | ||
615 | /* pageid fields */ | |
616 | lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h | |
617 | ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K | |
618 | ||
619 | /* xlat fields */ | |
620 | lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h | |
621 | ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH | |
622 | ||
623 | /* attrib fields */ | |
624 | li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G) | |
625 | li r0,62 /* TLB slot 0 */ | |
626 | ||
627 | tlbwe r3,r0,PPC44x_TLB_PAGEID | |
628 | tlbwe r4,r0,PPC44x_TLB_XLAT | |
629 | tlbwe r5,r0,PPC44x_TLB_ATTRIB | |
630 | ||
631 | /* Force context change */ | |
632 | isync | |
633 | #endif /* CONFIG_PPC_EARLY_DEBUG_44x */ | |
634 | ||
635 | /* Establish the interrupt vector offsets */ | |
636 | SET_IVOR(0, CriticalInput); | |
637 | SET_IVOR(1, MachineCheck); | |
638 | SET_IVOR(2, DataStorage); | |
639 | SET_IVOR(3, InstructionStorage); | |
640 | SET_IVOR(4, ExternalInput); | |
641 | SET_IVOR(5, Alignment); | |
642 | SET_IVOR(6, Program); | |
643 | SET_IVOR(7, FloatingPointUnavailable); | |
644 | SET_IVOR(8, SystemCall); | |
645 | SET_IVOR(9, AuxillaryProcessorUnavailable); | |
646 | SET_IVOR(10, Decrementer); | |
647 | SET_IVOR(11, FixedIntervalTimer); | |
648 | SET_IVOR(12, WatchdogTimer); | |
649 | SET_IVOR(13, DataTLBError); | |
650 | SET_IVOR(14, InstructionTLBError); | |
651 | SET_IVOR(15, DebugCrit); | |
652 | ||
653 | /* Establish the interrupt vector base */ | |
654 | lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */ | |
655 | mtspr SPRN_IVPR,r4 | |
656 | ||
657 | addis r22,r22,KERNELBASE@h | |
658 | mtlr r22 | |
659 | blr | |
660 | ||
14cf11af PM |
661 | /* |
662 | * We put a few things here that have to be page-aligned. This stuff | |
663 | * goes at the beginning of the data segment, which is page-aligned. | |
664 | */ | |
665 | .data | |
ca9153a3 | 666 | .align PAGE_SHIFT |
ea703ce2 KG |
667 | .globl sdata |
668 | sdata: | |
669 | .globl empty_zero_page | |
670 | empty_zero_page: | |
ca9153a3 | 671 | .space PAGE_SIZE |
14cf11af PM |
672 | |
673 | /* | |
674 | * To support >32-bit physical addresses, we use an 8KB pgdir. | |
675 | */ | |
ea703ce2 KG |
676 | .globl swapper_pg_dir |
677 | swapper_pg_dir: | |
bee86f14 | 678 | .space PGD_TABLE_SIZE |
14cf11af | 679 | |
14cf11af PM |
680 | /* |
681 | * Room for two PTE pointers, usually the kernel and current user pointers | |
682 | * to their respective root page table. | |
683 | */ | |
684 | abatron_pteptrs: | |
685 | .space 8 |