exception.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #ifndef _ASM_POWERPC_EXCEPTION_H
  2. #define _ASM_POWERPC_EXCEPTION_H
  3. /*
  4. * Extracted from head_64.S
  5. *
  6. * PowerPC version
  7. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  8. *
  9. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  10. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  11. * Adapted for Power Macintosh by Paul Mackerras.
  12. * Low-level exception handlers and MMU support
  13. * rewritten by Paul Mackerras.
  14. * Copyright (C) 1996 Paul Mackerras.
  15. *
  16. * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
  17. * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
  18. *
  19. * This file contains the low-level support and setup for the
  20. * PowerPC-64 platform, including trap and interrupt dispatch.
  21. *
  22. * This program is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU General Public License
  24. * as published by the Free Software Foundation; either version
  25. * 2 of the License, or (at your option) any later version.
  26. */
  27. /*
  28. * The following macros define the code that appears as
  29. * the prologue to each of the exception handlers. They
  30. * are split into two parts to allow a single kernel binary
  31. * to be used for pSeries and iSeries.
  32. *
  33. * We make as much of the exception code common between native
  34. * exception handlers (including pSeries LPAR) and iSeries LPAR
  35. * implementations as possible.
  36. */
  37. #define EX_R9 0
  38. #define EX_R10 8
  39. #define EX_R11 16
  40. #define EX_R12 24
  41. #define EX_R13 32
  42. #define EX_SRR0 40
  43. #define EX_DAR 48
  44. #define EX_DSISR 56
  45. #define EX_CCR 60
  46. #define EX_R3 64
  47. #define EX_LR 72
  48. /*
  49. * We're short on space and time in the exception prolog, so we can't
  50. * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
  51. * low halfword of the address, but for Kdump we need the whole low
  52. * word.
  53. */
  54. #ifdef CONFIG_CRASH_DUMP
  55. #define LOAD_HANDLER(reg, label) \
  56. oris reg,reg,(label)@h; /* virt addr of handler ... */ \
  57. ori reg,reg,(label)@l; /* .. and the rest */
  58. #else
  59. #define LOAD_HANDLER(reg, label) \
  60. ori reg,reg,(label)@l; /* virt addr of handler ... */
  61. #endif
  62. #define EXCEPTION_PROLOG_1(area) \
  63. mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
  64. std r9,area+EX_R9(r13); /* save r9 - r12 */ \
  65. std r10,area+EX_R10(r13); \
  66. std r11,area+EX_R11(r13); \
  67. std r12,area+EX_R12(r13); \
  68. mfspr r9,SPRN_SPRG1; \
  69. std r9,area+EX_R13(r13); \
  70. mfcr r9
  71. /*
  72. * Equal to EXCEPTION_PROLOG_PSERIES, except that it forces 64bit mode.
  73. * The firmware calls the registered system_reset_fwnmi and
  74. * machine_check_fwnmi handlers in 32bit mode if the cpu happens to run
  75. * a 32bit application at the time of the event.
  76. * This firmware bug is present on POWER4 and JS20.
  77. */
  78. #define EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(area, label) \
  79. EXCEPTION_PROLOG_1(area); \
  80. clrrdi r12,r13,32; /* get high part of &label */ \
  81. mfmsr r10; \
  82. /* force 64bit mode */ \
  83. li r11,5; /* MSR_SF_LG|MSR_ISF_LG */ \
  84. rldimi r10,r11,61,0; /* insert into top 3 bits */ \
  85. /* done 64bit mode */ \
  86. mfspr r11,SPRN_SRR0; /* save SRR0 */ \
  87. LOAD_HANDLER(r12,label) \
  88. ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
  89. mtspr SPRN_SRR0,r12; \
  90. mfspr r12,SPRN_SRR1; /* and SRR1 */ \
  91. mtspr SPRN_SRR1,r10; \
  92. rfid; \
  93. b . /* prevent speculative execution */
  94. #define EXCEPTION_PROLOG_PSERIES(area, label) \
  95. EXCEPTION_PROLOG_1(area); \
  96. clrrdi r12,r13,32; /* get high part of &label */ \
  97. mfmsr r10; \
  98. mfspr r11,SPRN_SRR0; /* save SRR0 */ \
  99. LOAD_HANDLER(r12,label) \
  100. ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
  101. mtspr SPRN_SRR0,r12; \
  102. mfspr r12,SPRN_SRR1; /* and SRR1 */ \
  103. mtspr SPRN_SRR1,r10; \
  104. rfid; \
  105. b . /* prevent speculative execution */
  106. /*
  107. * The common exception prolog is used for all except a few exceptions
  108. * such as a segment miss on a kernel address. We have to be prepared
  109. * to take another exception from the point where we first touch the
  110. * kernel stack onwards.
  111. *
  112. * On entry r13 points to the paca, r9-r13 are saved in the paca,
  113. * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
  114. * SRR1, and relocation is on.
  115. */
  116. #define EXCEPTION_PROLOG_COMMON(n, area) \
  117. andi. r10,r12,MSR_PR; /* See if coming from user */ \
  118. mr r10,r1; /* Save r1 */ \
  119. subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
  120. beq- 1f; \
  121. ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
  122. 1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \
  123. bge- cr1,2f; /* abort if it is */ \
  124. b 3f; \
  125. 2: li r1,(n); /* will be reloaded later */ \
  126. sth r1,PACA_TRAP_SAVE(r13); \
  127. b bad_stack; \
  128. 3: std r9,_CCR(r1); /* save CR in stackframe */ \
  129. std r11,_NIP(r1); /* save SRR0 in stackframe */ \
  130. std r12,_MSR(r1); /* save SRR1 in stackframe */ \
  131. std r10,0(r1); /* make stack chain pointer */ \
  132. std r0,GPR0(r1); /* save r0 in stackframe */ \
  133. std r10,GPR1(r1); /* save r1 in stackframe */ \
  134. ACCOUNT_CPU_USER_ENTRY(r9, r10); \
  135. std r2,GPR2(r1); /* save r2 in stackframe */ \
  136. SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
  137. SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
  138. ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
  139. ld r10,area+EX_R10(r13); \
  140. std r9,GPR9(r1); \
  141. std r10,GPR10(r1); \
  142. ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
  143. ld r10,area+EX_R12(r13); \
  144. ld r11,area+EX_R13(r13); \
  145. std r9,GPR11(r1); \
  146. std r10,GPR12(r1); \
  147. std r11,GPR13(r1); \
  148. ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
  149. mflr r9; /* save LR in stackframe */ \
  150. std r9,_LINK(r1); \
  151. mfctr r10; /* save CTR in stackframe */ \
  152. std r10,_CTR(r1); \
  153. lbz r10,PACASOFTIRQEN(r13); \
  154. mfspr r11,SPRN_XER; /* save XER in stackframe */ \
  155. std r10,SOFTE(r1); \
  156. std r11,_XER(r1); \
  157. li r9,(n)+1; \
  158. std r9,_TRAP(r1); /* set trap number */ \
  159. li r10,0; \
  160. ld r11,exception_marker@toc(r2); \
  161. std r10,RESULT(r1); /* clear regs->result */ \
  162. std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
  163. /*
  164. * Exception vectors.
  165. */
  166. #define STD_EXCEPTION_PSERIES(n, label) \
  167. . = n; \
  168. .globl label##_pSeries; \
  169. label##_pSeries: \
  170. HMT_MEDIUM; \
  171. mtspr SPRN_SPRG1,r13; /* save r13 */ \
  172. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
  173. #define HSTD_EXCEPTION_PSERIES(n, label) \
  174. . = n; \
  175. .globl label##_pSeries; \
  176. label##_pSeries: \
  177. HMT_MEDIUM; \
  178. mtspr SPRN_SPRG1,r20; /* save r20 */ \
  179. mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \
  180. mtspr SPRN_SRR0,r20; \
  181. mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \
  182. mtspr SPRN_SRR1,r20; \
  183. mfspr r20,SPRN_SPRG1; /* restore r20 */ \
  184. mtspr SPRN_SPRG1,r13; /* save r13 */ \
  185. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
  186. #define MASKABLE_EXCEPTION_PSERIES(n, label) \
  187. . = n; \
  188. .globl label##_pSeries; \
  189. label##_pSeries: \
  190. HMT_MEDIUM; \
  191. mtspr SPRN_SPRG1,r13; /* save r13 */ \
  192. mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \
  193. std r9,PACA_EXGEN+EX_R9(r13); /* save r9, r10 */ \
  194. std r10,PACA_EXGEN+EX_R10(r13); \
  195. lbz r10,PACASOFTIRQEN(r13); \
  196. mfcr r9; \
  197. cmpwi r10,0; \
  198. beq masked_interrupt; \
  199. mfspr r10,SPRN_SPRG1; \
  200. std r10,PACA_EXGEN+EX_R13(r13); \
  201. std r11,PACA_EXGEN+EX_R11(r13); \
  202. std r12,PACA_EXGEN+EX_R12(r13); \
  203. clrrdi r12,r13,32; /* get high part of &label */ \
  204. mfmsr r10; \
  205. mfspr r11,SPRN_SRR0; /* save SRR0 */ \
  206. LOAD_HANDLER(r12,label##_common) \
  207. ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \
  208. mtspr SPRN_SRR0,r12; \
  209. mfspr r12,SPRN_SRR1; /* and SRR1 */ \
  210. mtspr SPRN_SRR1,r10; \
  211. rfid; \
  212. b . /* prevent speculative execution */
  213. #ifdef CONFIG_PPC_ISERIES
  214. #define DISABLE_INTS \
  215. li r11,0; \
  216. stb r11,PACASOFTIRQEN(r13); \
  217. BEGIN_FW_FTR_SECTION; \
  218. stb r11,PACAHARDIRQEN(r13); \
  219. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES); \
  220. BEGIN_FW_FTR_SECTION; \
  221. mfmsr r10; \
  222. ori r10,r10,MSR_EE; \
  223. mtmsrd r10,1; \
  224. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  225. #else
  226. #define DISABLE_INTS \
  227. li r11,0; \
  228. stb r11,PACASOFTIRQEN(r13); \
  229. stb r11,PACAHARDIRQEN(r13)
  230. #endif /* CONFIG_PPC_ISERIES */
  231. #define ENABLE_INTS \
  232. ld r12,_MSR(r1); \
  233. mfmsr r11; \
  234. rlwimi r11,r12,0,MSR_EE; \
  235. mtmsrd r11,1
  236. #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
  237. .align 7; \
  238. .globl label##_common; \
  239. label##_common: \
  240. EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
  241. DISABLE_INTS; \
  242. bl .save_nvgprs; \
  243. addi r3,r1,STACK_FRAME_OVERHEAD; \
  244. bl hdlr; \
  245. b .ret_from_except
  246. /*
  247. * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
  248. * in the idle task and therefore need the special idle handling.
  249. */
  250. #define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \
  251. .align 7; \
  252. .globl label##_common; \
  253. label##_common: \
  254. EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
  255. FINISH_NAP; \
  256. DISABLE_INTS; \
  257. bl .save_nvgprs; \
  258. addi r3,r1,STACK_FRAME_OVERHEAD; \
  259. bl hdlr; \
  260. b .ret_from_except
  261. #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \
  262. .align 7; \
  263. .globl label##_common; \
  264. label##_common: \
  265. EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
  266. FINISH_NAP; \
  267. DISABLE_INTS; \
  268. BEGIN_FTR_SECTION \
  269. bl .ppc64_runlatch_on; \
  270. END_FTR_SECTION_IFSET(CPU_FTR_CTRL) \
  271. addi r3,r1,STACK_FRAME_OVERHEAD; \
  272. bl hdlr; \
  273. b .ret_from_except_lite
  274. /*
  275. * When the idle code in power4_idle puts the CPU into NAP mode,
  276. * it has to do so in a loop, and relies on the external interrupt
  277. * and decrementer interrupt entry code to get it out of the loop.
  278. * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
  279. * to signal that it is in the loop and needs help to get out.
  280. */
  281. #ifdef CONFIG_PPC_970_NAP
  282. #define FINISH_NAP \
  283. BEGIN_FTR_SECTION \
  284. clrrdi r11,r1,THREAD_SHIFT; \
  285. ld r9,TI_LOCAL_FLAGS(r11); \
  286. andi. r10,r9,_TLF_NAPPING; \
  287. bnel power4_fixup_nap; \
  288. END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
  289. #else
  290. #define FINISH_NAP
  291. #endif
  292. #endif /* _ASM_POWERPC_EXCEPTION_H */