head_44x.S 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. /*
  2. * Kernel execution entry point code.
  3. *
  4. * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org>
  5. * Initial PowerPC version.
  6. * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu>
  7. * Rewritten for PReP
  8. * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
  9. * Low-level exception handers, MMU support, and rewrite.
  10. * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
  11. * PowerPC 8xx modifications.
  12. * Copyright (c) 1998-1999 TiVo, Inc.
  13. * PowerPC 403GCX modifications.
  14. * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
  15. * PowerPC 403GCX/405GP modifications.
  16. * Copyright 2000 MontaVista Software Inc.
  17. * PPC405 modifications
  18. * PowerPC 403GCX/405GP modifications.
  19. * Author: MontaVista Software, Inc.
  20. * frank_rowand@mvista.com or source@mvista.com
  21. * debbie_chu@mvista.com
  22. * Copyright 2002-2005 MontaVista Software, Inc.
  23. * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
  24. *
  25. * This program is free software; you can redistribute it and/or modify it
  26. * under the terms of the GNU General Public License as published by the
  27. * Free Software Foundation; either version 2 of the License, or (at your
  28. * option) any later version.
  29. */
  30. #include <linux/init.h>
  31. #include <asm/processor.h>
  32. #include <asm/page.h>
  33. #include <asm/mmu.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/cputable.h>
  36. #include <asm/thread_info.h>
  37. #include <asm/ppc_asm.h>
  38. #include <asm/asm-offsets.h>
  39. #include <asm/synch.h>
  40. #include "head_booke.h"
  41. /* As with the other PowerPC ports, it is expected that when code
  42. * execution begins here, the following registers contain valid, yet
  43. * optional, information:
  44. *
  45. * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
  46. * r4 - Starting address of the init RAM disk
  47. * r5 - Ending address of the init RAM disk
  48. * r6 - Start of kernel command line string (e.g. "mem=128")
  49. * r7 - End of kernel command line string
  50. *
  51. */
  52. __HEAD
  53. _ENTRY(_stext);
  54. _ENTRY(_start);
  55. /*
  56. * Reserve a word at a fixed location to store the address
  57. * of abatron_pteptrs
  58. */
  59. nop
  60. /*
  61. * Save parameters we are passed
  62. */
  63. mr r31,r3
  64. mr r30,r4
  65. mr r29,r5
  66. mr r28,r6
  67. mr r27,r7
  68. li r24,0 /* CPU number */
  69. bl init_cpu_state
  70. /*
  71. * This is where the main kernel code starts.
  72. */
  73. /* ptr to current */
  74. lis r2,init_task@h
  75. ori r2,r2,init_task@l
  76. /* ptr to current thread */
  77. addi r4,r2,THREAD /* init task's THREAD */
  78. mtspr SPRN_SPRG_THREAD,r4
  79. /* stack */
  80. lis r1,init_thread_union@h
  81. ori r1,r1,init_thread_union@l
  82. li r0,0
  83. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  84. bl early_init
  85. /*
  86. * Decide what sort of machine this is and initialize the MMU.
  87. */
  88. mr r3,r31
  89. mr r4,r30
  90. mr r5,r29
  91. mr r6,r28
  92. mr r7,r27
  93. bl machine_init
  94. bl MMU_init
  95. /* Setup PTE pointers for the Abatron bdiGDB */
  96. lis r6, swapper_pg_dir@h
  97. ori r6, r6, swapper_pg_dir@l
  98. lis r5, abatron_pteptrs@h
  99. ori r5, r5, abatron_pteptrs@l
  100. lis r4, KERNELBASE@h
  101. ori r4, r4, KERNELBASE@l
  102. stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */
  103. stw r6, 0(r5)
  104. /* Let's move on */
  105. lis r4,start_kernel@h
  106. ori r4,r4,start_kernel@l
  107. lis r3,MSR_KERNEL@h
  108. ori r3,r3,MSR_KERNEL@l
  109. mtspr SPRN_SRR0,r4
  110. mtspr SPRN_SRR1,r3
  111. rfi /* change context and jump to start_kernel */
  112. /*
  113. * Interrupt vector entry code
  114. *
  115. * The Book E MMUs are always on so we don't need to handle
  116. * interrupts in real mode as with previous PPC processors. In
  117. * this case we handle interrupts in the kernel virtual address
  118. * space.
  119. *
  120. * Interrupt vectors are dynamically placed relative to the
  121. * interrupt prefix as determined by the address of interrupt_base.
  122. * The interrupt vectors offsets are programmed using the labels
  123. * for each interrupt vector entry.
  124. *
  125. * Interrupt vectors must be aligned on a 16 byte boundary.
  126. * We align on a 32 byte cache line boundary for good measure.
  127. */
  128. interrupt_base:
  129. /* Critical Input Interrupt */
  130. CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception)
  131. /* Machine Check Interrupt */
  132. CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
  133. MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception)
  134. /* Data Storage Interrupt */
  135. DATA_STORAGE_EXCEPTION
  136. /* Instruction Storage Interrupt */
  137. INSTRUCTION_STORAGE_EXCEPTION
  138. /* External Input Interrupt */
  139. EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE)
  140. /* Alignment Interrupt */
  141. ALIGNMENT_EXCEPTION
  142. /* Program Interrupt */
  143. PROGRAM_EXCEPTION
  144. /* Floating Point Unavailable Interrupt */
  145. #ifdef CONFIG_PPC_FPU
  146. FP_UNAVAILABLE_EXCEPTION
  147. #else
  148. EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE)
  149. #endif
  150. /* System Call Interrupt */
  151. START_EXCEPTION(SystemCall)
  152. NORMAL_EXCEPTION_PROLOG
  153. EXC_XFER_EE_LITE(0x0c00, DoSyscall)
  154. /* Auxillary Processor Unavailable Interrupt */
  155. EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE)
  156. /* Decrementer Interrupt */
  157. DECREMENTER_EXCEPTION
  158. /* Fixed Internal Timer Interrupt */
  159. /* TODO: Add FIT support */
  160. EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE)
  161. /* Watchdog Timer Interrupt */
  162. /* TODO: Add watchdog support */
  163. #ifdef CONFIG_BOOKE_WDT
  164. CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException)
  165. #else
  166. CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception)
  167. #endif
  168. /* Data TLB Error Interrupt */
  169. START_EXCEPTION(DataTLBError44x)
  170. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  171. mtspr SPRN_SPRG_WSCRATCH1, r11
  172. mtspr SPRN_SPRG_WSCRATCH2, r12
  173. mtspr SPRN_SPRG_WSCRATCH3, r13
  174. mfcr r11
  175. mtspr SPRN_SPRG_WSCRATCH4, r11
  176. mfspr r10, SPRN_DEAR /* Get faulting address */
  177. /* If we are faulting a kernel address, we have to use the
  178. * kernel page tables.
  179. */
  180. lis r11, PAGE_OFFSET@h
  181. cmplw r10, r11
  182. blt+ 3f
  183. lis r11, swapper_pg_dir@h
  184. ori r11, r11, swapper_pg_dir@l
  185. mfspr r12,SPRN_MMUCR
  186. rlwinm r12,r12,0,0,23 /* Clear TID */
  187. b 4f
  188. /* Get the PGD for the current thread */
  189. 3:
  190. mfspr r11,SPRN_SPRG_THREAD
  191. lwz r11,PGDIR(r11)
  192. /* Load PID into MMUCR TID */
  193. mfspr r12,SPRN_MMUCR
  194. mfspr r13,SPRN_PID /* Get PID */
  195. rlwimi r12,r13,0,24,31 /* Set TID */
  196. 4:
  197. mtspr SPRN_MMUCR,r12
  198. /* Mask of required permission bits. Note that while we
  199. * do copy ESR:ST to _PAGE_RW position as trying to write
  200. * to an RO page is pretty common, we don't do it with
  201. * _PAGE_DIRTY. We could do it, but it's a fairly rare
  202. * event so I'd rather take the overhead when it happens
  203. * rather than adding an instruction here. We should measure
  204. * whether the whole thing is worth it in the first place
  205. * as we could avoid loading SPRN_ESR completely in the first
  206. * place...
  207. *
  208. * TODO: Is it worth doing that mfspr & rlwimi in the first
  209. * place or can we save a couple of instructions here ?
  210. */
  211. mfspr r12,SPRN_ESR
  212. li r13,_PAGE_PRESENT|_PAGE_ACCESSED
  213. rlwimi r13,r12,10,30,30
  214. /* Load the PTE */
  215. /* Compute pgdir/pmd offset */
  216. rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
  217. lwzx r11, r12, r11 /* Get pgd/pmd entry */
  218. rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */
  219. beq 2f /* Bail if no table */
  220. /* Compute pte address */
  221. rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
  222. lwz r11, 0(r12) /* Get high word of pte entry */
  223. lwz r12, 4(r12) /* Get low word of pte entry */
  224. lis r10,tlb_44x_index@ha
  225. andc. r13,r13,r12 /* Check permission */
  226. /* Load the next available TLB index */
  227. lwz r13,tlb_44x_index@l(r10)
  228. bne 2f /* Bail if permission mismach */
  229. /* Increment, rollover, and store TLB index */
  230. addi r13,r13,1
  231. /* Compare with watermark (instruction gets patched) */
  232. .globl tlb_44x_patch_hwater_D
  233. tlb_44x_patch_hwater_D:
  234. cmpwi 0,r13,1 /* reserve entries */
  235. ble 5f
  236. li r13,0
  237. 5:
  238. /* Store the next available TLB index */
  239. stw r13,tlb_44x_index@l(r10)
  240. /* Re-load the faulting address */
  241. mfspr r10,SPRN_DEAR
  242. /* Jump to common tlb load */
  243. b finish_tlb_load_44x
  244. 2:
  245. /* The bailout. Restore registers to pre-exception conditions
  246. * and call the heavyweights to help us out.
  247. */
  248. mfspr r11, SPRN_SPRG_RSCRATCH4
  249. mtcr r11
  250. mfspr r13, SPRN_SPRG_RSCRATCH3
  251. mfspr r12, SPRN_SPRG_RSCRATCH2
  252. mfspr r11, SPRN_SPRG_RSCRATCH1
  253. mfspr r10, SPRN_SPRG_RSCRATCH0
  254. b DataStorage
  255. /* Instruction TLB Error Interrupt */
  256. /*
  257. * Nearly the same as above, except we get our
  258. * information from different registers and bailout
  259. * to a different point.
  260. */
  261. START_EXCEPTION(InstructionTLBError44x)
  262. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  263. mtspr SPRN_SPRG_WSCRATCH1, r11
  264. mtspr SPRN_SPRG_WSCRATCH2, r12
  265. mtspr SPRN_SPRG_WSCRATCH3, r13
  266. mfcr r11
  267. mtspr SPRN_SPRG_WSCRATCH4, r11
  268. mfspr r10, SPRN_SRR0 /* Get faulting address */
  269. /* If we are faulting a kernel address, we have to use the
  270. * kernel page tables.
  271. */
  272. lis r11, PAGE_OFFSET@h
  273. cmplw r10, r11
  274. blt+ 3f
  275. lis r11, swapper_pg_dir@h
  276. ori r11, r11, swapper_pg_dir@l
  277. mfspr r12,SPRN_MMUCR
  278. rlwinm r12,r12,0,0,23 /* Clear TID */
  279. b 4f
  280. /* Get the PGD for the current thread */
  281. 3:
  282. mfspr r11,SPRN_SPRG_THREAD
  283. lwz r11,PGDIR(r11)
  284. /* Load PID into MMUCR TID */
  285. mfspr r12,SPRN_MMUCR
  286. mfspr r13,SPRN_PID /* Get PID */
  287. rlwimi r12,r13,0,24,31 /* Set TID */
  288. 4:
  289. mtspr SPRN_MMUCR,r12
  290. /* Make up the required permissions */
  291. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  292. /* Compute pgdir/pmd offset */
  293. rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
  294. lwzx r11, r12, r11 /* Get pgd/pmd entry */
  295. rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */
  296. beq 2f /* Bail if no table */
  297. /* Compute pte address */
  298. rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
  299. lwz r11, 0(r12) /* Get high word of pte entry */
  300. lwz r12, 4(r12) /* Get low word of pte entry */
  301. lis r10,tlb_44x_index@ha
  302. andc. r13,r13,r12 /* Check permission */
  303. /* Load the next available TLB index */
  304. lwz r13,tlb_44x_index@l(r10)
  305. bne 2f /* Bail if permission mismach */
  306. /* Increment, rollover, and store TLB index */
  307. addi r13,r13,1
  308. /* Compare with watermark (instruction gets patched) */
  309. .globl tlb_44x_patch_hwater_I
  310. tlb_44x_patch_hwater_I:
  311. cmpwi 0,r13,1 /* reserve entries */
  312. ble 5f
  313. li r13,0
  314. 5:
  315. /* Store the next available TLB index */
  316. stw r13,tlb_44x_index@l(r10)
  317. /* Re-load the faulting address */
  318. mfspr r10,SPRN_SRR0
  319. /* Jump to common TLB load point */
  320. b finish_tlb_load_44x
  321. 2:
  322. /* The bailout. Restore registers to pre-exception conditions
  323. * and call the heavyweights to help us out.
  324. */
  325. mfspr r11, SPRN_SPRG_RSCRATCH4
  326. mtcr r11
  327. mfspr r13, SPRN_SPRG_RSCRATCH3
  328. mfspr r12, SPRN_SPRG_RSCRATCH2
  329. mfspr r11, SPRN_SPRG_RSCRATCH1
  330. mfspr r10, SPRN_SPRG_RSCRATCH0
  331. b InstructionStorage
  332. /*
  333. * Both the instruction and data TLB miss get to this
  334. * point to load the TLB.
  335. * r10 - EA of fault
  336. * r11 - PTE high word value
  337. * r12 - PTE low word value
  338. * r13 - TLB index
  339. * MMUCR - loaded with proper value when we get here
  340. * Upon exit, we reload everything and RFI.
  341. */
  342. finish_tlb_load_44x:
  343. /* Combine RPN & ERPN an write WS 0 */
  344. rlwimi r11,r12,0,0,31-PAGE_SHIFT
  345. tlbwe r11,r13,PPC44x_TLB_XLAT
  346. /*
  347. * Create WS1. This is the faulting address (EPN),
  348. * page size, and valid flag.
  349. */
  350. li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE
  351. /* Insert valid and page size */
  352. rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31
  353. tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */
  354. /* And WS 2 */
  355. li r10,0xf85 /* Mask to apply from PTE */
  356. rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */
  357. and r11,r12,r10 /* Mask PTE bits to keep */
  358. andi. r10,r12,_PAGE_USER /* User page ? */
  359. beq 1f /* nope, leave U bits empty */
  360. rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
  361. 1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */
  362. /* Done...restore registers and get out of here.
  363. */
  364. mfspr r11, SPRN_SPRG_RSCRATCH4
  365. mtcr r11
  366. mfspr r13, SPRN_SPRG_RSCRATCH3
  367. mfspr r12, SPRN_SPRG_RSCRATCH2
  368. mfspr r11, SPRN_SPRG_RSCRATCH1
  369. mfspr r10, SPRN_SPRG_RSCRATCH0
  370. rfi /* Force context change */
  371. /* TLB error interrupts for 476
  372. */
  373. #ifdef CONFIG_PPC_47x
  374. START_EXCEPTION(DataTLBError47x)
  375. mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
  376. mtspr SPRN_SPRG_WSCRATCH1,r11
  377. mtspr SPRN_SPRG_WSCRATCH2,r12
  378. mtspr SPRN_SPRG_WSCRATCH3,r13
  379. mfcr r11
  380. mtspr SPRN_SPRG_WSCRATCH4,r11
  381. mfspr r10,SPRN_DEAR /* Get faulting address */
  382. /* If we are faulting a kernel address, we have to use the
  383. * kernel page tables.
  384. */
  385. lis r11,PAGE_OFFSET@h
  386. cmplw cr0,r10,r11
  387. blt+ 3f
  388. lis r11,swapper_pg_dir@h
  389. ori r11,r11, swapper_pg_dir@l
  390. li r12,0 /* MMUCR = 0 */
  391. b 4f
  392. /* Get the PGD for the current thread and setup MMUCR */
  393. 3: mfspr r11,SPRN_SPRG3
  394. lwz r11,PGDIR(r11)
  395. mfspr r12,SPRN_PID /* Get PID */
  396. 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
  397. /* Mask of required permission bits. Note that while we
  398. * do copy ESR:ST to _PAGE_RW position as trying to write
  399. * to an RO page is pretty common, we don't do it with
  400. * _PAGE_DIRTY. We could do it, but it's a fairly rare
  401. * event so I'd rather take the overhead when it happens
  402. * rather than adding an instruction here. We should measure
  403. * whether the whole thing is worth it in the first place
  404. * as we could avoid loading SPRN_ESR completely in the first
  405. * place...
  406. *
  407. * TODO: Is it worth doing that mfspr & rlwimi in the first
  408. * place or can we save a couple of instructions here ?
  409. */
  410. mfspr r12,SPRN_ESR
  411. li r13,_PAGE_PRESENT|_PAGE_ACCESSED
  412. rlwimi r13,r12,10,30,30
  413. /* Load the PTE */
  414. /* Compute pgdir/pmd offset */
  415. rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
  416. lwzx r11,r12,r11 /* Get pgd/pmd entry */
  417. /* Word 0 is EPN,V,TS,DSIZ */
  418. li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
  419. rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
  420. li r12,0
  421. tlbwe r10,r12,0
  422. /* XXX can we do better ? Need to make sure tlbwe has established
  423. * latch V bit in MMUCR0 before the PTE is loaded further down */
  424. #ifdef CONFIG_SMP
  425. isync
  426. #endif
  427. rlwinm. r12,r11,0,0,20 /* Extract pt base address */
  428. /* Compute pte address */
  429. rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
  430. beq 2f /* Bail if no table */
  431. lwz r11,0(r12) /* Get high word of pte entry */
  432. /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
  433. * bottom of r12 to create a data dependency... We can also use r10
  434. * as destination nowadays
  435. */
  436. #ifdef CONFIG_SMP
  437. lwsync
  438. #endif
  439. lwz r12,4(r12) /* Get low word of pte entry */
  440. andc. r13,r13,r12 /* Check permission */
  441. /* Jump to common tlb load */
  442. beq finish_tlb_load_47x
  443. 2: /* The bailout. Restore registers to pre-exception conditions
  444. * and call the heavyweights to help us out.
  445. */
  446. mfspr r11,SPRN_SPRG_RSCRATCH4
  447. mtcr r11
  448. mfspr r13,SPRN_SPRG_RSCRATCH3
  449. mfspr r12,SPRN_SPRG_RSCRATCH2
  450. mfspr r11,SPRN_SPRG_RSCRATCH1
  451. mfspr r10,SPRN_SPRG_RSCRATCH0
  452. b DataStorage
  453. /* Instruction TLB Error Interrupt */
  454. /*
  455. * Nearly the same as above, except we get our
  456. * information from different registers and bailout
  457. * to a different point.
  458. */
  459. START_EXCEPTION(InstructionTLBError47x)
  460. mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
  461. mtspr SPRN_SPRG_WSCRATCH1,r11
  462. mtspr SPRN_SPRG_WSCRATCH2,r12
  463. mtspr SPRN_SPRG_WSCRATCH3,r13
  464. mfcr r11
  465. mtspr SPRN_SPRG_WSCRATCH4,r11
  466. mfspr r10,SPRN_SRR0 /* Get faulting address */
  467. /* If we are faulting a kernel address, we have to use the
  468. * kernel page tables.
  469. */
  470. lis r11,PAGE_OFFSET@h
  471. cmplw cr0,r10,r11
  472. blt+ 3f
  473. lis r11,swapper_pg_dir@h
  474. ori r11,r11, swapper_pg_dir@l
  475. li r12,0 /* MMUCR = 0 */
  476. b 4f
  477. /* Get the PGD for the current thread and setup MMUCR */
  478. 3: mfspr r11,SPRN_SPRG_THREAD
  479. lwz r11,PGDIR(r11)
  480. mfspr r12,SPRN_PID /* Get PID */
  481. 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
  482. /* Make up the required permissions */
  483. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  484. /* Load PTE */
  485. /* Compute pgdir/pmd offset */
  486. rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
  487. lwzx r11,r12,r11 /* Get pgd/pmd entry */
  488. /* Word 0 is EPN,V,TS,DSIZ */
  489. li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
  490. rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
  491. li r12,0
  492. tlbwe r10,r12,0
  493. /* XXX can we do better ? Need to make sure tlbwe has established
  494. * latch V bit in MMUCR0 before the PTE is loaded further down */
  495. #ifdef CONFIG_SMP
  496. isync
  497. #endif
  498. rlwinm. r12,r11,0,0,20 /* Extract pt base address */
  499. /* Compute pte address */
  500. rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
  501. beq 2f /* Bail if no table */
  502. lwz r11,0(r12) /* Get high word of pte entry */
  503. /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
  504. * bottom of r12 to create a data dependency... We can also use r10
  505. * as destination nowadays
  506. */
  507. #ifdef CONFIG_SMP
  508. lwsync
  509. #endif
  510. lwz r12,4(r12) /* Get low word of pte entry */
  511. andc. r13,r13,r12 /* Check permission */
  512. /* Jump to common TLB load point */
  513. beq finish_tlb_load_47x
  514. 2: /* The bailout. Restore registers to pre-exception conditions
  515. * and call the heavyweights to help us out.
  516. */
  517. mfspr r11, SPRN_SPRG_RSCRATCH4
  518. mtcr r11
  519. mfspr r13, SPRN_SPRG_RSCRATCH3
  520. mfspr r12, SPRN_SPRG_RSCRATCH2
  521. mfspr r11, SPRN_SPRG_RSCRATCH1
  522. mfspr r10, SPRN_SPRG_RSCRATCH0
  523. b InstructionStorage
  524. /*
  525. * Both the instruction and data TLB miss get to this
  526. * point to load the TLB.
  527. * r10 - free to use
  528. * r11 - PTE high word value
  529. * r12 - PTE low word value
  530. * r13 - free to use
  531. * MMUCR - loaded with proper value when we get here
  532. * Upon exit, we reload everything and RFI.
  533. */
  534. finish_tlb_load_47x:
  535. /* Combine RPN & ERPN an write WS 1 */
  536. rlwimi r11,r12,0,0,31-PAGE_SHIFT
  537. tlbwe r11,r13,1
  538. /* And make up word 2 */
  539. li r10,0xf85 /* Mask to apply from PTE */
  540. rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */
  541. and r11,r12,r10 /* Mask PTE bits to keep */
  542. andi. r10,r12,_PAGE_USER /* User page ? */
  543. beq 1f /* nope, leave U bits empty */
  544. rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
  545. 1: tlbwe r11,r13,2
  546. /* Done...restore registers and get out of here.
  547. */
  548. mfspr r11, SPRN_SPRG_RSCRATCH4
  549. mtcr r11
  550. mfspr r13, SPRN_SPRG_RSCRATCH3
  551. mfspr r12, SPRN_SPRG_RSCRATCH2
  552. mfspr r11, SPRN_SPRG_RSCRATCH1
  553. mfspr r10, SPRN_SPRG_RSCRATCH0
  554. rfi
  555. #endif /* CONFIG_PPC_47x */
  556. /* Debug Interrupt */
  557. /*
  558. * This statement needs to exist at the end of the IVPR
  559. * definition just in case you end up taking a debug
  560. * exception within another exception.
  561. */
  562. DEBUG_CRIT_EXCEPTION
  563. /*
  564. * Global functions
  565. */
  566. /*
  567. * Adjust the machine check IVOR on 440A cores
  568. */
  569. _GLOBAL(__fixup_440A_mcheck)
  570. li r3,MachineCheckA@l
  571. mtspr SPRN_IVOR1,r3
  572. sync
  573. blr
  574. /*
  575. * extern void giveup_altivec(struct task_struct *prev)
  576. *
  577. * The 44x core does not have an AltiVec unit.
  578. */
  579. _GLOBAL(giveup_altivec)
  580. blr
  581. /*
  582. * extern void giveup_fpu(struct task_struct *prev)
  583. *
  584. * The 44x core does not have an FPU.
  585. */
  586. #ifndef CONFIG_PPC_FPU
  587. _GLOBAL(giveup_fpu)
  588. blr
  589. #endif
  590. _GLOBAL(set_context)
  591. #ifdef CONFIG_BDI_SWITCH
  592. /* Context switch the PTE pointer for the Abatron BDI2000.
  593. * The PGDIR is the second parameter.
  594. */
  595. lis r5, abatron_pteptrs@h
  596. ori r5, r5, abatron_pteptrs@l
  597. stw r4, 0x4(r5)
  598. #endif
  599. mtspr SPRN_PID,r3
  600. isync /* Force context change */
  601. blr
  602. /*
  603. * Init CPU state. This is called at boot time or for secondary CPUs
  604. * to setup initial TLB entries, setup IVORs, etc...
  605. *
  606. */
  607. _GLOBAL(init_cpu_state)
  608. mflr r22
  609. #ifdef CONFIG_PPC_47x
  610. /* We use the PVR to differenciate 44x cores from 476 */
  611. mfspr r3,SPRN_PVR
  612. srwi r3,r3,16
  613. cmplwi cr0,r3,PVR_476@h
  614. beq head_start_47x
  615. cmplwi cr0,r3,PVR_476_ISS@h
  616. beq head_start_47x
  617. #endif /* CONFIG_PPC_47x */
  618. /*
  619. * In case the firmware didn't do it, we apply some workarounds
  620. * that are good for all 440 core variants here
  621. */
  622. mfspr r3,SPRN_CCR0
  623. rlwinm r3,r3,0,0,27 /* disable icache prefetch */
  624. isync
  625. mtspr SPRN_CCR0,r3
  626. isync
  627. sync
  628. /*
  629. * Set up the initial MMU state for 44x
  630. *
  631. * We are still executing code at the virtual address
  632. * mappings set by the firmware for the base of RAM.
  633. *
  634. * We first invalidate all TLB entries but the one
  635. * we are running from. We then load the KERNELBASE
  636. * mappings so we can begin to use kernel addresses
  637. * natively and so the interrupt vector locations are
  638. * permanently pinned (necessary since Book E
  639. * implementations always have translation enabled).
  640. *
  641. * TODO: Use the known TLB entry we are running from to
  642. * determine which physical region we are located
  643. * in. This can be used to determine where in RAM
  644. * (on a shared CPU system) or PCI memory space
  645. * (on a DRAMless system) we are located.
  646. * For now, we assume a perfect world which means
  647. * we are located at the base of DRAM (physical 0).
  648. */
  649. /*
  650. * Search TLB for entry that we are currently using.
  651. * Invalidate all entries but the one we are using.
  652. */
  653. /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
  654. mfspr r3,SPRN_PID /* Get PID */
  655. mfmsr r4 /* Get MSR */
  656. andi. r4,r4,MSR_IS@l /* TS=1? */
  657. beq wmmucr /* If not, leave STS=0 */
  658. oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */
  659. wmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
  660. sync
  661. bl invstr /* Find our address */
  662. invstr: mflr r5 /* Make it accessible */
  663. tlbsx r23,0,r5 /* Find entry we are in */
  664. li r4,0 /* Start at TLB entry 0 */
  665. li r3,0 /* Set PAGEID inval value */
  666. 1: cmpw r23,r4 /* Is this our entry? */
  667. beq skpinv /* If so, skip the inval */
  668. tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */
  669. skpinv: addi r4,r4,1 /* Increment */
  670. cmpwi r4,64 /* Are we done? */
  671. bne 1b /* If not, repeat */
  672. isync /* If so, context change */
  673. /*
  674. * Configure and load pinned entry into TLB slot 63.
  675. */
  676. lis r3,PAGE_OFFSET@h
  677. ori r3,r3,PAGE_OFFSET@l
  678. /* Kernel is at the base of RAM */
  679. li r4, 0 /* Load the kernel physical address */
  680. /* Load the kernel PID = 0 */
  681. li r0,0
  682. mtspr SPRN_PID,r0
  683. sync
  684. /* Initialize MMUCR */
  685. li r5,0
  686. mtspr SPRN_MMUCR,r5
  687. sync
  688. /* pageid fields */
  689. clrrwi r3,r3,10 /* Mask off the effective page number */
  690. ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M
  691. /* xlat fields */
  692. clrrwi r4,r4,10 /* Mask off the real page number */
  693. /* ERPN is 0 for first 4GB page */
  694. /* attrib fields */
  695. /* Added guarded bit to protect against speculative loads/stores */
  696. li r5,0
  697. ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
  698. li r0,63 /* TLB slot 63 */
  699. tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */
  700. tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */
  701. tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */
  702. /* Force context change */
  703. mfmsr r0
  704. mtspr SPRN_SRR1, r0
  705. lis r0,3f@h
  706. ori r0,r0,3f@l
  707. mtspr SPRN_SRR0,r0
  708. sync
  709. rfi
  710. /* If necessary, invalidate original entry we used */
  711. 3: cmpwi r23,63
  712. beq 4f
  713. li r6,0
  714. tlbwe r6,r23,PPC44x_TLB_PAGEID
  715. isync
  716. 4:
  717. #ifdef CONFIG_PPC_EARLY_DEBUG_44x
  718. /* Add UART mapping for early debug. */
  719. /* pageid fields */
  720. lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
  721. ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K
  722. /* xlat fields */
  723. lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
  724. ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
  725. /* attrib fields */
  726. li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G)
  727. li r0,62 /* TLB slot 0 */
  728. tlbwe r3,r0,PPC44x_TLB_PAGEID
  729. tlbwe r4,r0,PPC44x_TLB_XLAT
  730. tlbwe r5,r0,PPC44x_TLB_ATTRIB
  731. /* Force context change */
  732. isync
  733. #endif /* CONFIG_PPC_EARLY_DEBUG_44x */
  734. /* Establish the interrupt vector offsets */
  735. SET_IVOR(0, CriticalInput);
  736. SET_IVOR(1, MachineCheck);
  737. SET_IVOR(2, DataStorage);
  738. SET_IVOR(3, InstructionStorage);
  739. SET_IVOR(4, ExternalInput);
  740. SET_IVOR(5, Alignment);
  741. SET_IVOR(6, Program);
  742. SET_IVOR(7, FloatingPointUnavailable);
  743. SET_IVOR(8, SystemCall);
  744. SET_IVOR(9, AuxillaryProcessorUnavailable);
  745. SET_IVOR(10, Decrementer);
  746. SET_IVOR(11, FixedIntervalTimer);
  747. SET_IVOR(12, WatchdogTimer);
  748. SET_IVOR(13, DataTLBError44x);
  749. SET_IVOR(14, InstructionTLBError44x);
  750. SET_IVOR(15, DebugCrit);
  751. b head_start_common
  752. #ifdef CONFIG_PPC_47x
  753. #ifdef CONFIG_SMP
  754. /* Entry point for secondary 47x processors */
  755. _GLOBAL(start_secondary_47x)
  756. mr r24,r3 /* CPU number */
  757. bl init_cpu_state
  758. /* Now we need to bolt the rest of kernel memory which
  759. * is done in C code. We must be careful because our task
  760. * struct or our stack can (and will probably) be out
  761. * of reach of the initial 256M TLB entry, so we use a
  762. * small temporary stack in .bss for that. This works
  763. * because only one CPU at a time can be in this code
  764. */
  765. lis r1,temp_boot_stack@h
  766. ori r1,r1,temp_boot_stack@l
  767. addi r1,r1,1024-STACK_FRAME_OVERHEAD
  768. li r0,0
  769. stw r0,0(r1)
  770. bl mmu_init_secondary
  771. /* Now we can get our task struct and real stack pointer */
  772. /* Get current_thread_info and current */
  773. lis r1,secondary_ti@ha
  774. lwz r1,secondary_ti@l(r1)
  775. lwz r2,TI_TASK(r1)
  776. /* Current stack pointer */
  777. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  778. li r0,0
  779. stw r0,0(r1)
  780. /* Kernel stack for exception entry in SPRG3 */
  781. addi r4,r2,THREAD /* init task's THREAD */
  782. mtspr SPRN_SPRG3,r4
  783. b start_secondary
  784. #endif /* CONFIG_SMP */
  785. /*
  786. * Set up the initial MMU state for 44x
  787. *
  788. * We are still executing code at the virtual address
  789. * mappings set by the firmware for the base of RAM.
  790. */
  791. head_start_47x:
  792. /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
  793. mfspr r3,SPRN_PID /* Get PID */
  794. mfmsr r4 /* Get MSR */
  795. andi. r4,r4,MSR_IS@l /* TS=1? */
  796. beq 1f /* If not, leave STS=0 */
  797. oris r3,r3,PPC47x_MMUCR_STS@h /* Set STS=1 */
  798. 1: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
  799. sync
  800. /* Find the entry we are running from */
  801. bl 1f
  802. 1: mflr r23
  803. tlbsx r23,0,r23
  804. tlbre r24,r23,0
  805. tlbre r25,r23,1
  806. tlbre r26,r23,2
  807. /*
  808. * Cleanup time
  809. */
  810. /* Initialize MMUCR */
  811. li r5,0
  812. mtspr SPRN_MMUCR,r5
  813. sync
  814. clear_all_utlb_entries:
  815. #; Set initial values.
  816. addis r3,0,0x8000
  817. addi r4,0,0
  818. addi r5,0,0
  819. b clear_utlb_entry
  820. #; Align the loop to speed things up.
  821. .align 6
  822. clear_utlb_entry:
  823. tlbwe r4,r3,0
  824. tlbwe r5,r3,1
  825. tlbwe r5,r3,2
  826. addis r3,r3,0x2000
  827. cmpwi r3,0
  828. bne clear_utlb_entry
  829. addis r3,0,0x8000
  830. addis r4,r4,0x100
  831. cmpwi r4,0
  832. bne clear_utlb_entry
  833. #; Restore original entry.
  834. oris r23,r23,0x8000 /* specify the way */
  835. tlbwe r24,r23,0
  836. tlbwe r25,r23,1
  837. tlbwe r26,r23,2
  838. /*
  839. * Configure and load pinned entry into TLB for the kernel core
  840. */
  841. lis r3,PAGE_OFFSET@h
  842. ori r3,r3,PAGE_OFFSET@l
  843. /* Kernel is at the base of RAM */
  844. li r4, 0 /* Load the kernel physical address */
  845. /* Load the kernel PID = 0 */
  846. li r0,0
  847. mtspr SPRN_PID,r0
  848. sync
  849. /* Word 0 */
  850. clrrwi r3,r3,12 /* Mask off the effective page number */
  851. ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M
  852. /* Word 1 */
  853. clrrwi r4,r4,12 /* Mask off the real page number */
  854. /* ERPN is 0 for first 4GB page */
  855. /* Word 2 */
  856. li r5,0
  857. ori r5,r5,PPC47x_TLB2_S_RWX
  858. #ifdef CONFIG_SMP
  859. ori r5,r5,PPC47x_TLB2_M
  860. #endif
  861. /* We write to way 0 and bolted 0 */
  862. lis r0,0x8800
  863. tlbwe r3,r0,0
  864. tlbwe r4,r0,1
  865. tlbwe r5,r0,2
  866. /*
  867. * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix
  868. * them up later
  869. */
  870. LOAD_REG_IMMEDIATE(r3, 0x9abcdef0)
  871. mtspr SPRN_SSPCR,r3
  872. mtspr SPRN_USPCR,r3
  873. LOAD_REG_IMMEDIATE(r3, 0x12345670)
  874. mtspr SPRN_ISPCR,r3
  875. /* Force context change */
  876. mfmsr r0
  877. mtspr SPRN_SRR1, r0
  878. lis r0,3f@h
  879. ori r0,r0,3f@l
  880. mtspr SPRN_SRR0,r0
  881. sync
  882. rfi
  883. /* Invalidate original entry we used */
  884. 3:
  885. rlwinm r24,r24,0,21,19 /* clear the "valid" bit */
  886. tlbwe r24,r23,0
  887. addi r24,0,0
  888. tlbwe r24,r23,1
  889. tlbwe r24,r23,2
  890. isync /* Clear out the shadow TLB entries */
  891. #ifdef CONFIG_PPC_EARLY_DEBUG_44x
  892. /* Add UART mapping for early debug. */
  893. /* Word 0 */
  894. lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
  895. ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M
  896. /* Word 1 */
  897. lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
  898. ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
  899. /* Word 2 */
  900. li r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG)
  901. /* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same
  902. * congruence class as the kernel, we need to make sure of it at
  903. * some point
  904. */
  905. lis r0,0x8d00
  906. tlbwe r3,r0,0
  907. tlbwe r4,r0,1
  908. tlbwe r5,r0,2
  909. /* Force context change */
  910. isync
  911. #endif /* CONFIG_PPC_EARLY_DEBUG_44x */
  912. /* Establish the interrupt vector offsets */
  913. SET_IVOR(0, CriticalInput);
  914. SET_IVOR(1, MachineCheckA);
  915. SET_IVOR(2, DataStorage);
  916. SET_IVOR(3, InstructionStorage);
  917. SET_IVOR(4, ExternalInput);
  918. SET_IVOR(5, Alignment);
  919. SET_IVOR(6, Program);
  920. SET_IVOR(7, FloatingPointUnavailable);
  921. SET_IVOR(8, SystemCall);
  922. SET_IVOR(9, AuxillaryProcessorUnavailable);
  923. SET_IVOR(10, Decrementer);
  924. SET_IVOR(11, FixedIntervalTimer);
  925. SET_IVOR(12, WatchdogTimer);
  926. SET_IVOR(13, DataTLBError47x);
  927. SET_IVOR(14, InstructionTLBError47x);
  928. SET_IVOR(15, DebugCrit);
  929. /* We configure icbi to invalidate 128 bytes at a time since the
  930. * current 32-bit kernel code isn't too happy with icache != dcache
  931. * block size
  932. */
  933. mfspr r3,SPRN_CCR0
  934. oris r3,r3,0x0020
  935. mtspr SPRN_CCR0,r3
  936. isync
  937. #endif /* CONFIG_PPC_47x */
  938. /*
  939. * Here we are back to code that is common between 44x and 47x
  940. *
  941. * We proceed to further kernel initialization and return to the
  942. * main kernel entry
  943. */
  944. head_start_common:
  945. /* Establish the interrupt vector base */
  946. lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
  947. mtspr SPRN_IVPR,r4
  948. addis r22,r22,KERNELBASE@h
  949. mtlr r22
  950. isync
  951. blr
  952. /*
  953. * We put a few things here that have to be page-aligned. This stuff
  954. * goes at the beginning of the data segment, which is page-aligned.
  955. */
  956. .data
  957. .align PAGE_SHIFT
  958. .globl sdata
  959. sdata:
  960. .globl empty_zero_page
  961. empty_zero_page:
  962. .space PAGE_SIZE
  963. /*
  964. * To support >32-bit physical addresses, we use an 8KB pgdir.
  965. */
  966. .globl swapper_pg_dir
  967. swapper_pg_dir:
  968. .space PGD_TABLE_SIZE
  969. /*
  970. * Room for two PTE pointers, usually the kernel and current user pointers
  971. * to their respective root page table.
  972. */
  973. abatron_pteptrs:
  974. .space 8
  975. #ifdef CONFIG_SMP
  976. .align 12
  977. temp_boot_stack:
  978. .space 1024
  979. #endif /* CONFIG_SMP */