exceptions-64s.S 46 KB

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