head_32.S 34 KB

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