head.S 41 KB

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