exceptions-64s.S 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  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 - 0x2fff : pSeries Interrupt prologs
  21. * 0x3000 - 0x5fff : interrupt support common interrupt prologs
  22. * 0x6000 - 0x6fff : Initial (CPU0) segment table
  23. * 0x7000 - 0x7fff : FWNMI data area
  24. * 0x8000 - : Early init and support code
  25. */
  26. /*
  27. * This is the start of the interrupt handlers for pSeries
  28. * This code runs with relocation off.
  29. * Code from here to __end_interrupts gets copied down to real
  30. * address 0x100 when we are running a relocatable kernel.
  31. * Therefore any relative branches in this section must only
  32. * branch to labels in this section.
  33. */
  34. . = 0x100
  35. .globl __start_interrupts
  36. __start_interrupts:
  37. .globl system_reset_pSeries;
  38. system_reset_pSeries:
  39. HMT_MEDIUM;
  40. SET_SCRATCH0(r13)
  41. #ifdef CONFIG_PPC_P7_NAP
  42. BEGIN_FTR_SECTION
  43. /* Running native on arch 2.06 or later, check if we are
  44. * waking up from nap. We only handle no state loss and
  45. * supervisor state loss. We do -not- handle hypervisor
  46. * state loss at this time.
  47. */
  48. mfspr r13,SPRN_SRR1
  49. rlwinm. r13,r13,47-31,30,31
  50. beq 9f
  51. /* waking up from powersave (nap) state */
  52. cmpwi cr1,r13,2
  53. /* Total loss of HV state is fatal, we could try to use the
  54. * PIR to locate a PACA, then use an emergency stack etc...
  55. * but for now, let's just stay stuck here
  56. */
  57. bgt cr1,.
  58. GET_PACA(r13)
  59. #ifdef CONFIG_KVM_BOOK3S_64_HV
  60. li r0,KVM_HWTHREAD_IN_KERNEL
  61. stb r0,HSTATE_HWTHREAD_STATE(r13)
  62. /* Order setting hwthread_state vs. testing hwthread_req */
  63. sync
  64. lbz r0,HSTATE_HWTHREAD_REQ(r13)
  65. cmpwi r0,0
  66. beq 1f
  67. b kvm_start_guest
  68. 1:
  69. #endif
  70. beq cr1,2f
  71. b .power7_wakeup_noloss
  72. 2: b .power7_wakeup_loss
  73. 9:
  74. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  75. #endif /* CONFIG_PPC_P7_NAP */
  76. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
  77. NOTEST, 0x100)
  78. . = 0x200
  79. machine_check_pSeries_1:
  80. /* This is moved out of line as it can be patched by FW, but
  81. * some code path might still want to branch into the original
  82. * vector
  83. */
  84. b machine_check_pSeries
  85. . = 0x300
  86. .globl data_access_pSeries
  87. data_access_pSeries:
  88. HMT_MEDIUM
  89. SET_SCRATCH0(r13)
  90. BEGIN_FTR_SECTION
  91. b data_access_check_stab
  92. data_access_not_stab:
  93. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
  94. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD,
  95. KVMTEST, 0x300)
  96. . = 0x380
  97. .globl data_access_slb_pSeries
  98. data_access_slb_pSeries:
  99. HMT_MEDIUM
  100. SET_SCRATCH0(r13)
  101. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x380)
  102. std r3,PACA_EXSLB+EX_R3(r13)
  103. mfspr r3,SPRN_DAR
  104. #ifdef __DISABLED__
  105. /* Keep that around for when we re-implement dynamic VSIDs */
  106. cmpdi r3,0
  107. bge slb_miss_user_pseries
  108. #endif /* __DISABLED__ */
  109. mfspr r12,SPRN_SRR1
  110. #ifndef CONFIG_RELOCATABLE
  111. b .slb_miss_realmode
  112. #else
  113. /*
  114. * We can't just use a direct branch to .slb_miss_realmode
  115. * because the distance from here to there depends on where
  116. * the kernel ends up being put.
  117. */
  118. mfctr r11
  119. ld r10,PACAKBASE(r13)
  120. LOAD_HANDLER(r10, .slb_miss_realmode)
  121. mtctr r10
  122. bctr
  123. #endif
  124. STD_EXCEPTION_PSERIES(0x400, 0x400, instruction_access)
  125. . = 0x480
  126. .globl instruction_access_slb_pSeries
  127. instruction_access_slb_pSeries:
  128. HMT_MEDIUM
  129. SET_SCRATCH0(r13)
  130. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
  131. std r3,PACA_EXSLB+EX_R3(r13)
  132. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  133. #ifdef __DISABLED__
  134. /* Keep that around for when we re-implement dynamic VSIDs */
  135. cmpdi r3,0
  136. bge slb_miss_user_pseries
  137. #endif /* __DISABLED__ */
  138. mfspr r12,SPRN_SRR1
  139. #ifndef CONFIG_RELOCATABLE
  140. b .slb_miss_realmode
  141. #else
  142. mfctr r11
  143. ld r10,PACAKBASE(r13)
  144. LOAD_HANDLER(r10, .slb_miss_realmode)
  145. mtctr r10
  146. bctr
  147. #endif
  148. /* We open code these as we can't have a ". = x" (even with
  149. * x = "." within a feature section
  150. */
  151. . = 0x500;
  152. .globl hardware_interrupt_pSeries;
  153. .globl hardware_interrupt_hv;
  154. hardware_interrupt_pSeries:
  155. hardware_interrupt_hv:
  156. BEGIN_FTR_SECTION
  157. _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt,
  158. EXC_HV, SOFTEN_TEST_HV)
  159. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
  160. FTR_SECTION_ELSE
  161. _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt,
  162. EXC_STD, SOFTEN_TEST_HV_201)
  163. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
  164. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  165. STD_EXCEPTION_PSERIES(0x600, 0x600, alignment)
  166. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x600)
  167. STD_EXCEPTION_PSERIES(0x700, 0x700, program_check)
  168. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x700)
  169. STD_EXCEPTION_PSERIES(0x800, 0x800, fp_unavailable)
  170. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x800)
  171. MASKABLE_EXCEPTION_PSERIES(0x900, 0x900, decrementer)
  172. MASKABLE_EXCEPTION_HV(0x980, 0x982, decrementer)
  173. STD_EXCEPTION_PSERIES(0xa00, 0xa00, trap_0a)
  174. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xa00)
  175. STD_EXCEPTION_PSERIES(0xb00, 0xb00, trap_0b)
  176. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xb00)
  177. . = 0xc00
  178. .globl system_call_pSeries
  179. system_call_pSeries:
  180. HMT_MEDIUM
  181. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  182. SET_SCRATCH0(r13)
  183. GET_PACA(r13)
  184. std r9,PACA_EXGEN+EX_R9(r13)
  185. std r10,PACA_EXGEN+EX_R10(r13)
  186. mfcr r9
  187. KVMTEST(0xc00)
  188. GET_SCRATCH0(r13)
  189. #endif
  190. BEGIN_FTR_SECTION
  191. cmpdi r0,0x1ebe
  192. beq- 1f
  193. END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
  194. mr r9,r13
  195. GET_PACA(r13)
  196. mfspr r11,SPRN_SRR0
  197. mfspr r12,SPRN_SRR1
  198. ld r10,PACAKBASE(r13)
  199. LOAD_HANDLER(r10, system_call_entry)
  200. mtspr SPRN_SRR0,r10
  201. ld r10,PACAKMSR(r13)
  202. mtspr SPRN_SRR1,r10
  203. rfid
  204. b . /* prevent speculative execution */
  205. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
  206. /* Fast LE/BE switch system call */
  207. 1: mfspr r12,SPRN_SRR1
  208. xori r12,r12,MSR_LE
  209. mtspr SPRN_SRR1,r12
  210. rfid /* return to userspace */
  211. b .
  212. STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
  213. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
  214. /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
  215. * out of line to handle them
  216. */
  217. . = 0xe00
  218. b h_data_storage_hv
  219. . = 0xe20
  220. b h_instr_storage_hv
  221. . = 0xe40
  222. b emulation_assist_hv
  223. . = 0xe50
  224. b hmi_exception_hv
  225. . = 0xe60
  226. b hmi_exception_hv
  227. /* We need to deal with the Altivec unavailable exception
  228. * here which is at 0xf20, thus in the middle of the
  229. * prolog code of the PerformanceMonitor one. A little
  230. * trickery is thus necessary
  231. */
  232. performance_monitor_pSeries_1:
  233. . = 0xf00
  234. b performance_monitor_pSeries
  235. altivec_unavailable_pSeries_1:
  236. . = 0xf20
  237. b altivec_unavailable_pSeries
  238. vsx_unavailable_pSeries_1:
  239. . = 0xf40
  240. b vsx_unavailable_pSeries
  241. #ifdef CONFIG_CBE_RAS
  242. STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
  243. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1202)
  244. #endif /* CONFIG_CBE_RAS */
  245. STD_EXCEPTION_PSERIES(0x1300, 0x1300, instruction_breakpoint)
  246. KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
  247. #ifdef CONFIG_CBE_RAS
  248. STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
  249. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1602)
  250. #endif /* CONFIG_CBE_RAS */
  251. STD_EXCEPTION_PSERIES(0x1700, 0x1700, altivec_assist)
  252. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x1700)
  253. #ifdef CONFIG_CBE_RAS
  254. STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
  255. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
  256. #endif /* CONFIG_CBE_RAS */
  257. . = 0x3000
  258. /*** Out of line interrupts support ***/
  259. /* moved from 0x200 */
  260. machine_check_pSeries:
  261. .globl machine_check_fwnmi
  262. machine_check_fwnmi:
  263. HMT_MEDIUM
  264. SET_SCRATCH0(r13) /* save r13 */
  265. EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common,
  266. EXC_STD, KVMTEST, 0x200)
  267. KVM_HANDLER_SKIP(PACA_EXMC, EXC_STD, 0x200)
  268. /* moved from 0x300 */
  269. data_access_check_stab:
  270. GET_PACA(r13)
  271. std r9,PACA_EXSLB+EX_R9(r13)
  272. std r10,PACA_EXSLB+EX_R10(r13)
  273. mfspr r10,SPRN_DAR
  274. mfspr r9,SPRN_DSISR
  275. srdi r10,r10,60
  276. rlwimi r10,r9,16,0x20
  277. #ifdef CONFIG_KVM_BOOK3S_PR
  278. lbz r9,HSTATE_IN_GUEST(r13)
  279. rlwimi r10,r9,8,0x300
  280. #endif
  281. mfcr r9
  282. cmpwi r10,0x2c
  283. beq do_stab_bolted_pSeries
  284. mtcrf 0x80,r9
  285. ld r9,PACA_EXSLB+EX_R9(r13)
  286. ld r10,PACA_EXSLB+EX_R10(r13)
  287. b data_access_not_stab
  288. do_stab_bolted_pSeries:
  289. std r11,PACA_EXSLB+EX_R11(r13)
  290. std r12,PACA_EXSLB+EX_R12(r13)
  291. GET_SCRATCH0(r10)
  292. std r10,PACA_EXSLB+EX_R13(r13)
  293. EXCEPTION_PROLOG_PSERIES_1(.do_stab_bolted, EXC_STD)
  294. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x300)
  295. KVM_HANDLER_SKIP(PACA_EXSLB, EXC_STD, 0x380)
  296. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x400)
  297. KVM_HANDLER_PR(PACA_EXSLB, EXC_STD, 0x480)
  298. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x900)
  299. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x982)
  300. .align 7
  301. /* moved from 0xe00 */
  302. STD_EXCEPTION_HV(., 0xe02, h_data_storage)
  303. KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0xe02)
  304. STD_EXCEPTION_HV(., 0xe22, h_instr_storage)
  305. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe22)
  306. STD_EXCEPTION_HV(., 0xe42, emulation_assist)
  307. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe42)
  308. STD_EXCEPTION_HV(., 0xe62, hmi_exception) /* need to flush cache ? */
  309. KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe62)
  310. /* moved from 0xf00 */
  311. STD_EXCEPTION_PSERIES(., 0xf00, performance_monitor)
  312. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf00)
  313. STD_EXCEPTION_PSERIES(., 0xf20, altivec_unavailable)
  314. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf20)
  315. STD_EXCEPTION_PSERIES(., 0xf40, vsx_unavailable)
  316. KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf40)
  317. /*
  318. * An interrupt came in while soft-disabled. We set paca->irq_happened,
  319. * then, if it was a decrementer interrupt, we bump the dec to max and
  320. * and return, else we hard disable and return. This is called with
  321. * r10 containing the value to OR to the paca field.
  322. */
  323. #define MASKED_INTERRUPT(_H) \
  324. masked_##_H##interrupt: \
  325. std r11,PACA_EXGEN+EX_R11(r13); \
  326. lbz r11,PACAIRQHAPPENED(r13); \
  327. or r11,r11,r10; \
  328. stb r11,PACAIRQHAPPENED(r13); \
  329. andi. r10,r10,PACA_IRQ_DEC; \
  330. beq 1f; \
  331. lis r10,0x7fff; \
  332. ori r10,r10,0xffff; \
  333. mtspr SPRN_DEC,r10; \
  334. b 2f; \
  335. 1: mfspr r10,SPRN_##_H##SRR1; \
  336. rldicl r10,r10,48,1; /* clear MSR_EE */ \
  337. rotldi r10,r10,16; \
  338. mtspr SPRN_##_H##SRR1,r10; \
  339. 2: mtcrf 0x80,r9; \
  340. ld r9,PACA_EXGEN+EX_R9(r13); \
  341. ld r10,PACA_EXGEN+EX_R10(r13); \
  342. ld r11,PACA_EXGEN+EX_R11(r13); \
  343. GET_SCRATCH0(r13); \
  344. ##_H##rfid; \
  345. b .
  346. MASKED_INTERRUPT()
  347. MASKED_INTERRUPT(H)
  348. /*
  349. * Called from arch_local_irq_enable when an interrupt needs
  350. * to be resent. r3 contains 0x500 or 0x900 to indicate which
  351. * kind of interrupt. MSR:EE is already off. We generate a
  352. * stackframe like if a real interrupt had happened.
  353. *
  354. * Note: While MSR:EE is off, we need to make sure that _MSR
  355. * in the generated frame has EE set to 1 or the exception
  356. * handler will not properly re-enable them.
  357. */
  358. _GLOBAL(__replay_interrupt)
  359. /* We are going to jump to the exception common code which
  360. * will retrieve various register values from the PACA which
  361. * we don't give a damn about, so we don't bother storing them.
  362. */
  363. mfmsr r12
  364. mflr r11
  365. mfcr r9
  366. ori r12,r12,MSR_EE
  367. andi. r3,r3,0x0800
  368. bne decrementer_common
  369. b hardware_interrupt_common
  370. #ifdef CONFIG_PPC_PSERIES
  371. /*
  372. * Vectors for the FWNMI option. Share common code.
  373. */
  374. .globl system_reset_fwnmi
  375. .align 7
  376. system_reset_fwnmi:
  377. HMT_MEDIUM
  378. SET_SCRATCH0(r13) /* save r13 */
  379. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
  380. NOTEST, 0x100)
  381. #endif /* CONFIG_PPC_PSERIES */
  382. #ifdef __DISABLED__
  383. /*
  384. * This is used for when the SLB miss handler has to go virtual,
  385. * which doesn't happen for now anymore but will once we re-implement
  386. * dynamic VSIDs for shared page tables
  387. */
  388. slb_miss_user_pseries:
  389. std r10,PACA_EXGEN+EX_R10(r13)
  390. std r11,PACA_EXGEN+EX_R11(r13)
  391. std r12,PACA_EXGEN+EX_R12(r13)
  392. GET_SCRATCH0(r10)
  393. ld r11,PACA_EXSLB+EX_R9(r13)
  394. ld r12,PACA_EXSLB+EX_R3(r13)
  395. std r10,PACA_EXGEN+EX_R13(r13)
  396. std r11,PACA_EXGEN+EX_R9(r13)
  397. std r12,PACA_EXGEN+EX_R3(r13)
  398. clrrdi r12,r13,32
  399. mfmsr r10
  400. mfspr r11,SRR0 /* save SRR0 */
  401. ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
  402. ori r10,r10,MSR_IR|MSR_DR|MSR_RI
  403. mtspr SRR0,r12
  404. mfspr r12,SRR1 /* and SRR1 */
  405. mtspr SRR1,r10
  406. rfid
  407. b . /* prevent spec. execution */
  408. #endif /* __DISABLED__ */
  409. .align 7
  410. .globl __end_interrupts
  411. __end_interrupts:
  412. /*
  413. * Code from here down to __end_handlers is invoked from the
  414. * exception prologs above. Because the prologs assemble the
  415. * addresses of these handlers using the LOAD_HANDLER macro,
  416. * which uses an addi instruction, these handlers must be in
  417. * the first 32k of the kernel image.
  418. */
  419. /*** Common interrupt handlers ***/
  420. STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
  421. /*
  422. * Machine check is different because we use a different
  423. * save area: PACA_EXMC instead of PACA_EXGEN.
  424. */
  425. .align 7
  426. .globl machine_check_common
  427. machine_check_common:
  428. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  429. FINISH_NAP
  430. DISABLE_INTS
  431. bl .save_nvgprs
  432. addi r3,r1,STACK_FRAME_OVERHEAD
  433. bl .machine_check_exception
  434. b .ret_from_except
  435. STD_EXCEPTION_COMMON_ASYNC(0x500, hardware_interrupt, do_IRQ)
  436. STD_EXCEPTION_COMMON_ASYNC(0x900, decrementer, .timer_interrupt)
  437. STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
  438. STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
  439. STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
  440. STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
  441. STD_EXCEPTION_COMMON(0xe40, emulation_assist, .program_check_exception)
  442. STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception)
  443. STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, .performance_monitor_exception)
  444. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
  445. #ifdef CONFIG_ALTIVEC
  446. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
  447. #else
  448. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
  449. #endif
  450. #ifdef CONFIG_CBE_RAS
  451. STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
  452. STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
  453. STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
  454. #endif /* CONFIG_CBE_RAS */
  455. .align 7
  456. system_call_entry:
  457. b system_call_common
  458. ppc64_runlatch_on_trampoline:
  459. b .__ppc64_runlatch_on
  460. /*
  461. * Here we have detected that the kernel stack pointer is bad.
  462. * R9 contains the saved CR, r13 points to the paca,
  463. * r10 contains the (bad) kernel stack pointer,
  464. * r11 and r12 contain the saved SRR0 and SRR1.
  465. * We switch to using an emergency stack, save the registers there,
  466. * and call kernel_bad_stack(), which panics.
  467. */
  468. bad_stack:
  469. ld r1,PACAEMERGSP(r13)
  470. subi r1,r1,64+INT_FRAME_SIZE
  471. std r9,_CCR(r1)
  472. std r10,GPR1(r1)
  473. std r11,_NIP(r1)
  474. std r12,_MSR(r1)
  475. mfspr r11,SPRN_DAR
  476. mfspr r12,SPRN_DSISR
  477. std r11,_DAR(r1)
  478. std r12,_DSISR(r1)
  479. mflr r10
  480. mfctr r11
  481. mfxer r12
  482. std r10,_LINK(r1)
  483. std r11,_CTR(r1)
  484. std r12,_XER(r1)
  485. SAVE_GPR(0,r1)
  486. SAVE_GPR(2,r1)
  487. ld r10,EX_R3(r3)
  488. std r10,GPR3(r1)
  489. SAVE_GPR(4,r1)
  490. SAVE_4GPRS(5,r1)
  491. ld r9,EX_R9(r3)
  492. ld r10,EX_R10(r3)
  493. SAVE_2GPRS(9,r1)
  494. ld r9,EX_R11(r3)
  495. ld r10,EX_R12(r3)
  496. ld r11,EX_R13(r3)
  497. std r9,GPR11(r1)
  498. std r10,GPR12(r1)
  499. std r11,GPR13(r1)
  500. BEGIN_FTR_SECTION
  501. ld r10,EX_CFAR(r3)
  502. std r10,ORIG_GPR3(r1)
  503. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  504. SAVE_8GPRS(14,r1)
  505. SAVE_10GPRS(22,r1)
  506. lhz r12,PACA_TRAP_SAVE(r13)
  507. std r12,_TRAP(r1)
  508. addi r11,r1,INT_FRAME_SIZE
  509. std r11,0(r1)
  510. li r12,0
  511. std r12,0(r11)
  512. ld r2,PACATOC(r13)
  513. ld r11,exception_marker@toc(r2)
  514. std r12,RESULT(r1)
  515. std r11,STACK_FRAME_OVERHEAD-16(r1)
  516. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  517. bl .kernel_bad_stack
  518. b 1b
  519. /*
  520. * Here r13 points to the paca, r9 contains the saved CR,
  521. * SRR0 and SRR1 are saved in r11 and r12,
  522. * r9 - r13 are saved in paca->exgen.
  523. */
  524. .align 7
  525. .globl data_access_common
  526. data_access_common:
  527. mfspr r10,SPRN_DAR
  528. std r10,PACA_EXGEN+EX_DAR(r13)
  529. mfspr r10,SPRN_DSISR
  530. stw r10,PACA_EXGEN+EX_DSISR(r13)
  531. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  532. DISABLE_INTS
  533. ld r12,_MSR(r1)
  534. ld r3,PACA_EXGEN+EX_DAR(r13)
  535. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  536. li r5,0x300
  537. b .do_hash_page /* Try to handle as hpte fault */
  538. .align 7
  539. .globl h_data_storage_common
  540. h_data_storage_common:
  541. mfspr r10,SPRN_HDAR
  542. std r10,PACA_EXGEN+EX_DAR(r13)
  543. mfspr r10,SPRN_HDSISR
  544. stw r10,PACA_EXGEN+EX_DSISR(r13)
  545. EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
  546. bl .save_nvgprs
  547. DISABLE_INTS
  548. addi r3,r1,STACK_FRAME_OVERHEAD
  549. bl .unknown_exception
  550. b .ret_from_except
  551. .align 7
  552. .globl instruction_access_common
  553. instruction_access_common:
  554. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  555. DISABLE_INTS
  556. ld r12,_MSR(r1)
  557. ld r3,_NIP(r1)
  558. andis. r4,r12,0x5820
  559. li r5,0x400
  560. b .do_hash_page /* Try to handle as hpte fault */
  561. STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception)
  562. /*
  563. * Here is the common SLB miss user that is used when going to virtual
  564. * mode for SLB misses, that is currently not used
  565. */
  566. #ifdef __DISABLED__
  567. .align 7
  568. .globl slb_miss_user_common
  569. slb_miss_user_common:
  570. mflr r10
  571. std r3,PACA_EXGEN+EX_DAR(r13)
  572. stw r9,PACA_EXGEN+EX_CCR(r13)
  573. std r10,PACA_EXGEN+EX_LR(r13)
  574. std r11,PACA_EXGEN+EX_SRR0(r13)
  575. bl .slb_allocate_user
  576. ld r10,PACA_EXGEN+EX_LR(r13)
  577. ld r3,PACA_EXGEN+EX_R3(r13)
  578. lwz r9,PACA_EXGEN+EX_CCR(r13)
  579. ld r11,PACA_EXGEN+EX_SRR0(r13)
  580. mtlr r10
  581. beq- slb_miss_fault
  582. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  583. beq- unrecov_user_slb
  584. mfmsr r10
  585. .machine push
  586. .machine "power4"
  587. mtcrf 0x80,r9
  588. .machine pop
  589. clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
  590. mtmsrd r10,1
  591. mtspr SRR0,r11
  592. mtspr SRR1,r12
  593. ld r9,PACA_EXGEN+EX_R9(r13)
  594. ld r10,PACA_EXGEN+EX_R10(r13)
  595. ld r11,PACA_EXGEN+EX_R11(r13)
  596. ld r12,PACA_EXGEN+EX_R12(r13)
  597. ld r13,PACA_EXGEN+EX_R13(r13)
  598. rfid
  599. b .
  600. slb_miss_fault:
  601. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
  602. ld r4,PACA_EXGEN+EX_DAR(r13)
  603. li r5,0
  604. std r4,_DAR(r1)
  605. std r5,_DSISR(r1)
  606. b handle_page_fault
  607. unrecov_user_slb:
  608. EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
  609. DISABLE_INTS
  610. bl .save_nvgprs
  611. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  612. bl .unrecoverable_exception
  613. b 1b
  614. #endif /* __DISABLED__ */
  615. /*
  616. * r13 points to the PACA, r9 contains the saved CR,
  617. * r12 contain the saved SRR1, SRR0 is still ready for return
  618. * r3 has the faulting address
  619. * r9 - r13 are saved in paca->exslb.
  620. * r3 is saved in paca->slb_r3
  621. * We assume we aren't going to take any exceptions during this procedure.
  622. */
  623. _GLOBAL(slb_miss_realmode)
  624. mflr r10
  625. #ifdef CONFIG_RELOCATABLE
  626. mtctr r11
  627. #endif
  628. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  629. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  630. bl .slb_allocate_realmode
  631. /* All done -- return from exception. */
  632. ld r10,PACA_EXSLB+EX_LR(r13)
  633. ld r3,PACA_EXSLB+EX_R3(r13)
  634. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  635. mtlr r10
  636. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  637. beq- 2f
  638. .machine push
  639. .machine "power4"
  640. mtcrf 0x80,r9
  641. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  642. .machine pop
  643. ld r9,PACA_EXSLB+EX_R9(r13)
  644. ld r10,PACA_EXSLB+EX_R10(r13)
  645. ld r11,PACA_EXSLB+EX_R11(r13)
  646. ld r12,PACA_EXSLB+EX_R12(r13)
  647. ld r13,PACA_EXSLB+EX_R13(r13)
  648. rfid
  649. b . /* prevent speculative execution */
  650. 2: mfspr r11,SPRN_SRR0
  651. ld r10,PACAKBASE(r13)
  652. LOAD_HANDLER(r10,unrecov_slb)
  653. mtspr SPRN_SRR0,r10
  654. ld r10,PACAKMSR(r13)
  655. mtspr SPRN_SRR1,r10
  656. rfid
  657. b .
  658. unrecov_slb:
  659. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  660. DISABLE_INTS
  661. bl .save_nvgprs
  662. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  663. bl .unrecoverable_exception
  664. b 1b
  665. #ifdef CONFIG_PPC_970_NAP
  666. power4_fixup_nap:
  667. andc r9,r9,r10
  668. std r9,TI_LOCAL_FLAGS(r11)
  669. ld r10,_LINK(r1) /* make idle task do the */
  670. std r10,_NIP(r1) /* equivalent of a blr */
  671. blr
  672. #endif
  673. .align 7
  674. .globl alignment_common
  675. alignment_common:
  676. mfspr r10,SPRN_DAR
  677. std r10,PACA_EXGEN+EX_DAR(r13)
  678. mfspr r10,SPRN_DSISR
  679. stw r10,PACA_EXGEN+EX_DSISR(r13)
  680. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  681. ld r3,PACA_EXGEN+EX_DAR(r13)
  682. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  683. std r3,_DAR(r1)
  684. std r4,_DSISR(r1)
  685. bl .save_nvgprs
  686. DISABLE_INTS
  687. addi r3,r1,STACK_FRAME_OVERHEAD
  688. bl .alignment_exception
  689. b .ret_from_except
  690. .align 7
  691. .globl program_check_common
  692. program_check_common:
  693. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  694. bl .save_nvgprs
  695. DISABLE_INTS
  696. addi r3,r1,STACK_FRAME_OVERHEAD
  697. bl .program_check_exception
  698. b .ret_from_except
  699. .align 7
  700. .globl fp_unavailable_common
  701. fp_unavailable_common:
  702. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  703. bne 1f /* if from user, just load it up */
  704. bl .save_nvgprs
  705. DISABLE_INTS
  706. addi r3,r1,STACK_FRAME_OVERHEAD
  707. bl .kernel_fp_unavailable_exception
  708. BUG_OPCODE
  709. 1: bl .load_up_fpu
  710. b fast_exception_return
  711. .align 7
  712. .globl altivec_unavailable_common
  713. altivec_unavailable_common:
  714. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  715. #ifdef CONFIG_ALTIVEC
  716. BEGIN_FTR_SECTION
  717. beq 1f
  718. bl .load_up_altivec
  719. b fast_exception_return
  720. 1:
  721. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  722. #endif
  723. bl .save_nvgprs
  724. DISABLE_INTS
  725. addi r3,r1,STACK_FRAME_OVERHEAD
  726. bl .altivec_unavailable_exception
  727. b .ret_from_except
  728. .align 7
  729. .globl vsx_unavailable_common
  730. vsx_unavailable_common:
  731. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  732. #ifdef CONFIG_VSX
  733. BEGIN_FTR_SECTION
  734. beq 1f
  735. b .load_up_vsx
  736. 1:
  737. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  738. #endif
  739. bl .save_nvgprs
  740. DISABLE_INTS
  741. addi r3,r1,STACK_FRAME_OVERHEAD
  742. bl .vsx_unavailable_exception
  743. b .ret_from_except
  744. .align 7
  745. .globl __end_handlers
  746. __end_handlers:
  747. /*
  748. * Hash table stuff
  749. */
  750. .align 7
  751. _STATIC(do_hash_page)
  752. std r3,_DAR(r1)
  753. std r4,_DSISR(r1)
  754. andis. r0,r4,0xa410 /* weird error? */
  755. bne- handle_page_fault /* if not, try to insert a HPTE */
  756. andis. r0,r4,DSISR_DABRMATCH@h
  757. bne- handle_dabr_fault
  758. BEGIN_FTR_SECTION
  759. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  760. bne- do_ste_alloc /* If so handle it */
  761. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
  762. clrrdi r11,r1,THREAD_SHIFT
  763. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  764. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  765. bne 77f /* then don't call hash_page now */
  766. /*
  767. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  768. * accessing a userspace segment (even from the kernel). We assume
  769. * kernel addresses always have the high bit set.
  770. */
  771. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  772. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  773. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  774. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  775. ori r4,r4,1 /* add _PAGE_PRESENT */
  776. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  777. /*
  778. * r3 contains the faulting address
  779. * r4 contains the required access permissions
  780. * r5 contains the trap number
  781. *
  782. * at return r3 = 0 for success, 1 for page fault, negative for error
  783. */
  784. bl .hash_page /* build HPTE if possible */
  785. cmpdi r3,0 /* see if hash_page succeeded */
  786. /* Success */
  787. beq fast_exc_return_irq /* Return from exception on success */
  788. /* Error */
  789. blt- 13f
  790. /* Here we have a page fault that hash_page can't handle. */
  791. handle_page_fault:
  792. 11: ld r4,_DAR(r1)
  793. ld r5,_DSISR(r1)
  794. addi r3,r1,STACK_FRAME_OVERHEAD
  795. bl .do_page_fault
  796. cmpdi r3,0
  797. beq+ 12f
  798. bl .save_nvgprs
  799. mr r5,r3
  800. addi r3,r1,STACK_FRAME_OVERHEAD
  801. lwz r4,_DAR(r1)
  802. bl .bad_page_fault
  803. b .ret_from_except
  804. /* We have a data breakpoint exception - handle it */
  805. handle_dabr_fault:
  806. bl .save_nvgprs
  807. ld r4,_DAR(r1)
  808. ld r5,_DSISR(r1)
  809. addi r3,r1,STACK_FRAME_OVERHEAD
  810. bl .do_dabr
  811. 12: b .ret_from_except_lite
  812. /* We have a page fault that hash_page could handle but HV refused
  813. * the PTE insertion
  814. */
  815. 13: bl .save_nvgprs
  816. mr r5,r3
  817. addi r3,r1,STACK_FRAME_OVERHEAD
  818. ld r4,_DAR(r1)
  819. bl .low_hash_fault
  820. b .ret_from_except
  821. /*
  822. * We come here as a result of a DSI at a point where we don't want
  823. * to call hash_page, such as when we are accessing memory (possibly
  824. * user memory) inside a PMU interrupt that occurred while interrupts
  825. * were soft-disabled. We want to invoke the exception handler for
  826. * the access, or panic if there isn't a handler.
  827. */
  828. 77: bl .save_nvgprs
  829. mr r4,r3
  830. addi r3,r1,STACK_FRAME_OVERHEAD
  831. li r5,SIGSEGV
  832. bl .bad_page_fault
  833. b .ret_from_except
  834. /* here we have a segment miss */
  835. do_ste_alloc:
  836. bl .ste_allocate /* try to insert stab entry */
  837. cmpdi r3,0
  838. bne- handle_page_fault
  839. b fast_exception_return
  840. /*
  841. * r13 points to the PACA, r9 contains the saved CR,
  842. * r11 and r12 contain the saved SRR0 and SRR1.
  843. * r9 - r13 are saved in paca->exslb.
  844. * We assume we aren't going to take any exceptions during this procedure.
  845. * We assume (DAR >> 60) == 0xc.
  846. */
  847. .align 7
  848. _GLOBAL(do_stab_bolted)
  849. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  850. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  851. /* Hash to the primary group */
  852. ld r10,PACASTABVIRT(r13)
  853. mfspr r11,SPRN_DAR
  854. srdi r11,r11,28
  855. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  856. /* Calculate VSID */
  857. /* This is a kernel address, so protovsid = ESID */
  858. ASM_VSID_SCRAMBLE(r11, r9, 256M)
  859. rldic r9,r11,12,16 /* r9 = vsid << 12 */
  860. /* Search the primary group for a free entry */
  861. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  862. andi. r11,r11,0x80
  863. beq 2f
  864. addi r10,r10,16
  865. andi. r11,r10,0x70
  866. bne 1b
  867. /* Stick for only searching the primary group for now. */
  868. /* At least for now, we use a very simple random castout scheme */
  869. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  870. mftb r11
  871. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  872. ori r11,r11,0x10
  873. /* r10 currently points to an ste one past the group of interest */
  874. /* make it point to the randomly selected entry */
  875. subi r10,r10,128
  876. or r10,r10,r11 /* r10 is the entry to invalidate */
  877. isync /* mark the entry invalid */
  878. ld r11,0(r10)
  879. rldicl r11,r11,56,1 /* clear the valid bit */
  880. rotldi r11,r11,8
  881. std r11,0(r10)
  882. sync
  883. clrrdi r11,r11,28 /* Get the esid part of the ste */
  884. slbie r11
  885. 2: std r9,8(r10) /* Store the vsid part of the ste */
  886. eieio
  887. mfspr r11,SPRN_DAR /* Get the new esid */
  888. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  889. ori r11,r11,0x90 /* Turn on valid and kp */
  890. std r11,0(r10) /* Put new entry back into the stab */
  891. sync
  892. /* All done -- return from exception. */
  893. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  894. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  895. andi. r10,r12,MSR_RI
  896. beq- unrecov_slb
  897. mtcrf 0x80,r9 /* restore CR */
  898. mfmsr r10
  899. clrrdi r10,r10,2
  900. mtmsrd r10,1
  901. mtspr SPRN_SRR0,r11
  902. mtspr SPRN_SRR1,r12
  903. ld r9,PACA_EXSLB+EX_R9(r13)
  904. ld r10,PACA_EXSLB+EX_R10(r13)
  905. ld r11,PACA_EXSLB+EX_R11(r13)
  906. ld r12,PACA_EXSLB+EX_R12(r13)
  907. ld r13,PACA_EXSLB+EX_R13(r13)
  908. rfid
  909. b . /* prevent speculative execution */
  910. #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
  911. /*
  912. * Data area reserved for FWNMI option.
  913. * This address (0x7000) is fixed by the RPA.
  914. */
  915. .= 0x7000
  916. .globl fwnmi_data_area
  917. fwnmi_data_area:
  918. /* pseries and powernv need to keep the whole page from
  919. * 0x7000 to 0x8000 free for use by the firmware
  920. */
  921. . = 0x8000
  922. #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
  923. /* Space for CPU0's segment table */
  924. .balign 4096
  925. .globl initial_stab
  926. initial_stab:
  927. .space 4096
  928. #ifdef CONFIG_PPC_POWERNV
  929. _GLOBAL(opal_mc_secondary_handler)
  930. HMT_MEDIUM
  931. SET_SCRATCH0(r13)
  932. GET_PACA(r13)
  933. clrldi r3,r3,2
  934. tovirt(r3,r3)
  935. std r3,PACA_OPAL_MC_EVT(r13)
  936. ld r13,OPAL_MC_SRR0(r3)
  937. mtspr SPRN_SRR0,r13
  938. ld r13,OPAL_MC_SRR1(r3)
  939. mtspr SPRN_SRR1,r13
  940. ld r3,OPAL_MC_GPR3(r3)
  941. GET_SCRATCH0(r13)
  942. b machine_check_pSeries
  943. #endif /* CONFIG_PPC_POWERNV */