exceptions-64s.S 24 KB

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