exceptions-64s.S 30 KB

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