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