head_32.S 36 KB

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