head_32.S 36 KB

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