head_32.S 38 KB

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