exceptions-64s.S 46 KB

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