powerpc/32: Allow __ioremap on RAM addresses for kdump kernel
[linux-block.git] / arch / powerpc / kernel / head_32.S
CommitLineData
14cf11af
PM
1/*
2 * PowerPC version
3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4 *
5 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
6 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
7 * Adapted for Power Macintosh by Paul Mackerras.
8 * Low-level exception handlers and MMU support
9 * rewritten by Paul Mackerras.
10 * Copyright (C) 1996 Paul Mackerras.
11 * MPC8xx modifications Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
14cf11af
PM
12 *
13 * This file contains the low-level support and setup for the
14 * PowerPC platform, including trap and interrupt dispatch.
15 * (The PPC 8xx embedded CPUs use head_8xx.S instead.)
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
21 *
22 */
23
b3b8dc6c 24#include <asm/reg.h>
14cf11af
PM
25#include <asm/page.h>
26#include <asm/mmu.h>
27#include <asm/pgtable.h>
28#include <asm/cputable.h>
29#include <asm/cache.h>
30#include <asm/thread_info.h>
31#include <asm/ppc_asm.h>
32#include <asm/asm-offsets.h>
ec2b36b9 33#include <asm/ptrace.h>
5e696617 34#include <asm/bug.h>
14cf11af 35
14cf11af
PM
36/* 601 only have IBAT; cr0.eq is set on 601 when using this macro */
37#define LOAD_BAT(n, reg, RA, RB) \
38 /* see the comment for clear_bats() -- Cort */ \
39 li RA,0; \
40 mtspr SPRN_IBAT##n##U,RA; \
41 mtspr SPRN_DBAT##n##U,RA; \
42 lwz RA,(n*16)+0(reg); \
43 lwz RB,(n*16)+4(reg); \
44 mtspr SPRN_IBAT##n##U,RA; \
45 mtspr SPRN_IBAT##n##L,RB; \
46 beq 1f; \
47 lwz RA,(n*16)+8(reg); \
48 lwz RB,(n*16)+12(reg); \
49 mtspr SPRN_DBAT##n##U,RA; \
50 mtspr SPRN_DBAT##n##L,RB; \
511:
14cf11af 52
748a7683 53 .section .text.head, "ax"
b3b8dc6c
PM
54 .stabs "arch/powerpc/kernel/",N_SO,0,0,0f
55 .stabs "head_32.S",N_SO,0,0,0f
14cf11af 560:
748a7683 57_ENTRY(_stext);
14cf11af
PM
58
59/*
60 * _start is defined this way because the XCOFF loader in the OpenFirmware
61 * on the powermac expects the entry point to be a procedure descriptor.
62 */
748a7683 63_ENTRY(_start);
14cf11af
PM
64 /*
65 * These are here for legacy reasons, the kernel used to
66 * need to look like a coff function entry for the pmac
67 * but we're always started by some kind of bootloader now.
68 * -- Cort
69 */
70 nop /* used by __secondary_hold on prep (mtx) and chrp smp */
71 nop /* used by __secondary_hold on prep (mtx) and chrp smp */
72 nop
73
74/* PMAC
75 * Enter here with the kernel text, data and bss loaded starting at
76 * 0, running with virtual == physical mapping.
77 * r5 points to the prom entry point (the client interface handler
78 * address). Address translation is turned on, with the prom
79 * managing the hash table. Interrupts are disabled. The stack
80 * pointer (r1) points to just below the end of the half-meg region
81 * from 0x380000 - 0x400000, which is mapped in already.
82 *
83 * If we are booted from MacOS via BootX, we enter with the kernel
84 * image loaded somewhere, and the following values in registers:
85 * r3: 'BooX' (0x426f6f58)
86 * r4: virtual address of boot_infos_t
87 * r5: 0
88 *
14cf11af
PM
89 * PREP
90 * This is jumped to on prep systems right after the kernel is relocated
91 * to its proper place in memory by the boot loader. The expected layout
92 * of the regs is:
93 * r3: ptr to residual data
94 * r4: initrd_start or if no initrd then 0
95 * r5: initrd_end - unused if r4 is 0
96 * r6: Start of command line string
97 * r7: End of command line string
98 *
99 * This just gets a minimal mmu environment setup so we can call
100 * start_here() to do the real work.
101 * -- Cort
102 */
103
104 .globl __start
105__start:
106/*
107 * We have to do any OF calls before we map ourselves to KERNELBASE,
108 * because OF may have I/O devices mapped into that area
109 * (particularly on CHRP).
110 */
0a498d96 111#ifdef CONFIG_PPC_MULTIPLATFORM
9b6b563c
PM
112 cmpwi 0,r5,0
113 beq 1f
2bda347b
BH
114
115 /* find out where we are now */
116 bcl 20,31,$+4
1170: mflr r8 /* r8 = runtime addr here */
118 addis r8,r8,(_stext - 0b)@ha
119 addi r8,r8,(_stext - 0b)@l /* current runtime base addr */
9b6b563c
PM
120 bl prom_init
121 trap
0a498d96 122#endif
9b6b563c 123
d7f39454
BH
124/*
125 * Check for BootX signature when supporting PowerMac and branch to
126 * appropriate trampoline if it's present
127 */
128#ifdef CONFIG_PPC_PMAC
1291: lis r31,0x426f
130 ori r31,r31,0x6f58
131 cmpw 0,r3,r31
132 bne 1f
133 bl bootx_init
134 trap
135#endif /* CONFIG_PPC_PMAC */
136
9b6b563c 1371: mr r31,r3 /* save parameters */
14cf11af 138 mr r30,r4
14cf11af
PM
139 li r24,0 /* cpu # */
140
141/*
142 * early_init() does the early machine identification and does
143 * the necessary low-level setup and clears the BSS
144 * -- Cort <cort@fsmlabs.com>
145 */
146 bl early_init
147
14cf11af
PM
148/* Switch MMU off, clear BATs and flush TLB. At this point, r3 contains
149 * the physical address we are running at, returned by early_init()
150 */
151 bl mmu_off
152__after_mmu_off:
14cf11af
PM
153 bl clear_bats
154 bl flush_tlbs
155
156 bl initial_bats
f21f49ea 157#if defined(CONFIG_BOOTX_TEXT)
51d3082f
BH
158 bl setup_disp_bat
159#endif
c374e00e
SW
160#ifdef CONFIG_PPC_EARLY_DEBUG_CPM
161 bl setup_cpm_bat
162#endif
14cf11af
PM
163
164/*
165 * Call setup_cpu for CPU 0 and initialize 6xx Idle
166 */
167 bl reloc_offset
168 li r24,0 /* cpu# */
169 bl call_setup_cpu /* Call setup_cpu for this CPU */
170#ifdef CONFIG_6xx
171 bl reloc_offset
172 bl init_idle_6xx
173#endif /* CONFIG_6xx */
14cf11af
PM
174
175
14cf11af
PM
176/*
177 * We need to run with _start at physical address 0.
178 * On CHRP, we are loaded at 0x10000 since OF on CHRP uses
179 * the exception vectors at 0 (and therefore this copy
180 * overwrites OF's exception vectors with our own).
9b6b563c 181 * The MMU is off at this point.
14cf11af
PM
182 */
183 bl reloc_offset
184 mr r26,r3
185 addis r4,r3,KERNELBASE@h /* current address of _start */
186 cmpwi 0,r4,0 /* are we already running at 0? */
187 bne relocate_kernel
14cf11af
PM
188/*
189 * we now have the 1st 16M of ram mapped with the bats.
190 * prep needs the mmu to be turned on here, but pmac already has it on.
191 * this shouldn't bother the pmac since it just gets turned on again
192 * as we jump to our code at KERNELBASE. -- Cort
193 * Actually no, pmac doesn't have it on any more. BootX enters with MMU
194 * off, and in other cases, we now turn it off before changing BATs above.
195 */
196turn_on_mmu:
197 mfmsr r0
198 ori r0,r0,MSR_DR|MSR_IR
199 mtspr SPRN_SRR1,r0
200 lis r0,start_here@h
201 ori r0,r0,start_here@l
202 mtspr SPRN_SRR0,r0
203 SYNC
204 RFI /* enables MMU */
205
206/*
207 * We need __secondary_hold as a place to hold the other cpus on
208 * an SMP machine, even when we are running a UP kernel.
209 */
210 . = 0xc0 /* for prep bootloader */
211 li r3,1 /* MTX only has 1 cpu */
212 .globl __secondary_hold
213__secondary_hold:
214 /* tell the master we're here */
bbd0abda 215 stw r3,__secondary_hold_acknowledge@l(0)
14cf11af
PM
216#ifdef CONFIG_SMP
217100: lwz r4,0(0)
218 /* wait until we're told to start */
219 cmpw 0,r4,r3
220 bne 100b
221 /* our cpu # was at addr 0 - go */
222 mr r24,r3 /* cpu # */
223 b __secondary_start
224#else
225 b .
226#endif /* CONFIG_SMP */
227
bbd0abda
PM
228 .globl __secondary_hold_spinloop
229__secondary_hold_spinloop:
230 .long 0
231 .globl __secondary_hold_acknowledge
232__secondary_hold_acknowledge:
233 .long -1
234
14cf11af
PM
235/*
236 * Exception entry code. This code runs with address translation
237 * turned off, i.e. using physical addresses.
238 * We assume sprg3 has the physical address of the current
239 * task's thread_struct.
240 */
241#define EXCEPTION_PROLOG \
242 mtspr SPRN_SPRG0,r10; \
243 mtspr SPRN_SPRG1,r11; \
244 mfcr r10; \
245 EXCEPTION_PROLOG_1; \
246 EXCEPTION_PROLOG_2
247
248#define EXCEPTION_PROLOG_1 \
249 mfspr r11,SPRN_SRR1; /* check whether user or kernel */ \
250 andi. r11,r11,MSR_PR; \
251 tophys(r11,r1); /* use tophys(r1) if kernel */ \
252 beq 1f; \
253 mfspr r11,SPRN_SPRG3; \
254 lwz r11,THREAD_INFO-THREAD(r11); \
255 addi r11,r11,THREAD_SIZE; \
256 tophys(r11,r11); \
2571: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */
258
259
260#define EXCEPTION_PROLOG_2 \
261 CLR_TOP32(r11); \
262 stw r10,_CCR(r11); /* save registers */ \
263 stw r12,GPR12(r11); \
264 stw r9,GPR9(r11); \
265 mfspr r10,SPRN_SPRG0; \
266 stw r10,GPR10(r11); \
267 mfspr r12,SPRN_SPRG1; \
268 stw r12,GPR11(r11); \
269 mflr r10; \
270 stw r10,_LINK(r11); \
271 mfspr r12,SPRN_SRR0; \
272 mfspr r9,SPRN_SRR1; \
273 stw r1,GPR1(r11); \
274 stw r1,0(r11); \
275 tovirt(r1,r11); /* set new kernel sp */ \
276 li r10,MSR_KERNEL & ~(MSR_IR|MSR_DR); /* can take exceptions */ \
277 MTMSRD(r10); /* (except for mach check in rtas) */ \
278 stw r0,GPR0(r11); \
ec2b36b9
BH
279 lis r10,STACK_FRAME_REGS_MARKER@ha; /* exception frame marker */ \
280 addi r10,r10,STACK_FRAME_REGS_MARKER@l; \
f78541dc 281 stw r10,8(r11); \
14cf11af
PM
282 SAVE_4GPRS(3, r11); \
283 SAVE_2GPRS(7, r11)
284
285/*
286 * Note: code which follows this uses cr0.eq (set if from kernel),
287 * r11, r12 (SRR0), and r9 (SRR1).
288 *
289 * Note2: once we have set r1 we are in a position to take exceptions
290 * again, and we could thus set MSR:RI at that point.
291 */
292
293/*
294 * Exception vectors.
295 */
296#define EXCEPTION(n, label, hdlr, xfer) \
297 . = n; \
298label: \
299 EXCEPTION_PROLOG; \
300 addi r3,r1,STACK_FRAME_OVERHEAD; \
301 xfer(n, hdlr)
302
303#define EXC_XFER_TEMPLATE(n, hdlr, trap, copyee, tfer, ret) \
304 li r10,trap; \
d73e0c99 305 stw r10,_TRAP(r11); \
14cf11af
PM
306 li r10,MSR_KERNEL; \
307 copyee(r10, r9); \
308 bl tfer; \
309i##n: \
310 .long hdlr; \
311 .long ret
312
313#define COPY_EE(d, s) rlwimi d,s,0,16,16
314#define NOCOPY(d, s)
315
316#define EXC_XFER_STD(n, hdlr) \
317 EXC_XFER_TEMPLATE(n, hdlr, n, NOCOPY, transfer_to_handler_full, \
318 ret_from_except_full)
319
320#define EXC_XFER_LITE(n, hdlr) \
321 EXC_XFER_TEMPLATE(n, hdlr, n+1, NOCOPY, transfer_to_handler, \
322 ret_from_except)
323
324#define EXC_XFER_EE(n, hdlr) \
325 EXC_XFER_TEMPLATE(n, hdlr, n, COPY_EE, transfer_to_handler_full, \
326 ret_from_except_full)
327
328#define EXC_XFER_EE_LITE(n, hdlr) \
329 EXC_XFER_TEMPLATE(n, hdlr, n+1, COPY_EE, transfer_to_handler, \
330 ret_from_except)
331
332/* System reset */
333/* core99 pmac starts the seconary here by changing the vector, and
dc1c1ca3 334 putting it back to what it was (unknown_exception) when done. */
dc1c1ca3 335 EXCEPTION(0x100, Reset, unknown_exception, EXC_XFER_STD)
14cf11af
PM
336
337/* Machine check */
338/*
339 * On CHRP, this is complicated by the fact that we could get a
340 * machine check inside RTAS, and we have no guarantee that certain
341 * critical registers will have the values we expect. The set of
342 * registers that might have bad values includes all the GPRs
343 * and all the BATs. We indicate that we are in RTAS by putting
344 * a non-zero value, the address of the exception frame to use,
345 * in SPRG2. The machine check handler checks SPRG2 and uses its
346 * value if it is non-zero. If we ever needed to free up SPRG2,
347 * we could use a field in the thread_info or thread_struct instead.
348 * (Other exception handlers assume that r1 is a valid kernel stack
349 * pointer when we take an exception from supervisor mode.)
350 * -- paulus.
351 */
352 . = 0x200
353 mtspr SPRN_SPRG0,r10
354 mtspr SPRN_SPRG1,r11
355 mfcr r10
356#ifdef CONFIG_PPC_CHRP
357 mfspr r11,SPRN_SPRG2
358 cmpwi 0,r11,0
359 bne 7f
360#endif /* CONFIG_PPC_CHRP */
361 EXCEPTION_PROLOG_1
3627: EXCEPTION_PROLOG_2
363 addi r3,r1,STACK_FRAME_OVERHEAD
364#ifdef CONFIG_PPC_CHRP
365 mfspr r4,SPRN_SPRG2
366 cmpwi cr1,r4,0
367 bne cr1,1f
368#endif
dc1c1ca3 369 EXC_XFER_STD(0x200, machine_check_exception)
14cf11af
PM
370#ifdef CONFIG_PPC_CHRP
3711: b machine_check_in_rtas
372#endif
373
374/* Data access exception. */
375 . = 0x300
14cf11af
PM
376DataAccess:
377 EXCEPTION_PROLOG
14cf11af 378 mfspr r10,SPRN_DSISR
4ee7084e 379 stw r10,_DSISR(r11)
14cf11af
PM
380 andis. r0,r10,0xa470 /* weird error? */
381 bne 1f /* if not, try to put a PTE */
382 mfspr r4,SPRN_DAR /* into the hash table */
383 rlwinm r3,r10,32-15,21,21 /* DSISR_STORE -> _PAGE_RW */
384 bl hash_page
4ee7084e 3851: lwz r5,_DSISR(r11) /* get DSISR value */
14cf11af
PM
386 mfspr r4,SPRN_DAR
387 EXC_XFER_EE_LITE(0x300, handle_page_fault)
388
14cf11af
PM
389
390/* Instruction access exception. */
391 . = 0x400
14cf11af
PM
392InstructionAccess:
393 EXCEPTION_PROLOG
14cf11af
PM
394 andis. r0,r9,0x4000 /* no pte found? */
395 beq 1f /* if so, try to put a PTE */
396 li r3,0 /* into the hash table */
397 mr r4,r12 /* SRR0 is fault address */
398 bl hash_page
3991: mr r4,r12
400 mr r5,r9
401 EXC_XFER_EE_LITE(0x400, handle_page_fault)
402
14cf11af
PM
403/* External interrupt */
404 EXCEPTION(0x500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
405
406/* Alignment exception */
407 . = 0x600
408Alignment:
409 EXCEPTION_PROLOG
410 mfspr r4,SPRN_DAR
411 stw r4,_DAR(r11)
412 mfspr r5,SPRN_DSISR
413 stw r5,_DSISR(r11)
414 addi r3,r1,STACK_FRAME_OVERHEAD
dc1c1ca3 415 EXC_XFER_EE(0x600, alignment_exception)
14cf11af
PM
416
417/* Program check exception */
dc1c1ca3 418 EXCEPTION(0x700, ProgramCheck, program_check_exception, EXC_XFER_STD)
14cf11af
PM
419
420/* Floating-point unavailable */
421 . = 0x800
422FPUnavailable:
aa42c69c
KP
423BEGIN_FTR_SECTION
424/*
425 * Certain Freescale cores don't have a FPU and treat fp instructions
426 * as a FP Unavailable exception. Redirect to illegal/emulation handling.
427 */
428 b ProgramCheck
429END_FTR_SECTION_IFSET(CPU_FTR_FPU_UNAVAILABLE)
14cf11af 430 EXCEPTION_PROLOG
6f3d8e69
MN
431 beq 1f
432 bl load_up_fpu /* if from user, just load it up */
433 b fast_exception_return
4341: addi r3,r1,STACK_FRAME_OVERHEAD
8dad3f92 435 EXC_XFER_EE_LITE(0x800, kernel_fp_unavailable_exception)
14cf11af
PM
436
437/* Decrementer */
438 EXCEPTION(0x900, Decrementer, timer_interrupt, EXC_XFER_LITE)
439
dc1c1ca3
SR
440 EXCEPTION(0xa00, Trap_0a, unknown_exception, EXC_XFER_EE)
441 EXCEPTION(0xb00, Trap_0b, unknown_exception, EXC_XFER_EE)
14cf11af
PM
442
443/* System call */
444 . = 0xc00
445SystemCall:
446 EXCEPTION_PROLOG
447 EXC_XFER_EE_LITE(0xc00, DoSyscall)
448
449/* Single step - not used on 601 */
dc1c1ca3
SR
450 EXCEPTION(0xd00, SingleStep, single_step_exception, EXC_XFER_STD)
451 EXCEPTION(0xe00, Trap_0e, unknown_exception, EXC_XFER_EE)
14cf11af
PM
452
453/*
454 * The Altivec unavailable trap is at 0x0f20. Foo.
455 * We effectively remap it to 0x3000.
456 * We include an altivec unavailable exception vector even if
457 * not configured for Altivec, so that you can't panic a
458 * non-altivec kernel running on a machine with altivec just
459 * by executing an altivec instruction.
460 */
461 . = 0xf00
555d97ac 462 b PerformanceMonitor
14cf11af
PM
463
464 . = 0xf20
465 b AltiVecUnavailable
466
14cf11af
PM
467/*
468 * Handle TLB miss for instruction on 603/603e.
469 * Note: we get an alternate set of r0 - r3 to use automatically.
470 */
471 . = 0x1000
472InstructionTLBMiss:
473/*
474 * r0: stored ctr
475 * r1: linux style pte ( later becomes ppc hardware pte )
476 * r2: ptr to linux-style pte
477 * r3: scratch
478 */
479 mfctr r0
480 /* Get PTE (linux-style) and check access */
481 mfspr r3,SPRN_IMISS
8a13c4f9
KG
482 lis r1,PAGE_OFFSET@h /* check if kernel address */
483 cmplw 0,r1,r3
14cf11af
PM
484 mfspr r2,SPRN_SPRG3
485 li r1,_PAGE_USER|_PAGE_PRESENT /* low addresses tested as user */
486 lwz r2,PGDIR(r2)
8a13c4f9 487 bge- 112f
bde6c6e1
SW
488 mfspr r2,SPRN_SRR1 /* and MSR_PR bit from SRR1 */
489 rlwimi r1,r2,32-12,29,29 /* shift MSR_PR to _PAGE_USER posn */
14cf11af
PM
490 lis r2,swapper_pg_dir@ha /* if kernel address, use */
491 addi r2,r2,swapper_pg_dir@l /* kernel page table */
14cf11af
PM
492112: tophys(r2,r2)
493 rlwimi r2,r3,12,20,29 /* insert top 10 bits of address */
494 lwz r2,0(r2) /* get pmd entry */
495 rlwinm. r2,r2,0,0,19 /* extract address of pte page */
496 beq- InstructionAddressInvalid /* return if no mapping */
497 rlwimi r2,r3,22,20,29 /* insert next 10 bits of address */
498 lwz r3,0(r2) /* get linux-style pte */
499 andc. r1,r1,r3 /* check access & ~permission */
500 bne- InstructionAddressInvalid /* return if access not permitted */
501 ori r3,r3,_PAGE_ACCESSED /* set _PAGE_ACCESSED in pte */
502 /*
503 * NOTE! We are assuming this is not an SMP system, otherwise
504 * we would need to update the pte atomically with lwarx/stwcx.
505 */
506 stw r3,0(r2) /* update PTE (accessed bit) */
507 /* Convert linux-style PTE to low word of PPC-style PTE */
508 rlwinm r1,r3,32-10,31,31 /* _PAGE_RW -> PP lsb */
509 rlwinm r2,r3,32-7,31,31 /* _PAGE_DIRTY -> PP lsb */
510 and r1,r1,r2 /* writable if _RW and _DIRTY */
511 rlwimi r3,r3,32-1,30,30 /* _PAGE_USER -> PP msb */
512 rlwimi r3,r3,32-1,31,31 /* _PAGE_USER -> PP lsb */
513 ori r1,r1,0xe14 /* clear out reserved bits and M */
514 andc r1,r3,r1 /* PP = user? (rw&dirty? 2: 3): 0 */
515 mtspr SPRN_RPA,r1
516 mfspr r3,SPRN_IMISS
517 tlbli r3
518 mfspr r3,SPRN_SRR1 /* Need to restore CR0 */
519 mtcrf 0x80,r3
520 rfi
521InstructionAddressInvalid:
522 mfspr r3,SPRN_SRR1
523 rlwinm r1,r3,9,6,6 /* Get load/store bit */
524
525 addis r1,r1,0x2000
526 mtspr SPRN_DSISR,r1 /* (shouldn't be needed) */
527 mtctr r0 /* Restore CTR */
528 andi. r2,r3,0xFFFF /* Clear upper bits of SRR1 */
529 or r2,r2,r1
530 mtspr SPRN_SRR1,r2
531 mfspr r1,SPRN_IMISS /* Get failing address */
532 rlwinm. r2,r2,0,31,31 /* Check for little endian access */
533 rlwimi r2,r2,1,30,30 /* change 1 -> 3 */
534 xor r1,r1,r2
535 mtspr SPRN_DAR,r1 /* Set fault address */
536 mfmsr r0 /* Restore "normal" registers */
537 xoris r0,r0,MSR_TGPR>>16
538 mtcrf 0x80,r3 /* Restore CR0 */
539 mtmsr r0
540 b InstructionAccess
541
542/*
543 * Handle TLB miss for DATA Load operation on 603/603e
544 */
545 . = 0x1100
546DataLoadTLBMiss:
547/*
548 * r0: stored ctr
549 * r1: linux style pte ( later becomes ppc hardware pte )
550 * r2: ptr to linux-style pte
551 * r3: scratch
552 */
553 mfctr r0
554 /* Get PTE (linux-style) and check access */
555 mfspr r3,SPRN_DMISS
8a13c4f9
KG
556 lis r1,PAGE_OFFSET@h /* check if kernel address */
557 cmplw 0,r1,r3
14cf11af
PM
558 mfspr r2,SPRN_SPRG3
559 li r1,_PAGE_USER|_PAGE_PRESENT /* low addresses tested as user */
560 lwz r2,PGDIR(r2)
8a13c4f9 561 bge- 112f
bde6c6e1
SW
562 mfspr r2,SPRN_SRR1 /* and MSR_PR bit from SRR1 */
563 rlwimi r1,r2,32-12,29,29 /* shift MSR_PR to _PAGE_USER posn */
14cf11af
PM
564 lis r2,swapper_pg_dir@ha /* if kernel address, use */
565 addi r2,r2,swapper_pg_dir@l /* kernel page table */
14cf11af
PM
566112: tophys(r2,r2)
567 rlwimi r2,r3,12,20,29 /* insert top 10 bits of address */
568 lwz r2,0(r2) /* get pmd entry */
569 rlwinm. r2,r2,0,0,19 /* extract address of pte page */
570 beq- DataAddressInvalid /* return if no mapping */
571 rlwimi r2,r3,22,20,29 /* insert next 10 bits of address */
572 lwz r3,0(r2) /* get linux-style pte */
573 andc. r1,r1,r3 /* check access & ~permission */
574 bne- DataAddressInvalid /* return if access not permitted */
575 ori r3,r3,_PAGE_ACCESSED /* set _PAGE_ACCESSED in pte */
576 /*
577 * NOTE! We are assuming this is not an SMP system, otherwise
578 * we would need to update the pte atomically with lwarx/stwcx.
579 */
580 stw r3,0(r2) /* update PTE (accessed bit) */
581 /* Convert linux-style PTE to low word of PPC-style PTE */
582 rlwinm r1,r3,32-10,31,31 /* _PAGE_RW -> PP lsb */
583 rlwinm r2,r3,32-7,31,31 /* _PAGE_DIRTY -> PP lsb */
584 and r1,r1,r2 /* writable if _RW and _DIRTY */
585 rlwimi r3,r3,32-1,30,30 /* _PAGE_USER -> PP msb */
586 rlwimi r3,r3,32-1,31,31 /* _PAGE_USER -> PP lsb */
587 ori r1,r1,0xe14 /* clear out reserved bits and M */
588 andc r1,r3,r1 /* PP = user? (rw&dirty? 2: 3): 0 */
589 mtspr SPRN_RPA,r1
590 mfspr r3,SPRN_DMISS
591 tlbld r3
592 mfspr r3,SPRN_SRR1 /* Need to restore CR0 */
593 mtcrf 0x80,r3
594 rfi
595DataAddressInvalid:
596 mfspr r3,SPRN_SRR1
597 rlwinm r1,r3,9,6,6 /* Get load/store bit */
598 addis r1,r1,0x2000
599 mtspr SPRN_DSISR,r1
600 mtctr r0 /* Restore CTR */
601 andi. r2,r3,0xFFFF /* Clear upper bits of SRR1 */
602 mtspr SPRN_SRR1,r2
603 mfspr r1,SPRN_DMISS /* Get failing address */
604 rlwinm. r2,r2,0,31,31 /* Check for little endian access */
605 beq 20f /* Jump if big endian */
606 xori r1,r1,3
60720: mtspr SPRN_DAR,r1 /* Set fault address */
608 mfmsr r0 /* Restore "normal" registers */
609 xoris r0,r0,MSR_TGPR>>16
610 mtcrf 0x80,r3 /* Restore CR0 */
611 mtmsr r0
612 b DataAccess
613
614/*
615 * Handle TLB miss for DATA Store on 603/603e
616 */
617 . = 0x1200
618DataStoreTLBMiss:
619/*
620 * r0: stored ctr
621 * r1: linux style pte ( later becomes ppc hardware pte )
622 * r2: ptr to linux-style pte
623 * r3: scratch
624 */
625 mfctr r0
626 /* Get PTE (linux-style) and check access */
627 mfspr r3,SPRN_DMISS
8a13c4f9
KG
628 lis r1,PAGE_OFFSET@h /* check if kernel address */
629 cmplw 0,r1,r3
14cf11af
PM
630 mfspr r2,SPRN_SPRG3
631 li r1,_PAGE_RW|_PAGE_USER|_PAGE_PRESENT /* access flags */
632 lwz r2,PGDIR(r2)
8a13c4f9 633 bge- 112f
bde6c6e1
SW
634 mfspr r2,SPRN_SRR1 /* and MSR_PR bit from SRR1 */
635 rlwimi r1,r2,32-12,29,29 /* shift MSR_PR to _PAGE_USER posn */
14cf11af
PM
636 lis r2,swapper_pg_dir@ha /* if kernel address, use */
637 addi r2,r2,swapper_pg_dir@l /* kernel page table */
14cf11af
PM
638112: tophys(r2,r2)
639 rlwimi r2,r3,12,20,29 /* insert top 10 bits of address */
640 lwz r2,0(r2) /* get pmd entry */
641 rlwinm. r2,r2,0,0,19 /* extract address of pte page */
642 beq- DataAddressInvalid /* return if no mapping */
643 rlwimi r2,r3,22,20,29 /* insert next 10 bits of address */
644 lwz r3,0(r2) /* get linux-style pte */
645 andc. r1,r1,r3 /* check access & ~permission */
646 bne- DataAddressInvalid /* return if access not permitted */
647 ori r3,r3,_PAGE_ACCESSED|_PAGE_DIRTY
648 /*
649 * NOTE! We are assuming this is not an SMP system, otherwise
650 * we would need to update the pte atomically with lwarx/stwcx.
651 */
652 stw r3,0(r2) /* update PTE (accessed/dirty bits) */
653 /* Convert linux-style PTE to low word of PPC-style PTE */
654 rlwimi r3,r3,32-1,30,30 /* _PAGE_USER -> PP msb */
655 li r1,0xe15 /* clear out reserved bits and M */
656 andc r1,r3,r1 /* PP = user? 2: 0 */
657 mtspr SPRN_RPA,r1
658 mfspr r3,SPRN_DMISS
659 tlbld r3
660 mfspr r3,SPRN_SRR1 /* Need to restore CR0 */
661 mtcrf 0x80,r3
662 rfi
663
664#ifndef CONFIG_ALTIVEC
dc1c1ca3 665#define altivec_assist_exception unknown_exception
14cf11af
PM
666#endif
667
dc1c1ca3 668 EXCEPTION(0x1300, Trap_13, instruction_breakpoint_exception, EXC_XFER_EE)
14cf11af 669 EXCEPTION(0x1400, SMI, SMIException, EXC_XFER_EE)
dc1c1ca3 670 EXCEPTION(0x1500, Trap_15, unknown_exception, EXC_XFER_EE)
dc1c1ca3 671 EXCEPTION(0x1600, Trap_16, altivec_assist_exception, EXC_XFER_EE)
14cf11af 672 EXCEPTION(0x1700, Trap_17, TAUException, EXC_XFER_STD)
dc1c1ca3 673 EXCEPTION(0x1800, Trap_18, unknown_exception, EXC_XFER_EE)
dc1c1ca3
SR
674 EXCEPTION(0x1900, Trap_19, unknown_exception, EXC_XFER_EE)
675 EXCEPTION(0x1a00, Trap_1a, unknown_exception, EXC_XFER_EE)
676 EXCEPTION(0x1b00, Trap_1b, unknown_exception, EXC_XFER_EE)
677 EXCEPTION(0x1c00, Trap_1c, unknown_exception, EXC_XFER_EE)
678 EXCEPTION(0x1d00, Trap_1d, unknown_exception, EXC_XFER_EE)
679 EXCEPTION(0x1e00, Trap_1e, unknown_exception, EXC_XFER_EE)
680 EXCEPTION(0x1f00, Trap_1f, unknown_exception, EXC_XFER_EE)
14cf11af 681 EXCEPTION(0x2000, RunMode, RunModeException, EXC_XFER_EE)
dc1c1ca3
SR
682 EXCEPTION(0x2100, Trap_21, unknown_exception, EXC_XFER_EE)
683 EXCEPTION(0x2200, Trap_22, unknown_exception, EXC_XFER_EE)
684 EXCEPTION(0x2300, Trap_23, unknown_exception, EXC_XFER_EE)
685 EXCEPTION(0x2400, Trap_24, unknown_exception, EXC_XFER_EE)
686 EXCEPTION(0x2500, Trap_25, unknown_exception, EXC_XFER_EE)
687 EXCEPTION(0x2600, Trap_26, unknown_exception, EXC_XFER_EE)
688 EXCEPTION(0x2700, Trap_27, unknown_exception, EXC_XFER_EE)
689 EXCEPTION(0x2800, Trap_28, unknown_exception, EXC_XFER_EE)
690 EXCEPTION(0x2900, Trap_29, unknown_exception, EXC_XFER_EE)
691 EXCEPTION(0x2a00, Trap_2a, unknown_exception, EXC_XFER_EE)
692 EXCEPTION(0x2b00, Trap_2b, unknown_exception, EXC_XFER_EE)
693 EXCEPTION(0x2c00, Trap_2c, unknown_exception, EXC_XFER_EE)
694 EXCEPTION(0x2d00, Trap_2d, unknown_exception, EXC_XFER_EE)
695 EXCEPTION(0x2e00, Trap_2e, unknown_exception, EXC_XFER_EE)
696 EXCEPTION(0x2f00, MOLTrampoline, unknown_exception, EXC_XFER_EE_LITE)
14cf11af
PM
697
698 .globl mol_trampoline
699 .set mol_trampoline, i0x2f00
700
701 . = 0x3000
702
703AltiVecUnavailable:
704 EXCEPTION_PROLOG
705#ifdef CONFIG_ALTIVEC
706 bne load_up_altivec /* if from user, just load it up */
707#endif /* CONFIG_ALTIVEC */
f1434a48 708 addi r3,r1,STACK_FRAME_OVERHEAD
dc1c1ca3 709 EXC_XFER_EE_LITE(0xf20, altivec_unavailable_exception)
14cf11af 710
555d97ac
AF
711PerformanceMonitor:
712 EXCEPTION_PROLOG
713 addi r3,r1,STACK_FRAME_OVERHEAD
714 EXC_XFER_STD(0xf00, performance_monitor_exception)
715
14cf11af
PM
716#ifdef CONFIG_ALTIVEC
717/* Note that the AltiVec support is closely modeled after the FP
718 * support. Changes to one are likely to be applicable to the
719 * other! */
720load_up_altivec:
721/*
722 * Disable AltiVec for the task which had AltiVec previously,
723 * and save its AltiVec registers in its thread_struct.
724 * Enables AltiVec for use in the kernel on return.
725 * On SMP we know the AltiVec units are free, since we give it up every
726 * switch. -- Kumar
727 */
728 mfmsr r5
729 oris r5,r5,MSR_VEC@h
730 MTMSRD(r5) /* enable use of AltiVec now */
731 isync
732/*
733 * For SMP, we don't do lazy AltiVec switching because it just gets too
734 * horrendously complex, especially when a task switches from one CPU
735 * to another. Instead we call giveup_altivec in switch_to.
736 */
737#ifndef CONFIG_SMP
738 tophys(r6,0)
739 addis r3,r6,last_task_used_altivec@ha
740 lwz r4,last_task_used_altivec@l(r3)
741 cmpwi 0,r4,0
742 beq 1f
743 add r4,r4,r6
744 addi r4,r4,THREAD /* want THREAD of last_task_used_altivec */
745 SAVE_32VRS(0,r10,r4)
746 mfvscr vr0
747 li r10,THREAD_VSCR
748 stvx vr0,r10,r4
749 lwz r5,PT_REGS(r4)
750 add r5,r5,r6
751 lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
752 lis r10,MSR_VEC@h
753 andc r4,r4,r10 /* disable altivec for previous task */
754 stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
7551:
756#endif /* CONFIG_SMP */
757 /* enable use of AltiVec after return */
758 oris r9,r9,MSR_VEC@h
759 mfspr r5,SPRN_SPRG3 /* current task's THREAD (phys) */
760 li r4,1
761 li r10,THREAD_VSCR
762 stw r4,THREAD_USED_VR(r5)
763 lvx vr0,r10,r5
764 mtvscr vr0
765 REST_32VRS(0,r10,r5)
766#ifndef CONFIG_SMP
767 subi r4,r5,THREAD
768 sub r4,r4,r6
769 stw r4,last_task_used_altivec@l(r3)
770#endif /* CONFIG_SMP */
771 /* restore registers and return */
772 /* we haven't used ctr or xer or lr */
773 b fast_exception_return
774
14cf11af
PM
775/*
776 * giveup_altivec(tsk)
777 * Disable AltiVec for the task given as the argument,
778 * and save the AltiVec registers in its thread_struct.
779 * Enables AltiVec for use in the kernel on return.
780 */
781
782 .globl giveup_altivec
783giveup_altivec:
784 mfmsr r5
785 oris r5,r5,MSR_VEC@h
786 SYNC
787 MTMSRD(r5) /* enable use of AltiVec now */
788 isync
789 cmpwi 0,r3,0
790 beqlr- /* if no previous owner, done */
791 addi r3,r3,THREAD /* want THREAD of task */
792 lwz r5,PT_REGS(r3)
793 cmpwi 0,r5,0
794 SAVE_32VRS(0, r4, r3)
795 mfvscr vr0
796 li r4,THREAD_VSCR
797 stvx vr0,r4,r3
798 beq 1f
799 lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
800 lis r3,MSR_VEC@h
801 andc r4,r4,r3 /* disable AltiVec for previous task */
802 stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
8031:
804#ifndef CONFIG_SMP
805 li r5,0
806 lis r4,last_task_used_altivec@ha
807 stw r5,last_task_used_altivec@l(r4)
808#endif /* CONFIG_SMP */
809 blr
810#endif /* CONFIG_ALTIVEC */
811
812/*
813 * This code is jumped to from the startup code to copy
814 * the kernel image to physical address 0.
815 */
816relocate_kernel:
817 addis r9,r26,klimit@ha /* fetch klimit */
818 lwz r25,klimit@l(r9)
819 addis r25,r25,-KERNELBASE@h
820 li r3,0 /* Destination base address */
821 li r6,0 /* Destination offset */
822 li r5,0x4000 /* # bytes of memory to copy */
823 bl copy_and_flush /* copy the first 0x4000 bytes */
824 addi r0,r3,4f@l /* jump to the address of 4f */
825 mtctr r0 /* in copy and do the rest. */
826 bctr /* jump to the copy */
8274: mr r5,r25
828 bl copy_and_flush /* copy the rest */
829 b turn_on_mmu
830
831/*
832 * Copy routine used to copy the kernel to start at physical address 0
833 * and flush and invalidate the caches as needed.
834 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
835 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
836 */
748a7683 837_ENTRY(copy_and_flush)
14cf11af
PM
838 addi r5,r5,-4
839 addi r6,r6,-4
7dffb720 8404: li r0,L1_CACHE_BYTES/4
14cf11af
PM
841 mtctr r0
8423: addi r6,r6,4 /* copy a cache line */
843 lwzx r0,r6,r4
844 stwx r0,r6,r3
845 bdnz 3b
846 dcbst r6,r3 /* write it to memory */
847 sync
848 icbi r6,r3 /* flush the icache line */
849 cmplw 0,r6,r5
850 blt 4b
851 sync /* additional sync needed on g4 */
852 isync
853 addi r5,r5,4
854 addi r6,r6,4
855 blr
856
14cf11af
PM
857#ifdef CONFIG_SMP
858#ifdef CONFIG_GEMINI
859 .globl __secondary_start_gemini
860__secondary_start_gemini:
861 mfspr r4,SPRN_HID0
862 ori r4,r4,HID0_ICFI
863 li r3,0
864 ori r3,r3,HID0_ICE
865 andc r4,r4,r3
866 mtspr SPRN_HID0,r4
867 sync
868 b __secondary_start
869#endif /* CONFIG_GEMINI */
870
ee0339f2
JL
871 .globl __secondary_start_mpc86xx
872__secondary_start_mpc86xx:
873 mfspr r3, SPRN_PIR
874 stw r3, __secondary_hold_acknowledge@l(0)
875 mr r24, r3 /* cpu # */
876 b __secondary_start
877
14cf11af
PM
878 .globl __secondary_start_pmac_0
879__secondary_start_pmac_0:
880 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
881 li r24,0
882 b 1f
883 li r24,1
884 b 1f
885 li r24,2
886 b 1f
887 li r24,3
8881:
889 /* on powersurge, we come in here with IR=0 and DR=1, and DBAT 0
890 set to map the 0xf0000000 - 0xffffffff region */
891 mfmsr r0
892 rlwinm r0,r0,0,28,26 /* clear DR (0x10) */
893 SYNC
894 mtmsr r0
895 isync
896
897 .globl __secondary_start
898__secondary_start:
14cf11af
PM
899 /* Copy some CPU settings from CPU 0 */
900 bl __restore_cpu_setup
901
902 lis r3,-KERNELBASE@h
903 mr r4,r24
14cf11af
PM
904 bl call_setup_cpu /* Call setup_cpu for this CPU */
905#ifdef CONFIG_6xx
906 lis r3,-KERNELBASE@h
907 bl init_idle_6xx
908#endif /* CONFIG_6xx */
14cf11af
PM
909
910 /* get current_thread_info and current */
911 lis r1,secondary_ti@ha
912 tophys(r1,r1)
913 lwz r1,secondary_ti@l(r1)
914 tophys(r2,r1)
915 lwz r2,TI_TASK(r2)
916
917 /* stack */
918 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
919 li r0,0
920 tophys(r3,r1)
921 stw r0,0(r3)
922
923 /* load up the MMU */
924 bl load_up_mmu
925
926 /* ptr to phys current thread */
927 tophys(r4,r2)
928 addi r4,r4,THREAD /* phys address of our thread_struct */
929 CLR_TOP32(r4)
930 mtspr SPRN_SPRG3,r4
931 li r3,0
932 mtspr SPRN_SPRG2,r3 /* 0 => not in RTAS */
933
934 /* enable MMU and jump to start_secondary */
935 li r4,MSR_KERNEL
936 FIX_SRR1(r4,r5)
937 lis r3,start_secondary@h
938 ori r3,r3,start_secondary@l
939 mtspr SPRN_SRR0,r3
940 mtspr SPRN_SRR1,r4
941 SYNC
942 RFI
943#endif /* CONFIG_SMP */
944
945/*
946 * Those generic dummy functions are kept for CPUs not
947 * included in CONFIG_6xx
948 */
187a0067 949#if !defined(CONFIG_6xx)
748a7683 950_ENTRY(__save_cpu_setup)
14cf11af 951 blr
748a7683 952_ENTRY(__restore_cpu_setup)
14cf11af 953 blr
187a0067 954#endif /* !defined(CONFIG_6xx) */
14cf11af
PM
955
956
957/*
958 * Load stuff into the MMU. Intended to be called with
959 * IR=0 and DR=0.
960 */
961load_up_mmu:
962 sync /* Force all PTE updates to finish */
963 isync
964 tlbia /* Clear all TLB entries */
965 sync /* wait for tlbia/tlbie to finish */
966 TLBSYNC /* ... on all CPUs */
967 /* Load the SDR1 register (hash table base & size) */
968 lis r6,_SDR1@ha
969 tophys(r6,r6)
970 lwz r6,_SDR1@l(r6)
971 mtspr SPRN_SDR1,r6
14cf11af
PM
972 li r0,16 /* load up segment register values */
973 mtctr r0 /* for context 0 */
974 lis r3,0x2000 /* Ku = 1, VSID = 0 */
975 li r4,0
9763: mtsrin r3,r4
977 addi r3,r3,0x111 /* increment VSID */
978 addis r4,r4,0x1000 /* address of next segment */
979 bdnz 3b
187a0067 980
14cf11af
PM
981/* Load the BAT registers with the values set up by MMU_init.
982 MMU_init takes care of whether we're on a 601 or not. */
983 mfpvr r3
984 srwi r3,r3,16
985 cmpwi r3,1
986 lis r3,BATS@ha
987 addi r3,r3,BATS@l
988 tophys(r3,r3)
989 LOAD_BAT(0,r3,r4,r5)
990 LOAD_BAT(1,r3,r4,r5)
991 LOAD_BAT(2,r3,r4,r5)
992 LOAD_BAT(3,r3,r4,r5)
7c03d653 993BEGIN_MMU_FTR_SECTION
ee0339f2
JL
994 LOAD_BAT(4,r3,r4,r5)
995 LOAD_BAT(5,r3,r4,r5)
996 LOAD_BAT(6,r3,r4,r5)
997 LOAD_BAT(7,r3,r4,r5)
7c03d653 998END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
14cf11af
PM
999 blr
1000
1001/*
1002 * This is where the main kernel code starts.
1003 */
1004start_here:
1005 /* ptr to current */
1006 lis r2,init_task@h
1007 ori r2,r2,init_task@l
1008 /* Set up for using our exception vectors */
1009 /* ptr to phys current thread */
1010 tophys(r4,r2)
1011 addi r4,r4,THREAD /* init task's THREAD */
1012 CLR_TOP32(r4)
1013 mtspr SPRN_SPRG3,r4
1014 li r3,0
1015 mtspr SPRN_SPRG2,r3 /* 0 => not in RTAS */
1016
1017 /* stack */
1018 lis r1,init_thread_union@ha
1019 addi r1,r1,init_thread_union@l
1020 li r0,0
1021 stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
1022/*
187a0067 1023 * Do early platform-specific initialization,
14cf11af
PM
1024 * and set up the MMU.
1025 */
1026 mr r3,r31
1027 mr r4,r30
14cf11af 1028 bl machine_init
22c841c9 1029 bl __save_cpu_setup
14cf11af
PM
1030 bl MMU_init
1031
14cf11af
PM
1032/*
1033 * Go back to running unmapped so we can load up new values
1034 * for SDR1 (hash table pointer) and the segment registers
1035 * and change to using our exception vectors.
1036 */
1037 lis r4,2f@h
1038 ori r4,r4,2f@l
1039 tophys(r4,r4)
1040 li r3,MSR_KERNEL & ~(MSR_IR|MSR_DR)
1041 FIX_SRR1(r3,r5)
1042 mtspr SPRN_SRR0,r4
1043 mtspr SPRN_SRR1,r3
1044 SYNC
1045 RFI
1046/* Load up the kernel context */
10472: bl load_up_mmu
1048
1049#ifdef CONFIG_BDI_SWITCH
1050 /* Add helper information for the Abatron bdiGDB debugger.
1051 * We do this here because we know the mmu is disabled, and
1052 * will be enabled for real in just a few instructions.
1053 */
1054 lis r5, abatron_pteptrs@h
1055 ori r5, r5, abatron_pteptrs@l
1056 stw r5, 0xf0(r0) /* This much match your Abatron config */
1057 lis r6, swapper_pg_dir@h
1058 ori r6, r6, swapper_pg_dir@l
1059 tophys(r5, r5)
1060 stw r6, 0(r5)
1061#endif /* CONFIG_BDI_SWITCH */
1062
1063/* Now turn on the MMU for real! */
1064 li r4,MSR_KERNEL
1065 FIX_SRR1(r4,r5)
1066 lis r3,start_kernel@h
1067 ori r3,r3,start_kernel@l
1068 mtspr SPRN_SRR0,r3
1069 mtspr SPRN_SRR1,r4
1070 SYNC
1071 RFI
1072
1073/*
5e696617
BH
1074 * void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next);
1075 *
14cf11af
PM
1076 * Set up the segment registers for a new context.
1077 */
5e696617
BH
1078_ENTRY(switch_mmu_context)
1079 lwz r3,MMCONTEXTID(r4)
1080 cmpwi cr0,r3,0
1081 blt- 4f
14cf11af
PM
1082 mulli r3,r3,897 /* multiply context by skew factor */
1083 rlwinm r3,r3,4,8,27 /* VSID = (context & 0xfffff) << 4 */
1084 addis r3,r3,0x6000 /* Set Ks, Ku bits */
1085 li r0,NUM_USER_SEGMENTS
1086 mtctr r0
1087
1088#ifdef CONFIG_BDI_SWITCH
1089 /* Context switch the PTE pointer for the Abatron BDI2000.
1090 * The PGDIR is passed as second argument.
1091 */
5e696617 1092 lwz r4,MM_PGD(r4)
14cf11af
PM
1093 lis r5, KERNELBASE@h
1094 lwz r5, 0xf0(r5)
1095 stw r4, 0x4(r5)
1096#endif
1097 li r4,0
1098 isync
10993:
14cf11af
PM
1100 mtsrin r3,r4
1101 addi r3,r3,0x111 /* next VSID */
1102 rlwinm r3,r3,0,8,3 /* clear out any overflow from VSID field */
1103 addis r4,r4,0x1000 /* address of next segment */
1104 bdnz 3b
1105 sync
1106 isync
1107 blr
5e696617
BH
11084: trap
1109 EMIT_BUG_ENTRY 4b,__FILE__,__LINE__,0
1110 blr
14cf11af
PM
1111
1112/*
1113 * An undocumented "feature" of 604e requires that the v bit
1114 * be cleared before changing BAT values.
1115 *
1116 * Also, newer IBM firmware does not clear bat3 and 4 so
1117 * this makes sure it's done.
1118 * -- Cort
1119 */
1120clear_bats:
1121 li r10,0
1122 mfspr r9,SPRN_PVR
1123 rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
1124 cmpwi r9, 1
1125 beq 1f
1126
1127 mtspr SPRN_DBAT0U,r10
1128 mtspr SPRN_DBAT0L,r10
1129 mtspr SPRN_DBAT1U,r10
1130 mtspr SPRN_DBAT1L,r10
1131 mtspr SPRN_DBAT2U,r10
1132 mtspr SPRN_DBAT2L,r10
1133 mtspr SPRN_DBAT3U,r10
1134 mtspr SPRN_DBAT3L,r10
11351:
1136 mtspr SPRN_IBAT0U,r10
1137 mtspr SPRN_IBAT0L,r10
1138 mtspr SPRN_IBAT1U,r10
1139 mtspr SPRN_IBAT1L,r10
1140 mtspr SPRN_IBAT2U,r10
1141 mtspr SPRN_IBAT2L,r10
1142 mtspr SPRN_IBAT3U,r10
1143 mtspr SPRN_IBAT3L,r10
7c03d653 1144BEGIN_MMU_FTR_SECTION
14cf11af
PM
1145 /* Here's a tweak: at this point, CPU setup have
1146 * not been called yet, so HIGH_BAT_EN may not be
1147 * set in HID0 for the 745x processors. However, it
1148 * seems that doesn't affect our ability to actually
1149 * write to these SPRs.
1150 */
1151 mtspr SPRN_DBAT4U,r10
1152 mtspr SPRN_DBAT4L,r10
1153 mtspr SPRN_DBAT5U,r10
1154 mtspr SPRN_DBAT5L,r10
1155 mtspr SPRN_DBAT6U,r10
1156 mtspr SPRN_DBAT6L,r10
1157 mtspr SPRN_DBAT7U,r10
1158 mtspr SPRN_DBAT7L,r10
1159 mtspr SPRN_IBAT4U,r10
1160 mtspr SPRN_IBAT4L,r10
1161 mtspr SPRN_IBAT5U,r10
1162 mtspr SPRN_IBAT5L,r10
1163 mtspr SPRN_IBAT6U,r10
1164 mtspr SPRN_IBAT6L,r10
1165 mtspr SPRN_IBAT7U,r10
1166 mtspr SPRN_IBAT7L,r10
7c03d653 1167END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
14cf11af
PM
1168 blr
1169
1170flush_tlbs:
1171 lis r10, 0x40
11721: addic. r10, r10, -0x1000
1173 tlbie r10
9acd57ca 1174 bgt 1b
14cf11af
PM
1175 sync
1176 blr
1177
1178mmu_off:
1179 addi r4, r3, __after_mmu_off - _start
1180 mfmsr r3
1181 andi. r0,r3,MSR_DR|MSR_IR /* MMU enabled? */
1182 beqlr
1183 andc r3,r3,r0
1184 mtspr SPRN_SRR0,r4
1185 mtspr SPRN_SRR1,r3
1186 sync
1187 RFI
1188
14cf11af
PM
1189/*
1190 * Use the first pair of BAT registers to map the 1st 16MB
1191 * of RAM to KERNELBASE. From this point on we can't safely
1192 * call OF any more.
1193 */
1194initial_bats:
1195 lis r11,KERNELBASE@h
14cf11af
PM
1196 mfspr r9,SPRN_PVR
1197 rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
1198 cmpwi 0,r9,1
1199 bne 4f
1200 ori r11,r11,4 /* set up BAT registers for 601 */
1201 li r8,0x7f /* valid, block length = 8MB */
1202 oris r9,r11,0x800000@h /* set up BAT reg for 2nd 8M */
1203 oris r10,r8,0x800000@h /* set up BAT reg for 2nd 8M */
1204 mtspr SPRN_IBAT0U,r11 /* N.B. 601 has valid bit in */
1205 mtspr SPRN_IBAT0L,r8 /* lower BAT register */
1206 mtspr SPRN_IBAT1U,r9
1207 mtspr SPRN_IBAT1L,r10
1208 isync
1209 blr
14cf11af
PM
1210
12114: tophys(r8,r11)
1212#ifdef CONFIG_SMP
1213 ori r8,r8,0x12 /* R/W access, M=1 */
1214#else
1215 ori r8,r8,2 /* R/W access */
1216#endif /* CONFIG_SMP */
14cf11af 1217 ori r11,r11,BL_256M<<2|0x2 /* set up BAT registers for 604 */
14cf11af 1218
14cf11af
PM
1219 mtspr SPRN_DBAT0L,r8 /* N.B. 6xx (not 601) have valid */
1220 mtspr SPRN_DBAT0U,r11 /* bit in upper BAT register */
1221 mtspr SPRN_IBAT0L,r8
1222 mtspr SPRN_IBAT0U,r11
1223 isync
1224 blr
1225
14cf11af 1226
f21f49ea 1227#ifdef CONFIG_BOOTX_TEXT
51d3082f
BH
1228setup_disp_bat:
1229 /*
1230 * setup the display bat prepared for us in prom.c
1231 */
1232 mflr r8
1233 bl reloc_offset
1234 mtlr r8
1235 addis r8,r3,disp_BAT@ha
1236 addi r8,r8,disp_BAT@l
1237 cmpwi cr0,r8,0
1238 beqlr
1239 lwz r11,0(r8)
1240 lwz r8,4(r8)
1241 mfspr r9,SPRN_PVR
1242 rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
1243 cmpwi 0,r9,1
1244 beq 1f
1245 mtspr SPRN_DBAT3L,r8
1246 mtspr SPRN_DBAT3U,r11
1247 blr
12481: mtspr SPRN_IBAT3L,r8
1249 mtspr SPRN_IBAT3U,r11
1250 blr
f21f49ea 1251#endif /* CONFIG_BOOTX_TEXT */
51d3082f 1252
c374e00e
SW
1253#ifdef CONFIG_PPC_EARLY_DEBUG_CPM
1254setup_cpm_bat:
1255 lis r8, 0xf000
1256 ori r8, r8, 0x002a
1257 mtspr SPRN_DBAT1L, r8
1258
1259 lis r11, 0xf000
1260 ori r11, r11, (BL_1M << 2) | 2
1261 mtspr SPRN_DBAT1U, r11
1262
1263 blr
1264#endif
1265
14cf11af
PM
1266#ifdef CONFIG_8260
1267/* Jump into the system reset for the rom.
1268 * We first disable the MMU, and then jump to the ROM reset address.
1269 *
1270 * r3 is the board info structure, r4 is the location for starting.
1271 * I use this for building a small kernel that can load other kernels,
1272 * rather than trying to write or rely on a rom monitor that can tftp load.
1273 */
1274 .globl m8260_gorom
1275m8260_gorom:
1276 mfmsr r0
1277 rlwinm r0,r0,0,17,15 /* clear MSR_EE in r0 */
1278 sync
1279 mtmsr r0
1280 sync
1281 mfspr r11, SPRN_HID0
1282 lis r10, 0
1283 ori r10,r10,HID0_ICE|HID0_DCE
1284 andc r11, r11, r10
1285 mtspr SPRN_HID0, r11
1286 isync
1287 li r5, MSR_ME|MSR_RI
1288 lis r6,2f@h
1289 addis r6,r6,-KERNELBASE@h
1290 ori r6,r6,2f@l
1291 mtspr SPRN_SRR0,r6
1292 mtspr SPRN_SRR1,r5
1293 isync
1294 sync
1295 rfi
12962:
1297 mtlr r4
1298 blr
1299#endif
1300
1301
1302/*
1303 * We put a few things here that have to be page-aligned.
1304 * This stuff goes at the beginning of the data segment,
1305 * which is page-aligned.
1306 */
1307 .data
1308 .globl sdata
1309sdata:
1310 .globl empty_zero_page
1311empty_zero_page:
1312 .space 4096
1313
1314 .globl swapper_pg_dir
1315swapper_pg_dir:
bee86f14 1316 .space PGD_TABLE_SIZE
14cf11af 1317
14cf11af
PM
1318 .globl intercept_table
1319intercept_table:
1320 .long 0, 0, i0x200, i0x300, i0x400, 0, i0x600, i0x700
1321 .long i0x800, 0, 0, 0, 0, i0xd00, 0, 0
1322 .long 0, 0, 0, i0x1300, 0, 0, 0, 0
1323 .long 0, 0, 0, 0, 0, 0, 0, 0
1324 .long 0, 0, 0, 0, 0, 0, 0, 0
1325 .long 0, 0, 0, 0, 0, 0, 0, 0
1326
1327/* Room for two PTE pointers, usually the kernel and current user pointers
1328 * to their respective root page table.
1329 */
1330abatron_pteptrs:
1331 .space 8