head_fsl_booke.S 26 KB

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