head_32.S 39 KB

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