exceptions-64s.S 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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. .align 7
  276. .globl __end_interrupts
  277. __end_interrupts:
  278. /*
  279. * Code from here down to __end_handlers is invoked from the
  280. * exception prologs above. Because the prologs assemble the
  281. * addresses of these handlers using the LOAD_HANDLER macro,
  282. * which uses an addi instruction, these handlers must be in
  283. * the first 32k of the kernel image.
  284. */
  285. /*** Common interrupt handlers ***/
  286. STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
  287. /*
  288. * Machine check is different because we use a different
  289. * save area: PACA_EXMC instead of PACA_EXGEN.
  290. */
  291. .align 7
  292. .globl machine_check_common
  293. machine_check_common:
  294. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  295. FINISH_NAP
  296. DISABLE_INTS
  297. bl .save_nvgprs
  298. addi r3,r1,STACK_FRAME_OVERHEAD
  299. bl .machine_check_exception
  300. b .ret_from_except
  301. STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
  302. STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
  303. STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
  304. STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
  305. STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
  306. STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
  307. STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
  308. #ifdef CONFIG_ALTIVEC
  309. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
  310. #else
  311. STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
  312. #endif
  313. #ifdef CONFIG_CBE_RAS
  314. STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
  315. STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
  316. STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
  317. #endif /* CONFIG_CBE_RAS */
  318. .align 7
  319. system_call_entry:
  320. b system_call_common
  321. /*
  322. * Here we have detected that the kernel stack pointer is bad.
  323. * R9 contains the saved CR, r13 points to the paca,
  324. * r10 contains the (bad) kernel stack pointer,
  325. * r11 and r12 contain the saved SRR0 and SRR1.
  326. * We switch to using an emergency stack, save the registers there,
  327. * and call kernel_bad_stack(), which panics.
  328. */
  329. bad_stack:
  330. ld r1,PACAEMERGSP(r13)
  331. subi r1,r1,64+INT_FRAME_SIZE
  332. std r9,_CCR(r1)
  333. std r10,GPR1(r1)
  334. std r11,_NIP(r1)
  335. std r12,_MSR(r1)
  336. mfspr r11,SPRN_DAR
  337. mfspr r12,SPRN_DSISR
  338. std r11,_DAR(r1)
  339. std r12,_DSISR(r1)
  340. mflr r10
  341. mfctr r11
  342. mfxer r12
  343. std r10,_LINK(r1)
  344. std r11,_CTR(r1)
  345. std r12,_XER(r1)
  346. SAVE_GPR(0,r1)
  347. SAVE_GPR(2,r1)
  348. SAVE_4GPRS(3,r1)
  349. SAVE_2GPRS(7,r1)
  350. SAVE_10GPRS(12,r1)
  351. SAVE_10GPRS(22,r1)
  352. lhz r12,PACA_TRAP_SAVE(r13)
  353. std r12,_TRAP(r1)
  354. addi r11,r1,INT_FRAME_SIZE
  355. std r11,0(r1)
  356. li r12,0
  357. std r12,0(r11)
  358. ld r2,PACATOC(r13)
  359. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  360. bl .kernel_bad_stack
  361. b 1b
  362. /*
  363. * Here r13 points to the paca, r9 contains the saved CR,
  364. * SRR0 and SRR1 are saved in r11 and r12,
  365. * r9 - r13 are saved in paca->exgen.
  366. */
  367. .align 7
  368. .globl data_access_common
  369. data_access_common:
  370. mfspr r10,SPRN_DAR
  371. std r10,PACA_EXGEN+EX_DAR(r13)
  372. mfspr r10,SPRN_DSISR
  373. stw r10,PACA_EXGEN+EX_DSISR(r13)
  374. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  375. ld r3,PACA_EXGEN+EX_DAR(r13)
  376. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  377. li r5,0x300
  378. b .do_hash_page /* Try to handle as hpte fault */
  379. .align 7
  380. .globl instruction_access_common
  381. instruction_access_common:
  382. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  383. ld r3,_NIP(r1)
  384. andis. r4,r12,0x5820
  385. li r5,0x400
  386. b .do_hash_page /* Try to handle as hpte fault */
  387. /*
  388. * Here is the common SLB miss user that is used when going to virtual
  389. * mode for SLB misses, that is currently not used
  390. */
  391. #ifdef __DISABLED__
  392. .align 7
  393. .globl slb_miss_user_common
  394. slb_miss_user_common:
  395. mflr r10
  396. std r3,PACA_EXGEN+EX_DAR(r13)
  397. stw r9,PACA_EXGEN+EX_CCR(r13)
  398. std r10,PACA_EXGEN+EX_LR(r13)
  399. std r11,PACA_EXGEN+EX_SRR0(r13)
  400. bl .slb_allocate_user
  401. ld r10,PACA_EXGEN+EX_LR(r13)
  402. ld r3,PACA_EXGEN+EX_R3(r13)
  403. lwz r9,PACA_EXGEN+EX_CCR(r13)
  404. ld r11,PACA_EXGEN+EX_SRR0(r13)
  405. mtlr r10
  406. beq- slb_miss_fault
  407. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  408. beq- unrecov_user_slb
  409. mfmsr r10
  410. .machine push
  411. .machine "power4"
  412. mtcrf 0x80,r9
  413. .machine pop
  414. clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
  415. mtmsrd r10,1
  416. mtspr SRR0,r11
  417. mtspr SRR1,r12
  418. ld r9,PACA_EXGEN+EX_R9(r13)
  419. ld r10,PACA_EXGEN+EX_R10(r13)
  420. ld r11,PACA_EXGEN+EX_R11(r13)
  421. ld r12,PACA_EXGEN+EX_R12(r13)
  422. ld r13,PACA_EXGEN+EX_R13(r13)
  423. rfid
  424. b .
  425. slb_miss_fault:
  426. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
  427. ld r4,PACA_EXGEN+EX_DAR(r13)
  428. li r5,0
  429. std r4,_DAR(r1)
  430. std r5,_DSISR(r1)
  431. b handle_page_fault
  432. unrecov_user_slb:
  433. EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
  434. DISABLE_INTS
  435. bl .save_nvgprs
  436. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  437. bl .unrecoverable_exception
  438. b 1b
  439. #endif /* __DISABLED__ */
  440. /*
  441. * r13 points to the PACA, r9 contains the saved CR,
  442. * r12 contain the saved SRR1, SRR0 is still ready for return
  443. * r3 has the faulting address
  444. * r9 - r13 are saved in paca->exslb.
  445. * r3 is saved in paca->slb_r3
  446. * We assume we aren't going to take any exceptions during this procedure.
  447. */
  448. _GLOBAL(slb_miss_realmode)
  449. mflr r10
  450. #ifdef CONFIG_RELOCATABLE
  451. mtctr r11
  452. #endif
  453. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  454. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  455. bl .slb_allocate_realmode
  456. /* All done -- return from exception. */
  457. ld r10,PACA_EXSLB+EX_LR(r13)
  458. ld r3,PACA_EXSLB+EX_R3(r13)
  459. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  460. #ifdef CONFIG_PPC_ISERIES
  461. BEGIN_FW_FTR_SECTION
  462. ld r11,PACALPPACAPTR(r13)
  463. ld r11,LPPACASRR0(r11) /* get SRR0 value */
  464. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  465. #endif /* CONFIG_PPC_ISERIES */
  466. mtlr r10
  467. andi. r10,r12,MSR_RI /* check for unrecoverable exception */
  468. beq- 2f
  469. .machine push
  470. .machine "power4"
  471. mtcrf 0x80,r9
  472. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  473. .machine pop
  474. #ifdef CONFIG_PPC_ISERIES
  475. BEGIN_FW_FTR_SECTION
  476. mtspr SPRN_SRR0,r11
  477. mtspr SPRN_SRR1,r12
  478. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  479. #endif /* CONFIG_PPC_ISERIES */
  480. ld r9,PACA_EXSLB+EX_R9(r13)
  481. ld r10,PACA_EXSLB+EX_R10(r13)
  482. ld r11,PACA_EXSLB+EX_R11(r13)
  483. ld r12,PACA_EXSLB+EX_R12(r13)
  484. ld r13,PACA_EXSLB+EX_R13(r13)
  485. rfid
  486. b . /* prevent speculative execution */
  487. 2:
  488. #ifdef CONFIG_PPC_ISERIES
  489. BEGIN_FW_FTR_SECTION
  490. b unrecov_slb
  491. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  492. #endif /* CONFIG_PPC_ISERIES */
  493. mfspr r11,SPRN_SRR0
  494. ld r10,PACAKBASE(r13)
  495. LOAD_HANDLER(r10,unrecov_slb)
  496. mtspr SPRN_SRR0,r10
  497. ld r10,PACAKMSR(r13)
  498. mtspr SPRN_SRR1,r10
  499. rfid
  500. b .
  501. unrecov_slb:
  502. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  503. DISABLE_INTS
  504. bl .save_nvgprs
  505. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  506. bl .unrecoverable_exception
  507. b 1b
  508. .align 7
  509. .globl hardware_interrupt_common
  510. .globl hardware_interrupt_entry
  511. hardware_interrupt_common:
  512. EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
  513. FINISH_NAP
  514. hardware_interrupt_entry:
  515. DISABLE_INTS
  516. BEGIN_FTR_SECTION
  517. bl .ppc64_runlatch_on
  518. END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
  519. addi r3,r1,STACK_FRAME_OVERHEAD
  520. bl .do_IRQ
  521. b .ret_from_except_lite
  522. #ifdef CONFIG_PPC_970_NAP
  523. power4_fixup_nap:
  524. andc r9,r9,r10
  525. std r9,TI_LOCAL_FLAGS(r11)
  526. ld r10,_LINK(r1) /* make idle task do the */
  527. std r10,_NIP(r1) /* equivalent of a blr */
  528. blr
  529. #endif
  530. .align 7
  531. .globl alignment_common
  532. alignment_common:
  533. mfspr r10,SPRN_DAR
  534. std r10,PACA_EXGEN+EX_DAR(r13)
  535. mfspr r10,SPRN_DSISR
  536. stw r10,PACA_EXGEN+EX_DSISR(r13)
  537. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  538. ld r3,PACA_EXGEN+EX_DAR(r13)
  539. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  540. std r3,_DAR(r1)
  541. std r4,_DSISR(r1)
  542. bl .save_nvgprs
  543. addi r3,r1,STACK_FRAME_OVERHEAD
  544. ENABLE_INTS
  545. bl .alignment_exception
  546. b .ret_from_except
  547. .align 7
  548. .globl program_check_common
  549. program_check_common:
  550. EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  551. bl .save_nvgprs
  552. addi r3,r1,STACK_FRAME_OVERHEAD
  553. ENABLE_INTS
  554. bl .program_check_exception
  555. b .ret_from_except
  556. .align 7
  557. .globl fp_unavailable_common
  558. fp_unavailable_common:
  559. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  560. bne 1f /* if from user, just load it up */
  561. bl .save_nvgprs
  562. addi r3,r1,STACK_FRAME_OVERHEAD
  563. ENABLE_INTS
  564. bl .kernel_fp_unavailable_exception
  565. BUG_OPCODE
  566. 1: bl .load_up_fpu
  567. b fast_exception_return
  568. .align 7
  569. .globl altivec_unavailable_common
  570. altivec_unavailable_common:
  571. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  572. #ifdef CONFIG_ALTIVEC
  573. BEGIN_FTR_SECTION
  574. beq 1f
  575. bl .load_up_altivec
  576. b fast_exception_return
  577. 1:
  578. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  579. #endif
  580. bl .save_nvgprs
  581. addi r3,r1,STACK_FRAME_OVERHEAD
  582. ENABLE_INTS
  583. bl .altivec_unavailable_exception
  584. b .ret_from_except
  585. .align 7
  586. .globl vsx_unavailable_common
  587. vsx_unavailable_common:
  588. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  589. #ifdef CONFIG_VSX
  590. BEGIN_FTR_SECTION
  591. bne .load_up_vsx
  592. 1:
  593. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  594. #endif
  595. bl .save_nvgprs
  596. addi r3,r1,STACK_FRAME_OVERHEAD
  597. ENABLE_INTS
  598. bl .vsx_unavailable_exception
  599. b .ret_from_except
  600. .align 7
  601. .globl __end_handlers
  602. __end_handlers:
  603. /*
  604. * Return from an exception with minimal checks.
  605. * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
  606. * If interrupts have been enabled, or anything has been
  607. * done that might have changed the scheduling status of
  608. * any task or sent any task a signal, you should use
  609. * ret_from_except or ret_from_except_lite instead of this.
  610. */
  611. fast_exc_return_irq: /* restores irq state too */
  612. ld r3,SOFTE(r1)
  613. TRACE_AND_RESTORE_IRQ(r3);
  614. ld r12,_MSR(r1)
  615. rldicl r4,r12,49,63 /* get MSR_EE to LSB */
  616. stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
  617. b 1f
  618. .globl fast_exception_return
  619. fast_exception_return:
  620. ld r12,_MSR(r1)
  621. 1: ld r11,_NIP(r1)
  622. andi. r3,r12,MSR_RI /* check if RI is set */
  623. beq- unrecov_fer
  624. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  625. andi. r3,r12,MSR_PR
  626. beq 2f
  627. ACCOUNT_CPU_USER_EXIT(r3, r4)
  628. 2:
  629. #endif
  630. ld r3,_CCR(r1)
  631. ld r4,_LINK(r1)
  632. ld r5,_CTR(r1)
  633. ld r6,_XER(r1)
  634. mtcr r3
  635. mtlr r4
  636. mtctr r5
  637. mtxer r6
  638. REST_GPR(0, r1)
  639. REST_8GPRS(2, r1)
  640. mfmsr r10
  641. rldicl r10,r10,48,1 /* clear EE */
  642. rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
  643. mtmsrd r10,1
  644. mtspr SPRN_SRR1,r12
  645. mtspr SPRN_SRR0,r11
  646. REST_4GPRS(10, r1)
  647. ld r1,GPR1(r1)
  648. rfid
  649. b . /* prevent speculative execution */
  650. unrecov_fer:
  651. bl .save_nvgprs
  652. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  653. bl .unrecoverable_exception
  654. b 1b
  655. /*
  656. * Hash table stuff
  657. */
  658. .align 7
  659. _STATIC(do_hash_page)
  660. std r3,_DAR(r1)
  661. std r4,_DSISR(r1)
  662. andis. r0,r4,0xa410 /* weird error? */
  663. bne- handle_page_fault /* if not, try to insert a HPTE */
  664. andis. r0,r4,DSISR_DABRMATCH@h
  665. bne- handle_dabr_fault
  666. BEGIN_FTR_SECTION
  667. andis. r0,r4,0x0020 /* Is it a segment table fault? */
  668. bne- do_ste_alloc /* If so handle it */
  669. END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
  670. clrrdi r11,r1,THREAD_SHIFT
  671. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  672. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  673. bne 77f /* then don't call hash_page now */
  674. /*
  675. * On iSeries, we soft-disable interrupts here, then
  676. * hard-enable interrupts so that the hash_page code can spin on
  677. * the hash_table_lock without problems on a shared processor.
  678. */
  679. DISABLE_INTS
  680. /*
  681. * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
  682. * and will clobber volatile registers when irq tracing is enabled
  683. * so we need to reload them. It may be possible to be smarter here
  684. * and move the irq tracing elsewhere but let's keep it simple for
  685. * now
  686. */
  687. #ifdef CONFIG_TRACE_IRQFLAGS
  688. ld r3,_DAR(r1)
  689. ld r4,_DSISR(r1)
  690. ld r5,_TRAP(r1)
  691. ld r12,_MSR(r1)
  692. clrrdi r5,r5,4
  693. #endif /* CONFIG_TRACE_IRQFLAGS */
  694. /*
  695. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  696. * accessing a userspace segment (even from the kernel). We assume
  697. * kernel addresses always have the high bit set.
  698. */
  699. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  700. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  701. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  702. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  703. ori r4,r4,1 /* add _PAGE_PRESENT */
  704. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  705. /*
  706. * r3 contains the faulting address
  707. * r4 contains the required access permissions
  708. * r5 contains the trap number
  709. *
  710. * at return r3 = 0 for success
  711. */
  712. bl .hash_page /* build HPTE if possible */
  713. cmpdi r3,0 /* see if hash_page succeeded */
  714. BEGIN_FW_FTR_SECTION
  715. /*
  716. * If we had interrupts soft-enabled at the point where the
  717. * DSI/ISI occurred, and an interrupt came in during hash_page,
  718. * handle it now.
  719. * We jump to ret_from_except_lite rather than fast_exception_return
  720. * because ret_from_except_lite will check for and handle pending
  721. * interrupts if necessary.
  722. */
  723. beq 13f
  724. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  725. BEGIN_FW_FTR_SECTION
  726. /*
  727. * Here we have interrupts hard-disabled, so it is sufficient
  728. * to restore paca->{soft,hard}_enable and get out.
  729. */
  730. beq fast_exc_return_irq /* Return from exception on success */
  731. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  732. /* For a hash failure, we don't bother re-enabling interrupts */
  733. ble- 12f
  734. /*
  735. * hash_page couldn't handle it, set soft interrupt enable back
  736. * to what it was before the trap. Note that .raw_local_irq_restore
  737. * handles any interrupts pending at this point.
  738. */
  739. ld r3,SOFTE(r1)
  740. TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
  741. bl .raw_local_irq_restore
  742. b 11f
  743. /* We have a data breakpoint exception - handle it */
  744. handle_dabr_fault:
  745. bl .save_nvgprs
  746. ld r4,_DAR(r1)
  747. ld r5,_DSISR(r1)
  748. addi r3,r1,STACK_FRAME_OVERHEAD
  749. bl .do_dabr
  750. b .ret_from_except_lite
  751. /* Here we have a page fault that hash_page can't handle. */
  752. handle_page_fault:
  753. ENABLE_INTS
  754. 11: ld r4,_DAR(r1)
  755. ld r5,_DSISR(r1)
  756. addi r3,r1,STACK_FRAME_OVERHEAD
  757. bl .do_page_fault
  758. cmpdi r3,0
  759. beq+ 13f
  760. bl .save_nvgprs
  761. mr r5,r3
  762. addi r3,r1,STACK_FRAME_OVERHEAD
  763. lwz r4,_DAR(r1)
  764. bl .bad_page_fault
  765. b .ret_from_except
  766. 13: b .ret_from_except_lite
  767. /* We have a page fault that hash_page could handle but HV refused
  768. * the PTE insertion
  769. */
  770. 12: bl .save_nvgprs
  771. mr r5,r3
  772. addi r3,r1,STACK_FRAME_OVERHEAD
  773. ld r4,_DAR(r1)
  774. bl .low_hash_fault
  775. b .ret_from_except
  776. /*
  777. * We come here as a result of a DSI at a point where we don't want
  778. * to call hash_page, such as when we are accessing memory (possibly
  779. * user memory) inside a PMU interrupt that occurred while interrupts
  780. * were soft-disabled. We want to invoke the exception handler for
  781. * the access, or panic if there isn't a handler.
  782. */
  783. 77: bl .save_nvgprs
  784. mr r4,r3
  785. addi r3,r1,STACK_FRAME_OVERHEAD
  786. li r5,SIGSEGV
  787. bl .bad_page_fault
  788. b .ret_from_except
  789. /* here we have a segment miss */
  790. do_ste_alloc:
  791. bl .ste_allocate /* try to insert stab entry */
  792. cmpdi r3,0
  793. bne- handle_page_fault
  794. b fast_exception_return
  795. /*
  796. * r13 points to the PACA, r9 contains the saved CR,
  797. * r11 and r12 contain the saved SRR0 and SRR1.
  798. * r9 - r13 are saved in paca->exslb.
  799. * We assume we aren't going to take any exceptions during this procedure.
  800. * We assume (DAR >> 60) == 0xc.
  801. */
  802. .align 7
  803. _GLOBAL(do_stab_bolted)
  804. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  805. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  806. /* Hash to the primary group */
  807. ld r10,PACASTABVIRT(r13)
  808. mfspr r11,SPRN_DAR
  809. srdi r11,r11,28
  810. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  811. /* Calculate VSID */
  812. /* This is a kernel address, so protovsid = ESID */
  813. ASM_VSID_SCRAMBLE(r11, r9, 256M)
  814. rldic r9,r11,12,16 /* r9 = vsid << 12 */
  815. /* Search the primary group for a free entry */
  816. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  817. andi. r11,r11,0x80
  818. beq 2f
  819. addi r10,r10,16
  820. andi. r11,r10,0x70
  821. bne 1b
  822. /* Stick for only searching the primary group for now. */
  823. /* At least for now, we use a very simple random castout scheme */
  824. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  825. mftb r11
  826. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  827. ori r11,r11,0x10
  828. /* r10 currently points to an ste one past the group of interest */
  829. /* make it point to the randomly selected entry */
  830. subi r10,r10,128
  831. or r10,r10,r11 /* r10 is the entry to invalidate */
  832. isync /* mark the entry invalid */
  833. ld r11,0(r10)
  834. rldicl r11,r11,56,1 /* clear the valid bit */
  835. rotldi r11,r11,8
  836. std r11,0(r10)
  837. sync
  838. clrrdi r11,r11,28 /* Get the esid part of the ste */
  839. slbie r11
  840. 2: std r9,8(r10) /* Store the vsid part of the ste */
  841. eieio
  842. mfspr r11,SPRN_DAR /* Get the new esid */
  843. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  844. ori r11,r11,0x90 /* Turn on valid and kp */
  845. std r11,0(r10) /* Put new entry back into the stab */
  846. sync
  847. /* All done -- return from exception. */
  848. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  849. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  850. andi. r10,r12,MSR_RI
  851. beq- unrecov_slb
  852. mtcrf 0x80,r9 /* restore CR */
  853. mfmsr r10
  854. clrrdi r10,r10,2
  855. mtmsrd r10,1
  856. mtspr SPRN_SRR0,r11
  857. mtspr SPRN_SRR1,r12
  858. ld r9,PACA_EXSLB+EX_R9(r13)
  859. ld r10,PACA_EXSLB+EX_R10(r13)
  860. ld r11,PACA_EXSLB+EX_R11(r13)
  861. ld r12,PACA_EXSLB+EX_R12(r13)
  862. ld r13,PACA_EXSLB+EX_R13(r13)
  863. rfid
  864. b . /* prevent speculative execution */
  865. /*
  866. * Space for CPU0's segment table.
  867. *
  868. * On iSeries, the hypervisor must fill in at least one entry before
  869. * we get control (with relocate on). The address is given to the hv
  870. * as a page number (see xLparMap below), so this must be at a
  871. * fixed address (the linker can't compute (u64)&initial_stab >>
  872. * PAGE_SHIFT).
  873. */
  874. . = STAB0_OFFSET /* 0x6000 */
  875. .globl initial_stab
  876. initial_stab:
  877. .space 4096
  878. #ifdef CONFIG_PPC_PSERIES
  879. /*
  880. * Data area reserved for FWNMI option.
  881. * This address (0x7000) is fixed by the RPA.
  882. */
  883. .= 0x7000
  884. .globl fwnmi_data_area
  885. fwnmi_data_area:
  886. #endif /* CONFIG_PPC_PSERIES */
  887. /* iSeries does not use the FWNMI stuff, so it is safe to put
  888. * this here, even if we later allow kernels that will boot on
  889. * both pSeries and iSeries */
  890. #ifdef CONFIG_PPC_ISERIES
  891. . = LPARMAP_PHYS
  892. .globl xLparMap
  893. xLparMap:
  894. .quad HvEsidsToMap /* xNumberEsids */
  895. .quad HvRangesToMap /* xNumberRanges */
  896. .quad STAB0_PAGE /* xSegmentTableOffs */
  897. .zero 40 /* xRsvd */
  898. /* xEsids (HvEsidsToMap entries of 2 quads) */
  899. .quad PAGE_OFFSET_ESID /* xKernelEsid */
  900. .quad PAGE_OFFSET_VSID /* xKernelVsid */
  901. .quad VMALLOC_START_ESID /* xKernelEsid */
  902. .quad VMALLOC_START_VSID /* xKernelVsid */
  903. /* xRanges (HvRangesToMap entries of 3 quads) */
  904. .quad HvPagesToMap /* xPages */
  905. .quad 0 /* xOffset */
  906. .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
  907. #endif /* CONFIG_PPC_ISERIES */
  908. #ifdef CONFIG_PPC_PSERIES
  909. . = 0x8000
  910. #endif /* CONFIG_PPC_PSERIES */