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