exceptions-64s.S 25 KB

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