exceptions-64s.S 54 KB

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