head_fsl_booke.S 26 KB

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