exceptions-64s.S 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  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. clrrdi r11,r1,THREAD_SHIFT
  655. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  656. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  657. bne 77f /* then don't call hash_page now */
  658. /*
  659. * On iSeries, we soft-disable interrupts here, then
  660. * hard-enable interrupts so that the hash_page code can spin on
  661. * the hash_table_lock without problems on a shared processor.
  662. */
  663. DISABLE_INTS
  664. /*
  665. * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
  666. * and will clobber volatile registers when irq tracing is enabled
  667. * so we need to reload them. It may be possible to be smarter here
  668. * and move the irq tracing elsewhere but let's keep it simple for
  669. * now
  670. */
  671. #ifdef CONFIG_TRACE_IRQFLAGS
  672. ld r3,_DAR(r1)
  673. ld r4,_DSISR(r1)
  674. ld r5,_TRAP(r1)
  675. ld r12,_MSR(r1)
  676. clrrdi r5,r5,4
  677. #endif /* CONFIG_TRACE_IRQFLAGS */
  678. /*
  679. * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
  680. * accessing a userspace segment (even from the kernel). We assume
  681. * kernel addresses always have the high bit set.
  682. */
  683. rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
  684. rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
  685. orc r0,r12,r0 /* MSR_PR | ~high_bit */
  686. rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
  687. ori r4,r4,1 /* add _PAGE_PRESENT */
  688. rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
  689. /*
  690. * r3 contains the faulting address
  691. * r4 contains the required access permissions
  692. * r5 contains the trap number
  693. *
  694. * at return r3 = 0 for success
  695. */
  696. bl .hash_page /* build HPTE if possible */
  697. cmpdi r3,0 /* see if hash_page succeeded */
  698. BEGIN_FW_FTR_SECTION
  699. /*
  700. * If we had interrupts soft-enabled at the point where the
  701. * DSI/ISI occurred, and an interrupt came in during hash_page,
  702. * handle it now.
  703. * We jump to ret_from_except_lite rather than fast_exception_return
  704. * because ret_from_except_lite will check for and handle pending
  705. * interrupts if necessary.
  706. */
  707. beq 13f
  708. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  709. BEGIN_FW_FTR_SECTION
  710. /*
  711. * Here we have interrupts hard-disabled, so it is sufficient
  712. * to restore paca->{soft,hard}_enable and get out.
  713. */
  714. beq fast_exc_return_irq /* Return from exception on success */
  715. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  716. /* For a hash failure, we don't bother re-enabling interrupts */
  717. ble- 12f
  718. /*
  719. * hash_page couldn't handle it, set soft interrupt enable back
  720. * to what it was before the trap. Note that .raw_local_irq_restore
  721. * handles any interrupts pending at this point.
  722. */
  723. ld r3,SOFTE(r1)
  724. TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
  725. bl .raw_local_irq_restore
  726. b 11f
  727. /* Here we have a page fault that hash_page can't handle. */
  728. handle_page_fault:
  729. ENABLE_INTS
  730. 11: ld r4,_DAR(r1)
  731. ld r5,_DSISR(r1)
  732. addi r3,r1,STACK_FRAME_OVERHEAD
  733. bl .do_page_fault
  734. cmpdi r3,0
  735. beq+ 13f
  736. bl .save_nvgprs
  737. mr r5,r3
  738. addi r3,r1,STACK_FRAME_OVERHEAD
  739. lwz r4,_DAR(r1)
  740. bl .bad_page_fault
  741. b .ret_from_except
  742. 13: b .ret_from_except_lite
  743. /* We have a page fault that hash_page could handle but HV refused
  744. * the PTE insertion
  745. */
  746. 12: bl .save_nvgprs
  747. mr r5,r3
  748. addi r3,r1,STACK_FRAME_OVERHEAD
  749. ld r4,_DAR(r1)
  750. bl .low_hash_fault
  751. b .ret_from_except
  752. /*
  753. * We come here as a result of a DSI at a point where we don't want
  754. * to call hash_page, such as when we are accessing memory (possibly
  755. * user memory) inside a PMU interrupt that occurred while interrupts
  756. * were soft-disabled. We want to invoke the exception handler for
  757. * the access, or panic if there isn't a handler.
  758. */
  759. 77: bl .save_nvgprs
  760. mr r4,r3
  761. addi r3,r1,STACK_FRAME_OVERHEAD
  762. li r5,SIGSEGV
  763. bl .bad_page_fault
  764. b .ret_from_except
  765. /* here we have a segment miss */
  766. do_ste_alloc:
  767. bl .ste_allocate /* try to insert stab entry */
  768. cmpdi r3,0
  769. bne- handle_page_fault
  770. b fast_exception_return
  771. /*
  772. * r13 points to the PACA, r9 contains the saved CR,
  773. * r11 and r12 contain the saved SRR0 and SRR1.
  774. * r9 - r13 are saved in paca->exslb.
  775. * We assume we aren't going to take any exceptions during this procedure.
  776. * We assume (DAR >> 60) == 0xc.
  777. */
  778. .align 7
  779. _GLOBAL(do_stab_bolted)
  780. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  781. std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
  782. /* Hash to the primary group */
  783. ld r10,PACASTABVIRT(r13)
  784. mfspr r11,SPRN_DAR
  785. srdi r11,r11,28
  786. rldimi r10,r11,7,52 /* r10 = first ste of the group */
  787. /* Calculate VSID */
  788. /* This is a kernel address, so protovsid = ESID */
  789. ASM_VSID_SCRAMBLE(r11, r9, 256M)
  790. rldic r9,r11,12,16 /* r9 = vsid << 12 */
  791. /* Search the primary group for a free entry */
  792. 1: ld r11,0(r10) /* Test valid bit of the current ste */
  793. andi. r11,r11,0x80
  794. beq 2f
  795. addi r10,r10,16
  796. andi. r11,r10,0x70
  797. bne 1b
  798. /* Stick for only searching the primary group for now. */
  799. /* At least for now, we use a very simple random castout scheme */
  800. /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
  801. mftb r11
  802. rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
  803. ori r11,r11,0x10
  804. /* r10 currently points to an ste one past the group of interest */
  805. /* make it point to the randomly selected entry */
  806. subi r10,r10,128
  807. or r10,r10,r11 /* r10 is the entry to invalidate */
  808. isync /* mark the entry invalid */
  809. ld r11,0(r10)
  810. rldicl r11,r11,56,1 /* clear the valid bit */
  811. rotldi r11,r11,8
  812. std r11,0(r10)
  813. sync
  814. clrrdi r11,r11,28 /* Get the esid part of the ste */
  815. slbie r11
  816. 2: std r9,8(r10) /* Store the vsid part of the ste */
  817. eieio
  818. mfspr r11,SPRN_DAR /* Get the new esid */
  819. clrrdi r11,r11,28 /* Permits a full 32b of ESID */
  820. ori r11,r11,0x90 /* Turn on valid and kp */
  821. std r11,0(r10) /* Put new entry back into the stab */
  822. sync
  823. /* All done -- return from exception. */
  824. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  825. ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
  826. andi. r10,r12,MSR_RI
  827. beq- unrecov_slb
  828. mtcrf 0x80,r9 /* restore CR */
  829. mfmsr r10
  830. clrrdi r10,r10,2
  831. mtmsrd r10,1
  832. mtspr SPRN_SRR0,r11
  833. mtspr SPRN_SRR1,r12
  834. ld r9,PACA_EXSLB+EX_R9(r13)
  835. ld r10,PACA_EXSLB+EX_R10(r13)
  836. ld r11,PACA_EXSLB+EX_R11(r13)
  837. ld r12,PACA_EXSLB+EX_R12(r13)
  838. ld r13,PACA_EXSLB+EX_R13(r13)
  839. rfid
  840. b . /* prevent speculative execution */
  841. /*
  842. * Space for CPU0's segment table.
  843. *
  844. * On iSeries, the hypervisor must fill in at least one entry before
  845. * we get control (with relocate on). The address is given to the hv
  846. * as a page number (see xLparMap below), so this must be at a
  847. * fixed address (the linker can't compute (u64)&initial_stab >>
  848. * PAGE_SHIFT).
  849. */
  850. . = STAB0_OFFSET /* 0x6000 */
  851. .globl initial_stab
  852. initial_stab:
  853. .space 4096
  854. #ifdef CONFIG_PPC_PSERIES
  855. /*
  856. * Data area reserved for FWNMI option.
  857. * This address (0x7000) is fixed by the RPA.
  858. */
  859. .= 0x7000
  860. .globl fwnmi_data_area
  861. fwnmi_data_area:
  862. #endif /* CONFIG_PPC_PSERIES */
  863. /* iSeries does not use the FWNMI stuff, so it is safe to put
  864. * this here, even if we later allow kernels that will boot on
  865. * both pSeries and iSeries */
  866. #ifdef CONFIG_PPC_ISERIES
  867. . = LPARMAP_PHYS
  868. .globl xLparMap
  869. xLparMap:
  870. .quad HvEsidsToMap /* xNumberEsids */
  871. .quad HvRangesToMap /* xNumberRanges */
  872. .quad STAB0_PAGE /* xSegmentTableOffs */
  873. .zero 40 /* xRsvd */
  874. /* xEsids (HvEsidsToMap entries of 2 quads) */
  875. .quad PAGE_OFFSET_ESID /* xKernelEsid */
  876. .quad PAGE_OFFSET_VSID /* xKernelVsid */
  877. .quad VMALLOC_START_ESID /* xKernelEsid */
  878. .quad VMALLOC_START_VSID /* xKernelVsid */
  879. /* xRanges (HvRangesToMap entries of 3 quads) */
  880. .quad HvPagesToMap /* xPages */
  881. .quad 0 /* xOffset */
  882. .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
  883. #endif /* CONFIG_PPC_ISERIES */
  884. #ifdef CONFIG_PPC_PSERIES
  885. . = 0x8000
  886. #endif /* CONFIG_PPC_PSERIES */