head.S 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  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. * giveup_altivec(tsk)
  653. * Disable AltiVec for the task given as the argument,
  654. * and save the AltiVec registers in its thread_struct.
  655. * Enables AltiVec for use in the kernel on return.
  656. */
  657. .globl giveup_altivec
  658. giveup_altivec:
  659. mfmsr r5
  660. oris r5,r5,MSR_VEC@h
  661. SYNC
  662. MTMSRD(r5) /* enable use of AltiVec now */
  663. isync
  664. cmpwi 0,r3,0
  665. beqlr- /* if no previous owner, done */
  666. addi r3,r3,THREAD /* want THREAD of task */
  667. lwz r5,PT_REGS(r3)
  668. cmpwi 0,r5,0
  669. SAVE_32VRS(0, r4, r3)
  670. mfvscr vr0
  671. li r4,THREAD_VSCR
  672. stvx vr0,r4,r3
  673. beq 1f
  674. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  675. lis r3,MSR_VEC@h
  676. andc r4,r4,r3 /* disable AltiVec for previous task */
  677. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  678. 1:
  679. #ifndef CONFIG_SMP
  680. li r5,0
  681. lis r4,last_task_used_altivec@ha
  682. stw r5,last_task_used_altivec@l(r4)
  683. #endif /* CONFIG_SMP */
  684. blr
  685. #endif /* CONFIG_ALTIVEC */
  686. /*
  687. * This code is jumped to from the startup code to copy
  688. * the kernel image to physical address 0.
  689. */
  690. relocate_kernel:
  691. addis r9,r26,klimit@ha /* fetch klimit */
  692. lwz r25,klimit@l(r9)
  693. addis r25,r25,-KERNELBASE@h
  694. li r3,0 /* Destination base address */
  695. li r6,0 /* Destination offset */
  696. li r5,0x4000 /* # bytes of memory to copy */
  697. bl copy_and_flush /* copy the first 0x4000 bytes */
  698. addi r0,r3,4f@l /* jump to the address of 4f */
  699. mtctr r0 /* in copy and do the rest. */
  700. bctr /* jump to the copy */
  701. 4: mr r5,r25
  702. bl copy_and_flush /* copy the rest */
  703. b turn_on_mmu
  704. /*
  705. * Copy routine used to copy the kernel to start at physical address 0
  706. * and flush and invalidate the caches as needed.
  707. * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
  708. * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
  709. */
  710. copy_and_flush:
  711. addi r5,r5,-4
  712. addi r6,r6,-4
  713. 4: li r0,L1_CACHE_BYTES/4
  714. mtctr r0
  715. 3: addi r6,r6,4 /* copy a cache line */
  716. lwzx r0,r6,r4
  717. stwx r0,r6,r3
  718. bdnz 3b
  719. dcbst r6,r3 /* write it to memory */
  720. sync
  721. icbi r6,r3 /* flush the icache line */
  722. cmplw 0,r6,r5
  723. blt 4b
  724. sync /* additional sync needed on g4 */
  725. isync
  726. addi r5,r5,4
  727. addi r6,r6,4
  728. blr
  729. #ifdef CONFIG_SMP
  730. .globl __secondary_start_pmac_0
  731. __secondary_start_pmac_0:
  732. /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
  733. li r24,0
  734. b 1f
  735. li r24,1
  736. b 1f
  737. li r24,2
  738. b 1f
  739. li r24,3
  740. 1:
  741. /* on powersurge, we come in here with IR=0 and DR=1, and DBAT 0
  742. set to map the 0xf0000000 - 0xffffffff region */
  743. mfmsr r0
  744. rlwinm r0,r0,0,28,26 /* clear DR (0x10) */
  745. SYNC
  746. mtmsr r0
  747. isync
  748. .globl __secondary_start
  749. __secondary_start:
  750. /* Copy some CPU settings from CPU 0 */
  751. bl __restore_cpu_setup
  752. lis r3,-KERNELBASE@h
  753. mr r4,r24
  754. bl call_setup_cpu /* Call setup_cpu for this CPU */
  755. #ifdef CONFIG_6xx
  756. lis r3,-KERNELBASE@h
  757. bl init_idle_6xx
  758. #endif /* CONFIG_6xx */
  759. /* get current_thread_info and current */
  760. lis r1,secondary_ti@ha
  761. tophys(r1,r1)
  762. lwz r1,secondary_ti@l(r1)
  763. tophys(r2,r1)
  764. lwz r2,TI_TASK(r2)
  765. /* stack */
  766. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  767. li r0,0
  768. tophys(r3,r1)
  769. stw r0,0(r3)
  770. /* load up the MMU */
  771. bl load_up_mmu
  772. /* ptr to phys current thread */
  773. tophys(r4,r2)
  774. addi r4,r4,THREAD /* phys address of our thread_struct */
  775. CLR_TOP32(r4)
  776. mtspr SPRN_SPRG3,r4
  777. li r3,0
  778. mtspr SPRN_SPRG2,r3 /* 0 => not in RTAS */
  779. /* enable MMU and jump to start_secondary */
  780. li r4,MSR_KERNEL
  781. FIX_SRR1(r4,r5)
  782. lis r3,start_secondary@h
  783. ori r3,r3,start_secondary@l
  784. mtspr SPRN_SRR0,r3
  785. mtspr SPRN_SRR1,r4
  786. SYNC
  787. RFI
  788. #endif /* CONFIG_SMP */
  789. /*
  790. * Those generic dummy functions are kept for CPUs not
  791. * included in CONFIG_6xx
  792. */
  793. #if !defined(CONFIG_6xx)
  794. _GLOBAL(__save_cpu_setup)
  795. blr
  796. _GLOBAL(__restore_cpu_setup)
  797. blr
  798. #endif /* !defined(CONFIG_6xx) */
  799. /*
  800. * Load stuff into the MMU. Intended to be called with
  801. * IR=0 and DR=0.
  802. */
  803. load_up_mmu:
  804. sync /* Force all PTE updates to finish */
  805. isync
  806. tlbia /* Clear all TLB entries */
  807. sync /* wait for tlbia/tlbie to finish */
  808. TLBSYNC /* ... on all CPUs */
  809. /* Load the SDR1 register (hash table base & size) */
  810. lis r6,_SDR1@ha
  811. tophys(r6,r6)
  812. lwz r6,_SDR1@l(r6)
  813. mtspr SPRN_SDR1,r6
  814. li r0,16 /* load up segment register values */
  815. mtctr r0 /* for context 0 */
  816. lis r3,0x2000 /* Ku = 1, VSID = 0 */
  817. li r4,0
  818. 3: mtsrin r3,r4
  819. addi r3,r3,0x111 /* increment VSID */
  820. addis r4,r4,0x1000 /* address of next segment */
  821. bdnz 3b
  822. /* Load the BAT registers with the values set up by MMU_init.
  823. MMU_init takes care of whether we're on a 601 or not. */
  824. mfpvr r3
  825. srwi r3,r3,16
  826. cmpwi r3,1
  827. lis r3,BATS@ha
  828. addi r3,r3,BATS@l
  829. tophys(r3,r3)
  830. LOAD_BAT(0,r3,r4,r5)
  831. LOAD_BAT(1,r3,r4,r5)
  832. LOAD_BAT(2,r3,r4,r5)
  833. LOAD_BAT(3,r3,r4,r5)
  834. blr
  835. /*
  836. * This is where the main kernel code starts.
  837. */
  838. start_here:
  839. /* ptr to current */
  840. lis r2,init_task@h
  841. ori r2,r2,init_task@l
  842. /* Set up for using our exception vectors */
  843. /* ptr to phys current thread */
  844. tophys(r4,r2)
  845. addi r4,r4,THREAD /* init task's THREAD */
  846. CLR_TOP32(r4)
  847. mtspr SPRN_SPRG3,r4
  848. li r3,0
  849. mtspr SPRN_SPRG2,r3 /* 0 => not in RTAS */
  850. /* stack */
  851. lis r1,init_thread_union@ha
  852. addi r1,r1,init_thread_union@l
  853. li r0,0
  854. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  855. /*
  856. * Do early bootinfo parsing, platform-specific initialization,
  857. * and set up the MMU.
  858. */
  859. mr r3,r31
  860. mr r4,r30
  861. mr r5,r29
  862. mr r6,r28
  863. mr r7,r27
  864. bl machine_init
  865. bl MMU_init
  866. /*
  867. * Go back to running unmapped so we can load up new values
  868. * for SDR1 (hash table pointer) and the segment registers
  869. * and change to using our exception vectors.
  870. */
  871. lis r4,2f@h
  872. ori r4,r4,2f@l
  873. tophys(r4,r4)
  874. li r3,MSR_KERNEL & ~(MSR_IR|MSR_DR)
  875. FIX_SRR1(r3,r5)
  876. mtspr SPRN_SRR0,r4
  877. mtspr SPRN_SRR1,r3
  878. SYNC
  879. RFI
  880. /* Load up the kernel context */
  881. 2: bl load_up_mmu
  882. #ifdef CONFIG_BDI_SWITCH
  883. /* Add helper information for the Abatron bdiGDB debugger.
  884. * We do this here because we know the mmu is disabled, and
  885. * will be enabled for real in just a few instructions.
  886. */
  887. lis r5, abatron_pteptrs@h
  888. ori r5, r5, abatron_pteptrs@l
  889. stw r5, 0xf0(r0) /* This much match your Abatron config */
  890. lis r6, swapper_pg_dir@h
  891. ori r6, r6, swapper_pg_dir@l
  892. tophys(r5, r5)
  893. stw r6, 0(r5)
  894. #endif /* CONFIG_BDI_SWITCH */
  895. /* Now turn on the MMU for real! */
  896. li r4,MSR_KERNEL
  897. FIX_SRR1(r4,r5)
  898. lis r3,start_kernel@h
  899. ori r3,r3,start_kernel@l
  900. mtspr SPRN_SRR0,r3
  901. mtspr SPRN_SRR1,r4
  902. SYNC
  903. RFI
  904. /*
  905. * Set up the segment registers for a new context.
  906. */
  907. _GLOBAL(set_context)
  908. mulli r3,r3,897 /* multiply context by skew factor */
  909. rlwinm r3,r3,4,8,27 /* VSID = (context & 0xfffff) << 4 */
  910. addis r3,r3,0x6000 /* Set Ks, Ku bits */
  911. li r0,NUM_USER_SEGMENTS
  912. mtctr r0
  913. #ifdef CONFIG_BDI_SWITCH
  914. /* Context switch the PTE pointer for the Abatron BDI2000.
  915. * The PGDIR is passed as second argument.
  916. */
  917. lis r5, KERNELBASE@h
  918. lwz r5, 0xf0(r5)
  919. stw r4, 0x4(r5)
  920. #endif
  921. li r4,0
  922. isync
  923. 3:
  924. mtsrin r3,r4
  925. addi r3,r3,0x111 /* next VSID */
  926. rlwinm r3,r3,0,8,3 /* clear out any overflow from VSID field */
  927. addis r4,r4,0x1000 /* address of next segment */
  928. bdnz 3b
  929. sync
  930. isync
  931. blr
  932. /*
  933. * An undocumented "feature" of 604e requires that the v bit
  934. * be cleared before changing BAT values.
  935. *
  936. * Also, newer IBM firmware does not clear bat3 and 4 so
  937. * this makes sure it's done.
  938. * -- Cort
  939. */
  940. clear_bats:
  941. li r10,0
  942. mfspr r9,SPRN_PVR
  943. rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
  944. cmpwi r9, 1
  945. beq 1f
  946. mtspr SPRN_DBAT0U,r10
  947. mtspr SPRN_DBAT0L,r10
  948. mtspr SPRN_DBAT1U,r10
  949. mtspr SPRN_DBAT1L,r10
  950. mtspr SPRN_DBAT2U,r10
  951. mtspr SPRN_DBAT2L,r10
  952. mtspr SPRN_DBAT3U,r10
  953. mtspr SPRN_DBAT3L,r10
  954. 1:
  955. mtspr SPRN_IBAT0U,r10
  956. mtspr SPRN_IBAT0L,r10
  957. mtspr SPRN_IBAT1U,r10
  958. mtspr SPRN_IBAT1L,r10
  959. mtspr SPRN_IBAT2U,r10
  960. mtspr SPRN_IBAT2L,r10
  961. mtspr SPRN_IBAT3U,r10
  962. mtspr SPRN_IBAT3L,r10
  963. BEGIN_FTR_SECTION
  964. /* Here's a tweak: at this point, CPU setup have
  965. * not been called yet, so HIGH_BAT_EN may not be
  966. * set in HID0 for the 745x processors. However, it
  967. * seems that doesn't affect our ability to actually
  968. * write to these SPRs.
  969. */
  970. mtspr SPRN_DBAT4U,r10
  971. mtspr SPRN_DBAT4L,r10
  972. mtspr SPRN_DBAT5U,r10
  973. mtspr SPRN_DBAT5L,r10
  974. mtspr SPRN_DBAT6U,r10
  975. mtspr SPRN_DBAT6L,r10
  976. mtspr SPRN_DBAT7U,r10
  977. mtspr SPRN_DBAT7L,r10
  978. mtspr SPRN_IBAT4U,r10
  979. mtspr SPRN_IBAT4L,r10
  980. mtspr SPRN_IBAT5U,r10
  981. mtspr SPRN_IBAT5L,r10
  982. mtspr SPRN_IBAT6U,r10
  983. mtspr SPRN_IBAT6L,r10
  984. mtspr SPRN_IBAT7U,r10
  985. mtspr SPRN_IBAT7L,r10
  986. END_FTR_SECTION_IFSET(CPU_FTR_HAS_HIGH_BATS)
  987. blr
  988. flush_tlbs:
  989. lis r10, 0x40
  990. 1: addic. r10, r10, -0x1000
  991. tlbie r10
  992. blt 1b
  993. sync
  994. blr
  995. mmu_off:
  996. addi r4, r3, __after_mmu_off - _start
  997. mfmsr r3
  998. andi. r0,r3,MSR_DR|MSR_IR /* MMU enabled? */
  999. beqlr
  1000. andc r3,r3,r0
  1001. mtspr SPRN_SRR0,r4
  1002. mtspr SPRN_SRR1,r3
  1003. sync
  1004. RFI
  1005. /*
  1006. * Use the first pair of BAT registers to map the 1st 16MB
  1007. * of RAM to KERNELBASE. From this point on we can't safely
  1008. * call OF any more.
  1009. */
  1010. initial_bats:
  1011. lis r11,KERNELBASE@h
  1012. mfspr r9,SPRN_PVR
  1013. rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
  1014. cmpwi 0,r9,1
  1015. bne 4f
  1016. ori r11,r11,4 /* set up BAT registers for 601 */
  1017. li r8,0x7f /* valid, block length = 8MB */
  1018. oris r9,r11,0x800000@h /* set up BAT reg for 2nd 8M */
  1019. oris r10,r8,0x800000@h /* set up BAT reg for 2nd 8M */
  1020. mtspr SPRN_IBAT0U,r11 /* N.B. 601 has valid bit in */
  1021. mtspr SPRN_IBAT0L,r8 /* lower BAT register */
  1022. mtspr SPRN_IBAT1U,r9
  1023. mtspr SPRN_IBAT1L,r10
  1024. isync
  1025. blr
  1026. 4: tophys(r8,r11)
  1027. #ifdef CONFIG_SMP
  1028. ori r8,r8,0x12 /* R/W access, M=1 */
  1029. #else
  1030. ori r8,r8,2 /* R/W access */
  1031. #endif /* CONFIG_SMP */
  1032. ori r11,r11,BL_256M<<2|0x2 /* set up BAT registers for 604 */
  1033. mtspr SPRN_DBAT0L,r8 /* N.B. 6xx (not 601) have valid */
  1034. mtspr SPRN_DBAT0U,r11 /* bit in upper BAT register */
  1035. mtspr SPRN_IBAT0L,r8
  1036. mtspr SPRN_IBAT0U,r11
  1037. isync
  1038. blr
  1039. #ifdef CONFIG_BOOTX_TEXT
  1040. setup_disp_bat:
  1041. /*
  1042. * setup the display bat prepared for us in prom.c
  1043. */
  1044. mflr r8
  1045. bl reloc_offset
  1046. mtlr r8
  1047. addis r8,r3,disp_BAT@ha
  1048. addi r8,r8,disp_BAT@l
  1049. lwz r11,0(r8)
  1050. lwz r8,4(r8)
  1051. mfspr r9,SPRN_PVR
  1052. rlwinm r9,r9,16,16,31 /* r9 = 1 for 601, 4 for 604 */
  1053. cmpwi 0,r9,1
  1054. beq 1f
  1055. mtspr SPRN_DBAT3L,r8
  1056. mtspr SPRN_DBAT3U,r11
  1057. blr
  1058. 1: mtspr SPRN_IBAT3L,r8
  1059. mtspr SPRN_IBAT3U,r11
  1060. blr
  1061. #endif /* defined(CONFIG_BOOTX_TEXT) */
  1062. #ifdef CONFIG_8260
  1063. /* Jump into the system reset for the rom.
  1064. * We first disable the MMU, and then jump to the ROM reset address.
  1065. *
  1066. * r3 is the board info structure, r4 is the location for starting.
  1067. * I use this for building a small kernel that can load other kernels,
  1068. * rather than trying to write or rely on a rom monitor that can tftp load.
  1069. */
  1070. .globl m8260_gorom
  1071. m8260_gorom:
  1072. mfmsr r0
  1073. rlwinm r0,r0,0,17,15 /* clear MSR_EE in r0 */
  1074. sync
  1075. mtmsr r0
  1076. sync
  1077. mfspr r11, SPRN_HID0
  1078. lis r10, 0
  1079. ori r10,r10,HID0_ICE|HID0_DCE
  1080. andc r11, r11, r10
  1081. mtspr SPRN_HID0, r11
  1082. isync
  1083. li r5, MSR_ME|MSR_RI
  1084. lis r6,2f@h
  1085. addis r6,r6,-KERNELBASE@h
  1086. ori r6,r6,2f@l
  1087. mtspr SPRN_SRR0,r6
  1088. mtspr SPRN_SRR1,r5
  1089. isync
  1090. sync
  1091. rfi
  1092. 2:
  1093. mtlr r4
  1094. blr
  1095. #endif
  1096. /*
  1097. * We put a few things here that have to be page-aligned.
  1098. * This stuff goes at the beginning of the data segment,
  1099. * which is page-aligned.
  1100. */
  1101. .data
  1102. .globl sdata
  1103. sdata:
  1104. .globl empty_zero_page
  1105. empty_zero_page:
  1106. .space 4096
  1107. .globl swapper_pg_dir
  1108. swapper_pg_dir:
  1109. .space 4096
  1110. /*
  1111. * This space gets a copy of optional info passed to us by the bootstrap
  1112. * Used to pass parameters into the kernel like root=/dev/sda1, etc.
  1113. */
  1114. .globl cmd_line
  1115. cmd_line:
  1116. .space 512
  1117. .globl intercept_table
  1118. intercept_table:
  1119. .long 0, 0, i0x200, i0x300, i0x400, 0, i0x600, i0x700
  1120. .long i0x800, 0, 0, 0, 0, i0xd00, 0, 0
  1121. .long 0, 0, 0, i0x1300, 0, 0, 0, 0
  1122. .long 0, 0, 0, 0, 0, 0, 0, 0
  1123. .long 0, 0, 0, 0, 0, 0, 0, 0
  1124. .long 0, 0, 0, 0, 0, 0, 0, 0
  1125. /* Room for two PTE pointers, usually the kernel and current user pointers
  1126. * to their respective root page table.
  1127. */
  1128. abatron_pteptrs:
  1129. .space 8