exceptions-64s.S 39 KB

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