exceptions-64s.S 45 KB

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