exceptions-64s.S 48 KB

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