exceptions-64s.S 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693
  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. /*
  18. * We layout physical memory as follows:
  19. * 0x0000 - 0x00ff : Secondary processor spin code
  20. * 0x0100 - 0x17ff : pSeries Interrupt prologs
  21. * 0x1800 - 0x4000 : interrupt support common interrupt prologs
  22. * 0x4000 - 0x5fff : pSeries interrupts with IR=1,DR=1
  23. * 0x6000 - 0x6fff : more interrupt support including for IR=1,DR=1
  24. * 0x7000 - 0x7fff : FWNMI data area
  25. * 0x8000 - 0x8fff : Initial (CPU0) segment table
  26. * 0x9000 - : Early init and support code
  27. */
  28. /* Syscall routine is used twice, in reloc-off and reloc-on paths */
  29. #define SYSCALL_PSERIES_1 \
  30. BEGIN_FTR_SECTION \
  31. cmpdi r0,0x1ebe ; \
  32. beq- 1f ; \
  33. END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
  34. mr r9,r13 ; \
  35. GET_PACA(r13) ; \
  36. mfspr r11,SPRN_SRR0 ; \
  37. 0:
  38. #define SYSCALL_PSERIES_2_RFID \
  39. mfspr r12,SPRN_SRR1 ; \
  40. ld r10,PACAKBASE(r13) ; \
  41. LOAD_HANDLER(r10, system_call_entry) ; \
  42. mtspr SPRN_SRR0,r10 ; \
  43. ld r10,PACAKMSR(r13) ; \
  44. mtspr SPRN_SRR1,r10 ; \
  45. rfid ; \
  46. b . ; /* prevent speculative execution */
  47. #define SYSCALL_PSERIES_3 \
  48. /* Fast LE/BE switch system call */ \
  49. 1: mfspr r12,SPRN_SRR1 ; \
  50. xori r12,r12,MSR_LE ; \
  51. mtspr SPRN_SRR1,r12 ; \
  52. rfid ; /* return to userspace */ \
  53. b . ; /* prevent speculative execution */
  54. #if defined(CONFIG_RELOCATABLE)
  55. /*
  56. * We can't branch directly; in the direct case we use LR
  57. * and system_call_entry restores LR. (We thus need to move
  58. * LR to r10 in the RFID case too.)
  59. */
  60. #define SYSCALL_PSERIES_2_DIRECT \
  61. mflr r10 ; \
  62. ld r12,PACAKBASE(r13) ; \
  63. LOAD_HANDLER(r12, system_call_entry_direct) ; \
  64. mtctr r12 ; \
  65. mfspr r12,SPRN_SRR1 ; \
  66. /* Re-use of r13... No spare regs to do this */ \
  67. li r13,MSR_RI ; \
  68. mtmsrd r13,1 ; \
  69. GET_PACA(r13) ; /* get r13 back */ \
  70. bctr ;
  71. #else
  72. /* We can branch directly */
  73. #define SYSCALL_PSERIES_2_DIRECT \
  74. mfspr r12,SPRN_SRR1 ; \
  75. li r10,MSR_RI ; \
  76. mtmsrd r10,1 ; /* Set RI (EE=0) */ \
  77. b system_call_entry_direct ;
  78. #endif
  79. /*
  80. * This is the start of the interrupt handlers for pSeries
  81. * This code runs with relocation off.
  82. * Code from here to __end_interrupts gets copied down to real
  83. * address 0x100 when we are running a relocatable kernel.
  84. * Therefore any relative branches in this section must only
  85. * branch to labels in this section.
  86. */
  87. . = 0x100
  88. .globl __start_interrupts
  89. __start_interrupts:
  90. .globl system_reset_pSeries;
  91. system_reset_pSeries:
  92. HMT_MEDIUM_PPR_DISCARD
  93. SET_SCRATCH0(r13)
  94. #ifdef CONFIG_PPC_P7_NAP
  95. BEGIN_FTR_SECTION
  96. /* Running native on arch 2.06 or later, check if we are
  97. * waking up from nap. We only handle no state loss and
  98. * supervisor state loss. We do -not- handle hypervisor
  99. * state loss at this time.
  100. */
  101. mfspr r13,SPRN_SRR1
  102. rlwinm. r13,r13,47-31,30,31
  103. beq 9f
  104. /* waking up from powersave (nap) state */
  105. cmpwi cr1,r13,2
  106. /* Total loss of HV state is fatal, we could try to use the
  107. * PIR to locate a PACA, then use an emergency stack etc...
  108. * OPAL v3 based powernv platforms have new idle states
  109. * which fall in this catagory.
  110. */
  111. bgt cr1,8f
  112. GET_PACA(r13)
  113. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  114. li r0,KVM_HWTHREAD_IN_KERNEL
  115. stb r0,HSTATE_HWTHREAD_STATE(r13)
  116. /* Order setting hwthread_state vs. testing hwthread_req */
  117. sync
  118. lbz r0,HSTATE_HWTHREAD_REQ(r13)
  119. cmpwi r0,0
  120. beq 1f
  121. b kvm_start_guest
  122. 1:
  123. #endif
  124. beq cr1,2f
  125. b power7_wakeup_noloss
  126. 2: b power7_wakeup_loss
  127. /* Fast Sleep wakeup on PowerNV */
  128. 8: GET_PACA(r13)
  129. b power7_wakeup_tb_loss
  130. 9:
  131. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  132. #endif /* CONFIG_PPC_P7_NAP */
  133. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
  134. NOTEST, 0x100)
  135. . = 0x200
  136. machine_check_pSeries_1:
  137. /* This is moved out of line as it can be patched by FW, but
  138. * some code path might still want to branch into the original
  139. * vector
  140. */
  141. HMT_MEDIUM_PPR_DISCARD
  142. SET_SCRATCH0(r13) /* save r13 */
  143. #ifdef CONFIG_PPC_P7_NAP
  144. BEGIN_FTR_SECTION
  145. /* Running native on arch 2.06 or later, check if we are
  146. * waking up from nap. We only handle no state loss and
  147. * supervisor state loss. We do -not- handle hypervisor
  148. * state loss at this time.
  149. */
  150. mfspr r13,SPRN_SRR1
  151. rlwinm. r13,r13,47-31,30,31
  152. OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
  153. beq 9f
  154. mfspr r13,SPRN_SRR1
  155. rlwinm. r13,r13,47-31,30,31
  156. /* waking up from powersave (nap) state */
  157. cmpwi cr1,r13,2
  158. /* Total loss of HV state is fatal. let's just stay stuck here */
  159. OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
  160. bgt cr1,.
  161. 9:
  162. OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
  163. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  164. #endif /* CONFIG_PPC_P7_NAP */
  165. EXCEPTION_PROLOG_0(PACA_EXMC)
  166. BEGIN_FTR_SECTION
  167. b machine_check_pSeries_early
  168. FTR_SECTION_ELSE
  169. b machine_check_pSeries_0
  170. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  171. . = 0x300
  172. .globl data_access_pSeries
  173. data_access_pSeries:
  174. HMT_MEDIUM_PPR_DISCARD
  175. SET_SCRATCH0(r13)
  176. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD,
  177. KVMTEST, 0x300)
  178. . = 0x380
  179. .globl data_access_slb_pSeries
  180. data_access_slb_pSeries:
  181. HMT_MEDIUM_PPR_DISCARD
  182. SET_SCRATCH0(r13)
  183. EXCEPTION_PROLOG_0(PACA_EXSLB)
  184. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x380)
  185. std r3,PACA_EXSLB+EX_R3(r13)
  186. mfspr r3,SPRN_DAR
  187. #ifdef __DISABLED__
  188. /* Keep that around for when we re-implement dynamic VSIDs */
  189. cmpdi r3,0
  190. bge slb_miss_user_pseries
  191. #endif /* __DISABLED__ */
  192. mfspr r12,SPRN_SRR1
  193. #ifndef CONFIG_RELOCATABLE
  194. b slb_miss_realmode
  195. #else
  196. /*
  197. * We can't just use a direct branch to slb_miss_realmode
  198. * because the distance from here to there depends on where
  199. * the kernel ends up being put.
  200. */
  201. mfctr r11
  202. ld r10,PACAKBASE(r13)
  203. LOAD_HANDLER(r10, slb_miss_realmode)
  204. mtctr r10
  205. bctr
  206. #endif
  207. STD_EXCEPTION_PSERIES(0x400, 0x400, instruction_access)
  208. . = 0x480
  209. .globl instruction_access_slb_pSeries
  210. instruction_access_slb_pSeries:
  211. HMT_MEDIUM_PPR_DISCARD
  212. SET_SCRATCH0(r13)
  213. EXCEPTION_PROLOG_0(PACA_EXSLB)
  214. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
  215. std r3,PACA_EXSLB+EX_R3(r13)
  216. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  217. #ifdef __DISABLED__
  218. /* Keep that around for when we re-implement dynamic VSIDs */
  219. cmpdi r3,0
  220. bge slb_miss_user_pseries
  221. #endif /* __DISABLED__ */
  222. mfspr r12,SPRN_SRR1
  223. #ifndef CONFIG_RELOCATABLE
  224. b slb_miss_realmode
  225. #else
  226. mfctr r11
  227. ld r10,PACAKBASE(r13)
  228. LOAD_HANDLER(r10, slb_miss_realmode)
  229. mtctr r10
  230. bctr
  231. #endif
  232. /* We open code these as we can't have a ". = x" (even with
  233. * x = "." within a feature section
  234. */
  235. . = 0x500;
  236. .globl hardware_interrupt_pSeries;
  237. .globl hardware_interrupt_hv;
  238. hardware_interrupt_pSeries:
  239. hardware_interrupt_hv:
  240. HMT_MEDIUM_PPR_DISCARD
  241. BEGIN_FTR_SECTION
  242. _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt,
  243. EXC_HV, SOFTEN_TEST_HV)
  244. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
  245. FTR_SECTION_ELSE
  246. _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt,
  247. EXC_STD, SOFTEN_TEST_HV_201)
  248. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
  249. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  250. STD_EXCEPTION_PSERIES(0x600, 0x600, alignment)
  251. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x600)
  252. STD_EXCEPTION_PSERIES(0x700, 0x700, program_check)
  253. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x700)
  254. STD_EXCEPTION_PSERIES(0x800, 0x800, fp_unavailable)
  255. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x800)
  256. . = 0x900
  257. .globl decrementer_pSeries
  258. decrementer_pSeries:
  259. _MASKABLE_EXCEPTION_PSERIES(0x900, decrementer, EXC_STD, SOFTEN_TEST_PR)
  260. STD_EXCEPTION_HV(0x980, 0x982, hdecrementer)
  261. MASKABLE_EXCEPTION_PSERIES(0xa00, 0xa00, doorbell_super)
  262. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xa00)
  263. STD_EXCEPTION_PSERIES(0xb00, 0xb00, trap_0b)
  264. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xb00)
  265. . = 0xc00
  266. .globl system_call_pSeries
  267. system_call_pSeries:
  268. HMT_MEDIUM
  269. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  270. SET_SCRATCH0(r13)
  271. GET_PACA(r13)
  272. std r9,PACA_EXGEN+EX_R9(r13)
  273. std r10,PACA_EXGEN+EX_R10(r13)
  274. mfcr r9
  275. KVMTEST(0xc00)
  276. GET_SCRATCH0(r13)
  277. #endif
  278. SYSCALL_PSERIES_1
  279. SYSCALL_PSERIES_2_RFID
  280. SYSCALL_PSERIES_3
  281. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
  282. STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
  283. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
  284. /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
  285. * out of line to handle them
  286. */
  287. . = 0xe00
  288. hv_data_storage_trampoline:
  289. SET_SCRATCH0(r13)
  290. EXCEPTION_PROLOG_0(PACA_EXGEN)
  291. b h_data_storage_hv
  292. . = 0xe20
  293. hv_instr_storage_trampoline:
  294. SET_SCRATCH0(r13)
  295. EXCEPTION_PROLOG_0(PACA_EXGEN)
  296. b h_instr_storage_hv
  297. . = 0xe40
  298. emulation_assist_trampoline:
  299. SET_SCRATCH0(r13)
  300. EXCEPTION_PROLOG_0(PACA_EXGEN)
  301. b emulation_assist_hv
  302. . = 0xe60
  303. hv_exception_trampoline:
  304. SET_SCRATCH0(r13)
  305. EXCEPTION_PROLOG_0(PACA_EXGEN)
  306. b hmi_exception_early
  307. . = 0xe80
  308. hv_doorbell_trampoline:
  309. SET_SCRATCH0(r13)
  310. EXCEPTION_PROLOG_0(PACA_EXGEN)
  311. b h_doorbell_hv
  312. /* We need to deal with the Altivec unavailable exception
  313. * here which is at 0xf20, thus in the middle of the
  314. * prolog code of the PerformanceMonitor one. A little
  315. * trickery is thus necessary
  316. */
  317. . = 0xf00
  318. performance_monitor_pseries_trampoline:
  319. SET_SCRATCH0(r13)
  320. EXCEPTION_PROLOG_0(PACA_EXGEN)
  321. b performance_monitor_pSeries
  322. . = 0xf20
  323. altivec_unavailable_pseries_trampoline:
  324. SET_SCRATCH0(r13)
  325. EXCEPTION_PROLOG_0(PACA_EXGEN)
  326. b altivec_unavailable_pSeries
  327. . = 0xf40
  328. vsx_unavailable_pseries_trampoline:
  329. SET_SCRATCH0(r13)
  330. EXCEPTION_PROLOG_0(PACA_EXGEN)
  331. b vsx_unavailable_pSeries
  332. . = 0xf60
  333. facility_unavailable_trampoline:
  334. SET_SCRATCH0(r13)
  335. EXCEPTION_PROLOG_0(PACA_EXGEN)
  336. b facility_unavailable_pSeries
  337. . = 0xf80
  338. hv_facility_unavailable_trampoline:
  339. SET_SCRATCH0(r13)
  340. EXCEPTION_PROLOG_0(PACA_EXGEN)
  341. b facility_unavailable_hv
  342. #ifdef CONFIG_CBE_RAS
  343. STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
  344. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1202)
  345. #endif /* CONFIG_CBE_RAS */
  346. STD_EXCEPTION_PSERIES(0x1300, 0x1300, instruction_breakpoint)
  347. KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
  348. . = 0x1500
  349. .global denorm_exception_hv
  350. denorm_exception_hv:
  351. HMT_MEDIUM_PPR_DISCARD
  352. mtspr SPRN_SPRG_HSCRATCH0,r13
  353. EXCEPTION_PROLOG_0(PACA_EXGEN)
  354. EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
  355. #ifdef CONFIG_PPC_DENORMALISATION
  356. mfspr r10,SPRN_HSRR1
  357. mfspr r11,SPRN_HSRR0 /* save HSRR0 */
  358. andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
  359. addi r11,r11,-4 /* HSRR0 is next instruction */
  360. bne+ denorm_assist
  361. #endif
  362. KVMTEST(0x1500)
  363. EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
  364. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x1500)
  365. #ifdef CONFIG_CBE_RAS
  366. STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
  367. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1602)
  368. #endif /* CONFIG_CBE_RAS */
  369. STD_EXCEPTION_PSERIES(0x1700, 0x1700, altivec_assist)
  370. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x1700)
  371. #ifdef CONFIG_CBE_RAS
  372. STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
  373. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
  374. #else
  375. . = 0x1800
  376. #endif /* CONFIG_CBE_RAS */
  377. /*** Out of line interrupts support ***/
  378. .align 7
  379. /* moved from 0x200 */
  380. machine_check_pSeries_early:
  381. BEGIN_FTR_SECTION
  382. EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
  383. /*
  384. * Register contents:
  385. * R13 = PACA
  386. * R9 = CR
  387. * Original R9 to R13 is saved on PACA_EXMC
  388. *
  389. * Switch to mc_emergency stack and handle re-entrancy (we limit
  390. * the nested MCE upto level 4 to avoid stack overflow).
  391. * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
  392. *
  393. * We use paca->in_mce to check whether this is the first entry or
  394. * nested machine check. We increment paca->in_mce to track nested
  395. * machine checks.
  396. *
  397. * If this is the first entry then set stack pointer to
  398. * paca->mc_emergency_sp, otherwise r1 is already pointing to
  399. * stack frame on mc_emergency stack.
  400. *
  401. * NOTE: We are here with MSR_ME=0 (off), which means we risk a
  402. * checkstop if we get another machine check exception before we do
  403. * rfid with MSR_ME=1.
  404. */
  405. mr r11,r1 /* Save r1 */
  406. lhz r10,PACA_IN_MCE(r13)
  407. cmpwi r10,0 /* Are we in nested machine check */
  408. bne 0f /* Yes, we are. */
  409. /* First machine check entry */
  410. ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
  411. 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  412. addi r10,r10,1 /* increment paca->in_mce */
  413. sth r10,PACA_IN_MCE(r13)
  414. /* Limit nested MCE to level 4 to avoid stack overflow */
  415. cmpwi r10,4
  416. bgt 2f /* Check if we hit limit of 4 */
  417. std r11,GPR1(r1) /* Save r1 on the stack. */
  418. std r11,0(r1) /* make stack chain pointer */
  419. mfspr r11,SPRN_SRR0 /* Save SRR0 */
  420. std r11,_NIP(r1)
  421. mfspr r11,SPRN_SRR1 /* Save SRR1 */
  422. std r11,_MSR(r1)
  423. mfspr r11,SPRN_DAR /* Save DAR */
  424. std r11,_DAR(r1)
  425. mfspr r11,SPRN_DSISR /* Save DSISR */
  426. std r11,_DSISR(r1)
  427. std r9,_CCR(r1) /* Save CR in stackframe */
  428. /* Save r9 through r13 from EXMC save area to stack frame. */
  429. EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
  430. mfmsr r11 /* get MSR value */
  431. ori r11,r11,MSR_ME /* turn on ME bit */
  432. ori r11,r11,MSR_RI /* turn on RI bit */
  433. ld r12,PACAKBASE(r13) /* get high part of &label */
  434. LOAD_HANDLER(r12, machine_check_handle_early)
  435. 1: mtspr SPRN_SRR0,r12
  436. mtspr SPRN_SRR1,r11
  437. rfid
  438. b . /* prevent speculative execution */
  439. 2:
  440. /* Stack overflow. Stay on emergency stack and panic.
  441. * Keep the ME bit off while panic-ing, so that if we hit
  442. * another machine check we checkstop.
  443. */
  444. addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
  445. ld r11,PACAKMSR(r13)
  446. ld r12,PACAKBASE(r13)
  447. LOAD_HANDLER(r12, unrecover_mce)
  448. li r10,MSR_ME
  449. andc r11,r11,r10 /* Turn off MSR_ME */
  450. b 1b
  451. b . /* prevent speculative execution */
  452. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
  453. machine_check_pSeries:
  454. .globl machine_check_fwnmi
  455. machine_check_fwnmi:
  456. HMT_MEDIUM_PPR_DISCARD
  457. SET_SCRATCH0(r13) /* save r13 */
  458. EXCEPTION_PROLOG_0(PACA_EXMC)
  459. machine_check_pSeries_0:
  460. EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST, 0x200)
  461. EXCEPTION_PROLOG_PSERIES_1(machine_check_common, EXC_STD)
  462. KVM_HANDLER_SKIP(PACA_EXMC, EXC_STD, 0x200)
  463. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x300)
  464. KVM_HANDLER_SKIP(PACA_EXSLB, EXC_STD, 0x380)
  465. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x400)
  466. KVM_HANDLER_PR(PACA_EXSLB, EXC_STD, 0x480)
  467. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x900)
  468. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x982)
  469. #ifdef CONFIG_PPC_DENORMALISATION
  470. denorm_assist:
  471. BEGIN_FTR_SECTION
  472. /*
  473. * To denormalise we need to move a copy of the register to itself.
  474. * For POWER6 do that here for all FP regs.
  475. */
  476. mfmsr r10
  477. ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
  478. xori r10,r10,(MSR_FE0|MSR_FE1)
  479. mtmsrd r10
  480. sync
  481. #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
  482. #define FMR4(n) FMR2(n) ; FMR2(n+2)
  483. #define FMR8(n) FMR4(n) ; FMR4(n+4)
  484. #define FMR16(n) FMR8(n) ; FMR8(n+8)
  485. #define FMR32(n) FMR16(n) ; FMR16(n+16)
  486. FMR32(0)
  487. FTR_SECTION_ELSE
  488. /*
  489. * To denormalise we need to move a copy of the register to itself.
  490. * For POWER7 do that here for the first 32 VSX registers only.
  491. */
  492. mfmsr r10
  493. oris r10,r10,MSR_VSX@h
  494. mtmsrd r10
  495. sync
  496. #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
  497. #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
  498. #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
  499. #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
  500. #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
  501. XVCPSGNDP32(0)
  502. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
  503. BEGIN_FTR_SECTION
  504. b denorm_done
  505. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  506. /*
  507. * To denormalise we need to move a copy of the register to itself.
  508. * For POWER8 we need to do that for all 64 VSX registers
  509. */
  510. XVCPSGNDP32(32)
  511. denorm_done:
  512. mtspr SPRN_HSRR0,r11
  513. mtcrf 0x80,r9
  514. ld r9,PACA_EXGEN+EX_R9(r13)
  515. RESTORE_PPR_PACA(PACA_EXGEN, r10)
  516. BEGIN_FTR_SECTION
  517. ld r10,PACA_EXGEN+EX_CFAR(r13)
  518. mtspr SPRN_CFAR,r10
  519. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  520. ld r10,PACA_EXGEN+EX_R10(r13)
  521. ld r11,PACA_EXGEN+EX_R11(r13)
  522. ld r12,PACA_EXGEN+EX_R12(r13)
  523. ld r13,PACA_EXGEN+EX_R13(r13)
  524. HRFID
  525. b .
  526. #endif
  527. .align 7
  528. /* moved from 0xe00 */
  529. STD_EXCEPTION_HV_OOL(0xe02, h_data_storage)
  530. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0xe02)
  531. STD_EXCEPTION_HV_OOL(0xe22, h_instr_storage)
  532. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe22)
  533. STD_EXCEPTION_HV_OOL(0xe42, emulation_assist)
  534. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe42)
  535. MASKABLE_EXCEPTION_HV_OOL(0xe62, hmi_exception)
  536. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe62)
  537. MASKABLE_EXCEPTION_HV_OOL(0xe82, h_doorbell)
  538. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe82)
  539. /* moved from 0xf00 */
  540. STD_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
  541. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf00)
  542. STD_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
  543. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf20)
  544. STD_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
  545. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf40)
  546. STD_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
  547. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf60)
  548. STD_EXCEPTION_HV_OOL(0xf82, facility_unavailable)
  549. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xf82)
  550. /*
  551. * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
  552. * - If it was a decrementer interrupt, we bump the dec to max and and return.
  553. * - If it was a doorbell we return immediately since doorbells are edge
  554. * triggered and won't automatically refire.
  555. * - If it was a HMI we return immediately since we handled it in realmode
  556. * and it won't refire.
  557. * - else we hard disable and return.
  558. * This is called with r10 containing the value to OR to the paca field.
  559. */
  560. #define MASKED_INTERRUPT(_H) \
  561. masked_##_H##interrupt: \
  562. std r11,PACA_EXGEN+EX_R11(r13); \
  563. lbz r11,PACAIRQHAPPENED(r13); \
  564. or r11,r11,r10; \
  565. stb r11,PACAIRQHAPPENED(r13); \
  566. cmpwi r10,PACA_IRQ_DEC; \
  567. bne 1f; \
  568. lis r10,0x7fff; \
  569. ori r10,r10,0xffff; \
  570. mtspr SPRN_DEC,r10; \
  571. b 2f; \
  572. 1: cmpwi r10,PACA_IRQ_DBELL; \
  573. beq 2f; \
  574. cmpwi r10,PACA_IRQ_HMI; \
  575. beq 2f; \
  576. mfspr r10,SPRN_##_H##SRR1; \
  577. rldicl r10,r10,48,1; /* clear MSR_EE */ \
  578. rotldi r10,r10,16; \
  579. mtspr SPRN_##_H##SRR1,r10; \
  580. 2: mtcrf 0x80,r9; \
  581. ld r9,PACA_EXGEN+EX_R9(r13); \
  582. ld r10,PACA_EXGEN+EX_R10(r13); \
  583. ld r11,PACA_EXGEN+EX_R11(r13); \
  584. GET_SCRATCH0(r13); \
  585. ##_H##rfid; \
  586. b .
  587. MASKED_INTERRUPT()
  588. MASKED_INTERRUPT(H)
  589. /*
  590. * Called from arch_local_irq_enable when an interrupt needs
  591. * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
  592. * which kind of interrupt. MSR:EE is already off. We generate a
  593. * stackframe like if a real interrupt had happened.
  594. *
  595. * Note: While MSR:EE is off, we need to make sure that _MSR
  596. * in the generated frame has EE set to 1 or the exception
  597. * handler will not properly re-enable them.
  598. */
  599. _GLOBAL(__replay_interrupt)
  600. /* We are going to jump to the exception common code which
  601. * will retrieve various register values from the PACA which
  602. * we don't give a damn about, so we don't bother storing them.
  603. */
  604. mfmsr r12
  605. mflr r11
  606. mfcr r9
  607. ori r12,r12,MSR_EE
  608. cmpwi r3,0x900
  609. beq decrementer_common
  610. cmpwi r3,0x500
  611. beq hardware_interrupt_common
  612. BEGIN_FTR_SECTION
  613. cmpwi r3,0xe80
  614. beq h_doorbell_common
  615. FTR_SECTION_ELSE
  616. cmpwi r3,0xa00
  617. beq doorbell_super_common
  618. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  619. blr
  620. #ifdef CONFIG_PPC_PSERIES
  621. /*
  622. * Vectors for the FWNMI option. Share common code.
  623. */
  624. .globl system_reset_fwnmi
  625. .align 7
  626. system_reset_fwnmi:
  627. HMT_MEDIUM_PPR_DISCARD
  628. SET_SCRATCH0(r13) /* save r13 */
  629. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
  630. NOTEST, 0x100)
  631. #endif /* CONFIG_PPC_PSERIES */
  632. #ifdef __DISABLED__
  633. /*
  634. * This is used for when the SLB miss handler has to go virtual,
  635. * which doesn't happen for now anymore but will once we re-implement
  636. * dynamic VSIDs for shared page tables
  637. */
  638. slb_miss_user_pseries:
  639. std r10,PACA_EXGEN+EX_R10(r13)
  640. std r11,PACA_EXGEN+EX_R11(r13)
  641. std r12,PACA_EXGEN+EX_R12(r13)
  642. GET_SCRATCH0(r10)
  643. ld r11,PACA_EXSLB+EX_R9(r13)
  644. ld r12,PACA_EXSLB+EX_R3(r13)
  645. std r10,PACA_EXGEN+EX_R13(r13)
  646. std r11,PACA_EXGEN+EX_R9(r13)
  647. std r12,PACA_EXGEN+EX_R3(r13)
  648. clrrdi r12,r13,32
  649. mfmsr r10
  650. mfspr r11,SRR0 /* save SRR0 */
  651. ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
  652. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  653. mtspr SRR0,r12
  654. mfspr r12,SRR1 /* and SRR1 */
  655. mtspr SRR1,r10
  656. rfid
  657. b . /* prevent spec. execution */
  658. #endif /* __DISABLED__ */
  659. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  660. kvmppc_skip_interrupt:
  661. /*
  662. * Here all GPRs are unchanged from when the interrupt happened
  663. * except for r13, which is saved in SPRG_SCRATCH0.
  664. */
  665. mfspr r13, SPRN_SRR0
  666. addi r13, r13, 4
  667. mtspr SPRN_SRR0, r13
  668. GET_SCRATCH0(r13)
  669. rfid
  670. b .
  671. kvmppc_skip_Hinterrupt:
  672. /*
  673. * Here all GPRs are unchanged from when the interrupt happened
  674. * except for r13, which is saved in SPRG_SCRATCH0.
  675. */
  676. mfspr r13, SPRN_HSRR0
  677. addi r13, r13, 4
  678. mtspr SPRN_HSRR0, r13
  679. GET_SCRATCH0(r13)
  680. hrfid
  681. b .
  682. #endif
  683. /*
  684. * Code from here down to __end_handlers is invoked from the
  685. * exception prologs above. Because the prologs assemble the
  686. * addresses of these handlers using the LOAD_HANDLER macro,
  687. * which uses an ori instruction, these handlers must be in
  688. * the first 64k of the kernel image.
  689. */
  690. /*** Common interrupt handlers ***/
  691. STD_EXCEPTION_COMMON(0x100, system_reset, system_reset_exception)
  692. STD_EXCEPTION_COMMON_ASYNC(0x500, hardware_interrupt, do_IRQ)
  693. STD_EXCEPTION_COMMON_ASYNC(0x900, decrementer, timer_interrupt)
  694. STD_EXCEPTION_COMMON(0x980, hdecrementer, hdec_interrupt)
  695. #ifdef CONFIG_PPC_DOORBELL
  696. STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, doorbell_exception)
  697. #else
  698. STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, unknown_exception)
  699. #endif
  700. STD_EXCEPTION_COMMON(0xb00, trap_0b, unknown_exception)
  701. STD_EXCEPTION_COMMON(0xd00, single_step, single_step_exception)
  702. STD_EXCEPTION_COMMON(0xe00, trap_0e, unknown_exception)
  703. STD_EXCEPTION_COMMON(0xe40, emulation_assist, emulation_assist_interrupt)
  704. STD_EXCEPTION_COMMON_ASYNC(0xe60, hmi_exception, handle_hmi_exception)
  705. #ifdef CONFIG_PPC_DOORBELL
  706. STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, doorbell_exception)
  707. #else
  708. STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, unknown_exception)
  709. #endif
  710. STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, performance_monitor_exception)
  711. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, instruction_breakpoint_exception)
  712. STD_EXCEPTION_COMMON(0x1502, denorm, unknown_exception)
  713. #ifdef CONFIG_ALTIVEC
  714. STD_EXCEPTION_COMMON(0x1700, altivec_assist, altivec_assist_exception)
  715. #else
  716. STD_EXCEPTION_COMMON(0x1700, altivec_assist, unknown_exception)
  717. #endif
  718. #ifdef CONFIG_CBE_RAS
  719. STD_EXCEPTION_COMMON(0x1200, cbe_system_error, cbe_system_error_exception)
  720. STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, cbe_maintenance_exception)
  721. STD_EXCEPTION_COMMON(0x1800, cbe_thermal, cbe_thermal_exception)
  722. #endif /* CONFIG_CBE_RAS */
  723. /*
  724. * Relocation-on interrupts: A subset of the interrupts can be delivered
  725. * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
  726. * it. Addresses are the same as the original interrupt addresses, but
  727. * offset by 0xc000000000004000.
  728. * It's impossible to receive interrupts below 0x300 via this mechanism.
  729. * KVM: None of these traps are from the guest ; anything that escalated
  730. * to HV=1 from HV=0 is delivered via real mode handlers.
  731. */
  732. /*
  733. * This uses the standard macro, since the original 0x300 vector
  734. * only has extra guff for STAB-based processors -- which never
  735. * come here.
  736. */
  737. STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
  738. . = 0x4380
  739. .globl data_access_slb_relon_pSeries
  740. data_access_slb_relon_pSeries:
  741. SET_SCRATCH0(r13)
  742. EXCEPTION_PROLOG_0(PACA_EXSLB)
  743. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
  744. std r3,PACA_EXSLB+EX_R3(r13)
  745. mfspr r3,SPRN_DAR
  746. mfspr r12,SPRN_SRR1
  747. #ifndef CONFIG_RELOCATABLE
  748. b slb_miss_realmode
  749. #else
  750. /*
  751. * We can't just use a direct branch to slb_miss_realmode
  752. * because the distance from here to there depends on where
  753. * the kernel ends up being put.
  754. */
  755. mfctr r11
  756. ld r10,PACAKBASE(r13)
  757. LOAD_HANDLER(r10, slb_miss_realmode)
  758. mtctr r10
  759. bctr
  760. #endif
  761. STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
  762. . = 0x4480
  763. .globl instruction_access_slb_relon_pSeries
  764. instruction_access_slb_relon_pSeries:
  765. SET_SCRATCH0(r13)
  766. EXCEPTION_PROLOG_0(PACA_EXSLB)
  767. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
  768. std r3,PACA_EXSLB+EX_R3(r13)
  769. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  770. mfspr r12,SPRN_SRR1
  771. #ifndef CONFIG_RELOCATABLE
  772. b slb_miss_realmode
  773. #else
  774. mfctr r11
  775. ld r10,PACAKBASE(r13)
  776. LOAD_HANDLER(r10, slb_miss_realmode)
  777. mtctr r10
  778. bctr
  779. #endif
  780. . = 0x4500
  781. .globl hardware_interrupt_relon_pSeries;
  782. .globl hardware_interrupt_relon_hv;
  783. hardware_interrupt_relon_pSeries:
  784. hardware_interrupt_relon_hv:
  785. BEGIN_FTR_SECTION
  786. _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
  787. FTR_SECTION_ELSE
  788. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
  789. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  790. STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
  791. STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
  792. STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
  793. MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
  794. STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
  795. MASKABLE_RELON_EXCEPTION_PSERIES(0x4a00, 0xa00, doorbell_super)
  796. STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
  797. . = 0x4c00
  798. .globl system_call_relon_pSeries
  799. system_call_relon_pSeries:
  800. HMT_MEDIUM
  801. SYSCALL_PSERIES_1
  802. SYSCALL_PSERIES_2_DIRECT
  803. SYSCALL_PSERIES_3
  804. STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
  805. . = 0x4e00
  806. b . /* Can't happen, see v2.07 Book III-S section 6.5 */
  807. . = 0x4e20
  808. b . /* Can't happen, see v2.07 Book III-S section 6.5 */
  809. . = 0x4e40
  810. emulation_assist_relon_trampoline:
  811. SET_SCRATCH0(r13)
  812. EXCEPTION_PROLOG_0(PACA_EXGEN)
  813. b emulation_assist_relon_hv
  814. . = 0x4e60
  815. b . /* Can't happen, see v2.07 Book III-S section 6.5 */
  816. . = 0x4e80
  817. h_doorbell_relon_trampoline:
  818. SET_SCRATCH0(r13)
  819. EXCEPTION_PROLOG_0(PACA_EXGEN)
  820. b h_doorbell_relon_hv
  821. . = 0x4f00
  822. performance_monitor_relon_pseries_trampoline:
  823. SET_SCRATCH0(r13)
  824. EXCEPTION_PROLOG_0(PACA_EXGEN)
  825. b performance_monitor_relon_pSeries
  826. . = 0x4f20
  827. altivec_unavailable_relon_pseries_trampoline:
  828. SET_SCRATCH0(r13)
  829. EXCEPTION_PROLOG_0(PACA_EXGEN)
  830. b altivec_unavailable_relon_pSeries
  831. . = 0x4f40
  832. vsx_unavailable_relon_pseries_trampoline:
  833. SET_SCRATCH0(r13)
  834. EXCEPTION_PROLOG_0(PACA_EXGEN)
  835. b vsx_unavailable_relon_pSeries
  836. . = 0x4f60
  837. facility_unavailable_relon_trampoline:
  838. SET_SCRATCH0(r13)
  839. EXCEPTION_PROLOG_0(PACA_EXGEN)
  840. b facility_unavailable_relon_pSeries
  841. . = 0x4f80
  842. hv_facility_unavailable_relon_trampoline:
  843. SET_SCRATCH0(r13)
  844. EXCEPTION_PROLOG_0(PACA_EXGEN)
  845. b hv_facility_unavailable_relon_hv
  846. STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
  847. #ifdef CONFIG_PPC_DENORMALISATION
  848. . = 0x5500
  849. b denorm_exception_hv
  850. #endif
  851. STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
  852. /* Other future vectors */
  853. .align 7
  854. .globl __end_interrupts
  855. __end_interrupts:
  856. .align 7
  857. system_call_entry_direct:
  858. #if defined(CONFIG_RELOCATABLE)
  859. /* The first level prologue may have used LR to get here, saving
  860. * orig in r10. To save hacking/ifdeffing common code, restore here.
  861. */
  862. mtlr r10
  863. #endif
  864. system_call_entry:
  865. b system_call_common
  866. ppc64_runlatch_on_trampoline:
  867. b __ppc64_runlatch_on
  868. /*
  869. * Here r13 points to the paca, r9 contains the saved CR,
  870. * SRR0 and SRR1 are saved in r11 and r12,
  871. * r9 - r13 are saved in paca->exgen.
  872. */
  873. .align 7
  874. .globl data_access_common
  875. data_access_common:
  876. mfspr r10,SPRN_DAR
  877. std r10,PACA_EXGEN+EX_DAR(r13)
  878. mfspr r10,SPRN_DSISR
  879. stw r10,PACA_EXGEN+EX_DSISR(r13)
  880. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  881. RECONCILE_IRQ_STATE(r10, r11)
  882. ld r12,_MSR(r1)
  883. ld r3,PACA_EXGEN+EX_DAR(r13)
  884. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  885. li r5,0x300
  886. b do_hash_page /* Try to handle as hpte fault */
  887. .align 7
  888. .globl h_data_storage_common
  889. h_data_storage_common:
  890. mfspr r10,SPRN_HDAR
  891. std r10,PACA_EXGEN+EX_DAR(r13)
  892. mfspr r10,SPRN_HDSISR
  893. stw r10,PACA_EXGEN+EX_DSISR(r13)
  894. EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
  895. bl save_nvgprs
  896. RECONCILE_IRQ_STATE(r10, r11)
  897. addi r3,r1,STACK_FRAME_OVERHEAD
  898. bl unknown_exception
  899. b ret_from_except
  900. .align 7
  901. .globl instruction_access_common
  902. instruction_access_common:
  903. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  904. RECONCILE_IRQ_STATE(r10, r11)
  905. ld r12,_MSR(r1)
  906. ld r3,_NIP(r1)
  907. andis. r4,r12,0x5820
  908. li r5,0x400
  909. b do_hash_page /* Try to handle as hpte fault */
  910. STD_EXCEPTION_COMMON(0xe20, h_instr_storage, unknown_exception)
  911. /*
  912. * Here is the common SLB miss user that is used when going to virtual
  913. * mode for SLB misses, that is currently not used
  914. */
  915. #ifdef __DISABLED__
  916. .align 7
  917. .globl slb_miss_user_common
  918. slb_miss_user_common:
  919. mflr r10
  920. std r3,PACA_EXGEN+EX_DAR(r13)
  921. stw r9,PACA_EXGEN+EX_CCR(r13)
  922. std r10,PACA_EXGEN+EX_LR(r13)
  923. std r11,PACA_EXGEN+EX_SRR0(r13)
  924. bl slb_allocate_user
  925. ld r10,PACA_EXGEN+EX_LR(r13)
  926. ld r3,PACA_EXGEN+EX_R3(r13)
  927. lwz r9,PACA_EXGEN+EX_CCR(r13)
  928. ld r11,PACA_EXGEN+EX_SRR0(r13)
  929. mtlr r10
  930. beq- slb_miss_fault
  931. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  932. beq- unrecov_user_slb
  933. mfmsr r10
  934. .machine push
  935. .machine "power4"
  936. mtcrf 0x80,r9
  937. .machine pop
  938. clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
  939. mtmsrd r10,1
  940. mtspr SRR0,r11
  941. mtspr SRR1,r12
  942. ld r9,PACA_EXGEN+EX_R9(r13)
  943. ld r10,PACA_EXGEN+EX_R10(r13)
  944. ld r11,PACA_EXGEN+EX_R11(r13)
  945. ld r12,PACA_EXGEN+EX_R12(r13)
  946. ld r13,PACA_EXGEN+EX_R13(r13)
  947. rfid
  948. b .
  949. slb_miss_fault:
  950. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
  951. ld r4,PACA_EXGEN+EX_DAR(r13)
  952. li r5,0
  953. std r4,_DAR(r1)
  954. std r5,_DSISR(r1)
  955. b handle_page_fault
  956. unrecov_user_slb:
  957. EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
  958. RECONCILE_IRQ_STATE(r10, r11)
  959. bl save_nvgprs
  960. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  961. bl unrecoverable_exception
  962. b 1b
  963. #endif /* __DISABLED__ */
  964. /*
  965. * Machine check is different because we use a different
  966. * save area: PACA_EXMC instead of PACA_EXGEN.
  967. */
  968. .align 7
  969. .globl machine_check_common
  970. machine_check_common:
  971. mfspr r10,SPRN_DAR
  972. std r10,PACA_EXGEN+EX_DAR(r13)
  973. mfspr r10,SPRN_DSISR
  974. stw r10,PACA_EXGEN+EX_DSISR(r13)
  975. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  976. FINISH_NAP
  977. RECONCILE_IRQ_STATE(r10, r11)
  978. ld r3,PACA_EXGEN+EX_DAR(r13)
  979. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  980. std r3,_DAR(r1)
  981. std r4,_DSISR(r1)
  982. bl save_nvgprs
  983. addi r3,r1,STACK_FRAME_OVERHEAD
  984. bl machine_check_exception
  985. b ret_from_except
  986. .align 7
  987. .globl alignment_common
  988. alignment_common:
  989. mfspr r10,SPRN_DAR
  990. std r10,PACA_EXGEN+EX_DAR(r13)
  991. mfspr r10,SPRN_DSISR
  992. stw r10,PACA_EXGEN+EX_DSISR(r13)
  993. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  994. ld r3,PACA_EXGEN+EX_DAR(r13)
  995. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  996. std r3,_DAR(r1)
  997. std r4,_DSISR(r1)
  998. bl save_nvgprs
  999. RECONCILE_IRQ_STATE(r10, r11)
  1000. addi r3,r1,STACK_FRAME_OVERHEAD
  1001. bl alignment_exception
  1002. b ret_from_except
  1003. .align 7
  1004. .globl program_check_common
  1005. program_check_common:
  1006. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  1007. bl save_nvgprs
  1008. RECONCILE_IRQ_STATE(r10, r11)
  1009. addi r3,r1,STACK_FRAME_OVERHEAD
  1010. bl program_check_exception
  1011. b ret_from_except
  1012. .align 7
  1013. .globl fp_unavailable_common
  1014. fp_unavailable_common:
  1015. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  1016. bne 1f /* if from user, just load it up */
  1017. bl save_nvgprs
  1018. RECONCILE_IRQ_STATE(r10, r11)
  1019. addi r3,r1,STACK_FRAME_OVERHEAD
  1020. bl kernel_fp_unavailable_exception
  1021. BUG_OPCODE
  1022. 1:
  1023. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1024. BEGIN_FTR_SECTION
  1025. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1026. * transaction), go do TM stuff
  1027. */
  1028. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1029. bne- 2f
  1030. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  1031. #endif
  1032. bl load_up_fpu
  1033. b fast_exception_return
  1034. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1035. 2: /* User process was in a transaction */
  1036. bl save_nvgprs
  1037. RECONCILE_IRQ_STATE(r10, r11)
  1038. addi r3,r1,STACK_FRAME_OVERHEAD
  1039. bl fp_unavailable_tm
  1040. b ret_from_except
  1041. #endif
  1042. .align 7
  1043. .globl altivec_unavailable_common
  1044. altivec_unavailable_common:
  1045. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  1046. #ifdef CONFIG_ALTIVEC
  1047. BEGIN_FTR_SECTION
  1048. beq 1f
  1049. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1050. BEGIN_FTR_SECTION_NESTED(69)
  1051. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1052. * transaction), go do TM stuff
  1053. */
  1054. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1055. bne- 2f
  1056. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1057. #endif
  1058. bl load_up_altivec
  1059. b fast_exception_return
  1060. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1061. 2: /* User process was in a transaction */
  1062. bl save_nvgprs
  1063. RECONCILE_IRQ_STATE(r10, r11)
  1064. addi r3,r1,STACK_FRAME_OVERHEAD
  1065. bl altivec_unavailable_tm
  1066. b ret_from_except
  1067. #endif
  1068. 1:
  1069. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1070. #endif
  1071. bl save_nvgprs
  1072. RECONCILE_IRQ_STATE(r10, r11)
  1073. addi r3,r1,STACK_FRAME_OVERHEAD
  1074. bl altivec_unavailable_exception
  1075. b ret_from_except
  1076. .align 7
  1077. .globl vsx_unavailable_common
  1078. vsx_unavailable_common:
  1079. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  1080. #ifdef CONFIG_VSX
  1081. BEGIN_FTR_SECTION
  1082. beq 1f
  1083. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1084. BEGIN_FTR_SECTION_NESTED(69)
  1085. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1086. * transaction), go do TM stuff
  1087. */
  1088. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1089. bne- 2f
  1090. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1091. #endif
  1092. b load_up_vsx
  1093. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1094. 2: /* User process was in a transaction */
  1095. bl save_nvgprs
  1096. RECONCILE_IRQ_STATE(r10, r11)
  1097. addi r3,r1,STACK_FRAME_OVERHEAD
  1098. bl vsx_unavailable_tm
  1099. b ret_from_except
  1100. #endif
  1101. 1:
  1102. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1103. #endif
  1104. bl save_nvgprs
  1105. RECONCILE_IRQ_STATE(r10, r11)
  1106. addi r3,r1,STACK_FRAME_OVERHEAD
  1107. bl vsx_unavailable_exception
  1108. b ret_from_except
  1109. STD_EXCEPTION_COMMON(0xf60, facility_unavailable, facility_unavailable_exception)
  1110. STD_EXCEPTION_COMMON(0xf80, hv_facility_unavailable, facility_unavailable_exception)
  1111. .align 7
  1112. .globl __end_handlers
  1113. __end_handlers:
  1114. /* Equivalents to the above handlers for relocation-on interrupt vectors */
  1115. STD_RELON_EXCEPTION_HV_OOL(0xe40, emulation_assist)
  1116. MASKABLE_RELON_EXCEPTION_HV_OOL(0xe80, h_doorbell)
  1117. STD_RELON_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
  1118. STD_RELON_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
  1119. STD_RELON_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
  1120. STD_RELON_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
  1121. STD_RELON_EXCEPTION_HV_OOL(0xf80, hv_facility_unavailable)
  1122. #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
  1123. /*
  1124. * Data area reserved for FWNMI option.
  1125. * This address (0x7000) is fixed by the RPA.
  1126. */
  1127. .= 0x7000
  1128. .globl fwnmi_data_area
  1129. fwnmi_data_area:
  1130. /* pseries and powernv need to keep the whole page from
  1131. * 0x7000 to 0x8000 free for use by the firmware
  1132. */
  1133. . = 0x8000
  1134. #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
  1135. .globl hmi_exception_early
  1136. hmi_exception_early:
  1137. EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0xe60)
  1138. mr r10,r1 /* Save r1 */
  1139. ld r1,PACAEMERGSP(r13) /* Use emergency stack */
  1140. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  1141. std r9,_CCR(r1) /* save CR in stackframe */
  1142. mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
  1143. std r11,_NIP(r1) /* save HSRR0 in stackframe */
  1144. mfspr r12,SPRN_HSRR1 /* Save SRR1 */
  1145. std r12,_MSR(r1) /* save SRR1 in stackframe */
  1146. std r10,0(r1) /* make stack chain pointer */
  1147. std r0,GPR0(r1) /* save r0 in stackframe */
  1148. std r10,GPR1(r1) /* save r1 in stackframe */
  1149. EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
  1150. EXCEPTION_PROLOG_COMMON_3(0xe60)
  1151. addi r3,r1,STACK_FRAME_OVERHEAD
  1152. bl hmi_exception_realmode
  1153. /* Windup the stack. */
  1154. /* Move original HSRR0 and HSRR1 into the respective regs */
  1155. ld r9,_MSR(r1)
  1156. mtspr SPRN_HSRR1,r9
  1157. ld r3,_NIP(r1)
  1158. mtspr SPRN_HSRR0,r3
  1159. ld r9,_CTR(r1)
  1160. mtctr r9
  1161. ld r9,_XER(r1)
  1162. mtxer r9
  1163. ld r9,_LINK(r1)
  1164. mtlr r9
  1165. REST_GPR(0, r1)
  1166. REST_8GPRS(2, r1)
  1167. REST_GPR(10, r1)
  1168. ld r11,_CCR(r1)
  1169. mtcr r11
  1170. REST_GPR(11, r1)
  1171. REST_2GPRS(12, r1)
  1172. /* restore original r1. */
  1173. ld r1,GPR1(r1)
  1174. /*
  1175. * Go to virtual mode and pull the HMI event information from
  1176. * firmware.
  1177. */
  1178. .globl hmi_exception_after_realmode
  1179. hmi_exception_after_realmode:
  1180. SET_SCRATCH0(r13)
  1181. EXCEPTION_PROLOG_0(PACA_EXGEN)
  1182. b hmi_exception_hv
  1183. #ifdef CONFIG_PPC_POWERNV
  1184. _GLOBAL(opal_mc_secondary_handler)
  1185. HMT_MEDIUM_PPR_DISCARD
  1186. SET_SCRATCH0(r13)
  1187. GET_PACA(r13)
  1188. clrldi r3,r3,2
  1189. tovirt(r3,r3)
  1190. std r3,PACA_OPAL_MC_EVT(r13)
  1191. ld r13,OPAL_MC_SRR0(r3)
  1192. mtspr SPRN_SRR0,r13
  1193. ld r13,OPAL_MC_SRR1(r3)
  1194. mtspr SPRN_SRR1,r13
  1195. ld r3,OPAL_MC_GPR3(r3)
  1196. GET_SCRATCH0(r13)
  1197. b machine_check_pSeries
  1198. #endif /* CONFIG_PPC_POWERNV */
  1199. #define MACHINE_CHECK_HANDLER_WINDUP \
  1200. /* Clear MSR_RI before setting SRR0 and SRR1. */\
  1201. li r0,MSR_RI; \
  1202. mfmsr r9; /* get MSR value */ \
  1203. andc r9,r9,r0; \
  1204. mtmsrd r9,1; /* Clear MSR_RI */ \
  1205. /* Move original SRR0 and SRR1 into the respective regs */ \
  1206. ld r9,_MSR(r1); \
  1207. mtspr SPRN_SRR1,r9; \
  1208. ld r3,_NIP(r1); \
  1209. mtspr SPRN_SRR0,r3; \
  1210. ld r9,_CTR(r1); \
  1211. mtctr r9; \
  1212. ld r9,_XER(r1); \
  1213. mtxer r9; \
  1214. ld r9,_LINK(r1); \
  1215. mtlr r9; \
  1216. REST_GPR(0, r1); \
  1217. REST_8GPRS(2, r1); \
  1218. REST_GPR(10, r1); \
  1219. ld r11,_CCR(r1); \
  1220. mtcr r11; \
  1221. /* Decrement paca->in_mce. */ \
  1222. lhz r12,PACA_IN_MCE(r13); \
  1223. subi r12,r12,1; \
  1224. sth r12,PACA_IN_MCE(r13); \
  1225. REST_GPR(11, r1); \
  1226. REST_2GPRS(12, r1); \
  1227. /* restore original r1. */ \
  1228. ld r1,GPR1(r1)
  1229. /*
  1230. * Handle machine check early in real mode. We come here with
  1231. * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
  1232. */
  1233. .align 7
  1234. .globl machine_check_handle_early
  1235. machine_check_handle_early:
  1236. std r0,GPR0(r1) /* Save r0 */
  1237. EXCEPTION_PROLOG_COMMON_3(0x200)
  1238. bl save_nvgprs
  1239. addi r3,r1,STACK_FRAME_OVERHEAD
  1240. bl machine_check_early
  1241. std r3,RESULT(r1) /* Save result */
  1242. ld r12,_MSR(r1)
  1243. #ifdef CONFIG_PPC_P7_NAP
  1244. /*
  1245. * Check if thread was in power saving mode. We come here when any
  1246. * of the following is true:
  1247. * a. thread wasn't in power saving mode
  1248. * b. thread was in power saving mode with no state loss or
  1249. * supervisor state loss
  1250. *
  1251. * Go back to nap again if (b) is true.
  1252. */
  1253. rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
  1254. beq 4f /* No, it wasn;t */
  1255. /* Thread was in power saving mode. Go back to nap again. */
  1256. cmpwi r11,2
  1257. bne 3f
  1258. /* Supervisor state loss */
  1259. li r0,1
  1260. stb r0,PACA_NAPSTATELOST(r13)
  1261. 3: bl machine_check_queue_event
  1262. MACHINE_CHECK_HANDLER_WINDUP
  1263. GET_PACA(r13)
  1264. ld r1,PACAR1(r13)
  1265. b power7_enter_nap_mode
  1266. 4:
  1267. #endif
  1268. /*
  1269. * Check if we are coming from hypervisor userspace. If yes then we
  1270. * continue in host kernel in V mode to deliver the MC event.
  1271. */
  1272. rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
  1273. beq 5f
  1274. andi. r11,r12,MSR_PR /* See if coming from user. */
  1275. bne 9f /* continue in V mode if we are. */
  1276. 5:
  1277. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  1278. /*
  1279. * We are coming from kernel context. Check if we are coming from
  1280. * guest. if yes, then we can continue. We will fall through
  1281. * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
  1282. */
  1283. lbz r11,HSTATE_IN_GUEST(r13)
  1284. cmpwi r11,0 /* Check if coming from guest */
  1285. bne 9f /* continue if we are. */
  1286. #endif
  1287. /*
  1288. * At this point we are not sure about what context we come from.
  1289. * Queue up the MCE event and return from the interrupt.
  1290. * But before that, check if this is an un-recoverable exception.
  1291. * If yes, then stay on emergency stack and panic.
  1292. */
  1293. andi. r11,r12,MSR_RI
  1294. bne 2f
  1295. 1: mfspr r11,SPRN_SRR0
  1296. ld r10,PACAKBASE(r13)
  1297. LOAD_HANDLER(r10,unrecover_mce)
  1298. mtspr SPRN_SRR0,r10
  1299. ld r10,PACAKMSR(r13)
  1300. /*
  1301. * We are going down. But there are chances that we might get hit by
  1302. * another MCE during panic path and we may run into unstable state
  1303. * with no way out. Hence, turn ME bit off while going down, so that
  1304. * when another MCE is hit during panic path, system will checkstop
  1305. * and hypervisor will get restarted cleanly by SP.
  1306. */
  1307. li r3,MSR_ME
  1308. andc r10,r10,r3 /* Turn off MSR_ME */
  1309. mtspr SPRN_SRR1,r10
  1310. rfid
  1311. b .
  1312. 2:
  1313. /*
  1314. * Check if we have successfully handled/recovered from error, if not
  1315. * then stay on emergency stack and panic.
  1316. */
  1317. ld r3,RESULT(r1) /* Load result */
  1318. cmpdi r3,0 /* see if we handled MCE successfully */
  1319. beq 1b /* if !handled then panic */
  1320. /*
  1321. * Return from MC interrupt.
  1322. * Queue up the MCE event so that we can log it later, while
  1323. * returning from kernel or opal call.
  1324. */
  1325. bl machine_check_queue_event
  1326. MACHINE_CHECK_HANDLER_WINDUP
  1327. rfid
  1328. 9:
  1329. /* Deliver the machine check to host kernel in V mode. */
  1330. MACHINE_CHECK_HANDLER_WINDUP
  1331. b machine_check_pSeries
  1332. unrecover_mce:
  1333. /* Invoke machine_check_exception to print MCE event and panic. */
  1334. addi r3,r1,STACK_FRAME_OVERHEAD
  1335. bl machine_check_exception
  1336. /*
  1337. * We will not reach here. Even if we did, there is no way out. Call
  1338. * unrecoverable_exception and die.
  1339. */
  1340. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1341. bl unrecoverable_exception
  1342. b 1b
  1343. /*
  1344. * r13 points to the PACA, r9 contains the saved CR,
  1345. * r12 contain the saved SRR1, SRR0 is still ready for return
  1346. * r3 has the faulting address
  1347. * r9 - r13 are saved in paca->exslb.
  1348. * r3 is saved in paca->slb_r3
  1349. * We assume we aren't going to take any exceptions during this procedure.
  1350. */
  1351. slb_miss_realmode:
  1352. mflr r10
  1353. #ifdef CONFIG_RELOCATABLE
  1354. mtctr r11
  1355. #endif
  1356. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1357. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  1358. bl slb_allocate_realmode
  1359. /* All done -- return from exception. */
  1360. ld r10,PACA_EXSLB+EX_LR(r13)
  1361. ld r3,PACA_EXSLB+EX_R3(r13)
  1362. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1363. mtlr r10
  1364. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  1365. beq- 2f
  1366. .machine push
  1367. .machine "power4"
  1368. mtcrf 0x80,r9
  1369. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  1370. .machine pop
  1371. RESTORE_PPR_PACA(PACA_EXSLB, r9)
  1372. ld r9,PACA_EXSLB+EX_R9(r13)
  1373. ld r10,PACA_EXSLB+EX_R10(r13)
  1374. ld r11,PACA_EXSLB+EX_R11(r13)
  1375. ld r12,PACA_EXSLB+EX_R12(r13)
  1376. ld r13,PACA_EXSLB+EX_R13(r13)
  1377. rfid
  1378. b . /* prevent speculative execution */
  1379. 2: mfspr r11,SPRN_SRR0
  1380. ld r10,PACAKBASE(r13)
  1381. LOAD_HANDLER(r10,unrecov_slb)
  1382. mtspr SPRN_SRR0,r10
  1383. ld r10,PACAKMSR(r13)
  1384. mtspr SPRN_SRR1,r10
  1385. rfid
  1386. b .
  1387. unrecov_slb:
  1388. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  1389. RECONCILE_IRQ_STATE(r10, r11)
  1390. bl save_nvgprs
  1391. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1392. bl unrecoverable_exception
  1393. b 1b
  1394. #ifdef CONFIG_PPC_970_NAP
  1395. power4_fixup_nap:
  1396. andc r9,r9,r10
  1397. std r9,TI_LOCAL_FLAGS(r11)
  1398. ld r10,_LINK(r1) /* make idle task do the */
  1399. std r10,_NIP(r1) /* equivalent of a blr */
  1400. blr
  1401. #endif
  1402. /*
  1403. * Hash table stuff
  1404. */
  1405. .align 7
  1406. do_hash_page:
  1407. std r3,_DAR(r1)
  1408. std r4,_DSISR(r1)
  1409. andis. r0,r4,0xa410 /* weird error? */
  1410. bne- handle_page_fault /* if not, try to insert a HPTE */
  1411. andis. r0,r4,DSISR_DABRMATCH@h
  1412. bne- handle_dabr_fault
  1413. CURRENT_THREAD_INFO(r11, r1)
  1414. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  1415. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  1416. bne 77f /* then don't call hash_page now */
  1417. /*
  1418. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  1419. * accessing a userspace segment (even from the kernel). We assume
  1420. * kernel addresses always have the high bit set.
  1421. */
  1422. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  1423. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  1424. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  1425. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  1426. ori r4,r4,1 /* add _PAGE_PRESENT */
  1427. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  1428. /*
  1429. * r3 contains the faulting address
  1430. * r4 contains the required access permissions
  1431. * r5 contains the trap number
  1432. *
  1433. * at return r3 = 0 for success, 1 for page fault, negative for error
  1434. */
  1435. bl hash_page /* build HPTE if possible */
  1436. cmpdi r3,0 /* see if hash_page succeeded */
  1437. /* Success */
  1438. beq fast_exc_return_irq /* Return from exception on success */
  1439. /* Error */
  1440. blt- 13f
  1441. /* Here we have a page fault that hash_page can't handle. */
  1442. handle_page_fault:
  1443. 11: ld r4,_DAR(r1)
  1444. ld r5,_DSISR(r1)
  1445. addi r3,r1,STACK_FRAME_OVERHEAD
  1446. bl do_page_fault
  1447. cmpdi r3,0
  1448. beq+ 12f
  1449. bl save_nvgprs
  1450. mr r5,r3
  1451. addi r3,r1,STACK_FRAME_OVERHEAD
  1452. lwz r4,_DAR(r1)
  1453. bl bad_page_fault
  1454. b ret_from_except
  1455. /* We have a data breakpoint exception - handle it */
  1456. handle_dabr_fault:
  1457. bl save_nvgprs
  1458. ld r4,_DAR(r1)
  1459. ld r5,_DSISR(r1)
  1460. addi r3,r1,STACK_FRAME_OVERHEAD
  1461. bl do_break
  1462. 12: b ret_from_except_lite
  1463. /* We have a page fault that hash_page could handle but HV refused
  1464. * the PTE insertion
  1465. */
  1466. 13: bl save_nvgprs
  1467. mr r5,r3
  1468. addi r3,r1,STACK_FRAME_OVERHEAD
  1469. ld r4,_DAR(r1)
  1470. bl low_hash_fault
  1471. b ret_from_except
  1472. /*
  1473. * We come here as a result of a DSI at a point where we don't want
  1474. * to call hash_page, such as when we are accessing memory (possibly
  1475. * user memory) inside a PMU interrupt that occurred while interrupts
  1476. * were soft-disabled. We want to invoke the exception handler for
  1477. * the access, or panic if there isn't a handler.
  1478. */
  1479. 77: bl save_nvgprs
  1480. mr r4,r3
  1481. addi r3,r1,STACK_FRAME_OVERHEAD
  1482. li r5,SIGSEGV
  1483. bl bad_page_fault
  1484. b ret_from_except
  1485. /*
  1486. * Here we have detected that the kernel stack pointer is bad.
  1487. * R9 contains the saved CR, r13 points to the paca,
  1488. * r10 contains the (bad) kernel stack pointer,
  1489. * r11 and r12 contain the saved SRR0 and SRR1.
  1490. * We switch to using an emergency stack, save the registers there,
  1491. * and call kernel_bad_stack(), which panics.
  1492. */
  1493. bad_stack:
  1494. ld r1,PACAEMERGSP(r13)
  1495. subi r1,r1,64+INT_FRAME_SIZE
  1496. std r9,_CCR(r1)
  1497. std r10,GPR1(r1)
  1498. std r11,_NIP(r1)
  1499. std r12,_MSR(r1)
  1500. mfspr r11,SPRN_DAR
  1501. mfspr r12,SPRN_DSISR
  1502. std r11,_DAR(r1)
  1503. std r12,_DSISR(r1)
  1504. mflr r10
  1505. mfctr r11
  1506. mfxer r12
  1507. std r10,_LINK(r1)
  1508. std r11,_CTR(r1)
  1509. std r12,_XER(r1)
  1510. SAVE_GPR(0,r1)
  1511. SAVE_GPR(2,r1)
  1512. ld r10,EX_R3(r3)
  1513. std r10,GPR3(r1)
  1514. SAVE_GPR(4,r1)
  1515. SAVE_4GPRS(5,r1)
  1516. ld r9,EX_R9(r3)
  1517. ld r10,EX_R10(r3)
  1518. SAVE_2GPRS(9,r1)
  1519. ld r9,EX_R11(r3)
  1520. ld r10,EX_R12(r3)
  1521. ld r11,EX_R13(r3)
  1522. std r9,GPR11(r1)
  1523. std r10,GPR12(r1)
  1524. std r11,GPR13(r1)
  1525. BEGIN_FTR_SECTION
  1526. ld r10,EX_CFAR(r3)
  1527. std r10,ORIG_GPR3(r1)
  1528. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1529. SAVE_8GPRS(14,r1)
  1530. SAVE_10GPRS(22,r1)
  1531. lhz r12,PACA_TRAP_SAVE(r13)
  1532. std r12,_TRAP(r1)
  1533. addi r11,r1,INT_FRAME_SIZE
  1534. std r11,0(r1)
  1535. li r12,0
  1536. std r12,0(r11)
  1537. ld r2,PACATOC(r13)
  1538. ld r11,exception_marker@toc(r2)
  1539. std r12,RESULT(r1)
  1540. std r11,STACK_FRAME_OVERHEAD-16(r1)
  1541. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1542. bl kernel_bad_stack
  1543. b 1b