head_fsl_booke.S 28 KB

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