blob: 9a3eee66129766d84d8bd5063fd8ecd142e8fc21 [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
Michael Ellermanda2bc462016-09-30 19:43:18 +1000236#define __KVM_HANDLER_PROLOG(area, 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 stw r9,HSTATE_SCRATCH1(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000247 ld r9,area+EX_R9(r13); \
Paul Mackerras0acb9112013-02-04 18:10:51 +0000248 std r12,HSTATE_SCRATCH0(r13); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000249
250#define __KVM_HANDLER(area, h, n) \
251 __KVM_HANDLER_PROLOG(area, n) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000252 li r12,n; \
253 b kvmppc_interrupt
254
255#define __KVM_HANDLER_SKIP(area, h, n) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000256 cmpwi r10,KVM_GUEST_MODE_SKIP; \
257 ld r10,area+EX_R10(r13); \
258 beq 89f; \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000259 stw r9,HSTATE_SCRATCH1(r13); \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000260 BEGIN_FTR_SECTION_NESTED(948) \
261 ld r9,area+EX_PPR(r13); \
262 std r9,HSTATE_PPR(r13); \
263 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000264 ld r9,area+EX_R9(r13); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000265 std r12,HSTATE_SCRATCH0(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000266 li r12,n; \
267 b kvmppc_interrupt; \
26889: mtocrf 0x80,r9; \
269 ld r9,area+EX_R9(r13); \
270 b kvmppc_skip_##h##interrupt
271
272#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
Michael Ellermanda2bc462016-09-30 19:43:18 +1000273#define KVMTEST(h, n) __KVMTEST(h, n)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000274#define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n)
275#define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n)
276
277#else
Michael Ellermanda2bc462016-09-30 19:43:18 +1000278#define KVMTEST(h, n)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000279#define KVM_HANDLER(area, h, n)
280#define KVM_HANDLER_SKIP(area, h, n)
281#endif
282
283#define NOTEST(n)
284
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000285/*
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000286 * The common exception prolog is used for all except a few exceptions
287 * such as a segment miss on a kernel address. We have to be prepared
288 * to take another exception from the point where we first touch the
289 * kernel stack onwards.
290 *
291 * On entry r13 points to the paca, r9-r13 are saved in the paca,
292 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
293 * SRR1, and relocation is on.
294 */
295#define EXCEPTION_PROLOG_COMMON(n, area) \
296 andi. r10,r12,MSR_PR; /* See if coming from user */ \
297 mr r10,r1; /* Save r1 */ \
298 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
299 beq- 1f; \
300 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
Michael Neuling90ff5d62013-12-16 15:12:43 +11003011: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \
Paul Mackerras1977b502011-05-01 19:46:44 +0000302 blt+ cr1,3f; /* abort if it is */ \
303 li r1,(n); /* will be reloaded later */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000304 sth r1,PACA_TRAP_SAVE(r13); \
Paul Mackerras1977b502011-05-01 19:46:44 +0000305 std r3,area+EX_R3(r13); \
306 addi r3,r13,area; /* r3 -> where regs are saved*/ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000307 RESTORE_CTR(r1, area); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000308 b bad_stack; \
3093: std r9,_CCR(r1); /* save CR in stackframe */ \
310 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
311 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
312 std r10,0(r1); /* make stack chain pointer */ \
313 std r0,GPR0(r1); /* save r0 in stackframe */ \
314 std r10,GPR1(r1); /* save r1 in stackframe */ \
Haren Myneni5d75b262012-12-06 21:46:37 +0000315 beq 4f; /* if from kernel mode */ \
Christophe Leroyc223c902016-05-17 08:33:46 +0200316 ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \
Haren Myneni44e93092012-12-06 21:51:04 +0000317 SAVE_PPR(area, r9, r10); \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +05303184: EXCEPTION_PROLOG_COMMON_2(area) \
319 EXCEPTION_PROLOG_COMMON_3(n) \
320 ACCOUNT_STOLEN_TIME
321
322/* Save original regs values from save area to stack frame. */
323#define EXCEPTION_PROLOG_COMMON_2(area) \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000324 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
325 ld r10,area+EX_R10(r13); \
326 std r9,GPR9(r1); \
327 std r10,GPR10(r1); \
328 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
329 ld r10,area+EX_R12(r13); \
330 ld r11,area+EX_R13(r13); \
331 std r9,GPR11(r1); \
332 std r10,GPR12(r1); \
333 std r11,GPR13(r1); \
Paul Mackerras48404f22011-05-01 19:48:20 +0000334 BEGIN_FTR_SECTION_NESTED(66); \
335 ld r10,area+EX_CFAR(r13); \
336 std r10,ORIG_GPR3(r1); \
337 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +0530338 GET_CTR(r10, area); \
339 std r10,_CTR(r1);
340
341#define EXCEPTION_PROLOG_COMMON_3(n) \
342 std r2,GPR2(r1); /* save r2 in stackframe */ \
343 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
344 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000345 mflr r9; /* Get LR, later save to stack */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000346 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000347 std r9,_LINK(r1); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000348 lbz r10,PACASOFTIRQEN(r13); \
349 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
350 std r10,SOFTE(r1); \
351 std r11,_XER(r1); \
352 li r9,(n)+1; \
353 std r9,_TRAP(r1); /* set trap number */ \
354 li r10,0; \
355 ld r11,exception_marker@toc(r2); \
356 std r10,RESULT(r1); /* clear regs->result */ \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +0530357 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000358
359/*
360 * Exception vectors.
361 */
Michael Ellermanda2bc462016-09-30 19:43:18 +1000362#define STD_EXCEPTION_PSERIES(vec, label) \
Paul Mackerras673b1892011-04-05 13:59:58 +1000363 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000364 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
365 EXC_STD, KVMTEST_PR, vec); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000366
Paul Mackerras1707dd12013-02-04 18:10:15 +0000367/* Version of above for when we have to branch out-of-line */
Michael Ellermanda2bc462016-09-30 19:43:18 +1000368#define __OOL_EXCEPTION(vec, label, hdlr) \
369 SET_SCRATCH0(r13) \
370 EXCEPTION_PROLOG_0(PACA_EXGEN) \
371 b hdlr;
372
Paul Mackerras1707dd12013-02-04 18:10:15 +0000373#define STD_EXCEPTION_PSERIES_OOL(vec, label) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000374 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \
375 EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000376
Michael Ellermanda2bc462016-09-30 19:43:18 +1000377#define STD_EXCEPTION_HV(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000378 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000379 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
380 EXC_HV, KVMTEST_HV, vec);
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000381
Michael Ellermanda2bc462016-09-30 19:43:18 +1000382#define STD_EXCEPTION_HV_OOL(vec, label) \
383 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \
384 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000385
Michael Neuling4700dfa2012-11-02 17:21:28 +1100386#define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100387 /* No guest interrupts come through here */ \
388 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000389 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_STD, NOTEST, vec);
Michael Neuling4700dfa2012-11-02 17:21:28 +1100390
Paul Mackerras1707dd12013-02-04 18:10:15 +0000391#define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label) \
Michael Ellermanc9f69512013-06-25 17:47:55 +1000392 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000393 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_STD)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000394
Michael Neuling4700dfa2012-11-02 17:21:28 +1100395#define STD_RELON_EXCEPTION_HV(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100396 /* No guest interrupts come through here */ \
397 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000398 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_HV, NOTEST, vec);
Michael Neuling4700dfa2012-11-02 17:21:28 +1100399
Paul Mackerras1707dd12013-02-04 18:10:15 +0000400#define STD_RELON_EXCEPTION_HV_OOL(vec, label) \
Michael Ellermanc9f69512013-06-25 17:47:55 +1000401 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000402 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000403
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100404/* This associate vector numbers with bits in paca->irq_happened */
405#define SOFTEN_VALUE_0x500 PACA_IRQ_EE
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100406#define SOFTEN_VALUE_0x900 PACA_IRQ_DEC
Michael Ellermanda2bc462016-09-30 19:43:18 +1000407#define SOFTEN_VALUE_0x980 PACA_IRQ_DEC
Ian Munsie1dbdafe2012-11-14 18:49:46 +0000408#define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL
Ian Munsie655bb3f2012-11-14 18:49:45 +0000409#define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +0530410#define SOFTEN_VALUE_0xe60 PACA_IRQ_HMI
Benjamin Herrenschmidt9baaef0a2016-07-08 16:37:06 +1000411#define SOFTEN_VALUE_0xea0 PACA_IRQ_EE
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100412
413#define __SOFTEN_TEST(h, vec) \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000414 lbz r10,PACASOFTIRQEN(r13); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000415 cmpwi r10,0; \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100416 li r10,SOFTEN_VALUE_##vec; \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000417 beq masked_##h##interrupt
Michael Ellermanda2bc462016-09-30 19:43:18 +1000418
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100419#define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000420
Paul Mackerrasde56a942011-06-29 00:21:34 +0000421#define SOFTEN_TEST_PR(vec) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000422 KVMTEST(EXC_STD, vec); \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100423 _SOFTEN_TEST(EXC_STD, vec)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000424
425#define SOFTEN_TEST_HV(vec) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000426 KVMTEST(EXC_HV, vec); \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100427 _SOFTEN_TEST(EXC_HV, vec)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000428
Michael Ellermanda2bc462016-09-30 19:43:18 +1000429#define KVMTEST_PR(vec) \
430 KVMTEST(EXC_STD, vec)
431
432#define KVMTEST_HV(vec) \
433 KVMTEST(EXC_HV, vec)
434
Michael Neuling4700dfa2012-11-02 17:21:28 +1100435#define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec)
436#define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec)
437
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000438#define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000439 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000440 EXCEPTION_PROLOG_0(PACA_EXGEN); \
441 __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000442 EXCEPTION_PROLOG_PSERIES_1(label, h);
Paul Mackerras1707dd12013-02-04 18:10:15 +0000443
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000444#define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \
445 __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000446
447#define MASKABLE_EXCEPTION_PSERIES(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000448 _MASKABLE_EXCEPTION_PSERIES(vec, label, \
Paul Mackerrasde56a942011-06-29 00:21:34 +0000449 EXC_STD, SOFTEN_TEST_PR)
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000450
Michael Ellermanda2bc462016-09-30 19:43:18 +1000451#define MASKABLE_EXCEPTION_PSERIES_OOL(vec, label) \
452 EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec); \
453 EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
454
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000455#define MASKABLE_EXCEPTION_HV(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000456 _MASKABLE_EXCEPTION_PSERIES(vec, label, \
457 EXC_HV, SOFTEN_TEST_HV)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000458
Paul Mackerras1707dd12013-02-04 18:10:15 +0000459#define MASKABLE_EXCEPTION_HV_OOL(vec, label) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000460 EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000461 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000462
Michael Neuling4700dfa2012-11-02 17:21:28 +1100463#define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100464 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000465 EXCEPTION_PROLOG_0(PACA_EXGEN); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000466 __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \
467 EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
468
469#define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100470 __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)
471
472#define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100473 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
474 EXC_STD, SOFTEN_NOTEST_PR)
475
476#define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100477 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
478 EXC_HV, SOFTEN_NOTEST_HV)
479
Paul Mackerras1707dd12013-02-04 18:10:15 +0000480#define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000481 EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_NOTEST_HV, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000482 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000483
Benjamin Herrenschmidt1b701172012-03-01 15:42:56 +1100484/*
485 * Our exception common code can be passed various "additions"
486 * to specify the behaviour of interrupts, whether to kick the
487 * runlatch, etc...
488 */
489
Michael Ellerman9daf1122014-07-15 21:15:38 +1000490/*
491 * This addition reconciles our actual IRQ state with the various software
492 * flags that track it. This may call C code.
493 */
494#define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000495
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100496#define ADD_NVGPRS \
Anton Blanchardb1576fe2014-02-04 16:04:35 +1100497 bl save_nvgprs
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100498
499#define RUNLATCH_ON \
500BEGIN_FTR_SECTION \
Stuart Yoder9778b692012-07-05 04:41:35 +0000501 CURRENT_THREAD_INFO(r3, r1); \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100502 ld r4,TI_LOCAL_FLAGS(r3); \
503 andi. r0,r4,_TLF_RUNLATCH; \
504 beql ppc64_runlatch_on_trampoline; \
505END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
506
507#define EXCEPTION_COMMON(trap, label, hdlr, ret, additions) \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100508 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
Michael Ellermana1d711c2014-07-15 21:15:37 +1000509 /* Volatile regs are potentially clobbered here */ \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100510 additions; \
511 addi r3,r1,STACK_FRAME_OVERHEAD; \
512 bl hdlr; \
513 b ret
514
515#define STD_EXCEPTION_COMMON(trap, label, hdlr) \
516 EXCEPTION_COMMON(trap, label, hdlr, ret_from_except, \
Michael Ellerman9daf1122014-07-15 21:15:38 +1000517 ADD_NVGPRS;ADD_RECONCILE)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000518
519/*
520 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
Benjamin Herrenschmidt7450f6f2012-03-01 10:52:01 +1100521 * in the idle task and therefore need the special idle handling
522 * (finish nap and runlatch)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000523 */
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100524#define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \
525 EXCEPTION_COMMON(trap, label, hdlr, ret_from_except_lite, \
Michael Ellerman9daf1122014-07-15 21:15:38 +1000526 FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000527
528/*
529 * When the idle code in power4_idle puts the CPU into NAP mode,
530 * it has to do so in a loop, and relies on the external interrupt
531 * and decrementer interrupt entry code to get it out of the loop.
532 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
533 * to signal that it is in the loop and needs help to get out.
534 */
535#ifdef CONFIG_PPC_970_NAP
536#define FINISH_NAP \
537BEGIN_FTR_SECTION \
Stuart Yoder9778b692012-07-05 04:41:35 +0000538 CURRENT_THREAD_INFO(r11, r1); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000539 ld r9,TI_LOCAL_FLAGS(r11); \
540 andi. r10,r9,_TLF_NAPPING; \
541 bnel power4_fixup_nap; \
542END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
543#else
544#define FINISH_NAP
545#endif
546
547#endif /* _ASM_POWERPC_EXCEPTION_H */