exceptions-64s.S 36 KB

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