head_32.S 37 KB

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