head_32.S 38 KB

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