exceptions-64s.S 26 KB

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