head_fsl_booke.S 31 KB

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