head_fsl_booke.S 26 KB

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