head_32.S 35 KB

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