exceptions-64s.S 48 KB

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