head_32.S 35 KB

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