head_fsl_booke.S 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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-2004 MontaVista Software, Inc.
  23. * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
  24. * Copyright 2004 Freescale Semiconductor, Inc
  25. * PowerPC e500 modifications, Kumar Gala <galak@kernel.crashing.org>
  26. *
  27. * This program is free software; you can redistribute it and/or modify it
  28. * under the terms of the GNU General Public License as published by the
  29. * Free Software Foundation; either version 2 of the License, or (at your
  30. * option) any later version.
  31. */
  32. #include <linux/threads.h>
  33. #include <asm/processor.h>
  34. #include <asm/page.h>
  35. #include <asm/mmu.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/cputable.h>
  38. #include <asm/thread_info.h>
  39. #include <asm/ppc_asm.h>
  40. #include <asm/asm-offsets.h>
  41. #include <asm/cache.h>
  42. #include "head_booke.h"
  43. /* As with the other PowerPC ports, it is expected that when code
  44. * execution begins here, the following registers contain valid, yet
  45. * optional, information:
  46. *
  47. * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
  48. * r4 - Starting address of the init RAM disk
  49. * r5 - Ending address of the init RAM disk
  50. * r6 - Start of kernel command line string (e.g. "mem=128")
  51. * r7 - End of kernel command line string
  52. *
  53. */
  54. .section .text.head, "ax"
  55. _ENTRY(_stext);
  56. _ENTRY(_start);
  57. /*
  58. * Reserve a word at a fixed location to store the address
  59. * of abatron_pteptrs
  60. */
  61. nop
  62. /*
  63. * Save parameters we are passed
  64. */
  65. mr r31,r3
  66. mr r30,r4
  67. mr r29,r5
  68. mr r28,r6
  69. mr r27,r7
  70. li r25,0 /* phys kernel start (low) */
  71. li r24,0 /* CPU number */
  72. li r23,0 /* phys kernel start (high) */
  73. /* We try to not make any assumptions about how the boot loader
  74. * setup or used the TLBs. We invalidate all mappings from the
  75. * boot loader and load a single entry in TLB1[0] to map the
  76. * first 64M of kernel memory. Any boot info passed from the
  77. * bootloader needs to live in this first 64M.
  78. *
  79. * Requirement on bootloader:
  80. * - The page we're executing in needs to reside in TLB1 and
  81. * have IPROT=1. If not an invalidate broadcast could
  82. * evict the entry we're currently executing in.
  83. *
  84. * r3 = Index of TLB1 were executing in
  85. * r4 = Current MSR[IS]
  86. * r5 = Index of TLB1 temp mapping
  87. *
  88. * Later in mapin_ram we will correctly map lowmem, and resize TLB1[0]
  89. * if needed
  90. */
  91. /* 1. Find the index of the entry we're executing in */
  92. bl invstr /* Find our address */
  93. invstr: mflr r6 /* Make it accessible */
  94. mfmsr r7
  95. rlwinm r4,r7,27,31,31 /* extract MSR[IS] */
  96. mfspr r7, SPRN_PID0
  97. slwi r7,r7,16
  98. or r7,r7,r4
  99. mtspr SPRN_MAS6,r7
  100. tlbsx 0,r6 /* search MSR[IS], SPID=PID0 */
  101. #ifndef CONFIG_E200
  102. mfspr r7,SPRN_MAS1
  103. andis. r7,r7,MAS1_VALID@h
  104. bne match_TLB
  105. mfspr r7,SPRN_PID1
  106. slwi r7,r7,16
  107. or r7,r7,r4
  108. mtspr SPRN_MAS6,r7
  109. tlbsx 0,r6 /* search MSR[IS], SPID=PID1 */
  110. mfspr r7,SPRN_MAS1
  111. andis. r7,r7,MAS1_VALID@h
  112. bne match_TLB
  113. mfspr r7, SPRN_PID2
  114. slwi r7,r7,16
  115. or r7,r7,r4
  116. mtspr SPRN_MAS6,r7
  117. tlbsx 0,r6 /* Fall through, we had to match */
  118. #endif
  119. match_TLB:
  120. mfspr r7,SPRN_MAS0
  121. rlwinm r3,r7,16,20,31 /* Extract MAS0(Entry) */
  122. mfspr r7,SPRN_MAS1 /* Insure IPROT set */
  123. oris r7,r7,MAS1_IPROT@h
  124. mtspr SPRN_MAS1,r7
  125. tlbwe
  126. /* 2. Invalidate all entries except the entry we're executing in */
  127. mfspr r9,SPRN_TLB1CFG
  128. andi. r9,r9,0xfff
  129. li r6,0 /* Set Entry counter to 0 */
  130. 1: lis r7,0x1000 /* Set MAS0(TLBSEL) = 1 */
  131. rlwimi r7,r6,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r6) */
  132. mtspr SPRN_MAS0,r7
  133. tlbre
  134. mfspr r7,SPRN_MAS1
  135. rlwinm r7,r7,0,2,31 /* Clear MAS1 Valid and IPROT */
  136. cmpw r3,r6
  137. beq skpinv /* Dont update the current execution TLB */
  138. mtspr SPRN_MAS1,r7
  139. tlbwe
  140. isync
  141. skpinv: addi r6,r6,1 /* Increment */
  142. cmpw r6,r9 /* Are we done? */
  143. bne 1b /* If not, repeat */
  144. /* Invalidate TLB0 */
  145. li r6,0x04
  146. tlbivax 0,r6
  147. TLBSYNC
  148. /* Invalidate TLB1 */
  149. li r6,0x0c
  150. tlbivax 0,r6
  151. TLBSYNC
  152. /* 3. Setup a temp mapping and jump to it */
  153. andi. r5, r3, 0x1 /* Find an entry not used and is non-zero */
  154. addi r5, r5, 0x1
  155. lis r7,0x1000 /* Set MAS0(TLBSEL) = 1 */
  156. rlwimi r7,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  157. mtspr SPRN_MAS0,r7
  158. tlbre
  159. /* grab and fixup the RPN */
  160. mfspr r6,SPRN_MAS1 /* extract MAS1[SIZE] */
  161. rlwinm r6,r6,25,27,30
  162. li r8,-1
  163. addi r6,r6,10
  164. slw r6,r8,r6 /* convert to mask */
  165. bl 1f /* Find our address */
  166. 1: mflr r7
  167. mfspr r8,SPRN_MAS3
  168. #ifdef CONFIG_PHYS_64BIT
  169. mfspr r23,SPRN_MAS7
  170. #endif
  171. and r8,r6,r8
  172. subfic r9,r6,-4096
  173. and r9,r9,r7
  174. or r25,r8,r9
  175. ori r8,r25,(MAS3_SX|MAS3_SW|MAS3_SR)
  176. /* Just modify the entry ID and EPN for the temp mapping */
  177. lis r7,0x1000 /* Set MAS0(TLBSEL) = 1 */
  178. rlwimi r7,r5,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r5) */
  179. mtspr SPRN_MAS0,r7
  180. xori r6,r4,1 /* Setup TMP mapping in the other Address space */
  181. slwi r6,r6,12
  182. oris r6,r6,(MAS1_VALID|MAS1_IPROT)@h
  183. ori r6,r6,(MAS1_TSIZE(BOOKE_PAGESZ_4K))@l
  184. mtspr SPRN_MAS1,r6
  185. mfspr r6,SPRN_MAS2
  186. li r7,0 /* temp EPN = 0 */
  187. rlwimi r7,r6,0,20,31
  188. mtspr SPRN_MAS2,r7
  189. mtspr SPRN_MAS3,r8
  190. tlbwe
  191. xori r6,r4,1
  192. slwi r6,r6,5 /* setup new context with other address space */
  193. bl 1f /* Find our address */
  194. 1: mflr r9
  195. rlwimi r7,r9,0,20,31
  196. addi r7,r7,24
  197. mtspr SPRN_SRR0,r7
  198. mtspr SPRN_SRR1,r6
  199. rfi
  200. /* 4. Clear out PIDs & Search info */
  201. li r6,0
  202. mtspr SPRN_PID0,r6
  203. #ifndef CONFIG_E200
  204. mtspr SPRN_PID1,r6
  205. mtspr SPRN_PID2,r6
  206. #endif
  207. mtspr SPRN_MAS6,r6
  208. /* 5. Invalidate mapping we started in */
  209. lis r7,0x1000 /* Set MAS0(TLBSEL) = 1 */
  210. rlwimi r7,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  211. mtspr SPRN_MAS0,r7
  212. tlbre
  213. mfspr r6,SPRN_MAS1
  214. rlwinm r6,r6,0,2,0 /* clear IPROT */
  215. mtspr SPRN_MAS1,r6
  216. tlbwe
  217. /* Invalidate TLB1 */
  218. li r9,0x0c
  219. tlbivax 0,r9
  220. TLBSYNC
  221. /* 6. Setup KERNELBASE mapping in TLB1[0] */
  222. lis r6,0x1000 /* Set MAS0(TLBSEL) = TLB1(1), ESEL = 0 */
  223. mtspr SPRN_MAS0,r6
  224. lis r6,(MAS1_VALID|MAS1_IPROT)@h
  225. ori r6,r6,(MAS1_TSIZE(BOOKE_PAGESZ_64M))@l
  226. mtspr SPRN_MAS1,r6
  227. li r7,0
  228. lis r6,PAGE_OFFSET@h
  229. ori r6,r6,PAGE_OFFSET@l
  230. rlwimi r6,r7,0,20,31
  231. mtspr SPRN_MAS2,r6
  232. mtspr SPRN_MAS3,r8
  233. tlbwe
  234. /* 7. Jump to KERNELBASE mapping */
  235. lis r6,KERNELBASE@h
  236. ori r6,r6,KERNELBASE@l
  237. rlwimi r6,r7,0,20,31
  238. lis r7,MSR_KERNEL@h
  239. ori r7,r7,MSR_KERNEL@l
  240. bl 1f /* Find our address */
  241. 1: mflr r9
  242. rlwimi r6,r9,0,20,31
  243. addi r6,r6,24
  244. mtspr SPRN_SRR0,r6
  245. mtspr SPRN_SRR1,r7
  246. rfi /* start execution out of TLB1[0] entry */
  247. /* 8. Clear out the temp mapping */
  248. lis r7,0x1000 /* Set MAS0(TLBSEL) = 1 */
  249. rlwimi r7,r5,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r5) */
  250. mtspr SPRN_MAS0,r7
  251. tlbre
  252. mfspr r8,SPRN_MAS1
  253. rlwinm r8,r8,0,2,0 /* clear IPROT */
  254. mtspr SPRN_MAS1,r8
  255. tlbwe
  256. /* Invalidate TLB1 */
  257. li r9,0x0c
  258. tlbivax 0,r9
  259. TLBSYNC
  260. /* Establish the interrupt vector offsets */
  261. SET_IVOR(0, CriticalInput);
  262. SET_IVOR(1, MachineCheck);
  263. SET_IVOR(2, DataStorage);
  264. SET_IVOR(3, InstructionStorage);
  265. SET_IVOR(4, ExternalInput);
  266. SET_IVOR(5, Alignment);
  267. SET_IVOR(6, Program);
  268. SET_IVOR(7, FloatingPointUnavailable);
  269. SET_IVOR(8, SystemCall);
  270. SET_IVOR(9, AuxillaryProcessorUnavailable);
  271. SET_IVOR(10, Decrementer);
  272. SET_IVOR(11, FixedIntervalTimer);
  273. SET_IVOR(12, WatchdogTimer);
  274. SET_IVOR(13, DataTLBError);
  275. SET_IVOR(14, InstructionTLBError);
  276. SET_IVOR(15, DebugDebug);
  277. #if defined(CONFIG_E500) && !defined(CONFIG_PPC_E500MC)
  278. SET_IVOR(15, DebugCrit);
  279. #endif
  280. SET_IVOR(32, SPEUnavailable);
  281. SET_IVOR(33, SPEFloatingPointData);
  282. SET_IVOR(34, SPEFloatingPointRound);
  283. #ifndef CONFIG_E200
  284. SET_IVOR(35, PerformanceMonitor);
  285. #endif
  286. #ifdef CONFIG_PPC_E500MC
  287. SET_IVOR(36, Doorbell);
  288. #endif
  289. /* Establish the interrupt vector base */
  290. lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
  291. mtspr SPRN_IVPR,r4
  292. /* Setup the defaults for TLB entries */
  293. li r2,(MAS4_TSIZED(BOOKE_PAGESZ_4K))@l
  294. #ifdef CONFIG_E200
  295. oris r2,r2,MAS4_TLBSELD(1)@h
  296. #endif
  297. mtspr SPRN_MAS4, r2
  298. #if 0
  299. /* Enable DOZE */
  300. mfspr r2,SPRN_HID0
  301. oris r2,r2,HID0_DOZE@h
  302. mtspr SPRN_HID0, r2
  303. #endif
  304. #ifdef CONFIG_E200
  305. /* enable dedicated debug exception handling resources (Debug APU) */
  306. mfspr r2,SPRN_HID0
  307. ori r2,r2,HID0_DAPUEN@l
  308. mtspr SPRN_HID0,r2
  309. #endif
  310. #if !defined(CONFIG_BDI_SWITCH)
  311. /*
  312. * The Abatron BDI JTAG debugger does not tolerate others
  313. * mucking with the debug registers.
  314. */
  315. lis r2,DBCR0_IDM@h
  316. mtspr SPRN_DBCR0,r2
  317. isync
  318. /* clear any residual debug events */
  319. li r2,-1
  320. mtspr SPRN_DBSR,r2
  321. #endif
  322. /*
  323. * This is where the main kernel code starts.
  324. */
  325. /* ptr to current */
  326. lis r2,init_task@h
  327. ori r2,r2,init_task@l
  328. /* ptr to current thread */
  329. addi r4,r2,THREAD /* init task's THREAD */
  330. mtspr SPRN_SPRG3,r4
  331. /* stack */
  332. lis r1,init_thread_union@h
  333. ori r1,r1,init_thread_union@l
  334. li r0,0
  335. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  336. bl early_init
  337. #ifdef CONFIG_RELOCATABLE
  338. lis r3,kernstart_addr@ha
  339. la r3,kernstart_addr@l(r3)
  340. #ifdef CONFIG_PHYS_64BIT
  341. stw r23,0(r3)
  342. stw r25,4(r3)
  343. #else
  344. stw r25,0(r3)
  345. #endif
  346. #endif
  347. mfspr r3,SPRN_TLB1CFG
  348. andi. r3,r3,0xfff
  349. lis r4,num_tlbcam_entries@ha
  350. stw r3,num_tlbcam_entries@l(r4)
  351. /*
  352. * Decide what sort of machine this is and initialize the MMU.
  353. */
  354. mr r3,r31
  355. mr r4,r30
  356. mr r5,r29
  357. mr r6,r28
  358. mr r7,r27
  359. bl machine_init
  360. bl MMU_init
  361. /* Setup PTE pointers for the Abatron bdiGDB */
  362. lis r6, swapper_pg_dir@h
  363. ori r6, r6, swapper_pg_dir@l
  364. lis r5, abatron_pteptrs@h
  365. ori r5, r5, abatron_pteptrs@l
  366. lis r4, KERNELBASE@h
  367. ori r4, r4, KERNELBASE@l
  368. stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */
  369. stw r6, 0(r5)
  370. /* Let's move on */
  371. lis r4,start_kernel@h
  372. ori r4,r4,start_kernel@l
  373. lis r3,MSR_KERNEL@h
  374. ori r3,r3,MSR_KERNEL@l
  375. mtspr SPRN_SRR0,r4
  376. mtspr SPRN_SRR1,r3
  377. rfi /* change context and jump to start_kernel */
  378. /* Macros to hide the PTE size differences
  379. *
  380. * FIND_PTE -- walks the page tables given EA & pgdir pointer
  381. * r10 -- EA of fault
  382. * r11 -- PGDIR pointer
  383. * r12 -- free
  384. * label 2: is the bailout case
  385. *
  386. * if we find the pte (fall through):
  387. * r11 is low pte word
  388. * r12 is pointer to the pte
  389. */
  390. #ifdef CONFIG_PTE_64BIT
  391. #define FIND_PTE \
  392. rlwinm r12, r10, 13, 19, 29; /* Compute pgdir/pmd offset */ \
  393. lwzx r11, r12, r11; /* Get pgd/pmd entry */ \
  394. rlwinm. r12, r11, 0, 0, 20; /* Extract pt base address */ \
  395. beq 2f; /* Bail if no table */ \
  396. rlwimi r12, r10, 23, 20, 28; /* Compute pte address */ \
  397. lwz r11, 4(r12); /* Get pte entry */
  398. #else
  399. #define FIND_PTE \
  400. rlwimi r11, r10, 12, 20, 29; /* Create L1 (pgdir/pmd) address */ \
  401. lwz r11, 0(r11); /* Get L1 entry */ \
  402. rlwinm. r12, r11, 0, 0, 19; /* Extract L2 (pte) base address */ \
  403. beq 2f; /* Bail if no table */ \
  404. rlwimi r12, r10, 22, 20, 29; /* Compute PTE address */ \
  405. lwz r11, 0(r12); /* Get Linux PTE */
  406. #endif
  407. /*
  408. * Interrupt vector entry code
  409. *
  410. * The Book E MMUs are always on so we don't need to handle
  411. * interrupts in real mode as with previous PPC processors. In
  412. * this case we handle interrupts in the kernel virtual address
  413. * space.
  414. *
  415. * Interrupt vectors are dynamically placed relative to the
  416. * interrupt prefix as determined by the address of interrupt_base.
  417. * The interrupt vectors offsets are programmed using the labels
  418. * for each interrupt vector entry.
  419. *
  420. * Interrupt vectors must be aligned on a 16 byte boundary.
  421. * We align on a 32 byte cache line boundary for good measure.
  422. */
  423. interrupt_base:
  424. /* Critical Input Interrupt */
  425. CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception)
  426. /* Machine Check Interrupt */
  427. #ifdef CONFIG_E200
  428. /* no RFMCI, MCSRRs on E200 */
  429. CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
  430. #else
  431. MCHECK_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
  432. #endif
  433. /* Data Storage Interrupt */
  434. START_EXCEPTION(DataStorage)
  435. NORMAL_EXCEPTION_PROLOG
  436. mfspr r5,SPRN_ESR /* Grab the ESR, save it, pass arg3 */
  437. stw r5,_ESR(r11)
  438. mfspr r4,SPRN_DEAR /* Grab the DEAR, save it, pass arg2 */
  439. andis. r10,r5,(ESR_ILK|ESR_DLK)@h
  440. bne 1f
  441. EXC_XFER_EE_LITE(0x0300, handle_page_fault)
  442. 1:
  443. addi r3,r1,STACK_FRAME_OVERHEAD
  444. EXC_XFER_EE_LITE(0x0300, CacheLockingException)
  445. /* Instruction Storage Interrupt */
  446. INSTRUCTION_STORAGE_EXCEPTION
  447. /* External Input Interrupt */
  448. EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE)
  449. /* Alignment Interrupt */
  450. ALIGNMENT_EXCEPTION
  451. /* Program Interrupt */
  452. PROGRAM_EXCEPTION
  453. /* Floating Point Unavailable Interrupt */
  454. #ifdef CONFIG_PPC_FPU
  455. FP_UNAVAILABLE_EXCEPTION
  456. #else
  457. #ifdef CONFIG_E200
  458. /* E200 treats 'normal' floating point instructions as FP Unavail exception */
  459. EXCEPTION(0x0800, FloatingPointUnavailable, program_check_exception, EXC_XFER_EE)
  460. #else
  461. EXCEPTION(0x0800, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE)
  462. #endif
  463. #endif
  464. /* System Call Interrupt */
  465. START_EXCEPTION(SystemCall)
  466. NORMAL_EXCEPTION_PROLOG
  467. EXC_XFER_EE_LITE(0x0c00, DoSyscall)
  468. /* Auxillary Processor Unavailable Interrupt */
  469. EXCEPTION(0x2900, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE)
  470. /* Decrementer Interrupt */
  471. DECREMENTER_EXCEPTION
  472. /* Fixed Internal Timer Interrupt */
  473. /* TODO: Add FIT support */
  474. EXCEPTION(0x3100, FixedIntervalTimer, unknown_exception, EXC_XFER_EE)
  475. /* Watchdog Timer Interrupt */
  476. #ifdef CONFIG_BOOKE_WDT
  477. CRITICAL_EXCEPTION(0x3200, WatchdogTimer, WatchdogException)
  478. #else
  479. CRITICAL_EXCEPTION(0x3200, WatchdogTimer, unknown_exception)
  480. #endif
  481. /* Data TLB Error Interrupt */
  482. START_EXCEPTION(DataTLBError)
  483. mtspr SPRN_SPRG0, r10 /* Save some working registers */
  484. mtspr SPRN_SPRG1, r11
  485. mtspr SPRN_SPRG4W, r12
  486. mtspr SPRN_SPRG5W, r13
  487. mfcr r11
  488. mtspr SPRN_SPRG7W, r11
  489. mfspr r10, SPRN_DEAR /* Get faulting address */
  490. /* If we are faulting a kernel address, we have to use the
  491. * kernel page tables.
  492. */
  493. lis r11, PAGE_OFFSET@h
  494. cmplw 5, r10, r11
  495. blt 5, 3f
  496. lis r11, swapper_pg_dir@h
  497. ori r11, r11, swapper_pg_dir@l
  498. mfspr r12,SPRN_MAS1 /* Set TID to 0 */
  499. rlwinm r12,r12,0,16,1
  500. mtspr SPRN_MAS1,r12
  501. b 4f
  502. /* Get the PGD for the current thread */
  503. 3:
  504. mfspr r11,SPRN_SPRG3
  505. lwz r11,PGDIR(r11)
  506. 4:
  507. /* Mask of required permission bits. Note that while we
  508. * do copy ESR:ST to _PAGE_RW position as trying to write
  509. * to an RO page is pretty common, we don't do it with
  510. * _PAGE_DIRTY. We could do it, but it's a fairly rare
  511. * event so I'd rather take the overhead when it happens
  512. * rather than adding an instruction here. We should measure
  513. * whether the whole thing is worth it in the first place
  514. * as we could avoid loading SPRN_ESR completely in the first
  515. * place...
  516. *
  517. * TODO: Is it worth doing that mfspr & rlwimi in the first
  518. * place or can we save a couple of instructions here ?
  519. */
  520. mfspr r12,SPRN_ESR
  521. li r13,_PAGE_PRESENT|_PAGE_ACCESSED
  522. rlwimi r13,r12,11,29,29
  523. FIND_PTE
  524. andc. r13,r13,r11 /* Check permission */
  525. #ifdef CONFIG_PTE_64BIT
  526. #ifdef CONFIG_SMP
  527. subf r10,r11,r12 /* create false data dep */
  528. lwzx r13,r11,r10 /* Get upper pte bits */
  529. #else
  530. lwz r13,0(r12) /* Get upper pte bits */
  531. #endif
  532. #endif
  533. bne 2f /* Bail if permission/valid mismach */
  534. /* Jump to common tlb load */
  535. b finish_tlb_load
  536. 2:
  537. /* The bailout. Restore registers to pre-exception conditions
  538. * and call the heavyweights to help us out.
  539. */
  540. mfspr r11, SPRN_SPRG7R
  541. mtcr r11
  542. mfspr r13, SPRN_SPRG5R
  543. mfspr r12, SPRN_SPRG4R
  544. mfspr r11, SPRN_SPRG1
  545. mfspr r10, SPRN_SPRG0
  546. b DataStorage
  547. /* Instruction TLB Error Interrupt */
  548. /*
  549. * Nearly the same as above, except we get our
  550. * information from different registers and bailout
  551. * to a different point.
  552. */
  553. START_EXCEPTION(InstructionTLBError)
  554. mtspr SPRN_SPRG0, r10 /* Save some working registers */
  555. mtspr SPRN_SPRG1, r11
  556. mtspr SPRN_SPRG4W, r12
  557. mtspr SPRN_SPRG5W, r13
  558. mfcr r11
  559. mtspr SPRN_SPRG7W, r11
  560. mfspr r10, SPRN_SRR0 /* Get faulting address */
  561. /* If we are faulting a kernel address, we have to use the
  562. * kernel page tables.
  563. */
  564. lis r11, PAGE_OFFSET@h
  565. cmplw 5, r10, r11
  566. blt 5, 3f
  567. lis r11, swapper_pg_dir@h
  568. ori r11, r11, swapper_pg_dir@l
  569. mfspr r12,SPRN_MAS1 /* Set TID to 0 */
  570. rlwinm r12,r12,0,16,1
  571. mtspr SPRN_MAS1,r12
  572. b 4f
  573. /* Get the PGD for the current thread */
  574. 3:
  575. mfspr r11,SPRN_SPRG3
  576. lwz r11,PGDIR(r11)
  577. 4:
  578. /* Make up the required permissions */
  579. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_HWEXEC
  580. FIND_PTE
  581. andc. r13,r13,r11 /* Check permission */
  582. #ifdef CONFIG_PTE_64BIT
  583. #ifdef CONFIG_SMP
  584. subf r10,r11,r12 /* create false data dep */
  585. lwzx r13,r11,r10 /* Get upper pte bits */
  586. #else
  587. lwz r13,0(r12) /* Get upper pte bits */
  588. #endif
  589. #endif
  590. bne 2f /* Bail if permission mismach */
  591. /* Jump to common TLB load point */
  592. b finish_tlb_load
  593. 2:
  594. /* The bailout. Restore registers to pre-exception conditions
  595. * and call the heavyweights to help us out.
  596. */
  597. mfspr r11, SPRN_SPRG7R
  598. mtcr r11
  599. mfspr r13, SPRN_SPRG5R
  600. mfspr r12, SPRN_SPRG4R
  601. mfspr r11, SPRN_SPRG1
  602. mfspr r10, SPRN_SPRG0
  603. b InstructionStorage
  604. #ifdef CONFIG_SPE
  605. /* SPE Unavailable */
  606. START_EXCEPTION(SPEUnavailable)
  607. NORMAL_EXCEPTION_PROLOG
  608. bne load_up_spe
  609. addi r3,r1,STACK_FRAME_OVERHEAD
  610. EXC_XFER_EE_LITE(0x2010, KernelSPE)
  611. #else
  612. EXCEPTION(0x2020, SPEUnavailable, unknown_exception, EXC_XFER_EE)
  613. #endif /* CONFIG_SPE */
  614. /* SPE Floating Point Data */
  615. #ifdef CONFIG_SPE
  616. EXCEPTION(0x2030, SPEFloatingPointData, SPEFloatingPointException, EXC_XFER_EE);
  617. #else
  618. EXCEPTION(0x2040, SPEFloatingPointData, unknown_exception, EXC_XFER_EE)
  619. #endif /* CONFIG_SPE */
  620. /* SPE Floating Point Round */
  621. EXCEPTION(0x2050, SPEFloatingPointRound, unknown_exception, EXC_XFER_EE)
  622. /* Performance Monitor */
  623. EXCEPTION(0x2060, PerformanceMonitor, performance_monitor_exception, EXC_XFER_STD)
  624. #ifdef CONFIG_PPC_E500MC
  625. EXCEPTION(0x2070, Doorbell, unknown_exception, EXC_XFER_EE)
  626. #endif
  627. /* Debug Interrupt */
  628. DEBUG_DEBUG_EXCEPTION
  629. #if defined(CONFIG_E500) && !defined(CONFIG_PPC_E500MC)
  630. DEBUG_CRIT_EXCEPTION
  631. #endif
  632. /*
  633. * Local functions
  634. */
  635. /*
  636. * Both the instruction and data TLB miss get to this
  637. * point to load the TLB.
  638. * r10 - available to use
  639. * r11 - TLB (info from Linux PTE)
  640. * r12 - available to use
  641. * r13 - upper bits of PTE (if PTE_64BIT) or available to use
  642. * CR5 - results of addr >= PAGE_OFFSET
  643. * MAS0, MAS1 - loaded with proper value when we get here
  644. * MAS2, MAS3 - will need additional info from Linux PTE
  645. * Upon exit, we reload everything and RFI.
  646. */
  647. finish_tlb_load:
  648. /*
  649. * We set execute, because we don't have the granularity to
  650. * properly set this at the page level (Linux problem).
  651. * Many of these bits are software only. Bits we don't set
  652. * here we (properly should) assume have the appropriate value.
  653. */
  654. mfspr r12, SPRN_MAS2
  655. #ifdef CONFIG_PTE_64BIT
  656. rlwimi r12, r11, 26, 24, 31 /* extract ...WIMGE from pte */
  657. #else
  658. rlwimi r12, r11, 26, 27, 31 /* extract WIMGE from pte */
  659. #endif
  660. mtspr SPRN_MAS2, r12
  661. li r10, (_PAGE_HWEXEC | _PAGE_PRESENT)
  662. rlwimi r10, r11, 31, 29, 29 /* extract _PAGE_DIRTY into SW */
  663. and r12, r11, r10
  664. andi. r10, r11, _PAGE_USER /* Test for _PAGE_USER */
  665. slwi r10, r12, 1
  666. or r10, r10, r12
  667. iseleq r12, r12, r10
  668. #ifdef CONFIG_PTE_64BIT
  669. 2: rlwimi r12, r13, 24, 0, 7 /* grab RPN[32:39] */
  670. rlwimi r12, r11, 24, 8, 19 /* grab RPN[40:51] */
  671. mtspr SPRN_MAS3, r12
  672. BEGIN_FTR_SECTION
  673. srwi r10, r13, 8 /* grab RPN[8:31] */
  674. mtspr SPRN_MAS7, r10
  675. END_FTR_SECTION_IFSET(CPU_FTR_BIG_PHYS)
  676. #else
  677. 2: rlwimi r11, r12, 0, 20, 31 /* Extract RPN from PTE and merge with perms */
  678. mtspr SPRN_MAS3, r11
  679. #endif
  680. #ifdef CONFIG_E200
  681. /* Round robin TLB1 entries assignment */
  682. mfspr r12, SPRN_MAS0
  683. /* Extract TLB1CFG(NENTRY) */
  684. mfspr r11, SPRN_TLB1CFG
  685. andi. r11, r11, 0xfff
  686. /* Extract MAS0(NV) */
  687. andi. r13, r12, 0xfff
  688. addi r13, r13, 1
  689. cmpw 0, r13, r11
  690. addi r12, r12, 1
  691. /* check if we need to wrap */
  692. blt 7f
  693. /* wrap back to first free tlbcam entry */
  694. lis r13, tlbcam_index@ha
  695. lwz r13, tlbcam_index@l(r13)
  696. rlwimi r12, r13, 0, 20, 31
  697. 7:
  698. mtspr SPRN_MAS0,r12
  699. #endif /* CONFIG_E200 */
  700. tlbwe
  701. /* Done...restore registers and get out of here. */
  702. mfspr r11, SPRN_SPRG7R
  703. mtcr r11
  704. mfspr r13, SPRN_SPRG5R
  705. mfspr r12, SPRN_SPRG4R
  706. mfspr r11, SPRN_SPRG1
  707. mfspr r10, SPRN_SPRG0
  708. rfi /* Force context change */
  709. #ifdef CONFIG_SPE
  710. /* Note that the SPE support is closely modeled after the AltiVec
  711. * support. Changes to one are likely to be applicable to the
  712. * other! */
  713. load_up_spe:
  714. /*
  715. * Disable SPE for the task which had SPE previously,
  716. * and save its SPE registers in its thread_struct.
  717. * Enables SPE for use in the kernel on return.
  718. * On SMP we know the SPE units are free, since we give it up every
  719. * switch. -- Kumar
  720. */
  721. mfmsr r5
  722. oris r5,r5,MSR_SPE@h
  723. mtmsr r5 /* enable use of SPE now */
  724. isync
  725. /*
  726. * For SMP, we don't do lazy SPE switching because it just gets too
  727. * horrendously complex, especially when a task switches from one CPU
  728. * to another. Instead we call giveup_spe in switch_to.
  729. */
  730. #ifndef CONFIG_SMP
  731. lis r3,last_task_used_spe@ha
  732. lwz r4,last_task_used_spe@l(r3)
  733. cmpi 0,r4,0
  734. beq 1f
  735. addi r4,r4,THREAD /* want THREAD of last_task_used_spe */
  736. SAVE_32EVRS(0,r10,r4)
  737. evxor evr10, evr10, evr10 /* clear out evr10 */
  738. evmwumiaa evr10, evr10, evr10 /* evr10 <- ACC = 0 * 0 + ACC */
  739. li r5,THREAD_ACC
  740. evstddx evr10, r4, r5 /* save off accumulator */
  741. lwz r5,PT_REGS(r4)
  742. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  743. lis r10,MSR_SPE@h
  744. andc r4,r4,r10 /* disable SPE for previous task */
  745. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  746. 1:
  747. #endif /* !CONFIG_SMP */
  748. /* enable use of SPE after return */
  749. oris r9,r9,MSR_SPE@h
  750. mfspr r5,SPRN_SPRG3 /* current task's THREAD (phys) */
  751. li r4,1
  752. li r10,THREAD_ACC
  753. stw r4,THREAD_USED_SPE(r5)
  754. evlddx evr4,r10,r5
  755. evmra evr4,evr4
  756. REST_32EVRS(0,r10,r5)
  757. #ifndef CONFIG_SMP
  758. subi r4,r5,THREAD
  759. stw r4,last_task_used_spe@l(r3)
  760. #endif /* !CONFIG_SMP */
  761. /* restore registers and return */
  762. 2: REST_4GPRS(3, r11)
  763. lwz r10,_CCR(r11)
  764. REST_GPR(1, r11)
  765. mtcr r10
  766. lwz r10,_LINK(r11)
  767. mtlr r10
  768. REST_GPR(10, r11)
  769. mtspr SPRN_SRR1,r9
  770. mtspr SPRN_SRR0,r12
  771. REST_GPR(9, r11)
  772. REST_GPR(12, r11)
  773. lwz r11,GPR11(r11)
  774. rfi
  775. /*
  776. * SPE unavailable trap from kernel - print a message, but let
  777. * the task use SPE in the kernel until it returns to user mode.
  778. */
  779. KernelSPE:
  780. lwz r3,_MSR(r1)
  781. oris r3,r3,MSR_SPE@h
  782. stw r3,_MSR(r1) /* enable use of SPE after return */
  783. lis r3,87f@h
  784. ori r3,r3,87f@l
  785. mr r4,r2 /* current */
  786. lwz r5,_NIP(r1)
  787. bl printk
  788. b ret_from_except
  789. 87: .string "SPE used in kernel (task=%p, pc=%x) \n"
  790. .align 4,0
  791. #endif /* CONFIG_SPE */
  792. /*
  793. * Global functions
  794. */
  795. /*
  796. * extern void loadcam_entry(unsigned int index)
  797. *
  798. * Load TLBCAM[index] entry in to the L2 CAM MMU
  799. */
  800. _GLOBAL(loadcam_entry)
  801. lis r4,TLBCAM@ha
  802. addi r4,r4,TLBCAM@l
  803. mulli r5,r3,20
  804. add r3,r5,r4
  805. lwz r4,0(r3)
  806. mtspr SPRN_MAS0,r4
  807. lwz r4,4(r3)
  808. mtspr SPRN_MAS1,r4
  809. lwz r4,8(r3)
  810. mtspr SPRN_MAS2,r4
  811. lwz r4,12(r3)
  812. mtspr SPRN_MAS3,r4
  813. tlbwe
  814. isync
  815. blr
  816. /*
  817. * extern void giveup_altivec(struct task_struct *prev)
  818. *
  819. * The e500 core does not have an AltiVec unit.
  820. */
  821. _GLOBAL(giveup_altivec)
  822. blr
  823. #ifdef CONFIG_SPE
  824. /*
  825. * extern void giveup_spe(struct task_struct *prev)
  826. *
  827. */
  828. _GLOBAL(giveup_spe)
  829. mfmsr r5
  830. oris r5,r5,MSR_SPE@h
  831. mtmsr r5 /* enable use of SPE now */
  832. isync
  833. cmpi 0,r3,0
  834. beqlr- /* if no previous owner, done */
  835. addi r3,r3,THREAD /* want THREAD of task */
  836. lwz r5,PT_REGS(r3)
  837. cmpi 0,r5,0
  838. SAVE_32EVRS(0, r4, r3)
  839. evxor evr6, evr6, evr6 /* clear out evr6 */
  840. evmwumiaa evr6, evr6, evr6 /* evr6 <- ACC = 0 * 0 + ACC */
  841. li r4,THREAD_ACC
  842. evstddx evr6, r4, r3 /* save off accumulator */
  843. mfspr r6,SPRN_SPEFSCR
  844. stw r6,THREAD_SPEFSCR(r3) /* save spefscr register value */
  845. beq 1f
  846. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  847. lis r3,MSR_SPE@h
  848. andc r4,r4,r3 /* disable SPE for previous task */
  849. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  850. 1:
  851. #ifndef CONFIG_SMP
  852. li r5,0
  853. lis r4,last_task_used_spe@ha
  854. stw r5,last_task_used_spe@l(r4)
  855. #endif /* !CONFIG_SMP */
  856. blr
  857. #endif /* CONFIG_SPE */
  858. /*
  859. * extern void giveup_fpu(struct task_struct *prev)
  860. *
  861. * Not all FSL Book-E cores have an FPU
  862. */
  863. #ifndef CONFIG_PPC_FPU
  864. _GLOBAL(giveup_fpu)
  865. blr
  866. #endif
  867. /*
  868. * extern void abort(void)
  869. *
  870. * At present, this routine just applies a system reset.
  871. */
  872. _GLOBAL(abort)
  873. li r13,0
  874. mtspr SPRN_DBCR0,r13 /* disable all debug events */
  875. isync
  876. mfmsr r13
  877. ori r13,r13,MSR_DE@l /* Enable Debug Events */
  878. mtmsr r13
  879. isync
  880. mfspr r13,SPRN_DBCR0
  881. lis r13,(DBCR0_IDM|DBCR0_RST_CHIP)@h
  882. mtspr SPRN_DBCR0,r13
  883. isync
  884. _GLOBAL(set_context)
  885. #ifdef CONFIG_BDI_SWITCH
  886. /* Context switch the PTE pointer for the Abatron BDI2000.
  887. * The PGDIR is the second parameter.
  888. */
  889. lis r5, abatron_pteptrs@h
  890. ori r5, r5, abatron_pteptrs@l
  891. stw r4, 0x4(r5)
  892. #endif
  893. mtspr SPRN_PID,r3
  894. isync /* Force context change */
  895. blr
  896. _GLOBAL(flush_dcache_L1)
  897. mfspr r3,SPRN_L1CFG0
  898. rlwinm r5,r3,9,3 /* Extract cache block size */
  899. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  900. * are currently defined.
  901. */
  902. li r4,32
  903. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  904. * log2(number of ways)
  905. */
  906. slw r5,r4,r5 /* r5 = cache block size */
  907. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  908. mulli r7,r7,13 /* An 8-way cache will require 13
  909. * loads per set.
  910. */
  911. slw r7,r7,r6
  912. /* save off HID0 and set DCFA */
  913. mfspr r8,SPRN_HID0
  914. ori r9,r8,HID0_DCFA@l
  915. mtspr SPRN_HID0,r9
  916. isync
  917. lis r4,KERNELBASE@h
  918. mtctr r7
  919. 1: lwz r3,0(r4) /* Load... */
  920. add r4,r4,r5
  921. bdnz 1b
  922. msync
  923. lis r4,KERNELBASE@h
  924. mtctr r7
  925. 1: dcbf 0,r4 /* ...and flush. */
  926. add r4,r4,r5
  927. bdnz 1b
  928. /* restore HID0 */
  929. mtspr SPRN_HID0,r8
  930. isync
  931. blr
  932. /*
  933. * We put a few things here that have to be page-aligned. This stuff
  934. * goes at the beginning of the data segment, which is page-aligned.
  935. */
  936. .data
  937. .align 12
  938. .globl sdata
  939. sdata:
  940. .globl empty_zero_page
  941. empty_zero_page:
  942. .space 4096
  943. .globl swapper_pg_dir
  944. swapper_pg_dir:
  945. .space PGD_TABLE_SIZE
  946. /*
  947. * Room for two PTE pointers, usually the kernel and current user pointers
  948. * to their respective root page table.
  949. */
  950. abatron_pteptrs:
  951. .space 8