exceptions-64s.S 25 KB

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