exceptions-64s.S 26 KB

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