exceptions-64s.S 27 KB

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