head.S 33 KB

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