head.S 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540
  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/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 (unknown_exception) when done. */
  322. #if defined(CONFIG_GEMINI) && defined(CONFIG_SMP)
  323. . = 0x100
  324. b __secondary_start_gemini
  325. #else
  326. EXCEPTION(0x100, Reset, unknown_exception, 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, machine_check_exception)
  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, alignment_exception)
  422. /* Program check exception */
  423. EXCEPTION(0x700, ProgramCheck, program_check_exception, 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, kernel_fp_unavailable_exception)
  431. /* Decrementer */
  432. EXCEPTION(0x900, Decrementer, timer_interrupt, EXC_XFER_LITE)
  433. EXCEPTION(0xa00, Trap_0a, unknown_exception, EXC_XFER_EE)
  434. EXCEPTION(0xb00, Trap_0b, unknown_exception, 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, single_step_exception, EXC_XFER_STD)
  442. EXCEPTION(0xe00, Trap_0e, unknown_exception, 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, unknown_exception)
  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 altivec_assist_exception unknown_exception
  654. #endif
  655. EXCEPTION(0x1300, Trap_13, instruction_breakpoint_exception, EXC_XFER_EE)
  656. EXCEPTION(0x1400, SMI, SMIException, EXC_XFER_EE)
  657. EXCEPTION(0x1500, Trap_15, unknown_exception, EXC_XFER_EE)
  658. #ifdef CONFIG_POWER4
  659. EXCEPTION(0x1600, Trap_16, unknown_exception, EXC_XFER_EE)
  660. EXCEPTION(0x1700, Trap_17, altivec_assist_exception, EXC_XFER_EE)
  661. EXCEPTION(0x1800, Trap_18, TAUException, EXC_XFER_STD)
  662. #else /* !CONFIG_POWER4 */
  663. EXCEPTION(0x1600, Trap_16, altivec_assist_exception, EXC_XFER_EE)
  664. EXCEPTION(0x1700, Trap_17, TAUException, EXC_XFER_STD)
  665. EXCEPTION(0x1800, Trap_18, unknown_exception, EXC_XFER_EE)
  666. #endif /* CONFIG_POWER4 */
  667. EXCEPTION(0x1900, Trap_19, unknown_exception, EXC_XFER_EE)
  668. EXCEPTION(0x1a00, Trap_1a, unknown_exception, EXC_XFER_EE)
  669. EXCEPTION(0x1b00, Trap_1b, unknown_exception, EXC_XFER_EE)
  670. EXCEPTION(0x1c00, Trap_1c, unknown_exception, EXC_XFER_EE)
  671. EXCEPTION(0x1d00, Trap_1d, unknown_exception, EXC_XFER_EE)
  672. EXCEPTION(0x1e00, Trap_1e, unknown_exception, EXC_XFER_EE)
  673. EXCEPTION(0x1f00, Trap_1f, unknown_exception, EXC_XFER_EE)
  674. EXCEPTION(0x2000, RunMode, RunModeException, EXC_XFER_EE)
  675. EXCEPTION(0x2100, Trap_21, unknown_exception, EXC_XFER_EE)
  676. EXCEPTION(0x2200, Trap_22, unknown_exception, EXC_XFER_EE)
  677. EXCEPTION(0x2300, Trap_23, unknown_exception, EXC_XFER_EE)
  678. EXCEPTION(0x2400, Trap_24, unknown_exception, EXC_XFER_EE)
  679. EXCEPTION(0x2500, Trap_25, unknown_exception, EXC_XFER_EE)
  680. EXCEPTION(0x2600, Trap_26, unknown_exception, EXC_XFER_EE)
  681. EXCEPTION(0x2700, Trap_27, unknown_exception, EXC_XFER_EE)
  682. EXCEPTION(0x2800, Trap_28, unknown_exception, EXC_XFER_EE)
  683. EXCEPTION(0x2900, Trap_29, unknown_exception, EXC_XFER_EE)
  684. EXCEPTION(0x2a00, Trap_2a, unknown_exception, EXC_XFER_EE)
  685. EXCEPTION(0x2b00, Trap_2b, unknown_exception, EXC_XFER_EE)
  686. EXCEPTION(0x2c00, Trap_2c, unknown_exception, EXC_XFER_EE)
  687. EXCEPTION(0x2d00, Trap_2d, unknown_exception, EXC_XFER_EE)
  688. EXCEPTION(0x2e00, Trap_2e, unknown_exception, EXC_XFER_EE)
  689. EXCEPTION(0x2f00, MOLTrampoline, unknown_exception, 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. addi r3,r1,STACK_FRAME_OVERHEAD
  699. EXC_XFER_EE_LITE(0xf20, altivec_unavailable_exception)
  700. #ifdef CONFIG_PPC64BRIDGE
  701. DataAccess:
  702. EXCEPTION_PROLOG
  703. b DataAccessCont
  704. InstructionAccess:
  705. EXCEPTION_PROLOG
  706. b InstructionAccessCont
  707. DataSegment:
  708. EXCEPTION_PROLOG
  709. addi r3,r1,STACK_FRAME_OVERHEAD
  710. mfspr r4,SPRN_DAR
  711. stw r4,_DAR(r11)
  712. EXC_XFER_STD(0x380, unknown_exception)
  713. InstructionSegment:
  714. EXCEPTION_PROLOG
  715. addi r3,r1,STACK_FRAME_OVERHEAD
  716. EXC_XFER_STD(0x480, unknown_exception)
  717. #endif /* CONFIG_PPC64BRIDGE */
  718. #ifdef CONFIG_ALTIVEC
  719. /* Note that the AltiVec support is closely modeled after the FP
  720. * support. Changes to one are likely to be applicable to the
  721. * other! */
  722. load_up_altivec:
  723. /*
  724. * Disable AltiVec for the task which had AltiVec previously,
  725. * and save its AltiVec registers in its thread_struct.
  726. * Enables AltiVec for use in the kernel on return.
  727. * On SMP we know the AltiVec units are free, since we give it up every
  728. * switch. -- Kumar
  729. */
  730. mfmsr r5
  731. oris r5,r5,MSR_VEC@h
  732. MTMSRD(r5) /* enable use of AltiVec now */
  733. isync
  734. /*
  735. * For SMP, we don't do lazy AltiVec switching because it just gets too
  736. * horrendously complex, especially when a task switches from one CPU
  737. * to another. Instead we call giveup_altivec in switch_to.
  738. */
  739. #ifndef CONFIG_SMP
  740. tophys(r6,0)
  741. addis r3,r6,last_task_used_altivec@ha
  742. lwz r4,last_task_used_altivec@l(r3)
  743. cmpwi 0,r4,0
  744. beq 1f
  745. add r4,r4,r6
  746. addi r4,r4,THREAD /* want THREAD of last_task_used_altivec */
  747. SAVE_32VRS(0,r10,r4)
  748. mfvscr vr0
  749. li r10,THREAD_VSCR
  750. stvx vr0,r10,r4
  751. lwz r5,PT_REGS(r4)
  752. add r5,r5,r6
  753. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  754. lis r10,MSR_VEC@h
  755. andc r4,r4,r10 /* disable altivec for previous task */
  756. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  757. 1:
  758. #endif /* CONFIG_SMP */
  759. /* enable use of AltiVec after return */
  760. oris r9,r9,MSR_VEC@h
  761. mfspr r5,SPRN_SPRG3 /* current task's THREAD (phys) */
  762. li r4,1
  763. li r10,THREAD_VSCR
  764. stw r4,THREAD_USED_VR(r5)
  765. lvx vr0,r10,r5
  766. mtvscr vr0
  767. REST_32VRS(0,r10,r5)
  768. #ifndef CONFIG_SMP
  769. subi r4,r5,THREAD
  770. sub r4,r4,r6
  771. stw r4,last_task_used_altivec@l(r3)
  772. #endif /* CONFIG_SMP */
  773. /* restore registers and return */
  774. /* we haven't used ctr or xer or lr */
  775. b fast_exception_return
  776. /*
  777. * AltiVec unavailable trap from kernel - print a message, but let
  778. * the task use AltiVec in the kernel until it returns to user mode.
  779. */
  780. KernelAltiVec:
  781. lwz r3,_MSR(r1)
  782. oris r3,r3,MSR_VEC@h
  783. stw r3,_MSR(r1) /* enable use of AltiVec after return */
  784. lis r3,87f@h
  785. ori r3,r3,87f@l
  786. mr r4,r2 /* current */
  787. lwz r5,_NIP(r1)
  788. bl printk
  789. b ret_from_except
  790. 87: .string "AltiVec used in kernel (task=%p, pc=%x) \n"
  791. .align 4,0
  792. /*
  793. * giveup_altivec(tsk)
  794. * Disable AltiVec for the task given as the argument,
  795. * and save the AltiVec registers in its thread_struct.
  796. * Enables AltiVec for use in the kernel on return.
  797. */
  798. .globl giveup_altivec
  799. giveup_altivec:
  800. mfmsr r5
  801. oris r5,r5,MSR_VEC@h
  802. SYNC
  803. MTMSRD(r5) /* enable use of AltiVec now */
  804. isync
  805. cmpwi 0,r3,0
  806. beqlr- /* if no previous owner, done */
  807. addi r3,r3,THREAD /* want THREAD of task */
  808. lwz r5,PT_REGS(r3)
  809. cmpwi 0,r5,0
  810. SAVE_32VRS(0, r4, r3)
  811. mfvscr vr0
  812. li r4,THREAD_VSCR
  813. stvx vr0,r4,r3
  814. beq 1f
  815. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  816. lis r3,MSR_VEC@h
  817. andc r4,r4,r3 /* disable AltiVec for previous task */
  818. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  819. 1:
  820. #ifndef CONFIG_SMP
  821. li r5,0
  822. lis r4,last_task_used_altivec@ha
  823. stw r5,last_task_used_altivec@l(r4)
  824. #endif /* CONFIG_SMP */
  825. blr
  826. #endif /* CONFIG_ALTIVEC */
  827. /*
  828. * This code is jumped to from the startup code to copy
  829. * the kernel image to physical address 0.
  830. */
  831. relocate_kernel:
  832. addis r9,r26,klimit@ha /* fetch klimit */
  833. lwz r25,klimit@l(r9)
  834. addis r25,r25,-KERNELBASE@h
  835. li r3,0 /* Destination base address */
  836. li r6,0 /* Destination offset */
  837. li r5,0x4000 /* # bytes of memory to copy */
  838. bl copy_and_flush /* copy the first 0x4000 bytes */
  839. addi r0,r3,4f@l /* jump to the address of 4f */
  840. mtctr r0 /* in copy and do the rest. */
  841. bctr /* jump to the copy */
  842. 4: mr r5,r25
  843. bl copy_and_flush /* copy the rest */
  844. b turn_on_mmu
  845. /*
  846. * Copy routine used to copy the kernel to start at physical address 0
  847. * and flush and invalidate the caches as needed.
  848. * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
  849. * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
  850. */
  851. copy_and_flush:
  852. addi r5,r5,-4
  853. addi r6,r6,-4
  854. 4: li r0,L1_CACHE_BYTES/4
  855. mtctr r0
  856. 3: addi r6,r6,4 /* copy a cache line */
  857. lwzx r0,r6,r4
  858. stwx r0,r6,r3
  859. bdnz 3b
  860. dcbst r6,r3 /* write it to memory */
  861. sync
  862. icbi r6,r3 /* flush the icache line */
  863. cmplw 0,r6,r5
  864. blt 4b
  865. sync /* additional sync needed on g4 */
  866. isync
  867. addi r5,r5,4
  868. addi r6,r6,4
  869. blr
  870. #ifdef CONFIG_APUS
  871. /*
  872. * On APUS the physical base address of the kernel is not known at compile
  873. * time, which means the __pa/__va constants used are incorrect. In the
  874. * __init section is recorded the virtual addresses of instructions using
  875. * these constants, so all that has to be done is fix these before
  876. * continuing the kernel boot.
  877. *
  878. * r4 = The physical address of the kernel base.
  879. */
  880. fix_mem_constants:
  881. mr r10,r4
  882. addis r10,r10,-KERNELBASE@h /* virt_to_phys constant */
  883. neg r11,r10 /* phys_to_virt constant */
  884. lis r12,__vtop_table_begin@h
  885. ori r12,r12,__vtop_table_begin@l
  886. add r12,r12,r10 /* table begin phys address */
  887. lis r13,__vtop_table_end@h
  888. ori r13,r13,__vtop_table_end@l
  889. add r13,r13,r10 /* table end phys address */
  890. subi r12,r12,4
  891. subi r13,r13,4
  892. 1: lwzu r14,4(r12) /* virt address of instruction */
  893. add r14,r14,r10 /* phys address of instruction */
  894. lwz r15,0(r14) /* instruction, now insert top */
  895. rlwimi r15,r10,16,16,31 /* half of vp const in low half */
  896. stw r15,0(r14) /* of instruction and restore. */
  897. dcbst r0,r14 /* write it to memory */
  898. sync
  899. icbi r0,r14 /* flush the icache line */
  900. cmpw r12,r13
  901. bne 1b
  902. sync /* additional sync needed on g4 */
  903. isync
  904. /*
  905. * Map the memory where the exception handlers will
  906. * be copied to when hash constants have been patched.
  907. */
  908. #ifdef CONFIG_APUS_FAST_EXCEPT
  909. lis r8,0xfff0
  910. #else
  911. lis r8,0
  912. #endif
  913. ori r8,r8,0x2 /* 128KB, supervisor */
  914. mtspr SPRN_DBAT3U,r8
  915. mtspr SPRN_DBAT3L,r8
  916. lis r12,__ptov_table_begin@h
  917. ori r12,r12,__ptov_table_begin@l
  918. add r12,r12,r10 /* table begin phys address */
  919. lis r13,__ptov_table_end@h
  920. ori r13,r13,__ptov_table_end@l
  921. add r13,r13,r10 /* table end phys address */
  922. subi r12,r12,4
  923. subi r13,r13,4
  924. 1: lwzu r14,4(r12) /* virt address of instruction */
  925. add r14,r14,r10 /* phys address of instruction */
  926. lwz r15,0(r14) /* instruction, now insert top */
  927. rlwimi r15,r11,16,16,31 /* half of pv const in low half*/
  928. stw r15,0(r14) /* of instruction and restore. */
  929. dcbst r0,r14 /* write it to memory */
  930. sync
  931. icbi r0,r14 /* flush the icache line */
  932. cmpw r12,r13
  933. bne 1b
  934. sync /* additional sync needed on g4 */
  935. isync /* No speculative loading until now */
  936. blr
  937. /***********************************************************************
  938. * Please note that on APUS the exception handlers are located at the
  939. * physical address 0xfff0000. For this reason, the exception handlers
  940. * cannot use relative branches to access the code below.
  941. ***********************************************************************/
  942. #endif /* CONFIG_APUS */
  943. #ifdef CONFIG_SMP
  944. #ifdef CONFIG_GEMINI
  945. .globl __secondary_start_gemini
  946. __secondary_start_gemini:
  947. mfspr r4,SPRN_HID0
  948. ori r4,r4,HID0_ICFI
  949. li r3,0
  950. ori r3,r3,HID0_ICE
  951. andc r4,r4,r3
  952. mtspr SPRN_HID0,r4
  953. sync
  954. b __secondary_start
  955. #endif /* CONFIG_GEMINI */
  956. .globl __secondary_start_pmac_0
  957. __secondary_start_pmac_0:
  958. /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
  959. li r24,0
  960. b 1f
  961. li r24,1
  962. b 1f
  963. li r24,2
  964. b 1f
  965. li r24,3
  966. 1:
  967. /* on powersurge, we come in here with IR=0 and DR=1, and DBAT 0
  968. set to map the 0xf0000000 - 0xffffffff region */
  969. mfmsr r0
  970. rlwinm r0,r0,0,28,26 /* clear DR (0x10) */
  971. SYNC
  972. mtmsr r0
  973. isync
  974. .globl __secondary_start
  975. __secondary_start:
  976. #ifdef CONFIG_PPC64BRIDGE
  977. mfmsr r0
  978. clrldi r0,r0,1 /* make sure it's in 32-bit mode */
  979. SYNC
  980. MTMSRD(r0)
  981. isync
  982. #endif
  983. /* Copy some CPU settings from CPU 0 */
  984. bl __restore_cpu_setup
  985. lis r3,-KERNELBASE@h
  986. mr r4,r24
  987. bl call_setup_cpu /* Call setup_cpu for this CPU */
  988. #ifdef CONFIG_6xx
  989. lis r3,-KERNELBASE@h
  990. bl init_idle_6xx
  991. #endif /* CONFIG_6xx */
  992. #ifdef CONFIG_POWER4
  993. lis r3,-KERNELBASE@h
  994. bl init_idle_power4
  995. #endif /* CONFIG_POWER4 */
  996. /* get current_thread_info and current */
  997. lis r1,secondary_ti@ha
  998. tophys(r1,r1)
  999. lwz r1,secondary_ti@l(r1)
  1000. tophys(r2,r1)
  1001. lwz r2,TI_TASK(r2)
  1002. /* stack */
  1003. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  1004. li r0,0
  1005. tophys(r3,r1)
  1006. stw r0,0(r3)
  1007. /* load up the MMU */
  1008. bl load_up_mmu
  1009. /* ptr to phys current thread */
  1010. tophys(r4,r2)
  1011. addi r4,r4,THREAD /* phys address of our thread_struct */
  1012. CLR_TOP32(r4)
  1013. mtspr SPRN_SPRG3,r4
  1014. li r3,0
  1015. mtspr SPRN_SPRG2,r3 /* 0 => not in RTAS */
  1016. /* enable MMU and jump to start_secondary */
  1017. li r4,MSR_KERNEL
  1018. FIX_SRR1(r4,r5)
  1019. lis r3,start_secondary@h
  1020. ori r3,r3,start_secondary@l
  1021. mtspr SPRN_SRR0,r3
  1022. mtspr SPRN_SRR1,r4
  1023. SYNC
  1024. RFI
  1025. #endif /* CONFIG_SMP */
  1026. /*
  1027. * Those generic dummy functions are kept for CPUs not
  1028. * included in CONFIG_6xx
  1029. */
  1030. #if !defined(CONFIG_6xx) && !defined(CONFIG_POWER4)
  1031. _GLOBAL(__save_cpu_setup)
  1032. blr
  1033. _GLOBAL(__restore_cpu_setup)
  1034. blr
  1035. #endif /* !defined(CONFIG_6xx) && !defined(CONFIG_POWER4) */
  1036. /*
  1037. * Load stuff into the MMU. Intended to be called with
  1038. * IR=0 and DR=0.
  1039. */
  1040. load_up_mmu:
  1041. sync /* Force all PTE updates to finish */
  1042. isync
  1043. tlbia /* Clear all TLB entries */
  1044. sync /* wait for tlbia/tlbie to finish */
  1045. TLBSYNC /* ... on all CPUs */
  1046. /* Load the SDR1 register (hash table base & size) */
  1047. lis r6,_SDR1@ha
  1048. tophys(r6,r6)
  1049. lwz r6,_SDR1@l(r6)
  1050. mtspr SPRN_SDR1,r6
  1051. #ifdef CONFIG_PPC64BRIDGE
  1052. /* clear the ASR so we only use the pseudo-segment registers. */
  1053. li r6,0
  1054. mtasr r6
  1055. #endif /* CONFIG_PPC64BRIDGE */
  1056. li r0,16 /* load up segment register values */
  1057. mtctr r0 /* for context 0 */
  1058. lis r3,0x2000 /* Ku = 1, VSID = 0 */
  1059. li r4,0
  1060. 3: mtsrin r3,r4
  1061. addi r3,r3,0x111 /* increment VSID */
  1062. addis r4,r4,0x1000 /* address of next segment */
  1063. bdnz 3b
  1064. #ifndef CONFIG_POWER4
  1065. /* Load the BAT registers with the values set up by MMU_init.
  1066. MMU_init takes care of whether we're on a 601 or not. */
  1067. mfpvr r3
  1068. srwi r3,r3,16
  1069. cmpwi r3,1
  1070. lis r3,BATS@ha
  1071. addi r3,r3,BATS@l
  1072. tophys(r3,r3)
  1073. LOAD_BAT(0,r3,r4,r5)
  1074. LOAD_BAT(1,r3,r4,r5)
  1075. LOAD_BAT(2,r3,r4,r5)
  1076. LOAD_BAT(3,r3,r4,r5)
  1077. #endif /* CONFIG_POWER4 */
  1078. blr
  1079. /*
  1080. * This is where the main kernel code starts.
  1081. */
  1082. start_here:
  1083. /* ptr to current */
  1084. lis r2,init_task@h
  1085. ori r2,r2,init_task@l
  1086. /* Set up for using our exception vectors */
  1087. /* ptr to phys current thread */
  1088. tophys(r4,r2)
  1089. addi r4,r4,THREAD /* init task's THREAD */
  1090. CLR_TOP32(r4)
  1091. mtspr SPRN_SPRG3,r4
  1092. li r3,0
  1093. mtspr SPRN_SPRG2,r3 /* 0 => not in RTAS */
  1094. /* stack */
  1095. lis r1,init_thread_union@ha
  1096. addi r1,r1,init_thread_union@l
  1097. li r0,0
  1098. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  1099. /*
  1100. * Do early bootinfo parsing, platform-specific initialization,
  1101. * and set up the MMU.
  1102. */
  1103. mr r3,r31
  1104. mr r4,r30
  1105. mr r5,r29
  1106. mr r6,r28
  1107. mr r7,r27
  1108. bl machine_init
  1109. bl MMU_init
  1110. #ifdef CONFIG_APUS
  1111. /* Copy exception code to exception vector base on APUS. */
  1112. lis r4,KERNELBASE@h
  1113. #ifdef CONFIG_APUS_FAST_EXCEPT
  1114. lis r3,0xfff0 /* Copy to 0xfff00000 */
  1115. #else
  1116. lis r3,0 /* Copy to 0x00000000 */
  1117. #endif
  1118. li r5,0x4000 /* # bytes of memory to copy */
  1119. li r6,0
  1120. bl copy_and_flush /* copy the first 0x4000 bytes */
  1121. #endif /* CONFIG_APUS */
  1122. /*
  1123. * Go back to running unmapped so we can load up new values
  1124. * for SDR1 (hash table pointer) and the segment registers
  1125. * and change to using our exception vectors.
  1126. */
  1127. lis r4,2f@h
  1128. ori r4,r4,2f@l
  1129. tophys(r4,r4)
  1130. li r3,MSR_KERNEL & ~(MSR_IR|MSR_DR)
  1131. FIX_SRR1(r3,r5)
  1132. mtspr SPRN_SRR0,r4
  1133. mtspr SPRN_SRR1,r3
  1134. SYNC
  1135. RFI
  1136. /* Load up the kernel context */
  1137. 2: bl load_up_mmu
  1138. #ifdef CONFIG_BDI_SWITCH
  1139. /* Add helper information for the Abatron bdiGDB debugger.
  1140. * We do this here because we know the mmu is disabled, and
  1141. * will be enabled for real in just a few instructions.
  1142. */
  1143. lis r5, abatron_pteptrs@h
  1144. ori r5, r5, abatron_pteptrs@l
  1145. stw r5, 0xf0(r0) /* This much match your Abatron config */
  1146. lis r6, swapper_pg_dir@h
  1147. ori r6, r6, swapper_pg_dir@l
  1148. tophys(r5, r5)
  1149. stw r6, 0(r5)
  1150. #endif /* CONFIG_BDI_SWITCH */
  1151. /* Now turn on the MMU for real! */
  1152. li r4,MSR_KERNEL
  1153. FIX_SRR1(r4,r5)
  1154. lis r3,start_kernel@h
  1155. ori r3,r3,start_kernel@l
  1156. mtspr SPRN_SRR0,r3
  1157. mtspr SPRN_SRR1,r4
  1158. SYNC
  1159. RFI
  1160. /*
  1161. * Set up the segment registers for a new context.
  1162. */
  1163. _GLOBAL(set_context)
  1164. mulli r3,r3,897 /* multiply context by skew factor */
  1165. rlwinm r3,r3,4,8,27 /* VSID = (context & 0xfffff) << 4 */
  1166. addis r3,r3,0x6000 /* Set Ks, Ku bits */
  1167. li r0,NUM_USER_SEGMENTS
  1168. mtctr r0
  1169. #ifdef CONFIG_BDI_SWITCH
  1170. /* Context switch the PTE pointer for the Abatron BDI2000.
  1171. * The PGDIR is passed as second argument.
  1172. */
  1173. lis r5, KERNELBASE@h
  1174. lwz r5, 0xf0(r5)
  1175. stw r4, 0x4(r5)
  1176. #endif
  1177. li r4,0
  1178. isync
  1179. 3:
  1180. #ifdef CONFIG_PPC64BRIDGE
  1181. slbie r4
  1182. #endif /* CONFIG_PPC64BRIDGE */
  1183. mtsrin r3,r4
  1184. addi r3,r3,0x111 /* next VSID */
  1185. rlwinm r3,r3,0,8,3 /* clear out any overflow from VSID field */
  1186. addis r4,r4,0x1000 /* address of next segment */
  1187. bdnz 3b
  1188. sync
  1189. isync
  1190. blr
  1191. /*
  1192. * An undocumented "feature" of 604e requires that the v bit
  1193. * be cleared before changing BAT values.
  1194. *
  1195. * Also, newer IBM firmware does not clear bat3 and 4 so
  1196. * this makes sure it's done.
  1197. * -- Cort
  1198. */
  1199. clear_bats:
  1200. li r10,0
  1201. mfspr r9,SPRN_PVR
  1202. rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
  1203. cmpwi r9, 1
  1204. beq 1f
  1205. mtspr SPRN_DBAT0U,r10
  1206. mtspr SPRN_DBAT0L,r10
  1207. mtspr SPRN_DBAT1U,r10
  1208. mtspr SPRN_DBAT1L,r10
  1209. mtspr SPRN_DBAT2U,r10
  1210. mtspr SPRN_DBAT2L,r10
  1211. mtspr SPRN_DBAT3U,r10
  1212. mtspr SPRN_DBAT3L,r10
  1213. 1:
  1214. mtspr SPRN_IBAT0U,r10
  1215. mtspr SPRN_IBAT0L,r10
  1216. mtspr SPRN_IBAT1U,r10
  1217. mtspr SPRN_IBAT1L,r10
  1218. mtspr SPRN_IBAT2U,r10
  1219. mtspr SPRN_IBAT2L,r10
  1220. mtspr SPRN_IBAT3U,r10
  1221. mtspr SPRN_IBAT3L,r10
  1222. BEGIN_FTR_SECTION
  1223. /* Here's a tweak: at this point, CPU setup have
  1224. * not been called yet, so HIGH_BAT_EN may not be
  1225. * set in HID0 for the 745x processors. However, it
  1226. * seems that doesn't affect our ability to actually
  1227. * write to these SPRs.
  1228. */
  1229. mtspr SPRN_DBAT4U,r10
  1230. mtspr SPRN_DBAT4L,r10
  1231. mtspr SPRN_DBAT5U,r10
  1232. mtspr SPRN_DBAT5L,r10
  1233. mtspr SPRN_DBAT6U,r10
  1234. mtspr SPRN_DBAT6L,r10
  1235. mtspr SPRN_DBAT7U,r10
  1236. mtspr SPRN_DBAT7L,r10
  1237. mtspr SPRN_IBAT4U,r10
  1238. mtspr SPRN_IBAT4L,r10
  1239. mtspr SPRN_IBAT5U,r10
  1240. mtspr SPRN_IBAT5L,r10
  1241. mtspr SPRN_IBAT6U,r10
  1242. mtspr SPRN_IBAT6L,r10
  1243. mtspr SPRN_IBAT7U,r10
  1244. mtspr SPRN_IBAT7L,r10
  1245. END_FTR_SECTION_IFSET(CPU_FTR_HAS_HIGH_BATS)
  1246. blr
  1247. flush_tlbs:
  1248. lis r10, 0x40
  1249. 1: addic. r10, r10, -0x1000
  1250. tlbie r10
  1251. blt 1b
  1252. sync
  1253. blr
  1254. mmu_off:
  1255. addi r4, r3, __after_mmu_off - _start
  1256. mfmsr r3
  1257. andi. r0,r3,MSR_DR|MSR_IR /* MMU enabled? */
  1258. beqlr
  1259. andc r3,r3,r0
  1260. mtspr SPRN_SRR0,r4
  1261. mtspr SPRN_SRR1,r3
  1262. sync
  1263. RFI
  1264. #ifndef CONFIG_POWER4
  1265. /*
  1266. * Use the first pair of BAT registers to map the 1st 16MB
  1267. * of RAM to KERNELBASE. From this point on we can't safely
  1268. * call OF any more.
  1269. */
  1270. initial_bats:
  1271. lis r11,KERNELBASE@h
  1272. #ifndef CONFIG_PPC64BRIDGE
  1273. mfspr r9,SPRN_PVR
  1274. rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
  1275. cmpwi 0,r9,1
  1276. bne 4f
  1277. ori r11,r11,4 /* set up BAT registers for 601 */
  1278. li r8,0x7f /* valid, block length = 8MB */
  1279. oris r9,r11,0x800000@h /* set up BAT reg for 2nd 8M */
  1280. oris r10,r8,0x800000@h /* set up BAT reg for 2nd 8M */
  1281. mtspr SPRN_IBAT0U,r11 /* N.B. 601 has valid bit in */
  1282. mtspr SPRN_IBAT0L,r8 /* lower BAT register */
  1283. mtspr SPRN_IBAT1U,r9
  1284. mtspr SPRN_IBAT1L,r10
  1285. isync
  1286. blr
  1287. #endif /* CONFIG_PPC64BRIDGE */
  1288. 4: tophys(r8,r11)
  1289. #ifdef CONFIG_SMP
  1290. ori r8,r8,0x12 /* R/W access, M=1 */
  1291. #else
  1292. ori r8,r8,2 /* R/W access */
  1293. #endif /* CONFIG_SMP */
  1294. #ifdef CONFIG_APUS
  1295. ori r11,r11,BL_8M<<2|0x2 /* set up 8MB BAT registers for 604 */
  1296. #else
  1297. ori r11,r11,BL_256M<<2|0x2 /* set up BAT registers for 604 */
  1298. #endif /* CONFIG_APUS */
  1299. #ifdef CONFIG_PPC64BRIDGE
  1300. /* clear out the high 32 bits in the BAT */
  1301. clrldi r11,r11,32
  1302. clrldi r8,r8,32
  1303. #endif /* CONFIG_PPC64BRIDGE */
  1304. mtspr SPRN_DBAT0L,r8 /* N.B. 6xx (not 601) have valid */
  1305. mtspr SPRN_DBAT0U,r11 /* bit in upper BAT register */
  1306. mtspr SPRN_IBAT0L,r8
  1307. mtspr SPRN_IBAT0U,r11
  1308. isync
  1309. blr
  1310. #if !defined(CONFIG_APUS) && defined(CONFIG_BOOTX_TEXT)
  1311. setup_disp_bat:
  1312. /*
  1313. * setup the display bat prepared for us in prom.c
  1314. */
  1315. mflr r8
  1316. bl reloc_offset
  1317. mtlr r8
  1318. addis r8,r3,disp_BAT@ha
  1319. addi r8,r8,disp_BAT@l
  1320. lwz r11,0(r8)
  1321. lwz r8,4(r8)
  1322. mfspr r9,SPRN_PVR
  1323. rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
  1324. cmpwi 0,r9,1
  1325. beq 1f
  1326. mtspr SPRN_DBAT3L,r8
  1327. mtspr SPRN_DBAT3U,r11
  1328. blr
  1329. 1: mtspr SPRN_IBAT3L,r8
  1330. mtspr SPRN_IBAT3U,r11
  1331. blr
  1332. #endif /* !defined(CONFIG_APUS) && defined(CONFIG_BOOTX_TEXT) */
  1333. #else /* CONFIG_POWER4 */
  1334. /*
  1335. * Load up the SDR1 and segment register values now
  1336. * since we don't have the BATs.
  1337. * Also make sure we are running in 32-bit mode.
  1338. */
  1339. initial_mm_power4:
  1340. addis r14,r3,_SDR1@ha /* get the value from _SDR1 */
  1341. lwz r14,_SDR1@l(r14) /* assume hash table below 4GB */
  1342. mtspr SPRN_SDR1,r14
  1343. slbia
  1344. lis r4,0x2000 /* set pseudo-segment reg 12 */
  1345. ori r5,r4,0x0ccc
  1346. mtsr 12,r5
  1347. #if 0
  1348. ori r5,r4,0x0888 /* set pseudo-segment reg 8 */
  1349. mtsr 8,r5 /* (for access to serial port) */
  1350. #endif
  1351. #ifdef CONFIG_BOOTX_TEXT
  1352. ori r5,r4,0x0999 /* set pseudo-segment reg 9 */
  1353. mtsr 9,r5 /* (for access to screen) */
  1354. #endif
  1355. mfmsr r0
  1356. clrldi r0,r0,1
  1357. sync
  1358. mtmsr r0
  1359. isync
  1360. blr
  1361. #endif /* CONFIG_POWER4 */
  1362. #ifdef CONFIG_8260
  1363. /* Jump into the system reset for the rom.
  1364. * We first disable the MMU, and then jump to the ROM reset address.
  1365. *
  1366. * r3 is the board info structure, r4 is the location for starting.
  1367. * I use this for building a small kernel that can load other kernels,
  1368. * rather than trying to write or rely on a rom monitor that can tftp load.
  1369. */
  1370. .globl m8260_gorom
  1371. m8260_gorom:
  1372. mfmsr r0
  1373. rlwinm r0,r0,0,17,15 /* clear MSR_EE in r0 */
  1374. sync
  1375. mtmsr r0
  1376. sync
  1377. mfspr r11, SPRN_HID0
  1378. lis r10, 0
  1379. ori r10,r10,HID0_ICE|HID0_DCE
  1380. andc r11, r11, r10
  1381. mtspr SPRN_HID0, r11
  1382. isync
  1383. li r5, MSR_ME|MSR_RI
  1384. lis r6,2f@h
  1385. addis r6,r6,-KERNELBASE@h
  1386. ori r6,r6,2f@l
  1387. mtspr SPRN_SRR0,r6
  1388. mtspr SPRN_SRR1,r5
  1389. isync
  1390. sync
  1391. rfi
  1392. 2:
  1393. mtlr r4
  1394. blr
  1395. #endif
  1396. /*
  1397. * We put a few things here that have to be page-aligned.
  1398. * This stuff goes at the beginning of the data segment,
  1399. * which is page-aligned.
  1400. */
  1401. .data
  1402. .globl sdata
  1403. sdata:
  1404. .globl empty_zero_page
  1405. empty_zero_page:
  1406. .space 4096
  1407. .globl swapper_pg_dir
  1408. swapper_pg_dir:
  1409. .space 4096
  1410. /*
  1411. * This space gets a copy of optional info passed to us by the bootstrap
  1412. * Used to pass parameters into the kernel like root=/dev/sda1, etc.
  1413. */
  1414. .globl cmd_line
  1415. cmd_line:
  1416. .space 512
  1417. .globl intercept_table
  1418. intercept_table:
  1419. .long 0, 0, i0x200, i0x300, i0x400, 0, i0x600, i0x700
  1420. .long i0x800, 0, 0, 0, 0, i0xd00, 0, 0
  1421. .long 0, 0, 0, i0x1300, 0, 0, 0, 0
  1422. .long 0, 0, 0, 0, 0, 0, 0, 0
  1423. .long 0, 0, 0, 0, 0, 0, 0, 0
  1424. .long 0, 0, 0, 0, 0, 0, 0, 0
  1425. /* Room for two PTE pointers, usually the kernel and current user pointers
  1426. * to their respective root page table.
  1427. */
  1428. abatron_pteptrs:
  1429. .space 8