head_fsl_booke.S 27 KB

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