head.S 37 KB

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