exceptions-64s.S 49 KB

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