blob: a02a268bde6bf0f9a271567f430c70b56cfb4cca [file] [log] [blame]
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +10001#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 */
Michael Ellermanda2bc462016-09-30 19:43:18 +100037#include <asm/head-64.h>
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +100038
39#define EX_R9 0
40#define EX_R10 8
41#define EX_R11 16
42#define EX_R12 24
43#define EX_R13 32
44#define EX_SRR0 40
45#define EX_DAR 48
46#define EX_DSISR 56
47#define EX_CCR 60
48#define EX_R3 64
49#define EX_LR 72
Paul Mackerras48404f22011-05-01 19:48:20 +000050#define EX_CFAR 80
Haren Mynenia09688c2012-12-06 21:48:26 +000051#define EX_PPR 88 /* SMT thread status register (priority) */
Michael Neulingbc2e6c62013-08-13 15:54:52 +100052#define EX_CTR 96
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +100053
Michael Neuling4700dfa2012-11-02 17:21:28 +110054#ifdef CONFIG_RELOCATABLE
Paul Mackerras1707dd12013-02-04 18:10:15 +000055#define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
Michael Neuling4700dfa2012-11-02 17:21:28 +110056 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
57 LOAD_HANDLER(r12,label); \
Michael Neulingbc2e6c62013-08-13 15:54:52 +100058 mtctr r12; \
Michael Neuling4700dfa2012-11-02 17:21:28 +110059 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
60 li r10,MSR_RI; \
61 mtmsrd r10,1; /* Set RI (EE=0) */ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +100062 bctr;
Michael Neuling4700dfa2012-11-02 17:21:28 +110063#else
64/* If not relocatable, we can jump directly -- and save messing with LR */
Paul Mackerras1707dd12013-02-04 18:10:15 +000065#define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
Michael Neuling4700dfa2012-11-02 17:21:28 +110066 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
67 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
68 li r10,MSR_RI; \
69 mtmsrd r10,1; /* Set RI (EE=0) */ \
70 b label;
71#endif
Paul Mackerras1707dd12013-02-04 18:10:15 +000072#define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
73 __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
Michael Neuling4700dfa2012-11-02 17:21:28 +110074
75/*
76 * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on
77 * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which
78 * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr.
79 */
80#define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \
Paul Mackerras1707dd12013-02-04 18:10:15 +000081 EXCEPTION_PROLOG_0(area); \
Michael Neuling4700dfa2012-11-02 17:21:28 +110082 EXCEPTION_PROLOG_1(area, extra, vec); \
83 EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
84
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +100085/*
86 * We're short on space and time in the exception prolog, so we can't
Michael Ellerman27510232016-07-26 15:29:29 +100087 * use the normal LOAD_REG_IMMEDIATE macro to load the address of label.
88 * Instead we get the base of the kernel from paca->kernelbase and or in the low
89 * part of label. This requires that the label be within 64KB of kernelbase, and
90 * that kernelbase be 64K aligned.
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +100091 */
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +100092#define LOAD_HANDLER(reg, label) \
Michael Ellermand8d42b02016-07-26 15:29:30 +100093 ld reg,PACAKBASE(r13); /* get high part of &label */ \
Hugh Dickinse6740ae2016-11-07 22:28:21 -080094 ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label);
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +100095
Nicholas Pigginfb479e42016-10-13 13:17:14 +110096#define __LOAD_HANDLER(reg, label) \
97 ld reg,PACAKBASE(r13); \
98 ori reg,reg,(ABS_ADDR(label))@l;
99
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000100/* Exception register prefixes */
101#define EXC_HV H
102#define EXC_STD
103
Michael Neuling4700dfa2012-11-02 17:21:28 +1100104#if defined(CONFIG_RELOCATABLE)
105/*
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000106 * If we support interrupts with relocation on AND we're a relocatable kernel,
107 * we need to use CTR to get to the 2nd level handler. So, save/restore it
108 * when required.
Michael Neuling4700dfa2012-11-02 17:21:28 +1100109 */
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000110#define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13)
111#define GET_CTR(reg, area) ld reg,area+EX_CTR(r13)
112#define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg
Michael Neuling4700dfa2012-11-02 17:21:28 +1100113#else
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000114/* ...else CTR is unused and in register. */
115#define SAVE_CTR(reg, area)
116#define GET_CTR(reg, area) mfctr reg
117#define RESTORE_CTR(reg, area)
Michael Neuling4700dfa2012-11-02 17:21:28 +1100118#endif
119
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000120/*
121 * PPR save/restore macros used in exceptions_64s.S
122 * Used for P7 or later processors
123 */
124#define SAVE_PPR(area, ra, rb) \
125BEGIN_FTR_SECTION_NESTED(940) \
126 ld ra,PACACURRENT(r13); \
127 ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \
128 std rb,TASKTHREADPPR(ra); \
129END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940)
130
131#define RESTORE_PPR_PACA(area, ra) \
132BEGIN_FTR_SECTION_NESTED(941) \
133 ld ra,area+EX_PPR(r13); \
134 mtspr SPRN_PPR,ra; \
135END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941)
136
137/*
Paul Mackerras1707dd12013-02-04 18:10:15 +0000138 * Get an SPR into a register if the CPU has the given feature
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000139 */
Paul Mackerras1707dd12013-02-04 18:10:15 +0000140#define OPT_GET_SPR(ra, spr, ftr) \
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000141BEGIN_FTR_SECTION_NESTED(943) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000142 mfspr ra,spr; \
143END_FTR_SECTION_NESTED(ftr,ftr,943)
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000144
Paul Mackerras1707dd12013-02-04 18:10:15 +0000145/*
Mahesh Salgaonkard410ae22014-03-11 10:56:18 +0530146 * Set an SPR from a register if the CPU has the given feature
147 */
148#define OPT_SET_SPR(ra, spr, ftr) \
149BEGIN_FTR_SECTION_NESTED(943) \
150 mtspr spr,ra; \
151END_FTR_SECTION_NESTED(ftr,ftr,943)
152
153/*
Paul Mackerras1707dd12013-02-04 18:10:15 +0000154 * Save a register to the PACA if the CPU has the given feature
155 */
156#define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \
157BEGIN_FTR_SECTION_NESTED(943) \
158 std ra,offset(r13); \
159END_FTR_SECTION_NESTED(ftr,ftr,943)
160
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100161#define EXCEPTION_PROLOG_0_PACA(area) \
Haren Myneni44e93092012-12-06 21:51:04 +0000162 std r9,area+EX_R9(r13); /* save r9 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000163 OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \
164 HMT_MEDIUM; \
Haren Myneni44e93092012-12-06 21:51:04 +0000165 std r10,area+EX_R10(r13); /* save r10 - r12 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000166 OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR)
167
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100168#define EXCEPTION_PROLOG_0(area) \
169 GET_PACA(r13); \
170 EXCEPTION_PROLOG_0_PACA(area)
171
Paul Mackerras1707dd12013-02-04 18:10:15 +0000172#define __EXCEPTION_PROLOG_1(area, extra, vec) \
173 OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \
174 OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000175 SAVE_CTR(r10, area); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000176 mfcr r9; \
177 extra(vec); \
178 std r11,area+EX_R11(r13); \
179 std r12,area+EX_R12(r13); \
180 GET_SCRATCH0(r10); \
181 std r10,area+EX_R13(r13)
182#define EXCEPTION_PROLOG_1(area, extra, vec) \
183 __EXCEPTION_PROLOG_1(area, extra, vec)
Stephen Rothwell7180e3e2007-08-22 13:48:37 +1000184
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000185#define __EXCEPTION_PROLOG_PSERIES_1(label, h) \
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000186 ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000187 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000188 LOAD_HANDLER(r12,label) \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000189 mtspr SPRN_##h##SRR0,r12; \
190 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
191 mtspr SPRN_##h##SRR1,r10; \
192 h##rfid; \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000193 b . /* prevent speculative execution */
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000194#define EXCEPTION_PROLOG_PSERIES_1(label, h) \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000195 __EXCEPTION_PROLOG_PSERIES_1(label, h)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000196
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000197#define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000198 EXCEPTION_PROLOG_0(area); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000199 EXCEPTION_PROLOG_1(area, extra, vec); \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000200 EXCEPTION_PROLOG_PSERIES_1(label, h);
Benjamin Herrenschmidtc5a8c0c2009-07-16 19:36:57 +0000201
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100202/* Have the PACA in r13 already */
203#define EXCEPTION_PROLOG_PSERIES_PACA(area, label, h, extra, vec) \
204 EXCEPTION_PROLOG_0_PACA(area); \
205 EXCEPTION_PROLOG_1(area, extra, vec); \
206 EXCEPTION_PROLOG_PSERIES_1(label, h);
207
Michael Ellermanda2bc462016-09-30 19:43:18 +1000208#define __KVMTEST(h, n) \
209 lbz r10,HSTATE_IN_GUEST(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000210 cmpwi r10,0; \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000211 bne do_kvm_##h##n
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000212
Aneesh Kumar K.Vdd96b2c2013-10-07 22:17:55 +0530213#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
214/*
215 * If hv is possible, interrupts come into to the hv version
216 * of the kvmppc_interrupt code, which then jumps to the PR handler,
217 * kvmppc_interrupt_pr, if the guest is a PR guest.
218 */
219#define kvmppc_interrupt kvmppc_interrupt_hv
220#else
221#define kvmppc_interrupt kvmppc_interrupt_pr
222#endif
223
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100224#ifdef CONFIG_RELOCATABLE
225#define BRANCH_TO_COMMON(reg, label) \
226 __LOAD_HANDLER(reg, label); \
227 mtctr reg; \
228 bctr
229
230#else
231#define BRANCH_TO_COMMON(reg, label) \
232 b label
233
234#endif
235
Nicholas Piggind3918e72016-12-22 04:29:25 +1000236#define __KVM_HANDLER(area, h, n) \
Paul Mackerras0acb9112013-02-04 18:10:51 +0000237 BEGIN_FTR_SECTION_NESTED(947) \
238 ld r10,area+EX_CFAR(r13); \
239 std r10,HSTATE_CFAR(r13); \
240 END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947); \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000241 BEGIN_FTR_SECTION_NESTED(948) \
242 ld r10,area+EX_PPR(r13); \
243 std r10,HSTATE_PPR(r13); \
244 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000245 ld r10,area+EX_R10(r13); \
Paul Mackerras0acb9112013-02-04 18:10:51 +0000246 std r12,HSTATE_SCRATCH0(r13); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000247 sldi r12,r9,32; \
248 ori r12,r12,(n); \
249 ld r9,area+EX_R9(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000250 b kvmppc_interrupt
251
252#define __KVM_HANDLER_SKIP(area, h, n) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000253 cmpwi r10,KVM_GUEST_MODE_SKIP; \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000254 beq 89f; \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000255 BEGIN_FTR_SECTION_NESTED(948) \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000256 ld r10,area+EX_PPR(r13); \
257 std r10,HSTATE_PPR(r13); \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000258 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000259 ld r10,area+EX_R10(r13); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000260 std r12,HSTATE_SCRATCH0(r13); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000261 sldi r12,r9,32; \
262 ori r12,r12,(n); \
263 ld r9,area+EX_R9(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000264 b kvmppc_interrupt; \
26589: mtocrf 0x80,r9; \
266 ld r9,area+EX_R9(r13); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000267 ld r10,area+EX_R10(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000268 b kvmppc_skip_##h##interrupt
269
270#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
Michael Ellermanda2bc462016-09-30 19:43:18 +1000271#define KVMTEST(h, n) __KVMTEST(h, n)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000272#define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n)
273#define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n)
274
275#else
Michael Ellermanda2bc462016-09-30 19:43:18 +1000276#define KVMTEST(h, n)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000277#define KVM_HANDLER(area, h, n)
278#define KVM_HANDLER_SKIP(area, h, n)
279#endif
280
281#define NOTEST(n)
282
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000283/*
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000284 * The common exception prolog is used for all except a few exceptions
285 * such as a segment miss on a kernel address. We have to be prepared
286 * to take another exception from the point where we first touch the
287 * kernel stack onwards.
288 *
289 * On entry r13 points to the paca, r9-r13 are saved in the paca,
290 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
291 * SRR1, and relocation is on.
292 */
293#define EXCEPTION_PROLOG_COMMON(n, area) \
294 andi. r10,r12,MSR_PR; /* See if coming from user */ \
295 mr r10,r1; /* Save r1 */ \
296 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
297 beq- 1f; \
298 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
Michael Neuling90ff5d62013-12-16 15:12:43 +11002991: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \
Paul Mackerras1977b502011-05-01 19:46:44 +0000300 blt+ cr1,3f; /* abort if it is */ \
301 li r1,(n); /* will be reloaded later */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000302 sth r1,PACA_TRAP_SAVE(r13); \
Paul Mackerras1977b502011-05-01 19:46:44 +0000303 std r3,area+EX_R3(r13); \
304 addi r3,r13,area; /* r3 -> where regs are saved*/ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000305 RESTORE_CTR(r1, area); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000306 b bad_stack; \
3073: std r9,_CCR(r1); /* save CR in stackframe */ \
308 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
309 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
310 std r10,0(r1); /* make stack chain pointer */ \
311 std r0,GPR0(r1); /* save r0 in stackframe */ \
312 std r10,GPR1(r1); /* save r1 in stackframe */ \
Haren Myneni5d75b262012-12-06 21:46:37 +0000313 beq 4f; /* if from kernel mode */ \
Christophe Leroyc223c902016-05-17 08:33:46 +0200314 ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \
Haren Myneni44e93092012-12-06 21:51:04 +0000315 SAVE_PPR(area, r9, r10); \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +05303164: EXCEPTION_PROLOG_COMMON_2(area) \
317 EXCEPTION_PROLOG_COMMON_3(n) \
318 ACCOUNT_STOLEN_TIME
319
320/* Save original regs values from save area to stack frame. */
321#define EXCEPTION_PROLOG_COMMON_2(area) \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000322 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
323 ld r10,area+EX_R10(r13); \
324 std r9,GPR9(r1); \
325 std r10,GPR10(r1); \
326 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
327 ld r10,area+EX_R12(r13); \
328 ld r11,area+EX_R13(r13); \
329 std r9,GPR11(r1); \
330 std r10,GPR12(r1); \
331 std r11,GPR13(r1); \
Paul Mackerras48404f22011-05-01 19:48:20 +0000332 BEGIN_FTR_SECTION_NESTED(66); \
333 ld r10,area+EX_CFAR(r13); \
334 std r10,ORIG_GPR3(r1); \
335 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +0530336 GET_CTR(r10, area); \
337 std r10,_CTR(r1);
338
339#define EXCEPTION_PROLOG_COMMON_3(n) \
340 std r2,GPR2(r1); /* save r2 in stackframe */ \
341 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
342 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000343 mflr r9; /* Get LR, later save to stack */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000344 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000345 std r9,_LINK(r1); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000346 lbz r10,PACASOFTIRQEN(r13); \
347 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
348 std r10,SOFTE(r1); \
349 std r11,_XER(r1); \
350 li r9,(n)+1; \
351 std r9,_TRAP(r1); /* set trap number */ \
352 li r10,0; \
353 ld r11,exception_marker@toc(r2); \
354 std r10,RESULT(r1); /* clear regs->result */ \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +0530355 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000356
357/*
358 * Exception vectors.
359 */
Michael Ellermanda2bc462016-09-30 19:43:18 +1000360#define STD_EXCEPTION_PSERIES(vec, label) \
Paul Mackerras673b1892011-04-05 13:59:58 +1000361 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000362 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
363 EXC_STD, KVMTEST_PR, vec); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000364
Paul Mackerras1707dd12013-02-04 18:10:15 +0000365/* Version of above for when we have to branch out-of-line */
Michael Ellermanda2bc462016-09-30 19:43:18 +1000366#define __OOL_EXCEPTION(vec, label, hdlr) \
367 SET_SCRATCH0(r13) \
368 EXCEPTION_PROLOG_0(PACA_EXGEN) \
369 b hdlr;
370
Paul Mackerras1707dd12013-02-04 18:10:15 +0000371#define STD_EXCEPTION_PSERIES_OOL(vec, label) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000372 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \
373 EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000374
Michael Ellermanda2bc462016-09-30 19:43:18 +1000375#define STD_EXCEPTION_HV(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000376 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000377 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
378 EXC_HV, KVMTEST_HV, vec);
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000379
Michael Ellermanda2bc462016-09-30 19:43:18 +1000380#define STD_EXCEPTION_HV_OOL(vec, label) \
381 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \
382 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000383
Michael Neuling4700dfa2012-11-02 17:21:28 +1100384#define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100385 /* No guest interrupts come through here */ \
386 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000387 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_STD, NOTEST, vec);
Michael Neuling4700dfa2012-11-02 17:21:28 +1100388
Paul Mackerras1707dd12013-02-04 18:10:15 +0000389#define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label) \
Michael Ellermanc9f69512013-06-25 17:47:55 +1000390 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000391 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_STD)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000392
Michael Neuling4700dfa2012-11-02 17:21:28 +1100393#define STD_RELON_EXCEPTION_HV(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100394 /* No guest interrupts come through here */ \
395 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000396 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_HV, NOTEST, vec);
Michael Neuling4700dfa2012-11-02 17:21:28 +1100397
Paul Mackerras1707dd12013-02-04 18:10:15 +0000398#define STD_RELON_EXCEPTION_HV_OOL(vec, label) \
Michael Ellermanc9f69512013-06-25 17:47:55 +1000399 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000400 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000401
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100402/* This associate vector numbers with bits in paca->irq_happened */
403#define SOFTEN_VALUE_0x500 PACA_IRQ_EE
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100404#define SOFTEN_VALUE_0x900 PACA_IRQ_DEC
Michael Ellermanda2bc462016-09-30 19:43:18 +1000405#define SOFTEN_VALUE_0x980 PACA_IRQ_DEC
Ian Munsie1dbdafe2012-11-14 18:49:46 +0000406#define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL
Ian Munsie655bb3f2012-11-14 18:49:45 +0000407#define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +0530408#define SOFTEN_VALUE_0xe60 PACA_IRQ_HMI
Benjamin Herrenschmidt9baaef0a2016-07-08 16:37:06 +1000409#define SOFTEN_VALUE_0xea0 PACA_IRQ_EE
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100410
411#define __SOFTEN_TEST(h, vec) \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000412 lbz r10,PACASOFTIRQEN(r13); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000413 cmpwi r10,0; \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100414 li r10,SOFTEN_VALUE_##vec; \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000415 beq masked_##h##interrupt
Michael Ellermanda2bc462016-09-30 19:43:18 +1000416
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100417#define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000418
Paul Mackerrasde56a942011-06-29 00:21:34 +0000419#define SOFTEN_TEST_PR(vec) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000420 KVMTEST(EXC_STD, vec); \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100421 _SOFTEN_TEST(EXC_STD, vec)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000422
423#define SOFTEN_TEST_HV(vec) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000424 KVMTEST(EXC_HV, vec); \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100425 _SOFTEN_TEST(EXC_HV, vec)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000426
Michael Ellermanda2bc462016-09-30 19:43:18 +1000427#define KVMTEST_PR(vec) \
428 KVMTEST(EXC_STD, vec)
429
430#define KVMTEST_HV(vec) \
431 KVMTEST(EXC_HV, vec)
432
Michael Neuling4700dfa2012-11-02 17:21:28 +1100433#define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec)
434#define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec)
435
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000436#define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000437 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000438 EXCEPTION_PROLOG_0(PACA_EXGEN); \
439 __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000440 EXCEPTION_PROLOG_PSERIES_1(label, h);
Paul Mackerras1707dd12013-02-04 18:10:15 +0000441
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000442#define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \
443 __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000444
445#define MASKABLE_EXCEPTION_PSERIES(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000446 _MASKABLE_EXCEPTION_PSERIES(vec, label, \
Paul Mackerrasde56a942011-06-29 00:21:34 +0000447 EXC_STD, SOFTEN_TEST_PR)
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000448
Michael Ellermanda2bc462016-09-30 19:43:18 +1000449#define MASKABLE_EXCEPTION_PSERIES_OOL(vec, label) \
450 EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec); \
451 EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
452
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000453#define MASKABLE_EXCEPTION_HV(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000454 _MASKABLE_EXCEPTION_PSERIES(vec, label, \
455 EXC_HV, SOFTEN_TEST_HV)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000456
Paul Mackerras1707dd12013-02-04 18:10:15 +0000457#define MASKABLE_EXCEPTION_HV_OOL(vec, label) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000458 EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000459 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000460
Michael Neuling4700dfa2012-11-02 17:21:28 +1100461#define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100462 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000463 EXCEPTION_PROLOG_0(PACA_EXGEN); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000464 __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \
465 EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
466
467#define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100468 __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)
469
470#define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100471 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
472 EXC_STD, SOFTEN_NOTEST_PR)
473
474#define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100475 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
476 EXC_HV, SOFTEN_NOTEST_HV)
477
Paul Mackerras1707dd12013-02-04 18:10:15 +0000478#define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000479 EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_NOTEST_HV, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000480 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000481
Benjamin Herrenschmidt1b701172012-03-01 15:42:56 +1100482/*
483 * Our exception common code can be passed various "additions"
484 * to specify the behaviour of interrupts, whether to kick the
485 * runlatch, etc...
486 */
487
Michael Ellerman9daf1122014-07-15 21:15:38 +1000488/*
489 * This addition reconciles our actual IRQ state with the various software
490 * flags that track it. This may call C code.
491 */
492#define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000493
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100494#define ADD_NVGPRS \
Anton Blanchardb1576fe2014-02-04 16:04:35 +1100495 bl save_nvgprs
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100496
497#define RUNLATCH_ON \
498BEGIN_FTR_SECTION \
Stuart Yoder9778b692012-07-05 04:41:35 +0000499 CURRENT_THREAD_INFO(r3, r1); \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100500 ld r4,TI_LOCAL_FLAGS(r3); \
501 andi. r0,r4,_TLF_RUNLATCH; \
502 beql ppc64_runlatch_on_trampoline; \
503END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
504
505#define EXCEPTION_COMMON(trap, label, hdlr, ret, additions) \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100506 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
Michael Ellermana1d711c2014-07-15 21:15:37 +1000507 /* Volatile regs are potentially clobbered here */ \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100508 additions; \
509 addi r3,r1,STACK_FRAME_OVERHEAD; \
510 bl hdlr; \
511 b ret
512
513#define STD_EXCEPTION_COMMON(trap, label, hdlr) \
514 EXCEPTION_COMMON(trap, label, hdlr, ret_from_except, \
Michael Ellerman9daf1122014-07-15 21:15:38 +1000515 ADD_NVGPRS;ADD_RECONCILE)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000516
517/*
518 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
Benjamin Herrenschmidt7450f6f2012-03-01 10:52:01 +1100519 * in the idle task and therefore need the special idle handling
520 * (finish nap and runlatch)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000521 */
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100522#define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \
523 EXCEPTION_COMMON(trap, label, hdlr, ret_from_except_lite, \
Michael Ellerman9daf1122014-07-15 21:15:38 +1000524 FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000525
526/*
527 * When the idle code in power4_idle puts the CPU into NAP mode,
528 * it has to do so in a loop, and relies on the external interrupt
529 * and decrementer interrupt entry code to get it out of the loop.
530 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
531 * to signal that it is in the loop and needs help to get out.
532 */
533#ifdef CONFIG_PPC_970_NAP
534#define FINISH_NAP \
535BEGIN_FTR_SECTION \
Stuart Yoder9778b692012-07-05 04:41:35 +0000536 CURRENT_THREAD_INFO(r11, r1); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000537 ld r9,TI_LOCAL_FLAGS(r11); \
538 andi. r10,r9,_TLF_NAPPING; \
539 bnel power4_fixup_nap; \
540END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
541#else
542#define FINISH_NAP
543#endif
544
545#endif /* _ASM_POWERPC_EXCEPTION_H */