blob: 14752eee3d0c44816a61b395970186c1e56d4a21 [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
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000100/*
101 * Branches from unrelocated code (e.g., interrupts) to labels outside
102 * head-y require >64K offsets.
103 */
104#define __LOAD_FAR_HANDLER(reg, label) \
105 ld reg,PACAKBASE(r13); \
106 ori reg,reg,(ABS_ADDR(label))@l; \
107 addis reg,reg,(ABS_ADDR(label))@h;
108
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000109/* Exception register prefixes */
110#define EXC_HV H
111#define EXC_STD
112
Michael Neuling4700dfa2012-11-02 17:21:28 +1100113#if defined(CONFIG_RELOCATABLE)
114/*
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000115 * If we support interrupts with relocation on AND we're a relocatable kernel,
116 * we need to use CTR to get to the 2nd level handler. So, save/restore it
117 * when required.
Michael Neuling4700dfa2012-11-02 17:21:28 +1100118 */
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000119#define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13)
120#define GET_CTR(reg, area) ld reg,area+EX_CTR(r13)
121#define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg
Michael Neuling4700dfa2012-11-02 17:21:28 +1100122#else
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000123/* ...else CTR is unused and in register. */
124#define SAVE_CTR(reg, area)
125#define GET_CTR(reg, area) mfctr reg
126#define RESTORE_CTR(reg, area)
Michael Neuling4700dfa2012-11-02 17:21:28 +1100127#endif
128
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000129/*
130 * PPR save/restore macros used in exceptions_64s.S
131 * Used for P7 or later processors
132 */
133#define SAVE_PPR(area, ra, rb) \
134BEGIN_FTR_SECTION_NESTED(940) \
135 ld ra,PACACURRENT(r13); \
136 ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \
137 std rb,TASKTHREADPPR(ra); \
138END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940)
139
140#define RESTORE_PPR_PACA(area, ra) \
141BEGIN_FTR_SECTION_NESTED(941) \
142 ld ra,area+EX_PPR(r13); \
143 mtspr SPRN_PPR,ra; \
144END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941)
145
146/*
Paul Mackerras1707dd12013-02-04 18:10:15 +0000147 * Get an SPR into a register if the CPU has the given feature
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000148 */
Paul Mackerras1707dd12013-02-04 18:10:15 +0000149#define OPT_GET_SPR(ra, spr, ftr) \
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000150BEGIN_FTR_SECTION_NESTED(943) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000151 mfspr ra,spr; \
152END_FTR_SECTION_NESTED(ftr,ftr,943)
Haren Myneni13e7a8e2012-12-06 21:50:32 +0000153
Paul Mackerras1707dd12013-02-04 18:10:15 +0000154/*
Mahesh Salgaonkard410ae22014-03-11 10:56:18 +0530155 * Set an SPR from a register if the CPU has the given feature
156 */
157#define OPT_SET_SPR(ra, spr, ftr) \
158BEGIN_FTR_SECTION_NESTED(943) \
159 mtspr spr,ra; \
160END_FTR_SECTION_NESTED(ftr,ftr,943)
161
162/*
Paul Mackerras1707dd12013-02-04 18:10:15 +0000163 * Save a register to the PACA if the CPU has the given feature
164 */
165#define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \
166BEGIN_FTR_SECTION_NESTED(943) \
167 std ra,offset(r13); \
168END_FTR_SECTION_NESTED(ftr,ftr,943)
169
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100170#define EXCEPTION_PROLOG_0_PACA(area) \
Haren Myneni44e93092012-12-06 21:51:04 +0000171 std r9,area+EX_R9(r13); /* save r9 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000172 OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \
173 HMT_MEDIUM; \
Haren Myneni44e93092012-12-06 21:51:04 +0000174 std r10,area+EX_R10(r13); /* save r10 - r12 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000175 OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR)
176
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100177#define EXCEPTION_PROLOG_0(area) \
178 GET_PACA(r13); \
179 EXCEPTION_PROLOG_0_PACA(area)
180
Paul Mackerras1707dd12013-02-04 18:10:15 +0000181#define __EXCEPTION_PROLOG_1(area, extra, vec) \
182 OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \
183 OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000184 SAVE_CTR(r10, area); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000185 mfcr r9; \
186 extra(vec); \
187 std r11,area+EX_R11(r13); \
188 std r12,area+EX_R12(r13); \
189 GET_SCRATCH0(r10); \
190 std r10,area+EX_R13(r13)
191#define EXCEPTION_PROLOG_1(area, extra, vec) \
192 __EXCEPTION_PROLOG_1(area, extra, vec)
Stephen Rothwell7180e3e2007-08-22 13:48:37 +1000193
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000194#define __EXCEPTION_PROLOG_PSERIES_1(label, h) \
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000195 ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000196 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000197 LOAD_HANDLER(r12,label) \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000198 mtspr SPRN_##h##SRR0,r12; \
199 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
200 mtspr SPRN_##h##SRR1,r10; \
201 h##rfid; \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000202 b . /* prevent speculative execution */
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000203#define EXCEPTION_PROLOG_PSERIES_1(label, h) \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000204 __EXCEPTION_PROLOG_PSERIES_1(label, h)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000205
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000206#define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000207 EXCEPTION_PROLOG_0(area); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000208 EXCEPTION_PROLOG_1(area, extra, vec); \
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000209 EXCEPTION_PROLOG_PSERIES_1(label, h);
Benjamin Herrenschmidtc5a8c0c2009-07-16 19:36:57 +0000210
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100211/* Have the PACA in r13 already */
212#define EXCEPTION_PROLOG_PSERIES_PACA(area, label, h, extra, vec) \
213 EXCEPTION_PROLOG_0_PACA(area); \
214 EXCEPTION_PROLOG_1(area, extra, vec); \
215 EXCEPTION_PROLOG_PSERIES_1(label, h);
216
Michael Ellermanda2bc462016-09-30 19:43:18 +1000217#define __KVMTEST(h, n) \
218 lbz r10,HSTATE_IN_GUEST(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000219 cmpwi r10,0; \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000220 bne do_kvm_##h##n
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000221
Aneesh Kumar K.Vdd96b2c2013-10-07 22:17:55 +0530222#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
223/*
224 * If hv is possible, interrupts come into to the hv version
225 * of the kvmppc_interrupt code, which then jumps to the PR handler,
226 * kvmppc_interrupt_pr, if the guest is a PR guest.
227 */
228#define kvmppc_interrupt kvmppc_interrupt_hv
229#else
230#define kvmppc_interrupt kvmppc_interrupt_pr
231#endif
232
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100233#ifdef CONFIG_RELOCATABLE
234#define BRANCH_TO_COMMON(reg, label) \
235 __LOAD_HANDLER(reg, label); \
236 mtctr reg; \
237 bctr
238
Nicholas Piggin2337d202017-01-27 14:24:33 +1000239#define BRANCH_LINK_TO_FAR(reg, label) \
240 __LOAD_FAR_HANDLER(reg, label); \
241 mtctr reg; \
242 bctrl
243
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000244/*
245 * KVM requires __LOAD_FAR_HANDLER.
246 *
247 * __BRANCH_TO_KVM_EXIT branches are also a special case because they
248 * explicitly use r9 then reload it from PACA before branching. Hence
249 * the double-underscore.
250 */
251#define __BRANCH_TO_KVM_EXIT(area, label) \
252 mfctr r9; \
253 std r9,HSTATE_SCRATCH1(r13); \
254 __LOAD_FAR_HANDLER(r9, label); \
255 mtctr r9; \
256 ld r9,area+EX_R9(r13); \
257 bctr
258
259#define BRANCH_TO_KVM(reg, label) \
260 __LOAD_FAR_HANDLER(reg, label); \
261 mtctr reg; \
262 bctr
263
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100264#else
265#define BRANCH_TO_COMMON(reg, label) \
266 b label
267
Nicholas Piggin2337d202017-01-27 14:24:33 +1000268#define BRANCH_LINK_TO_FAR(reg, label) \
269 bl label
270
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000271#define BRANCH_TO_KVM(reg, label) \
272 b label
273
274#define __BRANCH_TO_KVM_EXIT(area, label) \
275 ld r9,area+EX_R9(r13); \
276 b label
277
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100278#endif
279
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000280
Nicholas Piggind3918e72016-12-22 04:29:25 +1000281#define __KVM_HANDLER(area, h, n) \
Paul Mackerras0acb9112013-02-04 18:10:51 +0000282 BEGIN_FTR_SECTION_NESTED(947) \
283 ld r10,area+EX_CFAR(r13); \
284 std r10,HSTATE_CFAR(r13); \
285 END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947); \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000286 BEGIN_FTR_SECTION_NESTED(948) \
287 ld r10,area+EX_PPR(r13); \
288 std r10,HSTATE_PPR(r13); \
289 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000290 ld r10,area+EX_R10(r13); \
Paul Mackerras0acb9112013-02-04 18:10:51 +0000291 std r12,HSTATE_SCRATCH0(r13); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000292 sldi r12,r9,32; \
293 ori r12,r12,(n); \
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000294 /* This reloads r9 before branching to kvmppc_interrupt */ \
295 __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000296
297#define __KVM_HANDLER_SKIP(area, h, n) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000298 cmpwi r10,KVM_GUEST_MODE_SKIP; \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000299 beq 89f; \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000300 BEGIN_FTR_SECTION_NESTED(948) \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000301 ld r10,area+EX_PPR(r13); \
302 std r10,HSTATE_PPR(r13); \
Paul Mackerras4b8473c2013-09-20 14:52:39 +1000303 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000304 ld r10,area+EX_R10(r13); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000305 std r12,HSTATE_SCRATCH0(r13); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000306 sldi r12,r9,32; \
307 ori r12,r12,(n); \
Nicholas Piggina97a65d2017-01-27 14:00:34 +1000308 /* This reloads r9 before branching to kvmppc_interrupt */ \
309 __BRANCH_TO_KVM_EXIT(area, kvmppc_interrupt); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000031089: mtocrf 0x80,r9; \
311 ld r9,area+EX_R9(r13); \
Nicholas Piggind3918e72016-12-22 04:29:25 +1000312 ld r10,area+EX_R10(r13); \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000313 b kvmppc_skip_##h##interrupt
314
315#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
Michael Ellermanda2bc462016-09-30 19:43:18 +1000316#define KVMTEST(h, n) __KVMTEST(h, n)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000317#define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n)
318#define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n)
319
320#else
Michael Ellermanda2bc462016-09-30 19:43:18 +1000321#define KVMTEST(h, n)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000322#define KVM_HANDLER(area, h, n)
323#define KVM_HANDLER_SKIP(area, h, n)
324#endif
325
326#define NOTEST(n)
327
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000328/*
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000329 * The common exception prolog is used for all except a few exceptions
330 * such as a segment miss on a kernel address. We have to be prepared
331 * to take another exception from the point where we first touch the
332 * kernel stack onwards.
333 *
334 * On entry r13 points to the paca, r9-r13 are saved in the paca,
335 * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
336 * SRR1, and relocation is on.
337 */
338#define EXCEPTION_PROLOG_COMMON(n, area) \
339 andi. r10,r12,MSR_PR; /* See if coming from user */ \
340 mr r10,r1; /* Save r1 */ \
341 subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
342 beq- 1f; \
343 ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
Michael Neuling90ff5d62013-12-16 15:12:43 +11003441: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \
Paul Mackerras1977b502011-05-01 19:46:44 +0000345 blt+ cr1,3f; /* abort if it is */ \
346 li r1,(n); /* will be reloaded later */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000347 sth r1,PACA_TRAP_SAVE(r13); \
Paul Mackerras1977b502011-05-01 19:46:44 +0000348 std r3,area+EX_R3(r13); \
349 addi r3,r13,area; /* r3 -> where regs are saved*/ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000350 RESTORE_CTR(r1, area); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000351 b bad_stack; \
3523: std r9,_CCR(r1); /* save CR in stackframe */ \
353 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
354 std r12,_MSR(r1); /* save SRR1 in stackframe */ \
355 std r10,0(r1); /* make stack chain pointer */ \
356 std r0,GPR0(r1); /* save r0 in stackframe */ \
357 std r10,GPR1(r1); /* save r1 in stackframe */ \
Haren Myneni5d75b262012-12-06 21:46:37 +0000358 beq 4f; /* if from kernel mode */ \
Christophe Leroyc223c902016-05-17 08:33:46 +0200359 ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \
Haren Myneni44e93092012-12-06 21:51:04 +0000360 SAVE_PPR(area, r9, r10); \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +05303614: EXCEPTION_PROLOG_COMMON_2(area) \
362 EXCEPTION_PROLOG_COMMON_3(n) \
363 ACCOUNT_STOLEN_TIME
364
365/* Save original regs values from save area to stack frame. */
366#define EXCEPTION_PROLOG_COMMON_2(area) \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000367 ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
368 ld r10,area+EX_R10(r13); \
369 std r9,GPR9(r1); \
370 std r10,GPR10(r1); \
371 ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
372 ld r10,area+EX_R12(r13); \
373 ld r11,area+EX_R13(r13); \
374 std r9,GPR11(r1); \
375 std r10,GPR12(r1); \
376 std r11,GPR13(r1); \
Paul Mackerras48404f22011-05-01 19:48:20 +0000377 BEGIN_FTR_SECTION_NESTED(66); \
378 ld r10,area+EX_CFAR(r13); \
379 std r10,ORIG_GPR3(r1); \
380 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +0530381 GET_CTR(r10, area); \
382 std r10,_CTR(r1);
383
384#define EXCEPTION_PROLOG_COMMON_3(n) \
385 std r2,GPR2(r1); /* save r2 in stackframe */ \
386 SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
387 SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
Michael Neulingbc2e6c62013-08-13 15:54:52 +1000388 mflr r9; /* Get LR, later save to stack */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000389 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000390 std r9,_LINK(r1); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000391 lbz r10,PACASOFTIRQEN(r13); \
392 mfspr r11,SPRN_XER; /* save XER in stackframe */ \
393 std r10,SOFTE(r1); \
394 std r11,_XER(r1); \
395 li r9,(n)+1; \
396 std r9,_TRAP(r1); /* set trap number */ \
397 li r10,0; \
398 ld r11,exception_marker@toc(r2); \
399 std r10,RESULT(r1); /* clear regs->result */ \
Mahesh Salgaonkarb14a72532013-10-30 20:03:51 +0530400 std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000401
402/*
403 * Exception vectors.
404 */
Michael Ellermanda2bc462016-09-30 19:43:18 +1000405#define STD_EXCEPTION_PSERIES(vec, label) \
Paul Mackerras673b1892011-04-05 13:59:58 +1000406 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000407 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
408 EXC_STD, KVMTEST_PR, vec); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000409
Paul Mackerras1707dd12013-02-04 18:10:15 +0000410/* Version of above for when we have to branch out-of-line */
Michael Ellermanda2bc462016-09-30 19:43:18 +1000411#define __OOL_EXCEPTION(vec, label, hdlr) \
412 SET_SCRATCH0(r13) \
413 EXCEPTION_PROLOG_0(PACA_EXGEN) \
414 b hdlr;
415
Paul Mackerras1707dd12013-02-04 18:10:15 +0000416#define STD_EXCEPTION_PSERIES_OOL(vec, label) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000417 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \
418 EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000419
Michael Ellermanda2bc462016-09-30 19:43:18 +1000420#define STD_EXCEPTION_HV(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000421 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000422 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
423 EXC_HV, KVMTEST_HV, vec);
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000424
Michael Ellermanda2bc462016-09-30 19:43:18 +1000425#define STD_EXCEPTION_HV_OOL(vec, label) \
426 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \
427 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000428
Michael Neuling4700dfa2012-11-02 17:21:28 +1100429#define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100430 /* No guest interrupts come through here */ \
431 SET_SCRATCH0(r13); /* save r13 */ \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000432 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_STD, NOTEST, vec);
Michael Neuling4700dfa2012-11-02 17:21:28 +1100433
Paul Mackerras1707dd12013-02-04 18:10:15 +0000434#define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label) \
Michael Ellermanc9f69512013-06-25 17:47:55 +1000435 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000436 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_STD)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000437
Michael Neuling4700dfa2012-11-02 17:21:28 +1100438#define STD_RELON_EXCEPTION_HV(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100439 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerrasbc355122017-01-30 21:21:40 +1100440 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, \
441 EXC_HV, KVMTEST_HV, vec);
Michael Neuling4700dfa2012-11-02 17:21:28 +1100442
Paul Mackerras1707dd12013-02-04 18:10:15 +0000443#define STD_RELON_EXCEPTION_HV_OOL(vec, label) \
Paul Mackerrasbc355122017-01-30 21:21:40 +1100444 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000445 EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000446
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100447/* This associate vector numbers with bits in paca->irq_happened */
448#define SOFTEN_VALUE_0x500 PACA_IRQ_EE
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100449#define SOFTEN_VALUE_0x900 PACA_IRQ_DEC
Michael Ellermanda2bc462016-09-30 19:43:18 +1000450#define SOFTEN_VALUE_0x980 PACA_IRQ_DEC
Ian Munsie1dbdafe2012-11-14 18:49:46 +0000451#define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL
Ian Munsie655bb3f2012-11-14 18:49:45 +0000452#define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +0530453#define SOFTEN_VALUE_0xe60 PACA_IRQ_HMI
Benjamin Herrenschmidt9baaef0a2016-07-08 16:37:06 +1000454#define SOFTEN_VALUE_0xea0 PACA_IRQ_EE
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100455
456#define __SOFTEN_TEST(h, vec) \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000457 lbz r10,PACASOFTIRQEN(r13); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000458 cmpwi r10,0; \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100459 li r10,SOFTEN_VALUE_##vec; \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000460 beq masked_##h##interrupt
Michael Ellermanda2bc462016-09-30 19:43:18 +1000461
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100462#define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000463
Paul Mackerrasde56a942011-06-29 00:21:34 +0000464#define SOFTEN_TEST_PR(vec) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000465 KVMTEST(EXC_STD, vec); \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100466 _SOFTEN_TEST(EXC_STD, vec)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000467
468#define SOFTEN_TEST_HV(vec) \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000469 KVMTEST(EXC_HV, vec); \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +1100470 _SOFTEN_TEST(EXC_HV, vec)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000471
Michael Ellermanda2bc462016-09-30 19:43:18 +1000472#define KVMTEST_PR(vec) \
473 KVMTEST(EXC_STD, vec)
474
475#define KVMTEST_HV(vec) \
476 KVMTEST(EXC_HV, vec)
477
Michael Neuling4700dfa2012-11-02 17:21:28 +1100478#define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec)
479#define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec)
480
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000481#define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000482 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000483 EXCEPTION_PROLOG_0(PACA_EXGEN); \
484 __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000485 EXCEPTION_PROLOG_PSERIES_1(label, h);
Paul Mackerras1707dd12013-02-04 18:10:15 +0000486
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000487#define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \
488 __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000489
490#define MASKABLE_EXCEPTION_PSERIES(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000491 _MASKABLE_EXCEPTION_PSERIES(vec, label, \
Paul Mackerrasde56a942011-06-29 00:21:34 +0000492 EXC_STD, SOFTEN_TEST_PR)
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000493
Michael Ellermanda2bc462016-09-30 19:43:18 +1000494#define MASKABLE_EXCEPTION_PSERIES_OOL(vec, label) \
495 EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec); \
496 EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
497
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000498#define MASKABLE_EXCEPTION_HV(loc, vec, label) \
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000499 _MASKABLE_EXCEPTION_PSERIES(vec, label, \
500 EXC_HV, SOFTEN_TEST_HV)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000501
Paul Mackerras1707dd12013-02-04 18:10:15 +0000502#define MASKABLE_EXCEPTION_HV_OOL(vec, label) \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000503 EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000504 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000505
Michael Neuling4700dfa2012-11-02 17:21:28 +1100506#define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100507 SET_SCRATCH0(r13); /* save r13 */ \
Paul Mackerras1707dd12013-02-04 18:10:15 +0000508 EXCEPTION_PROLOG_0(PACA_EXGEN); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000509 __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \
510 EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
511
512#define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100513 __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)
514
515#define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100516 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
517 EXC_STD, SOFTEN_NOTEST_PR)
518
519#define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \
Michael Neuling4700dfa2012-11-02 17:21:28 +1100520 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
Paul Mackerrasbc355122017-01-30 21:21:40 +1100521 EXC_HV, SOFTEN_TEST_HV)
Michael Neuling4700dfa2012-11-02 17:21:28 +1100522
Paul Mackerras1707dd12013-02-04 18:10:15 +0000523#define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label) \
Paul Mackerrasbc355122017-01-30 21:21:40 +1100524 EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \
Michael Ellermanda2bc462016-09-30 19:43:18 +1000525 EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000526
Benjamin Herrenschmidt1b701172012-03-01 15:42:56 +1100527/*
528 * Our exception common code can be passed various "additions"
529 * to specify the behaviour of interrupts, whether to kick the
530 * runlatch, etc...
531 */
532
Michael Ellerman9daf1122014-07-15 21:15:38 +1000533/*
534 * This addition reconciles our actual IRQ state with the various software
535 * flags that track it. This may call C code.
536 */
537#define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000538
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100539#define ADD_NVGPRS \
Anton Blanchardb1576fe2014-02-04 16:04:35 +1100540 bl save_nvgprs
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100541
542#define RUNLATCH_ON \
543BEGIN_FTR_SECTION \
Stuart Yoder9778b692012-07-05 04:41:35 +0000544 CURRENT_THREAD_INFO(r3, r1); \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100545 ld r4,TI_LOCAL_FLAGS(r3); \
546 andi. r0,r4,_TLF_RUNLATCH; \
547 beql ppc64_runlatch_on_trampoline; \
548END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
549
550#define EXCEPTION_COMMON(trap, label, hdlr, ret, additions) \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100551 EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
Michael Ellermana1d711c2014-07-15 21:15:37 +1000552 /* Volatile regs are potentially clobbered here */ \
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100553 additions; \
554 addi r3,r1,STACK_FRAME_OVERHEAD; \
555 bl hdlr; \
556 b ret
557
558#define STD_EXCEPTION_COMMON(trap, label, hdlr) \
559 EXCEPTION_COMMON(trap, label, hdlr, ret_from_except, \
Michael Ellerman9daf1122014-07-15 21:15:38 +1000560 ADD_NVGPRS;ADD_RECONCILE)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000561
562/*
563 * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
Benjamin Herrenschmidt7450f6f2012-03-01 10:52:01 +1100564 * in the idle task and therefore need the special idle handling
565 * (finish nap and runlatch)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000566 */
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100567#define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \
568 EXCEPTION_COMMON(trap, label, hdlr, ret_from_except_lite, \
Michael Ellerman9daf1122014-07-15 21:15:38 +1000569 FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON)
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000570
571/*
572 * When the idle code in power4_idle puts the CPU into NAP mode,
573 * it has to do so in a loop, and relies on the external interrupt
574 * and decrementer interrupt entry code to get it out of the loop.
575 * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
576 * to signal that it is in the loop and needs help to get out.
577 */
578#ifdef CONFIG_PPC_970_NAP
579#define FINISH_NAP \
580BEGIN_FTR_SECTION \
Stuart Yoder9778b692012-07-05 04:41:35 +0000581 CURRENT_THREAD_INFO(r11, r1); \
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +1000582 ld r9,TI_LOCAL_FLAGS(r11); \
583 andi. r10,r9,_TLF_NAPPING; \
584 bnel power4_fixup_nap; \
585END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
586#else
587#define FINISH_NAP
588#endif
589
590#endif /* _ASM_POWERPC_EXCEPTION_H */