exceptions-64s.S 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698
  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. /* Clear MSR_RI before setting SRR0 and SRR1. */
  1155. li r0,MSR_RI
  1156. mfmsr r9 /* get MSR value */
  1157. andc r9,r9,r0
  1158. mtmsrd r9,1 /* Clear MSR_RI */
  1159. /* Move original HSRR0 and HSRR1 into the respective regs */
  1160. ld r9,_MSR(r1)
  1161. mtspr SPRN_HSRR1,r9
  1162. ld r3,_NIP(r1)
  1163. mtspr SPRN_HSRR0,r3
  1164. ld r9,_CTR(r1)
  1165. mtctr r9
  1166. ld r9,_XER(r1)
  1167. mtxer r9
  1168. ld r9,_LINK(r1)
  1169. mtlr r9
  1170. REST_GPR(0, r1)
  1171. REST_8GPRS(2, r1)
  1172. REST_GPR(10, r1)
  1173. ld r11,_CCR(r1)
  1174. mtcr r11
  1175. REST_GPR(11, r1)
  1176. REST_2GPRS(12, r1)
  1177. /* restore original r1. */
  1178. ld r1,GPR1(r1)
  1179. /*
  1180. * Go to virtual mode and pull the HMI event information from
  1181. * firmware.
  1182. */
  1183. .globl hmi_exception_after_realmode
  1184. hmi_exception_after_realmode:
  1185. SET_SCRATCH0(r13)
  1186. EXCEPTION_PROLOG_0(PACA_EXGEN)
  1187. b hmi_exception_hv
  1188. #ifdef CONFIG_PPC_POWERNV
  1189. _GLOBAL(opal_mc_secondary_handler)
  1190. HMT_MEDIUM_PPR_DISCARD
  1191. SET_SCRATCH0(r13)
  1192. GET_PACA(r13)
  1193. clrldi r3,r3,2
  1194. tovirt(r3,r3)
  1195. std r3,PACA_OPAL_MC_EVT(r13)
  1196. ld r13,OPAL_MC_SRR0(r3)
  1197. mtspr SPRN_SRR0,r13
  1198. ld r13,OPAL_MC_SRR1(r3)
  1199. mtspr SPRN_SRR1,r13
  1200. ld r3,OPAL_MC_GPR3(r3)
  1201. GET_SCRATCH0(r13)
  1202. b machine_check_pSeries
  1203. #endif /* CONFIG_PPC_POWERNV */
  1204. #define MACHINE_CHECK_HANDLER_WINDUP \
  1205. /* Clear MSR_RI before setting SRR0 and SRR1. */\
  1206. li r0,MSR_RI; \
  1207. mfmsr r9; /* get MSR value */ \
  1208. andc r9,r9,r0; \
  1209. mtmsrd r9,1; /* Clear MSR_RI */ \
  1210. /* Move original SRR0 and SRR1 into the respective regs */ \
  1211. ld r9,_MSR(r1); \
  1212. mtspr SPRN_SRR1,r9; \
  1213. ld r3,_NIP(r1); \
  1214. mtspr SPRN_SRR0,r3; \
  1215. ld r9,_CTR(r1); \
  1216. mtctr r9; \
  1217. ld r9,_XER(r1); \
  1218. mtxer r9; \
  1219. ld r9,_LINK(r1); \
  1220. mtlr r9; \
  1221. REST_GPR(0, r1); \
  1222. REST_8GPRS(2, r1); \
  1223. REST_GPR(10, r1); \
  1224. ld r11,_CCR(r1); \
  1225. mtcr r11; \
  1226. /* Decrement paca->in_mce. */ \
  1227. lhz r12,PACA_IN_MCE(r13); \
  1228. subi r12,r12,1; \
  1229. sth r12,PACA_IN_MCE(r13); \
  1230. REST_GPR(11, r1); \
  1231. REST_2GPRS(12, r1); \
  1232. /* restore original r1. */ \
  1233. ld r1,GPR1(r1)
  1234. /*
  1235. * Handle machine check early in real mode. We come here with
  1236. * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
  1237. */
  1238. .align 7
  1239. .globl machine_check_handle_early
  1240. machine_check_handle_early:
  1241. std r0,GPR0(r1) /* Save r0 */
  1242. EXCEPTION_PROLOG_COMMON_3(0x200)
  1243. bl save_nvgprs
  1244. addi r3,r1,STACK_FRAME_OVERHEAD
  1245. bl machine_check_early
  1246. std r3,RESULT(r1) /* Save result */
  1247. ld r12,_MSR(r1)
  1248. #ifdef CONFIG_PPC_P7_NAP
  1249. /*
  1250. * Check if thread was in power saving mode. We come here when any
  1251. * of the following is true:
  1252. * a. thread wasn't in power saving mode
  1253. * b. thread was in power saving mode with no state loss or
  1254. * supervisor state loss
  1255. *
  1256. * Go back to nap again if (b) is true.
  1257. */
  1258. rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
  1259. beq 4f /* No, it wasn;t */
  1260. /* Thread was in power saving mode. Go back to nap again. */
  1261. cmpwi r11,2
  1262. bne 3f
  1263. /* Supervisor state loss */
  1264. li r0,1
  1265. stb r0,PACA_NAPSTATELOST(r13)
  1266. 3: bl machine_check_queue_event
  1267. MACHINE_CHECK_HANDLER_WINDUP
  1268. GET_PACA(r13)
  1269. ld r1,PACAR1(r13)
  1270. b power7_enter_nap_mode
  1271. 4:
  1272. #endif
  1273. /*
  1274. * Check if we are coming from hypervisor userspace. If yes then we
  1275. * continue in host kernel in V mode to deliver the MC event.
  1276. */
  1277. rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
  1278. beq 5f
  1279. andi. r11,r12,MSR_PR /* See if coming from user. */
  1280. bne 9f /* continue in V mode if we are. */
  1281. 5:
  1282. #ifdef CONFIG_KVM_BOOK3S_64_HV
  1283. /*
  1284. * We are coming from kernel context. Check if we are coming from
  1285. * guest. if yes, then we can continue. We will fall through
  1286. * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
  1287. */
  1288. lbz r11,HSTATE_IN_GUEST(r13)
  1289. cmpwi r11,0 /* Check if coming from guest */
  1290. bne 9f /* continue if we are. */
  1291. #endif
  1292. /*
  1293. * At this point we are not sure about what context we come from.
  1294. * Queue up the MCE event and return from the interrupt.
  1295. * But before that, check if this is an un-recoverable exception.
  1296. * If yes, then stay on emergency stack and panic.
  1297. */
  1298. andi. r11,r12,MSR_RI
  1299. bne 2f
  1300. 1: mfspr r11,SPRN_SRR0
  1301. ld r10,PACAKBASE(r13)
  1302. LOAD_HANDLER(r10,unrecover_mce)
  1303. mtspr SPRN_SRR0,r10
  1304. ld r10,PACAKMSR(r13)
  1305. /*
  1306. * We are going down. But there are chances that we might get hit by
  1307. * another MCE during panic path and we may run into unstable state
  1308. * with no way out. Hence, turn ME bit off while going down, so that
  1309. * when another MCE is hit during panic path, system will checkstop
  1310. * and hypervisor will get restarted cleanly by SP.
  1311. */
  1312. li r3,MSR_ME
  1313. andc r10,r10,r3 /* Turn off MSR_ME */
  1314. mtspr SPRN_SRR1,r10
  1315. rfid
  1316. b .
  1317. 2:
  1318. /*
  1319. * Check if we have successfully handled/recovered from error, if not
  1320. * then stay on emergency stack and panic.
  1321. */
  1322. ld r3,RESULT(r1) /* Load result */
  1323. cmpdi r3,0 /* see if we handled MCE successfully */
  1324. beq 1b /* if !handled then panic */
  1325. /*
  1326. * Return from MC interrupt.
  1327. * Queue up the MCE event so that we can log it later, while
  1328. * returning from kernel or opal call.
  1329. */
  1330. bl machine_check_queue_event
  1331. MACHINE_CHECK_HANDLER_WINDUP
  1332. rfid
  1333. 9:
  1334. /* Deliver the machine check to host kernel in V mode. */
  1335. MACHINE_CHECK_HANDLER_WINDUP
  1336. b machine_check_pSeries
  1337. unrecover_mce:
  1338. /* Invoke machine_check_exception to print MCE event and panic. */
  1339. addi r3,r1,STACK_FRAME_OVERHEAD
  1340. bl machine_check_exception
  1341. /*
  1342. * We will not reach here. Even if we did, there is no way out. Call
  1343. * unrecoverable_exception and die.
  1344. */
  1345. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1346. bl unrecoverable_exception
  1347. b 1b
  1348. /*
  1349. * r13 points to the PACA, r9 contains the saved CR,
  1350. * r12 contain the saved SRR1, SRR0 is still ready for return
  1351. * r3 has the faulting address
  1352. * r9 - r13 are saved in paca->exslb.
  1353. * r3 is saved in paca->slb_r3
  1354. * We assume we aren't going to take any exceptions during this procedure.
  1355. */
  1356. slb_miss_realmode:
  1357. mflr r10
  1358. #ifdef CONFIG_RELOCATABLE
  1359. mtctr r11
  1360. #endif
  1361. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1362. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  1363. bl slb_allocate_realmode
  1364. /* All done -- return from exception. */
  1365. ld r10,PACA_EXSLB+EX_LR(r13)
  1366. ld r3,PACA_EXSLB+EX_R3(r13)
  1367. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1368. mtlr r10
  1369. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  1370. beq- 2f
  1371. .machine push
  1372. .machine "power4"
  1373. mtcrf 0x80,r9
  1374. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  1375. .machine pop
  1376. RESTORE_PPR_PACA(PACA_EXSLB, r9)
  1377. ld r9,PACA_EXSLB+EX_R9(r13)
  1378. ld r10,PACA_EXSLB+EX_R10(r13)
  1379. ld r11,PACA_EXSLB+EX_R11(r13)
  1380. ld r12,PACA_EXSLB+EX_R12(r13)
  1381. ld r13,PACA_EXSLB+EX_R13(r13)
  1382. rfid
  1383. b . /* prevent speculative execution */
  1384. 2: mfspr r11,SPRN_SRR0
  1385. ld r10,PACAKBASE(r13)
  1386. LOAD_HANDLER(r10,unrecov_slb)
  1387. mtspr SPRN_SRR0,r10
  1388. ld r10,PACAKMSR(r13)
  1389. mtspr SPRN_SRR1,r10
  1390. rfid
  1391. b .
  1392. unrecov_slb:
  1393. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  1394. RECONCILE_IRQ_STATE(r10, r11)
  1395. bl save_nvgprs
  1396. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1397. bl unrecoverable_exception
  1398. b 1b
  1399. #ifdef CONFIG_PPC_970_NAP
  1400. power4_fixup_nap:
  1401. andc r9,r9,r10
  1402. std r9,TI_LOCAL_FLAGS(r11)
  1403. ld r10,_LINK(r1) /* make idle task do the */
  1404. std r10,_NIP(r1) /* equivalent of a blr */
  1405. blr
  1406. #endif
  1407. /*
  1408. * Hash table stuff
  1409. */
  1410. .align 7
  1411. do_hash_page:
  1412. std r3,_DAR(r1)
  1413. std r4,_DSISR(r1)
  1414. andis. r0,r4,0xa410 /* weird error? */
  1415. bne- handle_page_fault /* if not, try to insert a HPTE */
  1416. andis. r0,r4,DSISR_DABRMATCH@h
  1417. bne- handle_dabr_fault
  1418. CURRENT_THREAD_INFO(r11, r1)
  1419. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  1420. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  1421. bne 77f /* then don't call hash_page now */
  1422. /*
  1423. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  1424. * accessing a userspace segment (even from the kernel). We assume
  1425. * kernel addresses always have the high bit set.
  1426. */
  1427. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  1428. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  1429. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  1430. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  1431. ori r4,r4,1 /* add _PAGE_PRESENT */
  1432. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  1433. /*
  1434. * r3 contains the faulting address
  1435. * r4 contains the required access permissions
  1436. * r5 contains the trap number
  1437. *
  1438. * at return r3 = 0 for success, 1 for page fault, negative for error
  1439. */
  1440. bl hash_page /* build HPTE if possible */
  1441. cmpdi r3,0 /* see if hash_page succeeded */
  1442. /* Success */
  1443. beq fast_exc_return_irq /* Return from exception on success */
  1444. /* Error */
  1445. blt- 13f
  1446. /* Here we have a page fault that hash_page can't handle. */
  1447. handle_page_fault:
  1448. 11: ld r4,_DAR(r1)
  1449. ld r5,_DSISR(r1)
  1450. addi r3,r1,STACK_FRAME_OVERHEAD
  1451. bl do_page_fault
  1452. cmpdi r3,0
  1453. beq+ 12f
  1454. bl save_nvgprs
  1455. mr r5,r3
  1456. addi r3,r1,STACK_FRAME_OVERHEAD
  1457. lwz r4,_DAR(r1)
  1458. bl bad_page_fault
  1459. b ret_from_except
  1460. /* We have a data breakpoint exception - handle it */
  1461. handle_dabr_fault:
  1462. bl save_nvgprs
  1463. ld r4,_DAR(r1)
  1464. ld r5,_DSISR(r1)
  1465. addi r3,r1,STACK_FRAME_OVERHEAD
  1466. bl do_break
  1467. 12: b ret_from_except_lite
  1468. /* We have a page fault that hash_page could handle but HV refused
  1469. * the PTE insertion
  1470. */
  1471. 13: bl save_nvgprs
  1472. mr r5,r3
  1473. addi r3,r1,STACK_FRAME_OVERHEAD
  1474. ld r4,_DAR(r1)
  1475. bl low_hash_fault
  1476. b ret_from_except
  1477. /*
  1478. * We come here as a result of a DSI at a point where we don't want
  1479. * to call hash_page, such as when we are accessing memory (possibly
  1480. * user memory) inside a PMU interrupt that occurred while interrupts
  1481. * were soft-disabled. We want to invoke the exception handler for
  1482. * the access, or panic if there isn't a handler.
  1483. */
  1484. 77: bl save_nvgprs
  1485. mr r4,r3
  1486. addi r3,r1,STACK_FRAME_OVERHEAD
  1487. li r5,SIGSEGV
  1488. bl bad_page_fault
  1489. b ret_from_except
  1490. /*
  1491. * Here we have detected that the kernel stack pointer is bad.
  1492. * R9 contains the saved CR, r13 points to the paca,
  1493. * r10 contains the (bad) kernel stack pointer,
  1494. * r11 and r12 contain the saved SRR0 and SRR1.
  1495. * We switch to using an emergency stack, save the registers there,
  1496. * and call kernel_bad_stack(), which panics.
  1497. */
  1498. bad_stack:
  1499. ld r1,PACAEMERGSP(r13)
  1500. subi r1,r1,64+INT_FRAME_SIZE
  1501. std r9,_CCR(r1)
  1502. std r10,GPR1(r1)
  1503. std r11,_NIP(r1)
  1504. std r12,_MSR(r1)
  1505. mfspr r11,SPRN_DAR
  1506. mfspr r12,SPRN_DSISR
  1507. std r11,_DAR(r1)
  1508. std r12,_DSISR(r1)
  1509. mflr r10
  1510. mfctr r11
  1511. mfxer r12
  1512. std r10,_LINK(r1)
  1513. std r11,_CTR(r1)
  1514. std r12,_XER(r1)
  1515. SAVE_GPR(0,r1)
  1516. SAVE_GPR(2,r1)
  1517. ld r10,EX_R3(r3)
  1518. std r10,GPR3(r1)
  1519. SAVE_GPR(4,r1)
  1520. SAVE_4GPRS(5,r1)
  1521. ld r9,EX_R9(r3)
  1522. ld r10,EX_R10(r3)
  1523. SAVE_2GPRS(9,r1)
  1524. ld r9,EX_R11(r3)
  1525. ld r10,EX_R12(r3)
  1526. ld r11,EX_R13(r3)
  1527. std r9,GPR11(r1)
  1528. std r10,GPR12(r1)
  1529. std r11,GPR13(r1)
  1530. BEGIN_FTR_SECTION
  1531. ld r10,EX_CFAR(r3)
  1532. std r10,ORIG_GPR3(r1)
  1533. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1534. SAVE_8GPRS(14,r1)
  1535. SAVE_10GPRS(22,r1)
  1536. lhz r12,PACA_TRAP_SAVE(r13)
  1537. std r12,_TRAP(r1)
  1538. addi r11,r1,INT_FRAME_SIZE
  1539. std r11,0(r1)
  1540. li r12,0
  1541. std r12,0(r11)
  1542. ld r2,PACATOC(r13)
  1543. ld r11,exception_marker@toc(r2)
  1544. std r12,RESULT(r1)
  1545. std r11,STACK_FRAME_OVERHEAD-16(r1)
  1546. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1547. bl kernel_bad_stack
  1548. b 1b