exceptions-64s.S 53 KB

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