head_32.S 35 KB

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