head_fsl_booke.S 26 KB

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