head_32.S 35 KB

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