head_44x.S 29 KB

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