head_fsl_booke.S 26 KB

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