head_32.S 39 KB

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