exceptions-64s.S 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  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. #include <asm/head-64.h>
  19. /*
  20. * There are a few constraints to be concerned with.
  21. * - Real mode exceptions code/data must be located at their physical location.
  22. * - Virtual mode exceptions must be mapped at their 0xc000... location.
  23. * - Fixed location code must not call directly beyond the __end_interrupts
  24. * area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence
  25. * must be used.
  26. * - LOAD_HANDLER targets must be within first 64K of physical 0 /
  27. * virtual 0xc00...
  28. * - Conditional branch targets must be within +/-32K of caller.
  29. *
  30. * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and
  31. * therefore don't have to run in physically located code or rfid to
  32. * virtual mode kernel code. However on relocatable kernels they do have
  33. * to branch to KERNELBASE offset because the rest of the kernel (outside
  34. * the exception vectors) may be located elsewhere.
  35. *
  36. * Virtual exceptions correspond with physical, except their entry points
  37. * are offset by 0xc000000000000000 and also tend to get an added 0x4000
  38. * offset applied. Virtual exceptions are enabled with the Alternate
  39. * Interrupt Location (AIL) bit set in the LPCR. However this does not
  40. * guarantee they will be delivered virtually. Some conditions (see the ISA)
  41. * cause exceptions to be delivered in real mode.
  42. *
  43. * It's impossible to receive interrupts below 0x300 via AIL.
  44. *
  45. * KVM: None of the virtual exceptions are from the guest. Anything that
  46. * escalated to HV=1 from HV=0 is delivered via real mode handlers.
  47. *
  48. *
  49. * We layout physical memory as follows:
  50. * 0x0000 - 0x00ff : Secondary processor spin code
  51. * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors
  52. * 0x1900 - 0x3fff : Real mode trampolines
  53. * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors
  54. * 0x5900 - 0x6fff : Relon mode trampolines
  55. * 0x7000 - 0x7fff : FWNMI data area
  56. * 0x8000 - .... : Common interrupt handlers, remaining early
  57. * setup code, rest of kernel.
  58. *
  59. * We could reclaim 0x4000-0x42ff for real mode trampolines if the space
  60. * is necessary. Until then it's more consistent to explicitly put VIRT_NONE
  61. * vectors there.
  62. */
  63. OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900)
  64. OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x4000)
  65. OPEN_FIXED_SECTION(virt_vectors, 0x4000, 0x5900)
  66. OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000)
  67. #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
  68. /*
  69. * Data area reserved for FWNMI option.
  70. * This address (0x7000) is fixed by the RPA.
  71. * pseries and powernv need to keep the whole page from
  72. * 0x7000 to 0x8000 free for use by the firmware
  73. */
  74. ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000)
  75. OPEN_TEXT_SECTION(0x8000)
  76. #else
  77. OPEN_TEXT_SECTION(0x7000)
  78. #endif
  79. USE_FIXED_SECTION(real_vectors)
  80. /*
  81. * This is the start of the interrupt handlers for pSeries
  82. * This code runs with relocation off.
  83. * Code from here to __end_interrupts gets copied down to real
  84. * address 0x100 when we are running a relocatable kernel.
  85. * Therefore any relative branches in this section must only
  86. * branch to labels in this section.
  87. */
  88. .globl __start_interrupts
  89. __start_interrupts:
  90. /* No virt vectors corresponding with 0x0..0x100 */
  91. EXC_VIRT_NONE(0x4000, 0x100)
  92. #ifdef CONFIG_PPC_P7_NAP
  93. /*
  94. * If running native on arch 2.06 or later, check if we are waking up
  95. * from nap/sleep/winkle, and branch to idle handler. This tests SRR1
  96. * bits 46:47. A non-0 value indicates that we are coming from a power
  97. * saving state. The idle wakeup handler initially runs in real mode,
  98. * but we branch to the 0xc000... address so we can turn on relocation
  99. * with mtmsr.
  100. */
  101. #define IDLETEST(n) \
  102. BEGIN_FTR_SECTION ; \
  103. mfspr r10,SPRN_SRR1 ; \
  104. rlwinm. r10,r10,47-31,30,31 ; \
  105. beq- 1f ; \
  106. cmpwi cr3,r10,2 ; \
  107. BRANCH_TO_C000(r10, system_reset_idle_common) ; \
  108. 1: \
  109. KVMTEST_PR(n) ; \
  110. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  111. #else
  112. #define IDLETEST NOTEST
  113. #endif
  114. EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
  115. SET_SCRATCH0(r13)
  116. /*
  117. * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is
  118. * being used, so a nested NMI exception would corrupt it.
  119. */
  120. EXCEPTION_PROLOG_PSERIES_NORI(PACA_EXNMI, system_reset_common, EXC_STD,
  121. IDLETEST, 0x100)
  122. EXC_REAL_END(system_reset, 0x100, 0x100)
  123. EXC_VIRT_NONE(0x4100, 0x100)
  124. TRAMP_KVM(PACA_EXNMI, 0x100)
  125. #ifdef CONFIG_PPC_P7_NAP
  126. EXC_COMMON_BEGIN(system_reset_idle_common)
  127. mfspr r12,SPRN_SRR1
  128. b pnv_powersave_wakeup
  129. #endif
  130. EXC_COMMON_BEGIN(system_reset_common)
  131. /*
  132. * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able
  133. * to recover, but nested NMI will notice in_nmi and not recover
  134. * because of the use of the NMI stack. in_nmi reentrancy is tested in
  135. * system_reset_exception.
  136. */
  137. lhz r10,PACA_IN_NMI(r13)
  138. addi r10,r10,1
  139. sth r10,PACA_IN_NMI(r13)
  140. li r10,MSR_RI
  141. mtmsrd r10,1
  142. mr r10,r1
  143. ld r1,PACA_NMI_EMERG_SP(r13)
  144. subi r1,r1,INT_FRAME_SIZE
  145. EXCEPTION_COMMON_NORET_STACK(PACA_EXNMI, 0x100,
  146. system_reset, system_reset_exception,
  147. ADD_NVGPRS;ADD_RECONCILE)
  148. /*
  149. * The stack is no longer in use, decrement in_nmi.
  150. */
  151. lhz r10,PACA_IN_NMI(r13)
  152. subi r10,r10,1
  153. sth r10,PACA_IN_NMI(r13)
  154. b ret_from_except
  155. #ifdef CONFIG_PPC_PSERIES
  156. /*
  157. * Vectors for the FWNMI option. Share common code.
  158. */
  159. TRAMP_REAL_BEGIN(system_reset_fwnmi)
  160. SET_SCRATCH0(r13) /* save r13 */
  161. /* See comment at system_reset exception */
  162. EXCEPTION_PROLOG_PSERIES_NORI(PACA_EXNMI, system_reset_common,
  163. EXC_STD, NOTEST, 0x100)
  164. #endif /* CONFIG_PPC_PSERIES */
  165. EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
  166. /* This is moved out of line as it can be patched by FW, but
  167. * some code path might still want to branch into the original
  168. * vector
  169. */
  170. SET_SCRATCH0(r13) /* save r13 */
  171. EXCEPTION_PROLOG_0(PACA_EXMC)
  172. BEGIN_FTR_SECTION
  173. b machine_check_powernv_early
  174. FTR_SECTION_ELSE
  175. b machine_check_pSeries_0
  176. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  177. EXC_REAL_END(machine_check, 0x200, 0x100)
  178. EXC_VIRT_NONE(0x4200, 0x100)
  179. TRAMP_REAL_BEGIN(machine_check_powernv_early)
  180. BEGIN_FTR_SECTION
  181. EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
  182. /*
  183. * Register contents:
  184. * R13 = PACA
  185. * R9 = CR
  186. * Original R9 to R13 is saved on PACA_EXMC
  187. *
  188. * Switch to mc_emergency stack and handle re-entrancy (we limit
  189. * the nested MCE upto level 4 to avoid stack overflow).
  190. * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
  191. *
  192. * We use paca->in_mce to check whether this is the first entry or
  193. * nested machine check. We increment paca->in_mce to track nested
  194. * machine checks.
  195. *
  196. * If this is the first entry then set stack pointer to
  197. * paca->mc_emergency_sp, otherwise r1 is already pointing to
  198. * stack frame on mc_emergency stack.
  199. *
  200. * NOTE: We are here with MSR_ME=0 (off), which means we risk a
  201. * checkstop if we get another machine check exception before we do
  202. * rfid with MSR_ME=1.
  203. *
  204. * This interrupt can wake directly from idle. If that is the case,
  205. * the machine check is handled then the idle wakeup code is called
  206. * to restore state. In that case, the POWER9 DD1 idle PACA workaround
  207. * is not applied in the early machine check code, which will cause
  208. * bugs.
  209. */
  210. mr r11,r1 /* Save r1 */
  211. lhz r10,PACA_IN_MCE(r13)
  212. cmpwi r10,0 /* Are we in nested machine check */
  213. bne 0f /* Yes, we are. */
  214. /* First machine check entry */
  215. ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
  216. 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  217. addi r10,r10,1 /* increment paca->in_mce */
  218. sth r10,PACA_IN_MCE(r13)
  219. /* Limit nested MCE to level 4 to avoid stack overflow */
  220. cmpwi r10,MAX_MCE_DEPTH
  221. bgt 2f /* Check if we hit limit of 4 */
  222. std r11,GPR1(r1) /* Save r1 on the stack. */
  223. std r11,0(r1) /* make stack chain pointer */
  224. mfspr r11,SPRN_SRR0 /* Save SRR0 */
  225. std r11,_NIP(r1)
  226. mfspr r11,SPRN_SRR1 /* Save SRR1 */
  227. std r11,_MSR(r1)
  228. mfspr r11,SPRN_DAR /* Save DAR */
  229. std r11,_DAR(r1)
  230. mfspr r11,SPRN_DSISR /* Save DSISR */
  231. std r11,_DSISR(r1)
  232. std r9,_CCR(r1) /* Save CR in stackframe */
  233. /* Save r9 through r13 from EXMC save area to stack frame. */
  234. EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
  235. mfmsr r11 /* get MSR value */
  236. ori r11,r11,MSR_ME /* turn on ME bit */
  237. ori r11,r11,MSR_RI /* turn on RI bit */
  238. LOAD_HANDLER(r12, machine_check_handle_early)
  239. 1: mtspr SPRN_SRR0,r12
  240. mtspr SPRN_SRR1,r11
  241. rfid
  242. b . /* prevent speculative execution */
  243. 2:
  244. /* Stack overflow. Stay on emergency stack and panic.
  245. * Keep the ME bit off while panic-ing, so that if we hit
  246. * another machine check we checkstop.
  247. */
  248. addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
  249. ld r11,PACAKMSR(r13)
  250. LOAD_HANDLER(r12, unrecover_mce)
  251. li r10,MSR_ME
  252. andc r11,r11,r10 /* Turn off MSR_ME */
  253. b 1b
  254. b . /* prevent speculative execution */
  255. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
  256. TRAMP_REAL_BEGIN(machine_check_pSeries)
  257. .globl machine_check_fwnmi
  258. machine_check_fwnmi:
  259. SET_SCRATCH0(r13) /* save r13 */
  260. EXCEPTION_PROLOG_0(PACA_EXMC)
  261. machine_check_pSeries_0:
  262. EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST_PR, 0x200)
  263. /*
  264. * MSR_RI is not enabled, because PACA_EXMC is being used, so a
  265. * nested machine check corrupts it. machine_check_common enables
  266. * MSR_RI.
  267. */
  268. EXCEPTION_PROLOG_PSERIES_1_NORI(machine_check_common, EXC_STD)
  269. TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
  270. EXC_COMMON_BEGIN(machine_check_common)
  271. /*
  272. * Machine check is different because we use a different
  273. * save area: PACA_EXMC instead of PACA_EXGEN.
  274. */
  275. mfspr r10,SPRN_DAR
  276. std r10,PACA_EXMC+EX_DAR(r13)
  277. mfspr r10,SPRN_DSISR
  278. stw r10,PACA_EXMC+EX_DSISR(r13)
  279. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  280. FINISH_NAP
  281. RECONCILE_IRQ_STATE(r10, r11)
  282. ld r3,PACA_EXMC+EX_DAR(r13)
  283. lwz r4,PACA_EXMC+EX_DSISR(r13)
  284. /* Enable MSR_RI when finished with PACA_EXMC */
  285. li r10,MSR_RI
  286. mtmsrd r10,1
  287. std r3,_DAR(r1)
  288. std r4,_DSISR(r1)
  289. bl save_nvgprs
  290. addi r3,r1,STACK_FRAME_OVERHEAD
  291. bl machine_check_exception
  292. b ret_from_except
  293. #define MACHINE_CHECK_HANDLER_WINDUP \
  294. /* Clear MSR_RI before setting SRR0 and SRR1. */\
  295. li r0,MSR_RI; \
  296. mfmsr r9; /* get MSR value */ \
  297. andc r9,r9,r0; \
  298. mtmsrd r9,1; /* Clear MSR_RI */ \
  299. /* Move original SRR0 and SRR1 into the respective regs */ \
  300. ld r9,_MSR(r1); \
  301. mtspr SPRN_SRR1,r9; \
  302. ld r3,_NIP(r1); \
  303. mtspr SPRN_SRR0,r3; \
  304. ld r9,_CTR(r1); \
  305. mtctr r9; \
  306. ld r9,_XER(r1); \
  307. mtxer r9; \
  308. ld r9,_LINK(r1); \
  309. mtlr r9; \
  310. REST_GPR(0, r1); \
  311. REST_8GPRS(2, r1); \
  312. REST_GPR(10, r1); \
  313. ld r11,_CCR(r1); \
  314. mtcr r11; \
  315. /* Decrement paca->in_mce. */ \
  316. lhz r12,PACA_IN_MCE(r13); \
  317. subi r12,r12,1; \
  318. sth r12,PACA_IN_MCE(r13); \
  319. REST_GPR(11, r1); \
  320. REST_2GPRS(12, r1); \
  321. /* restore original r1. */ \
  322. ld r1,GPR1(r1)
  323. #ifdef CONFIG_PPC_P7_NAP
  324. /*
  325. * This is an idle wakeup. Low level machine check has already been
  326. * done. Queue the event then call the idle code to do the wake up.
  327. */
  328. EXC_COMMON_BEGIN(machine_check_idle_common)
  329. bl machine_check_queue_event
  330. /*
  331. * We have not used any non-volatile GPRs here, and as a rule
  332. * most exception code including machine check does not.
  333. * Therefore PACA_NAPSTATELOST does not need to be set. Idle
  334. * wakeup will restore volatile registers.
  335. *
  336. * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
  337. *
  338. * Then decrement MCE nesting after finishing with the stack.
  339. */
  340. ld r3,_MSR(r1)
  341. lhz r11,PACA_IN_MCE(r13)
  342. subi r11,r11,1
  343. sth r11,PACA_IN_MCE(r13)
  344. /* Turn off the RI bit because SRR1 is used by idle wakeup code. */
  345. /* Recoverability could be improved by reducing the use of SRR1. */
  346. li r11,0
  347. mtmsrd r11,1
  348. b pnv_powersave_wakeup_mce
  349. #endif
  350. /*
  351. * Handle machine check early in real mode. We come here with
  352. * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
  353. */
  354. EXC_COMMON_BEGIN(machine_check_handle_early)
  355. std r0,GPR0(r1) /* Save r0 */
  356. EXCEPTION_PROLOG_COMMON_3(0x200)
  357. bl save_nvgprs
  358. addi r3,r1,STACK_FRAME_OVERHEAD
  359. bl machine_check_early
  360. std r3,RESULT(r1) /* Save result */
  361. ld r12,_MSR(r1)
  362. #ifdef CONFIG_PPC_P7_NAP
  363. /*
  364. * Check if thread was in power saving mode. We come here when any
  365. * of the following is true:
  366. * a. thread wasn't in power saving mode
  367. * b. thread was in power saving mode with no state loss,
  368. * supervisor state loss or hypervisor state loss.
  369. *
  370. * Go back to nap/sleep/winkle mode again if (b) is true.
  371. */
  372. BEGIN_FTR_SECTION
  373. rlwinm. r11,r12,47-31,30,31
  374. bne machine_check_idle_common
  375. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  376. #endif
  377. /*
  378. * Check if we are coming from hypervisor userspace. If yes then we
  379. * continue in host kernel in V mode to deliver the MC event.
  380. */
  381. rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
  382. beq 5f
  383. andi. r11,r12,MSR_PR /* See if coming from user. */
  384. bne 9f /* continue in V mode if we are. */
  385. 5:
  386. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  387. /*
  388. * We are coming from kernel context. Check if we are coming from
  389. * guest. if yes, then we can continue. We will fall through
  390. * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
  391. */
  392. lbz r11,HSTATE_IN_GUEST(r13)
  393. cmpwi r11,0 /* Check if coming from guest */
  394. bne 9f /* continue if we are. */
  395. #endif
  396. /*
  397. * At this point we are not sure about what context we come from.
  398. * Queue up the MCE event and return from the interrupt.
  399. * But before that, check if this is an un-recoverable exception.
  400. * If yes, then stay on emergency stack and panic.
  401. */
  402. andi. r11,r12,MSR_RI
  403. bne 2f
  404. 1: mfspr r11,SPRN_SRR0
  405. LOAD_HANDLER(r10,unrecover_mce)
  406. mtspr SPRN_SRR0,r10
  407. ld r10,PACAKMSR(r13)
  408. /*
  409. * We are going down. But there are chances that we might get hit by
  410. * another MCE during panic path and we may run into unstable state
  411. * with no way out. Hence, turn ME bit off while going down, so that
  412. * when another MCE is hit during panic path, system will checkstop
  413. * and hypervisor will get restarted cleanly by SP.
  414. */
  415. li r3,MSR_ME
  416. andc r10,r10,r3 /* Turn off MSR_ME */
  417. mtspr SPRN_SRR1,r10
  418. rfid
  419. b .
  420. 2:
  421. /*
  422. * Check if we have successfully handled/recovered from error, if not
  423. * then stay on emergency stack and panic.
  424. */
  425. ld r3,RESULT(r1) /* Load result */
  426. cmpdi r3,0 /* see if we handled MCE successfully */
  427. beq 1b /* if !handled then panic */
  428. /*
  429. * Return from MC interrupt.
  430. * Queue up the MCE event so that we can log it later, while
  431. * returning from kernel or opal call.
  432. */
  433. bl machine_check_queue_event
  434. MACHINE_CHECK_HANDLER_WINDUP
  435. rfid
  436. 9:
  437. /* Deliver the machine check to host kernel in V mode. */
  438. MACHINE_CHECK_HANDLER_WINDUP
  439. b machine_check_pSeries
  440. EXC_COMMON_BEGIN(unrecover_mce)
  441. /* Invoke machine_check_exception to print MCE event and panic. */
  442. addi r3,r1,STACK_FRAME_OVERHEAD
  443. bl machine_check_exception
  444. /*
  445. * We will not reach here. Even if we did, there is no way out. Call
  446. * unrecoverable_exception and die.
  447. */
  448. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  449. bl unrecoverable_exception
  450. b 1b
  451. EXC_REAL(data_access, 0x300, 0x80)
  452. EXC_VIRT(data_access, 0x4300, 0x80, 0x300)
  453. TRAMP_KVM_SKIP(PACA_EXGEN, 0x300)
  454. EXC_COMMON_BEGIN(data_access_common)
  455. /*
  456. * Here r13 points to the paca, r9 contains the saved CR,
  457. * SRR0 and SRR1 are saved in r11 and r12,
  458. * r9 - r13 are saved in paca->exgen.
  459. */
  460. mfspr r10,SPRN_DAR
  461. std r10,PACA_EXGEN+EX_DAR(r13)
  462. mfspr r10,SPRN_DSISR
  463. stw r10,PACA_EXGEN+EX_DSISR(r13)
  464. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  465. RECONCILE_IRQ_STATE(r10, r11)
  466. ld r12,_MSR(r1)
  467. ld r3,PACA_EXGEN+EX_DAR(r13)
  468. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  469. li r5,0x300
  470. std r3,_DAR(r1)
  471. std r4,_DSISR(r1)
  472. BEGIN_MMU_FTR_SECTION
  473. b do_hash_page /* Try to handle as hpte fault */
  474. MMU_FTR_SECTION_ELSE
  475. b handle_page_fault
  476. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  477. EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
  478. SET_SCRATCH0(r13)
  479. EXCEPTION_PROLOG_0(PACA_EXSLB)
  480. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x380)
  481. mr r12,r3 /* save r3 */
  482. mfspr r3,SPRN_DAR
  483. mfspr r11,SPRN_SRR1
  484. crset 4*cr6+eq
  485. BRANCH_TO_COMMON(r10, slb_miss_common)
  486. EXC_REAL_END(data_access_slb, 0x380, 0x80)
  487. EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
  488. SET_SCRATCH0(r13)
  489. EXCEPTION_PROLOG_0(PACA_EXSLB)
  490. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
  491. mr r12,r3 /* save r3 */
  492. mfspr r3,SPRN_DAR
  493. mfspr r11,SPRN_SRR1
  494. crset 4*cr6+eq
  495. BRANCH_TO_COMMON(r10, slb_miss_common)
  496. EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
  497. TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
  498. EXC_REAL(instruction_access, 0x400, 0x80)
  499. EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400)
  500. TRAMP_KVM(PACA_EXGEN, 0x400)
  501. EXC_COMMON_BEGIN(instruction_access_common)
  502. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  503. RECONCILE_IRQ_STATE(r10, r11)
  504. ld r12,_MSR(r1)
  505. ld r3,_NIP(r1)
  506. andis. r4,r12,DSISR_BAD_FAULT_64S@h
  507. li r5,0x400
  508. std r3,_DAR(r1)
  509. std r4,_DSISR(r1)
  510. BEGIN_MMU_FTR_SECTION
  511. b do_hash_page /* Try to handle as hpte fault */
  512. MMU_FTR_SECTION_ELSE
  513. b handle_page_fault
  514. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  515. EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80)
  516. SET_SCRATCH0(r13)
  517. EXCEPTION_PROLOG_0(PACA_EXSLB)
  518. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
  519. mr r12,r3 /* save r3 */
  520. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  521. mfspr r11,SPRN_SRR1
  522. crclr 4*cr6+eq
  523. BRANCH_TO_COMMON(r10, slb_miss_common)
  524. EXC_REAL_END(instruction_access_slb, 0x480, 0x80)
  525. EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
  526. SET_SCRATCH0(r13)
  527. EXCEPTION_PROLOG_0(PACA_EXSLB)
  528. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
  529. mr r12,r3 /* save r3 */
  530. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  531. mfspr r11,SPRN_SRR1
  532. crclr 4*cr6+eq
  533. BRANCH_TO_COMMON(r10, slb_miss_common)
  534. EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)
  535. TRAMP_KVM(PACA_EXSLB, 0x480)
  536. /*
  537. * This handler is used by the 0x380 and 0x480 SLB miss interrupts, as well as
  538. * the virtual mode 0x4380 and 0x4480 interrupts if AIL is enabled.
  539. */
  540. EXC_COMMON_BEGIN(slb_miss_common)
  541. /*
  542. * r13 points to the PACA, r9 contains the saved CR,
  543. * r12 contains the saved r3,
  544. * r11 contain the saved SRR1, SRR0 is still ready for return
  545. * r3 has the faulting address
  546. * r9 - r13 are saved in paca->exslb.
  547. * cr6.eq is set for a D-SLB miss, clear for a I-SLB miss
  548. * We assume we aren't going to take any exceptions during this
  549. * procedure.
  550. */
  551. mflr r10
  552. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  553. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  554. /*
  555. * Test MSR_RI before calling slb_allocate_realmode, because the
  556. * MSR in r11 gets clobbered. However we still want to allocate
  557. * SLB in case MSR_RI=0, to minimise the risk of getting stuck in
  558. * recursive SLB faults. So use cr5 for this, which is preserved.
  559. */
  560. andi. r11,r11,MSR_RI /* check for unrecoverable exception */
  561. cmpdi cr5,r11,MSR_RI
  562. crset 4*cr0+eq
  563. #ifdef CONFIG_PPC_STD_MMU_64
  564. BEGIN_MMU_FTR_SECTION
  565. bl slb_allocate
  566. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
  567. #endif
  568. ld r10,PACA_EXSLB+EX_LR(r13)
  569. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  570. mtlr r10
  571. beq- 8f /* if bad address, make full stack frame */
  572. bne- cr5,2f /* if unrecoverable exception, oops */
  573. /* All done -- return from exception. */
  574. .machine push
  575. .machine "power4"
  576. mtcrf 0x80,r9
  577. mtcrf 0x04,r9 /* MSR[RI] indication is in cr5 */
  578. mtcrf 0x02,r9 /* I/D indication is in cr6 */
  579. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  580. .machine pop
  581. RESTORE_CTR(r9, PACA_EXSLB)
  582. RESTORE_PPR_PACA(PACA_EXSLB, r9)
  583. mr r3,r12
  584. ld r9,PACA_EXSLB+EX_R9(r13)
  585. ld r10,PACA_EXSLB+EX_R10(r13)
  586. ld r11,PACA_EXSLB+EX_R11(r13)
  587. ld r12,PACA_EXSLB+EX_R12(r13)
  588. ld r13,PACA_EXSLB+EX_R13(r13)
  589. rfid
  590. b . /* prevent speculative execution */
  591. 2: std r3,PACA_EXSLB+EX_DAR(r13)
  592. mr r3,r12
  593. mfspr r11,SPRN_SRR0
  594. mfspr r12,SPRN_SRR1
  595. LOAD_HANDLER(r10,unrecov_slb)
  596. mtspr SPRN_SRR0,r10
  597. ld r10,PACAKMSR(r13)
  598. mtspr SPRN_SRR1,r10
  599. rfid
  600. b .
  601. 8: std r3,PACA_EXSLB+EX_DAR(r13)
  602. mr r3,r12
  603. mfspr r11,SPRN_SRR0
  604. mfspr r12,SPRN_SRR1
  605. LOAD_HANDLER(r10,bad_addr_slb)
  606. mtspr SPRN_SRR0,r10
  607. ld r10,PACAKMSR(r13)
  608. mtspr SPRN_SRR1,r10
  609. rfid
  610. b .
  611. EXC_COMMON_BEGIN(unrecov_slb)
  612. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  613. RECONCILE_IRQ_STATE(r10, r11)
  614. bl save_nvgprs
  615. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  616. bl unrecoverable_exception
  617. b 1b
  618. EXC_COMMON_BEGIN(bad_addr_slb)
  619. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
  620. RECONCILE_IRQ_STATE(r10, r11)
  621. ld r3, PACA_EXSLB+EX_DAR(r13)
  622. std r3, _DAR(r1)
  623. beq cr6, 2f
  624. li r10, 0x480 /* fix trap number for I-SLB miss */
  625. std r10, _TRAP(r1)
  626. 2: bl save_nvgprs
  627. addi r3, r1, STACK_FRAME_OVERHEAD
  628. bl slb_miss_bad_addr
  629. b ret_from_except
  630. EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
  631. .globl hardware_interrupt_hv;
  632. hardware_interrupt_hv:
  633. BEGIN_FTR_SECTION
  634. _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
  635. EXC_HV, SOFTEN_TEST_HV)
  636. FTR_SECTION_ELSE
  637. _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
  638. EXC_STD, SOFTEN_TEST_PR)
  639. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  640. EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
  641. EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
  642. .globl hardware_interrupt_relon_hv;
  643. hardware_interrupt_relon_hv:
  644. BEGIN_FTR_SECTION
  645. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_HV, SOFTEN_TEST_HV)
  646. FTR_SECTION_ELSE
  647. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_STD, SOFTEN_TEST_PR)
  648. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  649. EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
  650. TRAMP_KVM(PACA_EXGEN, 0x500)
  651. TRAMP_KVM_HV(PACA_EXGEN, 0x500)
  652. EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
  653. EXC_REAL(alignment, 0x600, 0x100)
  654. EXC_VIRT(alignment, 0x4600, 0x100, 0x600)
  655. TRAMP_KVM(PACA_EXGEN, 0x600)
  656. EXC_COMMON_BEGIN(alignment_common)
  657. mfspr r10,SPRN_DAR
  658. std r10,PACA_EXGEN+EX_DAR(r13)
  659. mfspr r10,SPRN_DSISR
  660. stw r10,PACA_EXGEN+EX_DSISR(r13)
  661. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  662. ld r3,PACA_EXGEN+EX_DAR(r13)
  663. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  664. std r3,_DAR(r1)
  665. std r4,_DSISR(r1)
  666. bl save_nvgprs
  667. RECONCILE_IRQ_STATE(r10, r11)
  668. addi r3,r1,STACK_FRAME_OVERHEAD
  669. bl alignment_exception
  670. b ret_from_except
  671. EXC_REAL(program_check, 0x700, 0x100)
  672. EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
  673. TRAMP_KVM(PACA_EXGEN, 0x700)
  674. EXC_COMMON_BEGIN(program_check_common)
  675. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  676. bl save_nvgprs
  677. RECONCILE_IRQ_STATE(r10, r11)
  678. addi r3,r1,STACK_FRAME_OVERHEAD
  679. bl program_check_exception
  680. b ret_from_except
  681. EXC_REAL(fp_unavailable, 0x800, 0x100)
  682. EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
  683. TRAMP_KVM(PACA_EXGEN, 0x800)
  684. EXC_COMMON_BEGIN(fp_unavailable_common)
  685. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  686. bne 1f /* if from user, just load it up */
  687. bl save_nvgprs
  688. RECONCILE_IRQ_STATE(r10, r11)
  689. addi r3,r1,STACK_FRAME_OVERHEAD
  690. bl kernel_fp_unavailable_exception
  691. BUG_OPCODE
  692. 1:
  693. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  694. BEGIN_FTR_SECTION
  695. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  696. * transaction), go do TM stuff
  697. */
  698. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  699. bne- 2f
  700. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  701. #endif
  702. bl load_up_fpu
  703. b fast_exception_return
  704. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  705. 2: /* User process was in a transaction */
  706. bl save_nvgprs
  707. RECONCILE_IRQ_STATE(r10, r11)
  708. addi r3,r1,STACK_FRAME_OVERHEAD
  709. bl fp_unavailable_tm
  710. b ret_from_except
  711. #endif
  712. EXC_REAL_MASKABLE(decrementer, 0x900, 0x80)
  713. EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900)
  714. TRAMP_KVM(PACA_EXGEN, 0x900)
  715. EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
  716. EXC_REAL_HV(hdecrementer, 0x980, 0x80)
  717. EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
  718. TRAMP_KVM_HV(PACA_EXGEN, 0x980)
  719. EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
  720. EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100)
  721. EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00)
  722. TRAMP_KVM(PACA_EXGEN, 0xa00)
  723. #ifdef CONFIG_PPC_DOORBELL
  724. EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
  725. #else
  726. EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
  727. #endif
  728. EXC_REAL(trap_0b, 0xb00, 0x100)
  729. EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
  730. TRAMP_KVM(PACA_EXGEN, 0xb00)
  731. EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
  732. /*
  733. * system call / hypercall (0xc00, 0x4c00)
  734. *
  735. * The system call exception is invoked with "sc 0" and does not alter HV bit.
  736. * There is support for kernel code to invoke system calls but there are no
  737. * in-tree users.
  738. *
  739. * The hypercall is invoked with "sc 1" and sets HV=1.
  740. *
  741. * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
  742. * 0x4c00 virtual mode.
  743. *
  744. * Call convention:
  745. *
  746. * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
  747. *
  748. * For hypercalls, the register convention is as follows:
  749. * r0 volatile
  750. * r1-2 nonvolatile
  751. * r3 volatile parameter and return value for status
  752. * r4-r10 volatile input and output value
  753. * r11 volatile hypercall number and output value
  754. * r12 volatile input and output value
  755. * r13-r31 nonvolatile
  756. * LR nonvolatile
  757. * CTR volatile
  758. * XER volatile
  759. * CR0-1 CR5-7 volatile
  760. * CR2-4 nonvolatile
  761. * Other registers nonvolatile
  762. *
  763. * The intersection of volatile registers that don't contain possible
  764. * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
  765. * without saving, though xer is not a good idea to use, as hardware may
  766. * interpret some bits so it may be costly to change them.
  767. */
  768. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  769. /*
  770. * There is a little bit of juggling to get syscall and hcall
  771. * working well. Save r13 in ctr to avoid using SPRG scratch
  772. * register.
  773. *
  774. * Userspace syscalls have already saved the PPR, hcalls must save
  775. * it before setting HMT_MEDIUM.
  776. */
  777. #define SYSCALL_KVMTEST \
  778. mtctr r13; \
  779. GET_PACA(r13); \
  780. std r10,PACA_EXGEN+EX_R10(r13); \
  781. KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
  782. HMT_MEDIUM; \
  783. mfctr r9;
  784. #else
  785. #define SYSCALL_KVMTEST \
  786. HMT_MEDIUM; \
  787. mr r9,r13; \
  788. GET_PACA(r13);
  789. #endif
  790. #define LOAD_SYSCALL_HANDLER(reg) \
  791. __LOAD_HANDLER(reg, system_call_common)
  792. /*
  793. * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9,
  794. * and HMT_MEDIUM.
  795. */
  796. #define SYSCALL_REAL \
  797. mfspr r11,SPRN_SRR0 ; \
  798. mfspr r12,SPRN_SRR1 ; \
  799. LOAD_SYSCALL_HANDLER(r10) ; \
  800. mtspr SPRN_SRR0,r10 ; \
  801. ld r10,PACAKMSR(r13) ; \
  802. mtspr SPRN_SRR1,r10 ; \
  803. rfid ; \
  804. b . ; /* prevent speculative execution */
  805. #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
  806. #define SYSCALL_FASTENDIAN_TEST \
  807. BEGIN_FTR_SECTION \
  808. cmpdi r0,0x1ebe ; \
  809. beq- 1f ; \
  810. END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
  811. #define SYSCALL_FASTENDIAN \
  812. /* Fast LE/BE switch system call */ \
  813. 1: mfspr r12,SPRN_SRR1 ; \
  814. xori r12,r12,MSR_LE ; \
  815. mtspr SPRN_SRR1,r12 ; \
  816. mr r13,r9 ; \
  817. rfid ; /* return to userspace */ \
  818. b . ; /* prevent speculative execution */
  819. #else
  820. #define SYSCALL_FASTENDIAN_TEST
  821. #define SYSCALL_FASTENDIAN
  822. #endif /* CONFIG_PPC_FAST_ENDIAN_SWITCH */
  823. #if defined(CONFIG_RELOCATABLE)
  824. /*
  825. * We can't branch directly so we do it via the CTR which
  826. * is volatile across system calls.
  827. */
  828. #define SYSCALL_VIRT \
  829. LOAD_SYSCALL_HANDLER(r10) ; \
  830. mtctr r10 ; \
  831. mfspr r11,SPRN_SRR0 ; \
  832. mfspr r12,SPRN_SRR1 ; \
  833. li r10,MSR_RI ; \
  834. mtmsrd r10,1 ; \
  835. bctr ;
  836. #else
  837. /* We can branch directly */
  838. #define SYSCALL_VIRT \
  839. mfspr r11,SPRN_SRR0 ; \
  840. mfspr r12,SPRN_SRR1 ; \
  841. li r10,MSR_RI ; \
  842. mtmsrd r10,1 ; /* Set RI (EE=0) */ \
  843. b system_call_common ;
  844. #endif
  845. EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
  846. SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
  847. SYSCALL_FASTENDIAN_TEST
  848. SYSCALL_REAL
  849. SYSCALL_FASTENDIAN
  850. EXC_REAL_END(system_call, 0xc00, 0x100)
  851. EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
  852. SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
  853. SYSCALL_FASTENDIAN_TEST
  854. SYSCALL_VIRT
  855. SYSCALL_FASTENDIAN
  856. EXC_VIRT_END(system_call, 0x4c00, 0x100)
  857. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  858. /*
  859. * This is a hcall, so register convention is as above, with these
  860. * differences:
  861. * r13 = PACA
  862. * ctr = orig r13
  863. * orig r10 saved in PACA
  864. */
  865. TRAMP_KVM_BEGIN(do_kvm_0xc00)
  866. /*
  867. * Save the PPR (on systems that support it) before changing to
  868. * HMT_MEDIUM. That allows the KVM code to save that value into the
  869. * guest state (it is the guest's PPR value).
  870. */
  871. OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
  872. HMT_MEDIUM
  873. OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
  874. mfctr r10
  875. SET_SCRATCH0(r10)
  876. std r9,PACA_EXGEN+EX_R9(r13)
  877. mfcr r9
  878. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
  879. #endif
  880. EXC_REAL(single_step, 0xd00, 0x100)
  881. EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
  882. TRAMP_KVM(PACA_EXGEN, 0xd00)
  883. EXC_COMMON(single_step_common, 0xd00, single_step_exception)
  884. EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
  885. EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
  886. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
  887. EXC_COMMON_BEGIN(h_data_storage_common)
  888. mfspr r10,SPRN_HDAR
  889. std r10,PACA_EXGEN+EX_DAR(r13)
  890. mfspr r10,SPRN_HDSISR
  891. stw r10,PACA_EXGEN+EX_DSISR(r13)
  892. EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
  893. bl save_nvgprs
  894. RECONCILE_IRQ_STATE(r10, r11)
  895. addi r3,r1,STACK_FRAME_OVERHEAD
  896. bl unknown_exception
  897. b ret_from_except
  898. EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
  899. EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
  900. TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
  901. EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
  902. EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
  903. EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
  904. TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
  905. EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
  906. /*
  907. * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
  908. * first, and then eventaully from there to the trampoline to get into virtual
  909. * mode.
  910. */
  911. __EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
  912. __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60)
  913. EXC_VIRT_NONE(0x4e60, 0x20)
  914. TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
  915. TRAMP_REAL_BEGIN(hmi_exception_early)
  916. EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
  917. mr r10,r1 /* Save r1 */
  918. ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
  919. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  920. mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
  921. mfspr r12,SPRN_HSRR1 /* Save HSRR1 */
  922. EXCEPTION_PROLOG_COMMON_1()
  923. EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
  924. EXCEPTION_PROLOG_COMMON_3(0xe60)
  925. addi r3,r1,STACK_FRAME_OVERHEAD
  926. BRANCH_LINK_TO_FAR(hmi_exception_realmode) /* Function call ABI */
  927. cmpdi cr0,r3,0
  928. /* Windup the stack. */
  929. /* Move original HSRR0 and HSRR1 into the respective regs */
  930. ld r9,_MSR(r1)
  931. mtspr SPRN_HSRR1,r9
  932. ld r3,_NIP(r1)
  933. mtspr SPRN_HSRR0,r3
  934. ld r9,_CTR(r1)
  935. mtctr r9
  936. ld r9,_XER(r1)
  937. mtxer r9
  938. ld r9,_LINK(r1)
  939. mtlr r9
  940. REST_GPR(0, r1)
  941. REST_8GPRS(2, r1)
  942. REST_GPR(10, r1)
  943. ld r11,_CCR(r1)
  944. REST_2GPRS(12, r1)
  945. bne 1f
  946. mtcr r11
  947. REST_GPR(11, r1)
  948. ld r1,GPR1(r1)
  949. hrfid
  950. 1: mtcr r11
  951. REST_GPR(11, r1)
  952. ld r1,GPR1(r1)
  953. /*
  954. * Go to virtual mode and pull the HMI event information from
  955. * firmware.
  956. */
  957. .globl hmi_exception_after_realmode
  958. hmi_exception_after_realmode:
  959. SET_SCRATCH0(r13)
  960. EXCEPTION_PROLOG_0(PACA_EXGEN)
  961. b tramp_real_hmi_exception
  962. EXC_COMMON_BEGIN(hmi_exception_common)
  963. EXCEPTION_COMMON(PACA_EXGEN, 0xe60, hmi_exception_common, handle_hmi_exception,
  964. ret_from_except, FINISH_NAP;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON)
  965. EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20)
  966. EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80)
  967. TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
  968. #ifdef CONFIG_PPC_DOORBELL
  969. EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
  970. #else
  971. EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
  972. #endif
  973. EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20)
  974. EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0)
  975. TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
  976. EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
  977. EXC_REAL_NONE(0xec0, 0x20)
  978. EXC_VIRT_NONE(0x4ec0, 0x20)
  979. EXC_REAL_NONE(0xee0, 0x20)
  980. EXC_VIRT_NONE(0x4ee0, 0x20)
  981. EXC_REAL_OOL(performance_monitor, 0xf00, 0x20)
  982. EXC_VIRT_OOL(performance_monitor, 0x4f00, 0x20, 0xf00)
  983. TRAMP_KVM(PACA_EXGEN, 0xf00)
  984. EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
  985. EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
  986. EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
  987. TRAMP_KVM(PACA_EXGEN, 0xf20)
  988. EXC_COMMON_BEGIN(altivec_unavailable_common)
  989. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  990. #ifdef CONFIG_ALTIVEC
  991. BEGIN_FTR_SECTION
  992. beq 1f
  993. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  994. BEGIN_FTR_SECTION_NESTED(69)
  995. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  996. * transaction), go do TM stuff
  997. */
  998. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  999. bne- 2f
  1000. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1001. #endif
  1002. bl load_up_altivec
  1003. b fast_exception_return
  1004. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1005. 2: /* User process was in a transaction */
  1006. bl save_nvgprs
  1007. RECONCILE_IRQ_STATE(r10, r11)
  1008. addi r3,r1,STACK_FRAME_OVERHEAD
  1009. bl altivec_unavailable_tm
  1010. b ret_from_except
  1011. #endif
  1012. 1:
  1013. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1014. #endif
  1015. bl save_nvgprs
  1016. RECONCILE_IRQ_STATE(r10, r11)
  1017. addi r3,r1,STACK_FRAME_OVERHEAD
  1018. bl altivec_unavailable_exception
  1019. b ret_from_except
  1020. EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
  1021. EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
  1022. TRAMP_KVM(PACA_EXGEN, 0xf40)
  1023. EXC_COMMON_BEGIN(vsx_unavailable_common)
  1024. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  1025. #ifdef CONFIG_VSX
  1026. BEGIN_FTR_SECTION
  1027. beq 1f
  1028. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1029. BEGIN_FTR_SECTION_NESTED(69)
  1030. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1031. * transaction), go do TM stuff
  1032. */
  1033. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1034. bne- 2f
  1035. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1036. #endif
  1037. b load_up_vsx
  1038. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1039. 2: /* User process was in a transaction */
  1040. bl save_nvgprs
  1041. RECONCILE_IRQ_STATE(r10, r11)
  1042. addi r3,r1,STACK_FRAME_OVERHEAD
  1043. bl vsx_unavailable_tm
  1044. b ret_from_except
  1045. #endif
  1046. 1:
  1047. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1048. #endif
  1049. bl save_nvgprs
  1050. RECONCILE_IRQ_STATE(r10, r11)
  1051. addi r3,r1,STACK_FRAME_OVERHEAD
  1052. bl vsx_unavailable_exception
  1053. b ret_from_except
  1054. EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
  1055. EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
  1056. TRAMP_KVM(PACA_EXGEN, 0xf60)
  1057. EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
  1058. EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
  1059. EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
  1060. TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
  1061. EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
  1062. EXC_REAL_NONE(0xfa0, 0x20)
  1063. EXC_VIRT_NONE(0x4fa0, 0x20)
  1064. EXC_REAL_NONE(0xfc0, 0x20)
  1065. EXC_VIRT_NONE(0x4fc0, 0x20)
  1066. EXC_REAL_NONE(0xfe0, 0x20)
  1067. EXC_VIRT_NONE(0x4fe0, 0x20)
  1068. EXC_REAL_NONE(0x1000, 0x100)
  1069. EXC_VIRT_NONE(0x5000, 0x100)
  1070. EXC_REAL_NONE(0x1100, 0x100)
  1071. EXC_VIRT_NONE(0x5100, 0x100)
  1072. #ifdef CONFIG_CBE_RAS
  1073. EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
  1074. EXC_VIRT_NONE(0x5200, 0x100)
  1075. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
  1076. EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
  1077. #else /* CONFIG_CBE_RAS */
  1078. EXC_REAL_NONE(0x1200, 0x100)
  1079. EXC_VIRT_NONE(0x5200, 0x100)
  1080. #endif
  1081. EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
  1082. EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
  1083. TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
  1084. EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
  1085. EXC_REAL_NONE(0x1400, 0x100)
  1086. EXC_VIRT_NONE(0x5400, 0x100)
  1087. EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
  1088. mtspr SPRN_SPRG_HSCRATCH0,r13
  1089. EXCEPTION_PROLOG_0(PACA_EXGEN)
  1090. EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
  1091. #ifdef CONFIG_PPC_DENORMALISATION
  1092. mfspr r10,SPRN_HSRR1
  1093. mfspr r11,SPRN_HSRR0 /* save HSRR0 */
  1094. andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
  1095. addi r11,r11,-4 /* HSRR0 is next instruction */
  1096. bne+ denorm_assist
  1097. #endif
  1098. KVMTEST_PR(0x1500)
  1099. EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
  1100. EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
  1101. #ifdef CONFIG_PPC_DENORMALISATION
  1102. EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
  1103. b exc_real_0x1500_denorm_exception_hv
  1104. EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
  1105. #else
  1106. EXC_VIRT_NONE(0x5500, 0x100)
  1107. #endif
  1108. TRAMP_KVM_SKIP(PACA_EXGEN, 0x1500)
  1109. #ifdef CONFIG_PPC_DENORMALISATION
  1110. TRAMP_REAL_BEGIN(denorm_assist)
  1111. BEGIN_FTR_SECTION
  1112. /*
  1113. * To denormalise we need to move a copy of the register to itself.
  1114. * For POWER6 do that here for all FP regs.
  1115. */
  1116. mfmsr r10
  1117. ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
  1118. xori r10,r10,(MSR_FE0|MSR_FE1)
  1119. mtmsrd r10
  1120. sync
  1121. #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
  1122. #define FMR4(n) FMR2(n) ; FMR2(n+2)
  1123. #define FMR8(n) FMR4(n) ; FMR4(n+4)
  1124. #define FMR16(n) FMR8(n) ; FMR8(n+8)
  1125. #define FMR32(n) FMR16(n) ; FMR16(n+16)
  1126. FMR32(0)
  1127. FTR_SECTION_ELSE
  1128. /*
  1129. * To denormalise we need to move a copy of the register to itself.
  1130. * For POWER7 do that here for the first 32 VSX registers only.
  1131. */
  1132. mfmsr r10
  1133. oris r10,r10,MSR_VSX@h
  1134. mtmsrd r10
  1135. sync
  1136. #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
  1137. #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
  1138. #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
  1139. #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
  1140. #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
  1141. XVCPSGNDP32(0)
  1142. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
  1143. BEGIN_FTR_SECTION
  1144. b denorm_done
  1145. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  1146. /*
  1147. * To denormalise we need to move a copy of the register to itself.
  1148. * For POWER8 we need to do that for all 64 VSX registers
  1149. */
  1150. XVCPSGNDP32(32)
  1151. denorm_done:
  1152. mtspr SPRN_HSRR0,r11
  1153. mtcrf 0x80,r9
  1154. ld r9,PACA_EXGEN+EX_R9(r13)
  1155. RESTORE_PPR_PACA(PACA_EXGEN, r10)
  1156. BEGIN_FTR_SECTION
  1157. ld r10,PACA_EXGEN+EX_CFAR(r13)
  1158. mtspr SPRN_CFAR,r10
  1159. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1160. ld r10,PACA_EXGEN+EX_R10(r13)
  1161. ld r11,PACA_EXGEN+EX_R11(r13)
  1162. ld r12,PACA_EXGEN+EX_R12(r13)
  1163. ld r13,PACA_EXGEN+EX_R13(r13)
  1164. HRFID
  1165. b .
  1166. #endif
  1167. EXC_COMMON_HV(denorm_common, 0x1500, unknown_exception)
  1168. #ifdef CONFIG_CBE_RAS
  1169. EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
  1170. EXC_VIRT_NONE(0x5600, 0x100)
  1171. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
  1172. EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
  1173. #else /* CONFIG_CBE_RAS */
  1174. EXC_REAL_NONE(0x1600, 0x100)
  1175. EXC_VIRT_NONE(0x5600, 0x100)
  1176. #endif
  1177. EXC_REAL(altivec_assist, 0x1700, 0x100)
  1178. EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
  1179. TRAMP_KVM(PACA_EXGEN, 0x1700)
  1180. #ifdef CONFIG_ALTIVEC
  1181. EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
  1182. #else
  1183. EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
  1184. #endif
  1185. #ifdef CONFIG_CBE_RAS
  1186. EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
  1187. EXC_VIRT_NONE(0x5800, 0x100)
  1188. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
  1189. EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
  1190. #else /* CONFIG_CBE_RAS */
  1191. EXC_REAL_NONE(0x1800, 0x100)
  1192. EXC_VIRT_NONE(0x5800, 0x100)
  1193. #endif
  1194. #ifdef CONFIG_PPC_WATCHDOG
  1195. #define MASKED_DEC_HANDLER_LABEL 3f
  1196. #define MASKED_DEC_HANDLER(_H) \
  1197. 3: /* soft-nmi */ \
  1198. std r12,PACA_EXGEN+EX_R12(r13); \
  1199. GET_SCRATCH0(r10); \
  1200. std r10,PACA_EXGEN+EX_R13(r13); \
  1201. EXCEPTION_PROLOG_PSERIES_1(soft_nmi_common, _H)
  1202. /*
  1203. * Branch to soft_nmi_interrupt using the emergency stack. The emergency
  1204. * stack is one that is usable by maskable interrupts so long as MSR_EE
  1205. * remains off. It is used for recovery when something has corrupted the
  1206. * normal kernel stack, for example. The "soft NMI" must not use the process
  1207. * stack because we want irq disabled sections to avoid touching the stack
  1208. * at all (other than PMU interrupts), so use the emergency stack for this,
  1209. * and run it entirely with interrupts hard disabled.
  1210. */
  1211. EXC_COMMON_BEGIN(soft_nmi_common)
  1212. mr r10,r1
  1213. ld r1,PACAEMERGSP(r13)
  1214. subi r1,r1,INT_FRAME_SIZE
  1215. EXCEPTION_COMMON_NORET_STACK(PACA_EXGEN, 0x900,
  1216. system_reset, soft_nmi_interrupt,
  1217. ADD_NVGPRS;ADD_RECONCILE)
  1218. b ret_from_except
  1219. #else /* CONFIG_PPC_WATCHDOG */
  1220. #define MASKED_DEC_HANDLER_LABEL 2f /* normal return */
  1221. #define MASKED_DEC_HANDLER(_H)
  1222. #endif /* CONFIG_PPC_WATCHDOG */
  1223. /*
  1224. * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
  1225. * - If it was a decrementer interrupt, we bump the dec to max and and return.
  1226. * - If it was a doorbell we return immediately since doorbells are edge
  1227. * triggered and won't automatically refire.
  1228. * - If it was a HMI we return immediately since we handled it in realmode
  1229. * and it won't refire.
  1230. * - else we hard disable and return.
  1231. * This is called with r10 containing the value to OR to the paca field.
  1232. */
  1233. #define MASKED_INTERRUPT(_H) \
  1234. masked_##_H##interrupt: \
  1235. std r11,PACA_EXGEN+EX_R11(r13); \
  1236. lbz r11,PACAIRQHAPPENED(r13); \
  1237. or r11,r11,r10; \
  1238. stb r11,PACAIRQHAPPENED(r13); \
  1239. cmpwi r10,PACA_IRQ_DEC; \
  1240. bne 1f; \
  1241. lis r10,0x7fff; \
  1242. ori r10,r10,0xffff; \
  1243. mtspr SPRN_DEC,r10; \
  1244. b MASKED_DEC_HANDLER_LABEL; \
  1245. 1: andi. r10,r10,(PACA_IRQ_DBELL|PACA_IRQ_HMI); \
  1246. bne 2f; \
  1247. mfspr r10,SPRN_##_H##SRR1; \
  1248. xori r10,r10,MSR_EE; /* clear MSR_EE */ \
  1249. mtspr SPRN_##_H##SRR1,r10; \
  1250. 2: mtcrf 0x80,r9; \
  1251. ld r9,PACA_EXGEN+EX_R9(r13); \
  1252. ld r10,PACA_EXGEN+EX_R10(r13); \
  1253. ld r11,PACA_EXGEN+EX_R11(r13); \
  1254. /* returns to kernel where r13 must be set up, so don't restore it */ \
  1255. ##_H##rfid; \
  1256. b .; \
  1257. MASKED_DEC_HANDLER(_H)
  1258. /*
  1259. * Real mode exceptions actually use this too, but alternate
  1260. * instruction code patches (which end up in the common .text area)
  1261. * cannot reach these if they are put there.
  1262. */
  1263. USE_FIXED_SECTION(virt_trampolines)
  1264. MASKED_INTERRUPT()
  1265. MASKED_INTERRUPT(H)
  1266. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  1267. TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
  1268. /*
  1269. * Here all GPRs are unchanged from when the interrupt happened
  1270. * except for r13, which is saved in SPRG_SCRATCH0.
  1271. */
  1272. mfspr r13, SPRN_SRR0
  1273. addi r13, r13, 4
  1274. mtspr SPRN_SRR0, r13
  1275. GET_SCRATCH0(r13)
  1276. rfid
  1277. b .
  1278. TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
  1279. /*
  1280. * Here all GPRs are unchanged from when the interrupt happened
  1281. * except for r13, which is saved in SPRG_SCRATCH0.
  1282. */
  1283. mfspr r13, SPRN_HSRR0
  1284. addi r13, r13, 4
  1285. mtspr SPRN_HSRR0, r13
  1286. GET_SCRATCH0(r13)
  1287. hrfid
  1288. b .
  1289. #endif
  1290. /*
  1291. * Ensure that any handlers that get invoked from the exception prologs
  1292. * above are below the first 64KB (0x10000) of the kernel image because
  1293. * the prologs assemble the addresses of these handlers using the
  1294. * LOAD_HANDLER macro, which uses an ori instruction.
  1295. */
  1296. /*** Common interrupt handlers ***/
  1297. /*
  1298. * Relocation-on interrupts: A subset of the interrupts can be delivered
  1299. * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
  1300. * it. Addresses are the same as the original interrupt addresses, but
  1301. * offset by 0xc000000000004000.
  1302. * It's impossible to receive interrupts below 0x300 via this mechanism.
  1303. * KVM: None of these traps are from the guest ; anything that escalated
  1304. * to HV=1 from HV=0 is delivered via real mode handlers.
  1305. */
  1306. /*
  1307. * This uses the standard macro, since the original 0x300 vector
  1308. * only has extra guff for STAB-based processors -- which never
  1309. * come here.
  1310. */
  1311. EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
  1312. b __ppc64_runlatch_on
  1313. USE_FIXED_SECTION(virt_trampolines)
  1314. /*
  1315. * The __end_interrupts marker must be past the out-of-line (OOL)
  1316. * handlers, so that they are copied to real address 0x100 when running
  1317. * a relocatable kernel. This ensures they can be reached from the short
  1318. * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
  1319. * directly, without using LOAD_HANDLER().
  1320. */
  1321. .align 7
  1322. .globl __end_interrupts
  1323. __end_interrupts:
  1324. DEFINE_FIXED_SYMBOL(__end_interrupts)
  1325. #ifdef CONFIG_PPC_970_NAP
  1326. EXC_COMMON_BEGIN(power4_fixup_nap)
  1327. andc r9,r9,r10
  1328. std r9,TI_LOCAL_FLAGS(r11)
  1329. ld r10,_LINK(r1) /* make idle task do the */
  1330. std r10,_NIP(r1) /* equivalent of a blr */
  1331. blr
  1332. #endif
  1333. CLOSE_FIXED_SECTION(real_vectors);
  1334. CLOSE_FIXED_SECTION(real_trampolines);
  1335. CLOSE_FIXED_SECTION(virt_vectors);
  1336. CLOSE_FIXED_SECTION(virt_trampolines);
  1337. USE_TEXT_SECTION()
  1338. /*
  1339. * Hash table stuff
  1340. */
  1341. .balign IFETCH_ALIGN_BYTES
  1342. do_hash_page:
  1343. #ifdef CONFIG_PPC_STD_MMU_64
  1344. lis r0,DSISR_BAD_FAULT_64S@h
  1345. ori r0,r0,DSISR_BAD_FAULT_64S@l
  1346. and. r0,r4,r0 /* weird error? */
  1347. bne- handle_page_fault /* if not, try to insert a HPTE */
  1348. CURRENT_THREAD_INFO(r11, r1)
  1349. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  1350. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  1351. bne 77f /* then don't call hash_page now */
  1352. /*
  1353. * r3 contains the faulting address
  1354. * r4 msr
  1355. * r5 contains the trap number
  1356. * r6 contains dsisr
  1357. *
  1358. * at return r3 = 0 for success, 1 for page fault, negative for error
  1359. */
  1360. mr r4,r12
  1361. ld r6,_DSISR(r1)
  1362. bl __hash_page /* build HPTE if possible */
  1363. cmpdi r3,0 /* see if __hash_page succeeded */
  1364. /* Success */
  1365. beq fast_exc_return_irq /* Return from exception on success */
  1366. /* Error */
  1367. blt- 13f
  1368. /* Reload DSISR into r4 for the DABR check below */
  1369. ld r4,_DSISR(r1)
  1370. #endif /* CONFIG_PPC_STD_MMU_64 */
  1371. /* Here we have a page fault that hash_page can't handle. */
  1372. handle_page_fault:
  1373. 11: andis. r0,r4,DSISR_DABRMATCH@h
  1374. bne- handle_dabr_fault
  1375. ld r4,_DAR(r1)
  1376. ld r5,_DSISR(r1)
  1377. addi r3,r1,STACK_FRAME_OVERHEAD
  1378. bl do_page_fault
  1379. cmpdi r3,0
  1380. beq+ 12f
  1381. bl save_nvgprs
  1382. mr r5,r3
  1383. addi r3,r1,STACK_FRAME_OVERHEAD
  1384. lwz r4,_DAR(r1)
  1385. bl bad_page_fault
  1386. b ret_from_except
  1387. /* We have a data breakpoint exception - handle it */
  1388. handle_dabr_fault:
  1389. bl save_nvgprs
  1390. ld r4,_DAR(r1)
  1391. ld r5,_DSISR(r1)
  1392. addi r3,r1,STACK_FRAME_OVERHEAD
  1393. bl do_break
  1394. 12: b ret_from_except_lite
  1395. #ifdef CONFIG_PPC_STD_MMU_64
  1396. /* We have a page fault that hash_page could handle but HV refused
  1397. * the PTE insertion
  1398. */
  1399. 13: bl save_nvgprs
  1400. mr r5,r3
  1401. addi r3,r1,STACK_FRAME_OVERHEAD
  1402. ld r4,_DAR(r1)
  1403. bl low_hash_fault
  1404. b ret_from_except
  1405. #endif
  1406. /*
  1407. * We come here as a result of a DSI at a point where we don't want
  1408. * to call hash_page, such as when we are accessing memory (possibly
  1409. * user memory) inside a PMU interrupt that occurred while interrupts
  1410. * were soft-disabled. We want to invoke the exception handler for
  1411. * the access, or panic if there isn't a handler.
  1412. */
  1413. 77: bl save_nvgprs
  1414. mr r4,r3
  1415. addi r3,r1,STACK_FRAME_OVERHEAD
  1416. li r5,SIGSEGV
  1417. bl bad_page_fault
  1418. b ret_from_except
  1419. /*
  1420. * Here we have detected that the kernel stack pointer is bad.
  1421. * R9 contains the saved CR, r13 points to the paca,
  1422. * r10 contains the (bad) kernel stack pointer,
  1423. * r11 and r12 contain the saved SRR0 and SRR1.
  1424. * We switch to using an emergency stack, save the registers there,
  1425. * and call kernel_bad_stack(), which panics.
  1426. */
  1427. bad_stack:
  1428. ld r1,PACAEMERGSP(r13)
  1429. subi r1,r1,64+INT_FRAME_SIZE
  1430. std r9,_CCR(r1)
  1431. std r10,GPR1(r1)
  1432. std r11,_NIP(r1)
  1433. std r12,_MSR(r1)
  1434. mfspr r11,SPRN_DAR
  1435. mfspr r12,SPRN_DSISR
  1436. std r11,_DAR(r1)
  1437. std r12,_DSISR(r1)
  1438. mflr r10
  1439. mfctr r11
  1440. mfxer r12
  1441. std r10,_LINK(r1)
  1442. std r11,_CTR(r1)
  1443. std r12,_XER(r1)
  1444. SAVE_GPR(0,r1)
  1445. SAVE_GPR(2,r1)
  1446. ld r10,EX_R3(r3)
  1447. std r10,GPR3(r1)
  1448. SAVE_GPR(4,r1)
  1449. SAVE_4GPRS(5,r1)
  1450. ld r9,EX_R9(r3)
  1451. ld r10,EX_R10(r3)
  1452. SAVE_2GPRS(9,r1)
  1453. ld r9,EX_R11(r3)
  1454. ld r10,EX_R12(r3)
  1455. ld r11,EX_R13(r3)
  1456. std r9,GPR11(r1)
  1457. std r10,GPR12(r1)
  1458. std r11,GPR13(r1)
  1459. BEGIN_FTR_SECTION
  1460. ld r10,EX_CFAR(r3)
  1461. std r10,ORIG_GPR3(r1)
  1462. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1463. SAVE_8GPRS(14,r1)
  1464. SAVE_10GPRS(22,r1)
  1465. lhz r12,PACA_TRAP_SAVE(r13)
  1466. std r12,_TRAP(r1)
  1467. addi r11,r1,INT_FRAME_SIZE
  1468. std r11,0(r1)
  1469. li r12,0
  1470. std r12,0(r11)
  1471. ld r2,PACATOC(r13)
  1472. ld r11,exception_marker@toc(r2)
  1473. std r12,RESULT(r1)
  1474. std r11,STACK_FRAME_OVERHEAD-16(r1)
  1475. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1476. bl kernel_bad_stack
  1477. b 1b
  1478. _ASM_NOKPROBE_SYMBOL(bad_stack);
  1479. /*
  1480. * When doorbell is triggered from system reset wakeup, the message is
  1481. * not cleared, so it would fire again when EE is enabled.
  1482. *
  1483. * When coming from local_irq_enable, there may be the same problem if
  1484. * we were hard disabled.
  1485. *
  1486. * Execute msgclr to clear pending exceptions before handling it.
  1487. */
  1488. h_doorbell_common_msgclr:
  1489. LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
  1490. PPC_MSGCLR(3)
  1491. b h_doorbell_common
  1492. doorbell_super_common_msgclr:
  1493. LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
  1494. PPC_MSGCLRP(3)
  1495. b doorbell_super_common
  1496. /*
  1497. * Called from arch_local_irq_enable when an interrupt needs
  1498. * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
  1499. * which kind of interrupt. MSR:EE is already off. We generate a
  1500. * stackframe like if a real interrupt had happened.
  1501. *
  1502. * Note: While MSR:EE is off, we need to make sure that _MSR
  1503. * in the generated frame has EE set to 1 or the exception
  1504. * handler will not properly re-enable them.
  1505. *
  1506. * Note that we don't specify LR as the NIP (return address) for
  1507. * the interrupt because that would unbalance the return branch
  1508. * predictor.
  1509. */
  1510. _GLOBAL(__replay_interrupt)
  1511. /* We are going to jump to the exception common code which
  1512. * will retrieve various register values from the PACA which
  1513. * we don't give a damn about, so we don't bother storing them.
  1514. */
  1515. mfmsr r12
  1516. LOAD_REG_ADDR(r11, replay_interrupt_return)
  1517. mfcr r9
  1518. ori r12,r12,MSR_EE
  1519. cmpwi r3,0x900
  1520. beq decrementer_common
  1521. cmpwi r3,0x500
  1522. BEGIN_FTR_SECTION
  1523. beq h_virt_irq_common
  1524. FTR_SECTION_ELSE
  1525. beq hardware_interrupt_common
  1526. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300)
  1527. BEGIN_FTR_SECTION
  1528. cmpwi r3,0xa00
  1529. beq h_doorbell_common_msgclr
  1530. cmpwi r3,0xe60
  1531. beq hmi_exception_common
  1532. FTR_SECTION_ELSE
  1533. cmpwi r3,0xa00
  1534. beq doorbell_super_common_msgclr
  1535. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  1536. replay_interrupt_return:
  1537. blr
  1538. _ASM_NOKPROBE_SYMBOL(__replay_interrupt)