exceptions-64s.S 46 KB

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