head_fsl_booke.S 26 KB

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