head_32.S 36 KB

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