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