head_32.S 35 KB

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