exceptions-64s.S 28 KB

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