head_fsl_booke.S 25 KB

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