head_32.S 35 KB

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