1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <linux/init.h>
20 #include <asm/reg.h>
21 #include <asm/page.h>
22 #include <asm/mmu.h>
23 #include <asm/pgtable.h>
24 #include <asm/cputable.h>
25 #include <asm/cache.h>
26 #include <asm/thread_info.h>
27 #include <asm/ppc_asm.h>
28 #include <asm/asm-offsets.h>
29 #include <asm/ptrace.h>
30 #include <asm/bug.h>
31 #include <asm/kvm_book3s_asm.h>
32 #include <asm/export.h>
33 #include <asm/feature-fixups.h>
34
35 #include "head_32.h"
36
37
38 #ifdef CONFIG_PPC_BOOK3S_601
39 #define LOAD_BAT(n, reg, RA, RB) \
40 li RA,0; \
41 mtspr SPRN_IBAT##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 #else
47 #define LOAD_BAT(n, reg, RA, RB) \
48 \
49 li RA,0; \
50 mtspr SPRN_IBAT##n##U,RA; \
51 mtspr SPRN_DBAT##n##U,RA; \
52 lwz RA,(n*16)+0(reg); \
53 lwz RB,(n*16)+4(reg); \
54 mtspr SPRN_IBAT##n##U,RA; \
55 mtspr SPRN_IBAT##n##L,RB; \
56 lwz RA,(n*16)+8(reg); \
57 lwz RB,(n*16)+12(reg); \
58 mtspr SPRN_DBAT##n##U,RA; \
59 mtspr SPRN_DBAT##n##L,RB
60 #endif
61
62 __HEAD
63 .stabs "arch/powerpc/kernel/",N_SO,0,0,0f
64 .stabs "head_32.S",N_SO,0,0,0f
65 0:
66 _ENTRY(_stext);
67
68
69
70
71
72 _ENTRY(_start);
73
74
75
76
77
78
79 nop
80 nop
81 nop
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 .globl __start
114 __start:
115
116
117
118
119
120 cmpwi 0,r5,0
121 beq 1f
122
123 #ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE
124
125 bcl 20,31,$+4
126 0: mflr r8
127 addis r8,r8,(_stext - 0b)@ha
128 addi r8,r8,(_stext - 0b)@l
129 bl prom_init
130 #endif
131
132
133
134 trap
135
136
137
138
139
140 #ifdef CONFIG_PPC_PMAC
141 1: lis r31,0x426f
142 ori r31,r31,0x6f58
143 cmpw 0,r3,r31
144 bne 1f
145 bl bootx_init
146 trap
147 #endif
148
149 1: mr r31,r3
150 li r24,0
151
152
153
154
155
156
157 bl early_init
158
159
160
161
162 bl mmu_off
163 __after_mmu_off:
164 bl clear_bats
165 bl flush_tlbs
166
167 bl initial_bats
168 bl load_segment_registers
169 #ifdef CONFIG_KASAN
170 bl early_hash_table
171 #endif
172 #if defined(CONFIG_BOOTX_TEXT)
173 bl setup_disp_bat
174 #endif
175 #ifdef CONFIG_PPC_EARLY_DEBUG_CPM
176 bl setup_cpm_bat
177 #endif
178 #ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
179 bl setup_usbgecko_bat
180 #endif
181
182
183
184
185 bl reloc_offset
186 li r24,0
187 bl call_setup_cpu
188 #ifdef CONFIG_PPC_BOOK3S_32
189 bl reloc_offset
190 bl init_idle_6xx
191 #endif
192
193
194
195
196
197
198
199
200
201 bl reloc_offset
202 mr r26,r3
203 addis r4,r3,KERNELBASE@h
204 lis r5,PHYSICAL_START@h
205 cmplw 0,r4,r5
206 bne relocate_kernel
207
208
209
210
211
212
213
214
215 turn_on_mmu:
216 mfmsr r0
217 ori r0,r0,MSR_DR|MSR_IR|MSR_RI
218 mtspr SPRN_SRR1,r0
219 lis r0,start_here@h
220 ori r0,r0,start_here@l
221 mtspr SPRN_SRR0,r0
222 SYNC
223 RFI
224
225
226
227
228
229 . = 0xc0
230 li r3,1
231 .globl __secondary_hold
232 __secondary_hold:
233
234 stw r3,__secondary_hold_acknowledge@l(0)
235 #ifdef CONFIG_SMP
236 100: lwz r4,0(0)
237
238 cmpw 0,r4,r3
239 bne 100b
240
241 mr r24,r3
242 b __secondary_start
243 #else
244 b .
245 #endif
246
247 .globl __secondary_hold_spinloop
248 __secondary_hold_spinloop:
249 .long 0
250 .globl __secondary_hold_acknowledge
251 __secondary_hold_acknowledge:
252 .long -1
253
254
255
256
257 EXCEPTION(0x100, Reset, unknown_exception, EXC_XFER_STD)
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273 . = 0x200
274 DO_KVM 0x200
275 mtspr SPRN_SPRG_SCRATCH0,r10
276 mtspr SPRN_SPRG_SCRATCH1,r11
277 mfcr r10
278 #ifdef CONFIG_PPC_CHRP
279 mfspr r11, SPRN_SPRG_THREAD
280 lwz r11, RTAS_SP(r11)
281 cmpwi cr1, r11, 0
282 bne cr1, 7f
283 #endif
284 EXCEPTION_PROLOG_1
285 7: EXCEPTION_PROLOG_2
286 addi r3,r1,STACK_FRAME_OVERHEAD
287 #ifdef CONFIG_PPC_CHRP
288 bne cr1,1f
289 #endif
290 EXC_XFER_STD(0x200, machine_check_exception)
291 #ifdef CONFIG_PPC_CHRP
292 1: b machine_check_in_rtas
293 #endif
294
295
296 . = 0x300
297 DO_KVM 0x300
298 DataAccess:
299 EXCEPTION_PROLOG
300 mfspr r10,SPRN_DSISR
301 stw r10,_DSISR(r11)
302 #ifdef CONFIG_PPC_KUAP
303 andis. r0,r10,(DSISR_BAD_FAULT_32S | DSISR_DABRMATCH | DSISR_PROTFAULT)@h
304 #else
305 andis. r0,r10,(DSISR_BAD_FAULT_32S|DSISR_DABRMATCH)@h
306 #endif
307 bne 1f
308 mfspr r4,SPRN_DAR
309 rlwinm r3,r10,32-15,21,21
310 BEGIN_MMU_FTR_SECTION
311 bl hash_page
312 END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE)
313 1: lwz r5,_DSISR(r11)
314 mfspr r4,SPRN_DAR
315 EXC_XFER_LITE(0x300, handle_page_fault)
316
317
318
319 . = 0x400
320 DO_KVM 0x400
321 InstructionAccess:
322 EXCEPTION_PROLOG
323 andis. r0,r9,SRR1_ISI_NOPT@h
324 beq 1f
325 li r3,0
326 mr r4,r12
327 BEGIN_MMU_FTR_SECTION
328 bl hash_page
329 END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE)
330 1: mr r4,r12
331 andis. r5,r9,DSISR_SRR1_MATCH_32S@h
332 EXC_XFER_LITE(0x400, handle_page_fault)
333
334
335 EXCEPTION(0x500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
336
337
338 . = 0x600
339 DO_KVM 0x600
340 Alignment:
341 EXCEPTION_PROLOG
342 mfspr r4,SPRN_DAR
343 stw r4,_DAR(r11)
344 mfspr r5,SPRN_DSISR
345 stw r5,_DSISR(r11)
346 addi r3,r1,STACK_FRAME_OVERHEAD
347 EXC_XFER_STD(0x600, alignment_exception)
348
349
350 EXCEPTION(0x700, ProgramCheck, program_check_exception, EXC_XFER_STD)
351
352
353 . = 0x800
354 DO_KVM 0x800
355 FPUnavailable:
356 BEGIN_FTR_SECTION
357
358
359
360
361 b ProgramCheck
362 END_FTR_SECTION_IFSET(CPU_FTR_FPU_UNAVAILABLE)
363 EXCEPTION_PROLOG
364 beq 1f
365 bl load_up_fpu
366 b fast_exception_return
367 1: addi r3,r1,STACK_FRAME_OVERHEAD
368 EXC_XFER_LITE(0x800, kernel_fp_unavailable_exception)
369
370
371 EXCEPTION(0x900, Decrementer, timer_interrupt, EXC_XFER_LITE)
372
373 EXCEPTION(0xa00, Trap_0a, unknown_exception, EXC_XFER_STD)
374 EXCEPTION(0xb00, Trap_0b, unknown_exception, EXC_XFER_STD)
375
376
377 . = 0xc00
378 DO_KVM 0xc00
379 SystemCall:
380 SYSCALL_ENTRY 0xc00
381
382
383 EXCEPTION(0xd00, SingleStep, single_step_exception, EXC_XFER_STD)
384 EXCEPTION(0xe00, Trap_0e, unknown_exception, EXC_XFER_STD)
385
386
387
388
389
390
391
392
393
394 . = 0xf00
395 DO_KVM 0xf00
396 b PerformanceMonitor
397
398 . = 0xf20
399 DO_KVM 0xf20
400 b AltiVecUnavailable
401
402
403
404
405
406 . = 0x1000
407 InstructionTLBMiss:
408
409
410
411
412
413
414
415 mfspr r3,SPRN_IMISS
416 #if defined(CONFIG_MODULES) || defined(CONFIG_DEBUG_PAGEALLOC)
417 lis r1,PAGE_OFFSET@h
418 cmplw 0,r1,r3
419 #endif
420 mfspr r2, SPRN_SPRG_PGDIR
421 #ifdef CONFIG_SWAP
422 li r1,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
423 #else
424 li r1,_PAGE_PRESENT | _PAGE_EXEC
425 #endif
426 #if defined(CONFIG_MODULES) || defined(CONFIG_DEBUG_PAGEALLOC)
427 bge- 112f
428 lis r2, (swapper_pg_dir - PAGE_OFFSET)@ha
429 addi r2, r2, (swapper_pg_dir - PAGE_OFFSET)@l
430 #endif
431 112: rlwimi r2,r3,12,20,29
432 lwz r2,0(r2)
433 rlwinm. r2,r2,0,0,19
434 beq- InstructionAddressInvalid
435 rlwimi r2,r3,22,20,29
436 lwz r0,0(r2)
437 andc. r1,r1,r0
438 bne- InstructionAddressInvalid
439
440 rlwimi r0,r0,32-2,31,31
441 ori r1, r1, 0xe06
442 andc r1, r0, r1
443 BEGIN_FTR_SECTION
444 rlwinm r1,r1,0,~_PAGE_COHERENT
445 END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
446 mtspr SPRN_RPA,r1
447 tlbli r3
448 mfspr r3,SPRN_SRR1
449 mtcrf 0x80,r3
450 rfi
451 InstructionAddressInvalid:
452 mfspr r3,SPRN_SRR1
453 rlwinm r1,r3,9,6,6
454
455 addis r1,r1,0x2000
456 mtspr SPRN_DSISR,r1
457 andi. r2,r3,0xFFFF
458 or r2,r2,r1
459 mtspr SPRN_SRR1,r2
460 mfspr r1,SPRN_IMISS
461 rlwinm. r2,r2,0,31,31
462 rlwimi r2,r2,1,30,30
463 xor r1,r1,r2
464 mtspr SPRN_DAR,r1
465 mfmsr r0
466 xoris r0,r0,MSR_TGPR>>16
467 mtcrf 0x80,r3
468 mtmsr r0
469 b InstructionAccess
470
471
472
473
474 . = 0x1100
475 DataLoadTLBMiss:
476
477
478
479
480
481
482
483 mfspr r3,SPRN_DMISS
484 lis r1,PAGE_OFFSET@h
485 cmplw 0,r1,r3
486 mfspr r2, SPRN_SPRG_PGDIR
487 #ifdef CONFIG_SWAP
488 li r1, _PAGE_PRESENT | _PAGE_ACCESSED
489 #else
490 li r1, _PAGE_PRESENT
491 #endif
492 bge- 112f
493 lis r2, (swapper_pg_dir - PAGE_OFFSET)@ha
494 addi r2, r2, (swapper_pg_dir - PAGE_OFFSET)@l
495 112: rlwimi r2,r3,12,20,29
496 lwz r2,0(r2)
497 rlwinm. r2,r2,0,0,19
498 beq- DataAddressInvalid
499 rlwimi r2,r3,22,20,29
500 lwz r0,0(r2)
501 andc. r1,r1,r0
502 bne- DataAddressInvalid
503
504
505
506
507
508 rlwinm r1,r0,32-9,30,30
509 rlwimi r0,r0,32-1,30,30
510 rlwimi r0,r0,32-1,31,31
511 ori r1,r1,0xe04
512 andc r1,r0,r1
513 BEGIN_FTR_SECTION
514 rlwinm r1,r1,0,~_PAGE_COHERENT
515 END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
516 mtspr SPRN_RPA,r1
517 mfspr r2,SPRN_SRR1
518 mtcrf 0x80,r2
519 BEGIN_MMU_FTR_SECTION
520 li r0,1
521 mfspr r1,SPRN_SPRG_603_LRU
522 rlwinm r2,r3,20,27,31
523 slw r0,r0,r2
524 xor r1,r0,r1
525 srw r0,r1,r2
526 mtspr SPRN_SPRG_603_LRU,r1
527 mfspr r2,SPRN_SRR1
528 rlwimi r2,r0,31-14,14,14
529 mtspr SPRN_SRR1,r2
530 END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU)
531 tlbld r3
532 rfi
533 DataAddressInvalid:
534 mfspr r3,SPRN_SRR1
535 rlwinm r1,r3,9,6,6
536 addis r1,r1,0x2000
537 mtspr SPRN_DSISR,r1
538 andi. r2,r3,0xFFFF
539 mtspr SPRN_SRR1,r2
540 mfspr r1,SPRN_DMISS
541 rlwinm. r2,r2,0,31,31
542 beq 20f
543 xori r1,r1,3
544 20: mtspr SPRN_DAR,r1
545 mfmsr r0
546 xoris r0,r0,MSR_TGPR>>16
547 mtcrf 0x80,r3
548 mtmsr r0
549 b DataAccess
550
551
552
553
554 . = 0x1200
555 DataStoreTLBMiss:
556
557
558
559
560
561
562
563 mfspr r3,SPRN_DMISS
564 lis r1,PAGE_OFFSET@h
565 cmplw 0,r1,r3
566 mfspr r2, SPRN_SPRG_PGDIR
567 #ifdef CONFIG_SWAP
568 li r1, _PAGE_RW | _PAGE_DIRTY | _PAGE_PRESENT | _PAGE_ACCESSED
569 #else
570 li r1, _PAGE_RW | _PAGE_DIRTY | _PAGE_PRESENT
571 #endif
572 bge- 112f
573 lis r2, (swapper_pg_dir - PAGE_OFFSET)@ha
574 addi r2, r2, (swapper_pg_dir - PAGE_OFFSET)@l
575 112: rlwimi r2,r3,12,20,29
576 lwz r2,0(r2)
577 rlwinm. r2,r2,0,0,19
578 beq- DataAddressInvalid
579 rlwimi r2,r3,22,20,29
580 lwz r0,0(r2)
581 andc. r1,r1,r0
582 bne- DataAddressInvalid
583
584
585
586
587
588 rlwimi r0,r0,32-2,31,31
589 li r1,0xe06
590 andc r1,r0,r1
591 BEGIN_FTR_SECTION
592 rlwinm r1,r1,0,~_PAGE_COHERENT
593 END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
594 mtspr SPRN_RPA,r1
595 mfspr r2,SPRN_SRR1
596 mtcrf 0x80,r2
597 BEGIN_MMU_FTR_SECTION
598 li r0,1
599 mfspr r1,SPRN_SPRG_603_LRU
600 rlwinm r2,r3,20,27,31
601 slw r0,r0,r2
602 xor r1,r0,r1
603 srw r0,r1,r2
604 mtspr SPRN_SPRG_603_LRU,r1
605 mfspr r2,SPRN_SRR1
606 rlwimi r2,r0,31-14,14,14
607 mtspr SPRN_SRR1,r2
608 END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU)
609 tlbld r3
610 rfi
611
612 #ifndef CONFIG_ALTIVEC
613 #define altivec_assist_exception unknown_exception
614 #endif
615
616 EXCEPTION(0x1300, Trap_13, instruction_breakpoint_exception, EXC_XFER_STD)
617 EXCEPTION(0x1400, SMI, SMIException, EXC_XFER_STD)
618 EXCEPTION(0x1500, Trap_15, unknown_exception, EXC_XFER_STD)
619 EXCEPTION(0x1600, Trap_16, altivec_assist_exception, EXC_XFER_STD)
620 EXCEPTION(0x1700, Trap_17, TAUException, EXC_XFER_STD)
621 EXCEPTION(0x1800, Trap_18, unknown_exception, EXC_XFER_STD)
622 EXCEPTION(0x1900, Trap_19, unknown_exception, EXC_XFER_STD)
623 EXCEPTION(0x1a00, Trap_1a, unknown_exception, EXC_XFER_STD)
624 EXCEPTION(0x1b00, Trap_1b, unknown_exception, EXC_XFER_STD)
625 EXCEPTION(0x1c00, Trap_1c, unknown_exception, EXC_XFER_STD)
626 EXCEPTION(0x1d00, Trap_1d, unknown_exception, EXC_XFER_STD)
627 EXCEPTION(0x1e00, Trap_1e, unknown_exception, EXC_XFER_STD)
628 EXCEPTION(0x1f00, Trap_1f, unknown_exception, EXC_XFER_STD)
629 EXCEPTION(0x2000, RunMode, RunModeException, EXC_XFER_STD)
630 EXCEPTION(0x2100, Trap_21, unknown_exception, EXC_XFER_STD)
631 EXCEPTION(0x2200, Trap_22, unknown_exception, EXC_XFER_STD)
632 EXCEPTION(0x2300, Trap_23, unknown_exception, EXC_XFER_STD)
633 EXCEPTION(0x2400, Trap_24, unknown_exception, EXC_XFER_STD)
634 EXCEPTION(0x2500, Trap_25, unknown_exception, EXC_XFER_STD)
635 EXCEPTION(0x2600, Trap_26, unknown_exception, EXC_XFER_STD)
636 EXCEPTION(0x2700, Trap_27, unknown_exception, EXC_XFER_STD)
637 EXCEPTION(0x2800, Trap_28, unknown_exception, EXC_XFER_STD)
638 EXCEPTION(0x2900, Trap_29, unknown_exception, EXC_XFER_STD)
639 EXCEPTION(0x2a00, Trap_2a, unknown_exception, EXC_XFER_STD)
640 EXCEPTION(0x2b00, Trap_2b, unknown_exception, EXC_XFER_STD)
641 EXCEPTION(0x2c00, Trap_2c, unknown_exception, EXC_XFER_STD)
642 EXCEPTION(0x2d00, Trap_2d, unknown_exception, EXC_XFER_STD)
643 EXCEPTION(0x2e00, Trap_2e, unknown_exception, EXC_XFER_STD)
644 EXCEPTION(0x2f00, Trap_2f, unknown_exception, EXC_XFER_STD)
645
646 . = 0x3000
647
648 AltiVecUnavailable:
649 EXCEPTION_PROLOG
650 #ifdef CONFIG_ALTIVEC
651 beq 1f
652 bl load_up_altivec
653 b fast_exception_return
654 #endif
655 1: addi r3,r1,STACK_FRAME_OVERHEAD
656 EXC_XFER_LITE(0xf20, altivec_unavailable_exception)
657
658 PerformanceMonitor:
659 EXCEPTION_PROLOG
660 addi r3,r1,STACK_FRAME_OVERHEAD
661 EXC_XFER_STD(0xf00, performance_monitor_exception)
662
663
664
665
666
667
668 relocate_kernel:
669 addis r9,r26,klimit@ha
670 lwz r25,klimit@l(r9)
671 addis r25,r25,-KERNELBASE@h
672 lis r3,PHYSICAL_START@h
673 li r6,0
674 li r5,0x4000
675 bl copy_and_flush
676 addi r0,r3,4f@l
677 mtctr r0
678 bctr
679 4: mr r5,r25
680 bl copy_and_flush
681 b turn_on_mmu
682
683
684
685
686
687
688
689 _ENTRY(copy_and_flush)
690 addi r5,r5,-4
691 addi r6,r6,-4
692 4: li r0,L1_CACHE_BYTES/4
693 mtctr r0
694 3: addi r6,r6,4
695 lwzx r0,r6,r4
696 stwx r0,r6,r3
697 bdnz 3b
698 dcbst r6,r3
699 sync
700 icbi r6,r3
701 cmplw 0,r6,r5
702 blt 4b
703 sync
704 isync
705 addi r5,r5,4
706 addi r6,r6,4
707 blr
708
709 #ifdef CONFIG_SMP
710 .globl __secondary_start_mpc86xx
711 __secondary_start_mpc86xx:
712 mfspr r3, SPRN_PIR
713 stw r3, __secondary_hold_acknowledge@l(0)
714 mr r24, r3
715 b __secondary_start
716
717 .globl __secondary_start_pmac_0
718 __secondary_start_pmac_0:
719
720 li r24,0
721 b 1f
722 li r24,1
723 b 1f
724 li r24,2
725 b 1f
726 li r24,3
727 1:
728
729
730 mfmsr r0
731 rlwinm r0,r0,0,28,26
732 SYNC
733 mtmsr r0
734 isync
735
736 .globl __secondary_start
737 __secondary_start:
738
739 bl __restore_cpu_setup
740
741 lis r3,-KERNELBASE@h
742 mr r4,r24
743 bl call_setup_cpu
744 #ifdef CONFIG_PPC_BOOK3S_32
745 lis r3,-KERNELBASE@h
746 bl init_idle_6xx
747 #endif
748
749
750 lis r2,secondary_current@ha
751 tophys(r2,r2)
752 lwz r2,secondary_current@l(r2)
753 tophys(r1,r2)
754 lwz r1,TASK_STACK(r1)
755
756
757 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
758 li r0,0
759 tophys(r3,r1)
760 stw r0,0(r3)
761
762
763 bl load_segment_registers
764 bl load_up_mmu
765
766
767 tophys(r4,r2)
768 addi r4,r4,THREAD
769 mtspr SPRN_SPRG_THREAD,r4
770 lis r4, (swapper_pg_dir - PAGE_OFFSET)@h
771 ori r4, r4, (swapper_pg_dir - PAGE_OFFSET)@l
772 mtspr SPRN_SPRG_PGDIR, r4
773
774
775 li r4,MSR_KERNEL
776 lis r3,start_secondary@h
777 ori r3,r3,start_secondary@l
778 mtspr SPRN_SRR0,r3
779 mtspr SPRN_SRR1,r4
780 SYNC
781 RFI
782 #endif
783
784 #ifdef CONFIG_KVM_BOOK3S_HANDLER
785 #include "../kvm/book3s_rmhandlers.S"
786 #endif
787
788
789
790
791
792 #if !defined(CONFIG_PPC_BOOK3S_32)
793 _ENTRY(__save_cpu_setup)
794 blr
795 _ENTRY(__restore_cpu_setup)
796 blr
797 #endif
798
799
800
801
802
803 #ifdef CONFIG_KASAN
804 early_hash_table:
805 sync
806 isync
807 tlbia
808 sync
809 TLBSYNC
810
811 lis r6, early_hash - PAGE_OFFSET@h
812 ori r6, r6, 3
813 mtspr SPRN_SDR1, r6
814 blr
815 #endif
816
817 load_up_mmu:
818 sync
819 isync
820 tlbia
821 sync
822 TLBSYNC
823
824 lis r6,_SDR1@ha
825 tophys(r6,r6)
826 lwz r6,_SDR1@l(r6)
827 mtspr SPRN_SDR1,r6
828
829
830
831 lis r3,BATS@ha
832 addi r3,r3,BATS@l
833 tophys(r3,r3)
834 LOAD_BAT(0,r3,r4,r5)
835 LOAD_BAT(1,r3,r4,r5)
836 LOAD_BAT(2,r3,r4,r5)
837 LOAD_BAT(3,r3,r4,r5)
838 BEGIN_MMU_FTR_SECTION
839 LOAD_BAT(4,r3,r4,r5)
840 LOAD_BAT(5,r3,r4,r5)
841 LOAD_BAT(6,r3,r4,r5)
842 LOAD_BAT(7,r3,r4,r5)
843 END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
844 blr
845
846 load_segment_registers:
847 li r0, NUM_USER_SEGMENTS
848 mtctr r0
849 li r3, 0
850 #ifdef CONFIG_PPC_KUEP
851 oris r3, r3, SR_NX@h
852 #endif
853 #ifdef CONFIG_PPC_KUAP
854 oris r3, r3, SR_KS@h
855 #endif
856 li r4, 0
857 3: mtsrin r3, r4
858 addi r3, r3, 0x111
859 addis r4, r4, 0x1000
860 bdnz 3b
861 li r0, 16 - NUM_USER_SEGMENTS
862 mtctr r0
863 rlwinm r3, r3, 0, ~SR_NX
864 rlwinm r3, r3, 0, ~SR_KS
865 oris r3, r3, SR_KP@h
866 3: mtsrin r3, r4
867 addi r3, r3, 0x111
868 addis r4, r4, 0x1000
869 bdnz 3b
870 blr
871
872
873
874
875 start_here:
876
877 lis r2,init_task@h
878 ori r2,r2,init_task@l
879
880
881 tophys(r4,r2)
882 addi r4,r4,THREAD
883 mtspr SPRN_SPRG_THREAD,r4
884 lis r4, (swapper_pg_dir - PAGE_OFFSET)@h
885 ori r4, r4, (swapper_pg_dir - PAGE_OFFSET)@l
886 mtspr SPRN_SPRG_PGDIR, r4
887
888
889 lis r1,init_thread_union@ha
890 addi r1,r1,init_thread_union@l
891 li r0,0
892 stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
893
894
895
896
897 #ifdef CONFIG_KASAN
898 bl kasan_early_init
899 #endif
900 li r3,0
901 mr r4,r31
902 bl machine_init
903 bl __save_cpu_setup
904 bl MMU_init
905 #ifdef CONFIG_KASAN
906 BEGIN_MMU_FTR_SECTION
907 bl MMU_init_hw_patch
908 END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE)
909 #endif
910
911
912
913
914
915
916 lis r4,2f@h
917 ori r4,r4,2f@l
918 tophys(r4,r4)
919 li r3,MSR_KERNEL & ~(MSR_IR|MSR_DR)
920 mtspr SPRN_SRR0,r4
921 mtspr SPRN_SRR1,r3
922 SYNC
923 RFI
924
925 2: bl load_up_mmu
926
927 #ifdef CONFIG_BDI_SWITCH
928
929
930
931
932 lis r5, abatron_pteptrs@h
933 ori r5, r5, abatron_pteptrs@l
934 stw r5, 0xf0(r0)
935 lis r6, swapper_pg_dir@h
936 ori r6, r6, swapper_pg_dir@l
937 tophys(r5, r5)
938 stw r6, 0(r5)
939 #endif
940
941
942 li r4,MSR_KERNEL
943 lis r3,start_kernel@h
944 ori r3,r3,start_kernel@l
945 mtspr SPRN_SRR0,r3
946 mtspr SPRN_SRR1,r4
947 SYNC
948 RFI
949
950
951
952
953
954
955 _ENTRY(switch_mmu_context)
956 lwz r3,MMCONTEXTID(r4)
957 cmpwi cr0,r3,0
958 blt- 4f
959 mulli r3,r3,897
960 rlwinm r3,r3,4,8,27
961 #ifdef CONFIG_PPC_KUEP
962 oris r3, r3, SR_NX@h
963 #endif
964 #ifdef CONFIG_PPC_KUAP
965 oris r3, r3, SR_KS@h
966 #endif
967 li r0,NUM_USER_SEGMENTS
968 mtctr r0
969
970 lwz r4, MM_PGD(r4)
971 #ifdef CONFIG_BDI_SWITCH
972
973
974
975 lis r5, abatron_pteptrs@ha
976 stw r4, abatron_pteptrs@l + 0x4(r5)
977 #endif
978 tophys(r4, r4)
979 mtspr SPRN_SPRG_PGDIR, r4
980 li r4,0
981 isync
982 3:
983 mtsrin r3,r4
984 addi r3,r3,0x111
985 rlwinm r3,r3,0,8,3
986 addis r4,r4,0x1000
987 bdnz 3b
988 sync
989 isync
990 blr
991 4: trap
992 EMIT_BUG_ENTRY 4b,__FILE__,__LINE__,0
993 blr
994 EXPORT_SYMBOL(switch_mmu_context)
995
996
997
998
999
1000
1001
1002
1003
1004 clear_bats:
1005 li r10,0
1006
1007 #ifndef CONFIG_PPC_BOOK3S_601
1008 mtspr SPRN_DBAT0U,r10
1009 mtspr SPRN_DBAT0L,r10
1010 mtspr SPRN_DBAT1U,r10
1011 mtspr SPRN_DBAT1L,r10
1012 mtspr SPRN_DBAT2U,r10
1013 mtspr SPRN_DBAT2L,r10
1014 mtspr SPRN_DBAT3U,r10
1015 mtspr SPRN_DBAT3L,r10
1016 #endif
1017 mtspr SPRN_IBAT0U,r10
1018 mtspr SPRN_IBAT0L,r10
1019 mtspr SPRN_IBAT1U,r10
1020 mtspr SPRN_IBAT1L,r10
1021 mtspr SPRN_IBAT2U,r10
1022 mtspr SPRN_IBAT2L,r10
1023 mtspr SPRN_IBAT3U,r10
1024 mtspr SPRN_IBAT3L,r10
1025 BEGIN_MMU_FTR_SECTION
1026
1027
1028
1029
1030
1031
1032 mtspr SPRN_DBAT4U,r10
1033 mtspr SPRN_DBAT4L,r10
1034 mtspr SPRN_DBAT5U,r10
1035 mtspr SPRN_DBAT5L,r10
1036 mtspr SPRN_DBAT6U,r10
1037 mtspr SPRN_DBAT6L,r10
1038 mtspr SPRN_DBAT7U,r10
1039 mtspr SPRN_DBAT7L,r10
1040 mtspr SPRN_IBAT4U,r10
1041 mtspr SPRN_IBAT4L,r10
1042 mtspr SPRN_IBAT5U,r10
1043 mtspr SPRN_IBAT5L,r10
1044 mtspr SPRN_IBAT6U,r10
1045 mtspr SPRN_IBAT6L,r10
1046 mtspr SPRN_IBAT7U,r10
1047 mtspr SPRN_IBAT7L,r10
1048 END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
1049 blr
1050
1051 _ENTRY(update_bats)
1052 lis r4, 1f@h
1053 ori r4, r4, 1f@l
1054 tophys(r4, r4)
1055 mfmsr r6
1056 mflr r7
1057 li r3, MSR_KERNEL & ~(MSR_IR | MSR_DR)
1058 rlwinm r0, r6, 0, ~MSR_RI
1059 rlwinm r0, r0, 0, ~MSR_EE
1060 mtmsr r0
1061 mtspr SPRN_SRR0, r4
1062 mtspr SPRN_SRR1, r3
1063 SYNC
1064 RFI
1065 1: bl clear_bats
1066 lis r3, BATS@ha
1067 addi r3, r3, BATS@l
1068 tophys(r3, r3)
1069 LOAD_BAT(0, r3, r4, r5)
1070 LOAD_BAT(1, r3, r4, r5)
1071 LOAD_BAT(2, r3, r4, r5)
1072 LOAD_BAT(3, r3, r4, r5)
1073 BEGIN_MMU_FTR_SECTION
1074 LOAD_BAT(4, r3, r4, r5)
1075 LOAD_BAT(5, r3, r4, r5)
1076 LOAD_BAT(6, r3, r4, r5)
1077 LOAD_BAT(7, r3, r4, r5)
1078 END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
1079 li r3, MSR_KERNEL & ~(MSR_IR | MSR_DR | MSR_RI)
1080 mtmsr r3
1081 mtspr SPRN_SRR0, r7
1082 mtspr SPRN_SRR1, r6
1083 SYNC
1084 RFI
1085
1086 flush_tlbs:
1087 lis r10, 0x40
1088 1: addic. r10, r10, -0x1000
1089 tlbie r10
1090 bgt 1b
1091 sync
1092 blr
1093
1094 mmu_off:
1095 addi r4, r3, __after_mmu_off - _start
1096 mfmsr r3
1097 andi. r0,r3,MSR_DR|MSR_IR
1098 beqlr
1099 andc r3,r3,r0
1100 mtspr SPRN_SRR0,r4
1101 mtspr SPRN_SRR1,r3
1102 sync
1103 RFI
1104
1105
1106
1107
1108
1109 initial_bats:
1110 lis r11,PAGE_OFFSET@h
1111 #ifdef CONFIG_PPC_BOOK3S_601
1112 ori r11,r11,4
1113 li r8,0x7f
1114 mtspr SPRN_IBAT0U,r11
1115 mtspr SPRN_IBAT0L,r8
1116 addis r11,r11,0x800000@h
1117 addis r8,r8,0x800000@h
1118 mtspr SPRN_IBAT1U,r11
1119 mtspr SPRN_IBAT1L,r8
1120 addis r11,r11,0x800000@h
1121 addis r8,r8,0x800000@h
1122 mtspr SPRN_IBAT2U,r11
1123 mtspr SPRN_IBAT2L,r8
1124 #else
1125 tophys(r8,r11)
1126 #ifdef CONFIG_SMP
1127 ori r8,r8,0x12
1128 #else
1129 ori r8,r8,2
1130 #endif
1131 ori r11,r11,BL_256M<<2|0x2
1132
1133 mtspr SPRN_DBAT0L,r8
1134 mtspr SPRN_DBAT0U,r11
1135 mtspr SPRN_IBAT0L,r8
1136 mtspr SPRN_IBAT0U,r11
1137 #endif
1138 isync
1139 blr
1140
1141 #ifdef CONFIG_BOOTX_TEXT
1142 setup_disp_bat:
1143
1144
1145
1146 mflr r8
1147 bl reloc_offset
1148 mtlr r8
1149 addis r8,r3,disp_BAT@ha
1150 addi r8,r8,disp_BAT@l
1151 cmpwi cr0,r8,0
1152 beqlr
1153 lwz r11,0(r8)
1154 lwz r8,4(r8)
1155 #ifndef CONFIG_PPC_BOOK3S_601
1156 mtspr SPRN_DBAT3L,r8
1157 mtspr SPRN_DBAT3U,r11
1158 #else
1159 mtspr SPRN_IBAT3L,r8
1160 mtspr SPRN_IBAT3U,r11
1161 #endif
1162 blr
1163 #endif
1164
1165 #ifdef CONFIG_PPC_EARLY_DEBUG_CPM
1166 setup_cpm_bat:
1167 lis r8, 0xf000
1168 ori r8, r8, 0x002a
1169 mtspr SPRN_DBAT1L, r8
1170
1171 lis r11, 0xf000
1172 ori r11, r11, (BL_1M << 2) | 2
1173 mtspr SPRN_DBAT1U, r11
1174
1175 blr
1176 #endif
1177
1178 #ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
1179 setup_usbgecko_bat:
1180
1181 #if defined(CONFIG_GAMECUBE)
1182 lis r8, 0x0c00
1183 #elif defined(CONFIG_WII)
1184 lis r8, 0x0d00
1185 #else
1186 #error Invalid platform for USB Gecko based early debugging.
1187 #endif
1188
1189
1190
1191
1192 lis r11, 0xfffe
1193 ori r8, r8, 0x002a
1194 ori r11, r11, 0x2
1195 mtspr SPRN_DBAT1L, r8
1196 mtspr SPRN_DBAT1U, r11
1197 blr
1198 #endif
1199
1200 #ifdef CONFIG_8260
1201
1202
1203
1204
1205
1206
1207
1208 .globl m8260_gorom
1209 m8260_gorom:
1210 mfmsr r0
1211 rlwinm r0,r0,0,17,15
1212 sync
1213 mtmsr r0
1214 sync
1215 mfspr r11, SPRN_HID0
1216 lis r10, 0
1217 ori r10,r10,HID0_ICE|HID0_DCE
1218 andc r11, r11, r10
1219 mtspr SPRN_HID0, r11
1220 isync
1221 li r5, MSR_ME|MSR_RI
1222 lis r6,2f@h
1223 addis r6,r6,-KERNELBASE@h
1224 ori r6,r6,2f@l
1225 mtspr SPRN_SRR0,r6
1226 mtspr SPRN_SRR1,r5
1227 isync
1228 sync
1229 rfi
1230 2:
1231 mtlr r4
1232 blr
1233 #endif
1234
1235
1236
1237
1238
1239
1240
1241 .data
1242 .globl sdata
1243 sdata:
1244 .globl empty_zero_page
1245 empty_zero_page:
1246 .space 4096
1247 EXPORT_SYMBOL(empty_zero_page)
1248
1249 .globl swapper_pg_dir
1250 swapper_pg_dir:
1251 .space PGD_TABLE_SIZE
1252
1253
1254
1255
1256 abatron_pteptrs:
1257 .space 8