head_32.S 34 KB

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