head_32.S 36 KB

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