exceptions-64s.S 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843
  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. FTR_SECTION_ELSE
  661. _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
  662. EXC_STD, SOFTEN_TEST_PR)
  663. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  664. EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
  665. EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
  666. .globl hardware_interrupt_relon_hv;
  667. hardware_interrupt_relon_hv:
  668. BEGIN_FTR_SECTION
  669. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_HV, SOFTEN_TEST_HV)
  670. FTR_SECTION_ELSE
  671. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_STD, SOFTEN_TEST_PR)
  672. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  673. EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
  674. TRAMP_KVM(PACA_EXGEN, 0x500)
  675. TRAMP_KVM_HV(PACA_EXGEN, 0x500)
  676. EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
  677. EXC_REAL(alignment, 0x600, 0x100)
  678. EXC_VIRT(alignment, 0x4600, 0x100, 0x600)
  679. TRAMP_KVM(PACA_EXGEN, 0x600)
  680. EXC_COMMON_BEGIN(alignment_common)
  681. mfspr r10,SPRN_DAR
  682. std r10,PACA_EXGEN+EX_DAR(r13)
  683. mfspr r10,SPRN_DSISR
  684. stw r10,PACA_EXGEN+EX_DSISR(r13)
  685. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  686. ld r3,PACA_EXGEN+EX_DAR(r13)
  687. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  688. std r3,_DAR(r1)
  689. std r4,_DSISR(r1)
  690. bl save_nvgprs
  691. RECONCILE_IRQ_STATE(r10, r11)
  692. addi r3,r1,STACK_FRAME_OVERHEAD
  693. bl alignment_exception
  694. b ret_from_except
  695. EXC_REAL(program_check, 0x700, 0x100)
  696. EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
  697. TRAMP_KVM(PACA_EXGEN, 0x700)
  698. EXC_COMMON_BEGIN(program_check_common)
  699. /*
  700. * It's possible to receive a TM Bad Thing type program check with
  701. * userspace register values (in particular r1), but with SRR1 reporting
  702. * that we came from the kernel. Normally that would confuse the bad
  703. * stack logic, and we would report a bad kernel stack pointer. Instead
  704. * we switch to the emergency stack if we're taking a TM Bad Thing from
  705. * the kernel.
  706. */
  707. li r10,MSR_PR /* Build a mask of MSR_PR .. */
  708. oris r10,r10,0x200000@h /* .. and SRR1_PROGTM */
  709. and r10,r10,r12 /* Mask SRR1 with that. */
  710. srdi r10,r10,8 /* Shift it so we can compare */
  711. cmpldi r10,(0x200000 >> 8) /* .. with an immediate. */
  712. bne 1f /* If != go to normal path. */
  713. /* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack */
  714. andi. r10,r12,MSR_PR; /* Set CR0 correctly for label */
  715. /* 3 in EXCEPTION_PROLOG_COMMON */
  716. mr r10,r1 /* Save r1 */
  717. ld r1,PACAEMERGSP(r13) /* Use emergency stack */
  718. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  719. b 3f /* Jump into the macro !! */
  720. 1: EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  721. bl save_nvgprs
  722. RECONCILE_IRQ_STATE(r10, r11)
  723. addi r3,r1,STACK_FRAME_OVERHEAD
  724. bl program_check_exception
  725. b ret_from_except
  726. EXC_REAL(fp_unavailable, 0x800, 0x100)
  727. EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
  728. TRAMP_KVM(PACA_EXGEN, 0x800)
  729. EXC_COMMON_BEGIN(fp_unavailable_common)
  730. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  731. bne 1f /* if from user, just load it up */
  732. bl save_nvgprs
  733. RECONCILE_IRQ_STATE(r10, r11)
  734. addi r3,r1,STACK_FRAME_OVERHEAD
  735. bl kernel_fp_unavailable_exception
  736. BUG_OPCODE
  737. 1:
  738. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  739. BEGIN_FTR_SECTION
  740. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  741. * transaction), go do TM stuff
  742. */
  743. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  744. bne- 2f
  745. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  746. #endif
  747. bl load_up_fpu
  748. b fast_exception_return
  749. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  750. 2: /* User process was in a transaction */
  751. bl save_nvgprs
  752. RECONCILE_IRQ_STATE(r10, r11)
  753. addi r3,r1,STACK_FRAME_OVERHEAD
  754. bl fp_unavailable_tm
  755. b ret_from_except
  756. #endif
  757. EXC_REAL_MASKABLE(decrementer, 0x900, 0x80)
  758. EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900)
  759. TRAMP_KVM(PACA_EXGEN, 0x900)
  760. EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
  761. EXC_REAL_HV(hdecrementer, 0x980, 0x80)
  762. EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
  763. TRAMP_KVM_HV(PACA_EXGEN, 0x980)
  764. EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
  765. EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100)
  766. EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00)
  767. TRAMP_KVM(PACA_EXGEN, 0xa00)
  768. #ifdef CONFIG_PPC_DOORBELL
  769. EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
  770. #else
  771. EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
  772. #endif
  773. EXC_REAL(trap_0b, 0xb00, 0x100)
  774. EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
  775. TRAMP_KVM(PACA_EXGEN, 0xb00)
  776. EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
  777. /*
  778. * system call / hypercall (0xc00, 0x4c00)
  779. *
  780. * The system call exception is invoked with "sc 0" and does not alter HV bit.
  781. * There is support for kernel code to invoke system calls but there are no
  782. * in-tree users.
  783. *
  784. * The hypercall is invoked with "sc 1" and sets HV=1.
  785. *
  786. * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
  787. * 0x4c00 virtual mode.
  788. *
  789. * Call convention:
  790. *
  791. * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
  792. *
  793. * For hypercalls, the register convention is as follows:
  794. * r0 volatile
  795. * r1-2 nonvolatile
  796. * r3 volatile parameter and return value for status
  797. * r4-r10 volatile input and output value
  798. * r11 volatile hypercall number and output value
  799. * r12 volatile input and output value
  800. * r13-r31 nonvolatile
  801. * LR nonvolatile
  802. * CTR volatile
  803. * XER volatile
  804. * CR0-1 CR5-7 volatile
  805. * CR2-4 nonvolatile
  806. * Other registers nonvolatile
  807. *
  808. * The intersection of volatile registers that don't contain possible
  809. * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
  810. * without saving, though xer is not a good idea to use, as hardware may
  811. * interpret some bits so it may be costly to change them.
  812. */
  813. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  814. /*
  815. * There is a little bit of juggling to get syscall and hcall
  816. * working well. Save r13 in ctr to avoid using SPRG scratch
  817. * register.
  818. *
  819. * Userspace syscalls have already saved the PPR, hcalls must save
  820. * it before setting HMT_MEDIUM.
  821. */
  822. #define SYSCALL_KVMTEST \
  823. mtctr r13; \
  824. GET_PACA(r13); \
  825. std r10,PACA_EXGEN+EX_R10(r13); \
  826. KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
  827. HMT_MEDIUM; \
  828. mfctr r9;
  829. #else
  830. #define SYSCALL_KVMTEST \
  831. HMT_MEDIUM; \
  832. mr r9,r13; \
  833. GET_PACA(r13);
  834. #endif
  835. #define LOAD_SYSCALL_HANDLER(reg) \
  836. __LOAD_HANDLER(reg, system_call_common)
  837. /*
  838. * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9,
  839. * and HMT_MEDIUM.
  840. */
  841. #define SYSCALL_REAL \
  842. mfspr r11,SPRN_SRR0 ; \
  843. mfspr r12,SPRN_SRR1 ; \
  844. LOAD_SYSCALL_HANDLER(r10) ; \
  845. mtspr SPRN_SRR0,r10 ; \
  846. ld r10,PACAKMSR(r13) ; \
  847. mtspr SPRN_SRR1,r10 ; \
  848. RFI_TO_KERNEL ; \
  849. b . ; /* prevent speculative execution */
  850. #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
  851. #define SYSCALL_FASTENDIAN_TEST \
  852. BEGIN_FTR_SECTION \
  853. cmpdi r0,0x1ebe ; \
  854. beq- 1f ; \
  855. END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
  856. #define SYSCALL_FASTENDIAN \
  857. /* Fast LE/BE switch system call */ \
  858. 1: mfspr r12,SPRN_SRR1 ; \
  859. xori r12,r12,MSR_LE ; \
  860. mtspr SPRN_SRR1,r12 ; \
  861. mr r13,r9 ; \
  862. RFI_TO_USER ; /* return to userspace */ \
  863. b . ; /* prevent speculative execution */
  864. #else
  865. #define SYSCALL_FASTENDIAN_TEST
  866. #define SYSCALL_FASTENDIAN
  867. #endif /* CONFIG_PPC_FAST_ENDIAN_SWITCH */
  868. #if defined(CONFIG_RELOCATABLE)
  869. /*
  870. * We can't branch directly so we do it via the CTR which
  871. * is volatile across system calls.
  872. */
  873. #define SYSCALL_VIRT \
  874. LOAD_SYSCALL_HANDLER(r10) ; \
  875. mtctr r10 ; \
  876. mfspr r11,SPRN_SRR0 ; \
  877. mfspr r12,SPRN_SRR1 ; \
  878. li r10,MSR_RI ; \
  879. mtmsrd r10,1 ; \
  880. bctr ;
  881. #else
  882. /* We can branch directly */
  883. #define SYSCALL_VIRT \
  884. mfspr r11,SPRN_SRR0 ; \
  885. mfspr r12,SPRN_SRR1 ; \
  886. li r10,MSR_RI ; \
  887. mtmsrd r10,1 ; /* Set RI (EE=0) */ \
  888. b system_call_common ;
  889. #endif
  890. EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
  891. SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
  892. SYSCALL_FASTENDIAN_TEST
  893. SYSCALL_REAL
  894. SYSCALL_FASTENDIAN
  895. EXC_REAL_END(system_call, 0xc00, 0x100)
  896. EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
  897. SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
  898. SYSCALL_FASTENDIAN_TEST
  899. SYSCALL_VIRT
  900. SYSCALL_FASTENDIAN
  901. EXC_VIRT_END(system_call, 0x4c00, 0x100)
  902. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  903. /*
  904. * This is a hcall, so register convention is as above, with these
  905. * differences:
  906. * r13 = PACA
  907. * ctr = orig r13
  908. * orig r10 saved in PACA
  909. */
  910. TRAMP_KVM_BEGIN(do_kvm_0xc00)
  911. /*
  912. * Save the PPR (on systems that support it) before changing to
  913. * HMT_MEDIUM. That allows the KVM code to save that value into the
  914. * guest state (it is the guest's PPR value).
  915. */
  916. OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
  917. HMT_MEDIUM
  918. OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
  919. mfctr r10
  920. SET_SCRATCH0(r10)
  921. std r9,PACA_EXGEN+EX_R9(r13)
  922. mfcr r9
  923. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
  924. #endif
  925. EXC_REAL(single_step, 0xd00, 0x100)
  926. EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
  927. TRAMP_KVM(PACA_EXGEN, 0xd00)
  928. EXC_COMMON(single_step_common, 0xd00, single_step_exception)
  929. EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
  930. EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
  931. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
  932. EXC_COMMON_BEGIN(h_data_storage_common)
  933. mfspr r10,SPRN_HDAR
  934. std r10,PACA_EXGEN+EX_DAR(r13)
  935. mfspr r10,SPRN_HDSISR
  936. stw r10,PACA_EXGEN+EX_DSISR(r13)
  937. EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
  938. bl save_nvgprs
  939. RECONCILE_IRQ_STATE(r10, r11)
  940. addi r3,r1,STACK_FRAME_OVERHEAD
  941. bl unknown_exception
  942. b ret_from_except
  943. EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
  944. EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
  945. TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
  946. EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
  947. EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
  948. EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
  949. TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
  950. EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
  951. /*
  952. * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
  953. * first, and then eventaully from there to the trampoline to get into virtual
  954. * mode.
  955. */
  956. __EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
  957. __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60)
  958. EXC_VIRT_NONE(0x4e60, 0x20)
  959. TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
  960. TRAMP_REAL_BEGIN(hmi_exception_early)
  961. EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
  962. mr r10,r1 /* Save r1 */
  963. ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
  964. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  965. mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
  966. mfspr r12,SPRN_HSRR1 /* Save HSRR1 */
  967. EXCEPTION_PROLOG_COMMON_1()
  968. EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
  969. EXCEPTION_PROLOG_COMMON_3(0xe60)
  970. addi r3,r1,STACK_FRAME_OVERHEAD
  971. BRANCH_LINK_TO_FAR(hmi_exception_realmode) /* Function call ABI */
  972. cmpdi cr0,r3,0
  973. /* Windup the stack. */
  974. /* Move original HSRR0 and HSRR1 into the respective regs */
  975. ld r9,_MSR(r1)
  976. mtspr SPRN_HSRR1,r9
  977. ld r3,_NIP(r1)
  978. mtspr SPRN_HSRR0,r3
  979. ld r9,_CTR(r1)
  980. mtctr r9
  981. ld r9,_XER(r1)
  982. mtxer r9
  983. ld r9,_LINK(r1)
  984. mtlr r9
  985. REST_GPR(0, r1)
  986. REST_8GPRS(2, r1)
  987. REST_GPR(10, r1)
  988. ld r11,_CCR(r1)
  989. REST_2GPRS(12, r1)
  990. bne 1f
  991. mtcr r11
  992. REST_GPR(11, r1)
  993. ld r1,GPR1(r1)
  994. HRFI_TO_USER_OR_KERNEL
  995. 1: mtcr r11
  996. REST_GPR(11, r1)
  997. ld r1,GPR1(r1)
  998. /*
  999. * Go to virtual mode and pull the HMI event information from
  1000. * firmware.
  1001. */
  1002. .globl hmi_exception_after_realmode
  1003. hmi_exception_after_realmode:
  1004. SET_SCRATCH0(r13)
  1005. EXCEPTION_PROLOG_0(PACA_EXGEN)
  1006. b tramp_real_hmi_exception
  1007. EXC_COMMON_BEGIN(hmi_exception_common)
  1008. EXCEPTION_COMMON(PACA_EXGEN, 0xe60, hmi_exception_common, handle_hmi_exception,
  1009. ret_from_except, FINISH_NAP;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON)
  1010. EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20)
  1011. EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80)
  1012. TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
  1013. #ifdef CONFIG_PPC_DOORBELL
  1014. EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
  1015. #else
  1016. EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
  1017. #endif
  1018. EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20)
  1019. EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0)
  1020. TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
  1021. EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
  1022. EXC_REAL_NONE(0xec0, 0x20)
  1023. EXC_VIRT_NONE(0x4ec0, 0x20)
  1024. EXC_REAL_NONE(0xee0, 0x20)
  1025. EXC_VIRT_NONE(0x4ee0, 0x20)
  1026. EXC_REAL_OOL(performance_monitor, 0xf00, 0x20)
  1027. EXC_VIRT_OOL(performance_monitor, 0x4f00, 0x20, 0xf00)
  1028. TRAMP_KVM(PACA_EXGEN, 0xf00)
  1029. EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
  1030. EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
  1031. EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
  1032. TRAMP_KVM(PACA_EXGEN, 0xf20)
  1033. EXC_COMMON_BEGIN(altivec_unavailable_common)
  1034. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  1035. #ifdef CONFIG_ALTIVEC
  1036. BEGIN_FTR_SECTION
  1037. beq 1f
  1038. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1039. BEGIN_FTR_SECTION_NESTED(69)
  1040. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1041. * transaction), go do TM stuff
  1042. */
  1043. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1044. bne- 2f
  1045. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1046. #endif
  1047. bl load_up_altivec
  1048. b fast_exception_return
  1049. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1050. 2: /* User process was in a transaction */
  1051. bl save_nvgprs
  1052. RECONCILE_IRQ_STATE(r10, r11)
  1053. addi r3,r1,STACK_FRAME_OVERHEAD
  1054. bl altivec_unavailable_tm
  1055. b ret_from_except
  1056. #endif
  1057. 1:
  1058. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1059. #endif
  1060. bl save_nvgprs
  1061. RECONCILE_IRQ_STATE(r10, r11)
  1062. addi r3,r1,STACK_FRAME_OVERHEAD
  1063. bl altivec_unavailable_exception
  1064. b ret_from_except
  1065. EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
  1066. EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
  1067. TRAMP_KVM(PACA_EXGEN, 0xf40)
  1068. EXC_COMMON_BEGIN(vsx_unavailable_common)
  1069. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  1070. #ifdef CONFIG_VSX
  1071. BEGIN_FTR_SECTION
  1072. beq 1f
  1073. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1074. BEGIN_FTR_SECTION_NESTED(69)
  1075. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1076. * transaction), go do TM stuff
  1077. */
  1078. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1079. bne- 2f
  1080. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1081. #endif
  1082. b load_up_vsx
  1083. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1084. 2: /* User process was in a transaction */
  1085. bl save_nvgprs
  1086. RECONCILE_IRQ_STATE(r10, r11)
  1087. addi r3,r1,STACK_FRAME_OVERHEAD
  1088. bl vsx_unavailable_tm
  1089. b ret_from_except
  1090. #endif
  1091. 1:
  1092. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1093. #endif
  1094. bl save_nvgprs
  1095. RECONCILE_IRQ_STATE(r10, r11)
  1096. addi r3,r1,STACK_FRAME_OVERHEAD
  1097. bl vsx_unavailable_exception
  1098. b ret_from_except
  1099. EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
  1100. EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
  1101. TRAMP_KVM(PACA_EXGEN, 0xf60)
  1102. EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
  1103. EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
  1104. EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
  1105. TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
  1106. EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
  1107. EXC_REAL_NONE(0xfa0, 0x20)
  1108. EXC_VIRT_NONE(0x4fa0, 0x20)
  1109. EXC_REAL_NONE(0xfc0, 0x20)
  1110. EXC_VIRT_NONE(0x4fc0, 0x20)
  1111. EXC_REAL_NONE(0xfe0, 0x20)
  1112. EXC_VIRT_NONE(0x4fe0, 0x20)
  1113. EXC_REAL_NONE(0x1000, 0x100)
  1114. EXC_VIRT_NONE(0x5000, 0x100)
  1115. EXC_REAL_NONE(0x1100, 0x100)
  1116. EXC_VIRT_NONE(0x5100, 0x100)
  1117. #ifdef CONFIG_CBE_RAS
  1118. EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
  1119. EXC_VIRT_NONE(0x5200, 0x100)
  1120. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
  1121. EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
  1122. #else /* CONFIG_CBE_RAS */
  1123. EXC_REAL_NONE(0x1200, 0x100)
  1124. EXC_VIRT_NONE(0x5200, 0x100)
  1125. #endif
  1126. EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
  1127. EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
  1128. TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
  1129. EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
  1130. EXC_REAL_NONE(0x1400, 0x100)
  1131. EXC_VIRT_NONE(0x5400, 0x100)
  1132. EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
  1133. mtspr SPRN_SPRG_HSCRATCH0,r13
  1134. EXCEPTION_PROLOG_0(PACA_EXGEN)
  1135. EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
  1136. #ifdef CONFIG_PPC_DENORMALISATION
  1137. mfspr r10,SPRN_HSRR1
  1138. mfspr r11,SPRN_HSRR0 /* save HSRR0 */
  1139. andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
  1140. addi r11,r11,-4 /* HSRR0 is next instruction */
  1141. bne+ denorm_assist
  1142. #endif
  1143. KVMTEST_PR(0x1500)
  1144. EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
  1145. EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
  1146. #ifdef CONFIG_PPC_DENORMALISATION
  1147. EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
  1148. b exc_real_0x1500_denorm_exception_hv
  1149. EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
  1150. #else
  1151. EXC_VIRT_NONE(0x5500, 0x100)
  1152. #endif
  1153. TRAMP_KVM_SKIP(PACA_EXGEN, 0x1500)
  1154. #ifdef CONFIG_PPC_DENORMALISATION
  1155. TRAMP_REAL_BEGIN(denorm_assist)
  1156. BEGIN_FTR_SECTION
  1157. /*
  1158. * To denormalise we need to move a copy of the register to itself.
  1159. * For POWER6 do that here for all FP regs.
  1160. */
  1161. mfmsr r10
  1162. ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
  1163. xori r10,r10,(MSR_FE0|MSR_FE1)
  1164. mtmsrd r10
  1165. sync
  1166. #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
  1167. #define FMR4(n) FMR2(n) ; FMR2(n+2)
  1168. #define FMR8(n) FMR4(n) ; FMR4(n+4)
  1169. #define FMR16(n) FMR8(n) ; FMR8(n+8)
  1170. #define FMR32(n) FMR16(n) ; FMR16(n+16)
  1171. FMR32(0)
  1172. FTR_SECTION_ELSE
  1173. /*
  1174. * To denormalise we need to move a copy of the register to itself.
  1175. * For POWER7 do that here for the first 32 VSX registers only.
  1176. */
  1177. mfmsr r10
  1178. oris r10,r10,MSR_VSX@h
  1179. mtmsrd r10
  1180. sync
  1181. #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
  1182. #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
  1183. #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
  1184. #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
  1185. #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
  1186. XVCPSGNDP32(0)
  1187. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
  1188. BEGIN_FTR_SECTION
  1189. b denorm_done
  1190. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  1191. /*
  1192. * To denormalise we need to move a copy of the register to itself.
  1193. * For POWER8 we need to do that for all 64 VSX registers
  1194. */
  1195. XVCPSGNDP32(32)
  1196. denorm_done:
  1197. mtspr SPRN_HSRR0,r11
  1198. mtcrf 0x80,r9
  1199. ld r9,PACA_EXGEN+EX_R9(r13)
  1200. RESTORE_PPR_PACA(PACA_EXGEN, r10)
  1201. BEGIN_FTR_SECTION
  1202. ld r10,PACA_EXGEN+EX_CFAR(r13)
  1203. mtspr SPRN_CFAR,r10
  1204. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1205. ld r10,PACA_EXGEN+EX_R10(r13)
  1206. ld r11,PACA_EXGEN+EX_R11(r13)
  1207. ld r12,PACA_EXGEN+EX_R12(r13)
  1208. ld r13,PACA_EXGEN+EX_R13(r13)
  1209. HRFI_TO_UNKNOWN
  1210. b .
  1211. #endif
  1212. EXC_COMMON_HV(denorm_common, 0x1500, unknown_exception)
  1213. #ifdef CONFIG_CBE_RAS
  1214. EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
  1215. EXC_VIRT_NONE(0x5600, 0x100)
  1216. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
  1217. EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
  1218. #else /* CONFIG_CBE_RAS */
  1219. EXC_REAL_NONE(0x1600, 0x100)
  1220. EXC_VIRT_NONE(0x5600, 0x100)
  1221. #endif
  1222. EXC_REAL(altivec_assist, 0x1700, 0x100)
  1223. EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
  1224. TRAMP_KVM(PACA_EXGEN, 0x1700)
  1225. #ifdef CONFIG_ALTIVEC
  1226. EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
  1227. #else
  1228. EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
  1229. #endif
  1230. #ifdef CONFIG_CBE_RAS
  1231. EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
  1232. EXC_VIRT_NONE(0x5800, 0x100)
  1233. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
  1234. EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
  1235. #else /* CONFIG_CBE_RAS */
  1236. EXC_REAL_NONE(0x1800, 0x100)
  1237. EXC_VIRT_NONE(0x5800, 0x100)
  1238. #endif
  1239. #ifdef CONFIG_PPC_WATCHDOG
  1240. #define MASKED_DEC_HANDLER_LABEL 3f
  1241. #define MASKED_DEC_HANDLER(_H) \
  1242. 3: /* soft-nmi */ \
  1243. std r12,PACA_EXGEN+EX_R12(r13); \
  1244. GET_SCRATCH0(r10); \
  1245. std r10,PACA_EXGEN+EX_R13(r13); \
  1246. EXCEPTION_PROLOG_PSERIES_1(soft_nmi_common, _H)
  1247. /*
  1248. * Branch to soft_nmi_interrupt using the emergency stack. The emergency
  1249. * stack is one that is usable by maskable interrupts so long as MSR_EE
  1250. * remains off. It is used for recovery when something has corrupted the
  1251. * normal kernel stack, for example. The "soft NMI" must not use the process
  1252. * stack because we want irq disabled sections to avoid touching the stack
  1253. * at all (other than PMU interrupts), so use the emergency stack for this,
  1254. * and run it entirely with interrupts hard disabled.
  1255. */
  1256. EXC_COMMON_BEGIN(soft_nmi_common)
  1257. mr r10,r1
  1258. ld r1,PACAEMERGSP(r13)
  1259. subi r1,r1,INT_FRAME_SIZE
  1260. EXCEPTION_COMMON_NORET_STACK(PACA_EXGEN, 0x900,
  1261. system_reset, soft_nmi_interrupt,
  1262. ADD_NVGPRS;ADD_RECONCILE)
  1263. b ret_from_except
  1264. #else /* CONFIG_PPC_WATCHDOG */
  1265. #define MASKED_DEC_HANDLER_LABEL 2f /* normal return */
  1266. #define MASKED_DEC_HANDLER(_H)
  1267. #endif /* CONFIG_PPC_WATCHDOG */
  1268. /*
  1269. * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
  1270. * - If it was a decrementer interrupt, we bump the dec to max and and return.
  1271. * - If it was a doorbell we return immediately since doorbells are edge
  1272. * triggered and won't automatically refire.
  1273. * - If it was a HMI we return immediately since we handled it in realmode
  1274. * and it won't refire.
  1275. * - else we hard disable and return.
  1276. * This is called with r10 containing the value to OR to the paca field.
  1277. */
  1278. #define MASKED_INTERRUPT(_H) \
  1279. masked_##_H##interrupt: \
  1280. std r11,PACA_EXGEN+EX_R11(r13); \
  1281. lbz r11,PACAIRQHAPPENED(r13); \
  1282. or r11,r11,r10; \
  1283. stb r11,PACAIRQHAPPENED(r13); \
  1284. cmpwi r10,PACA_IRQ_DEC; \
  1285. bne 1f; \
  1286. lis r10,0x7fff; \
  1287. ori r10,r10,0xffff; \
  1288. mtspr SPRN_DEC,r10; \
  1289. b MASKED_DEC_HANDLER_LABEL; \
  1290. 1: andi. r10,r10,(PACA_IRQ_DBELL|PACA_IRQ_HMI); \
  1291. bne 2f; \
  1292. mfspr r10,SPRN_##_H##SRR1; \
  1293. xori r10,r10,MSR_EE; /* clear MSR_EE */ \
  1294. mtspr SPRN_##_H##SRR1,r10; \
  1295. 2: mtcrf 0x80,r9; \
  1296. ld r9,PACA_EXGEN+EX_R9(r13); \
  1297. ld r10,PACA_EXGEN+EX_R10(r13); \
  1298. ld r11,PACA_EXGEN+EX_R11(r13); \
  1299. /* returns to kernel where r13 must be set up, so don't restore it */ \
  1300. ##_H##RFI_TO_KERNEL; \
  1301. b .; \
  1302. MASKED_DEC_HANDLER(_H)
  1303. TRAMP_REAL_BEGIN(rfi_flush_fallback)
  1304. SET_SCRATCH0(r13);
  1305. GET_PACA(r13);
  1306. std r9,PACA_EXRFI+EX_R9(r13)
  1307. std r10,PACA_EXRFI+EX_R10(r13)
  1308. std r11,PACA_EXRFI+EX_R11(r13)
  1309. std r12,PACA_EXRFI+EX_R12(r13)
  1310. std r8,PACA_EXRFI+EX_R13(r13)
  1311. mfctr r9
  1312. ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
  1313. ld r11,PACA_L1D_FLUSH_SETS(r13)
  1314. ld r12,PACA_L1D_FLUSH_CONGRUENCE(r13)
  1315. /*
  1316. * The load adresses are at staggered offsets within cachelines,
  1317. * which suits some pipelines better (on others it should not
  1318. * hurt).
  1319. */
  1320. addi r12,r12,8
  1321. mtctr r11
  1322. DCBT_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
  1323. /* order ld/st prior to dcbt stop all streams with flushing */
  1324. sync
  1325. 1: li r8,0
  1326. .rept 8 /* 8-way set associative */
  1327. ldx r11,r10,r8
  1328. add r8,r8,r12
  1329. xor r11,r11,r11 // Ensure r11 is 0 even if fallback area is not
  1330. add r8,r8,r11 // Add 0, this creates a dependency on the ldx
  1331. .endr
  1332. addi r10,r10,128 /* 128 byte cache line */
  1333. bdnz 1b
  1334. mtctr r9
  1335. ld r9,PACA_EXRFI+EX_R9(r13)
  1336. ld r10,PACA_EXRFI+EX_R10(r13)
  1337. ld r11,PACA_EXRFI+EX_R11(r13)
  1338. ld r12,PACA_EXRFI+EX_R12(r13)
  1339. ld r8,PACA_EXRFI+EX_R13(r13)
  1340. GET_SCRATCH0(r13);
  1341. rfid
  1342. TRAMP_REAL_BEGIN(hrfi_flush_fallback)
  1343. SET_SCRATCH0(r13);
  1344. GET_PACA(r13);
  1345. std r9,PACA_EXRFI+EX_R9(r13)
  1346. std r10,PACA_EXRFI+EX_R10(r13)
  1347. std r11,PACA_EXRFI+EX_R11(r13)
  1348. std r12,PACA_EXRFI+EX_R12(r13)
  1349. std r8,PACA_EXRFI+EX_R13(r13)
  1350. mfctr r9
  1351. ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
  1352. ld r11,PACA_L1D_FLUSH_SETS(r13)
  1353. ld r12,PACA_L1D_FLUSH_CONGRUENCE(r13)
  1354. /*
  1355. * The load adresses are at staggered offsets within cachelines,
  1356. * which suits some pipelines better (on others it should not
  1357. * hurt).
  1358. */
  1359. addi r12,r12,8
  1360. mtctr r11
  1361. DCBT_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
  1362. /* order ld/st prior to dcbt stop all streams with flushing */
  1363. sync
  1364. 1: li r8,0
  1365. .rept 8 /* 8-way set associative */
  1366. ldx r11,r10,r8
  1367. add r8,r8,r12
  1368. xor r11,r11,r11 // Ensure r11 is 0 even if fallback area is not
  1369. add r8,r8,r11 // Add 0, this creates a dependency on the ldx
  1370. .endr
  1371. addi r10,r10,128 /* 128 byte cache line */
  1372. bdnz 1b
  1373. mtctr r9
  1374. ld r9,PACA_EXRFI+EX_R9(r13)
  1375. ld r10,PACA_EXRFI+EX_R10(r13)
  1376. ld r11,PACA_EXRFI+EX_R11(r13)
  1377. ld r12,PACA_EXRFI+EX_R12(r13)
  1378. ld r8,PACA_EXRFI+EX_R13(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)@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. BEGIN_FTR_SECTION
  1651. cmpwi r3,0xa00
  1652. beq h_doorbell_common_msgclr
  1653. cmpwi r3,0xe60
  1654. beq hmi_exception_common
  1655. FTR_SECTION_ELSE
  1656. cmpwi r3,0xa00
  1657. beq doorbell_super_common_msgclr
  1658. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  1659. replay_interrupt_return:
  1660. blr
  1661. _ASM_NOKPROBE_SYMBOL(__replay_interrupt)