exceptions-64s.S 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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. . = 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. STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
  604. STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
  605. STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
  606. STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
  607. STD_EXCEPTION_COMMON(0xe40, emulation_assist, .program_check_exception)
  608. STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception)
  609. #ifdef CONFIG_PPC_DOORBELL
  610. STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, .doorbell_exception)
  611. #else
  612. STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, .unknown_exception)
  613. #endif
  614. STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, .performance_monitor_exception)
  615. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
  616. STD_EXCEPTION_COMMON(0x1502, denorm, .unknown_exception)
  617. #ifdef CONFIG_ALTIVEC
  618. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
  619. #else
  620. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
  621. #endif
  622. #ifdef CONFIG_CBE_RAS
  623. STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
  624. STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
  625. STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
  626. #endif /* CONFIG_CBE_RAS */
  627. /*
  628. * Relocation-on interrupts: A subset of the interrupts can be delivered
  629. * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
  630. * it. Addresses are the same as the original interrupt addresses, but
  631. * offset by 0xc000000000004000.
  632. * It's impossible to receive interrupts below 0x300 via this mechanism.
  633. * KVM: None of these traps are from the guest ; anything that escalated
  634. * to HV=1 from HV=0 is delivered via real mode handlers.
  635. */
  636. /*
  637. * This uses the standard macro, since the original 0x300 vector
  638. * only has extra guff for STAB-based processors -- which never
  639. * come here.
  640. */
  641. STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
  642. . = 0x4380
  643. .globl data_access_slb_relon_pSeries
  644. data_access_slb_relon_pSeries:
  645. HMT_MEDIUM
  646. SET_SCRATCH0(r13)
  647. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
  648. std r3,PACA_EXSLB+EX_R3(r13)
  649. mfspr r3,SPRN_DAR
  650. mfspr r12,SPRN_SRR1
  651. #ifndef CONFIG_RELOCATABLE
  652. b .slb_miss_realmode
  653. #else
  654. /*
  655. * We can't just use a direct branch to .slb_miss_realmode
  656. * because the distance from here to there depends on where
  657. * the kernel ends up being put.
  658. */
  659. mfctr r11
  660. ld r10,PACAKBASE(r13)
  661. LOAD_HANDLER(r10, .slb_miss_realmode)
  662. mtctr r10
  663. bctr
  664. #endif
  665. STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
  666. . = 0x4480
  667. .globl instruction_access_slb_relon_pSeries
  668. instruction_access_slb_relon_pSeries:
  669. HMT_MEDIUM
  670. SET_SCRATCH0(r13)
  671. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
  672. std r3,PACA_EXSLB+EX_R3(r13)
  673. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  674. mfspr r12,SPRN_SRR1
  675. #ifndef CONFIG_RELOCATABLE
  676. b .slb_miss_realmode
  677. #else
  678. mfctr r11
  679. ld r10,PACAKBASE(r13)
  680. LOAD_HANDLER(r10, .slb_miss_realmode)
  681. mtctr r10
  682. bctr
  683. #endif
  684. . = 0x4500
  685. .globl hardware_interrupt_relon_pSeries;
  686. .globl hardware_interrupt_relon_hv;
  687. hardware_interrupt_relon_pSeries:
  688. hardware_interrupt_relon_hv:
  689. BEGIN_FTR_SECTION
  690. _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
  691. FTR_SECTION_ELSE
  692. _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
  693. ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_206)
  694. STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
  695. STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
  696. STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
  697. MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
  698. STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
  699. STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
  700. . = 0x4c00
  701. .globl system_call_relon_pSeries
  702. system_call_relon_pSeries:
  703. HMT_MEDIUM
  704. SYSCALL_PSERIES_1
  705. SYSCALL_PSERIES_2_DIRECT
  706. SYSCALL_PSERIES_3
  707. STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
  708. . = 0x4e00
  709. b h_data_storage_relon_hv
  710. . = 0x4e20
  711. b h_instr_storage_relon_hv
  712. . = 0x4e40
  713. b emulation_assist_relon_hv
  714. . = 0x4e50
  715. b hmi_exception_relon_hv
  716. . = 0x4e60
  717. b hmi_exception_relon_hv
  718. . = 0x4e80
  719. b h_doorbell_relon_hv
  720. performance_monitor_relon_pSeries_1:
  721. . = 0x4f00
  722. b performance_monitor_relon_pSeries
  723. altivec_unavailable_relon_pSeries_1:
  724. . = 0x4f20
  725. b altivec_unavailable_relon_pSeries
  726. vsx_unavailable_relon_pSeries_1:
  727. . = 0x4f40
  728. b vsx_unavailable_relon_pSeries
  729. #ifdef CONFIG_CBE_RAS
  730. STD_RELON_EXCEPTION_HV(0x5200, 0x1202, cbe_system_error)
  731. #endif /* CONFIG_CBE_RAS */
  732. STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
  733. #ifdef CONFIG_PPC_DENORMALISATION
  734. . = 0x5500
  735. b denorm_exception_hv
  736. #endif
  737. #ifdef CONFIG_CBE_RAS
  738. STD_RELON_EXCEPTION_HV(0x5600, 0x1602, cbe_maintenance)
  739. #else
  740. #ifdef CONFIG_HVC_SCOM
  741. STD_RELON_EXCEPTION_HV(0x5600, 0x1600, maintence_interrupt)
  742. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1600)
  743. #endif /* CONFIG_HVC_SCOM */
  744. #endif /* CONFIG_CBE_RAS */
  745. STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
  746. #ifdef CONFIG_CBE_RAS
  747. STD_RELON_EXCEPTION_HV(0x5800, 0x1802, cbe_thermal)
  748. #endif /* CONFIG_CBE_RAS */
  749. /* Other future vectors */
  750. .align 7
  751. .globl __end_interrupts
  752. __end_interrupts:
  753. .align 7
  754. system_call_entry_direct:
  755. #if defined(CONFIG_RELOCATABLE)
  756. /* The first level prologue may have used LR to get here, saving
  757. * orig in r10. To save hacking/ifdeffing common code, restore here.
  758. */
  759. mtlr r10
  760. #endif
  761. system_call_entry:
  762. b system_call_common
  763. ppc64_runlatch_on_trampoline:
  764. b .__ppc64_runlatch_on
  765. /*
  766. * Here we have detected that the kernel stack pointer is bad.
  767. * R9 contains the saved CR, r13 points to the paca,
  768. * r10 contains the (bad) kernel stack pointer,
  769. * r11 and r12 contain the saved SRR0 and SRR1.
  770. * We switch to using an emergency stack, save the registers there,
  771. * and call kernel_bad_stack(), which panics.
  772. */
  773. bad_stack:
  774. ld r1,PACAEMERGSP(r13)
  775. subi r1,r1,64+INT_FRAME_SIZE
  776. std r9,_CCR(r1)
  777. std r10,GPR1(r1)
  778. std r11,_NIP(r1)
  779. std r12,_MSR(r1)
  780. mfspr r11,SPRN_DAR
  781. mfspr r12,SPRN_DSISR
  782. std r11,_DAR(r1)
  783. std r12,_DSISR(r1)
  784. mflr r10
  785. mfctr r11
  786. mfxer r12
  787. std r10,_LINK(r1)
  788. std r11,_CTR(r1)
  789. std r12,_XER(r1)
  790. SAVE_GPR(0,r1)
  791. SAVE_GPR(2,r1)
  792. ld r10,EX_R3(r3)
  793. std r10,GPR3(r1)
  794. SAVE_GPR(4,r1)
  795. SAVE_4GPRS(5,r1)
  796. ld r9,EX_R9(r3)
  797. ld r10,EX_R10(r3)
  798. SAVE_2GPRS(9,r1)
  799. ld r9,EX_R11(r3)
  800. ld r10,EX_R12(r3)
  801. ld r11,EX_R13(r3)
  802. std r9,GPR11(r1)
  803. std r10,GPR12(r1)
  804. std r11,GPR13(r1)
  805. BEGIN_FTR_SECTION
  806. ld r10,EX_CFAR(r3)
  807. std r10,ORIG_GPR3(r1)
  808. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  809. SAVE_8GPRS(14,r1)
  810. SAVE_10GPRS(22,r1)
  811. lhz r12,PACA_TRAP_SAVE(r13)
  812. std r12,_TRAP(r1)
  813. addi r11,r1,INT_FRAME_SIZE
  814. std r11,0(r1)
  815. li r12,0
  816. std r12,0(r11)
  817. ld r2,PACATOC(r13)
  818. ld r11,exception_marker@toc(r2)
  819. std r12,RESULT(r1)
  820. std r11,STACK_FRAME_OVERHEAD-16(r1)
  821. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  822. bl .kernel_bad_stack
  823. b 1b
  824. /*
  825. * Here r13 points to the paca, r9 contains the saved CR,
  826. * SRR0 and SRR1 are saved in r11 and r12,
  827. * r9 - r13 are saved in paca->exgen.
  828. */
  829. .align 7
  830. .globl data_access_common
  831. data_access_common:
  832. mfspr r10,SPRN_DAR
  833. std r10,PACA_EXGEN+EX_DAR(r13)
  834. mfspr r10,SPRN_DSISR
  835. stw r10,PACA_EXGEN+EX_DSISR(r13)
  836. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  837. DISABLE_INTS
  838. ld r12,_MSR(r1)
  839. ld r3,PACA_EXGEN+EX_DAR(r13)
  840. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  841. li r5,0x300
  842. b .do_hash_page /* Try to handle as hpte fault */
  843. .align 7
  844. .globl h_data_storage_common
  845. h_data_storage_common:
  846. mfspr r10,SPRN_HDAR
  847. std r10,PACA_EXGEN+EX_DAR(r13)
  848. mfspr r10,SPRN_HDSISR
  849. stw r10,PACA_EXGEN+EX_DSISR(r13)
  850. EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
  851. bl .save_nvgprs
  852. DISABLE_INTS
  853. addi r3,r1,STACK_FRAME_OVERHEAD
  854. bl .unknown_exception
  855. b .ret_from_except
  856. .align 7
  857. .globl instruction_access_common
  858. instruction_access_common:
  859. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  860. DISABLE_INTS
  861. ld r12,_MSR(r1)
  862. ld r3,_NIP(r1)
  863. andis. r4,r12,0x5820
  864. li r5,0x400
  865. b .do_hash_page /* Try to handle as hpte fault */
  866. STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception)
  867. /*
  868. * Here is the common SLB miss user that is used when going to virtual
  869. * mode for SLB misses, that is currently not used
  870. */
  871. #ifdef __DISABLED__
  872. .align 7
  873. .globl slb_miss_user_common
  874. slb_miss_user_common:
  875. mflr r10
  876. std r3,PACA_EXGEN+EX_DAR(r13)
  877. stw r9,PACA_EXGEN+EX_CCR(r13)
  878. std r10,PACA_EXGEN+EX_LR(r13)
  879. std r11,PACA_EXGEN+EX_SRR0(r13)
  880. bl .slb_allocate_user
  881. ld r10,PACA_EXGEN+EX_LR(r13)
  882. ld r3,PACA_EXGEN+EX_R3(r13)
  883. lwz r9,PACA_EXGEN+EX_CCR(r13)
  884. ld r11,PACA_EXGEN+EX_SRR0(r13)
  885. mtlr r10
  886. beq- slb_miss_fault
  887. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  888. beq- unrecov_user_slb
  889. mfmsr r10
  890. .machine push
  891. .machine "power4"
  892. mtcrf 0x80,r9
  893. .machine pop
  894. clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
  895. mtmsrd r10,1
  896. mtspr SRR0,r11
  897. mtspr SRR1,r12
  898. ld r9,PACA_EXGEN+EX_R9(r13)
  899. ld r10,PACA_EXGEN+EX_R10(r13)
  900. ld r11,PACA_EXGEN+EX_R11(r13)
  901. ld r12,PACA_EXGEN+EX_R12(r13)
  902. ld r13,PACA_EXGEN+EX_R13(r13)
  903. rfid
  904. b .
  905. slb_miss_fault:
  906. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
  907. ld r4,PACA_EXGEN+EX_DAR(r13)
  908. li r5,0
  909. std r4,_DAR(r1)
  910. std r5,_DSISR(r1)
  911. b handle_page_fault
  912. unrecov_user_slb:
  913. EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
  914. DISABLE_INTS
  915. bl .save_nvgprs
  916. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  917. bl .unrecoverable_exception
  918. b 1b
  919. #endif /* __DISABLED__ */
  920. /*
  921. * r13 points to the PACA, r9 contains the saved CR,
  922. * r12 contain the saved SRR1, SRR0 is still ready for return
  923. * r3 has the faulting address
  924. * r9 - r13 are saved in paca->exslb.
  925. * r3 is saved in paca->slb_r3
  926. * We assume we aren't going to take any exceptions during this procedure.
  927. */
  928. _GLOBAL(slb_miss_realmode)
  929. mflr r10
  930. #ifdef CONFIG_RELOCATABLE
  931. mtctr r11
  932. #endif
  933. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  934. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  935. bl .slb_allocate_realmode
  936. /* All done -- return from exception. */
  937. ld r10,PACA_EXSLB+EX_LR(r13)
  938. ld r3,PACA_EXSLB+EX_R3(r13)
  939. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  940. mtlr r10
  941. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  942. beq- 2f
  943. .machine push
  944. .machine "power4"
  945. mtcrf 0x80,r9
  946. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  947. .machine pop
  948. ld r9,PACA_EXSLB+EX_R9(r13)
  949. ld r10,PACA_EXSLB+EX_R10(r13)
  950. ld r11,PACA_EXSLB+EX_R11(r13)
  951. ld r12,PACA_EXSLB+EX_R12(r13)
  952. ld r13,PACA_EXSLB+EX_R13(r13)
  953. rfid
  954. b . /* prevent speculative execution */
  955. 2: mfspr r11,SPRN_SRR0
  956. ld r10,PACAKBASE(r13)
  957. LOAD_HANDLER(r10,unrecov_slb)
  958. mtspr SPRN_SRR0,r10
  959. ld r10,PACAKMSR(r13)
  960. mtspr SPRN_SRR1,r10
  961. rfid
  962. b .
  963. unrecov_slb:
  964. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  965. DISABLE_INTS
  966. bl .save_nvgprs
  967. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  968. bl .unrecoverable_exception
  969. b 1b
  970. #ifdef CONFIG_PPC_970_NAP
  971. power4_fixup_nap:
  972. andc r9,r9,r10
  973. std r9,TI_LOCAL_FLAGS(r11)
  974. ld r10,_LINK(r1) /* make idle task do the */
  975. std r10,_NIP(r1) /* equivalent of a blr */
  976. blr
  977. #endif
  978. .align 7
  979. .globl alignment_common
  980. alignment_common:
  981. mfspr r10,SPRN_DAR
  982. std r10,PACA_EXGEN+EX_DAR(r13)
  983. mfspr r10,SPRN_DSISR
  984. stw r10,PACA_EXGEN+EX_DSISR(r13)
  985. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  986. ld r3,PACA_EXGEN+EX_DAR(r13)
  987. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  988. std r3,_DAR(r1)
  989. std r4,_DSISR(r1)
  990. bl .save_nvgprs
  991. DISABLE_INTS
  992. addi r3,r1,STACK_FRAME_OVERHEAD
  993. bl .alignment_exception
  994. b .ret_from_except
  995. .align 7
  996. .globl program_check_common
  997. program_check_common:
  998. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  999. bl .save_nvgprs
  1000. DISABLE_INTS
  1001. addi r3,r1,STACK_FRAME_OVERHEAD
  1002. bl .program_check_exception
  1003. b .ret_from_except
  1004. .align 7
  1005. .globl fp_unavailable_common
  1006. fp_unavailable_common:
  1007. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  1008. bne 1f /* if from user, just load it up */
  1009. bl .save_nvgprs
  1010. DISABLE_INTS
  1011. addi r3,r1,STACK_FRAME_OVERHEAD
  1012. bl .kernel_fp_unavailable_exception
  1013. BUG_OPCODE
  1014. 1: bl .load_up_fpu
  1015. b fast_exception_return
  1016. .align 7
  1017. .globl altivec_unavailable_common
  1018. altivec_unavailable_common:
  1019. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  1020. #ifdef CONFIG_ALTIVEC
  1021. BEGIN_FTR_SECTION
  1022. beq 1f
  1023. bl .load_up_altivec
  1024. b fast_exception_return
  1025. 1:
  1026. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1027. #endif
  1028. bl .save_nvgprs
  1029. DISABLE_INTS
  1030. addi r3,r1,STACK_FRAME_OVERHEAD
  1031. bl .altivec_unavailable_exception
  1032. b .ret_from_except
  1033. .align 7
  1034. .globl vsx_unavailable_common
  1035. vsx_unavailable_common:
  1036. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  1037. #ifdef CONFIG_VSX
  1038. BEGIN_FTR_SECTION
  1039. beq 1f
  1040. b .load_up_vsx
  1041. 1:
  1042. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1043. #endif
  1044. bl .save_nvgprs
  1045. DISABLE_INTS
  1046. addi r3,r1,STACK_FRAME_OVERHEAD
  1047. bl .vsx_unavailable_exception
  1048. b .ret_from_except
  1049. .align 7
  1050. .globl __end_handlers
  1051. __end_handlers:
  1052. /*
  1053. * Hash table stuff
  1054. */
  1055. .align 7
  1056. _STATIC(do_hash_page)
  1057. std r3,_DAR(r1)
  1058. std r4,_DSISR(r1)
  1059. andis. r0,r4,0xa410 /* weird error? */
  1060. bne- handle_page_fault /* if not, try to insert a HPTE */
  1061. andis. r0,r4,DSISR_DABRMATCH@h
  1062. bne- handle_dabr_fault
  1063. BEGIN_FTR_SECTION
  1064. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  1065. bne- do_ste_alloc /* If so handle it */
  1066. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
  1067. CURRENT_THREAD_INFO(r11, r1)
  1068. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  1069. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  1070. bne 77f /* then don't call hash_page now */
  1071. /*
  1072. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  1073. * accessing a userspace segment (even from the kernel). We assume
  1074. * kernel addresses always have the high bit set.
  1075. */
  1076. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  1077. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  1078. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  1079. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  1080. ori r4,r4,1 /* add _PAGE_PRESENT */
  1081. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  1082. /*
  1083. * r3 contains the faulting address
  1084. * r4 contains the required access permissions
  1085. * r5 contains the trap number
  1086. *
  1087. * at return r3 = 0 for success, 1 for page fault, negative for error
  1088. */
  1089. bl .hash_page /* build HPTE if possible */
  1090. cmpdi r3,0 /* see if hash_page succeeded */
  1091. /* Success */
  1092. beq fast_exc_return_irq /* Return from exception on success */
  1093. /* Error */
  1094. blt- 13f
  1095. /* Here we have a page fault that hash_page can't handle. */
  1096. handle_page_fault:
  1097. 11: ld r4,_DAR(r1)
  1098. ld r5,_DSISR(r1)
  1099. addi r3,r1,STACK_FRAME_OVERHEAD
  1100. bl .do_page_fault
  1101. cmpdi r3,0
  1102. beq+ 12f
  1103. bl .save_nvgprs
  1104. mr r5,r3
  1105. addi r3,r1,STACK_FRAME_OVERHEAD
  1106. lwz r4,_DAR(r1)
  1107. bl .bad_page_fault
  1108. b .ret_from_except
  1109. /* We have a data breakpoint exception - handle it */
  1110. handle_dabr_fault:
  1111. bl .save_nvgprs
  1112. ld r4,_DAR(r1)
  1113. ld r5,_DSISR(r1)
  1114. addi r3,r1,STACK_FRAME_OVERHEAD
  1115. bl .do_dabr
  1116. 12: b .ret_from_except_lite
  1117. /* We have a page fault that hash_page could handle but HV refused
  1118. * the PTE insertion
  1119. */
  1120. 13: bl .save_nvgprs
  1121. mr r5,r3
  1122. addi r3,r1,STACK_FRAME_OVERHEAD
  1123. ld r4,_DAR(r1)
  1124. bl .low_hash_fault
  1125. b .ret_from_except
  1126. /*
  1127. * We come here as a result of a DSI at a point where we don't want
  1128. * to call hash_page, such as when we are accessing memory (possibly
  1129. * user memory) inside a PMU interrupt that occurred while interrupts
  1130. * were soft-disabled. We want to invoke the exception handler for
  1131. * the access, or panic if there isn't a handler.
  1132. */
  1133. 77: bl .save_nvgprs
  1134. mr r4,r3
  1135. addi r3,r1,STACK_FRAME_OVERHEAD
  1136. li r5,SIGSEGV
  1137. bl .bad_page_fault
  1138. b .ret_from_except
  1139. /* here we have a segment miss */
  1140. do_ste_alloc:
  1141. bl .ste_allocate /* try to insert stab entry */
  1142. cmpdi r3,0
  1143. bne- handle_page_fault
  1144. b fast_exception_return
  1145. /*
  1146. * r13 points to the PACA, r9 contains the saved CR,
  1147. * r11 and r12 contain the saved SRR0 and SRR1.
  1148. * r9 - r13 are saved in paca->exslb.
  1149. * We assume we aren't going to take any exceptions during this procedure.
  1150. * We assume (DAR >> 60) == 0xc.
  1151. */
  1152. .align 7
  1153. _GLOBAL(do_stab_bolted)
  1154. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  1155. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  1156. /* Hash to the primary group */
  1157. ld r10,PACASTABVIRT(r13)
  1158. mfspr r11,SPRN_DAR
  1159. srdi r11,r11,28
  1160. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  1161. /* Calculate VSID */
  1162. /* This is a kernel address, so protovsid = ESID | 1 << 37 */
  1163. li r9,0x1
  1164. rldimi r11,r9,(CONTEXT_BITS + USER_ESID_BITS),0
  1165. ASM_VSID_SCRAMBLE(r11, r9, 256M)
  1166. rldic r9,r11,12,16 /* r9 = vsid << 12 */
  1167. /* Search the primary group for a free entry */
  1168. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  1169. andi. r11,r11,0x80
  1170. beq 2f
  1171. addi r10,r10,16
  1172. andi. r11,r10,0x70
  1173. bne 1b
  1174. /* Stick for only searching the primary group for now. */
  1175. /* At least for now, we use a very simple random castout scheme */
  1176. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  1177. mftb r11
  1178. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  1179. ori r11,r11,0x10
  1180. /* r10 currently points to an ste one past the group of interest */
  1181. /* make it point to the randomly selected entry */
  1182. subi r10,r10,128
  1183. or r10,r10,r11 /* r10 is the entry to invalidate */
  1184. isync /* mark the entry invalid */
  1185. ld r11,0(r10)
  1186. rldicl r11,r11,56,1 /* clear the valid bit */
  1187. rotldi r11,r11,8
  1188. std r11,0(r10)
  1189. sync
  1190. clrrdi r11,r11,28 /* Get the esid part of the ste */
  1191. slbie r11
  1192. 2: std r9,8(r10) /* Store the vsid part of the ste */
  1193. eieio
  1194. mfspr r11,SPRN_DAR /* Get the new esid */
  1195. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  1196. ori r11,r11,0x90 /* Turn on valid and kp */
  1197. std r11,0(r10) /* Put new entry back into the stab */
  1198. sync
  1199. /* All done -- return from exception. */
  1200. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  1201. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  1202. andi. r10,r12,MSR_RI
  1203. beq- unrecov_slb
  1204. mtcrf 0x80,r9 /* restore CR */
  1205. mfmsr r10
  1206. clrrdi r10,r10,2
  1207. mtmsrd r10,1
  1208. mtspr SPRN_SRR0,r11
  1209. mtspr SPRN_SRR1,r12
  1210. ld r9,PACA_EXSLB+EX_R9(r13)
  1211. ld r10,PACA_EXSLB+EX_R10(r13)
  1212. ld r11,PACA_EXSLB+EX_R11(r13)
  1213. ld r12,PACA_EXSLB+EX_R12(r13)
  1214. ld r13,PACA_EXSLB+EX_R13(r13)
  1215. rfid
  1216. b . /* prevent speculative execution */
  1217. /* Equivalents to the above handlers for relocation-on interrupt vectors */
  1218. STD_RELON_EXCEPTION_HV(., 0xe00, h_data_storage)
  1219. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe00)
  1220. STD_RELON_EXCEPTION_HV(., 0xe20, h_instr_storage)
  1221. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe20)
  1222. STD_RELON_EXCEPTION_HV(., 0xe40, emulation_assist)
  1223. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe40)
  1224. STD_RELON_EXCEPTION_HV(., 0xe60, hmi_exception)
  1225. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe60)
  1226. MASKABLE_RELON_EXCEPTION_HV(., 0xe80, h_doorbell)
  1227. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe80)
  1228. STD_RELON_EXCEPTION_PSERIES(., 0xf00, performance_monitor)
  1229. STD_RELON_EXCEPTION_PSERIES(., 0xf20, altivec_unavailable)
  1230. STD_RELON_EXCEPTION_PSERIES(., 0xf40, vsx_unavailable)
  1231. #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
  1232. /*
  1233. * Data area reserved for FWNMI option.
  1234. * This address (0x7000) is fixed by the RPA.
  1235. */
  1236. .= 0x7000
  1237. .globl fwnmi_data_area
  1238. fwnmi_data_area:
  1239. /* pseries and powernv need to keep the whole page from
  1240. * 0x7000 to 0x8000 free for use by the firmware
  1241. */
  1242. . = 0x8000
  1243. #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
  1244. /* Space for CPU0's segment table */
  1245. .balign 4096
  1246. .globl initial_stab
  1247. initial_stab:
  1248. .space 4096
  1249. #ifdef CONFIG_PPC_POWERNV
  1250. _GLOBAL(opal_mc_secondary_handler)
  1251. HMT_MEDIUM
  1252. SET_SCRATCH0(r13)
  1253. GET_PACA(r13)
  1254. clrldi r3,r3,2
  1255. tovirt(r3,r3)
  1256. std r3,PACA_OPAL_MC_EVT(r13)
  1257. ld r13,OPAL_MC_SRR0(r3)
  1258. mtspr SPRN_SRR0,r13
  1259. ld r13,OPAL_MC_SRR1(r3)
  1260. mtspr SPRN_SRR1,r13
  1261. ld r3,OPAL_MC_GPR3(r3)
  1262. GET_SCRATCH0(r13)
  1263. b machine_check_pSeries
  1264. #endif /* CONFIG_PPC_POWERNV */