head_32.S 35 KB

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