exceptions-64s.S 44 KB

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