exceptions-64s.S 25 KB

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