head_fsl_booke.S 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  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. mfspr r10, SPRN_DEAR /* Get faulting address */
  406. /* If we are faulting a kernel address, we have to use the
  407. * kernel page tables.
  408. */
  409. lis r11, PAGE_OFFSET@h
  410. cmplw 5, r10, r11
  411. blt 5, 3f
  412. lis r11, swapper_pg_dir@h
  413. ori r11, r11, swapper_pg_dir@l
  414. mfspr r12,SPRN_MAS1 /* Set TID to 0 */
  415. rlwinm r12,r12,0,16,1
  416. mtspr SPRN_MAS1,r12
  417. b 4f
  418. /* Get the PGD for the current thread */
  419. 3:
  420. mfspr r11,SPRN_SPRG_THREAD
  421. lwz r11,PGDIR(r11)
  422. 4:
  423. /* Mask of required permission bits. Note that while we
  424. * do copy ESR:ST to _PAGE_RW position as trying to write
  425. * to an RO page is pretty common, we don't do it with
  426. * _PAGE_DIRTY. We could do it, but it's a fairly rare
  427. * event so I'd rather take the overhead when it happens
  428. * rather than adding an instruction here. We should measure
  429. * whether the whole thing is worth it in the first place
  430. * as we could avoid loading SPRN_ESR completely in the first
  431. * place...
  432. *
  433. * TODO: Is it worth doing that mfspr & rlwimi in the first
  434. * place or can we save a couple of instructions here ?
  435. */
  436. mfspr r12,SPRN_ESR
  437. #ifdef CONFIG_PTE_64BIT
  438. li r13,_PAGE_PRESENT
  439. oris r13,r13,_PAGE_ACCESSED@h
  440. #else
  441. li r13,_PAGE_PRESENT|_PAGE_ACCESSED
  442. #endif
  443. rlwimi r13,r12,11,29,29
  444. FIND_PTE
  445. andc. r13,r13,r11 /* Check permission */
  446. #ifdef CONFIG_PTE_64BIT
  447. #ifdef CONFIG_SMP
  448. subf r13,r11,r12 /* create false data dep */
  449. lwzx r13,r11,r13 /* Get upper pte bits */
  450. #else
  451. lwz r13,0(r12) /* Get upper pte bits */
  452. #endif
  453. #endif
  454. bne 2f /* Bail if permission/valid mismach */
  455. /* Jump to common tlb load */
  456. b finish_tlb_load
  457. 2:
  458. /* The bailout. Restore registers to pre-exception conditions
  459. * and call the heavyweights to help us out.
  460. */
  461. mfspr r10, SPRN_SPRG_THREAD
  462. lwz r11, THREAD_NORMSAVE(3)(r10)
  463. mtcr r11
  464. lwz r13, THREAD_NORMSAVE(2)(r10)
  465. lwz r12, THREAD_NORMSAVE(1)(r10)
  466. lwz r11, THREAD_NORMSAVE(0)(r10)
  467. mfspr r10, SPRN_SPRG_RSCRATCH0
  468. b DataStorage
  469. /* Instruction TLB Error Interrupt */
  470. /*
  471. * Nearly the same as above, except we get our
  472. * information from different registers and bailout
  473. * to a different point.
  474. */
  475. START_EXCEPTION(InstructionTLBError)
  476. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  477. mfspr r10, SPRN_SPRG_THREAD
  478. stw r11, THREAD_NORMSAVE(0)(r10)
  479. #ifdef CONFIG_KVM_BOOKE_HV
  480. BEGIN_FTR_SECTION
  481. mfspr r11, SPRN_SRR1
  482. END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
  483. #endif
  484. stw r12, THREAD_NORMSAVE(1)(r10)
  485. stw r13, THREAD_NORMSAVE(2)(r10)
  486. mfcr r13
  487. stw r13, THREAD_NORMSAVE(3)(r10)
  488. DO_KVM BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR1
  489. mfspr r10, SPRN_SRR0 /* Get faulting address */
  490. /* If we are faulting a kernel address, we have to use the
  491. * kernel page tables.
  492. */
  493. lis r11, PAGE_OFFSET@h
  494. cmplw 5, r10, r11
  495. blt 5, 3f
  496. lis r11, swapper_pg_dir@h
  497. ori r11, r11, swapper_pg_dir@l
  498. mfspr r12,SPRN_MAS1 /* Set TID to 0 */
  499. rlwinm r12,r12,0,16,1
  500. mtspr SPRN_MAS1,r12
  501. /* Make up the required permissions for kernel code */
  502. #ifdef CONFIG_PTE_64BIT
  503. li r13,_PAGE_PRESENT | _PAGE_BAP_SX
  504. oris r13,r13,_PAGE_ACCESSED@h
  505. #else
  506. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  507. #endif
  508. b 4f
  509. /* Get the PGD for the current thread */
  510. 3:
  511. mfspr r11,SPRN_SPRG_THREAD
  512. lwz r11,PGDIR(r11)
  513. /* Make up the required permissions for user code */
  514. #ifdef CONFIG_PTE_64BIT
  515. li r13,_PAGE_PRESENT | _PAGE_BAP_UX
  516. oris r13,r13,_PAGE_ACCESSED@h
  517. #else
  518. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  519. #endif
  520. 4:
  521. FIND_PTE
  522. andc. r13,r13,r11 /* Check permission */
  523. #ifdef CONFIG_PTE_64BIT
  524. #ifdef CONFIG_SMP
  525. subf r13,r11,r12 /* create false data dep */
  526. lwzx r13,r11,r13 /* Get upper pte bits */
  527. #else
  528. lwz r13,0(r12) /* Get upper pte bits */
  529. #endif
  530. #endif
  531. bne 2f /* Bail if permission mismach */
  532. /* Jump to common TLB load point */
  533. b finish_tlb_load
  534. 2:
  535. /* The bailout. Restore registers to pre-exception conditions
  536. * and call the heavyweights to help us out.
  537. */
  538. mfspr r10, SPRN_SPRG_THREAD
  539. lwz r11, THREAD_NORMSAVE(3)(r10)
  540. mtcr r11
  541. lwz r13, THREAD_NORMSAVE(2)(r10)
  542. lwz r12, THREAD_NORMSAVE(1)(r10)
  543. lwz r11, THREAD_NORMSAVE(0)(r10)
  544. mfspr r10, SPRN_SPRG_RSCRATCH0
  545. b InstructionStorage
  546. /* Define SPE handlers for e200 and e500v2 */
  547. #ifdef CONFIG_SPE
  548. /* SPE Unavailable */
  549. START_EXCEPTION(SPEUnavailable)
  550. NORMAL_EXCEPTION_PROLOG(SPE_UNAVAIL)
  551. beq 1f
  552. bl load_up_spe
  553. b fast_exception_return
  554. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  555. EXC_XFER_EE_LITE(0x2010, KernelSPE)
  556. #elif defined(CONFIG_SPE_POSSIBLE)
  557. EXCEPTION(0x2020, SPE_UNAVAIL, SPEUnavailable, \
  558. unknown_exception, EXC_XFER_EE)
  559. #endif /* CONFIG_SPE_POSSIBLE */
  560. /* SPE Floating Point Data */
  561. #ifdef CONFIG_SPE
  562. EXCEPTION(0x2030, SPE_FP_DATA, SPEFloatingPointData,
  563. SPEFloatingPointException, EXC_XFER_EE)
  564. /* SPE Floating Point Round */
  565. EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  566. SPEFloatingPointRoundException, EXC_XFER_EE)
  567. #elif defined(CONFIG_SPE_POSSIBLE)
  568. EXCEPTION(0x2040, SPE_FP_DATA, SPEFloatingPointData,
  569. unknown_exception, EXC_XFER_EE)
  570. EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  571. unknown_exception, EXC_XFER_EE)
  572. #endif /* CONFIG_SPE_POSSIBLE */
  573. /* Performance Monitor */
  574. EXCEPTION(0x2060, PERFORMANCE_MONITOR, PerformanceMonitor, \
  575. performance_monitor_exception, EXC_XFER_STD)
  576. EXCEPTION(0x2070, DOORBELL, Doorbell, doorbell_exception, EXC_XFER_STD)
  577. CRITICAL_EXCEPTION(0x2080, DOORBELL_CRITICAL, \
  578. CriticalDoorbell, unknown_exception)
  579. /* Debug Interrupt */
  580. DEBUG_DEBUG_EXCEPTION
  581. DEBUG_CRIT_EXCEPTION
  582. GUEST_DOORBELL_EXCEPTION
  583. CRITICAL_EXCEPTION(0, GUEST_DBELL_CRIT, CriticalGuestDoorbell, \
  584. unknown_exception)
  585. /* Hypercall */
  586. EXCEPTION(0, HV_SYSCALL, Hypercall, unknown_exception, EXC_XFER_EE)
  587. /* Embedded Hypervisor Privilege */
  588. EXCEPTION(0, HV_PRIV, Ehvpriv, unknown_exception, EXC_XFER_EE)
  589. interrupt_end:
  590. /*
  591. * Local functions
  592. */
  593. /*
  594. * Both the instruction and data TLB miss get to this
  595. * point to load the TLB.
  596. * r10 - tsize encoding (if HUGETLB_PAGE) or available to use
  597. * r11 - TLB (info from Linux PTE)
  598. * r12 - available to use
  599. * r13 - upper bits of PTE (if PTE_64BIT) or available to use
  600. * CR5 - results of addr >= PAGE_OFFSET
  601. * MAS0, MAS1 - loaded with proper value when we get here
  602. * MAS2, MAS3 - will need additional info from Linux PTE
  603. * Upon exit, we reload everything and RFI.
  604. */
  605. finish_tlb_load:
  606. #ifdef CONFIG_HUGETLB_PAGE
  607. cmpwi 6, r10, 0 /* check for huge page */
  608. beq 6, finish_tlb_load_cont /* !huge */
  609. /* Alas, we need more scratch registers for hugepages */
  610. mfspr r12, SPRN_SPRG_THREAD
  611. stw r14, THREAD_NORMSAVE(4)(r12)
  612. stw r15, THREAD_NORMSAVE(5)(r12)
  613. stw r16, THREAD_NORMSAVE(6)(r12)
  614. stw r17, THREAD_NORMSAVE(7)(r12)
  615. /* Get the next_tlbcam_idx percpu var */
  616. #ifdef CONFIG_SMP
  617. lwz r12, THREAD_INFO-THREAD(r12)
  618. lwz r15, TI_CPU(r12)
  619. lis r14, __per_cpu_offset@h
  620. ori r14, r14, __per_cpu_offset@l
  621. rlwinm r15, r15, 2, 0, 29
  622. lwzx r16, r14, r15
  623. #else
  624. li r16, 0
  625. #endif
  626. lis r17, next_tlbcam_idx@h
  627. ori r17, r17, next_tlbcam_idx@l
  628. add r17, r17, r16 /* r17 = *next_tlbcam_idx */
  629. lwz r15, 0(r17) /* r15 = next_tlbcam_idx */
  630. lis r14, MAS0_TLBSEL(1)@h /* select TLB1 (TLBCAM) */
  631. rlwimi r14, r15, 16, 4, 15 /* next_tlbcam_idx entry */
  632. mtspr SPRN_MAS0, r14
  633. /* Extract TLB1CFG(NENTRY) */
  634. mfspr r16, SPRN_TLB1CFG
  635. andi. r16, r16, 0xfff
  636. /* Update next_tlbcam_idx, wrapping when necessary */
  637. addi r15, r15, 1
  638. cmpw r15, r16
  639. blt 100f
  640. lis r14, tlbcam_index@h
  641. ori r14, r14, tlbcam_index@l
  642. lwz r15, 0(r14)
  643. 100: stw r15, 0(r17)
  644. /*
  645. * Calc MAS1_TSIZE from r10 (which has pshift encoded)
  646. * tlb_enc = (pshift - 10).
  647. */
  648. subi r15, r10, 10
  649. mfspr r16, SPRN_MAS1
  650. rlwimi r16, r15, 7, 20, 24
  651. mtspr SPRN_MAS1, r16
  652. /* copy the pshift for use later */
  653. mr r14, r10
  654. /* fall through */
  655. #endif /* CONFIG_HUGETLB_PAGE */
  656. /*
  657. * We set execute, because we don't have the granularity to
  658. * properly set this at the page level (Linux problem).
  659. * Many of these bits are software only. Bits we don't set
  660. * here we (properly should) assume have the appropriate value.
  661. */
  662. finish_tlb_load_cont:
  663. #ifdef CONFIG_PTE_64BIT
  664. rlwinm r12, r11, 32-2, 26, 31 /* Move in perm bits */
  665. andi. r10, r11, _PAGE_DIRTY
  666. bne 1f
  667. li r10, MAS3_SW | MAS3_UW
  668. andc r12, r12, r10
  669. 1: rlwimi r12, r13, 20, 0, 11 /* grab RPN[32:43] */
  670. rlwimi r12, r11, 20, 12, 19 /* grab RPN[44:51] */
  671. 2: mtspr SPRN_MAS3, r12
  672. BEGIN_MMU_FTR_SECTION
  673. srwi r10, r13, 12 /* grab RPN[12:31] */
  674. mtspr SPRN_MAS7, r10
  675. END_MMU_FTR_SECTION_IFSET(MMU_FTR_BIG_PHYS)
  676. #else
  677. li r10, (_PAGE_EXEC | _PAGE_PRESENT)
  678. mr r13, r11
  679. rlwimi r10, r11, 31, 29, 29 /* extract _PAGE_DIRTY into SW */
  680. and r12, r11, r10
  681. andi. r10, r11, _PAGE_USER /* Test for _PAGE_USER */
  682. slwi r10, r12, 1
  683. or r10, r10, r12
  684. iseleq r12, r12, r10
  685. rlwimi r13, r12, 0, 20, 31 /* Get RPN from PTE, merge w/ perms */
  686. mtspr SPRN_MAS3, r13
  687. #endif
  688. mfspr r12, SPRN_MAS2
  689. #ifdef CONFIG_PTE_64BIT
  690. rlwimi r12, r11, 32-19, 27, 31 /* extract WIMGE from pte */
  691. #else
  692. rlwimi r12, r11, 26, 27, 31 /* extract WIMGE from pte */
  693. #endif
  694. #ifdef CONFIG_HUGETLB_PAGE
  695. beq 6, 3f /* don't mask if page isn't huge */
  696. li r13, 1
  697. slw r13, r13, r14
  698. subi r13, r13, 1
  699. rlwinm r13, r13, 0, 0, 19 /* bottom bits used for WIMGE/etc */
  700. andc r12, r12, r13 /* mask off ea bits within the page */
  701. #endif
  702. 3: mtspr SPRN_MAS2, r12
  703. #ifdef CONFIG_E200
  704. /* Round robin TLB1 entries assignment */
  705. mfspr r12, SPRN_MAS0
  706. /* Extract TLB1CFG(NENTRY) */
  707. mfspr r11, SPRN_TLB1CFG
  708. andi. r11, r11, 0xfff
  709. /* Extract MAS0(NV) */
  710. andi. r13, r12, 0xfff
  711. addi r13, r13, 1
  712. cmpw 0, r13, r11
  713. addi r12, r12, 1
  714. /* check if we need to wrap */
  715. blt 7f
  716. /* wrap back to first free tlbcam entry */
  717. lis r13, tlbcam_index@ha
  718. lwz r13, tlbcam_index@l(r13)
  719. rlwimi r12, r13, 0, 20, 31
  720. 7:
  721. mtspr SPRN_MAS0,r12
  722. #endif /* CONFIG_E200 */
  723. tlb_write_entry:
  724. tlbwe
  725. /* Done...restore registers and get out of here. */
  726. mfspr r10, SPRN_SPRG_THREAD
  727. #ifdef CONFIG_HUGETLB_PAGE
  728. beq 6, 8f /* skip restore for 4k page faults */
  729. lwz r14, THREAD_NORMSAVE(4)(r10)
  730. lwz r15, THREAD_NORMSAVE(5)(r10)
  731. lwz r16, THREAD_NORMSAVE(6)(r10)
  732. lwz r17, THREAD_NORMSAVE(7)(r10)
  733. #endif
  734. 8: lwz r11, THREAD_NORMSAVE(3)(r10)
  735. mtcr r11
  736. lwz r13, THREAD_NORMSAVE(2)(r10)
  737. lwz r12, THREAD_NORMSAVE(1)(r10)
  738. lwz r11, THREAD_NORMSAVE(0)(r10)
  739. mfspr r10, SPRN_SPRG_RSCRATCH0
  740. rfi /* Force context change */
  741. #ifdef CONFIG_SPE
  742. /* Note that the SPE support is closely modeled after the AltiVec
  743. * support. Changes to one are likely to be applicable to the
  744. * other! */
  745. _GLOBAL(load_up_spe)
  746. /*
  747. * Disable SPE for the task which had SPE previously,
  748. * and save its SPE registers in its thread_struct.
  749. * Enables SPE for use in the kernel on return.
  750. * On SMP we know the SPE units are free, since we give it up every
  751. * switch. -- Kumar
  752. */
  753. mfmsr r5
  754. oris r5,r5,MSR_SPE@h
  755. mtmsr r5 /* enable use of SPE now */
  756. isync
  757. /* enable use of SPE after return */
  758. oris r9,r9,MSR_SPE@h
  759. mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
  760. li r4,1
  761. li r10,THREAD_ACC
  762. stw r4,THREAD_USED_SPE(r5)
  763. evlddx evr4,r10,r5
  764. evmra evr4,evr4
  765. REST_32EVRS(0,r10,r5,THREAD_EVR0)
  766. blr
  767. /*
  768. * SPE unavailable trap from kernel - print a message, but let
  769. * the task use SPE in the kernel until it returns to user mode.
  770. */
  771. KernelSPE:
  772. lwz r3,_MSR(r1)
  773. oris r3,r3,MSR_SPE@h
  774. stw r3,_MSR(r1) /* enable use of SPE after return */
  775. #ifdef CONFIG_PRINTK
  776. lis r3,87f@h
  777. ori r3,r3,87f@l
  778. mr r4,r2 /* current */
  779. lwz r5,_NIP(r1)
  780. bl printk
  781. #endif
  782. b ret_from_except
  783. #ifdef CONFIG_PRINTK
  784. 87: .string "SPE used in kernel (task=%p, pc=%x) \n"
  785. #endif
  786. .align 4,0
  787. #endif /* CONFIG_SPE */
  788. /*
  789. * Translate the effec addr in r3 to phys addr. The phys addr will be put
  790. * into r3(higher 32bit) and r4(lower 32bit)
  791. */
  792. get_phys_addr:
  793. mfmsr r8
  794. mfspr r9,SPRN_PID
  795. rlwinm r9,r9,16,0x3fff0000 /* turn PID into MAS6[SPID] */
  796. rlwimi r9,r8,28,0x00000001 /* turn MSR[DS] into MAS6[SAS] */
  797. mtspr SPRN_MAS6,r9
  798. tlbsx 0,r3 /* must succeed */
  799. mfspr r8,SPRN_MAS1
  800. mfspr r12,SPRN_MAS3
  801. rlwinm r9,r8,25,0x1f /* r9 = log2(page size) */
  802. li r10,1024
  803. slw r10,r10,r9 /* r10 = page size */
  804. addi r10,r10,-1
  805. and r11,r3,r10 /* r11 = page offset */
  806. andc r4,r12,r10 /* r4 = page base */
  807. or r4,r4,r11 /* r4 = devtree phys addr */
  808. #ifdef CONFIG_PHYS_64BIT
  809. mfspr r3,SPRN_MAS7
  810. #endif
  811. blr
  812. /*
  813. * Global functions
  814. */
  815. #ifdef CONFIG_E200
  816. /* Adjust or setup IVORs for e200 */
  817. _GLOBAL(__setup_e200_ivors)
  818. li r3,DebugDebug@l
  819. mtspr SPRN_IVOR15,r3
  820. li r3,SPEUnavailable@l
  821. mtspr SPRN_IVOR32,r3
  822. li r3,SPEFloatingPointData@l
  823. mtspr SPRN_IVOR33,r3
  824. li r3,SPEFloatingPointRound@l
  825. mtspr SPRN_IVOR34,r3
  826. sync
  827. blr
  828. #endif
  829. #ifdef CONFIG_E500
  830. #ifndef CONFIG_PPC_E500MC
  831. /* Adjust or setup IVORs for e500v1/v2 */
  832. _GLOBAL(__setup_e500_ivors)
  833. li r3,DebugCrit@l
  834. mtspr SPRN_IVOR15,r3
  835. li r3,SPEUnavailable@l
  836. mtspr SPRN_IVOR32,r3
  837. li r3,SPEFloatingPointData@l
  838. mtspr SPRN_IVOR33,r3
  839. li r3,SPEFloatingPointRound@l
  840. mtspr SPRN_IVOR34,r3
  841. li r3,PerformanceMonitor@l
  842. mtspr SPRN_IVOR35,r3
  843. sync
  844. blr
  845. #else
  846. /* Adjust or setup IVORs for e500mc */
  847. _GLOBAL(__setup_e500mc_ivors)
  848. li r3,DebugDebug@l
  849. mtspr SPRN_IVOR15,r3
  850. li r3,PerformanceMonitor@l
  851. mtspr SPRN_IVOR35,r3
  852. li r3,Doorbell@l
  853. mtspr SPRN_IVOR36,r3
  854. li r3,CriticalDoorbell@l
  855. mtspr SPRN_IVOR37,r3
  856. sync
  857. blr
  858. /* setup ehv ivors for */
  859. _GLOBAL(__setup_ehv_ivors)
  860. li r3,GuestDoorbell@l
  861. mtspr SPRN_IVOR38,r3
  862. li r3,CriticalGuestDoorbell@l
  863. mtspr SPRN_IVOR39,r3
  864. li r3,Hypercall@l
  865. mtspr SPRN_IVOR40,r3
  866. li r3,Ehvpriv@l
  867. mtspr SPRN_IVOR41,r3
  868. sync
  869. blr
  870. #endif /* CONFIG_PPC_E500MC */
  871. #endif /* CONFIG_E500 */
  872. #ifdef CONFIG_SPE
  873. /*
  874. * extern void __giveup_spe(struct task_struct *prev)
  875. *
  876. */
  877. _GLOBAL(__giveup_spe)
  878. addi r3,r3,THREAD /* want THREAD of task */
  879. lwz r5,PT_REGS(r3)
  880. cmpi 0,r5,0
  881. SAVE_32EVRS(0, r4, r3, THREAD_EVR0)
  882. evxor evr6, evr6, evr6 /* clear out evr6 */
  883. evmwumiaa evr6, evr6, evr6 /* evr6 <- ACC = 0 * 0 + ACC */
  884. li r4,THREAD_ACC
  885. evstddx evr6, r4, r3 /* save off accumulator */
  886. beq 1f
  887. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  888. lis r3,MSR_SPE@h
  889. andc r4,r4,r3 /* disable SPE for previous task */
  890. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  891. 1:
  892. blr
  893. #endif /* CONFIG_SPE */
  894. /*
  895. * extern void abort(void)
  896. *
  897. * At present, this routine just applies a system reset.
  898. */
  899. _GLOBAL(abort)
  900. li r13,0
  901. mtspr SPRN_DBCR0,r13 /* disable all debug events */
  902. isync
  903. mfmsr r13
  904. ori r13,r13,MSR_DE@l /* Enable Debug Events */
  905. mtmsr r13
  906. isync
  907. mfspr r13,SPRN_DBCR0
  908. lis r13,(DBCR0_IDM|DBCR0_RST_CHIP)@h
  909. mtspr SPRN_DBCR0,r13
  910. isync
  911. _GLOBAL(set_context)
  912. #ifdef CONFIG_BDI_SWITCH
  913. /* Context switch the PTE pointer for the Abatron BDI2000.
  914. * The PGDIR is the second parameter.
  915. */
  916. lis r5, abatron_pteptrs@h
  917. ori r5, r5, abatron_pteptrs@l
  918. stw r4, 0x4(r5)
  919. #endif
  920. mtspr SPRN_PID,r3
  921. isync /* Force context change */
  922. blr
  923. #ifdef CONFIG_SMP
  924. /* When we get here, r24 needs to hold the CPU # */
  925. .globl __secondary_start
  926. __secondary_start:
  927. LOAD_REG_ADDR_PIC(r3, tlbcam_index)
  928. lwz r3,0(r3)
  929. mtctr r3
  930. li r26,0 /* r26 safe? */
  931. bl switch_to_as1
  932. mr r27,r3 /* tlb entry */
  933. /* Load each CAM entry */
  934. 1: mr r3,r26
  935. bl loadcam_entry
  936. addi r26,r26,1
  937. bdnz 1b
  938. mr r3,r27 /* tlb entry */
  939. LOAD_REG_ADDR_PIC(r4, memstart_addr)
  940. lwz r4,0(r4)
  941. mr r5,r25 /* phys kernel start */
  942. rlwinm r5,r5,0,~0x3ffffff /* aligned 64M */
  943. subf r4,r5,r4 /* memstart_addr - phys kernel start */
  944. li r5,0 /* no device tree */
  945. li r6,0 /* not boot cpu */
  946. bl restore_to_as0
  947. lis r3,__secondary_hold_acknowledge@h
  948. ori r3,r3,__secondary_hold_acknowledge@l
  949. stw r24,0(r3)
  950. li r3,0
  951. mr r4,r24 /* Why? */
  952. bl call_setup_cpu
  953. /* get current_thread_info and current */
  954. lis r1,secondary_ti@ha
  955. lwz r1,secondary_ti@l(r1)
  956. lwz r2,TI_TASK(r1)
  957. /* stack */
  958. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  959. li r0,0
  960. stw r0,0(r1)
  961. /* ptr to current thread */
  962. addi r4,r2,THREAD /* address of our thread_struct */
  963. mtspr SPRN_SPRG_THREAD,r4
  964. /* Setup the defaults for TLB entries */
  965. li r4,(MAS4_TSIZED(BOOK3E_PAGESZ_4K))@l
  966. mtspr SPRN_MAS4,r4
  967. /* Jump to start_secondary */
  968. lis r4,MSR_KERNEL@h
  969. ori r4,r4,MSR_KERNEL@l
  970. lis r3,start_secondary@h
  971. ori r3,r3,start_secondary@l
  972. mtspr SPRN_SRR0,r3
  973. mtspr SPRN_SRR1,r4
  974. sync
  975. rfi
  976. sync
  977. .globl __secondary_hold_acknowledge
  978. __secondary_hold_acknowledge:
  979. .long -1
  980. #endif
  981. /*
  982. * Create a tlb entry with the same effective and physical address as
  983. * the tlb entry used by the current running code. But set the TS to 1.
  984. * Then switch to the address space 1. It will return with the r3 set to
  985. * the ESEL of the new created tlb.
  986. */
  987. _GLOBAL(switch_to_as1)
  988. mflr r5
  989. /* Find a entry not used */
  990. mfspr r3,SPRN_TLB1CFG
  991. andi. r3,r3,0xfff
  992. mfspr r4,SPRN_PID
  993. rlwinm r4,r4,16,0x3fff0000 /* turn PID into MAS6[SPID] */
  994. mtspr SPRN_MAS6,r4
  995. 1: lis r4,0x1000 /* Set MAS0(TLBSEL) = 1 */
  996. addi r3,r3,-1
  997. rlwimi r4,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  998. mtspr SPRN_MAS0,r4
  999. tlbre
  1000. mfspr r4,SPRN_MAS1
  1001. andis. r4,r4,MAS1_VALID@h
  1002. bne 1b
  1003. /* Get the tlb entry used by the current running code */
  1004. bl 0f
  1005. 0: mflr r4
  1006. tlbsx 0,r4
  1007. mfspr r4,SPRN_MAS1
  1008. ori r4,r4,MAS1_TS /* Set the TS = 1 */
  1009. mtspr SPRN_MAS1,r4
  1010. mfspr r4,SPRN_MAS0
  1011. rlwinm r4,r4,0,~MAS0_ESEL_MASK
  1012. rlwimi r4,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  1013. mtspr SPRN_MAS0,r4
  1014. tlbwe
  1015. isync
  1016. sync
  1017. mfmsr r4
  1018. ori r4,r4,MSR_IS | MSR_DS
  1019. mtspr SPRN_SRR0,r5
  1020. mtspr SPRN_SRR1,r4
  1021. sync
  1022. rfi
  1023. /*
  1024. * Restore to the address space 0 and also invalidate the tlb entry created
  1025. * by switch_to_as1.
  1026. * r3 - the tlb entry which should be invalidated
  1027. * r4 - __pa(PAGE_OFFSET in AS1) - __pa(PAGE_OFFSET in AS0)
  1028. * r5 - device tree virtual address. If r4 is 0, r5 is ignored.
  1029. * r6 - boot cpu
  1030. */
  1031. _GLOBAL(restore_to_as0)
  1032. mflr r0
  1033. bl 0f
  1034. 0: mflr r9
  1035. addi r9,r9,1f - 0b
  1036. /*
  1037. * We may map the PAGE_OFFSET in AS0 to a different physical address,
  1038. * so we need calculate the right jump and device tree address based
  1039. * on the offset passed by r4.
  1040. */
  1041. add r9,r9,r4
  1042. add r5,r5,r4
  1043. add r0,r0,r4
  1044. 2: mfmsr r7
  1045. li r8,(MSR_IS | MSR_DS)
  1046. andc r7,r7,r8
  1047. mtspr SPRN_SRR0,r9
  1048. mtspr SPRN_SRR1,r7
  1049. sync
  1050. rfi
  1051. /* Invalidate the temporary tlb entry for AS1 */
  1052. 1: lis r9,0x1000 /* Set MAS0(TLBSEL) = 1 */
  1053. rlwimi r9,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  1054. mtspr SPRN_MAS0,r9
  1055. tlbre
  1056. mfspr r9,SPRN_MAS1
  1057. rlwinm r9,r9,0,2,31 /* Clear MAS1 Valid and IPPROT */
  1058. mtspr SPRN_MAS1,r9
  1059. tlbwe
  1060. isync
  1061. cmpwi r4,0
  1062. cmpwi cr1,r6,0
  1063. cror eq,4*cr1+eq,eq
  1064. bne 3f /* offset != 0 && is_boot_cpu */
  1065. mtlr r0
  1066. blr
  1067. /*
  1068. * The PAGE_OFFSET will map to a different physical address,
  1069. * jump to _start to do another relocation again.
  1070. */
  1071. 3: mr r3,r5
  1072. bl _start
  1073. /*
  1074. * We put a few things here that have to be page-aligned. This stuff
  1075. * goes at the beginning of the data segment, which is page-aligned.
  1076. */
  1077. .data
  1078. .align 12
  1079. .globl sdata
  1080. sdata:
  1081. .globl empty_zero_page
  1082. empty_zero_page:
  1083. .space 4096
  1084. EXPORT_SYMBOL(empty_zero_page)
  1085. .globl swapper_pg_dir
  1086. swapper_pg_dir:
  1087. .space PGD_TABLE_SIZE
  1088. /*
  1089. * Room for two PTE pointers, usually the kernel and current user pointers
  1090. * to their respective root page table.
  1091. */
  1092. abatron_pteptrs:
  1093. .space 8