exceptions-64s.S 30 KB

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