exceptions-64s.S 36 KB

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