exceptions-64s.S 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  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.
  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, 0x100)
  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, 0x100)
  116. EXC_VIRT_NONE(0x4100, 0x100)
  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. BRANCH_TO_KVM(r10, 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, 0x100)
  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, 0x100)
  173. EXC_VIRT_NONE(0x4200, 0x100)
  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. rfid
  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. rfid
  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_NORET(PPC_NAP)
  363. /* No return */
  364. 10:
  365. cmpwi r3,PNV_THREAD_SLEEP
  366. bgt 2f
  367. IDLE_STATE_ENTER_SEQ_NORET(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_NORET(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. rfid
  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. rfid
  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, 0x80)
  459. EXC_VIRT(data_access, 0x4300, 0x80, 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, 0x80)
  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, 0x80)
  506. EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
  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, 0x80)
  528. TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
  529. EXC_REAL(instruction_access, 0x400, 0x80)
  530. EXC_VIRT(instruction_access, 0x4400, 0x80, 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, 0x80)
  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, 0x80)
  563. EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
  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, 0x80)
  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. /* All done -- return from exception. */
  614. .machine push
  615. .machine "power4"
  616. mtcrf 0x80,r9
  617. mtcrf 0x02,r9 /* I/D indication is in cr6 */
  618. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  619. .machine pop
  620. RESTORE_PPR_PACA(PACA_EXSLB, r9)
  621. ld r9,PACA_EXSLB+EX_R9(r13)
  622. ld r10,PACA_EXSLB+EX_R10(r13)
  623. ld r11,PACA_EXSLB+EX_R11(r13)
  624. ld r12,PACA_EXSLB+EX_R12(r13)
  625. ld r13,PACA_EXSLB+EX_R13(r13)
  626. rfid
  627. b . /* prevent speculative execution */
  628. 2: mfspr r11,SPRN_SRR0
  629. LOAD_HANDLER(r10,unrecov_slb)
  630. mtspr SPRN_SRR0,r10
  631. ld r10,PACAKMSR(r13)
  632. mtspr SPRN_SRR1,r10
  633. rfid
  634. b .
  635. 8: mfspr r11,SPRN_SRR0
  636. LOAD_HANDLER(r10,bad_addr_slb)
  637. mtspr SPRN_SRR0,r10
  638. ld r10,PACAKMSR(r13)
  639. mtspr SPRN_SRR1,r10
  640. rfid
  641. b .
  642. EXC_COMMON_BEGIN(unrecov_slb)
  643. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  644. RECONCILE_IRQ_STATE(r10, r11)
  645. bl save_nvgprs
  646. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  647. bl unrecoverable_exception
  648. b 1b
  649. EXC_COMMON_BEGIN(bad_addr_slb)
  650. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
  651. RECONCILE_IRQ_STATE(r10, r11)
  652. ld r3, PACA_EXSLB+EX_DAR(r13)
  653. std r3, _DAR(r1)
  654. beq cr6, 2f
  655. li r10, 0x480 /* fix trap number for I-SLB miss */
  656. std r10, _TRAP(r1)
  657. 2: bl save_nvgprs
  658. addi r3, r1, STACK_FRAME_OVERHEAD
  659. bl slb_miss_bad_addr
  660. b ret_from_except
  661. EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
  662. .globl hardware_interrupt_hv;
  663. hardware_interrupt_hv:
  664. BEGIN_FTR_SECTION
  665. _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
  666. EXC_HV, SOFTEN_TEST_HV)
  667. FTR_SECTION_ELSE
  668. _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
  669. EXC_STD, SOFTEN_TEST_PR)
  670. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  671. EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
  672. EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
  673. .globl hardware_interrupt_relon_hv;
  674. hardware_interrupt_relon_hv:
  675. BEGIN_FTR_SECTION
  676. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_HV, SOFTEN_TEST_HV)
  677. FTR_SECTION_ELSE
  678. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_STD, SOFTEN_TEST_PR)
  679. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  680. EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
  681. TRAMP_KVM(PACA_EXGEN, 0x500)
  682. TRAMP_KVM_HV(PACA_EXGEN, 0x500)
  683. EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
  684. EXC_REAL(alignment, 0x600, 0x100)
  685. EXC_VIRT(alignment, 0x4600, 0x100, 0x600)
  686. TRAMP_KVM(PACA_EXGEN, 0x600)
  687. EXC_COMMON_BEGIN(alignment_common)
  688. mfspr r10,SPRN_DAR
  689. std r10,PACA_EXGEN+EX_DAR(r13)
  690. mfspr r10,SPRN_DSISR
  691. stw r10,PACA_EXGEN+EX_DSISR(r13)
  692. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  693. ld r3,PACA_EXGEN+EX_DAR(r13)
  694. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  695. std r3,_DAR(r1)
  696. std r4,_DSISR(r1)
  697. bl save_nvgprs
  698. RECONCILE_IRQ_STATE(r10, r11)
  699. addi r3,r1,STACK_FRAME_OVERHEAD
  700. bl alignment_exception
  701. b ret_from_except
  702. EXC_REAL(program_check, 0x700, 0x100)
  703. EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
  704. TRAMP_KVM(PACA_EXGEN, 0x700)
  705. EXC_COMMON_BEGIN(program_check_common)
  706. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  707. bl save_nvgprs
  708. RECONCILE_IRQ_STATE(r10, r11)
  709. addi r3,r1,STACK_FRAME_OVERHEAD
  710. bl program_check_exception
  711. b ret_from_except
  712. EXC_REAL(fp_unavailable, 0x800, 0x100)
  713. EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
  714. TRAMP_KVM(PACA_EXGEN, 0x800)
  715. EXC_COMMON_BEGIN(fp_unavailable_common)
  716. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  717. bne 1f /* if from user, just load it up */
  718. bl save_nvgprs
  719. RECONCILE_IRQ_STATE(r10, r11)
  720. addi r3,r1,STACK_FRAME_OVERHEAD
  721. bl kernel_fp_unavailable_exception
  722. BUG_OPCODE
  723. 1:
  724. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  725. BEGIN_FTR_SECTION
  726. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  727. * transaction), go do TM stuff
  728. */
  729. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  730. bne- 2f
  731. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  732. #endif
  733. bl load_up_fpu
  734. b fast_exception_return
  735. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  736. 2: /* User process was in a transaction */
  737. bl save_nvgprs
  738. RECONCILE_IRQ_STATE(r10, r11)
  739. addi r3,r1,STACK_FRAME_OVERHEAD
  740. bl fp_unavailable_tm
  741. b ret_from_except
  742. #endif
  743. EXC_REAL_MASKABLE(decrementer, 0x900, 0x80)
  744. EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900)
  745. TRAMP_KVM(PACA_EXGEN, 0x900)
  746. EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
  747. EXC_REAL_HV(hdecrementer, 0x980, 0x80)
  748. EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
  749. TRAMP_KVM_HV(PACA_EXGEN, 0x980)
  750. EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
  751. EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100)
  752. EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00)
  753. TRAMP_KVM(PACA_EXGEN, 0xa00)
  754. #ifdef CONFIG_PPC_DOORBELL
  755. EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
  756. #else
  757. EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
  758. #endif
  759. EXC_REAL(trap_0b, 0xb00, 0x100)
  760. EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
  761. TRAMP_KVM(PACA_EXGEN, 0xb00)
  762. EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
  763. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  764. /*
  765. * If CONFIG_KVM_BOOK3S_64_HANDLER is set, save the PPR (on systems
  766. * that support it) before changing to HMT_MEDIUM. That allows the KVM
  767. * code to save that value into the guest state (it is the guest's PPR
  768. * value). Otherwise just change to HMT_MEDIUM as userspace has
  769. * already saved the PPR.
  770. */
  771. #define SYSCALL_KVMTEST \
  772. SET_SCRATCH0(r13); \
  773. GET_PACA(r13); \
  774. std r9,PACA_EXGEN+EX_R9(r13); \
  775. OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \
  776. HMT_MEDIUM; \
  777. std r10,PACA_EXGEN+EX_R10(r13); \
  778. OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r9, CPU_FTR_HAS_PPR); \
  779. mfcr r9; \
  780. KVMTEST_PR(0xc00); \
  781. GET_SCRATCH0(r13)
  782. #else
  783. #define SYSCALL_KVMTEST \
  784. HMT_MEDIUM
  785. #endif
  786. #define LOAD_SYSCALL_HANDLER(reg) \
  787. __LOAD_HANDLER(reg, system_call_common)
  788. /* Syscall routine is used twice, in reloc-off and reloc-on paths */
  789. #define SYSCALL_PSERIES_1 \
  790. BEGIN_FTR_SECTION \
  791. cmpdi r0,0x1ebe ; \
  792. beq- 1f ; \
  793. END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
  794. mr r9,r13 ; \
  795. GET_PACA(r13) ; \
  796. mfspr r11,SPRN_SRR0 ; \
  797. 0:
  798. #define SYSCALL_PSERIES_2_RFID \
  799. mfspr r12,SPRN_SRR1 ; \
  800. LOAD_SYSCALL_HANDLER(r10) ; \
  801. mtspr SPRN_SRR0,r10 ; \
  802. ld r10,PACAKMSR(r13) ; \
  803. mtspr SPRN_SRR1,r10 ; \
  804. rfid ; \
  805. b . ; /* prevent speculative execution */
  806. #define SYSCALL_PSERIES_3 \
  807. /* Fast LE/BE switch system call */ \
  808. 1: mfspr r12,SPRN_SRR1 ; \
  809. xori r12,r12,MSR_LE ; \
  810. mtspr SPRN_SRR1,r12 ; \
  811. rfid ; /* return to userspace */ \
  812. b . ; /* prevent speculative execution */
  813. #if defined(CONFIG_RELOCATABLE)
  814. /*
  815. * We can't branch directly so we do it via the CTR which
  816. * is volatile across system calls.
  817. */
  818. #define SYSCALL_PSERIES_2_DIRECT \
  819. LOAD_SYSCALL_HANDLER(r12) ; \
  820. mtctr r12 ; \
  821. mfspr r12,SPRN_SRR1 ; \
  822. li r10,MSR_RI ; \
  823. mtmsrd r10,1 ; \
  824. bctr ;
  825. #else
  826. /* We can branch directly */
  827. #define SYSCALL_PSERIES_2_DIRECT \
  828. mfspr r12,SPRN_SRR1 ; \
  829. li r10,MSR_RI ; \
  830. mtmsrd r10,1 ; /* Set RI (EE=0) */ \
  831. b system_call_common ;
  832. #endif
  833. EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
  834. SYSCALL_KVMTEST
  835. SYSCALL_PSERIES_1
  836. SYSCALL_PSERIES_2_RFID
  837. SYSCALL_PSERIES_3
  838. EXC_REAL_END(system_call, 0xc00, 0x100)
  839. EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
  840. SYSCALL_KVMTEST
  841. SYSCALL_PSERIES_1
  842. SYSCALL_PSERIES_2_DIRECT
  843. SYSCALL_PSERIES_3
  844. EXC_VIRT_END(system_call, 0x4c00, 0x100)
  845. TRAMP_KVM(PACA_EXGEN, 0xc00)
  846. EXC_REAL(single_step, 0xd00, 0x100)
  847. EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
  848. TRAMP_KVM(PACA_EXGEN, 0xd00)
  849. EXC_COMMON(single_step_common, 0xd00, single_step_exception)
  850. EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
  851. EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
  852. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
  853. EXC_COMMON_BEGIN(h_data_storage_common)
  854. mfspr r10,SPRN_HDAR
  855. std r10,PACA_EXGEN+EX_DAR(r13)
  856. mfspr r10,SPRN_HDSISR
  857. stw r10,PACA_EXGEN+EX_DSISR(r13)
  858. EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
  859. bl save_nvgprs
  860. RECONCILE_IRQ_STATE(r10, r11)
  861. addi r3,r1,STACK_FRAME_OVERHEAD
  862. bl unknown_exception
  863. b ret_from_except
  864. EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
  865. EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
  866. TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
  867. EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
  868. EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
  869. EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
  870. TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
  871. EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
  872. /*
  873. * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
  874. * first, and then eventaully from there to the trampoline to get into virtual
  875. * mode.
  876. */
  877. __EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
  878. __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60)
  879. EXC_VIRT_NONE(0x4e60, 0x20)
  880. TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
  881. TRAMP_REAL_BEGIN(hmi_exception_early)
  882. EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
  883. mr r10,r1 /* Save r1 */
  884. ld r1,PACAEMERGSP(r13) /* Use emergency stack */
  885. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  886. std r9,_CCR(r1) /* save CR in stackframe */
  887. mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
  888. std r11,_NIP(r1) /* save HSRR0 in stackframe */
  889. mfspr r12,SPRN_HSRR1 /* Save SRR1 */
  890. std r12,_MSR(r1) /* save SRR1 in stackframe */
  891. std r10,0(r1) /* make stack chain pointer */
  892. std r0,GPR0(r1) /* save r0 in stackframe */
  893. std r10,GPR1(r1) /* save r1 in stackframe */
  894. EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
  895. EXCEPTION_PROLOG_COMMON_3(0xe60)
  896. addi r3,r1,STACK_FRAME_OVERHEAD
  897. BRANCH_LINK_TO_FAR(r4, hmi_exception_realmode)
  898. /* Windup the stack. */
  899. /* Move original HSRR0 and HSRR1 into the respective regs */
  900. ld r9,_MSR(r1)
  901. mtspr SPRN_HSRR1,r9
  902. ld r3,_NIP(r1)
  903. mtspr SPRN_HSRR0,r3
  904. ld r9,_CTR(r1)
  905. mtctr r9
  906. ld r9,_XER(r1)
  907. mtxer r9
  908. ld r9,_LINK(r1)
  909. mtlr r9
  910. REST_GPR(0, r1)
  911. REST_8GPRS(2, r1)
  912. REST_GPR(10, r1)
  913. ld r11,_CCR(r1)
  914. mtcr r11
  915. REST_GPR(11, r1)
  916. REST_2GPRS(12, r1)
  917. /* restore original r1. */
  918. ld r1,GPR1(r1)
  919. /*
  920. * Go to virtual mode and pull the HMI event information from
  921. * firmware.
  922. */
  923. .globl hmi_exception_after_realmode
  924. hmi_exception_after_realmode:
  925. SET_SCRATCH0(r13)
  926. EXCEPTION_PROLOG_0(PACA_EXGEN)
  927. b tramp_real_hmi_exception
  928. EXC_COMMON_ASYNC(hmi_exception_common, 0xe60, handle_hmi_exception)
  929. EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20)
  930. EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80)
  931. TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
  932. #ifdef CONFIG_PPC_DOORBELL
  933. EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
  934. #else
  935. EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
  936. #endif
  937. EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20)
  938. EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0)
  939. TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
  940. EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
  941. EXC_REAL_NONE(0xec0, 0x20)
  942. EXC_VIRT_NONE(0x4ec0, 0x20)
  943. EXC_REAL_NONE(0xee0, 0x20)
  944. EXC_VIRT_NONE(0x4ee0, 0x20)
  945. EXC_REAL_OOL(performance_monitor, 0xf00, 0x20)
  946. EXC_VIRT_OOL(performance_monitor, 0x4f00, 0x20, 0xf00)
  947. TRAMP_KVM(PACA_EXGEN, 0xf00)
  948. EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
  949. EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
  950. EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
  951. TRAMP_KVM(PACA_EXGEN, 0xf20)
  952. EXC_COMMON_BEGIN(altivec_unavailable_common)
  953. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  954. #ifdef CONFIG_ALTIVEC
  955. BEGIN_FTR_SECTION
  956. beq 1f
  957. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  958. BEGIN_FTR_SECTION_NESTED(69)
  959. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  960. * transaction), go do TM stuff
  961. */
  962. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  963. bne- 2f
  964. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  965. #endif
  966. bl load_up_altivec
  967. b fast_exception_return
  968. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  969. 2: /* User process was in a transaction */
  970. bl save_nvgprs
  971. RECONCILE_IRQ_STATE(r10, r11)
  972. addi r3,r1,STACK_FRAME_OVERHEAD
  973. bl altivec_unavailable_tm
  974. b ret_from_except
  975. #endif
  976. 1:
  977. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  978. #endif
  979. bl save_nvgprs
  980. RECONCILE_IRQ_STATE(r10, r11)
  981. addi r3,r1,STACK_FRAME_OVERHEAD
  982. bl altivec_unavailable_exception
  983. b ret_from_except
  984. EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
  985. EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
  986. TRAMP_KVM(PACA_EXGEN, 0xf40)
  987. EXC_COMMON_BEGIN(vsx_unavailable_common)
  988. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  989. #ifdef CONFIG_VSX
  990. BEGIN_FTR_SECTION
  991. beq 1f
  992. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  993. BEGIN_FTR_SECTION_NESTED(69)
  994. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  995. * transaction), go do TM stuff
  996. */
  997. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  998. bne- 2f
  999. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1000. #endif
  1001. b load_up_vsx
  1002. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1003. 2: /* User process was in a transaction */
  1004. bl save_nvgprs
  1005. RECONCILE_IRQ_STATE(r10, r11)
  1006. addi r3,r1,STACK_FRAME_OVERHEAD
  1007. bl vsx_unavailable_tm
  1008. b ret_from_except
  1009. #endif
  1010. 1:
  1011. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1012. #endif
  1013. bl save_nvgprs
  1014. RECONCILE_IRQ_STATE(r10, r11)
  1015. addi r3,r1,STACK_FRAME_OVERHEAD
  1016. bl vsx_unavailable_exception
  1017. b ret_from_except
  1018. EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
  1019. EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
  1020. TRAMP_KVM(PACA_EXGEN, 0xf60)
  1021. EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
  1022. EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
  1023. EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
  1024. TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
  1025. EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
  1026. EXC_REAL_NONE(0xfa0, 0x20)
  1027. EXC_VIRT_NONE(0x4fa0, 0x20)
  1028. EXC_REAL_NONE(0xfc0, 0x20)
  1029. EXC_VIRT_NONE(0x4fc0, 0x20)
  1030. EXC_REAL_NONE(0xfe0, 0x20)
  1031. EXC_VIRT_NONE(0x4fe0, 0x20)
  1032. EXC_REAL_NONE(0x1000, 0x100)
  1033. EXC_VIRT_NONE(0x5000, 0x100)
  1034. EXC_REAL_NONE(0x1100, 0x100)
  1035. EXC_VIRT_NONE(0x5100, 0x100)
  1036. #ifdef CONFIG_CBE_RAS
  1037. EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
  1038. EXC_VIRT_NONE(0x5200, 0x100)
  1039. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
  1040. EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
  1041. #else /* CONFIG_CBE_RAS */
  1042. EXC_REAL_NONE(0x1200, 0x100)
  1043. EXC_VIRT_NONE(0x5200, 0x100)
  1044. #endif
  1045. EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
  1046. EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
  1047. TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
  1048. EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
  1049. EXC_REAL_NONE(0x1400, 0x100)
  1050. EXC_VIRT_NONE(0x5400, 0x100)
  1051. EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
  1052. mtspr SPRN_SPRG_HSCRATCH0,r13
  1053. EXCEPTION_PROLOG_0(PACA_EXGEN)
  1054. EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
  1055. #ifdef CONFIG_PPC_DENORMALISATION
  1056. mfspr r10,SPRN_HSRR1
  1057. mfspr r11,SPRN_HSRR0 /* save HSRR0 */
  1058. andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
  1059. addi r11,r11,-4 /* HSRR0 is next instruction */
  1060. bne+ denorm_assist
  1061. #endif
  1062. KVMTEST_PR(0x1500)
  1063. EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
  1064. EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
  1065. #ifdef CONFIG_PPC_DENORMALISATION
  1066. EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
  1067. b exc_real_0x1500_denorm_exception_hv
  1068. EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
  1069. #else
  1070. EXC_VIRT_NONE(0x5500, 0x100)
  1071. #endif
  1072. TRAMP_KVM_SKIP(PACA_EXGEN, 0x1500)
  1073. #ifdef CONFIG_PPC_DENORMALISATION
  1074. TRAMP_REAL_BEGIN(denorm_assist)
  1075. BEGIN_FTR_SECTION
  1076. /*
  1077. * To denormalise we need to move a copy of the register to itself.
  1078. * For POWER6 do that here for all FP regs.
  1079. */
  1080. mfmsr r10
  1081. ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
  1082. xori r10,r10,(MSR_FE0|MSR_FE1)
  1083. mtmsrd r10
  1084. sync
  1085. #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
  1086. #define FMR4(n) FMR2(n) ; FMR2(n+2)
  1087. #define FMR8(n) FMR4(n) ; FMR4(n+4)
  1088. #define FMR16(n) FMR8(n) ; FMR8(n+8)
  1089. #define FMR32(n) FMR16(n) ; FMR16(n+16)
  1090. FMR32(0)
  1091. FTR_SECTION_ELSE
  1092. /*
  1093. * To denormalise we need to move a copy of the register to itself.
  1094. * For POWER7 do that here for the first 32 VSX registers only.
  1095. */
  1096. mfmsr r10
  1097. oris r10,r10,MSR_VSX@h
  1098. mtmsrd r10
  1099. sync
  1100. #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
  1101. #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
  1102. #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
  1103. #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
  1104. #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
  1105. XVCPSGNDP32(0)
  1106. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
  1107. BEGIN_FTR_SECTION
  1108. b denorm_done
  1109. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  1110. /*
  1111. * To denormalise we need to move a copy of the register to itself.
  1112. * For POWER8 we need to do that for all 64 VSX registers
  1113. */
  1114. XVCPSGNDP32(32)
  1115. denorm_done:
  1116. mtspr SPRN_HSRR0,r11
  1117. mtcrf 0x80,r9
  1118. ld r9,PACA_EXGEN+EX_R9(r13)
  1119. RESTORE_PPR_PACA(PACA_EXGEN, r10)
  1120. BEGIN_FTR_SECTION
  1121. ld r10,PACA_EXGEN+EX_CFAR(r13)
  1122. mtspr SPRN_CFAR,r10
  1123. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1124. ld r10,PACA_EXGEN+EX_R10(r13)
  1125. ld r11,PACA_EXGEN+EX_R11(r13)
  1126. ld r12,PACA_EXGEN+EX_R12(r13)
  1127. ld r13,PACA_EXGEN+EX_R13(r13)
  1128. HRFID
  1129. b .
  1130. #endif
  1131. EXC_COMMON_HV(denorm_common, 0x1500, unknown_exception)
  1132. #ifdef CONFIG_CBE_RAS
  1133. EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
  1134. EXC_VIRT_NONE(0x5600, 0x100)
  1135. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
  1136. EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
  1137. #else /* CONFIG_CBE_RAS */
  1138. EXC_REAL_NONE(0x1600, 0x100)
  1139. EXC_VIRT_NONE(0x5600, 0x100)
  1140. #endif
  1141. EXC_REAL(altivec_assist, 0x1700, 0x100)
  1142. EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
  1143. TRAMP_KVM(PACA_EXGEN, 0x1700)
  1144. #ifdef CONFIG_ALTIVEC
  1145. EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
  1146. #else
  1147. EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
  1148. #endif
  1149. #ifdef CONFIG_CBE_RAS
  1150. EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
  1151. EXC_VIRT_NONE(0x5800, 0x100)
  1152. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
  1153. EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
  1154. #else /* CONFIG_CBE_RAS */
  1155. EXC_REAL_NONE(0x1800, 0x100)
  1156. EXC_VIRT_NONE(0x5800, 0x100)
  1157. #endif
  1158. /*
  1159. * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
  1160. * - If it was a decrementer interrupt, we bump the dec to max and and return.
  1161. * - If it was a doorbell we return immediately since doorbells are edge
  1162. * triggered and won't automatically refire.
  1163. * - If it was a HMI we return immediately since we handled it in realmode
  1164. * and it won't refire.
  1165. * - else we hard disable and return.
  1166. * This is called with r10 containing the value to OR to the paca field.
  1167. */
  1168. #define MASKED_INTERRUPT(_H) \
  1169. masked_##_H##interrupt: \
  1170. std r11,PACA_EXGEN+EX_R11(r13); \
  1171. lbz r11,PACAIRQHAPPENED(r13); \
  1172. or r11,r11,r10; \
  1173. stb r11,PACAIRQHAPPENED(r13); \
  1174. cmpwi r10,PACA_IRQ_DEC; \
  1175. bne 1f; \
  1176. lis r10,0x7fff; \
  1177. ori r10,r10,0xffff; \
  1178. mtspr SPRN_DEC,r10; \
  1179. b 2f; \
  1180. 1: cmpwi r10,PACA_IRQ_DBELL; \
  1181. beq 2f; \
  1182. cmpwi r10,PACA_IRQ_HMI; \
  1183. beq 2f; \
  1184. mfspr r10,SPRN_##_H##SRR1; \
  1185. rldicl r10,r10,48,1; /* clear MSR_EE */ \
  1186. rotldi r10,r10,16; \
  1187. mtspr SPRN_##_H##SRR1,r10; \
  1188. 2: mtcrf 0x80,r9; \
  1189. ld r9,PACA_EXGEN+EX_R9(r13); \
  1190. ld r10,PACA_EXGEN+EX_R10(r13); \
  1191. ld r11,PACA_EXGEN+EX_R11(r13); \
  1192. GET_SCRATCH0(r13); \
  1193. ##_H##rfid; \
  1194. b .
  1195. /*
  1196. * Real mode exceptions actually use this too, but alternate
  1197. * instruction code patches (which end up in the common .text area)
  1198. * cannot reach these if they are put there.
  1199. */
  1200. USE_FIXED_SECTION(virt_trampolines)
  1201. MASKED_INTERRUPT()
  1202. MASKED_INTERRUPT(H)
  1203. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  1204. TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
  1205. /*
  1206. * Here all GPRs are unchanged from when the interrupt happened
  1207. * except for r13, which is saved in SPRG_SCRATCH0.
  1208. */
  1209. mfspr r13, SPRN_SRR0
  1210. addi r13, r13, 4
  1211. mtspr SPRN_SRR0, r13
  1212. GET_SCRATCH0(r13)
  1213. rfid
  1214. b .
  1215. TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
  1216. /*
  1217. * Here all GPRs are unchanged from when the interrupt happened
  1218. * except for r13, which is saved in SPRG_SCRATCH0.
  1219. */
  1220. mfspr r13, SPRN_HSRR0
  1221. addi r13, r13, 4
  1222. mtspr SPRN_HSRR0, r13
  1223. GET_SCRATCH0(r13)
  1224. hrfid
  1225. b .
  1226. #endif
  1227. /*
  1228. * Ensure that any handlers that get invoked from the exception prologs
  1229. * above are below the first 64KB (0x10000) of the kernel image because
  1230. * the prologs assemble the addresses of these handlers using the
  1231. * LOAD_HANDLER macro, which uses an ori instruction.
  1232. */
  1233. /*** Common interrupt handlers ***/
  1234. /*
  1235. * Relocation-on interrupts: A subset of the interrupts can be delivered
  1236. * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
  1237. * it. Addresses are the same as the original interrupt addresses, but
  1238. * offset by 0xc000000000004000.
  1239. * It's impossible to receive interrupts below 0x300 via this mechanism.
  1240. * KVM: None of these traps are from the guest ; anything that escalated
  1241. * to HV=1 from HV=0 is delivered via real mode handlers.
  1242. */
  1243. /*
  1244. * This uses the standard macro, since the original 0x300 vector
  1245. * only has extra guff for STAB-based processors -- which never
  1246. * come here.
  1247. */
  1248. EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
  1249. b __ppc64_runlatch_on
  1250. USE_FIXED_SECTION(virt_trampolines)
  1251. /*
  1252. * The __end_interrupts marker must be past the out-of-line (OOL)
  1253. * handlers, so that they are copied to real address 0x100 when running
  1254. * a relocatable kernel. This ensures they can be reached from the short
  1255. * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
  1256. * directly, without using LOAD_HANDLER().
  1257. */
  1258. .align 7
  1259. .globl __end_interrupts
  1260. __end_interrupts:
  1261. DEFINE_FIXED_SYMBOL(__end_interrupts)
  1262. #ifdef CONFIG_PPC_970_NAP
  1263. EXC_COMMON_BEGIN(power4_fixup_nap)
  1264. andc r9,r9,r10
  1265. std r9,TI_LOCAL_FLAGS(r11)
  1266. ld r10,_LINK(r1) /* make idle task do the */
  1267. std r10,_NIP(r1) /* equivalent of a blr */
  1268. blr
  1269. #endif
  1270. CLOSE_FIXED_SECTION(real_vectors);
  1271. CLOSE_FIXED_SECTION(real_trampolines);
  1272. CLOSE_FIXED_SECTION(virt_vectors);
  1273. CLOSE_FIXED_SECTION(virt_trampolines);
  1274. USE_TEXT_SECTION()
  1275. /*
  1276. * Hash table stuff
  1277. */
  1278. .balign IFETCH_ALIGN_BYTES
  1279. do_hash_page:
  1280. #ifdef CONFIG_PPC_STD_MMU_64
  1281. andis. r0,r4,0xa410 /* weird error? */
  1282. bne- handle_page_fault /* if not, try to insert a HPTE */
  1283. andis. r0,r4,DSISR_DABRMATCH@h
  1284. bne- handle_dabr_fault
  1285. CURRENT_THREAD_INFO(r11, r1)
  1286. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  1287. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  1288. bne 77f /* then don't call hash_page now */
  1289. /*
  1290. * r3 contains the faulting address
  1291. * r4 msr
  1292. * r5 contains the trap number
  1293. * r6 contains dsisr
  1294. *
  1295. * at return r3 = 0 for success, 1 for page fault, negative for error
  1296. */
  1297. mr r4,r12
  1298. ld r6,_DSISR(r1)
  1299. bl __hash_page /* build HPTE if possible */
  1300. cmpdi r3,0 /* see if __hash_page succeeded */
  1301. /* Success */
  1302. beq fast_exc_return_irq /* Return from exception on success */
  1303. /* Error */
  1304. blt- 13f
  1305. #endif /* CONFIG_PPC_STD_MMU_64 */
  1306. /* Here we have a page fault that hash_page can't handle. */
  1307. handle_page_fault:
  1308. 11: ld r4,_DAR(r1)
  1309. ld r5,_DSISR(r1)
  1310. addi r3,r1,STACK_FRAME_OVERHEAD
  1311. bl do_page_fault
  1312. cmpdi r3,0
  1313. beq+ 12f
  1314. bl save_nvgprs
  1315. mr r5,r3
  1316. addi r3,r1,STACK_FRAME_OVERHEAD
  1317. lwz r4,_DAR(r1)
  1318. bl bad_page_fault
  1319. b ret_from_except
  1320. /* We have a data breakpoint exception - handle it */
  1321. handle_dabr_fault:
  1322. bl save_nvgprs
  1323. ld r4,_DAR(r1)
  1324. ld r5,_DSISR(r1)
  1325. addi r3,r1,STACK_FRAME_OVERHEAD
  1326. bl do_break
  1327. 12: b ret_from_except_lite
  1328. #ifdef CONFIG_PPC_STD_MMU_64
  1329. /* We have a page fault that hash_page could handle but HV refused
  1330. * the PTE insertion
  1331. */
  1332. 13: bl save_nvgprs
  1333. mr r5,r3
  1334. addi r3,r1,STACK_FRAME_OVERHEAD
  1335. ld r4,_DAR(r1)
  1336. bl low_hash_fault
  1337. b ret_from_except
  1338. #endif
  1339. /*
  1340. * We come here as a result of a DSI at a point where we don't want
  1341. * to call hash_page, such as when we are accessing memory (possibly
  1342. * user memory) inside a PMU interrupt that occurred while interrupts
  1343. * were soft-disabled. We want to invoke the exception handler for
  1344. * the access, or panic if there isn't a handler.
  1345. */
  1346. 77: bl save_nvgprs
  1347. mr r4,r3
  1348. addi r3,r1,STACK_FRAME_OVERHEAD
  1349. li r5,SIGSEGV
  1350. bl bad_page_fault
  1351. b ret_from_except
  1352. /*
  1353. * Here we have detected that the kernel stack pointer is bad.
  1354. * R9 contains the saved CR, r13 points to the paca,
  1355. * r10 contains the (bad) kernel stack pointer,
  1356. * r11 and r12 contain the saved SRR0 and SRR1.
  1357. * We switch to using an emergency stack, save the registers there,
  1358. * and call kernel_bad_stack(), which panics.
  1359. */
  1360. bad_stack:
  1361. ld r1,PACAEMERGSP(r13)
  1362. subi r1,r1,64+INT_FRAME_SIZE
  1363. std r9,_CCR(r1)
  1364. std r10,GPR1(r1)
  1365. std r11,_NIP(r1)
  1366. std r12,_MSR(r1)
  1367. mfspr r11,SPRN_DAR
  1368. mfspr r12,SPRN_DSISR
  1369. std r11,_DAR(r1)
  1370. std r12,_DSISR(r1)
  1371. mflr r10
  1372. mfctr r11
  1373. mfxer r12
  1374. std r10,_LINK(r1)
  1375. std r11,_CTR(r1)
  1376. std r12,_XER(r1)
  1377. SAVE_GPR(0,r1)
  1378. SAVE_GPR(2,r1)
  1379. ld r10,EX_R3(r3)
  1380. std r10,GPR3(r1)
  1381. SAVE_GPR(4,r1)
  1382. SAVE_4GPRS(5,r1)
  1383. ld r9,EX_R9(r3)
  1384. ld r10,EX_R10(r3)
  1385. SAVE_2GPRS(9,r1)
  1386. ld r9,EX_R11(r3)
  1387. ld r10,EX_R12(r3)
  1388. ld r11,EX_R13(r3)
  1389. std r9,GPR11(r1)
  1390. std r10,GPR12(r1)
  1391. std r11,GPR13(r1)
  1392. BEGIN_FTR_SECTION
  1393. ld r10,EX_CFAR(r3)
  1394. std r10,ORIG_GPR3(r1)
  1395. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1396. SAVE_8GPRS(14,r1)
  1397. SAVE_10GPRS(22,r1)
  1398. lhz r12,PACA_TRAP_SAVE(r13)
  1399. std r12,_TRAP(r1)
  1400. addi r11,r1,INT_FRAME_SIZE
  1401. std r11,0(r1)
  1402. li r12,0
  1403. std r12,0(r11)
  1404. ld r2,PACATOC(r13)
  1405. ld r11,exception_marker@toc(r2)
  1406. std r12,RESULT(r1)
  1407. std r11,STACK_FRAME_OVERHEAD-16(r1)
  1408. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1409. bl kernel_bad_stack
  1410. b 1b
  1411. /*
  1412. * Called from arch_local_irq_enable when an interrupt needs
  1413. * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
  1414. * which kind of interrupt. MSR:EE is already off. We generate a
  1415. * stackframe like if a real interrupt had happened.
  1416. *
  1417. * Note: While MSR:EE is off, we need to make sure that _MSR
  1418. * in the generated frame has EE set to 1 or the exception
  1419. * handler will not properly re-enable them.
  1420. */
  1421. _GLOBAL(__replay_interrupt)
  1422. /* We are going to jump to the exception common code which
  1423. * will retrieve various register values from the PACA which
  1424. * we don't give a damn about, so we don't bother storing them.
  1425. */
  1426. mfmsr r12
  1427. mflr r11
  1428. mfcr r9
  1429. ori r12,r12,MSR_EE
  1430. cmpwi r3,0x900
  1431. beq decrementer_common
  1432. cmpwi r3,0x500
  1433. beq hardware_interrupt_common
  1434. BEGIN_FTR_SECTION
  1435. cmpwi r3,0xe80
  1436. beq h_doorbell_common
  1437. cmpwi r3,0xea0
  1438. beq h_virt_irq_common
  1439. cmpwi r3,0xe60
  1440. beq hmi_exception_common
  1441. FTR_SECTION_ELSE
  1442. cmpwi r3,0xa00
  1443. beq doorbell_super_common
  1444. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  1445. blr