head_32.S 39 KB

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