head_64.S 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  6. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  7. * Adapted for Power Macintosh by Paul Mackerras.
  8. * Low-level exception handlers and MMU support
  9. * rewritten by Paul Mackerras.
  10. * Copyright (C) 1996 Paul Mackerras.
  11. *
  12. * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
  13. * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
  14. *
  15. * This file contains the low-level support and setup for the
  16. * PowerPC-64 platform, including trap and interrupt dispatch.
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version
  21. * 2 of the License, or (at your option) any later version.
  22. */
  23. #include <linux/threads.h>
  24. #include <asm/reg.h>
  25. #include <asm/page.h>
  26. #include <asm/mmu.h>
  27. #include <asm/ppc_asm.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/bug.h>
  30. #include <asm/cputable.h>
  31. #include <asm/setup.h>
  32. #include <asm/hvcall.h>
  33. #include <asm/iseries/lpar_map.h>
  34. #include <asm/thread_info.h>
  35. #include <asm/firmware.h>
  36. #include <asm/page_64.h>
  37. #include <asm/exception.h>
  38. #include <asm/irqflags.h>
  39. /*
  40. * We layout physical memory as follows:
  41. * 0x0000 - 0x00ff : Secondary processor spin code
  42. * 0x0100 - 0x2fff : pSeries Interrupt prologs
  43. * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
  44. * 0x6000 - 0x6fff : Initial (CPU0) segment table
  45. * 0x7000 - 0x7fff : FWNMI data area
  46. * 0x8000 - : Early init and support code
  47. */
  48. /*
  49. * SPRG Usage
  50. *
  51. * Register Definition
  52. *
  53. * SPRG0 reserved for hypervisor
  54. * SPRG1 temp - used to save gpr
  55. * SPRG2 temp - used to save gpr
  56. * SPRG3 virt addr of paca
  57. */
  58. /*
  59. * Entering into this code we make the following assumptions:
  60. * For pSeries:
  61. * 1. The MMU is off & open firmware is running in real mode.
  62. * 2. The kernel is entered at __start
  63. *
  64. * For iSeries:
  65. * 1. The MMU is on (as it always is for iSeries)
  66. * 2. The kernel is entered at system_reset_iSeries
  67. */
  68. .text
  69. .globl _stext
  70. _stext:
  71. _GLOBAL(__start)
  72. /* NOP this out unconditionally */
  73. BEGIN_FTR_SECTION
  74. b .__start_initialization_multiplatform
  75. END_FTR_SECTION(0, 1)
  76. /* Catch branch to 0 in real mode */
  77. trap
  78. /* Secondary processors spin on this value until it goes to 1. */
  79. .globl __secondary_hold_spinloop
  80. __secondary_hold_spinloop:
  81. .llong 0x0
  82. /* Secondary processors write this value with their cpu # */
  83. /* after they enter the spin loop immediately below. */
  84. .globl __secondary_hold_acknowledge
  85. __secondary_hold_acknowledge:
  86. .llong 0x0
  87. #ifdef CONFIG_PPC_ISERIES
  88. /*
  89. * At offset 0x20, there is a pointer to iSeries LPAR data.
  90. * This is required by the hypervisor
  91. */
  92. . = 0x20
  93. .llong hvReleaseData-KERNELBASE
  94. #endif /* CONFIG_PPC_ISERIES */
  95. . = 0x60
  96. /*
  97. * The following code is used to hold secondary processors
  98. * in a spin loop after they have entered the kernel, but
  99. * before the bulk of the kernel has been relocated. This code
  100. * is relocated to physical address 0x60 before prom_init is run.
  101. * All of it must fit below the first exception vector at 0x100.
  102. */
  103. _GLOBAL(__secondary_hold)
  104. mfmsr r24
  105. ori r24,r24,MSR_RI
  106. mtmsrd r24 /* RI on */
  107. /* Grab our physical cpu number */
  108. mr r24,r3
  109. /* Tell the master cpu we're here */
  110. /* Relocation is off & we are located at an address less */
  111. /* than 0x100, so only need to grab low order offset. */
  112. std r24,__secondary_hold_acknowledge@l(0)
  113. sync
  114. /* All secondary cpus wait here until told to start. */
  115. 100: ld r4,__secondary_hold_spinloop@l(0)
  116. cmpdi 0,r4,1
  117. bne 100b
  118. #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
  119. LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
  120. mtctr r4
  121. mr r3,r24
  122. bctr
  123. #else
  124. BUG_OPCODE
  125. #endif
  126. /* This value is used to mark exception frames on the stack. */
  127. .section ".toc","aw"
  128. exception_marker:
  129. .tc ID_72656773_68657265[TC],0x7265677368657265
  130. .text
  131. /*
  132. * This is the start of the interrupt handlers for pSeries
  133. * This code runs with relocation off.
  134. */
  135. . = 0x100
  136. .globl __start_interrupts
  137. __start_interrupts:
  138. STD_EXCEPTION_PSERIES(0x100, system_reset)
  139. . = 0x200
  140. _machine_check_pSeries:
  141. HMT_MEDIUM
  142. mtspr SPRN_SPRG1,r13 /* save r13 */
  143. EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
  144. . = 0x300
  145. .globl data_access_pSeries
  146. data_access_pSeries:
  147. HMT_MEDIUM
  148. mtspr SPRN_SPRG1,r13
  149. BEGIN_FTR_SECTION
  150. mtspr SPRN_SPRG2,r12
  151. mfspr r13,SPRN_DAR
  152. mfspr r12,SPRN_DSISR
  153. srdi r13,r13,60
  154. rlwimi r13,r12,16,0x20
  155. mfcr r12
  156. cmpwi r13,0x2c
  157. beq do_stab_bolted_pSeries
  158. mtcrf 0x80,r12
  159. mfspr r12,SPRN_SPRG2
  160. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  161. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
  162. . = 0x380
  163. .globl data_access_slb_pSeries
  164. data_access_slb_pSeries:
  165. HMT_MEDIUM
  166. mtspr SPRN_SPRG1,r13
  167. mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
  168. std r3,PACA_EXSLB+EX_R3(r13)
  169. mfspr r3,SPRN_DAR
  170. std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
  171. mfcr r9
  172. #ifdef __DISABLED__
  173. /* Keep that around for when we re-implement dynamic VSIDs */
  174. cmpdi r3,0
  175. bge slb_miss_user_pseries
  176. #endif /* __DISABLED__ */
  177. std r10,PACA_EXSLB+EX_R10(r13)
  178. std r11,PACA_EXSLB+EX_R11(r13)
  179. std r12,PACA_EXSLB+EX_R12(r13)
  180. mfspr r10,SPRN_SPRG1
  181. std r10,PACA_EXSLB+EX_R13(r13)
  182. mfspr r12,SPRN_SRR1 /* and SRR1 */
  183. b .slb_miss_realmode /* Rel. branch works in real mode */
  184. STD_EXCEPTION_PSERIES(0x400, instruction_access)
  185. . = 0x480
  186. .globl instruction_access_slb_pSeries
  187. instruction_access_slb_pSeries:
  188. HMT_MEDIUM
  189. mtspr SPRN_SPRG1,r13
  190. mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
  191. std r3,PACA_EXSLB+EX_R3(r13)
  192. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  193. std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
  194. mfcr r9
  195. #ifdef __DISABLED__
  196. /* Keep that around for when we re-implement dynamic VSIDs */
  197. cmpdi r3,0
  198. bge slb_miss_user_pseries
  199. #endif /* __DISABLED__ */
  200. std r10,PACA_EXSLB+EX_R10(r13)
  201. std r11,PACA_EXSLB+EX_R11(r13)
  202. std r12,PACA_EXSLB+EX_R12(r13)
  203. mfspr r10,SPRN_SPRG1
  204. std r10,PACA_EXSLB+EX_R13(r13)
  205. mfspr r12,SPRN_SRR1 /* and SRR1 */
  206. b .slb_miss_realmode /* Rel. branch works in real mode */
  207. MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
  208. STD_EXCEPTION_PSERIES(0x600, alignment)
  209. STD_EXCEPTION_PSERIES(0x700, program_check)
  210. STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
  211. MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
  212. STD_EXCEPTION_PSERIES(0xa00, trap_0a)
  213. STD_EXCEPTION_PSERIES(0xb00, trap_0b)
  214. . = 0xc00
  215. .globl system_call_pSeries
  216. system_call_pSeries:
  217. HMT_MEDIUM
  218. BEGIN_FTR_SECTION
  219. cmpdi r0,0x1ebe
  220. beq- 1f
  221. END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
  222. mr r9,r13
  223. mfmsr r10
  224. mfspr r13,SPRN_SPRG3
  225. mfspr r11,SPRN_SRR0
  226. clrrdi r12,r13,32
  227. oris r12,r12,system_call_common@h
  228. ori r12,r12,system_call_common@l
  229. mtspr SPRN_SRR0,r12
  230. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  231. mfspr r12,SPRN_SRR1
  232. mtspr SPRN_SRR1,r10
  233. rfid
  234. b . /* prevent speculative execution */
  235. /* Fast LE/BE switch system call */
  236. 1: mfspr r12,SPRN_SRR1
  237. xori r12,r12,MSR_LE
  238. mtspr SPRN_SRR1,r12
  239. rfid /* return to userspace */
  240. b .
  241. STD_EXCEPTION_PSERIES(0xd00, single_step)
  242. STD_EXCEPTION_PSERIES(0xe00, trap_0e)
  243. /* We need to deal with the Altivec unavailable exception
  244. * here which is at 0xf20, thus in the middle of the
  245. * prolog code of the PerformanceMonitor one. A little
  246. * trickery is thus necessary
  247. */
  248. . = 0xf00
  249. b performance_monitor_pSeries
  250. . = 0xf20
  251. b altivec_unavailable_pSeries
  252. #ifdef CONFIG_CBE_RAS
  253. HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
  254. #endif /* CONFIG_CBE_RAS */
  255. STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
  256. #ifdef CONFIG_CBE_RAS
  257. HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
  258. #endif /* CONFIG_CBE_RAS */
  259. STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
  260. #ifdef CONFIG_CBE_RAS
  261. HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
  262. #endif /* CONFIG_CBE_RAS */
  263. . = 0x3000
  264. /*** pSeries interrupt support ***/
  265. /* moved from 0xf00 */
  266. STD_EXCEPTION_PSERIES(., performance_monitor)
  267. STD_EXCEPTION_PSERIES(., altivec_unavailable)
  268. /*
  269. * An interrupt came in while soft-disabled; clear EE in SRR1,
  270. * clear paca->hard_enabled and return.
  271. */
  272. masked_interrupt:
  273. stb r10,PACAHARDIRQEN(r13)
  274. mtcrf 0x80,r9
  275. ld r9,PACA_EXGEN+EX_R9(r13)
  276. mfspr r10,SPRN_SRR1
  277. rldicl r10,r10,48,1 /* clear MSR_EE */
  278. rotldi r10,r10,16
  279. mtspr SPRN_SRR1,r10
  280. ld r10,PACA_EXGEN+EX_R10(r13)
  281. mfspr r13,SPRN_SPRG1
  282. rfid
  283. b .
  284. .align 7
  285. do_stab_bolted_pSeries:
  286. mtcrf 0x80,r12
  287. mfspr r12,SPRN_SPRG2
  288. EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
  289. /*
  290. * We have some room here we use that to put
  291. * the peries slb miss user trampoline code so it's reasonably
  292. * away from slb_miss_user_common to avoid problems with rfid
  293. *
  294. * This is used for when the SLB miss handler has to go virtual,
  295. * which doesn't happen for now anymore but will once we re-implement
  296. * dynamic VSIDs for shared page tables
  297. */
  298. #ifdef __DISABLED__
  299. slb_miss_user_pseries:
  300. std r10,PACA_EXGEN+EX_R10(r13)
  301. std r11,PACA_EXGEN+EX_R11(r13)
  302. std r12,PACA_EXGEN+EX_R12(r13)
  303. mfspr r10,SPRG1
  304. ld r11,PACA_EXSLB+EX_R9(r13)
  305. ld r12,PACA_EXSLB+EX_R3(r13)
  306. std r10,PACA_EXGEN+EX_R13(r13)
  307. std r11,PACA_EXGEN+EX_R9(r13)
  308. std r12,PACA_EXGEN+EX_R3(r13)
  309. clrrdi r12,r13,32
  310. mfmsr r10
  311. mfspr r11,SRR0 /* save SRR0 */
  312. ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
  313. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  314. mtspr SRR0,r12
  315. mfspr r12,SRR1 /* and SRR1 */
  316. mtspr SRR1,r10
  317. rfid
  318. b . /* prevent spec. execution */
  319. #endif /* __DISABLED__ */
  320. #ifdef CONFIG_PPC_PSERIES
  321. /*
  322. * Vectors for the FWNMI option. Share common code.
  323. */
  324. .globl system_reset_fwnmi
  325. .align 7
  326. system_reset_fwnmi:
  327. HMT_MEDIUM
  328. mtspr SPRN_SPRG1,r13 /* save r13 */
  329. EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
  330. .globl machine_check_fwnmi
  331. .align 7
  332. machine_check_fwnmi:
  333. HMT_MEDIUM
  334. mtspr SPRN_SPRG1,r13 /* save r13 */
  335. EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
  336. #endif /* CONFIG_PPC_PSERIES */
  337. /*** Common interrupt handlers ***/
  338. STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
  339. /*
  340. * Machine check is different because we use a different
  341. * save area: PACA_EXMC instead of PACA_EXGEN.
  342. */
  343. .align 7
  344. .globl machine_check_common
  345. machine_check_common:
  346. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  347. FINISH_NAP
  348. DISABLE_INTS
  349. bl .save_nvgprs
  350. addi r3,r1,STACK_FRAME_OVERHEAD
  351. bl .machine_check_exception
  352. b .ret_from_except
  353. STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
  354. STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
  355. STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
  356. STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
  357. STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
  358. STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
  359. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
  360. #ifdef CONFIG_ALTIVEC
  361. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
  362. #else
  363. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
  364. #endif
  365. #ifdef CONFIG_CBE_RAS
  366. STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
  367. STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
  368. STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
  369. #endif /* CONFIG_CBE_RAS */
  370. /*
  371. * Here we have detected that the kernel stack pointer is bad.
  372. * R9 contains the saved CR, r13 points to the paca,
  373. * r10 contains the (bad) kernel stack pointer,
  374. * r11 and r12 contain the saved SRR0 and SRR1.
  375. * We switch to using an emergency stack, save the registers there,
  376. * and call kernel_bad_stack(), which panics.
  377. */
  378. bad_stack:
  379. ld r1,PACAEMERGSP(r13)
  380. subi r1,r1,64+INT_FRAME_SIZE
  381. std r9,_CCR(r1)
  382. std r10,GPR1(r1)
  383. std r11,_NIP(r1)
  384. std r12,_MSR(r1)
  385. mfspr r11,SPRN_DAR
  386. mfspr r12,SPRN_DSISR
  387. std r11,_DAR(r1)
  388. std r12,_DSISR(r1)
  389. mflr r10
  390. mfctr r11
  391. mfxer r12
  392. std r10,_LINK(r1)
  393. std r11,_CTR(r1)
  394. std r12,_XER(r1)
  395. SAVE_GPR(0,r1)
  396. SAVE_GPR(2,r1)
  397. SAVE_4GPRS(3,r1)
  398. SAVE_2GPRS(7,r1)
  399. SAVE_10GPRS(12,r1)
  400. SAVE_10GPRS(22,r1)
  401. lhz r12,PACA_TRAP_SAVE(r13)
  402. std r12,_TRAP(r1)
  403. addi r11,r1,INT_FRAME_SIZE
  404. std r11,0(r1)
  405. li r12,0
  406. std r12,0(r11)
  407. ld r2,PACATOC(r13)
  408. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  409. bl .kernel_bad_stack
  410. b 1b
  411. /*
  412. * Return from an exception with minimal checks.
  413. * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
  414. * If interrupts have been enabled, or anything has been
  415. * done that might have changed the scheduling status of
  416. * any task or sent any task a signal, you should use
  417. * ret_from_except or ret_from_except_lite instead of this.
  418. */
  419. fast_exc_return_irq: /* restores irq state too */
  420. ld r3,SOFTE(r1)
  421. TRACE_AND_RESTORE_IRQ(r3);
  422. ld r12,_MSR(r1)
  423. rldicl r4,r12,49,63 /* get MSR_EE to LSB */
  424. stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
  425. b 1f
  426. .globl fast_exception_return
  427. fast_exception_return:
  428. ld r12,_MSR(r1)
  429. 1: ld r11,_NIP(r1)
  430. andi. r3,r12,MSR_RI /* check if RI is set */
  431. beq- unrecov_fer
  432. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  433. andi. r3,r12,MSR_PR
  434. beq 2f
  435. ACCOUNT_CPU_USER_EXIT(r3, r4)
  436. 2:
  437. #endif
  438. ld r3,_CCR(r1)
  439. ld r4,_LINK(r1)
  440. ld r5,_CTR(r1)
  441. ld r6,_XER(r1)
  442. mtcr r3
  443. mtlr r4
  444. mtctr r5
  445. mtxer r6
  446. REST_GPR(0, r1)
  447. REST_8GPRS(2, r1)
  448. mfmsr r10
  449. rldicl r10,r10,48,1 /* clear EE */
  450. rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
  451. mtmsrd r10,1
  452. mtspr SPRN_SRR1,r12
  453. mtspr SPRN_SRR0,r11
  454. REST_4GPRS(10, r1)
  455. ld r1,GPR1(r1)
  456. rfid
  457. b . /* prevent speculative execution */
  458. unrecov_fer:
  459. bl .save_nvgprs
  460. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  461. bl .unrecoverable_exception
  462. b 1b
  463. /*
  464. * Here r13 points to the paca, r9 contains the saved CR,
  465. * SRR0 and SRR1 are saved in r11 and r12,
  466. * r9 - r13 are saved in paca->exgen.
  467. */
  468. .align 7
  469. .globl data_access_common
  470. data_access_common:
  471. mfspr r10,SPRN_DAR
  472. std r10,PACA_EXGEN+EX_DAR(r13)
  473. mfspr r10,SPRN_DSISR
  474. stw r10,PACA_EXGEN+EX_DSISR(r13)
  475. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  476. ld r3,PACA_EXGEN+EX_DAR(r13)
  477. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  478. li r5,0x300
  479. b .do_hash_page /* Try to handle as hpte fault */
  480. .align 7
  481. .globl instruction_access_common
  482. instruction_access_common:
  483. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  484. ld r3,_NIP(r1)
  485. andis. r4,r12,0x5820
  486. li r5,0x400
  487. b .do_hash_page /* Try to handle as hpte fault */
  488. /*
  489. * Here is the common SLB miss user that is used when going to virtual
  490. * mode for SLB misses, that is currently not used
  491. */
  492. #ifdef __DISABLED__
  493. .align 7
  494. .globl slb_miss_user_common
  495. slb_miss_user_common:
  496. mflr r10
  497. std r3,PACA_EXGEN+EX_DAR(r13)
  498. stw r9,PACA_EXGEN+EX_CCR(r13)
  499. std r10,PACA_EXGEN+EX_LR(r13)
  500. std r11,PACA_EXGEN+EX_SRR0(r13)
  501. bl .slb_allocate_user
  502. ld r10,PACA_EXGEN+EX_LR(r13)
  503. ld r3,PACA_EXGEN+EX_R3(r13)
  504. lwz r9,PACA_EXGEN+EX_CCR(r13)
  505. ld r11,PACA_EXGEN+EX_SRR0(r13)
  506. mtlr r10
  507. beq- slb_miss_fault
  508. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  509. beq- unrecov_user_slb
  510. mfmsr r10
  511. .machine push
  512. .machine "power4"
  513. mtcrf 0x80,r9
  514. .machine pop
  515. clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
  516. mtmsrd r10,1
  517. mtspr SRR0,r11
  518. mtspr SRR1,r12
  519. ld r9,PACA_EXGEN+EX_R9(r13)
  520. ld r10,PACA_EXGEN+EX_R10(r13)
  521. ld r11,PACA_EXGEN+EX_R11(r13)
  522. ld r12,PACA_EXGEN+EX_R12(r13)
  523. ld r13,PACA_EXGEN+EX_R13(r13)
  524. rfid
  525. b .
  526. slb_miss_fault:
  527. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
  528. ld r4,PACA_EXGEN+EX_DAR(r13)
  529. li r5,0
  530. std r4,_DAR(r1)
  531. std r5,_DSISR(r1)
  532. b handle_page_fault
  533. unrecov_user_slb:
  534. EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
  535. DISABLE_INTS
  536. bl .save_nvgprs
  537. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  538. bl .unrecoverable_exception
  539. b 1b
  540. #endif /* __DISABLED__ */
  541. /*
  542. * r13 points to the PACA, r9 contains the saved CR,
  543. * r12 contain the saved SRR1, SRR0 is still ready for return
  544. * r3 has the faulting address
  545. * r9 - r13 are saved in paca->exslb.
  546. * r3 is saved in paca->slb_r3
  547. * We assume we aren't going to take any exceptions during this procedure.
  548. */
  549. _GLOBAL(slb_miss_realmode)
  550. mflr r10
  551. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  552. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  553. bl .slb_allocate_realmode
  554. /* All done -- return from exception. */
  555. ld r10,PACA_EXSLB+EX_LR(r13)
  556. ld r3,PACA_EXSLB+EX_R3(r13)
  557. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  558. #ifdef CONFIG_PPC_ISERIES
  559. BEGIN_FW_FTR_SECTION
  560. ld r11,PACALPPACAPTR(r13)
  561. ld r11,LPPACASRR0(r11) /* get SRR0 value */
  562. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  563. #endif /* CONFIG_PPC_ISERIES */
  564. mtlr r10
  565. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  566. beq- 2f
  567. .machine push
  568. .machine "power4"
  569. mtcrf 0x80,r9
  570. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  571. .machine pop
  572. #ifdef CONFIG_PPC_ISERIES
  573. BEGIN_FW_FTR_SECTION
  574. mtspr SPRN_SRR0,r11
  575. mtspr SPRN_SRR1,r12
  576. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  577. #endif /* CONFIG_PPC_ISERIES */
  578. ld r9,PACA_EXSLB+EX_R9(r13)
  579. ld r10,PACA_EXSLB+EX_R10(r13)
  580. ld r11,PACA_EXSLB+EX_R11(r13)
  581. ld r12,PACA_EXSLB+EX_R12(r13)
  582. ld r13,PACA_EXSLB+EX_R13(r13)
  583. rfid
  584. b . /* prevent speculative execution */
  585. 2:
  586. #ifdef CONFIG_PPC_ISERIES
  587. BEGIN_FW_FTR_SECTION
  588. b unrecov_slb
  589. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  590. #endif /* CONFIG_PPC_ISERIES */
  591. mfspr r11,SPRN_SRR0
  592. clrrdi r10,r13,32
  593. LOAD_HANDLER(r10,unrecov_slb)
  594. mtspr SPRN_SRR0,r10
  595. mfmsr r10
  596. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  597. mtspr SPRN_SRR1,r10
  598. rfid
  599. b .
  600. unrecov_slb:
  601. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  602. DISABLE_INTS
  603. bl .save_nvgprs
  604. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  605. bl .unrecoverable_exception
  606. b 1b
  607. .align 7
  608. .globl hardware_interrupt_common
  609. .globl hardware_interrupt_entry
  610. hardware_interrupt_common:
  611. EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
  612. FINISH_NAP
  613. hardware_interrupt_entry:
  614. DISABLE_INTS
  615. BEGIN_FTR_SECTION
  616. bl .ppc64_runlatch_on
  617. END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
  618. addi r3,r1,STACK_FRAME_OVERHEAD
  619. bl .do_IRQ
  620. b .ret_from_except_lite
  621. #ifdef CONFIG_PPC_970_NAP
  622. power4_fixup_nap:
  623. andc r9,r9,r10
  624. std r9,TI_LOCAL_FLAGS(r11)
  625. ld r10,_LINK(r1) /* make idle task do the */
  626. std r10,_NIP(r1) /* equivalent of a blr */
  627. blr
  628. #endif
  629. .align 7
  630. .globl alignment_common
  631. alignment_common:
  632. mfspr r10,SPRN_DAR
  633. std r10,PACA_EXGEN+EX_DAR(r13)
  634. mfspr r10,SPRN_DSISR
  635. stw r10,PACA_EXGEN+EX_DSISR(r13)
  636. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  637. ld r3,PACA_EXGEN+EX_DAR(r13)
  638. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  639. std r3,_DAR(r1)
  640. std r4,_DSISR(r1)
  641. bl .save_nvgprs
  642. addi r3,r1,STACK_FRAME_OVERHEAD
  643. ENABLE_INTS
  644. bl .alignment_exception
  645. b .ret_from_except
  646. .align 7
  647. .globl program_check_common
  648. program_check_common:
  649. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  650. bl .save_nvgprs
  651. addi r3,r1,STACK_FRAME_OVERHEAD
  652. ENABLE_INTS
  653. bl .program_check_exception
  654. b .ret_from_except
  655. .align 7
  656. .globl fp_unavailable_common
  657. fp_unavailable_common:
  658. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  659. bne 1f /* if from user, just load it up */
  660. bl .save_nvgprs
  661. addi r3,r1,STACK_FRAME_OVERHEAD
  662. ENABLE_INTS
  663. bl .kernel_fp_unavailable_exception
  664. BUG_OPCODE
  665. 1: b .load_up_fpu
  666. .align 7
  667. .globl altivec_unavailable_common
  668. altivec_unavailable_common:
  669. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  670. #ifdef CONFIG_ALTIVEC
  671. BEGIN_FTR_SECTION
  672. bne .load_up_altivec /* if from user, just load it up */
  673. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  674. #endif
  675. bl .save_nvgprs
  676. addi r3,r1,STACK_FRAME_OVERHEAD
  677. ENABLE_INTS
  678. bl .altivec_unavailable_exception
  679. b .ret_from_except
  680. #ifdef CONFIG_ALTIVEC
  681. /*
  682. * load_up_altivec(unused, unused, tsk)
  683. * Disable VMX for the task which had it previously,
  684. * and save its vector registers in its thread_struct.
  685. * Enables the VMX for use in the kernel on return.
  686. * On SMP we know the VMX is free, since we give it up every
  687. * switch (ie, no lazy save of the vector registers).
  688. * On entry: r13 == 'current' && last_task_used_altivec != 'current'
  689. */
  690. _STATIC(load_up_altivec)
  691. mfmsr r5 /* grab the current MSR */
  692. oris r5,r5,MSR_VEC@h
  693. mtmsrd r5 /* enable use of VMX now */
  694. isync
  695. /*
  696. * For SMP, we don't do lazy VMX switching because it just gets too
  697. * horrendously complex, especially when a task switches from one CPU
  698. * to another. Instead we call giveup_altvec in switch_to.
  699. * VRSAVE isn't dealt with here, that is done in the normal context
  700. * switch code. Note that we could rely on vrsave value to eventually
  701. * avoid saving all of the VREGs here...
  702. */
  703. #ifndef CONFIG_SMP
  704. ld r3,last_task_used_altivec@got(r2)
  705. ld r4,0(r3)
  706. cmpdi 0,r4,0
  707. beq 1f
  708. /* Save VMX state to last_task_used_altivec's THREAD struct */
  709. addi r4,r4,THREAD
  710. SAVE_32VRS(0,r5,r4)
  711. mfvscr vr0
  712. li r10,THREAD_VSCR
  713. stvx vr0,r10,r4
  714. /* Disable VMX for last_task_used_altivec */
  715. ld r5,PT_REGS(r4)
  716. ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  717. lis r6,MSR_VEC@h
  718. andc r4,r4,r6
  719. std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  720. 1:
  721. #endif /* CONFIG_SMP */
  722. /* Hack: if we get an altivec unavailable trap with VRSAVE
  723. * set to all zeros, we assume this is a broken application
  724. * that fails to set it properly, and thus we switch it to
  725. * all 1's
  726. */
  727. mfspr r4,SPRN_VRSAVE
  728. cmpdi 0,r4,0
  729. bne+ 1f
  730. li r4,-1
  731. mtspr SPRN_VRSAVE,r4
  732. 1:
  733. /* enable use of VMX after return */
  734. ld r4,PACACURRENT(r13)
  735. addi r5,r4,THREAD /* Get THREAD */
  736. oris r12,r12,MSR_VEC@h
  737. std r12,_MSR(r1)
  738. li r4,1
  739. li r10,THREAD_VSCR
  740. stw r4,THREAD_USED_VR(r5)
  741. lvx vr0,r10,r5
  742. mtvscr vr0
  743. REST_32VRS(0,r4,r5)
  744. #ifndef CONFIG_SMP
  745. /* Update last_task_used_math to 'current' */
  746. subi r4,r5,THREAD /* Back to 'current' */
  747. std r4,0(r3)
  748. #endif /* CONFIG_SMP */
  749. /* restore registers and return */
  750. b fast_exception_return
  751. #endif /* CONFIG_ALTIVEC */
  752. /*
  753. * Hash table stuff
  754. */
  755. .align 7
  756. _STATIC(do_hash_page)
  757. std r3,_DAR(r1)
  758. std r4,_DSISR(r1)
  759. andis. r0,r4,0xa450 /* weird error? */
  760. bne- handle_page_fault /* if not, try to insert a HPTE */
  761. BEGIN_FTR_SECTION
  762. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  763. bne- do_ste_alloc /* If so handle it */
  764. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  765. /*
  766. * On iSeries, we soft-disable interrupts here, then
  767. * hard-enable interrupts so that the hash_page code can spin on
  768. * the hash_table_lock without problems on a shared processor.
  769. */
  770. DISABLE_INTS
  771. /*
  772. * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
  773. * and will clobber volatile registers when irq tracing is enabled
  774. * so we need to reload them. It may be possible to be smarter here
  775. * and move the irq tracing elsewhere but let's keep it simple for
  776. * now
  777. */
  778. #ifdef CONFIG_TRACE_IRQFLAGS
  779. ld r3,_DAR(r1)
  780. ld r4,_DSISR(r1)
  781. ld r5,_TRAP(r1)
  782. ld r12,_MSR(r1)
  783. clrrdi r5,r5,4
  784. #endif /* CONFIG_TRACE_IRQFLAGS */
  785. /*
  786. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  787. * accessing a userspace segment (even from the kernel). We assume
  788. * kernel addresses always have the high bit set.
  789. */
  790. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  791. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  792. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  793. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  794. ori r4,r4,1 /* add _PAGE_PRESENT */
  795. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  796. /*
  797. * r3 contains the faulting address
  798. * r4 contains the required access permissions
  799. * r5 contains the trap number
  800. *
  801. * at return r3 = 0 for success
  802. */
  803. bl .hash_page /* build HPTE if possible */
  804. cmpdi r3,0 /* see if hash_page succeeded */
  805. BEGIN_FW_FTR_SECTION
  806. /*
  807. * If we had interrupts soft-enabled at the point where the
  808. * DSI/ISI occurred, and an interrupt came in during hash_page,
  809. * handle it now.
  810. * We jump to ret_from_except_lite rather than fast_exception_return
  811. * because ret_from_except_lite will check for and handle pending
  812. * interrupts if necessary.
  813. */
  814. beq 13f
  815. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  816. BEGIN_FW_FTR_SECTION
  817. /*
  818. * Here we have interrupts hard-disabled, so it is sufficient
  819. * to restore paca->{soft,hard}_enable and get out.
  820. */
  821. beq fast_exc_return_irq /* Return from exception on success */
  822. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  823. /* For a hash failure, we don't bother re-enabling interrupts */
  824. ble- 12f
  825. /*
  826. * hash_page couldn't handle it, set soft interrupt enable back
  827. * to what it was before the trap. Note that .raw_local_irq_restore
  828. * handles any interrupts pending at this point.
  829. */
  830. ld r3,SOFTE(r1)
  831. TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
  832. bl .raw_local_irq_restore
  833. b 11f
  834. /* Here we have a page fault that hash_page can't handle. */
  835. handle_page_fault:
  836. ENABLE_INTS
  837. 11: ld r4,_DAR(r1)
  838. ld r5,_DSISR(r1)
  839. addi r3,r1,STACK_FRAME_OVERHEAD
  840. bl .do_page_fault
  841. cmpdi r3,0
  842. beq+ 13f
  843. bl .save_nvgprs
  844. mr r5,r3
  845. addi r3,r1,STACK_FRAME_OVERHEAD
  846. lwz r4,_DAR(r1)
  847. bl .bad_page_fault
  848. b .ret_from_except
  849. 13: b .ret_from_except_lite
  850. /* We have a page fault that hash_page could handle but HV refused
  851. * the PTE insertion
  852. */
  853. 12: bl .save_nvgprs
  854. mr r5,r3
  855. addi r3,r1,STACK_FRAME_OVERHEAD
  856. ld r4,_DAR(r1)
  857. bl .low_hash_fault
  858. b .ret_from_except
  859. /* here we have a segment miss */
  860. do_ste_alloc:
  861. bl .ste_allocate /* try to insert stab entry */
  862. cmpdi r3,0
  863. bne- handle_page_fault
  864. b fast_exception_return
  865. /*
  866. * r13 points to the PACA, r9 contains the saved CR,
  867. * r11 and r12 contain the saved SRR0 and SRR1.
  868. * r9 - r13 are saved in paca->exslb.
  869. * We assume we aren't going to take any exceptions during this procedure.
  870. * We assume (DAR >> 60) == 0xc.
  871. */
  872. .align 7
  873. _GLOBAL(do_stab_bolted)
  874. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  875. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  876. /* Hash to the primary group */
  877. ld r10,PACASTABVIRT(r13)
  878. mfspr r11,SPRN_DAR
  879. srdi r11,r11,28
  880. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  881. /* Calculate VSID */
  882. /* This is a kernel address, so protovsid = ESID */
  883. ASM_VSID_SCRAMBLE(r11, r9, 256M)
  884. rldic r9,r11,12,16 /* r9 = vsid << 12 */
  885. /* Search the primary group for a free entry */
  886. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  887. andi. r11,r11,0x80
  888. beq 2f
  889. addi r10,r10,16
  890. andi. r11,r10,0x70
  891. bne 1b
  892. /* Stick for only searching the primary group for now. */
  893. /* At least for now, we use a very simple random castout scheme */
  894. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  895. mftb r11
  896. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  897. ori r11,r11,0x10
  898. /* r10 currently points to an ste one past the group of interest */
  899. /* make it point to the randomly selected entry */
  900. subi r10,r10,128
  901. or r10,r10,r11 /* r10 is the entry to invalidate */
  902. isync /* mark the entry invalid */
  903. ld r11,0(r10)
  904. rldicl r11,r11,56,1 /* clear the valid bit */
  905. rotldi r11,r11,8
  906. std r11,0(r10)
  907. sync
  908. clrrdi r11,r11,28 /* Get the esid part of the ste */
  909. slbie r11
  910. 2: std r9,8(r10) /* Store the vsid part of the ste */
  911. eieio
  912. mfspr r11,SPRN_DAR /* Get the new esid */
  913. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  914. ori r11,r11,0x90 /* Turn on valid and kp */
  915. std r11,0(r10) /* Put new entry back into the stab */
  916. sync
  917. /* All done -- return from exception. */
  918. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  919. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  920. andi. r10,r12,MSR_RI
  921. beq- unrecov_slb
  922. mtcrf 0x80,r9 /* restore CR */
  923. mfmsr r10
  924. clrrdi r10,r10,2
  925. mtmsrd r10,1
  926. mtspr SPRN_SRR0,r11
  927. mtspr SPRN_SRR1,r12
  928. ld r9,PACA_EXSLB+EX_R9(r13)
  929. ld r10,PACA_EXSLB+EX_R10(r13)
  930. ld r11,PACA_EXSLB+EX_R11(r13)
  931. ld r12,PACA_EXSLB+EX_R12(r13)
  932. ld r13,PACA_EXSLB+EX_R13(r13)
  933. rfid
  934. b . /* prevent speculative execution */
  935. /*
  936. * Space for CPU0's segment table.
  937. *
  938. * On iSeries, the hypervisor must fill in at least one entry before
  939. * we get control (with relocate on). The address is given to the hv
  940. * as a page number (see xLparMap below), so this must be at a
  941. * fixed address (the linker can't compute (u64)&initial_stab >>
  942. * PAGE_SHIFT).
  943. */
  944. . = STAB0_OFFSET /* 0x6000 */
  945. .globl initial_stab
  946. initial_stab:
  947. .space 4096
  948. #ifdef CONFIG_PPC_PSERIES
  949. /*
  950. * Data area reserved for FWNMI option.
  951. * This address (0x7000) is fixed by the RPA.
  952. */
  953. .= 0x7000
  954. .globl fwnmi_data_area
  955. fwnmi_data_area:
  956. #endif /* CONFIG_PPC_PSERIES */
  957. /* iSeries does not use the FWNMI stuff, so it is safe to put
  958. * this here, even if we later allow kernels that will boot on
  959. * both pSeries and iSeries */
  960. #ifdef CONFIG_PPC_ISERIES
  961. . = LPARMAP_PHYS
  962. .globl xLparMap
  963. xLparMap:
  964. .quad HvEsidsToMap /* xNumberEsids */
  965. .quad HvRangesToMap /* xNumberRanges */
  966. .quad STAB0_PAGE /* xSegmentTableOffs */
  967. .zero 40 /* xRsvd */
  968. /* xEsids (HvEsidsToMap entries of 2 quads) */
  969. .quad PAGE_OFFSET_ESID /* xKernelEsid */
  970. .quad PAGE_OFFSET_VSID /* xKernelVsid */
  971. .quad VMALLOC_START_ESID /* xKernelEsid */
  972. .quad VMALLOC_START_VSID /* xKernelVsid */
  973. /* xRanges (HvRangesToMap entries of 3 quads) */
  974. .quad HvPagesToMap /* xPages */
  975. .quad 0 /* xOffset */
  976. .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
  977. #endif /* CONFIG_PPC_ISERIES */
  978. #ifdef CONFIG_PPC_PSERIES
  979. . = 0x8000
  980. #endif /* CONFIG_PPC_PSERIES */
  981. /*
  982. * On pSeries and most other platforms, secondary processors spin
  983. * in the following code.
  984. * At entry, r3 = this processor's number (physical cpu id)
  985. */
  986. _GLOBAL(generic_secondary_smp_init)
  987. mr r24,r3
  988. /* turn on 64-bit mode */
  989. bl .enable_64b_mode
  990. /* Set up a paca value for this processor. Since we have the
  991. * physical cpu id in r24, we need to search the pacas to find
  992. * which logical id maps to our physical one.
  993. */
  994. LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
  995. li r5,0 /* logical cpu id */
  996. 1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
  997. cmpw r6,r24 /* Compare to our id */
  998. beq 2f
  999. addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
  1000. addi r5,r5,1
  1001. cmpwi r5,NR_CPUS
  1002. blt 1b
  1003. mr r3,r24 /* not found, copy phys to r3 */
  1004. b .kexec_wait /* next kernel might do better */
  1005. 2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  1006. /* From now on, r24 is expected to be logical cpuid */
  1007. mr r24,r5
  1008. 3: HMT_LOW
  1009. lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
  1010. /* start. */
  1011. sync
  1012. #ifndef CONFIG_SMP
  1013. b 3b /* Never go on non-SMP */
  1014. #else
  1015. cmpwi 0,r23,0
  1016. beq 3b /* Loop until told to go */
  1017. /* See if we need to call a cpu state restore handler */
  1018. LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
  1019. ld r23,0(r23)
  1020. ld r23,CPU_SPEC_RESTORE(r23)
  1021. cmpdi 0,r23,0
  1022. beq 4f
  1023. ld r23,0(r23)
  1024. mtctr r23
  1025. bctrl
  1026. 4: /* Create a temp kernel stack for use before relocation is on. */
  1027. ld r1,PACAEMERGSP(r13)
  1028. subi r1,r1,STACK_FRAME_OVERHEAD
  1029. b __secondary_start
  1030. #endif
  1031. _STATIC(__mmu_off)
  1032. mfmsr r3
  1033. andi. r0,r3,MSR_IR|MSR_DR
  1034. beqlr
  1035. andc r3,r3,r0
  1036. mtspr SPRN_SRR0,r4
  1037. mtspr SPRN_SRR1,r3
  1038. sync
  1039. rfid
  1040. b . /* prevent speculative execution */
  1041. /*
  1042. * Here is our main kernel entry point. We support currently 2 kind of entries
  1043. * depending on the value of r5.
  1044. *
  1045. * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
  1046. * in r3...r7
  1047. *
  1048. * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
  1049. * DT block, r4 is a physical pointer to the kernel itself
  1050. *
  1051. */
  1052. _GLOBAL(__start_initialization_multiplatform)
  1053. /*
  1054. * Are we booted from a PROM Of-type client-interface ?
  1055. */
  1056. cmpldi cr0,r5,0
  1057. beq 1f
  1058. b .__boot_from_prom /* yes -> prom */
  1059. 1:
  1060. /* Save parameters */
  1061. mr r31,r3
  1062. mr r30,r4
  1063. /* Make sure we are running in 64 bits mode */
  1064. bl .enable_64b_mode
  1065. /* Setup some critical 970 SPRs before switching MMU off */
  1066. mfspr r0,SPRN_PVR
  1067. srwi r0,r0,16
  1068. cmpwi r0,0x39 /* 970 */
  1069. beq 1f
  1070. cmpwi r0,0x3c /* 970FX */
  1071. beq 1f
  1072. cmpwi r0,0x44 /* 970MP */
  1073. beq 1f
  1074. cmpwi r0,0x45 /* 970GX */
  1075. bne 2f
  1076. 1: bl .__cpu_preinit_ppc970
  1077. 2:
  1078. /* Switch off MMU if not already */
  1079. LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
  1080. add r4,r4,r30
  1081. bl .__mmu_off
  1082. b .__after_prom_start
  1083. _INIT_STATIC(__boot_from_prom)
  1084. /* Save parameters */
  1085. mr r31,r3
  1086. mr r30,r4
  1087. mr r29,r5
  1088. mr r28,r6
  1089. mr r27,r7
  1090. /*
  1091. * Align the stack to 16-byte boundary
  1092. * Depending on the size and layout of the ELF sections in the initial
  1093. * boot binary, the stack pointer will be unalignet on PowerMac
  1094. */
  1095. rldicr r1,r1,0,59
  1096. /* Make sure we are running in 64 bits mode */
  1097. bl .enable_64b_mode
  1098. /* put a relocation offset into r3 */
  1099. bl .reloc_offset
  1100. LOAD_REG_IMMEDIATE(r2,__toc_start)
  1101. addi r2,r2,0x4000
  1102. addi r2,r2,0x4000
  1103. /* Relocate the TOC from a virt addr to a real addr */
  1104. add r2,r2,r3
  1105. /* Restore parameters */
  1106. mr r3,r31
  1107. mr r4,r30
  1108. mr r5,r29
  1109. mr r6,r28
  1110. mr r7,r27
  1111. /* Do all of the interaction with OF client interface */
  1112. bl .prom_init
  1113. /* We never return */
  1114. trap
  1115. _STATIC(__after_prom_start)
  1116. /*
  1117. * We need to run with __start at physical address PHYSICAL_START.
  1118. * This will leave some code in the first 256B of
  1119. * real memory, which are reserved for software use.
  1120. * The remainder of the first page is loaded with the fixed
  1121. * interrupt vectors. The next two pages are filled with
  1122. * unknown exception placeholders.
  1123. *
  1124. * Note: This process overwrites the OF exception vectors.
  1125. * r26 == relocation offset
  1126. * r27 == KERNELBASE
  1127. */
  1128. bl .reloc_offset
  1129. mr r26,r3
  1130. LOAD_REG_IMMEDIATE(r27, KERNELBASE)
  1131. LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
  1132. // XXX FIXME: Use phys returned by OF (r30)
  1133. add r4,r27,r26 /* source addr */
  1134. /* current address of _start */
  1135. /* i.e. where we are running */
  1136. /* the source addr */
  1137. cmpdi r4,0 /* In some cases the loader may */
  1138. bne 1f
  1139. b .start_here_multiplatform /* have already put us at zero */
  1140. /* so we can skip the copy. */
  1141. 1: LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
  1142. sub r5,r5,r27
  1143. li r6,0x100 /* Start offset, the first 0x100 */
  1144. /* bytes were copied earlier. */
  1145. bl .copy_and_flush /* copy the first n bytes */
  1146. /* this includes the code being */
  1147. /* executed here. */
  1148. LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
  1149. mtctr r0 /* that we just made/relocated */
  1150. bctr
  1151. 4: LOAD_REG_IMMEDIATE(r5,klimit)
  1152. add r5,r5,r26
  1153. ld r5,0(r5) /* get the value of klimit */
  1154. sub r5,r5,r27
  1155. bl .copy_and_flush /* copy the rest */
  1156. b .start_here_multiplatform
  1157. /*
  1158. * Copy routine used to copy the kernel to start at physical address 0
  1159. * and flush and invalidate the caches as needed.
  1160. * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
  1161. * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
  1162. *
  1163. * Note: this routine *only* clobbers r0, r6 and lr
  1164. */
  1165. _GLOBAL(copy_and_flush)
  1166. addi r5,r5,-8
  1167. addi r6,r6,-8
  1168. 4: li r0,8 /* Use the smallest common */
  1169. /* denominator cache line */
  1170. /* size. This results in */
  1171. /* extra cache line flushes */
  1172. /* but operation is correct. */
  1173. /* Can't get cache line size */
  1174. /* from NACA as it is being */
  1175. /* moved too. */
  1176. mtctr r0 /* put # words/line in ctr */
  1177. 3: addi r6,r6,8 /* copy a cache line */
  1178. ldx r0,r6,r4
  1179. stdx r0,r6,r3
  1180. bdnz 3b
  1181. dcbst r6,r3 /* write it to memory */
  1182. sync
  1183. icbi r6,r3 /* flush the icache line */
  1184. cmpld 0,r6,r5
  1185. blt 4b
  1186. sync
  1187. addi r5,r5,8
  1188. addi r6,r6,8
  1189. blr
  1190. .align 8
  1191. copy_to_here:
  1192. #ifdef CONFIG_SMP
  1193. #ifdef CONFIG_PPC_PMAC
  1194. /*
  1195. * On PowerMac, secondary processors starts from the reset vector, which
  1196. * is temporarily turned into a call to one of the functions below.
  1197. */
  1198. .section ".text";
  1199. .align 2 ;
  1200. .globl __secondary_start_pmac_0
  1201. __secondary_start_pmac_0:
  1202. /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
  1203. li r24,0
  1204. b 1f
  1205. li r24,1
  1206. b 1f
  1207. li r24,2
  1208. b 1f
  1209. li r24,3
  1210. 1:
  1211. _GLOBAL(pmac_secondary_start)
  1212. /* turn on 64-bit mode */
  1213. bl .enable_64b_mode
  1214. /* Copy some CPU settings from CPU 0 */
  1215. bl .__restore_cpu_ppc970
  1216. /* pSeries do that early though I don't think we really need it */
  1217. mfmsr r3
  1218. ori r3,r3,MSR_RI
  1219. mtmsrd r3 /* RI on */
  1220. /* Set up a paca value for this processor. */
  1221. LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
  1222. mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
  1223. add r13,r13,r4 /* for this processor. */
  1224. mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
  1225. /* Create a temp kernel stack for use before relocation is on. */
  1226. ld r1,PACAEMERGSP(r13)
  1227. subi r1,r1,STACK_FRAME_OVERHEAD
  1228. b __secondary_start
  1229. #endif /* CONFIG_PPC_PMAC */
  1230. /*
  1231. * This function is called after the master CPU has released the
  1232. * secondary processors. The execution environment is relocation off.
  1233. * The paca for this processor has the following fields initialized at
  1234. * this point:
  1235. * 1. Processor number
  1236. * 2. Segment table pointer (virtual address)
  1237. * On entry the following are set:
  1238. * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
  1239. * r24 = cpu# (in Linux terms)
  1240. * r13 = paca virtual address
  1241. * SPRG3 = paca virtual address
  1242. */
  1243. .globl __secondary_start
  1244. __secondary_start:
  1245. /* Set thread priority to MEDIUM */
  1246. HMT_MEDIUM
  1247. /* Load TOC */
  1248. ld r2,PACATOC(r13)
  1249. /* Do early setup for that CPU (stab, slb, hash table pointer) */
  1250. bl .early_setup_secondary
  1251. /* Initialize the kernel stack. Just a repeat for iSeries. */
  1252. LOAD_REG_ADDR(r3, current_set)
  1253. sldi r28,r24,3 /* get current_set[cpu#] */
  1254. ldx r1,r3,r28
  1255. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  1256. std r1,PACAKSAVE(r13)
  1257. /* Clear backchain so we get nice backtraces */
  1258. li r7,0
  1259. mtlr r7
  1260. /* enable MMU and jump to start_secondary */
  1261. LOAD_REG_ADDR(r3, .start_secondary_prolog)
  1262. LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
  1263. #ifdef CONFIG_PPC_ISERIES
  1264. BEGIN_FW_FTR_SECTION
  1265. ori r4,r4,MSR_EE
  1266. li r8,1
  1267. stb r8,PACAHARDIRQEN(r13)
  1268. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  1269. #endif
  1270. BEGIN_FW_FTR_SECTION
  1271. stb r7,PACAHARDIRQEN(r13)
  1272. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  1273. stb r7,PACASOFTIRQEN(r13)
  1274. mtspr SPRN_SRR0,r3
  1275. mtspr SPRN_SRR1,r4
  1276. rfid
  1277. b . /* prevent speculative execution */
  1278. /*
  1279. * Running with relocation on at this point. All we want to do is
  1280. * zero the stack back-chain pointer before going into C code.
  1281. */
  1282. _GLOBAL(start_secondary_prolog)
  1283. li r3,0
  1284. std r3,0(r1) /* Zero the stack frame pointer */
  1285. bl .start_secondary
  1286. b .
  1287. #endif
  1288. /*
  1289. * This subroutine clobbers r11 and r12
  1290. */
  1291. _GLOBAL(enable_64b_mode)
  1292. mfmsr r11 /* grab the current MSR */
  1293. li r12,1
  1294. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  1295. or r11,r11,r12
  1296. li r12,1
  1297. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  1298. or r11,r11,r12
  1299. mtmsrd r11
  1300. isync
  1301. blr
  1302. /*
  1303. * This is where the main kernel code starts.
  1304. */
  1305. _INIT_STATIC(start_here_multiplatform)
  1306. /* get a new offset, now that the kernel has moved. */
  1307. bl .reloc_offset
  1308. mr r26,r3
  1309. /* Clear out the BSS. It may have been done in prom_init,
  1310. * already but that's irrelevant since prom_init will soon
  1311. * be detached from the kernel completely. Besides, we need
  1312. * to clear it now for kexec-style entry.
  1313. */
  1314. LOAD_REG_IMMEDIATE(r11,__bss_stop)
  1315. LOAD_REG_IMMEDIATE(r8,__bss_start)
  1316. sub r11,r11,r8 /* bss size */
  1317. addi r11,r11,7 /* round up to an even double word */
  1318. rldicl. r11,r11,61,3 /* shift right by 3 */
  1319. beq 4f
  1320. addi r8,r8,-8
  1321. li r0,0
  1322. mtctr r11 /* zero this many doublewords */
  1323. 3: stdu r0,8(r8)
  1324. bdnz 3b
  1325. 4:
  1326. mfmsr r6
  1327. ori r6,r6,MSR_RI
  1328. mtmsrd r6 /* RI on */
  1329. /* The following gets the stack and TOC set up with the regs */
  1330. /* pointing to the real addr of the kernel stack. This is */
  1331. /* all done to support the C function call below which sets */
  1332. /* up the htab. This is done because we have relocated the */
  1333. /* kernel but are still running in real mode. */
  1334. LOAD_REG_IMMEDIATE(r3,init_thread_union)
  1335. add r3,r3,r26
  1336. /* set up a stack pointer (physical address) */
  1337. addi r1,r3,THREAD_SIZE
  1338. li r0,0
  1339. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1340. /* set up the TOC (physical address) */
  1341. LOAD_REG_IMMEDIATE(r2,__toc_start)
  1342. addi r2,r2,0x4000
  1343. addi r2,r2,0x4000
  1344. add r2,r2,r26
  1345. /* Do very early kernel initializations, including initial hash table,
  1346. * stab and slb setup before we turn on relocation. */
  1347. /* Restore parameters passed from prom_init/kexec */
  1348. mr r3,r31
  1349. bl .early_setup
  1350. LOAD_REG_IMMEDIATE(r3, .start_here_common)
  1351. LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
  1352. mtspr SPRN_SRR0,r3
  1353. mtspr SPRN_SRR1,r4
  1354. rfid
  1355. b . /* prevent speculative execution */
  1356. /* This is where all platforms converge execution */
  1357. _INIT_GLOBAL(start_here_common)
  1358. /* relocation is on at this point */
  1359. /* The following code sets up the SP and TOC now that we are */
  1360. /* running with translation enabled. */
  1361. LOAD_REG_IMMEDIATE(r3,init_thread_union)
  1362. /* set up the stack */
  1363. addi r1,r3,THREAD_SIZE
  1364. li r0,0
  1365. stdu r0,-STACK_FRAME_OVERHEAD(r1)
  1366. /* Load the TOC */
  1367. ld r2,PACATOC(r13)
  1368. std r1,PACAKSAVE(r13)
  1369. bl .setup_system
  1370. /* Load up the kernel context */
  1371. 5:
  1372. li r5,0
  1373. stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
  1374. #ifdef CONFIG_PPC_ISERIES
  1375. BEGIN_FW_FTR_SECTION
  1376. mfmsr r5
  1377. ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/
  1378. mtmsrd r5
  1379. li r5,1
  1380. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  1381. #endif
  1382. stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */
  1383. bl .start_kernel
  1384. /* Not reached */
  1385. BUG_OPCODE
  1386. /*
  1387. * We put a few things here that have to be page-aligned.
  1388. * This stuff goes at the beginning of the bss, which is page-aligned.
  1389. */
  1390. .section ".bss"
  1391. .align PAGE_SHIFT
  1392. .globl empty_zero_page
  1393. empty_zero_page:
  1394. .space PAGE_SIZE
  1395. .globl swapper_pg_dir
  1396. swapper_pg_dir:
  1397. .space PGD_TABLE_SIZE