exceptions-64s.S 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. /*
  2. * This file contains the 64-bit "server" PowerPC variant
  3. * of the low level exception handling including exception
  4. * vectors, exception return, part of the slb and stab
  5. * handling and other fixed offset specific things.
  6. *
  7. * This file is meant to be #included from head_64.S due to
  8. * position dependent assembly.
  9. *
  10. * Most of this originates from head_64.S and thus has the same
  11. * copyright history.
  12. *
  13. */
  14. #include <asm/hw_irq.h>
  15. #include <asm/exception-64s.h>
  16. #include <asm/ptrace.h>
  17. /*
  18. * We layout physical memory as follows:
  19. * 0x0000 - 0x00ff : Secondary processor spin code
  20. * 0x0100 - 0x17ff : pSeries Interrupt prologs
  21. * 0x1800 - 0x4000 : interrupt support common interrupt prologs
  22. * 0x4000 - 0x5fff : pSeries interrupts with IR=1,DR=1
  23. * 0x6000 - 0x6fff : more interrupt support including for IR=1,DR=1
  24. * 0x7000 - 0x7fff : FWNMI data area
  25. * 0x8000 - 0x8fff : Initial (CPU0) segment table
  26. * 0x9000 - : Early init and support code
  27. */
  28. /* Syscall routine is used twice, in reloc-off and reloc-on paths */
  29. #define SYSCALL_PSERIES_1 \
  30. BEGIN_FTR_SECTION \
  31. cmpdi r0,0x1ebe ; \
  32. beq- 1f ; \
  33. END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
  34. mr r9,r13 ; \
  35. GET_PACA(r13) ; \
  36. mfspr r11,SPRN_SRR0 ; \
  37. 0:
  38. #define SYSCALL_PSERIES_2_RFID \
  39. mfspr r12,SPRN_SRR1 ; \
  40. ld r10,PACAKBASE(r13) ; \
  41. LOAD_HANDLER(r10, system_call_entry) ; \
  42. mtspr SPRN_SRR0,r10 ; \
  43. ld r10,PACAKMSR(r13) ; \
  44. mtspr SPRN_SRR1,r10 ; \
  45. rfid ; \
  46. b . ; /* prevent speculative execution */
  47. #define SYSCALL_PSERIES_3 \
  48. /* Fast LE/BE switch system call */ \
  49. 1: mfspr r12,SPRN_SRR1 ; \
  50. xori r12,r12,MSR_LE ; \
  51. mtspr SPRN_SRR1,r12 ; \
  52. rfid ; /* return to userspace */ \
  53. b . ; /* prevent speculative execution */
  54. #if defined(CONFIG_RELOCATABLE)
  55. /*
  56. * We can't branch directly; in the direct case we use LR
  57. * and system_call_entry restores LR. (We thus need to move
  58. * LR to r10 in the RFID case too.)
  59. */
  60. #define SYSCALL_PSERIES_2_DIRECT \
  61. mflr r10 ; \
  62. ld r12,PACAKBASE(r13) ; \
  63. LOAD_HANDLER(r12, system_call_entry_direct) ; \
  64. mtctr r12 ; \
  65. mfspr r12,SPRN_SRR1 ; \
  66. /* Re-use of r13... No spare regs to do this */ \
  67. li r13,MSR_RI ; \
  68. mtmsrd r13,1 ; \
  69. GET_PACA(r13) ; /* get r13 back */ \
  70. bctr ;
  71. #else
  72. /* We can branch directly */
  73. #define SYSCALL_PSERIES_2_DIRECT \
  74. mfspr r12,SPRN_SRR1 ; \
  75. li r10,MSR_RI ; \
  76. mtmsrd r10,1 ; /* Set RI (EE=0) */ \
  77. b system_call_entry_direct ;
  78. #endif
  79. /*
  80. * This is the start of the interrupt handlers for pSeries
  81. * This code runs with relocation off.
  82. * Code from here to __end_interrupts gets copied down to real
  83. * address 0x100 when we are running a relocatable kernel.
  84. * Therefore any relative branches in this section must only
  85. * branch to labels in this section.
  86. */
  87. . = 0x100
  88. .globl __start_interrupts
  89. __start_interrupts:
  90. .globl system_reset_pSeries;
  91. system_reset_pSeries:
  92. HMT_MEDIUM_PPR_DISCARD
  93. SET_SCRATCH0(r13)
  94. #ifdef CONFIG_PPC_P7_NAP
  95. BEGIN_FTR_SECTION
  96. /* Running native on arch 2.06 or later, check if we are
  97. * waking up from nap. We only handle no state loss and
  98. * supervisor state loss. We do -not- handle hypervisor
  99. * state loss at this time.
  100. */
  101. mfspr r13,SPRN_SRR1
  102. rlwinm. r13,r13,47-31,30,31
  103. beq 9f
  104. /* waking up from powersave (nap) state */
  105. cmpwi cr1,r13,2
  106. /* Total loss of HV state is fatal, we could try to use the
  107. * PIR to locate a PACA, then use an emergency stack etc...
  108. * OPAL v3 based powernv platforms have new idle states
  109. * which fall in this catagory.
  110. */
  111. bgt cr1,8f
  112. GET_PACA(r13)
  113. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  114. li r0,KVM_HWTHREAD_IN_KERNEL
  115. stb r0,HSTATE_HWTHREAD_STATE(r13)
  116. /* Order setting hwthread_state vs. testing hwthread_req */
  117. sync
  118. lbz r0,HSTATE_HWTHREAD_REQ(r13)
  119. cmpwi r0,0
  120. beq 1f
  121. b kvm_start_guest
  122. 1:
  123. #endif
  124. beq cr1,2f
  125. b power7_wakeup_noloss
  126. 2: b power7_wakeup_loss
  127. /* Fast Sleep wakeup on PowerNV */
  128. 8: GET_PACA(r13)
  129. b power7_wakeup_tb_loss
  130. 9:
  131. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  132. #endif /* CONFIG_PPC_P7_NAP */
  133. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
  134. NOTEST, 0x100)
  135. . = 0x200
  136. machine_check_pSeries_1:
  137. /* This is moved out of line as it can be patched by FW, but
  138. * some code path might still want to branch into the original
  139. * vector
  140. */
  141. HMT_MEDIUM_PPR_DISCARD
  142. SET_SCRATCH0(r13) /* save r13 */
  143. #ifdef CONFIG_PPC_P7_NAP
  144. BEGIN_FTR_SECTION
  145. /* Running native on arch 2.06 or later, check if we are
  146. * waking up from nap. We only handle no state loss and
  147. * supervisor state loss. We do -not- handle hypervisor
  148. * state loss at this time.
  149. */
  150. mfspr r13,SPRN_SRR1
  151. rlwinm. r13,r13,47-31,30,31
  152. OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
  153. beq 9f
  154. mfspr r13,SPRN_SRR1
  155. rlwinm. r13,r13,47-31,30,31
  156. /* waking up from powersave (nap) state */
  157. cmpwi cr1,r13,2
  158. /* Total loss of HV state is fatal. let's just stay stuck here */
  159. OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
  160. bgt cr1,.
  161. 9:
  162. OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
  163. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  164. #endif /* CONFIG_PPC_P7_NAP */
  165. EXCEPTION_PROLOG_0(PACA_EXMC)
  166. BEGIN_FTR_SECTION
  167. b machine_check_pSeries_early
  168. FTR_SECTION_ELSE
  169. b machine_check_pSeries_0
  170. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  171. . = 0x300
  172. .globl data_access_pSeries
  173. data_access_pSeries:
  174. HMT_MEDIUM_PPR_DISCARD
  175. SET_SCRATCH0(r13)
  176. BEGIN_FTR_SECTION
  177. b data_access_check_stab
  178. data_access_not_stab:
  179. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
  180. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD,
  181. KVMTEST, 0x300)
  182. . = 0x380
  183. .globl data_access_slb_pSeries
  184. data_access_slb_pSeries:
  185. HMT_MEDIUM_PPR_DISCARD
  186. SET_SCRATCH0(r13)
  187. EXCEPTION_PROLOG_0(PACA_EXSLB)
  188. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x380)
  189. std r3,PACA_EXSLB+EX_R3(r13)
  190. mfspr r3,SPRN_DAR
  191. #ifdef __DISABLED__
  192. /* Keep that around for when we re-implement dynamic VSIDs */
  193. cmpdi r3,0
  194. bge slb_miss_user_pseries
  195. #endif /* __DISABLED__ */
  196. mfspr r12,SPRN_SRR1
  197. #ifndef CONFIG_RELOCATABLE
  198. b slb_miss_realmode
  199. #else
  200. /*
  201. * We can't just use a direct branch to slb_miss_realmode
  202. * because the distance from here to there depends on where
  203. * the kernel ends up being put.
  204. */
  205. mfctr r11
  206. ld r10,PACAKBASE(r13)
  207. LOAD_HANDLER(r10, slb_miss_realmode)
  208. mtctr r10
  209. bctr
  210. #endif
  211. STD_EXCEPTION_PSERIES(0x400, 0x400, instruction_access)
  212. . = 0x480
  213. .globl instruction_access_slb_pSeries
  214. instruction_access_slb_pSeries:
  215. HMT_MEDIUM_PPR_DISCARD
  216. SET_SCRATCH0(r13)
  217. EXCEPTION_PROLOG_0(PACA_EXSLB)
  218. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
  219. std r3,PACA_EXSLB+EX_R3(r13)
  220. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  221. #ifdef __DISABLED__
  222. /* Keep that around for when we re-implement dynamic VSIDs */
  223. cmpdi r3,0
  224. bge slb_miss_user_pseries
  225. #endif /* __DISABLED__ */
  226. mfspr r12,SPRN_SRR1
  227. #ifndef CONFIG_RELOCATABLE
  228. b slb_miss_realmode
  229. #else
  230. mfctr r11
  231. ld r10,PACAKBASE(r13)
  232. LOAD_HANDLER(r10, slb_miss_realmode)
  233. mtctr r10
  234. bctr
  235. #endif
  236. /* We open code these as we can't have a ". = x" (even with
  237. * x = "." within a feature section
  238. */
  239. . = 0x500;
  240. .globl hardware_interrupt_pSeries;
  241. .globl hardware_interrupt_hv;
  242. hardware_interrupt_pSeries:
  243. hardware_interrupt_hv:
  244. HMT_MEDIUM_PPR_DISCARD
  245. BEGIN_FTR_SECTION
  246. _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt,
  247. EXC_HV, SOFTEN_TEST_HV)
  248. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
  249. FTR_SECTION_ELSE
  250. _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt,
  251. EXC_STD, SOFTEN_TEST_HV_201)
  252. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
  253. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  254. STD_EXCEPTION_PSERIES(0x600, 0x600, alignment)
  255. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x600)
  256. STD_EXCEPTION_PSERIES(0x700, 0x700, program_check)
  257. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x700)
  258. STD_EXCEPTION_PSERIES(0x800, 0x800, fp_unavailable)
  259. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x800)
  260. . = 0x900
  261. .globl decrementer_pSeries
  262. decrementer_pSeries:
  263. _MASKABLE_EXCEPTION_PSERIES(0x900, decrementer, EXC_STD, SOFTEN_TEST_PR)
  264. STD_EXCEPTION_HV(0x980, 0x982, hdecrementer)
  265. MASKABLE_EXCEPTION_PSERIES(0xa00, 0xa00, doorbell_super)
  266. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xa00)
  267. STD_EXCEPTION_PSERIES(0xb00, 0xb00, trap_0b)
  268. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xb00)
  269. . = 0xc00
  270. .globl system_call_pSeries
  271. system_call_pSeries:
  272. HMT_MEDIUM
  273. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  274. SET_SCRATCH0(r13)
  275. GET_PACA(r13)
  276. std r9,PACA_EXGEN+EX_R9(r13)
  277. std r10,PACA_EXGEN+EX_R10(r13)
  278. mfcr r9
  279. KVMTEST(0xc00)
  280. GET_SCRATCH0(r13)
  281. #endif
  282. SYSCALL_PSERIES_1
  283. SYSCALL_PSERIES_2_RFID
  284. SYSCALL_PSERIES_3
  285. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
  286. STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
  287. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
  288. /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
  289. * out of line to handle them
  290. */
  291. . = 0xe00
  292. hv_data_storage_trampoline:
  293. SET_SCRATCH0(r13)
  294. EXCEPTION_PROLOG_0(PACA_EXGEN)
  295. b h_data_storage_hv
  296. . = 0xe20
  297. hv_instr_storage_trampoline:
  298. SET_SCRATCH0(r13)
  299. EXCEPTION_PROLOG_0(PACA_EXGEN)
  300. b h_instr_storage_hv
  301. . = 0xe40
  302. emulation_assist_trampoline:
  303. SET_SCRATCH0(r13)
  304. EXCEPTION_PROLOG_0(PACA_EXGEN)
  305. b emulation_assist_hv
  306. . = 0xe60
  307. hv_exception_trampoline:
  308. SET_SCRATCH0(r13)
  309. EXCEPTION_PROLOG_0(PACA_EXGEN)
  310. b hmi_exception_hv
  311. . = 0xe80
  312. hv_doorbell_trampoline:
  313. SET_SCRATCH0(r13)
  314. EXCEPTION_PROLOG_0(PACA_EXGEN)
  315. b h_doorbell_hv
  316. /* We need to deal with the Altivec unavailable exception
  317. * here which is at 0xf20, thus in the middle of the
  318. * prolog code of the PerformanceMonitor one. A little
  319. * trickery is thus necessary
  320. */
  321. . = 0xf00
  322. performance_monitor_pseries_trampoline:
  323. SET_SCRATCH0(r13)
  324. EXCEPTION_PROLOG_0(PACA_EXGEN)
  325. b performance_monitor_pSeries
  326. . = 0xf20
  327. altivec_unavailable_pseries_trampoline:
  328. SET_SCRATCH0(r13)
  329. EXCEPTION_PROLOG_0(PACA_EXGEN)
  330. b altivec_unavailable_pSeries
  331. . = 0xf40
  332. vsx_unavailable_pseries_trampoline:
  333. SET_SCRATCH0(r13)
  334. EXCEPTION_PROLOG_0(PACA_EXGEN)
  335. b vsx_unavailable_pSeries
  336. . = 0xf60
  337. facility_unavailable_trampoline:
  338. SET_SCRATCH0(r13)
  339. EXCEPTION_PROLOG_0(PACA_EXGEN)
  340. b facility_unavailable_pSeries
  341. . = 0xf80
  342. hv_facility_unavailable_trampoline:
  343. SET_SCRATCH0(r13)
  344. EXCEPTION_PROLOG_0(PACA_EXGEN)
  345. b facility_unavailable_hv
  346. #ifdef CONFIG_CBE_RAS
  347. STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
  348. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1202)
  349. #endif /* CONFIG_CBE_RAS */
  350. STD_EXCEPTION_PSERIES(0x1300, 0x1300, instruction_breakpoint)
  351. KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
  352. . = 0x1500
  353. .global denorm_exception_hv
  354. denorm_exception_hv:
  355. HMT_MEDIUM_PPR_DISCARD
  356. mtspr SPRN_SPRG_HSCRATCH0,r13
  357. EXCEPTION_PROLOG_0(PACA_EXGEN)
  358. EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
  359. #ifdef CONFIG_PPC_DENORMALISATION
  360. mfspr r10,SPRN_HSRR1
  361. mfspr r11,SPRN_HSRR0 /* save HSRR0 */
  362. andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
  363. addi r11,r11,-4 /* HSRR0 is next instruction */
  364. bne+ denorm_assist
  365. #endif
  366. KVMTEST(0x1500)
  367. EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
  368. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x1500)
  369. #ifdef CONFIG_CBE_RAS
  370. STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
  371. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1602)
  372. #endif /* CONFIG_CBE_RAS */
  373. STD_EXCEPTION_PSERIES(0x1700, 0x1700, altivec_assist)
  374. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x1700)
  375. #ifdef CONFIG_CBE_RAS
  376. STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
  377. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
  378. #else
  379. . = 0x1800
  380. #endif /* CONFIG_CBE_RAS */
  381. /*** Out of line interrupts support ***/
  382. .align 7
  383. /* moved from 0x200 */
  384. machine_check_pSeries_early:
  385. BEGIN_FTR_SECTION
  386. EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
  387. /*
  388. * Register contents:
  389. * R13 = PACA
  390. * R9 = CR
  391. * Original R9 to R13 is saved on PACA_EXMC
  392. *
  393. * Switch to mc_emergency stack and handle re-entrancy (we limit
  394. * the nested MCE upto level 4 to avoid stack overflow).
  395. * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
  396. *
  397. * We use paca->in_mce to check whether this is the first entry or
  398. * nested machine check. We increment paca->in_mce to track nested
  399. * machine checks.
  400. *
  401. * If this is the first entry then set stack pointer to
  402. * paca->mc_emergency_sp, otherwise r1 is already pointing to
  403. * stack frame on mc_emergency stack.
  404. *
  405. * NOTE: We are here with MSR_ME=0 (off), which means we risk a
  406. * checkstop if we get another machine check exception before we do
  407. * rfid with MSR_ME=1.
  408. */
  409. mr r11,r1 /* Save r1 */
  410. lhz r10,PACA_IN_MCE(r13)
  411. cmpwi r10,0 /* Are we in nested machine check */
  412. bne 0f /* Yes, we are. */
  413. /* First machine check entry */
  414. ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
  415. 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  416. addi r10,r10,1 /* increment paca->in_mce */
  417. sth r10,PACA_IN_MCE(r13)
  418. /* Limit nested MCE to level 4 to avoid stack overflow */
  419. cmpwi r10,4
  420. bgt 2f /* Check if we hit limit of 4 */
  421. std r11,GPR1(r1) /* Save r1 on the stack. */
  422. std r11,0(r1) /* make stack chain pointer */
  423. mfspr r11,SPRN_SRR0 /* Save SRR0 */
  424. std r11,_NIP(r1)
  425. mfspr r11,SPRN_SRR1 /* Save SRR1 */
  426. std r11,_MSR(r1)
  427. mfspr r11,SPRN_DAR /* Save DAR */
  428. std r11,_DAR(r1)
  429. mfspr r11,SPRN_DSISR /* Save DSISR */
  430. std r11,_DSISR(r1)
  431. std r9,_CCR(r1) /* Save CR in stackframe */
  432. /* Save r9 through r13 from EXMC save area to stack frame. */
  433. EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
  434. mfmsr r11 /* get MSR value */
  435. ori r11,r11,MSR_ME /* turn on ME bit */
  436. ori r11,r11,MSR_RI /* turn on RI bit */
  437. ld r12,PACAKBASE(r13) /* get high part of &label */
  438. LOAD_HANDLER(r12, machine_check_handle_early)
  439. 1: mtspr SPRN_SRR0,r12
  440. mtspr SPRN_SRR1,r11
  441. rfid
  442. b . /* prevent speculative execution */
  443. 2:
  444. /* Stack overflow. Stay on emergency stack and panic.
  445. * Keep the ME bit off while panic-ing, so that if we hit
  446. * another machine check we checkstop.
  447. */
  448. addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
  449. ld r11,PACAKMSR(r13)
  450. ld r12,PACAKBASE(r13)
  451. LOAD_HANDLER(r12, unrecover_mce)
  452. li r10,MSR_ME
  453. andc r11,r11,r10 /* Turn off MSR_ME */
  454. b 1b
  455. b . /* prevent speculative execution */
  456. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
  457. machine_check_pSeries:
  458. .globl machine_check_fwnmi
  459. machine_check_fwnmi:
  460. HMT_MEDIUM_PPR_DISCARD
  461. SET_SCRATCH0(r13) /* save r13 */
  462. EXCEPTION_PROLOG_0(PACA_EXMC)
  463. machine_check_pSeries_0:
  464. EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST, 0x200)
  465. EXCEPTION_PROLOG_PSERIES_1(machine_check_common, EXC_STD)
  466. KVM_HANDLER_SKIP(PACA_EXMC, EXC_STD, 0x200)
  467. /* moved from 0x300 */
  468. data_access_check_stab:
  469. GET_PACA(r13)
  470. std r9,PACA_EXSLB+EX_R9(r13)
  471. std r10,PACA_EXSLB+EX_R10(r13)
  472. mfspr r10,SPRN_DAR
  473. mfspr r9,SPRN_DSISR
  474. srdi r10,r10,60
  475. rlwimi r10,r9,16,0x20
  476. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  477. lbz r9,HSTATE_IN_GUEST(r13)
  478. rlwimi r10,r9,8,0x300
  479. #endif
  480. mfcr r9
  481. cmpwi r10,0x2c
  482. beq do_stab_bolted_pSeries
  483. mtcrf 0x80,r9
  484. ld r9,PACA_EXSLB+EX_R9(r13)
  485. ld r10,PACA_EXSLB+EX_R10(r13)
  486. b data_access_not_stab
  487. do_stab_bolted_pSeries:
  488. std r11,PACA_EXSLB+EX_R11(r13)
  489. std r12,PACA_EXSLB+EX_R12(r13)
  490. GET_SCRATCH0(r10)
  491. std r10,PACA_EXSLB+EX_R13(r13)
  492. EXCEPTION_PROLOG_PSERIES_1(do_stab_bolted, EXC_STD)
  493. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x300)
  494. KVM_HANDLER_SKIP(PACA_EXSLB, EXC_STD, 0x380)
  495. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x400)
  496. KVM_HANDLER_PR(PACA_EXSLB, EXC_STD, 0x480)
  497. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x900)
  498. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x982)
  499. #ifdef CONFIG_PPC_DENORMALISATION
  500. denorm_assist:
  501. BEGIN_FTR_SECTION
  502. /*
  503. * To denormalise we need to move a copy of the register to itself.
  504. * For POWER6 do that here for all FP regs.
  505. */
  506. mfmsr r10
  507. ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
  508. xori r10,r10,(MSR_FE0|MSR_FE1)
  509. mtmsrd r10
  510. sync
  511. #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
  512. #define FMR4(n) FMR2(n) ; FMR2(n+2)
  513. #define FMR8(n) FMR4(n) ; FMR4(n+4)
  514. #define FMR16(n) FMR8(n) ; FMR8(n+8)
  515. #define FMR32(n) FMR16(n) ; FMR16(n+16)
  516. FMR32(0)
  517. FTR_SECTION_ELSE
  518. /*
  519. * To denormalise we need to move a copy of the register to itself.
  520. * For POWER7 do that here for the first 32 VSX registers only.
  521. */
  522. mfmsr r10
  523. oris r10,r10,MSR_VSX@h
  524. mtmsrd r10
  525. sync
  526. #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
  527. #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
  528. #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
  529. #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
  530. #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
  531. XVCPSGNDP32(0)
  532. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
  533. BEGIN_FTR_SECTION
  534. b denorm_done
  535. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  536. /*
  537. * To denormalise we need to move a copy of the register to itself.
  538. * For POWER8 we need to do that for all 64 VSX registers
  539. */
  540. XVCPSGNDP32(32)
  541. denorm_done:
  542. mtspr SPRN_HSRR0,r11
  543. mtcrf 0x80,r9
  544. ld r9,PACA_EXGEN+EX_R9(r13)
  545. RESTORE_PPR_PACA(PACA_EXGEN, r10)
  546. BEGIN_FTR_SECTION
  547. ld r10,PACA_EXGEN+EX_CFAR(r13)
  548. mtspr SPRN_CFAR,r10
  549. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  550. ld r10,PACA_EXGEN+EX_R10(r13)
  551. ld r11,PACA_EXGEN+EX_R11(r13)
  552. ld r12,PACA_EXGEN+EX_R12(r13)
  553. ld r13,PACA_EXGEN+EX_R13(r13)
  554. HRFID
  555. b .
  556. #endif
  557. .align 7
  558. /* moved from 0xe00 */
  559. STD_EXCEPTION_HV_OOL(0xe02, h_data_storage)
  560. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0xe02)
  561. STD_EXCEPTION_HV_OOL(0xe22, h_instr_storage)
  562. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe22)
  563. STD_EXCEPTION_HV_OOL(0xe42, emulation_assist)
  564. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe42)
  565. STD_EXCEPTION_HV_OOL(0xe62, hmi_exception) /* need to flush cache ? */
  566. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe62)
  567. MASKABLE_EXCEPTION_HV_OOL(0xe82, h_doorbell)
  568. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe82)
  569. /* moved from 0xf00 */
  570. STD_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
  571. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf00)
  572. STD_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
  573. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf20)
  574. STD_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
  575. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf40)
  576. STD_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
  577. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf60)
  578. STD_EXCEPTION_HV_OOL(0xf82, facility_unavailable)
  579. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xf82)
  580. /*
  581. * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
  582. * - If it was a decrementer interrupt, we bump the dec to max and and return.
  583. * - If it was a doorbell we return immediately since doorbells are edge
  584. * triggered and won't automatically refire.
  585. * - else we hard disable and return.
  586. * This is called with r10 containing the value to OR to the paca field.
  587. */
  588. #define MASKED_INTERRUPT(_H) \
  589. masked_##_H##interrupt: \
  590. std r11,PACA_EXGEN+EX_R11(r13); \
  591. lbz r11,PACAIRQHAPPENED(r13); \
  592. or r11,r11,r10; \
  593. stb r11,PACAIRQHAPPENED(r13); \
  594. cmpwi r10,PACA_IRQ_DEC; \
  595. bne 1f; \
  596. lis r10,0x7fff; \
  597. ori r10,r10,0xffff; \
  598. mtspr SPRN_DEC,r10; \
  599. b 2f; \
  600. 1: cmpwi r10,PACA_IRQ_DBELL; \
  601. beq 2f; \
  602. mfspr r10,SPRN_##_H##SRR1; \
  603. rldicl r10,r10,48,1; /* clear MSR_EE */ \
  604. rotldi r10,r10,16; \
  605. mtspr SPRN_##_H##SRR1,r10; \
  606. 2: mtcrf 0x80,r9; \
  607. ld r9,PACA_EXGEN+EX_R9(r13); \
  608. ld r10,PACA_EXGEN+EX_R10(r13); \
  609. ld r11,PACA_EXGEN+EX_R11(r13); \
  610. GET_SCRATCH0(r13); \
  611. ##_H##rfid; \
  612. b .
  613. MASKED_INTERRUPT()
  614. MASKED_INTERRUPT(H)
  615. /*
  616. * Called from arch_local_irq_enable when an interrupt needs
  617. * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
  618. * which kind of interrupt. MSR:EE is already off. We generate a
  619. * stackframe like if a real interrupt had happened.
  620. *
  621. * Note: While MSR:EE is off, we need to make sure that _MSR
  622. * in the generated frame has EE set to 1 or the exception
  623. * handler will not properly re-enable them.
  624. */
  625. _GLOBAL(__replay_interrupt)
  626. /* We are going to jump to the exception common code which
  627. * will retrieve various register values from the PACA which
  628. * we don't give a damn about, so we don't bother storing them.
  629. */
  630. mfmsr r12
  631. mflr r11
  632. mfcr r9
  633. ori r12,r12,MSR_EE
  634. cmpwi r3,0x900
  635. beq decrementer_common
  636. cmpwi r3,0x500
  637. beq hardware_interrupt_common
  638. BEGIN_FTR_SECTION
  639. cmpwi r3,0xe80
  640. beq h_doorbell_common
  641. FTR_SECTION_ELSE
  642. cmpwi r3,0xa00
  643. beq doorbell_super_common
  644. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  645. blr
  646. #ifdef CONFIG_PPC_PSERIES
  647. /*
  648. * Vectors for the FWNMI option. Share common code.
  649. */
  650. .globl system_reset_fwnmi
  651. .align 7
  652. system_reset_fwnmi:
  653. HMT_MEDIUM_PPR_DISCARD
  654. SET_SCRATCH0(r13) /* save r13 */
  655. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
  656. NOTEST, 0x100)
  657. #endif /* CONFIG_PPC_PSERIES */
  658. #ifdef __DISABLED__
  659. /*
  660. * This is used for when the SLB miss handler has to go virtual,
  661. * which doesn't happen for now anymore but will once we re-implement
  662. * dynamic VSIDs for shared page tables
  663. */
  664. slb_miss_user_pseries:
  665. std r10,PACA_EXGEN+EX_R10(r13)
  666. std r11,PACA_EXGEN+EX_R11(r13)
  667. std r12,PACA_EXGEN+EX_R12(r13)
  668. GET_SCRATCH0(r10)
  669. ld r11,PACA_EXSLB+EX_R9(r13)
  670. ld r12,PACA_EXSLB+EX_R3(r13)
  671. std r10,PACA_EXGEN+EX_R13(r13)
  672. std r11,PACA_EXGEN+EX_R9(r13)
  673. std r12,PACA_EXGEN+EX_R3(r13)
  674. clrrdi r12,r13,32
  675. mfmsr r10
  676. mfspr r11,SRR0 /* save SRR0 */
  677. ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
  678. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  679. mtspr SRR0,r12
  680. mfspr r12,SRR1 /* and SRR1 */
  681. mtspr SRR1,r10
  682. rfid
  683. b . /* prevent spec. execution */
  684. #endif /* __DISABLED__ */
  685. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  686. kvmppc_skip_interrupt:
  687. /*
  688. * Here all GPRs are unchanged from when the interrupt happened
  689. * except for r13, which is saved in SPRG_SCRATCH0.
  690. */
  691. mfspr r13, SPRN_SRR0
  692. addi r13, r13, 4
  693. mtspr SPRN_SRR0, r13
  694. GET_SCRATCH0(r13)
  695. rfid
  696. b .
  697. kvmppc_skip_Hinterrupt:
  698. /*
  699. * Here all GPRs are unchanged from when the interrupt happened
  700. * except for r13, which is saved in SPRG_SCRATCH0.
  701. */
  702. mfspr r13, SPRN_HSRR0
  703. addi r13, r13, 4
  704. mtspr SPRN_HSRR0, r13
  705. GET_SCRATCH0(r13)
  706. hrfid
  707. b .
  708. #endif
  709. /*
  710. * Code from here down to __end_handlers is invoked from the
  711. * exception prologs above. Because the prologs assemble the
  712. * addresses of these handlers using the LOAD_HANDLER macro,
  713. * which uses an ori instruction, these handlers must be in
  714. * the first 64k of the kernel image.
  715. */
  716. /*** Common interrupt handlers ***/
  717. STD_EXCEPTION_COMMON(0x100, system_reset, system_reset_exception)
  718. STD_EXCEPTION_COMMON_ASYNC(0x500, hardware_interrupt, do_IRQ)
  719. STD_EXCEPTION_COMMON_ASYNC(0x900, decrementer, timer_interrupt)
  720. STD_EXCEPTION_COMMON(0x980, hdecrementer, hdec_interrupt)
  721. #ifdef CONFIG_PPC_DOORBELL
  722. STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, doorbell_exception)
  723. #else
  724. STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, unknown_exception)
  725. #endif
  726. STD_EXCEPTION_COMMON(0xb00, trap_0b, unknown_exception)
  727. STD_EXCEPTION_COMMON(0xd00, single_step, single_step_exception)
  728. STD_EXCEPTION_COMMON(0xe00, trap_0e, unknown_exception)
  729. STD_EXCEPTION_COMMON(0xe40, emulation_assist, emulation_assist_interrupt)
  730. STD_EXCEPTION_COMMON(0xe60, hmi_exception, unknown_exception)
  731. #ifdef CONFIG_PPC_DOORBELL
  732. STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, doorbell_exception)
  733. #else
  734. STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, unknown_exception)
  735. #endif
  736. STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, performance_monitor_exception)
  737. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, instruction_breakpoint_exception)
  738. STD_EXCEPTION_COMMON(0x1502, denorm, unknown_exception)
  739. #ifdef CONFIG_ALTIVEC
  740. STD_EXCEPTION_COMMON(0x1700, altivec_assist, altivec_assist_exception)
  741. #else
  742. STD_EXCEPTION_COMMON(0x1700, altivec_assist, unknown_exception)
  743. #endif
  744. #ifdef CONFIG_CBE_RAS
  745. STD_EXCEPTION_COMMON(0x1200, cbe_system_error, cbe_system_error_exception)
  746. STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, cbe_maintenance_exception)
  747. STD_EXCEPTION_COMMON(0x1800, cbe_thermal, cbe_thermal_exception)
  748. #endif /* CONFIG_CBE_RAS */
  749. /*
  750. * Relocation-on interrupts: A subset of the interrupts can be delivered
  751. * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
  752. * it. Addresses are the same as the original interrupt addresses, but
  753. * offset by 0xc000000000004000.
  754. * It's impossible to receive interrupts below 0x300 via this mechanism.
  755. * KVM: None of these traps are from the guest ; anything that escalated
  756. * to HV=1 from HV=0 is delivered via real mode handlers.
  757. */
  758. /*
  759. * This uses the standard macro, since the original 0x300 vector
  760. * only has extra guff for STAB-based processors -- which never
  761. * come here.
  762. */
  763. STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
  764. . = 0x4380
  765. .globl data_access_slb_relon_pSeries
  766. data_access_slb_relon_pSeries:
  767. SET_SCRATCH0(r13)
  768. EXCEPTION_PROLOG_0(PACA_EXSLB)
  769. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
  770. std r3,PACA_EXSLB+EX_R3(r13)
  771. mfspr r3,SPRN_DAR
  772. mfspr r12,SPRN_SRR1
  773. #ifndef CONFIG_RELOCATABLE
  774. b slb_miss_realmode
  775. #else
  776. /*
  777. * We can't just use a direct branch to slb_miss_realmode
  778. * because the distance from here to there depends on where
  779. * the kernel ends up being put.
  780. */
  781. mfctr r11
  782. ld r10,PACAKBASE(r13)
  783. LOAD_HANDLER(r10, slb_miss_realmode)
  784. mtctr r10
  785. bctr
  786. #endif
  787. STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
  788. . = 0x4480
  789. .globl instruction_access_slb_relon_pSeries
  790. instruction_access_slb_relon_pSeries:
  791. SET_SCRATCH0(r13)
  792. EXCEPTION_PROLOG_0(PACA_EXSLB)
  793. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
  794. std r3,PACA_EXSLB+EX_R3(r13)
  795. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  796. mfspr r12,SPRN_SRR1
  797. #ifndef CONFIG_RELOCATABLE
  798. b slb_miss_realmode
  799. #else
  800. mfctr r11
  801. ld r10,PACAKBASE(r13)
  802. LOAD_HANDLER(r10, slb_miss_realmode)
  803. mtctr r10
  804. bctr
  805. #endif
  806. . = 0x4500
  807. .globl hardware_interrupt_relon_pSeries;
  808. .globl hardware_interrupt_relon_hv;
  809. hardware_interrupt_relon_pSeries:
  810. hardware_interrupt_relon_hv:
  811. BEGIN_FTR_SECTION
  812. _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
  813. FTR_SECTION_ELSE
  814. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
  815. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  816. STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
  817. STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
  818. STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
  819. MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
  820. STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
  821. MASKABLE_RELON_EXCEPTION_PSERIES(0x4a00, 0xa00, doorbell_super)
  822. STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
  823. . = 0x4c00
  824. .globl system_call_relon_pSeries
  825. system_call_relon_pSeries:
  826. HMT_MEDIUM
  827. SYSCALL_PSERIES_1
  828. SYSCALL_PSERIES_2_DIRECT
  829. SYSCALL_PSERIES_3
  830. STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
  831. . = 0x4e00
  832. b . /* Can't happen, see v2.07 Book III-S section 6.5 */
  833. . = 0x4e20
  834. b . /* Can't happen, see v2.07 Book III-S section 6.5 */
  835. . = 0x4e40
  836. emulation_assist_relon_trampoline:
  837. SET_SCRATCH0(r13)
  838. EXCEPTION_PROLOG_0(PACA_EXGEN)
  839. b emulation_assist_relon_hv
  840. . = 0x4e60
  841. b . /* Can't happen, see v2.07 Book III-S section 6.5 */
  842. . = 0x4e80
  843. h_doorbell_relon_trampoline:
  844. SET_SCRATCH0(r13)
  845. EXCEPTION_PROLOG_0(PACA_EXGEN)
  846. b h_doorbell_relon_hv
  847. . = 0x4f00
  848. performance_monitor_relon_pseries_trampoline:
  849. SET_SCRATCH0(r13)
  850. EXCEPTION_PROLOG_0(PACA_EXGEN)
  851. b performance_monitor_relon_pSeries
  852. . = 0x4f20
  853. altivec_unavailable_relon_pseries_trampoline:
  854. SET_SCRATCH0(r13)
  855. EXCEPTION_PROLOG_0(PACA_EXGEN)
  856. b altivec_unavailable_relon_pSeries
  857. . = 0x4f40
  858. vsx_unavailable_relon_pseries_trampoline:
  859. SET_SCRATCH0(r13)
  860. EXCEPTION_PROLOG_0(PACA_EXGEN)
  861. b vsx_unavailable_relon_pSeries
  862. . = 0x4f60
  863. facility_unavailable_relon_trampoline:
  864. SET_SCRATCH0(r13)
  865. EXCEPTION_PROLOG_0(PACA_EXGEN)
  866. b facility_unavailable_relon_pSeries
  867. . = 0x4f80
  868. hv_facility_unavailable_relon_trampoline:
  869. SET_SCRATCH0(r13)
  870. EXCEPTION_PROLOG_0(PACA_EXGEN)
  871. b hv_facility_unavailable_relon_hv
  872. STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
  873. #ifdef CONFIG_PPC_DENORMALISATION
  874. . = 0x5500
  875. b denorm_exception_hv
  876. #endif
  877. STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
  878. /* Other future vectors */
  879. .align 7
  880. .globl __end_interrupts
  881. __end_interrupts:
  882. .align 7
  883. system_call_entry_direct:
  884. #if defined(CONFIG_RELOCATABLE)
  885. /* The first level prologue may have used LR to get here, saving
  886. * orig in r10. To save hacking/ifdeffing common code, restore here.
  887. */
  888. mtlr r10
  889. #endif
  890. system_call_entry:
  891. b system_call_common
  892. ppc64_runlatch_on_trampoline:
  893. b __ppc64_runlatch_on
  894. /*
  895. * Here we have detected that the kernel stack pointer is bad.
  896. * R9 contains the saved CR, r13 points to the paca,
  897. * r10 contains the (bad) kernel stack pointer,
  898. * r11 and r12 contain the saved SRR0 and SRR1.
  899. * We switch to using an emergency stack, save the registers there,
  900. * and call kernel_bad_stack(), which panics.
  901. */
  902. bad_stack:
  903. ld r1,PACAEMERGSP(r13)
  904. subi r1,r1,64+INT_FRAME_SIZE
  905. std r9,_CCR(r1)
  906. std r10,GPR1(r1)
  907. std r11,_NIP(r1)
  908. std r12,_MSR(r1)
  909. mfspr r11,SPRN_DAR
  910. mfspr r12,SPRN_DSISR
  911. std r11,_DAR(r1)
  912. std r12,_DSISR(r1)
  913. mflr r10
  914. mfctr r11
  915. mfxer r12
  916. std r10,_LINK(r1)
  917. std r11,_CTR(r1)
  918. std r12,_XER(r1)
  919. SAVE_GPR(0,r1)
  920. SAVE_GPR(2,r1)
  921. ld r10,EX_R3(r3)
  922. std r10,GPR3(r1)
  923. SAVE_GPR(4,r1)
  924. SAVE_4GPRS(5,r1)
  925. ld r9,EX_R9(r3)
  926. ld r10,EX_R10(r3)
  927. SAVE_2GPRS(9,r1)
  928. ld r9,EX_R11(r3)
  929. ld r10,EX_R12(r3)
  930. ld r11,EX_R13(r3)
  931. std r9,GPR11(r1)
  932. std r10,GPR12(r1)
  933. std r11,GPR13(r1)
  934. BEGIN_FTR_SECTION
  935. ld r10,EX_CFAR(r3)
  936. std r10,ORIG_GPR3(r1)
  937. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  938. SAVE_8GPRS(14,r1)
  939. SAVE_10GPRS(22,r1)
  940. lhz r12,PACA_TRAP_SAVE(r13)
  941. std r12,_TRAP(r1)
  942. addi r11,r1,INT_FRAME_SIZE
  943. std r11,0(r1)
  944. li r12,0
  945. std r12,0(r11)
  946. ld r2,PACATOC(r13)
  947. ld r11,exception_marker@toc(r2)
  948. std r12,RESULT(r1)
  949. std r11,STACK_FRAME_OVERHEAD-16(r1)
  950. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  951. bl kernel_bad_stack
  952. b 1b
  953. /*
  954. * Here r13 points to the paca, r9 contains the saved CR,
  955. * SRR0 and SRR1 are saved in r11 and r12,
  956. * r9 - r13 are saved in paca->exgen.
  957. */
  958. .align 7
  959. .globl data_access_common
  960. data_access_common:
  961. mfspr r10,SPRN_DAR
  962. std r10,PACA_EXGEN+EX_DAR(r13)
  963. mfspr r10,SPRN_DSISR
  964. stw r10,PACA_EXGEN+EX_DSISR(r13)
  965. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  966. DISABLE_INTS
  967. ld r12,_MSR(r1)
  968. ld r3,PACA_EXGEN+EX_DAR(r13)
  969. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  970. li r5,0x300
  971. b do_hash_page /* Try to handle as hpte fault */
  972. .align 7
  973. .globl h_data_storage_common
  974. h_data_storage_common:
  975. mfspr r10,SPRN_HDAR
  976. std r10,PACA_EXGEN+EX_DAR(r13)
  977. mfspr r10,SPRN_HDSISR
  978. stw r10,PACA_EXGEN+EX_DSISR(r13)
  979. EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
  980. bl save_nvgprs
  981. DISABLE_INTS
  982. addi r3,r1,STACK_FRAME_OVERHEAD
  983. bl unknown_exception
  984. b ret_from_except
  985. .align 7
  986. .globl instruction_access_common
  987. instruction_access_common:
  988. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  989. DISABLE_INTS
  990. ld r12,_MSR(r1)
  991. ld r3,_NIP(r1)
  992. andis. r4,r12,0x5820
  993. li r5,0x400
  994. b do_hash_page /* Try to handle as hpte fault */
  995. STD_EXCEPTION_COMMON(0xe20, h_instr_storage, unknown_exception)
  996. /*
  997. * Here is the common SLB miss user that is used when going to virtual
  998. * mode for SLB misses, that is currently not used
  999. */
  1000. #ifdef __DISABLED__
  1001. .align 7
  1002. .globl slb_miss_user_common
  1003. slb_miss_user_common:
  1004. mflr r10
  1005. std r3,PACA_EXGEN+EX_DAR(r13)
  1006. stw r9,PACA_EXGEN+EX_CCR(r13)
  1007. std r10,PACA_EXGEN+EX_LR(r13)
  1008. std r11,PACA_EXGEN+EX_SRR0(r13)
  1009. bl slb_allocate_user
  1010. ld r10,PACA_EXGEN+EX_LR(r13)
  1011. ld r3,PACA_EXGEN+EX_R3(r13)
  1012. lwz r9,PACA_EXGEN+EX_CCR(r13)
  1013. ld r11,PACA_EXGEN+EX_SRR0(r13)
  1014. mtlr r10
  1015. beq- slb_miss_fault
  1016. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  1017. beq- unrecov_user_slb
  1018. mfmsr r10
  1019. .machine push
  1020. .machine "power4"
  1021. mtcrf 0x80,r9
  1022. .machine pop
  1023. clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
  1024. mtmsrd r10,1
  1025. mtspr SRR0,r11
  1026. mtspr SRR1,r12
  1027. ld r9,PACA_EXGEN+EX_R9(r13)
  1028. ld r10,PACA_EXGEN+EX_R10(r13)
  1029. ld r11,PACA_EXGEN+EX_R11(r13)
  1030. ld r12,PACA_EXGEN+EX_R12(r13)
  1031. ld r13,PACA_EXGEN+EX_R13(r13)
  1032. rfid
  1033. b .
  1034. slb_miss_fault:
  1035. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
  1036. ld r4,PACA_EXGEN+EX_DAR(r13)
  1037. li r5,0
  1038. std r4,_DAR(r1)
  1039. std r5,_DSISR(r1)
  1040. b handle_page_fault
  1041. unrecov_user_slb:
  1042. EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
  1043. DISABLE_INTS
  1044. bl save_nvgprs
  1045. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1046. bl unrecoverable_exception
  1047. b 1b
  1048. #endif /* __DISABLED__ */
  1049. /*
  1050. * Machine check is different because we use a different
  1051. * save area: PACA_EXMC instead of PACA_EXGEN.
  1052. */
  1053. .align 7
  1054. .globl machine_check_common
  1055. machine_check_common:
  1056. mfspr r10,SPRN_DAR
  1057. std r10,PACA_EXGEN+EX_DAR(r13)
  1058. mfspr r10,SPRN_DSISR
  1059. stw r10,PACA_EXGEN+EX_DSISR(r13)
  1060. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  1061. FINISH_NAP
  1062. DISABLE_INTS
  1063. ld r3,PACA_EXGEN+EX_DAR(r13)
  1064. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  1065. std r3,_DAR(r1)
  1066. std r4,_DSISR(r1)
  1067. bl save_nvgprs
  1068. addi r3,r1,STACK_FRAME_OVERHEAD
  1069. bl machine_check_exception
  1070. b ret_from_except
  1071. .align 7
  1072. .globl alignment_common
  1073. alignment_common:
  1074. mfspr r10,SPRN_DAR
  1075. std r10,PACA_EXGEN+EX_DAR(r13)
  1076. mfspr r10,SPRN_DSISR
  1077. stw r10,PACA_EXGEN+EX_DSISR(r13)
  1078. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  1079. ld r3,PACA_EXGEN+EX_DAR(r13)
  1080. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  1081. std r3,_DAR(r1)
  1082. std r4,_DSISR(r1)
  1083. bl save_nvgprs
  1084. DISABLE_INTS
  1085. addi r3,r1,STACK_FRAME_OVERHEAD
  1086. bl alignment_exception
  1087. b ret_from_except
  1088. .align 7
  1089. .globl program_check_common
  1090. program_check_common:
  1091. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  1092. bl save_nvgprs
  1093. DISABLE_INTS
  1094. addi r3,r1,STACK_FRAME_OVERHEAD
  1095. bl program_check_exception
  1096. b ret_from_except
  1097. .align 7
  1098. .globl fp_unavailable_common
  1099. fp_unavailable_common:
  1100. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  1101. bne 1f /* if from user, just load it up */
  1102. bl save_nvgprs
  1103. DISABLE_INTS
  1104. addi r3,r1,STACK_FRAME_OVERHEAD
  1105. bl kernel_fp_unavailable_exception
  1106. BUG_OPCODE
  1107. 1:
  1108. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1109. BEGIN_FTR_SECTION
  1110. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1111. * transaction), go do TM stuff
  1112. */
  1113. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1114. bne- 2f
  1115. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  1116. #endif
  1117. bl load_up_fpu
  1118. b fast_exception_return
  1119. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1120. 2: /* User process was in a transaction */
  1121. bl save_nvgprs
  1122. DISABLE_INTS
  1123. addi r3,r1,STACK_FRAME_OVERHEAD
  1124. bl fp_unavailable_tm
  1125. b ret_from_except
  1126. #endif
  1127. .align 7
  1128. .globl altivec_unavailable_common
  1129. altivec_unavailable_common:
  1130. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  1131. #ifdef CONFIG_ALTIVEC
  1132. BEGIN_FTR_SECTION
  1133. beq 1f
  1134. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1135. BEGIN_FTR_SECTION_NESTED(69)
  1136. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1137. * transaction), go do TM stuff
  1138. */
  1139. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1140. bne- 2f
  1141. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1142. #endif
  1143. bl load_up_altivec
  1144. b fast_exception_return
  1145. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1146. 2: /* User process was in a transaction */
  1147. bl save_nvgprs
  1148. DISABLE_INTS
  1149. addi r3,r1,STACK_FRAME_OVERHEAD
  1150. bl altivec_unavailable_tm
  1151. b ret_from_except
  1152. #endif
  1153. 1:
  1154. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1155. #endif
  1156. bl save_nvgprs
  1157. DISABLE_INTS
  1158. addi r3,r1,STACK_FRAME_OVERHEAD
  1159. bl altivec_unavailable_exception
  1160. b ret_from_except
  1161. .align 7
  1162. .globl vsx_unavailable_common
  1163. vsx_unavailable_common:
  1164. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  1165. #ifdef CONFIG_VSX
  1166. BEGIN_FTR_SECTION
  1167. beq 1f
  1168. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1169. BEGIN_FTR_SECTION_NESTED(69)
  1170. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1171. * transaction), go do TM stuff
  1172. */
  1173. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1174. bne- 2f
  1175. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1176. #endif
  1177. b load_up_vsx
  1178. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1179. 2: /* User process was in a transaction */
  1180. bl save_nvgprs
  1181. DISABLE_INTS
  1182. addi r3,r1,STACK_FRAME_OVERHEAD
  1183. bl vsx_unavailable_tm
  1184. b ret_from_except
  1185. #endif
  1186. 1:
  1187. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1188. #endif
  1189. bl save_nvgprs
  1190. DISABLE_INTS
  1191. addi r3,r1,STACK_FRAME_OVERHEAD
  1192. bl vsx_unavailable_exception
  1193. b ret_from_except
  1194. STD_EXCEPTION_COMMON(0xf60, facility_unavailable, facility_unavailable_exception)
  1195. STD_EXCEPTION_COMMON(0xf80, hv_facility_unavailable, facility_unavailable_exception)
  1196. .align 7
  1197. .globl __end_handlers
  1198. __end_handlers:
  1199. /* Equivalents to the above handlers for relocation-on interrupt vectors */
  1200. STD_RELON_EXCEPTION_HV_OOL(0xe40, emulation_assist)
  1201. MASKABLE_RELON_EXCEPTION_HV_OOL(0xe80, h_doorbell)
  1202. STD_RELON_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
  1203. STD_RELON_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
  1204. STD_RELON_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
  1205. STD_RELON_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
  1206. STD_RELON_EXCEPTION_HV_OOL(0xf80, hv_facility_unavailable)
  1207. #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
  1208. /*
  1209. * Data area reserved for FWNMI option.
  1210. * This address (0x7000) is fixed by the RPA.
  1211. */
  1212. .= 0x7000
  1213. .globl fwnmi_data_area
  1214. fwnmi_data_area:
  1215. /* pseries and powernv need to keep the whole page from
  1216. * 0x7000 to 0x8000 free for use by the firmware
  1217. */
  1218. . = 0x8000
  1219. #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
  1220. /* Space for CPU0's segment table */
  1221. .balign 4096
  1222. .globl initial_stab
  1223. initial_stab:
  1224. .space 4096
  1225. #ifdef CONFIG_PPC_POWERNV
  1226. _GLOBAL(opal_mc_secondary_handler)
  1227. HMT_MEDIUM_PPR_DISCARD
  1228. SET_SCRATCH0(r13)
  1229. GET_PACA(r13)
  1230. clrldi r3,r3,2
  1231. tovirt(r3,r3)
  1232. std r3,PACA_OPAL_MC_EVT(r13)
  1233. ld r13,OPAL_MC_SRR0(r3)
  1234. mtspr SPRN_SRR0,r13
  1235. ld r13,OPAL_MC_SRR1(r3)
  1236. mtspr SPRN_SRR1,r13
  1237. ld r3,OPAL_MC_GPR3(r3)
  1238. GET_SCRATCH0(r13)
  1239. b machine_check_pSeries
  1240. #endif /* CONFIG_PPC_POWERNV */
  1241. #define MACHINE_CHECK_HANDLER_WINDUP \
  1242. /* Clear MSR_RI before setting SRR0 and SRR1. */\
  1243. li r0,MSR_RI; \
  1244. mfmsr r9; /* get MSR value */ \
  1245. andc r9,r9,r0; \
  1246. mtmsrd r9,1; /* Clear MSR_RI */ \
  1247. /* Move original SRR0 and SRR1 into the respective regs */ \
  1248. ld r9,_MSR(r1); \
  1249. mtspr SPRN_SRR1,r9; \
  1250. ld r3,_NIP(r1); \
  1251. mtspr SPRN_SRR0,r3; \
  1252. ld r9,_CTR(r1); \
  1253. mtctr r9; \
  1254. ld r9,_XER(r1); \
  1255. mtxer r9; \
  1256. ld r9,_LINK(r1); \
  1257. mtlr r9; \
  1258. REST_GPR(0, r1); \
  1259. REST_8GPRS(2, r1); \
  1260. REST_GPR(10, r1); \
  1261. ld r11,_CCR(r1); \
  1262. mtcr r11; \
  1263. /* Decrement paca->in_mce. */ \
  1264. lhz r12,PACA_IN_MCE(r13); \
  1265. subi r12,r12,1; \
  1266. sth r12,PACA_IN_MCE(r13); \
  1267. REST_GPR(11, r1); \
  1268. REST_2GPRS(12, r1); \
  1269. /* restore original r1. */ \
  1270. ld r1,GPR1(r1)
  1271. /*
  1272. * Handle machine check early in real mode. We come here with
  1273. * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
  1274. */
  1275. .align 7
  1276. .globl machine_check_handle_early
  1277. machine_check_handle_early:
  1278. std r0,GPR0(r1) /* Save r0 */
  1279. EXCEPTION_PROLOG_COMMON_3(0x200)
  1280. bl save_nvgprs
  1281. addi r3,r1,STACK_FRAME_OVERHEAD
  1282. bl machine_check_early
  1283. std r3,RESULT(r1) /* Save result */
  1284. ld r12,_MSR(r1)
  1285. #ifdef CONFIG_PPC_P7_NAP
  1286. /*
  1287. * Check if thread was in power saving mode. We come here when any
  1288. * of the following is true:
  1289. * a. thread wasn't in power saving mode
  1290. * b. thread was in power saving mode with no state loss or
  1291. * supervisor state loss
  1292. *
  1293. * Go back to nap again if (b) is true.
  1294. */
  1295. rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
  1296. beq 4f /* No, it wasn;t */
  1297. /* Thread was in power saving mode. Go back to nap again. */
  1298. cmpwi r11,2
  1299. bne 3f
  1300. /* Supervisor state loss */
  1301. li r0,1
  1302. stb r0,PACA_NAPSTATELOST(r13)
  1303. 3: bl machine_check_queue_event
  1304. MACHINE_CHECK_HANDLER_WINDUP
  1305. GET_PACA(r13)
  1306. ld r1,PACAR1(r13)
  1307. b power7_enter_nap_mode
  1308. 4:
  1309. #endif
  1310. /*
  1311. * Check if we are coming from hypervisor userspace. If yes then we
  1312. * continue in host kernel in V mode to deliver the MC event.
  1313. */
  1314. rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
  1315. beq 5f
  1316. andi. r11,r12,MSR_PR /* See if coming from user. */
  1317. bne 9f /* continue in V mode if we are. */
  1318. 5:
  1319. #ifdef CONFIG_KVM_BOOK3S_64_HV
  1320. /*
  1321. * We are coming from kernel context. Check if we are coming from
  1322. * guest. if yes, then we can continue. We will fall through
  1323. * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
  1324. */
  1325. lbz r11,HSTATE_IN_GUEST(r13)
  1326. cmpwi r11,0 /* Check if coming from guest */
  1327. bne 9f /* continue if we are. */
  1328. #endif
  1329. /*
  1330. * At this point we are not sure about what context we come from.
  1331. * Queue up the MCE event and return from the interrupt.
  1332. * But before that, check if this is an un-recoverable exception.
  1333. * If yes, then stay on emergency stack and panic.
  1334. */
  1335. andi. r11,r12,MSR_RI
  1336. bne 2f
  1337. 1: mfspr r11,SPRN_SRR0
  1338. ld r10,PACAKBASE(r13)
  1339. LOAD_HANDLER(r10,unrecover_mce)
  1340. mtspr SPRN_SRR0,r10
  1341. ld r10,PACAKMSR(r13)
  1342. /*
  1343. * We are going down. But there are chances that we might get hit by
  1344. * another MCE during panic path and we may run into unstable state
  1345. * with no way out. Hence, turn ME bit off while going down, so that
  1346. * when another MCE is hit during panic path, system will checkstop
  1347. * and hypervisor will get restarted cleanly by SP.
  1348. */
  1349. li r3,MSR_ME
  1350. andc r10,r10,r3 /* Turn off MSR_ME */
  1351. mtspr SPRN_SRR1,r10
  1352. rfid
  1353. b .
  1354. 2:
  1355. /*
  1356. * Check if we have successfully handled/recovered from error, if not
  1357. * then stay on emergency stack and panic.
  1358. */
  1359. ld r3,RESULT(r1) /* Load result */
  1360. cmpdi r3,0 /* see if we handled MCE successfully */
  1361. beq 1b /* if !handled then panic */
  1362. /*
  1363. * Return from MC interrupt.
  1364. * Queue up the MCE event so that we can log it later, while
  1365. * returning from kernel or opal call.
  1366. */
  1367. bl machine_check_queue_event
  1368. MACHINE_CHECK_HANDLER_WINDUP
  1369. rfid
  1370. 9:
  1371. /* Deliver the machine check to host kernel in V mode. */
  1372. MACHINE_CHECK_HANDLER_WINDUP
  1373. b machine_check_pSeries
  1374. unrecover_mce:
  1375. /* Invoke machine_check_exception to print MCE event and panic. */
  1376. addi r3,r1,STACK_FRAME_OVERHEAD
  1377. bl machine_check_exception
  1378. /*
  1379. * We will not reach here. Even if we did, there is no way out. Call
  1380. * unrecoverable_exception and die.
  1381. */
  1382. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1383. bl unrecoverable_exception
  1384. b 1b
  1385. /*
  1386. * r13 points to the PACA, r9 contains the saved CR,
  1387. * r12 contain the saved SRR1, SRR0 is still ready for return
  1388. * r3 has the faulting address
  1389. * r9 - r13 are saved in paca->exslb.
  1390. * r3 is saved in paca->slb_r3
  1391. * We assume we aren't going to take any exceptions during this procedure.
  1392. */
  1393. slb_miss_realmode:
  1394. mflr r10
  1395. #ifdef CONFIG_RELOCATABLE
  1396. mtctr r11
  1397. #endif
  1398. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1399. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  1400. bl slb_allocate_realmode
  1401. /* All done -- return from exception. */
  1402. ld r10,PACA_EXSLB+EX_LR(r13)
  1403. ld r3,PACA_EXSLB+EX_R3(r13)
  1404. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1405. mtlr r10
  1406. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  1407. beq- 2f
  1408. .machine push
  1409. .machine "power4"
  1410. mtcrf 0x80,r9
  1411. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  1412. .machine pop
  1413. RESTORE_PPR_PACA(PACA_EXSLB, r9)
  1414. ld r9,PACA_EXSLB+EX_R9(r13)
  1415. ld r10,PACA_EXSLB+EX_R10(r13)
  1416. ld r11,PACA_EXSLB+EX_R11(r13)
  1417. ld r12,PACA_EXSLB+EX_R12(r13)
  1418. ld r13,PACA_EXSLB+EX_R13(r13)
  1419. rfid
  1420. b . /* prevent speculative execution */
  1421. 2: mfspr r11,SPRN_SRR0
  1422. ld r10,PACAKBASE(r13)
  1423. LOAD_HANDLER(r10,unrecov_slb)
  1424. mtspr SPRN_SRR0,r10
  1425. ld r10,PACAKMSR(r13)
  1426. mtspr SPRN_SRR1,r10
  1427. rfid
  1428. b .
  1429. unrecov_slb:
  1430. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  1431. DISABLE_INTS
  1432. bl save_nvgprs
  1433. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1434. bl unrecoverable_exception
  1435. b 1b
  1436. #ifdef CONFIG_PPC_970_NAP
  1437. power4_fixup_nap:
  1438. andc r9,r9,r10
  1439. std r9,TI_LOCAL_FLAGS(r11)
  1440. ld r10,_LINK(r1) /* make idle task do the */
  1441. std r10,_NIP(r1) /* equivalent of a blr */
  1442. blr
  1443. #endif
  1444. /*
  1445. * Hash table stuff
  1446. */
  1447. .align 7
  1448. do_hash_page:
  1449. std r3,_DAR(r1)
  1450. std r4,_DSISR(r1)
  1451. andis. r0,r4,0xa410 /* weird error? */
  1452. bne- handle_page_fault /* if not, try to insert a HPTE */
  1453. andis. r0,r4,DSISR_DABRMATCH@h
  1454. bne- handle_dabr_fault
  1455. BEGIN_FTR_SECTION
  1456. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  1457. bne- do_ste_alloc /* If so handle it */
  1458. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
  1459. CURRENT_THREAD_INFO(r11, r1)
  1460. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  1461. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  1462. bne 77f /* then don't call hash_page now */
  1463. /*
  1464. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  1465. * accessing a userspace segment (even from the kernel). We assume
  1466. * kernel addresses always have the high bit set.
  1467. */
  1468. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  1469. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  1470. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  1471. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  1472. ori r4,r4,1 /* add _PAGE_PRESENT */
  1473. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  1474. /*
  1475. * r3 contains the faulting address
  1476. * r4 contains the required access permissions
  1477. * r5 contains the trap number
  1478. *
  1479. * at return r3 = 0 for success, 1 for page fault, negative for error
  1480. */
  1481. bl hash_page /* build HPTE if possible */
  1482. cmpdi r3,0 /* see if hash_page succeeded */
  1483. /* Success */
  1484. beq fast_exc_return_irq /* Return from exception on success */
  1485. /* Error */
  1486. blt- 13f
  1487. /* Here we have a page fault that hash_page can't handle. */
  1488. handle_page_fault:
  1489. 11: ld r4,_DAR(r1)
  1490. ld r5,_DSISR(r1)
  1491. addi r3,r1,STACK_FRAME_OVERHEAD
  1492. bl do_page_fault
  1493. cmpdi r3,0
  1494. beq+ 12f
  1495. bl save_nvgprs
  1496. mr r5,r3
  1497. addi r3,r1,STACK_FRAME_OVERHEAD
  1498. lwz r4,_DAR(r1)
  1499. bl bad_page_fault
  1500. b ret_from_except
  1501. /* We have a data breakpoint exception - handle it */
  1502. handle_dabr_fault:
  1503. bl save_nvgprs
  1504. ld r4,_DAR(r1)
  1505. ld r5,_DSISR(r1)
  1506. addi r3,r1,STACK_FRAME_OVERHEAD
  1507. bl do_break
  1508. 12: b ret_from_except_lite
  1509. /* We have a page fault that hash_page could handle but HV refused
  1510. * the PTE insertion
  1511. */
  1512. 13: bl save_nvgprs
  1513. mr r5,r3
  1514. addi r3,r1,STACK_FRAME_OVERHEAD
  1515. ld r4,_DAR(r1)
  1516. bl low_hash_fault
  1517. b ret_from_except
  1518. /*
  1519. * We come here as a result of a DSI at a point where we don't want
  1520. * to call hash_page, such as when we are accessing memory (possibly
  1521. * user memory) inside a PMU interrupt that occurred while interrupts
  1522. * were soft-disabled. We want to invoke the exception handler for
  1523. * the access, or panic if there isn't a handler.
  1524. */
  1525. 77: bl save_nvgprs
  1526. mr r4,r3
  1527. addi r3,r1,STACK_FRAME_OVERHEAD
  1528. li r5,SIGSEGV
  1529. bl bad_page_fault
  1530. b ret_from_except
  1531. /* here we have a segment miss */
  1532. do_ste_alloc:
  1533. bl ste_allocate /* try to insert stab entry */
  1534. cmpdi r3,0
  1535. bne- handle_page_fault
  1536. b fast_exception_return
  1537. /*
  1538. * r13 points to the PACA, r9 contains the saved CR,
  1539. * r11 and r12 contain the saved SRR0 and SRR1.
  1540. * r9 - r13 are saved in paca->exslb.
  1541. * We assume we aren't going to take any exceptions during this procedure.
  1542. * We assume (DAR >> 60) == 0xc.
  1543. */
  1544. .align 7
  1545. do_stab_bolted:
  1546. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1547. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  1548. mfspr r11,SPRN_DAR /* ea */
  1549. /*
  1550. * check for bad kernel/user address
  1551. * (ea & ~REGION_MASK) >= PGTABLE_RANGE
  1552. */
  1553. rldicr. r9,r11,4,(63 - 46 - 4)
  1554. li r9,0 /* VSID = 0 for bad address */
  1555. bne- 0f
  1556. /*
  1557. * Calculate VSID:
  1558. * This is the kernel vsid, we take the top for context from
  1559. * the range. context = (MAX_USER_CONTEXT) + ((ea >> 60) - 0xc) + 1
  1560. * Here we know that (ea >> 60) == 0xc
  1561. */
  1562. lis r9,(MAX_USER_CONTEXT + 1)@ha
  1563. addi r9,r9,(MAX_USER_CONTEXT + 1)@l
  1564. srdi r10,r11,SID_SHIFT
  1565. rldimi r10,r9,ESID_BITS,0 /* proto vsid */
  1566. ASM_VSID_SCRAMBLE(r10, r9, 256M)
  1567. rldic r9,r10,12,16 /* r9 = vsid << 12 */
  1568. 0:
  1569. /* Hash to the primary group */
  1570. ld r10,PACASTABVIRT(r13)
  1571. srdi r11,r11,SID_SHIFT
  1572. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  1573. /* Search the primary group for a free entry */
  1574. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  1575. andi. r11,r11,0x80
  1576. beq 2f
  1577. addi r10,r10,16
  1578. andi. r11,r10,0x70
  1579. bne 1b
  1580. /* Stick for only searching the primary group for now. */
  1581. /* At least for now, we use a very simple random castout scheme */
  1582. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  1583. mftb r11
  1584. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  1585. ori r11,r11,0x10
  1586. /* r10 currently points to an ste one past the group of interest */
  1587. /* make it point to the randomly selected entry */
  1588. subi r10,r10,128
  1589. or r10,r10,r11 /* r10 is the entry to invalidate */
  1590. isync /* mark the entry invalid */
  1591. ld r11,0(r10)
  1592. rldicl r11,r11,56,1 /* clear the valid bit */
  1593. rotldi r11,r11,8
  1594. std r11,0(r10)
  1595. sync
  1596. clrrdi r11,r11,28 /* Get the esid part of the ste */
  1597. slbie r11
  1598. 2: std r9,8(r10) /* Store the vsid part of the ste */
  1599. eieio
  1600. mfspr r11,SPRN_DAR /* Get the new esid */
  1601. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  1602. ori r11,r11,0x90 /* Turn on valid and kp */
  1603. std r11,0(r10) /* Put new entry back into the stab */
  1604. sync
  1605. /* All done -- return from exception. */
  1606. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1607. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  1608. andi. r10,r12,MSR_RI
  1609. beq- unrecov_slb
  1610. mtcrf 0x80,r9 /* restore CR */
  1611. mfmsr r10
  1612. clrrdi r10,r10,2
  1613. mtmsrd r10,1
  1614. mtspr SPRN_SRR0,r11
  1615. mtspr SPRN_SRR1,r12
  1616. ld r9,PACA_EXSLB+EX_R9(r13)
  1617. ld r10,PACA_EXSLB+EX_R10(r13)
  1618. ld r11,PACA_EXSLB+EX_R11(r13)
  1619. ld r12,PACA_EXSLB+EX_R12(r13)
  1620. ld r13,PACA_EXSLB+EX_R13(r13)
  1621. rfid
  1622. b . /* prevent speculative execution */