head_32.S 36 KB

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