exceptions-64s.S 40 KB

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