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