exceptions-64s.S 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  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_64_HV
  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. EXCEPTION_PROLOG_0(PACA_EXMC)
  148. b machine_check_pSeries_0
  149. . = 0x300
  150. .globl data_access_pSeries
  151. data_access_pSeries:
  152. HMT_MEDIUM_PPR_DISCARD
  153. SET_SCRATCH0(r13)
  154. BEGIN_FTR_SECTION
  155. b data_access_check_stab
  156. data_access_not_stab:
  157. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
  158. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD,
  159. KVMTEST, 0x300)
  160. . = 0x380
  161. .globl data_access_slb_pSeries
  162. data_access_slb_pSeries:
  163. HMT_MEDIUM_PPR_DISCARD
  164. SET_SCRATCH0(r13)
  165. EXCEPTION_PROLOG_0(PACA_EXSLB)
  166. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x380)
  167. std r3,PACA_EXSLB+EX_R3(r13)
  168. mfspr r3,SPRN_DAR
  169. #ifdef __DISABLED__
  170. /* Keep that around for when we re-implement dynamic VSIDs */
  171. cmpdi r3,0
  172. bge slb_miss_user_pseries
  173. #endif /* __DISABLED__ */
  174. mfspr r12,SPRN_SRR1
  175. #ifndef CONFIG_RELOCATABLE
  176. b .slb_miss_realmode
  177. #else
  178. /*
  179. * We can't just use a direct branch to .slb_miss_realmode
  180. * because the distance from here to there depends on where
  181. * the kernel ends up being put.
  182. */
  183. mfctr r11
  184. ld r10,PACAKBASE(r13)
  185. LOAD_HANDLER(r10, .slb_miss_realmode)
  186. mtctr r10
  187. bctr
  188. #endif
  189. STD_EXCEPTION_PSERIES(0x400, 0x400, instruction_access)
  190. . = 0x480
  191. .globl instruction_access_slb_pSeries
  192. instruction_access_slb_pSeries:
  193. HMT_MEDIUM_PPR_DISCARD
  194. SET_SCRATCH0(r13)
  195. EXCEPTION_PROLOG_0(PACA_EXSLB)
  196. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
  197. std r3,PACA_EXSLB+EX_R3(r13)
  198. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  199. #ifdef __DISABLED__
  200. /* Keep that around for when we re-implement dynamic VSIDs */
  201. cmpdi r3,0
  202. bge slb_miss_user_pseries
  203. #endif /* __DISABLED__ */
  204. mfspr r12,SPRN_SRR1
  205. #ifndef CONFIG_RELOCATABLE
  206. b .slb_miss_realmode
  207. #else
  208. mfctr r11
  209. ld r10,PACAKBASE(r13)
  210. LOAD_HANDLER(r10, .slb_miss_realmode)
  211. mtctr r10
  212. bctr
  213. #endif
  214. /* We open code these as we can't have a ". = x" (even with
  215. * x = "." within a feature section
  216. */
  217. . = 0x500;
  218. .globl hardware_interrupt_pSeries;
  219. .globl hardware_interrupt_hv;
  220. hardware_interrupt_pSeries:
  221. hardware_interrupt_hv:
  222. HMT_MEDIUM_PPR_DISCARD
  223. BEGIN_FTR_SECTION
  224. _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt,
  225. EXC_HV, SOFTEN_TEST_HV)
  226. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
  227. FTR_SECTION_ELSE
  228. _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt,
  229. EXC_STD, SOFTEN_TEST_HV_201)
  230. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
  231. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  232. STD_EXCEPTION_PSERIES(0x600, 0x600, alignment)
  233. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x600)
  234. STD_EXCEPTION_PSERIES(0x700, 0x700, program_check)
  235. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x700)
  236. STD_EXCEPTION_PSERIES(0x800, 0x800, fp_unavailable)
  237. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x800)
  238. . = 0x900
  239. .globl decrementer_pSeries
  240. decrementer_pSeries:
  241. _MASKABLE_EXCEPTION_PSERIES(0x900, decrementer, EXC_STD, SOFTEN_TEST_PR)
  242. STD_EXCEPTION_HV(0x980, 0x982, hdecrementer)
  243. MASKABLE_EXCEPTION_PSERIES(0xa00, 0xa00, doorbell_super)
  244. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xa00)
  245. STD_EXCEPTION_PSERIES(0xb00, 0xb00, trap_0b)
  246. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xb00)
  247. . = 0xc00
  248. .globl system_call_pSeries
  249. system_call_pSeries:
  250. HMT_MEDIUM
  251. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  252. SET_SCRATCH0(r13)
  253. GET_PACA(r13)
  254. std r9,PACA_EXGEN+EX_R9(r13)
  255. std r10,PACA_EXGEN+EX_R10(r13)
  256. mfcr r9
  257. KVMTEST(0xc00)
  258. GET_SCRATCH0(r13)
  259. #endif
  260. SYSCALL_PSERIES_1
  261. SYSCALL_PSERIES_2_RFID
  262. SYSCALL_PSERIES_3
  263. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
  264. STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
  265. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
  266. /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
  267. * out of line to handle them
  268. */
  269. . = 0xe00
  270. hv_exception_trampoline:
  271. SET_SCRATCH0(r13)
  272. EXCEPTION_PROLOG_0(PACA_EXGEN)
  273. b h_data_storage_hv
  274. . = 0xe20
  275. SET_SCRATCH0(r13)
  276. EXCEPTION_PROLOG_0(PACA_EXGEN)
  277. b h_instr_storage_hv
  278. . = 0xe40
  279. SET_SCRATCH0(r13)
  280. EXCEPTION_PROLOG_0(PACA_EXGEN)
  281. b emulation_assist_hv
  282. . = 0xe60
  283. SET_SCRATCH0(r13)
  284. EXCEPTION_PROLOG_0(PACA_EXGEN)
  285. b hmi_exception_hv
  286. . = 0xe80
  287. SET_SCRATCH0(r13)
  288. EXCEPTION_PROLOG_0(PACA_EXGEN)
  289. b h_doorbell_hv
  290. /* We need to deal with the Altivec unavailable exception
  291. * here which is at 0xf20, thus in the middle of the
  292. * prolog code of the PerformanceMonitor one. A little
  293. * trickery is thus necessary
  294. */
  295. performance_monitor_pSeries_1:
  296. . = 0xf00
  297. SET_SCRATCH0(r13)
  298. EXCEPTION_PROLOG_0(PACA_EXGEN)
  299. b performance_monitor_pSeries
  300. altivec_unavailable_pSeries_1:
  301. . = 0xf20
  302. SET_SCRATCH0(r13)
  303. EXCEPTION_PROLOG_0(PACA_EXGEN)
  304. b altivec_unavailable_pSeries
  305. vsx_unavailable_pSeries_1:
  306. . = 0xf40
  307. SET_SCRATCH0(r13)
  308. EXCEPTION_PROLOG_0(PACA_EXGEN)
  309. b vsx_unavailable_pSeries
  310. facility_unavailable_trampoline:
  311. . = 0xf60
  312. SET_SCRATCH0(r13)
  313. EXCEPTION_PROLOG_0(PACA_EXGEN)
  314. b facility_unavailable_pSeries
  315. #ifdef CONFIG_CBE_RAS
  316. STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
  317. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1202)
  318. #endif /* CONFIG_CBE_RAS */
  319. STD_EXCEPTION_PSERIES(0x1300, 0x1300, instruction_breakpoint)
  320. KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
  321. . = 0x1500
  322. .global denorm_exception_hv
  323. denorm_exception_hv:
  324. HMT_MEDIUM_PPR_DISCARD
  325. mtspr SPRN_SPRG_HSCRATCH0,r13
  326. EXCEPTION_PROLOG_0(PACA_EXGEN)
  327. std r11,PACA_EXGEN+EX_R11(r13)
  328. std r12,PACA_EXGEN+EX_R12(r13)
  329. mfspr r9,SPRN_SPRG_HSCRATCH0
  330. std r9,PACA_EXGEN+EX_R13(r13)
  331. mfcr r9
  332. #ifdef CONFIG_PPC_DENORMALISATION
  333. mfspr r10,SPRN_HSRR1
  334. mfspr r11,SPRN_HSRR0 /* save HSRR0 */
  335. andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
  336. addi r11,r11,-4 /* HSRR0 is next instruction */
  337. bne+ denorm_assist
  338. #endif
  339. EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
  340. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x1500)
  341. #ifdef CONFIG_CBE_RAS
  342. STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
  343. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1602)
  344. #endif /* CONFIG_CBE_RAS */
  345. STD_EXCEPTION_PSERIES(0x1700, 0x1700, altivec_assist)
  346. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x1700)
  347. #ifdef CONFIG_CBE_RAS
  348. STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
  349. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
  350. #else
  351. . = 0x1800
  352. #endif /* CONFIG_CBE_RAS */
  353. /*** Out of line interrupts support ***/
  354. .align 7
  355. /* moved from 0x200 */
  356. machine_check_pSeries:
  357. .globl machine_check_fwnmi
  358. machine_check_fwnmi:
  359. HMT_MEDIUM_PPR_DISCARD
  360. SET_SCRATCH0(r13) /* save r13 */
  361. EXCEPTION_PROLOG_0(PACA_EXMC)
  362. machine_check_pSeries_0:
  363. EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST, 0x200)
  364. EXCEPTION_PROLOG_PSERIES_1(machine_check_common, EXC_STD)
  365. KVM_HANDLER_SKIP(PACA_EXMC, EXC_STD, 0x200)
  366. /* moved from 0x300 */
  367. data_access_check_stab:
  368. GET_PACA(r13)
  369. std r9,PACA_EXSLB+EX_R9(r13)
  370. std r10,PACA_EXSLB+EX_R10(r13)
  371. mfspr r10,SPRN_DAR
  372. mfspr r9,SPRN_DSISR
  373. srdi r10,r10,60
  374. rlwimi r10,r9,16,0x20
  375. #ifdef CONFIG_KVM_BOOK3S_PR
  376. lbz r9,HSTATE_IN_GUEST(r13)
  377. rlwimi r10,r9,8,0x300
  378. #endif
  379. mfcr r9
  380. cmpwi r10,0x2c
  381. beq do_stab_bolted_pSeries
  382. mtcrf 0x80,r9
  383. ld r9,PACA_EXSLB+EX_R9(r13)
  384. ld r10,PACA_EXSLB+EX_R10(r13)
  385. b data_access_not_stab
  386. do_stab_bolted_pSeries:
  387. std r11,PACA_EXSLB+EX_R11(r13)
  388. std r12,PACA_EXSLB+EX_R12(r13)
  389. GET_SCRATCH0(r10)
  390. std r10,PACA_EXSLB+EX_R13(r13)
  391. EXCEPTION_PROLOG_PSERIES_1(.do_stab_bolted, EXC_STD)
  392. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x300)
  393. KVM_HANDLER_SKIP(PACA_EXSLB, EXC_STD, 0x380)
  394. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x400)
  395. KVM_HANDLER_PR(PACA_EXSLB, EXC_STD, 0x480)
  396. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x900)
  397. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x982)
  398. #ifdef CONFIG_PPC_DENORMALISATION
  399. denorm_assist:
  400. BEGIN_FTR_SECTION
  401. /*
  402. * To denormalise we need to move a copy of the register to itself.
  403. * For POWER6 do that here for all FP regs.
  404. */
  405. mfmsr r10
  406. ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
  407. xori r10,r10,(MSR_FE0|MSR_FE1)
  408. mtmsrd r10
  409. sync
  410. #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
  411. #define FMR4(n) FMR2(n) ; FMR2(n+2)
  412. #define FMR8(n) FMR4(n) ; FMR4(n+4)
  413. #define FMR16(n) FMR8(n) ; FMR8(n+8)
  414. #define FMR32(n) FMR16(n) ; FMR16(n+16)
  415. FMR32(0)
  416. FTR_SECTION_ELSE
  417. /*
  418. * To denormalise we need to move a copy of the register to itself.
  419. * For POWER7 do that here for the first 32 VSX registers only.
  420. */
  421. mfmsr r10
  422. oris r10,r10,MSR_VSX@h
  423. mtmsrd r10
  424. sync
  425. #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
  426. #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
  427. #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
  428. #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
  429. #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
  430. XVCPSGNDP32(0)
  431. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
  432. BEGIN_FTR_SECTION
  433. b denorm_done
  434. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  435. /*
  436. * To denormalise we need to move a copy of the register to itself.
  437. * For POWER8 we need to do that for all 64 VSX registers
  438. */
  439. XVCPSGNDP32(32)
  440. denorm_done:
  441. mtspr SPRN_HSRR0,r11
  442. mtcrf 0x80,r9
  443. ld r9,PACA_EXGEN+EX_R9(r13)
  444. RESTORE_PPR_PACA(PACA_EXGEN, r10)
  445. ld r10,PACA_EXGEN+EX_R10(r13)
  446. ld r11,PACA_EXGEN+EX_R11(r13)
  447. ld r12,PACA_EXGEN+EX_R12(r13)
  448. ld r13,PACA_EXGEN+EX_R13(r13)
  449. HRFID
  450. b .
  451. #endif
  452. .align 7
  453. /* moved from 0xe00 */
  454. STD_EXCEPTION_HV_OOL(0xe02, h_data_storage)
  455. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0xe02)
  456. STD_EXCEPTION_HV_OOL(0xe22, h_instr_storage)
  457. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe22)
  458. STD_EXCEPTION_HV_OOL(0xe42, emulation_assist)
  459. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe42)
  460. STD_EXCEPTION_HV_OOL(0xe62, hmi_exception) /* need to flush cache ? */
  461. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe62)
  462. MASKABLE_EXCEPTION_HV_OOL(0xe82, h_doorbell)
  463. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe82)
  464. /* moved from 0xf00 */
  465. STD_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
  466. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf00)
  467. STD_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
  468. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf20)
  469. STD_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
  470. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf40)
  471. STD_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
  472. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf60)
  473. /*
  474. * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
  475. * - If it was a decrementer interrupt, we bump the dec to max and and return.
  476. * - If it was a doorbell we return immediately since doorbells are edge
  477. * triggered and won't automatically refire.
  478. * - else we hard disable and return.
  479. * This is called with r10 containing the value to OR to the paca field.
  480. */
  481. #define MASKED_INTERRUPT(_H) \
  482. masked_##_H##interrupt: \
  483. std r11,PACA_EXGEN+EX_R11(r13); \
  484. lbz r11,PACAIRQHAPPENED(r13); \
  485. or r11,r11,r10; \
  486. stb r11,PACAIRQHAPPENED(r13); \
  487. cmpwi r10,PACA_IRQ_DEC; \
  488. bne 1f; \
  489. lis r10,0x7fff; \
  490. ori r10,r10,0xffff; \
  491. mtspr SPRN_DEC,r10; \
  492. b 2f; \
  493. 1: cmpwi r10,PACA_IRQ_DBELL; \
  494. beq 2f; \
  495. mfspr r10,SPRN_##_H##SRR1; \
  496. rldicl r10,r10,48,1; /* clear MSR_EE */ \
  497. rotldi r10,r10,16; \
  498. mtspr SPRN_##_H##SRR1,r10; \
  499. 2: mtcrf 0x80,r9; \
  500. ld r9,PACA_EXGEN+EX_R9(r13); \
  501. ld r10,PACA_EXGEN+EX_R10(r13); \
  502. ld r11,PACA_EXGEN+EX_R11(r13); \
  503. GET_SCRATCH0(r13); \
  504. ##_H##rfid; \
  505. b .
  506. MASKED_INTERRUPT()
  507. MASKED_INTERRUPT(H)
  508. /*
  509. * Called from arch_local_irq_enable when an interrupt needs
  510. * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
  511. * which kind of interrupt. MSR:EE is already off. We generate a
  512. * stackframe like if a real interrupt had happened.
  513. *
  514. * Note: While MSR:EE is off, we need to make sure that _MSR
  515. * in the generated frame has EE set to 1 or the exception
  516. * handler will not properly re-enable them.
  517. */
  518. _GLOBAL(__replay_interrupt)
  519. /* We are going to jump to the exception common code which
  520. * will retrieve various register values from the PACA which
  521. * we don't give a damn about, so we don't bother storing them.
  522. */
  523. mfmsr r12
  524. mflr r11
  525. mfcr r9
  526. ori r12,r12,MSR_EE
  527. cmpwi r3,0x900
  528. beq decrementer_common
  529. cmpwi r3,0x500
  530. beq hardware_interrupt_common
  531. BEGIN_FTR_SECTION
  532. cmpwi r3,0xe80
  533. beq h_doorbell_common
  534. FTR_SECTION_ELSE
  535. cmpwi r3,0xa00
  536. beq doorbell_super_common
  537. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  538. blr
  539. #ifdef CONFIG_PPC_PSERIES
  540. /*
  541. * Vectors for the FWNMI option. Share common code.
  542. */
  543. .globl system_reset_fwnmi
  544. .align 7
  545. system_reset_fwnmi:
  546. HMT_MEDIUM_PPR_DISCARD
  547. SET_SCRATCH0(r13) /* save r13 */
  548. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
  549. NOTEST, 0x100)
  550. #endif /* CONFIG_PPC_PSERIES */
  551. #ifdef __DISABLED__
  552. /*
  553. * This is used for when the SLB miss handler has to go virtual,
  554. * which doesn't happen for now anymore but will once we re-implement
  555. * dynamic VSIDs for shared page tables
  556. */
  557. slb_miss_user_pseries:
  558. std r10,PACA_EXGEN+EX_R10(r13)
  559. std r11,PACA_EXGEN+EX_R11(r13)
  560. std r12,PACA_EXGEN+EX_R12(r13)
  561. GET_SCRATCH0(r10)
  562. ld r11,PACA_EXSLB+EX_R9(r13)
  563. ld r12,PACA_EXSLB+EX_R3(r13)
  564. std r10,PACA_EXGEN+EX_R13(r13)
  565. std r11,PACA_EXGEN+EX_R9(r13)
  566. std r12,PACA_EXGEN+EX_R3(r13)
  567. clrrdi r12,r13,32
  568. mfmsr r10
  569. mfspr r11,SRR0 /* save SRR0 */
  570. ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
  571. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  572. mtspr SRR0,r12
  573. mfspr r12,SRR1 /* and SRR1 */
  574. mtspr SRR1,r10
  575. rfid
  576. b . /* prevent spec. execution */
  577. #endif /* __DISABLED__ */
  578. /*
  579. * Code from here down to __end_handlers is invoked from the
  580. * exception prologs above. Because the prologs assemble the
  581. * addresses of these handlers using the LOAD_HANDLER macro,
  582. * which uses an ori instruction, these handlers must be in
  583. * the first 64k of the kernel image.
  584. */
  585. /*** Common interrupt handlers ***/
  586. STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
  587. /*
  588. * Machine check is different because we use a different
  589. * save area: PACA_EXMC instead of PACA_EXGEN.
  590. */
  591. .align 7
  592. .globl machine_check_common
  593. machine_check_common:
  594. mfspr r10,SPRN_DAR
  595. std r10,PACA_EXGEN+EX_DAR(r13)
  596. mfspr r10,SPRN_DSISR
  597. stw r10,PACA_EXGEN+EX_DSISR(r13)
  598. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  599. FINISH_NAP
  600. DISABLE_INTS
  601. ld r3,PACA_EXGEN+EX_DAR(r13)
  602. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  603. std r3,_DAR(r1)
  604. std r4,_DSISR(r1)
  605. bl .save_nvgprs
  606. addi r3,r1,STACK_FRAME_OVERHEAD
  607. bl .machine_check_exception
  608. b .ret_from_except
  609. STD_EXCEPTION_COMMON_ASYNC(0x500, hardware_interrupt, do_IRQ)
  610. STD_EXCEPTION_COMMON_ASYNC(0x900, decrementer, .timer_interrupt)
  611. STD_EXCEPTION_COMMON(0x980, hdecrementer, .hdec_interrupt)
  612. #ifdef CONFIG_PPC_DOORBELL
  613. STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, .doorbell_exception)
  614. #else
  615. STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, .unknown_exception)
  616. #endif
  617. STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
  618. STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
  619. STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
  620. STD_EXCEPTION_COMMON(0xe40, emulation_assist, .program_check_exception)
  621. STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception)
  622. #ifdef CONFIG_PPC_DOORBELL
  623. STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, .doorbell_exception)
  624. #else
  625. STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, .unknown_exception)
  626. #endif
  627. STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, .performance_monitor_exception)
  628. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
  629. STD_EXCEPTION_COMMON(0x1502, denorm, .unknown_exception)
  630. #ifdef CONFIG_ALTIVEC
  631. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
  632. #else
  633. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
  634. #endif
  635. #ifdef CONFIG_CBE_RAS
  636. STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
  637. STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
  638. STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
  639. #endif /* CONFIG_CBE_RAS */
  640. /*
  641. * Relocation-on interrupts: A subset of the interrupts can be delivered
  642. * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
  643. * it. Addresses are the same as the original interrupt addresses, but
  644. * offset by 0xc000000000004000.
  645. * It's impossible to receive interrupts below 0x300 via this mechanism.
  646. * KVM: None of these traps are from the guest ; anything that escalated
  647. * to HV=1 from HV=0 is delivered via real mode handlers.
  648. */
  649. /*
  650. * This uses the standard macro, since the original 0x300 vector
  651. * only has extra guff for STAB-based processors -- which never
  652. * come here.
  653. */
  654. STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
  655. . = 0x4380
  656. .globl data_access_slb_relon_pSeries
  657. data_access_slb_relon_pSeries:
  658. SET_SCRATCH0(r13)
  659. EXCEPTION_PROLOG_0(PACA_EXSLB)
  660. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
  661. std r3,PACA_EXSLB+EX_R3(r13)
  662. mfspr r3,SPRN_DAR
  663. mfspr r12,SPRN_SRR1
  664. #ifndef CONFIG_RELOCATABLE
  665. b .slb_miss_realmode
  666. #else
  667. /*
  668. * We can't just use a direct branch to .slb_miss_realmode
  669. * because the distance from here to there depends on where
  670. * the kernel ends up being put.
  671. */
  672. mfctr r11
  673. ld r10,PACAKBASE(r13)
  674. LOAD_HANDLER(r10, .slb_miss_realmode)
  675. mtctr r10
  676. bctr
  677. #endif
  678. STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
  679. . = 0x4480
  680. .globl instruction_access_slb_relon_pSeries
  681. instruction_access_slb_relon_pSeries:
  682. SET_SCRATCH0(r13)
  683. EXCEPTION_PROLOG_0(PACA_EXSLB)
  684. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
  685. std r3,PACA_EXSLB+EX_R3(r13)
  686. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  687. mfspr r12,SPRN_SRR1
  688. #ifndef CONFIG_RELOCATABLE
  689. b .slb_miss_realmode
  690. #else
  691. mfctr r11
  692. ld r10,PACAKBASE(r13)
  693. LOAD_HANDLER(r10, .slb_miss_realmode)
  694. mtctr r10
  695. bctr
  696. #endif
  697. . = 0x4500
  698. .globl hardware_interrupt_relon_pSeries;
  699. .globl hardware_interrupt_relon_hv;
  700. hardware_interrupt_relon_pSeries:
  701. hardware_interrupt_relon_hv:
  702. BEGIN_FTR_SECTION
  703. _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
  704. FTR_SECTION_ELSE
  705. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
  706. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  707. STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
  708. STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
  709. STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
  710. MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
  711. STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
  712. MASKABLE_RELON_EXCEPTION_PSERIES(0x4a00, 0xa00, doorbell_super)
  713. STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
  714. . = 0x4c00
  715. .globl system_call_relon_pSeries
  716. system_call_relon_pSeries:
  717. HMT_MEDIUM
  718. SYSCALL_PSERIES_1
  719. SYSCALL_PSERIES_2_DIRECT
  720. SYSCALL_PSERIES_3
  721. STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
  722. . = 0x4e00
  723. b . /* Can't happen, see v2.07 Book III-S section 6.5 */
  724. . = 0x4e20
  725. b . /* Can't happen, see v2.07 Book III-S section 6.5 */
  726. . = 0x4e40
  727. SET_SCRATCH0(r13)
  728. EXCEPTION_PROLOG_0(PACA_EXGEN)
  729. b emulation_assist_relon_hv
  730. . = 0x4e60
  731. b . /* Can't happen, see v2.07 Book III-S section 6.5 */
  732. . = 0x4e80
  733. SET_SCRATCH0(r13)
  734. EXCEPTION_PROLOG_0(PACA_EXGEN)
  735. b h_doorbell_relon_hv
  736. performance_monitor_relon_pSeries_1:
  737. . = 0x4f00
  738. SET_SCRATCH0(r13)
  739. EXCEPTION_PROLOG_0(PACA_EXGEN)
  740. b performance_monitor_relon_pSeries
  741. altivec_unavailable_relon_pSeries_1:
  742. . = 0x4f20
  743. SET_SCRATCH0(r13)
  744. EXCEPTION_PROLOG_0(PACA_EXGEN)
  745. b altivec_unavailable_relon_pSeries
  746. vsx_unavailable_relon_pSeries_1:
  747. . = 0x4f40
  748. SET_SCRATCH0(r13)
  749. EXCEPTION_PROLOG_0(PACA_EXGEN)
  750. b vsx_unavailable_relon_pSeries
  751. facility_unavailable_relon_trampoline:
  752. . = 0x4f60
  753. SET_SCRATCH0(r13)
  754. EXCEPTION_PROLOG_0(PACA_EXGEN)
  755. b facility_unavailable_relon_pSeries
  756. STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
  757. #ifdef CONFIG_PPC_DENORMALISATION
  758. . = 0x5500
  759. b denorm_exception_hv
  760. #endif
  761. STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
  762. /* Other future vectors */
  763. .align 7
  764. .globl __end_interrupts
  765. __end_interrupts:
  766. .align 7
  767. system_call_entry_direct:
  768. #if defined(CONFIG_RELOCATABLE)
  769. /* The first level prologue may have used LR to get here, saving
  770. * orig in r10. To save hacking/ifdeffing common code, restore here.
  771. */
  772. mtlr r10
  773. #endif
  774. system_call_entry:
  775. b system_call_common
  776. ppc64_runlatch_on_trampoline:
  777. b .__ppc64_runlatch_on
  778. /*
  779. * Here we have detected that the kernel stack pointer is bad.
  780. * R9 contains the saved CR, r13 points to the paca,
  781. * r10 contains the (bad) kernel stack pointer,
  782. * r11 and r12 contain the saved SRR0 and SRR1.
  783. * We switch to using an emergency stack, save the registers there,
  784. * and call kernel_bad_stack(), which panics.
  785. */
  786. bad_stack:
  787. ld r1,PACAEMERGSP(r13)
  788. subi r1,r1,64+INT_FRAME_SIZE
  789. std r9,_CCR(r1)
  790. std r10,GPR1(r1)
  791. std r11,_NIP(r1)
  792. std r12,_MSR(r1)
  793. mfspr r11,SPRN_DAR
  794. mfspr r12,SPRN_DSISR
  795. std r11,_DAR(r1)
  796. std r12,_DSISR(r1)
  797. mflr r10
  798. mfctr r11
  799. mfxer r12
  800. std r10,_LINK(r1)
  801. std r11,_CTR(r1)
  802. std r12,_XER(r1)
  803. SAVE_GPR(0,r1)
  804. SAVE_GPR(2,r1)
  805. ld r10,EX_R3(r3)
  806. std r10,GPR3(r1)
  807. SAVE_GPR(4,r1)
  808. SAVE_4GPRS(5,r1)
  809. ld r9,EX_R9(r3)
  810. ld r10,EX_R10(r3)
  811. SAVE_2GPRS(9,r1)
  812. ld r9,EX_R11(r3)
  813. ld r10,EX_R12(r3)
  814. ld r11,EX_R13(r3)
  815. std r9,GPR11(r1)
  816. std r10,GPR12(r1)
  817. std r11,GPR13(r1)
  818. BEGIN_FTR_SECTION
  819. ld r10,EX_CFAR(r3)
  820. std r10,ORIG_GPR3(r1)
  821. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  822. SAVE_8GPRS(14,r1)
  823. SAVE_10GPRS(22,r1)
  824. lhz r12,PACA_TRAP_SAVE(r13)
  825. std r12,_TRAP(r1)
  826. addi r11,r1,INT_FRAME_SIZE
  827. std r11,0(r1)
  828. li r12,0
  829. std r12,0(r11)
  830. ld r2,PACATOC(r13)
  831. ld r11,exception_marker@toc(r2)
  832. std r12,RESULT(r1)
  833. std r11,STACK_FRAME_OVERHEAD-16(r1)
  834. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  835. bl .kernel_bad_stack
  836. b 1b
  837. /*
  838. * Here r13 points to the paca, r9 contains the saved CR,
  839. * SRR0 and SRR1 are saved in r11 and r12,
  840. * r9 - r13 are saved in paca->exgen.
  841. */
  842. .align 7
  843. .globl data_access_common
  844. data_access_common:
  845. mfspr r10,SPRN_DAR
  846. std r10,PACA_EXGEN+EX_DAR(r13)
  847. mfspr r10,SPRN_DSISR
  848. stw r10,PACA_EXGEN+EX_DSISR(r13)
  849. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  850. DISABLE_INTS
  851. ld r12,_MSR(r1)
  852. ld r3,PACA_EXGEN+EX_DAR(r13)
  853. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  854. li r5,0x300
  855. b .do_hash_page /* Try to handle as hpte fault */
  856. .align 7
  857. .globl h_data_storage_common
  858. h_data_storage_common:
  859. mfspr r10,SPRN_HDAR
  860. std r10,PACA_EXGEN+EX_DAR(r13)
  861. mfspr r10,SPRN_HDSISR
  862. stw r10,PACA_EXGEN+EX_DSISR(r13)
  863. EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
  864. bl .save_nvgprs
  865. DISABLE_INTS
  866. addi r3,r1,STACK_FRAME_OVERHEAD
  867. bl .unknown_exception
  868. b .ret_from_except
  869. .align 7
  870. .globl instruction_access_common
  871. instruction_access_common:
  872. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  873. DISABLE_INTS
  874. ld r12,_MSR(r1)
  875. ld r3,_NIP(r1)
  876. andis. r4,r12,0x5820
  877. li r5,0x400
  878. b .do_hash_page /* Try to handle as hpte fault */
  879. STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception)
  880. /*
  881. * Here is the common SLB miss user that is used when going to virtual
  882. * mode for SLB misses, that is currently not used
  883. */
  884. #ifdef __DISABLED__
  885. .align 7
  886. .globl slb_miss_user_common
  887. slb_miss_user_common:
  888. mflr r10
  889. std r3,PACA_EXGEN+EX_DAR(r13)
  890. stw r9,PACA_EXGEN+EX_CCR(r13)
  891. std r10,PACA_EXGEN+EX_LR(r13)
  892. std r11,PACA_EXGEN+EX_SRR0(r13)
  893. bl .slb_allocate_user
  894. ld r10,PACA_EXGEN+EX_LR(r13)
  895. ld r3,PACA_EXGEN+EX_R3(r13)
  896. lwz r9,PACA_EXGEN+EX_CCR(r13)
  897. ld r11,PACA_EXGEN+EX_SRR0(r13)
  898. mtlr r10
  899. beq- slb_miss_fault
  900. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  901. beq- unrecov_user_slb
  902. mfmsr r10
  903. .machine push
  904. .machine "power4"
  905. mtcrf 0x80,r9
  906. .machine pop
  907. clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
  908. mtmsrd r10,1
  909. mtspr SRR0,r11
  910. mtspr SRR1,r12
  911. ld r9,PACA_EXGEN+EX_R9(r13)
  912. ld r10,PACA_EXGEN+EX_R10(r13)
  913. ld r11,PACA_EXGEN+EX_R11(r13)
  914. ld r12,PACA_EXGEN+EX_R12(r13)
  915. ld r13,PACA_EXGEN+EX_R13(r13)
  916. rfid
  917. b .
  918. slb_miss_fault:
  919. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
  920. ld r4,PACA_EXGEN+EX_DAR(r13)
  921. li r5,0
  922. std r4,_DAR(r1)
  923. std r5,_DSISR(r1)
  924. b handle_page_fault
  925. unrecov_user_slb:
  926. EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
  927. DISABLE_INTS
  928. bl .save_nvgprs
  929. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  930. bl .unrecoverable_exception
  931. b 1b
  932. #endif /* __DISABLED__ */
  933. .align 7
  934. .globl alignment_common
  935. alignment_common:
  936. mfspr r10,SPRN_DAR
  937. std r10,PACA_EXGEN+EX_DAR(r13)
  938. mfspr r10,SPRN_DSISR
  939. stw r10,PACA_EXGEN+EX_DSISR(r13)
  940. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  941. ld r3,PACA_EXGEN+EX_DAR(r13)
  942. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  943. std r3,_DAR(r1)
  944. std r4,_DSISR(r1)
  945. bl .save_nvgprs
  946. DISABLE_INTS
  947. addi r3,r1,STACK_FRAME_OVERHEAD
  948. bl .alignment_exception
  949. b .ret_from_except
  950. .align 7
  951. .globl program_check_common
  952. program_check_common:
  953. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  954. bl .save_nvgprs
  955. DISABLE_INTS
  956. addi r3,r1,STACK_FRAME_OVERHEAD
  957. bl .program_check_exception
  958. b .ret_from_except
  959. .align 7
  960. .globl fp_unavailable_common
  961. fp_unavailable_common:
  962. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  963. bne 1f /* if from user, just load it up */
  964. bl .save_nvgprs
  965. DISABLE_INTS
  966. addi r3,r1,STACK_FRAME_OVERHEAD
  967. bl .kernel_fp_unavailable_exception
  968. BUG_OPCODE
  969. 1:
  970. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  971. BEGIN_FTR_SECTION
  972. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  973. * transaction), go do TM stuff
  974. */
  975. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  976. bne- 2f
  977. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  978. #endif
  979. bl .load_up_fpu
  980. b fast_exception_return
  981. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  982. 2: /* User process was in a transaction */
  983. bl .save_nvgprs
  984. DISABLE_INTS
  985. addi r3,r1,STACK_FRAME_OVERHEAD
  986. bl .fp_unavailable_tm
  987. b .ret_from_except
  988. #endif
  989. .align 7
  990. .globl altivec_unavailable_common
  991. altivec_unavailable_common:
  992. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  993. #ifdef CONFIG_ALTIVEC
  994. BEGIN_FTR_SECTION
  995. beq 1f
  996. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  997. BEGIN_FTR_SECTION_NESTED(69)
  998. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  999. * transaction), go do TM stuff
  1000. */
  1001. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1002. bne- 2f
  1003. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1004. #endif
  1005. bl .load_up_altivec
  1006. b fast_exception_return
  1007. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1008. 2: /* User process was in a transaction */
  1009. bl .save_nvgprs
  1010. DISABLE_INTS
  1011. addi r3,r1,STACK_FRAME_OVERHEAD
  1012. bl .altivec_unavailable_tm
  1013. b .ret_from_except
  1014. #endif
  1015. 1:
  1016. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1017. #endif
  1018. bl .save_nvgprs
  1019. DISABLE_INTS
  1020. addi r3,r1,STACK_FRAME_OVERHEAD
  1021. bl .altivec_unavailable_exception
  1022. b .ret_from_except
  1023. .align 7
  1024. .globl vsx_unavailable_common
  1025. vsx_unavailable_common:
  1026. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  1027. #ifdef CONFIG_VSX
  1028. BEGIN_FTR_SECTION
  1029. beq 1f
  1030. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1031. BEGIN_FTR_SECTION_NESTED(69)
  1032. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1033. * transaction), go do TM stuff
  1034. */
  1035. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1036. bne- 2f
  1037. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1038. #endif
  1039. b .load_up_vsx
  1040. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1041. 2: /* User process was in a transaction */
  1042. bl .save_nvgprs
  1043. DISABLE_INTS
  1044. addi r3,r1,STACK_FRAME_OVERHEAD
  1045. bl .vsx_unavailable_tm
  1046. b .ret_from_except
  1047. #endif
  1048. 1:
  1049. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1050. #endif
  1051. bl .save_nvgprs
  1052. DISABLE_INTS
  1053. addi r3,r1,STACK_FRAME_OVERHEAD
  1054. bl .vsx_unavailable_exception
  1055. b .ret_from_except
  1056. STD_EXCEPTION_COMMON(0xf60, facility_unavailable, .facility_unavailable_exception)
  1057. .align 7
  1058. .globl __end_handlers
  1059. __end_handlers:
  1060. /* Equivalents to the above handlers for relocation-on interrupt vectors */
  1061. STD_RELON_EXCEPTION_HV_OOL(0xe40, emulation_assist)
  1062. MASKABLE_RELON_EXCEPTION_HV_OOL(0xe80, h_doorbell)
  1063. STD_RELON_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
  1064. STD_RELON_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
  1065. STD_RELON_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
  1066. STD_RELON_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
  1067. #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
  1068. /*
  1069. * Data area reserved for FWNMI option.
  1070. * This address (0x7000) is fixed by the RPA.
  1071. */
  1072. .= 0x7000
  1073. .globl fwnmi_data_area
  1074. fwnmi_data_area:
  1075. /* pseries and powernv need to keep the whole page from
  1076. * 0x7000 to 0x8000 free for use by the firmware
  1077. */
  1078. . = 0x8000
  1079. #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
  1080. /* Space for CPU0's segment table */
  1081. .balign 4096
  1082. .globl initial_stab
  1083. initial_stab:
  1084. .space 4096
  1085. #ifdef CONFIG_PPC_POWERNV
  1086. _GLOBAL(opal_mc_secondary_handler)
  1087. HMT_MEDIUM_PPR_DISCARD
  1088. SET_SCRATCH0(r13)
  1089. GET_PACA(r13)
  1090. clrldi r3,r3,2
  1091. tovirt(r3,r3)
  1092. std r3,PACA_OPAL_MC_EVT(r13)
  1093. ld r13,OPAL_MC_SRR0(r3)
  1094. mtspr SPRN_SRR0,r13
  1095. ld r13,OPAL_MC_SRR1(r3)
  1096. mtspr SPRN_SRR1,r13
  1097. ld r3,OPAL_MC_GPR3(r3)
  1098. GET_SCRATCH0(r13)
  1099. b machine_check_pSeries
  1100. #endif /* CONFIG_PPC_POWERNV */
  1101. /*
  1102. * r13 points to the PACA, r9 contains the saved CR,
  1103. * r12 contain the saved SRR1, SRR0 is still ready for return
  1104. * r3 has the faulting address
  1105. * r9 - r13 are saved in paca->exslb.
  1106. * r3 is saved in paca->slb_r3
  1107. * We assume we aren't going to take any exceptions during this procedure.
  1108. */
  1109. _GLOBAL(slb_miss_realmode)
  1110. mflr r10
  1111. #ifdef CONFIG_RELOCATABLE
  1112. mtctr r11
  1113. #endif
  1114. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1115. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  1116. bl .slb_allocate_realmode
  1117. /* All done -- return from exception. */
  1118. ld r10,PACA_EXSLB+EX_LR(r13)
  1119. ld r3,PACA_EXSLB+EX_R3(r13)
  1120. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1121. mtlr r10
  1122. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  1123. beq- 2f
  1124. .machine push
  1125. .machine "power4"
  1126. mtcrf 0x80,r9
  1127. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  1128. .machine pop
  1129. RESTORE_PPR_PACA(PACA_EXSLB, r9)
  1130. ld r9,PACA_EXSLB+EX_R9(r13)
  1131. ld r10,PACA_EXSLB+EX_R10(r13)
  1132. ld r11,PACA_EXSLB+EX_R11(r13)
  1133. ld r12,PACA_EXSLB+EX_R12(r13)
  1134. ld r13,PACA_EXSLB+EX_R13(r13)
  1135. rfid
  1136. b . /* prevent speculative execution */
  1137. 2: mfspr r11,SPRN_SRR0
  1138. ld r10,PACAKBASE(r13)
  1139. LOAD_HANDLER(r10,unrecov_slb)
  1140. mtspr SPRN_SRR0,r10
  1141. ld r10,PACAKMSR(r13)
  1142. mtspr SPRN_SRR1,r10
  1143. rfid
  1144. b .
  1145. unrecov_slb:
  1146. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  1147. DISABLE_INTS
  1148. bl .save_nvgprs
  1149. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1150. bl .unrecoverable_exception
  1151. b 1b
  1152. #ifdef CONFIG_PPC_970_NAP
  1153. power4_fixup_nap:
  1154. andc r9,r9,r10
  1155. std r9,TI_LOCAL_FLAGS(r11)
  1156. ld r10,_LINK(r1) /* make idle task do the */
  1157. std r10,_NIP(r1) /* equivalent of a blr */
  1158. blr
  1159. #endif
  1160. /*
  1161. * Hash table stuff
  1162. */
  1163. .align 7
  1164. _STATIC(do_hash_page)
  1165. std r3,_DAR(r1)
  1166. std r4,_DSISR(r1)
  1167. andis. r0,r4,0xa410 /* weird error? */
  1168. bne- handle_page_fault /* if not, try to insert a HPTE */
  1169. andis. r0,r4,DSISR_DABRMATCH@h
  1170. bne- handle_dabr_fault
  1171. BEGIN_FTR_SECTION
  1172. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  1173. bne- do_ste_alloc /* If so handle it */
  1174. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
  1175. CURRENT_THREAD_INFO(r11, r1)
  1176. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  1177. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  1178. bne 77f /* then don't call hash_page now */
  1179. /*
  1180. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  1181. * accessing a userspace segment (even from the kernel). We assume
  1182. * kernel addresses always have the high bit set.
  1183. */
  1184. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  1185. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  1186. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  1187. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  1188. ori r4,r4,1 /* add _PAGE_PRESENT */
  1189. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  1190. /*
  1191. * r3 contains the faulting address
  1192. * r4 contains the required access permissions
  1193. * r5 contains the trap number
  1194. *
  1195. * at return r3 = 0 for success, 1 for page fault, negative for error
  1196. */
  1197. bl .hash_page /* build HPTE if possible */
  1198. cmpdi r3,0 /* see if hash_page succeeded */
  1199. /* Success */
  1200. beq fast_exc_return_irq /* Return from exception on success */
  1201. /* Error */
  1202. blt- 13f
  1203. /* Here we have a page fault that hash_page can't handle. */
  1204. handle_page_fault:
  1205. 11: ld r4,_DAR(r1)
  1206. ld r5,_DSISR(r1)
  1207. addi r3,r1,STACK_FRAME_OVERHEAD
  1208. bl .do_page_fault
  1209. cmpdi r3,0
  1210. beq+ 12f
  1211. bl .save_nvgprs
  1212. mr r5,r3
  1213. addi r3,r1,STACK_FRAME_OVERHEAD
  1214. lwz r4,_DAR(r1)
  1215. bl .bad_page_fault
  1216. b .ret_from_except
  1217. /* We have a data breakpoint exception - handle it */
  1218. handle_dabr_fault:
  1219. bl .save_nvgprs
  1220. ld r4,_DAR(r1)
  1221. ld r5,_DSISR(r1)
  1222. addi r3,r1,STACK_FRAME_OVERHEAD
  1223. bl .do_break
  1224. 12: b .ret_from_except_lite
  1225. /* We have a page fault that hash_page could handle but HV refused
  1226. * the PTE insertion
  1227. */
  1228. 13: bl .save_nvgprs
  1229. mr r5,r3
  1230. addi r3,r1,STACK_FRAME_OVERHEAD
  1231. ld r4,_DAR(r1)
  1232. bl .low_hash_fault
  1233. b .ret_from_except
  1234. /*
  1235. * We come here as a result of a DSI at a point where we don't want
  1236. * to call hash_page, such as when we are accessing memory (possibly
  1237. * user memory) inside a PMU interrupt that occurred while interrupts
  1238. * were soft-disabled. We want to invoke the exception handler for
  1239. * the access, or panic if there isn't a handler.
  1240. */
  1241. 77: bl .save_nvgprs
  1242. mr r4,r3
  1243. addi r3,r1,STACK_FRAME_OVERHEAD
  1244. li r5,SIGSEGV
  1245. bl .bad_page_fault
  1246. b .ret_from_except
  1247. /* here we have a segment miss */
  1248. do_ste_alloc:
  1249. bl .ste_allocate /* try to insert stab entry */
  1250. cmpdi r3,0
  1251. bne- handle_page_fault
  1252. b fast_exception_return
  1253. /*
  1254. * r13 points to the PACA, r9 contains the saved CR,
  1255. * r11 and r12 contain the saved SRR0 and SRR1.
  1256. * r9 - r13 are saved in paca->exslb.
  1257. * We assume we aren't going to take any exceptions during this procedure.
  1258. * We assume (DAR >> 60) == 0xc.
  1259. */
  1260. .align 7
  1261. _GLOBAL(do_stab_bolted)
  1262. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1263. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  1264. mfspr r11,SPRN_DAR /* ea */
  1265. /*
  1266. * check for bad kernel/user address
  1267. * (ea & ~REGION_MASK) >= PGTABLE_RANGE
  1268. */
  1269. rldicr. r9,r11,4,(63 - 46 - 4)
  1270. li r9,0 /* VSID = 0 for bad address */
  1271. bne- 0f
  1272. /*
  1273. * Calculate VSID:
  1274. * This is the kernel vsid, we take the top for context from
  1275. * the range. context = (MAX_USER_CONTEXT) + ((ea >> 60) - 0xc) + 1
  1276. * Here we know that (ea >> 60) == 0xc
  1277. */
  1278. lis r9,(MAX_USER_CONTEXT + 1)@ha
  1279. addi r9,r9,(MAX_USER_CONTEXT + 1)@l
  1280. srdi r10,r11,SID_SHIFT
  1281. rldimi r10,r9,ESID_BITS,0 /* proto vsid */
  1282. ASM_VSID_SCRAMBLE(r10, r9, 256M)
  1283. rldic r9,r10,12,16 /* r9 = vsid << 12 */
  1284. 0:
  1285. /* Hash to the primary group */
  1286. ld r10,PACASTABVIRT(r13)
  1287. srdi r11,r11,SID_SHIFT
  1288. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  1289. /* Search the primary group for a free entry */
  1290. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  1291. andi. r11,r11,0x80
  1292. beq 2f
  1293. addi r10,r10,16
  1294. andi. r11,r10,0x70
  1295. bne 1b
  1296. /* Stick for only searching the primary group for now. */
  1297. /* At least for now, we use a very simple random castout scheme */
  1298. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  1299. mftb r11
  1300. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  1301. ori r11,r11,0x10
  1302. /* r10 currently points to an ste one past the group of interest */
  1303. /* make it point to the randomly selected entry */
  1304. subi r10,r10,128
  1305. or r10,r10,r11 /* r10 is the entry to invalidate */
  1306. isync /* mark the entry invalid */
  1307. ld r11,0(r10)
  1308. rldicl r11,r11,56,1 /* clear the valid bit */
  1309. rotldi r11,r11,8
  1310. std r11,0(r10)
  1311. sync
  1312. clrrdi r11,r11,28 /* Get the esid part of the ste */
  1313. slbie r11
  1314. 2: std r9,8(r10) /* Store the vsid part of the ste */
  1315. eieio
  1316. mfspr r11,SPRN_DAR /* Get the new esid */
  1317. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  1318. ori r11,r11,0x90 /* Turn on valid and kp */
  1319. std r11,0(r10) /* Put new entry back into the stab */
  1320. sync
  1321. /* All done -- return from exception. */
  1322. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1323. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  1324. andi. r10,r12,MSR_RI
  1325. beq- unrecov_slb
  1326. mtcrf 0x80,r9 /* restore CR */
  1327. mfmsr r10
  1328. clrrdi r10,r10,2
  1329. mtmsrd r10,1
  1330. mtspr SPRN_SRR0,r11
  1331. mtspr SPRN_SRR1,r12
  1332. ld r9,PACA_EXSLB+EX_R9(r13)
  1333. ld r10,PACA_EXSLB+EX_R10(r13)
  1334. ld r11,PACA_EXSLB+EX_R11(r13)
  1335. ld r12,PACA_EXSLB+EX_R12(r13)
  1336. ld r13,PACA_EXSLB+EX_R13(r13)
  1337. rfid
  1338. b . /* prevent speculative execution */