head.S 41 KB

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