head_32.S 35 KB

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