head_fsl_booke.S 25 KB

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