head_fsl_booke.S 27 KB

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