head_32.S 39 KB

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