blob: d50cc9b38b8021e31214448ebc0caa6968724ce4 [file] [log] [blame]
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001/*
2 * This file contains the 64-bit "server" PowerPC variant
3 * of the low level exception handling including exception
4 * vectors, exception return, part of the slb and stab
5 * handling and other fixed offset specific things.
6 *
7 * This file is meant to be #included from head_64.S due to
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008 * position dependent assembly.
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00009 *
10 * Most of this originates from head_64.S and thus has the same
11 * copyright history.
12 *
13 */
14
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +110015#include <asm/hw_irq.h>
Benjamin Herrenschmidt8aa34ab2009-07-14 20:52:52 +000016#include <asm/exception-64s.h>
Stephen Rothwell46f52212010-11-18 15:06:17 +000017#include <asm/ptrace.h>
Shreyas B. Prabhu7cba1602014-12-10 00:26:52 +053018#include <asm/cpuidle.h>
Michael Ellermanda2bc462016-09-30 19:43:18 +100019#include <asm/head-64.h>
Benjamin Herrenschmidt8aa34ab2009-07-14 20:52:52 +000020
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000021/*
Nicholas Piggin57f26642016-09-28 11:31:48 +100022 * There are a few constraints to be concerned with.
23 * - Real mode exceptions code/data must be located at their physical location.
24 * - Virtual mode exceptions must be mapped at their 0xc000... location.
25 * - Fixed location code must not call directly beyond the __end_interrupts
26 * area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence
27 * must be used.
28 * - LOAD_HANDLER targets must be within first 64K of physical 0 /
29 * virtual 0xc00...
30 * - Conditional branch targets must be within +/-32K of caller.
31 *
32 * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and
33 * therefore don't have to run in physically located code or rfid to
34 * virtual mode kernel code. However on relocatable kernels they do have
35 * to branch to KERNELBASE offset because the rest of the kernel (outside
36 * the exception vectors) may be located elsewhere.
37 *
38 * Virtual exceptions correspond with physical, except their entry points
39 * are offset by 0xc000000000000000 and also tend to get an added 0x4000
40 * offset applied. Virtual exceptions are enabled with the Alternate
41 * Interrupt Location (AIL) bit set in the LPCR. However this does not
42 * guarantee they will be delivered virtually. Some conditions (see the ISA)
43 * cause exceptions to be delivered in real mode.
44 *
45 * It's impossible to receive interrupts below 0x300 via AIL.
46 *
47 * KVM: None of the virtual exceptions are from the guest. Anything that
48 * escalated to HV=1 from HV=0 is delivered via real mode handlers.
49 *
50 *
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000051 * We layout physical memory as follows:
52 * 0x0000 - 0x00ff : Secondary processor spin code
Nicholas Piggin57f26642016-09-28 11:31:48 +100053 * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors
54 * 0x1900 - 0x3fff : Real mode trampolines
55 * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors
56 * 0x5900 - 0x6fff : Relon mode trampolines
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000057 * 0x7000 - 0x7fff : FWNMI data area
Nicholas Piggin57f26642016-09-28 11:31:48 +100058 * 0x8000 - .... : Common interrupt handlers, remaining early
59 * setup code, rest of kernel.
Nicholas Piggine0319822016-09-21 17:44:07 +100060 *
61 * We could reclaim 0x4000-0x42ff for real mode trampolines if the space
62 * is necessary. Until then it's more consistent to explicitly put VIRT_NONE
63 * vectors there.
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000064 */
Nicholas Piggin57f26642016-09-28 11:31:48 +100065OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900)
66OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x4000)
67OPEN_FIXED_SECTION(virt_vectors, 0x4000, 0x5900)
68OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000)
69#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
70/*
71 * Data area reserved for FWNMI option.
72 * This address (0x7000) is fixed by the RPA.
73 * pseries and powernv need to keep the whole page from
74 * 0x7000 to 0x8000 free for use by the firmware
75 */
76ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000)
77OPEN_TEXT_SECTION(0x8000)
78#else
79OPEN_TEXT_SECTION(0x7000)
80#endif
81
82USE_FIXED_SECTION(real_vectors)
83
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000084/*
85 * This is the start of the interrupt handlers for pSeries
86 * This code runs with relocation off.
87 * Code from here to __end_interrupts gets copied down to real
88 * address 0x100 when we are running a relocatable kernel.
89 * Therefore any relative branches in this section must only
90 * branch to labels in this section.
91 */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +000092 .globl __start_interrupts
93__start_interrupts:
94
Nicholas Piggine0319822016-09-21 17:44:07 +100095/* No virt vectors corresponding with 0x0..0x100 */
96EXC_VIRT_NONE(0x4000, 0x4100)
97
Nicholas Pigginfb479e42016-10-13 13:17:14 +110098
99#ifdef CONFIG_PPC_P7_NAP
100 /*
101 * If running native on arch 2.06 or later, check if we are waking up
102 * from nap/sleep/winkle, and branch to idle handler.
103 */
104#define IDLETEST(n) \
105 BEGIN_FTR_SECTION ; \
106 mfspr r10,SPRN_SRR1 ; \
107 rlwinm. r10,r10,47-31,30,31 ; \
108 beq- 1f ; \
109 cmpwi cr3,r10,2 ; \
110 BRANCH_TO_COMMON(r10, system_reset_idle_common) ; \
1111: \
112 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
113#else
114#define IDLETEST NOTEST
115#endif
116
Michael Ellermanda2bc462016-09-30 19:43:18 +1000117EXC_REAL_BEGIN(system_reset, 0x100, 0x200)
Benjamin Herrenschmidt948cf672011-01-24 18:42:41 +1100118 SET_SCRATCH0(r13)
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100119 GET_PACA(r13)
120 clrrdi r13,r13,1 /* Last bit of HSPRG0 is set if waking from winkle */
121 EXCEPTION_PROLOG_PSERIES_PACA(PACA_EXGEN, system_reset_common, EXC_STD,
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100122 IDLETEST, 0x100)
Paul Mackerras371fefd2011-06-29 00:23:08 +0000123
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100124EXC_REAL_END(system_reset, 0x100, 0x200)
125EXC_VIRT_NONE(0x4100, 0x4200)
126
127#ifdef CONFIG_PPC_P7_NAP
128EXC_COMMON_BEGIN(system_reset_idle_common)
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100129BEGIN_FTR_SECTION
130 GET_PACA(r13) /* Restore HSPRG0 to get the winkle bit in r13 */
131END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
Shreyas B. Prabhu5fa6b6b2016-07-08 11:50:46 +0530132 bl pnv_restore_hyp_resource
Shreyas B. Prabhu77b54e92014-12-10 00:26:53 +0530133
Shreyas B. Prabhu7cba1602014-12-10 00:26:52 +0530134 li r0,PNV_THREAD_RUNNING
135 stb r0,PACA_THREAD_IDLE_STATE(r13) /* Clear thread state */
Paul Mackerras371fefd2011-06-29 00:23:08 +0000136
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530137#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
Paul Mackerrasf0888f72012-02-03 00:54:17 +0000138 li r0,KVM_HWTHREAD_IN_KERNEL
139 stb r0,HSTATE_HWTHREAD_STATE(r13)
140 /* Order setting hwthread_state vs. testing hwthread_req */
141 sync
142 lbz r0,HSTATE_HWTHREAD_REQ(r13)
143 cmpwi r0,0
144 beq 1f
Paul Mackerras371fefd2011-06-29 00:23:08 +0000145 b kvm_start_guest
1461:
147#endif
148
Paul Mackerras56548fc2014-12-03 14:48:40 +1100149 /* Return SRR1 from power7_nap() */
150 mfspr r3,SPRN_SRR1
Shreyas B. Prabhu17065672016-07-08 11:50:44 +0530151 blt cr3,2f
Shreyas B. Prabhu5fa6b6b2016-07-08 11:50:46 +0530152 b pnv_wakeup_loss
1532: b pnv_wakeup_noloss
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100154#endif
Vaidyanathan Srinivasanaca79d22014-02-26 05:38:25 +0530155
Nicholas Piggin582baf42016-09-21 17:43:30 +1000156EXC_COMMON(system_reset_common, 0x100, system_reset_exception)
157
158#ifdef CONFIG_PPC_PSERIES
159/*
160 * Vectors for the FWNMI option. Share common code.
161 */
162TRAMP_REAL_BEGIN(system_reset_fwnmi)
163 SET_SCRATCH0(r13) /* save r13 */
164 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
165 NOTEST, 0x100)
166#endif /* CONFIG_PPC_PSERIES */
167
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000168
Michael Ellermanda2bc462016-09-30 19:43:18 +1000169EXC_REAL_BEGIN(machine_check, 0x200, 0x300)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000170 /* This is moved out of line as it can be patched by FW, but
171 * some code path might still want to branch into the original
172 * vector
173 */
Paul Mackerras1707dd12013-02-04 18:10:15 +0000174 SET_SCRATCH0(r13) /* save r13 */
Mahesh Salgaonkarbc14c492016-08-05 17:34:13 +0530175 /*
176 * Running native on arch 2.06 or later, we may wakeup from winkle
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100177 * inside machine check. If yes, then last bit of HSPRG0 would be set
Mahesh Salgaonkarbc14c492016-08-05 17:34:13 +0530178 * to 1. Hence clear it unconditionally.
Mahesh Salgaonkar1c510892013-10-30 20:04:31 +0530179 */
Mahesh Salgaonkarbc14c492016-08-05 17:34:13 +0530180 GET_PACA(r13)
181 clrrdi r13,r13,1
182 SET_PACA(r13)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000183 EXCEPTION_PROLOG_0(PACA_EXMC)
Mahesh Salgaonkar1e9b4502013-10-30 20:04:08 +0530184BEGIN_FTR_SECTION
Mahesh Salgaonkar25137672016-03-01 11:17:46 +0530185 b machine_check_powernv_early
Mahesh Salgaonkar1e9b4502013-10-30 20:04:08 +0530186FTR_SECTION_ELSE
Paul Mackerras1707dd12013-02-04 18:10:15 +0000187 b machine_check_pSeries_0
Mahesh Salgaonkar1e9b4502013-10-30 20:04:08 +0530188ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000189EXC_REAL_END(machine_check, 0x200, 0x300)
Nicholas Pigginafcf0092016-09-21 17:43:31 +1000190EXC_VIRT_NONE(0x4200, 0x4300)
191TRAMP_REAL_BEGIN(machine_check_powernv_early)
192BEGIN_FTR_SECTION
193 EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
194 /*
195 * Register contents:
196 * R13 = PACA
197 * R9 = CR
198 * Original R9 to R13 is saved on PACA_EXMC
199 *
200 * Switch to mc_emergency stack and handle re-entrancy (we limit
201 * the nested MCE upto level 4 to avoid stack overflow).
202 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
203 *
204 * We use paca->in_mce to check whether this is the first entry or
205 * nested machine check. We increment paca->in_mce to track nested
206 * machine checks.
207 *
208 * If this is the first entry then set stack pointer to
209 * paca->mc_emergency_sp, otherwise r1 is already pointing to
210 * stack frame on mc_emergency stack.
211 *
212 * NOTE: We are here with MSR_ME=0 (off), which means we risk a
213 * checkstop if we get another machine check exception before we do
214 * rfid with MSR_ME=1.
215 */
216 mr r11,r1 /* Save r1 */
217 lhz r10,PACA_IN_MCE(r13)
218 cmpwi r10,0 /* Are we in nested machine check */
219 bne 0f /* Yes, we are. */
220 /* First machine check entry */
221 ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
2220: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
223 addi r10,r10,1 /* increment paca->in_mce */
224 sth r10,PACA_IN_MCE(r13)
225 /* Limit nested MCE to level 4 to avoid stack overflow */
226 cmpwi r10,4
227 bgt 2f /* Check if we hit limit of 4 */
228 std r11,GPR1(r1) /* Save r1 on the stack. */
229 std r11,0(r1) /* make stack chain pointer */
230 mfspr r11,SPRN_SRR0 /* Save SRR0 */
231 std r11,_NIP(r1)
232 mfspr r11,SPRN_SRR1 /* Save SRR1 */
233 std r11,_MSR(r1)
234 mfspr r11,SPRN_DAR /* Save DAR */
235 std r11,_DAR(r1)
236 mfspr r11,SPRN_DSISR /* Save DSISR */
237 std r11,_DSISR(r1)
238 std r9,_CCR(r1) /* Save CR in stackframe */
239 /* Save r9 through r13 from EXMC save area to stack frame. */
240 EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
241 mfmsr r11 /* get MSR value */
242 ori r11,r11,MSR_ME /* turn on ME bit */
243 ori r11,r11,MSR_RI /* turn on RI bit */
244 LOAD_HANDLER(r12, machine_check_handle_early)
2451: mtspr SPRN_SRR0,r12
246 mtspr SPRN_SRR1,r11
Nicholas Pigginefe8bc02018-02-22 23:35:44 +1100247 RFI_TO_KERNEL
Nicholas Pigginafcf0092016-09-21 17:43:31 +1000248 b . /* prevent speculative execution */
2492:
250 /* Stack overflow. Stay on emergency stack and panic.
251 * Keep the ME bit off while panic-ing, so that if we hit
252 * another machine check we checkstop.
253 */
254 addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
255 ld r11,PACAKMSR(r13)
256 LOAD_HANDLER(r12, unrecover_mce)
257 li r10,MSR_ME
258 andc r11,r11,r10 /* Turn off MSR_ME */
259 b 1b
260 b . /* prevent speculative execution */
261END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
262
263TRAMP_REAL_BEGIN(machine_check_pSeries)
264 .globl machine_check_fwnmi
265machine_check_fwnmi:
266 SET_SCRATCH0(r13) /* save r13 */
267 EXCEPTION_PROLOG_0(PACA_EXMC)
268machine_check_pSeries_0:
269 EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST_PR, 0x200)
270 /*
271 * The following is essentially EXCEPTION_PROLOG_PSERIES_1 with the
272 * difference that MSR_RI is not enabled, because PACA_EXMC is being
273 * used, so nested machine check corrupts it. machine_check_common
274 * enables MSR_RI.
275 */
276 ld r10,PACAKMSR(r13)
277 xori r10,r10,MSR_RI
278 mfspr r11,SPRN_SRR0
279 LOAD_HANDLER(r12, machine_check_common)
280 mtspr SPRN_SRR0,r12
281 mfspr r12,SPRN_SRR1
282 mtspr SPRN_SRR1,r10
Nicholas Pigginefe8bc02018-02-22 23:35:44 +1100283 RFI_TO_KERNEL
Nicholas Pigginafcf0092016-09-21 17:43:31 +1000284 b . /* prevent speculative execution */
285
286TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
287
288EXC_COMMON_BEGIN(machine_check_common)
289 /*
290 * Machine check is different because we use a different
291 * save area: PACA_EXMC instead of PACA_EXGEN.
292 */
293 mfspr r10,SPRN_DAR
294 std r10,PACA_EXMC+EX_DAR(r13)
295 mfspr r10,SPRN_DSISR
296 stw r10,PACA_EXMC+EX_DSISR(r13)
297 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
298 FINISH_NAP
299 RECONCILE_IRQ_STATE(r10, r11)
300 ld r3,PACA_EXMC+EX_DAR(r13)
301 lwz r4,PACA_EXMC+EX_DSISR(r13)
302 /* Enable MSR_RI when finished with PACA_EXMC */
303 li r10,MSR_RI
304 mtmsrd r10,1
305 std r3,_DAR(r1)
306 std r4,_DSISR(r1)
307 bl save_nvgprs
308 addi r3,r1,STACK_FRAME_OVERHEAD
309 bl machine_check_exception
310 b ret_from_except
311
312#define MACHINE_CHECK_HANDLER_WINDUP \
313 /* Clear MSR_RI before setting SRR0 and SRR1. */\
314 li r0,MSR_RI; \
315 mfmsr r9; /* get MSR value */ \
316 andc r9,r9,r0; \
317 mtmsrd r9,1; /* Clear MSR_RI */ \
318 /* Move original SRR0 and SRR1 into the respective regs */ \
319 ld r9,_MSR(r1); \
320 mtspr SPRN_SRR1,r9; \
321 ld r3,_NIP(r1); \
322 mtspr SPRN_SRR0,r3; \
323 ld r9,_CTR(r1); \
324 mtctr r9; \
325 ld r9,_XER(r1); \
326 mtxer r9; \
327 ld r9,_LINK(r1); \
328 mtlr r9; \
329 REST_GPR(0, r1); \
330 REST_8GPRS(2, r1); \
331 REST_GPR(10, r1); \
332 ld r11,_CCR(r1); \
333 mtcr r11; \
334 /* Decrement paca->in_mce. */ \
335 lhz r12,PACA_IN_MCE(r13); \
336 subi r12,r12,1; \
337 sth r12,PACA_IN_MCE(r13); \
338 REST_GPR(11, r1); \
339 REST_2GPRS(12, r1); \
340 /* restore original r1. */ \
341 ld r1,GPR1(r1)
342
343 /*
344 * Handle machine check early in real mode. We come here with
345 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
346 */
347EXC_COMMON_BEGIN(machine_check_handle_early)
348 std r0,GPR0(r1) /* Save r0 */
349 EXCEPTION_PROLOG_COMMON_3(0x200)
350 bl save_nvgprs
351 addi r3,r1,STACK_FRAME_OVERHEAD
352 bl machine_check_early
353 std r3,RESULT(r1) /* Save result */
354 ld r12,_MSR(r1)
355#ifdef CONFIG_PPC_P7_NAP
356 /*
357 * Check if thread was in power saving mode. We come here when any
358 * of the following is true:
359 * a. thread wasn't in power saving mode
360 * b. thread was in power saving mode with no state loss,
361 * supervisor state loss or hypervisor state loss.
362 *
363 * Go back to nap/sleep/winkle mode again if (b) is true.
364 */
365 rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
366 beq 4f /* No, it wasn;t */
367 /* Thread was in power saving mode. Go back to nap again. */
368 cmpwi r11,2
369 blt 3f
370 /* Supervisor/Hypervisor state loss */
371 li r0,1
372 stb r0,PACA_NAPSTATELOST(r13)
3733: bl machine_check_queue_event
374 MACHINE_CHECK_HANDLER_WINDUP
375 GET_PACA(r13)
376 ld r1,PACAR1(r13)
377 /*
378 * Check what idle state this CPU was in and go back to same mode
379 * again.
380 */
381 lbz r3,PACA_THREAD_IDLE_STATE(r13)
382 cmpwi r3,PNV_THREAD_NAP
383 bgt 10f
384 IDLE_STATE_ENTER_SEQ(PPC_NAP)
385 /* No return */
38610:
387 cmpwi r3,PNV_THREAD_SLEEP
388 bgt 2f
389 IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
390 /* No return */
391
3922:
393 /*
394 * Go back to winkle. Please note that this thread was woken up in
395 * machine check from winkle and have not restored the per-subcore
Nicholas Pigginf23ed162016-11-02 17:57:01 +1100396 * state. Hence before going back to winkle, set last bit of HSPRG0
Nicholas Pigginafcf0092016-09-21 17:43:31 +1000397 * to 1. This will make sure that if this thread gets woken up
398 * again at reset vector 0x100 then it will get chance to restore
399 * the subcore state.
400 */
401 ori r13,r13,1
402 SET_PACA(r13)
403 IDLE_STATE_ENTER_SEQ(PPC_WINKLE)
404 /* No return */
4054:
406#endif
407 /*
408 * Check if we are coming from hypervisor userspace. If yes then we
409 * continue in host kernel in V mode to deliver the MC event.
410 */
411 rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
412 beq 5f
413 andi. r11,r12,MSR_PR /* See if coming from user. */
414 bne 9f /* continue in V mode if we are. */
415
4165:
417#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
418 /*
419 * We are coming from kernel context. Check if we are coming from
420 * guest. if yes, then we can continue. We will fall through
421 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
422 */
423 lbz r11,HSTATE_IN_GUEST(r13)
424 cmpwi r11,0 /* Check if coming from guest */
425 bne 9f /* continue if we are. */
426#endif
427 /*
428 * At this point we are not sure about what context we come from.
429 * Queue up the MCE event and return from the interrupt.
430 * But before that, check if this is an un-recoverable exception.
431 * If yes, then stay on emergency stack and panic.
432 */
433 andi. r11,r12,MSR_RI
434 bne 2f
4351: mfspr r11,SPRN_SRR0
436 LOAD_HANDLER(r10,unrecover_mce)
437 mtspr SPRN_SRR0,r10
438 ld r10,PACAKMSR(r13)
439 /*
440 * We are going down. But there are chances that we might get hit by
441 * another MCE during panic path and we may run into unstable state
442 * with no way out. Hence, turn ME bit off while going down, so that
443 * when another MCE is hit during panic path, system will checkstop
444 * and hypervisor will get restarted cleanly by SP.
445 */
446 li r3,MSR_ME
447 andc r10,r10,r3 /* Turn off MSR_ME */
448 mtspr SPRN_SRR1,r10
Nicholas Pigginefe8bc02018-02-22 23:35:44 +1100449 RFI_TO_KERNEL
Nicholas Pigginafcf0092016-09-21 17:43:31 +1000450 b .
4512:
452 /*
453 * Check if we have successfully handled/recovered from error, if not
454 * then stay on emergency stack and panic.
455 */
456 ld r3,RESULT(r1) /* Load result */
457 cmpdi r3,0 /* see if we handled MCE successfully */
458
459 beq 1b /* if !handled then panic */
460 /*
461 * Return from MC interrupt.
462 * Queue up the MCE event so that we can log it later, while
463 * returning from kernel or opal call.
464 */
465 bl machine_check_queue_event
466 MACHINE_CHECK_HANDLER_WINDUP
Nicholas Pigginefe8bc02018-02-22 23:35:44 +1100467 RFI_TO_USER_OR_KERNEL
Nicholas Pigginafcf0092016-09-21 17:43:31 +10004689:
469 /* Deliver the machine check to host kernel in V mode. */
470 MACHINE_CHECK_HANDLER_WINDUP
471 b machine_check_pSeries
472
473EXC_COMMON_BEGIN(unrecover_mce)
474 /* Invoke machine_check_exception to print MCE event and panic. */
475 addi r3,r1,STACK_FRAME_OVERHEAD
476 bl machine_check_exception
477 /*
478 * We will not reach here. Even if we did, there is no way out. Call
479 * unrecoverable_exception and die.
480 */
4811: addi r3,r1,STACK_FRAME_OVERHEAD
482 bl unrecoverable_exception
483 b 1b
484
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000485
Michael Ellermanda2bc462016-09-30 19:43:18 +1000486EXC_REAL(data_access, 0x300, 0x380)
Nicholas Piggin80795e62016-09-21 17:43:32 +1000487EXC_VIRT(data_access, 0x4300, 0x4380, 0x300)
488TRAMP_KVM_SKIP(PACA_EXGEN, 0x300)
489
490EXC_COMMON_BEGIN(data_access_common)
491 /*
492 * Here r13 points to the paca, r9 contains the saved CR,
493 * SRR0 and SRR1 are saved in r11 and r12,
494 * r9 - r13 are saved in paca->exgen.
495 */
496 mfspr r10,SPRN_DAR
497 std r10,PACA_EXGEN+EX_DAR(r13)
498 mfspr r10,SPRN_DSISR
499 stw r10,PACA_EXGEN+EX_DSISR(r13)
500 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
501 RECONCILE_IRQ_STATE(r10, r11)
502 ld r12,_MSR(r1)
503 ld r3,PACA_EXGEN+EX_DAR(r13)
504 lwz r4,PACA_EXGEN+EX_DSISR(r13)
505 li r5,0x300
506 std r3,_DAR(r1)
507 std r4,_DSISR(r1)
508BEGIN_MMU_FTR_SECTION
509 b do_hash_page /* Try to handle as hpte fault */
510MMU_FTR_SECTION_ELSE
511 b handle_page_fault
512ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
513
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000514
Michael Ellermanda2bc462016-09-30 19:43:18 +1000515EXC_REAL_BEGIN(data_access_slb, 0x380, 0x400)
Paul Mackerras673b1892011-04-05 13:59:58 +1000516 SET_SCRATCH0(r13)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000517 EXCEPTION_PROLOG_0(PACA_EXSLB)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000518 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x380)
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000519 std r3,PACA_EXSLB+EX_R3(r13)
520 mfspr r3,SPRN_DAR
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000521 mfspr r12,SPRN_SRR1
Paul Mackerrasf0f558b2016-09-02 21:49:21 +1000522 crset 4*cr6+eq
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000523#ifndef CONFIG_RELOCATABLE
Anton Blanchardb1576fe2014-02-04 16:04:35 +1100524 b slb_miss_realmode
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000525#else
526 /*
Anton Blanchardad0289e2014-02-04 16:04:52 +1100527 * We can't just use a direct branch to slb_miss_realmode
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000528 * because the distance from here to there depends on where
529 * the kernel ends up being put.
530 */
531 mfctr r11
Anton Blanchardad0289e2014-02-04 16:04:52 +1100532 LOAD_HANDLER(r10, slb_miss_realmode)
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000533 mtctr r10
534 bctr
535#endif
Michael Ellermanda2bc462016-09-30 19:43:18 +1000536EXC_REAL_END(data_access_slb, 0x380, 0x400)
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000537
Nicholas Piggin2b9af6e2016-09-21 17:43:33 +1000538EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x4400)
539 SET_SCRATCH0(r13)
540 EXCEPTION_PROLOG_0(PACA_EXSLB)
541 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
542 std r3,PACA_EXSLB+EX_R3(r13)
543 mfspr r3,SPRN_DAR
544 mfspr r12,SPRN_SRR1
545 crset 4*cr6+eq
546#ifndef CONFIG_RELOCATABLE
547 b slb_miss_realmode
548#else
549 /*
550 * We can't just use a direct branch to slb_miss_realmode
551 * because the distance from here to there depends on where
552 * the kernel ends up being put.
553 */
554 mfctr r11
555 LOAD_HANDLER(r10, slb_miss_realmode)
556 mtctr r10
557 bctr
558#endif
559EXC_VIRT_END(data_access_slb, 0x4380, 0x4400)
560TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
561
562
Michael Ellermanda2bc462016-09-30 19:43:18 +1000563EXC_REAL(instruction_access, 0x400, 0x480)
Nicholas Piggin27ce77d2016-09-21 17:43:34 +1000564EXC_VIRT(instruction_access, 0x4400, 0x4480, 0x400)
565TRAMP_KVM(PACA_EXGEN, 0x400)
566
567EXC_COMMON_BEGIN(instruction_access_common)
568 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
569 RECONCILE_IRQ_STATE(r10, r11)
570 ld r12,_MSR(r1)
571 ld r3,_NIP(r1)
572 andis. r4,r12,0x5820
573 li r5,0x400
574 std r3,_DAR(r1)
575 std r4,_DSISR(r1)
576BEGIN_MMU_FTR_SECTION
577 b do_hash_page /* Try to handle as hpte fault */
578MMU_FTR_SECTION_ELSE
579 b handle_page_fault
580ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
581
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000582
Michael Ellermanda2bc462016-09-30 19:43:18 +1000583EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x500)
Paul Mackerras673b1892011-04-05 13:59:58 +1000584 SET_SCRATCH0(r13)
Paul Mackerras1707dd12013-02-04 18:10:15 +0000585 EXCEPTION_PROLOG_0(PACA_EXSLB)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000586 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000587 std r3,PACA_EXSLB+EX_R3(r13)
588 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000589 mfspr r12,SPRN_SRR1
Paul Mackerrasf0f558b2016-09-02 21:49:21 +1000590 crclr 4*cr6+eq
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000591#ifndef CONFIG_RELOCATABLE
Anton Blanchardb1576fe2014-02-04 16:04:35 +1100592 b slb_miss_realmode
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000593#else
594 mfctr r11
Anton Blanchardad0289e2014-02-04 16:04:52 +1100595 LOAD_HANDLER(r10, slb_miss_realmode)
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000596 mtctr r10
597 bctr
598#endif
Michael Ellermanda2bc462016-09-30 19:43:18 +1000599EXC_REAL_END(instruction_access_slb, 0x480, 0x500)
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000600
Nicholas Piggin8d046312016-09-21 17:43:35 +1000601EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x4500)
602 SET_SCRATCH0(r13)
603 EXCEPTION_PROLOG_0(PACA_EXSLB)
604 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
605 std r3,PACA_EXSLB+EX_R3(r13)
606 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
607 mfspr r12,SPRN_SRR1
608 crclr 4*cr6+eq
609#ifndef CONFIG_RELOCATABLE
610 b slb_miss_realmode
611#else
612 mfctr r11
613 LOAD_HANDLER(r10, slb_miss_realmode)
614 mtctr r10
615 bctr
616#endif
617EXC_VIRT_END(instruction_access_slb, 0x4480, 0x4500)
618TRAMP_KVM(PACA_EXSLB, 0x480)
619
620
621/* This handler is used by both 0x380 and 0x480 slb miss interrupts */
622EXC_COMMON_BEGIN(slb_miss_realmode)
623 /*
624 * r13 points to the PACA, r9 contains the saved CR,
625 * r12 contain the saved SRR1, SRR0 is still ready for return
626 * r3 has the faulting address
627 * r9 - r13 are saved in paca->exslb.
628 * r3 is saved in paca->slb_r3
629 * cr6.eq is set for a D-SLB miss, clear for a I-SLB miss
630 * We assume we aren't going to take any exceptions during this
631 * procedure.
632 */
633 mflr r10
634#ifdef CONFIG_RELOCATABLE
635 mtctr r11
636#endif
637
638 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
639 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
640 std r3,PACA_EXSLB+EX_DAR(r13)
641
642 crset 4*cr0+eq
643#ifdef CONFIG_PPC_STD_MMU_64
644BEGIN_MMU_FTR_SECTION
645 bl slb_allocate_realmode
646END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
647#endif
648
649 ld r10,PACA_EXSLB+EX_LR(r13)
650 ld r3,PACA_EXSLB+EX_R3(r13)
651 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
652 mtlr r10
653
654 beq 8f /* if bad address, make full stack frame */
655
656 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
657 beq- 2f
Nicholas Piggin48cc95d2018-01-10 03:07:15 +1100658 andi. r10,r12,MSR_PR /* check for user mode (PR != 0) */
659 bne 1f
Nicholas Piggin8d046312016-09-21 17:43:35 +1000660
661 /* All done -- return from exception. */
662
663.machine push
664.machine "power4"
665 mtcrf 0x80,r9
666 mtcrf 0x02,r9 /* I/D indication is in cr6 */
667 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
668.machine pop
669
670 RESTORE_PPR_PACA(PACA_EXSLB, r9)
671 ld r9,PACA_EXSLB+EX_R9(r13)
672 ld r10,PACA_EXSLB+EX_R10(r13)
673 ld r11,PACA_EXSLB+EX_R11(r13)
674 ld r12,PACA_EXSLB+EX_R12(r13)
675 ld r13,PACA_EXSLB+EX_R13(r13)
Nicholas Piggin48cc95d2018-01-10 03:07:15 +1100676 RFI_TO_KERNEL
677 b . /* prevent speculative execution */
678
6791:
680.machine push
681.machine "power4"
682 mtcrf 0x80,r9
Michael Ellerman3146a322018-02-22 23:35:43 +1100683 mtcrf 0x02,r9 /* I/D indication is in cr6 */
Nicholas Piggin48cc95d2018-01-10 03:07:15 +1100684 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
685.machine pop
686
687 RESTORE_PPR_PACA(PACA_EXSLB, r9)
688 ld r9,PACA_EXSLB+EX_R9(r13)
689 ld r10,PACA_EXSLB+EX_R10(r13)
690 ld r11,PACA_EXSLB+EX_R11(r13)
691 ld r12,PACA_EXSLB+EX_R12(r13)
692 ld r13,PACA_EXSLB+EX_R13(r13)
693 RFI_TO_USER
Nicholas Piggin8d046312016-09-21 17:43:35 +1000694 b . /* prevent speculative execution */
695
6962: mfspr r11,SPRN_SRR0
697 LOAD_HANDLER(r10,unrecov_slb)
698 mtspr SPRN_SRR0,r10
699 ld r10,PACAKMSR(r13)
700 mtspr SPRN_SRR1,r10
Nicholas Piggin48cc95d2018-01-10 03:07:15 +1100701 RFI_TO_KERNEL
Nicholas Piggin8d046312016-09-21 17:43:35 +1000702 b .
703
7048: mfspr r11,SPRN_SRR0
705 LOAD_HANDLER(r10,bad_addr_slb)
706 mtspr SPRN_SRR0,r10
707 ld r10,PACAKMSR(r13)
708 mtspr SPRN_SRR1,r10
Nicholas Pigginefe8bc02018-02-22 23:35:44 +1100709 RFI_TO_KERNEL
Nicholas Piggin8d046312016-09-21 17:43:35 +1000710 b .
711
712EXC_COMMON_BEGIN(unrecov_slb)
713 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
714 RECONCILE_IRQ_STATE(r10, r11)
715 bl save_nvgprs
7161: addi r3,r1,STACK_FRAME_OVERHEAD
717 bl unrecoverable_exception
718 b 1b
719
720EXC_COMMON_BEGIN(bad_addr_slb)
721 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
722 RECONCILE_IRQ_STATE(r10, r11)
723 ld r3, PACA_EXSLB+EX_DAR(r13)
724 std r3, _DAR(r1)
725 beq cr6, 2f
Nicholas Piggine522e2e2018-03-23 15:53:38 +1000726 li r10, 0x481 /* fix trap number for I-SLB miss */
Nicholas Piggin8d046312016-09-21 17:43:35 +1000727 std r10, _TRAP(r1)
7282: bl save_nvgprs
729 addi r3, r1, STACK_FRAME_OVERHEAD
730 bl slb_miss_bad_addr
731 b ret_from_except
732
Michael Ellermanda2bc462016-09-30 19:43:18 +1000733EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x600)
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000734 .globl hardware_interrupt_hv;
Benjamin Herrenschmidtb3e6b5d2011-04-05 14:27:11 +1000735hardware_interrupt_hv:
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000736 BEGIN_FTR_SECTION
Michael Ellermanda2bc462016-09-30 19:43:18 +1000737 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000738 EXC_HV, SOFTEN_TEST_HV)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000739do_kvm_H0x500:
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000740 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
Paul Mackerrasde56a942011-06-29 00:21:34 +0000741 FTR_SECTION_ELSE
Michael Ellermanda2bc462016-09-30 19:43:18 +1000742 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
Paul Mackerras31a40e22015-11-12 16:44:42 +1100743 EXC_STD, SOFTEN_TEST_PR)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000744do_kvm_0x500:
Paul Mackerrasde56a942011-06-29 00:21:34 +0000745 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
Paul Mackerras969391c2011-06-29 00:26:11 +0000746 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000747EXC_REAL_END(hardware_interrupt, 0x500, 0x600)
Benjamin Herrenschmidta5d4f3a2011-04-05 14:20:31 +1000748
Nicholas Pigginc138e582016-09-21 17:43:36 +1000749EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x4600)
750 .globl hardware_interrupt_relon_hv;
751hardware_interrupt_relon_hv:
752 BEGIN_FTR_SECTION
753 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_HV, SOFTEN_TEST_HV)
754 FTR_SECTION_ELSE
755 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_STD, SOFTEN_TEST_PR)
756 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
757EXC_VIRT_END(hardware_interrupt, 0x4500, 0x4600)
758
759EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
760
761
Michael Ellermanda2bc462016-09-30 19:43:18 +1000762EXC_REAL(alignment, 0x600, 0x700)
Nicholas Pigginf9aa6712016-09-21 17:43:37 +1000763EXC_VIRT(alignment, 0x4600, 0x4700, 0x600)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000764TRAMP_KVM(PACA_EXGEN, 0x600)
Nicholas Pigginf9aa6712016-09-21 17:43:37 +1000765EXC_COMMON_BEGIN(alignment_common)
766 mfspr r10,SPRN_DAR
767 std r10,PACA_EXGEN+EX_DAR(r13)
768 mfspr r10,SPRN_DSISR
769 stw r10,PACA_EXGEN+EX_DSISR(r13)
770 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
771 ld r3,PACA_EXGEN+EX_DAR(r13)
772 lwz r4,PACA_EXGEN+EX_DSISR(r13)
773 std r3,_DAR(r1)
774 std r4,_DSISR(r1)
775 bl save_nvgprs
776 RECONCILE_IRQ_STATE(r10, r11)
777 addi r3,r1,STACK_FRAME_OVERHEAD
778 bl alignment_exception
779 b ret_from_except
780
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000781
Michael Ellermanda2bc462016-09-30 19:43:18 +1000782EXC_REAL(program_check, 0x700, 0x800)
Nicholas Piggin11e87342016-09-21 17:43:38 +1000783EXC_VIRT(program_check, 0x4700, 0x4800, 0x700)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000784TRAMP_KVM(PACA_EXGEN, 0x700)
Nicholas Piggin11e87342016-09-21 17:43:38 +1000785EXC_COMMON_BEGIN(program_check_common)
Cyril Burafebf5e2017-08-17 20:42:26 +1000786 /*
787 * It's possible to receive a TM Bad Thing type program check with
788 * userspace register values (in particular r1), but with SRR1 reporting
789 * that we came from the kernel. Normally that would confuse the bad
790 * stack logic, and we would report a bad kernel stack pointer. Instead
791 * we switch to the emergency stack if we're taking a TM Bad Thing from
792 * the kernel.
793 */
794 li r10,MSR_PR /* Build a mask of MSR_PR .. */
795 oris r10,r10,0x200000@h /* .. and SRR1_PROGTM */
796 and r10,r10,r12 /* Mask SRR1 with that. */
797 srdi r10,r10,8 /* Shift it so we can compare */
798 cmpldi r10,(0x200000 >> 8) /* .. with an immediate. */
799 bne 1f /* If != go to normal path. */
800
801 /* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack */
802 andi. r10,r12,MSR_PR; /* Set CR0 correctly for label */
803 /* 3 in EXCEPTION_PROLOG_COMMON */
804 mr r10,r1 /* Save r1 */
805 ld r1,PACAEMERGSP(r13) /* Use emergency stack */
806 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
807 b 3f /* Jump into the macro !! */
8081: EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
Nicholas Piggin11e87342016-09-21 17:43:38 +1000809 bl save_nvgprs
810 RECONCILE_IRQ_STATE(r10, r11)
811 addi r3,r1,STACK_FRAME_OVERHEAD
812 bl program_check_exception
813 b ret_from_except
814
Paul Mackerrasa485c702013-04-25 17:51:40 +0000815
Michael Ellermanda2bc462016-09-30 19:43:18 +1000816EXC_REAL(fp_unavailable, 0x800, 0x900)
Nicholas Pigginc78d9b92016-09-21 17:43:39 +1000817EXC_VIRT(fp_unavailable, 0x4800, 0x4900, 0x800)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000818TRAMP_KVM(PACA_EXGEN, 0x800)
Nicholas Pigginc78d9b92016-09-21 17:43:39 +1000819EXC_COMMON_BEGIN(fp_unavailable_common)
820 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
821 bne 1f /* if from user, just load it up */
822 bl save_nvgprs
823 RECONCILE_IRQ_STATE(r10, r11)
824 addi r3,r1,STACK_FRAME_OVERHEAD
825 bl kernel_fp_unavailable_exception
826 BUG_OPCODE
8271:
828#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
829BEGIN_FTR_SECTION
830 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
831 * transaction), go do TM stuff
832 */
833 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
834 bne- 2f
835END_FTR_SECTION_IFSET(CPU_FTR_TM)
836#endif
837 bl load_up_fpu
838 b fast_exception_return
839#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
8402: /* User process was in a transaction */
841 bl save_nvgprs
842 RECONCILE_IRQ_STATE(r10, r11)
843 addi r3,r1,STACK_FRAME_OVERHEAD
844 bl fp_unavailable_tm
845 b ret_from_except
846#endif
847
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000848
Nicholas Piggine9b911a2018-06-02 21:09:08 +1000849EXC_REAL_OOL_MASKABLE(decrementer, 0x900, 0x980)
Nicholas Piggin39c0da52016-09-21 17:43:40 +1000850EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x4980, 0x900)
851TRAMP_KVM(PACA_EXGEN, 0x900)
852EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
853
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +0000854
Michael Ellermanda2bc462016-09-30 19:43:18 +1000855EXC_REAL_HV(hdecrementer, 0x980, 0xa00)
Nicholas Pigginfacc6d72016-09-21 17:43:41 +1000856EXC_VIRT_HV(hdecrementer, 0x4980, 0x4a00, 0x980)
857TRAMP_KVM_HV(PACA_EXGEN, 0x980)
858EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
859
Michael Ellermanda2bc462016-09-30 19:43:18 +1000860
861EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0xb00)
Nicholas Pigginca243162016-09-21 17:43:42 +1000862EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x4b00, 0xa00)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000863TRAMP_KVM(PACA_EXGEN, 0xa00)
Nicholas Pigginca243162016-09-21 17:43:42 +1000864#ifdef CONFIG_PPC_DOORBELL
865EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
866#else
867EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
868#endif
869
Michael Ellermanda2bc462016-09-30 19:43:18 +1000870
871EXC_REAL(trap_0b, 0xb00, 0xc00)
Nicholas Piggin341215d2016-09-21 17:43:43 +1000872EXC_VIRT(trap_0b, 0x4b00, 0x4c00, 0xb00)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000873TRAMP_KVM(PACA_EXGEN, 0xb00)
Nicholas Piggin341215d2016-09-21 17:43:43 +1000874EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
875
Nicholas Pigginfb479e42016-10-13 13:17:14 +1100876#define LOAD_SYSCALL_HANDLER(reg) \
877 __LOAD_HANDLER(reg, system_call_common)
Nicholas Piggind807ad32016-09-21 17:43:44 +1000878
879/* Syscall routine is used twice, in reloc-off and reloc-on paths */
880#define SYSCALL_PSERIES_1 \
881BEGIN_FTR_SECTION \
882 cmpdi r0,0x1ebe ; \
883 beq- 1f ; \
884END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
885 mr r9,r13 ; \
886 GET_PACA(r13) ; \
Nicholas Piggine9b911a2018-06-02 21:09:08 +1000887 INTERRUPT_TO_KERNEL ; \
Nicholas Piggind807ad32016-09-21 17:43:44 +1000888 mfspr r11,SPRN_SRR0 ; \
8890:
890
891#define SYSCALL_PSERIES_2_RFID \
892 mfspr r12,SPRN_SRR1 ; \
893 LOAD_SYSCALL_HANDLER(r10) ; \
894 mtspr SPRN_SRR0,r10 ; \
895 ld r10,PACAKMSR(r13) ; \
896 mtspr SPRN_SRR1,r10 ; \
Nicholas Pigginefe8bc02018-02-22 23:35:44 +1100897 RFI_TO_KERNEL ; \
Nicholas Piggind807ad32016-09-21 17:43:44 +1000898 b . ; /* prevent speculative execution */
899
900#define SYSCALL_PSERIES_3 \
901 /* Fast LE/BE switch system call */ \
9021: mfspr r12,SPRN_SRR1 ; \
903 xori r12,r12,MSR_LE ; \
904 mtspr SPRN_SRR1,r12 ; \
Nicholas Pigginefe8bc02018-02-22 23:35:44 +1100905 RFI_TO_USER ; /* return to userspace */ \
Nicholas Piggind807ad32016-09-21 17:43:44 +1000906 b . ; /* prevent speculative execution */
907
908#if defined(CONFIG_RELOCATABLE)
909 /*
910 * We can't branch directly so we do it via the CTR which
911 * is volatile across system calls.
912 */
913#define SYSCALL_PSERIES_2_DIRECT \
914 LOAD_SYSCALL_HANDLER(r12) ; \
915 mtctr r12 ; \
916 mfspr r12,SPRN_SRR1 ; \
917 li r10,MSR_RI ; \
918 mtmsrd r10,1 ; \
919 bctr ;
920#else
921 /* We can branch directly */
922#define SYSCALL_PSERIES_2_DIRECT \
923 mfspr r12,SPRN_SRR1 ; \
924 li r10,MSR_RI ; \
925 mtmsrd r10,1 ; /* Set RI (EE=0) */ \
926 b system_call_common ;
927#endif
928
Michael Ellermanda2bc462016-09-30 19:43:18 +1000929EXC_REAL_BEGIN(system_call, 0xc00, 0xd00)
Suresh E. Warrier8b91a252014-11-03 15:46:42 +1100930 /*
931 * If CONFIG_KVM_BOOK3S_64_HANDLER is set, save the PPR (on systems
932 * that support it) before changing to HMT_MEDIUM. That allows the KVM
933 * code to save that value into the guest state (it is the guest's PPR
934 * value). Otherwise just change to HMT_MEDIUM as userspace has
935 * already saved the PPR.
936 */
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000937#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
938 SET_SCRATCH0(r13)
939 GET_PACA(r13)
940 std r9,PACA_EXGEN+EX_R9(r13)
Suresh E. Warrier8b91a252014-11-03 15:46:42 +1100941 OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR);
942 HMT_MEDIUM;
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000943 std r10,PACA_EXGEN+EX_R10(r13)
Suresh E. Warrier8b91a252014-11-03 15:46:42 +1100944 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r9, CPU_FTR_HAS_PPR);
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000945 mfcr r9
Michael Ellermanda2bc462016-09-30 19:43:18 +1000946 KVMTEST_PR(0xc00)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000947 GET_SCRATCH0(r13)
Suresh E. Warrier8b91a252014-11-03 15:46:42 +1100948#else
949 HMT_MEDIUM;
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000950#endif
Michael Neuling742415d2012-11-02 17:16:01 +1100951 SYSCALL_PSERIES_1
952 SYSCALL_PSERIES_2_RFID
953 SYSCALL_PSERIES_3
Michael Ellermanda2bc462016-09-30 19:43:18 +1000954EXC_REAL_END(system_call, 0xc00, 0xd00)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000955
Nicholas Piggind807ad32016-09-21 17:43:44 +1000956EXC_VIRT_BEGIN(system_call, 0x4c00, 0x4d00)
957 HMT_MEDIUM
958 SYSCALL_PSERIES_1
959 SYSCALL_PSERIES_2_DIRECT
960 SYSCALL_PSERIES_3
961EXC_VIRT_END(system_call, 0x4c00, 0x4d00)
962
Michael Ellermanda2bc462016-09-30 19:43:18 +1000963TRAMP_KVM(PACA_EXGEN, 0xc00)
964
Nicholas Piggind807ad32016-09-21 17:43:44 +1000965
Michael Ellermanda2bc462016-09-30 19:43:18 +1000966EXC_REAL(single_step, 0xd00, 0xe00)
Nicholas Pigginbc6675c2016-09-21 17:43:45 +1000967EXC_VIRT(single_step, 0x4d00, 0x4e00, 0xd00)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000968TRAMP_KVM(PACA_EXGEN, 0xd00)
Nicholas Pigginbc6675c2016-09-21 17:43:45 +1000969EXC_COMMON(single_step_common, 0xd00, single_step_exception)
Michael Ellermanda2bc462016-09-30 19:43:18 +1000970
Nicholas Piggina33532a2016-09-21 17:44:06 +1000971EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0xe20)
Nicholas Piggine0319822016-09-21 17:44:07 +1000972EXC_VIRT_NONE(0x4e00, 0x4e20)
Nicholas Pigginf5c32c12016-09-21 17:43:46 +1000973TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
974EXC_COMMON_BEGIN(h_data_storage_common)
975 mfspr r10,SPRN_HDAR
976 std r10,PACA_EXGEN+EX_DAR(r13)
977 mfspr r10,SPRN_HDSISR
978 stw r10,PACA_EXGEN+EX_DSISR(r13)
979 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
980 bl save_nvgprs
981 RECONCILE_IRQ_STATE(r10, r11)
982 addi r3,r1,STACK_FRAME_OVERHEAD
983 bl unknown_exception
984 b ret_from_except
Nicholas Pigginf5c32c12016-09-21 17:43:46 +1000985
Paul Mackerras1707dd12013-02-04 18:10:15 +0000986
Nicholas Piggina33532a2016-09-21 17:44:06 +1000987EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0xe40)
Nicholas Piggine0319822016-09-21 17:44:07 +1000988EXC_VIRT_NONE(0x4e20, 0x4e40)
Nicholas Piggin82517ca2016-09-21 17:43:47 +1000989TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
990EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
991
Paul Mackerras1707dd12013-02-04 18:10:15 +0000992
Nicholas Piggina33532a2016-09-21 17:44:06 +1000993EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0xe60)
994EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x4e60, 0xe40)
Nicholas Piggin031b4022016-09-21 17:43:48 +1000995TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
996EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
997
Paul Mackerras1707dd12013-02-04 18:10:15 +0000998
Nicholas Piggine0319822016-09-21 17:44:07 +1000999/*
1000 * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
1001 * first, and then eventaully from there to the trampoline to get into virtual
1002 * mode.
1003 */
Michael Ellermanda2bc462016-09-30 19:43:18 +10001004__EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0xe80, hmi_exception_early)
Nicholas Piggin62f9b032016-09-21 17:43:49 +10001005__TRAMP_REAL_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60)
Nicholas Piggine0319822016-09-21 17:44:07 +10001006EXC_VIRT_NONE(0x4e60, 0x4e80)
Nicholas Piggin62f9b032016-09-21 17:43:49 +10001007TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
1008TRAMP_REAL_BEGIN(hmi_exception_early)
1009 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
1010 mr r10,r1 /* Save r1 */
1011 ld r1,PACAEMERGSP(r13) /* Use emergency stack */
1012 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
1013 std r9,_CCR(r1) /* save CR in stackframe */
1014 mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
1015 std r11,_NIP(r1) /* save HSRR0 in stackframe */
1016 mfspr r12,SPRN_HSRR1 /* Save SRR1 */
1017 std r12,_MSR(r1) /* save SRR1 in stackframe */
1018 std r10,0(r1) /* make stack chain pointer */
1019 std r0,GPR0(r1) /* save r0 in stackframe */
1020 std r10,GPR1(r1) /* save r1 in stackframe */
1021 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1022 EXCEPTION_PROLOG_COMMON_3(0xe60)
1023 addi r3,r1,STACK_FRAME_OVERHEAD
1024 bl hmi_exception_realmode
1025 /* Windup the stack. */
1026 /* Move original HSRR0 and HSRR1 into the respective regs */
1027 ld r9,_MSR(r1)
1028 mtspr SPRN_HSRR1,r9
1029 ld r3,_NIP(r1)
1030 mtspr SPRN_HSRR0,r3
1031 ld r9,_CTR(r1)
1032 mtctr r9
1033 ld r9,_XER(r1)
1034 mtxer r9
1035 ld r9,_LINK(r1)
1036 mtlr r9
1037 REST_GPR(0, r1)
1038 REST_8GPRS(2, r1)
1039 REST_GPR(10, r1)
1040 ld r11,_CCR(r1)
1041 mtcr r11
1042 REST_GPR(11, r1)
1043 REST_2GPRS(12, r1)
1044 /* restore original r1. */
1045 ld r1,GPR1(r1)
1046
1047 /*
1048 * Go to virtual mode and pull the HMI event information from
1049 * firmware.
1050 */
1051 .globl hmi_exception_after_realmode
1052hmi_exception_after_realmode:
1053 SET_SCRATCH0(r13)
1054 EXCEPTION_PROLOG_0(PACA_EXGEN)
1055 b tramp_real_hmi_exception
1056
1057EXC_COMMON_ASYNC(hmi_exception_common, 0xe60, handle_hmi_exception)
1058
Paul Mackerras1707dd12013-02-04 18:10:15 +00001059
Nicholas Piggina33532a2016-09-21 17:44:06 +10001060EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0xea0)
1061EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x4ea0, 0xe80)
Nicholas Piggin9bcb81b2016-09-21 17:43:50 +10001062TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
1063#ifdef CONFIG_PPC_DOORBELL
1064EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
1065#else
1066EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
1067#endif
1068
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001069
Nicholas Piggina33532a2016-09-21 17:44:06 +10001070EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0xec0)
1071EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x4ec0, 0xea0)
Nicholas Piggin74408772016-09-21 17:43:51 +10001072TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
1073EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
1074
Benjamin Herrenschmidt9baaef0a2016-07-08 16:37:06 +10001075
Michael Ellermanda2bc462016-09-30 19:43:18 +10001076EXC_REAL_NONE(0xec0, 0xf00)
Nicholas Pigginbda7fea2016-09-21 17:43:52 +10001077EXC_VIRT_NONE(0x4ec0, 0x4f00)
1078
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001079
Nicholas Piggina33532a2016-09-21 17:44:06 +10001080EXC_REAL_OOL(performance_monitor, 0xf00, 0xf20)
1081EXC_VIRT_OOL(performance_monitor, 0x4f00, 0x4f20, 0xf00)
Nicholas Pigginb1c7f152016-09-21 17:43:53 +10001082TRAMP_KVM(PACA_EXGEN, 0xf00)
1083EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
1084
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001085
Nicholas Piggina33532a2016-09-21 17:44:06 +10001086EXC_REAL_OOL(altivec_unavailable, 0xf20, 0xf40)
1087EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x4f40, 0xf20)
Nicholas Piggind1a0ca92016-09-21 17:43:54 +10001088TRAMP_KVM(PACA_EXGEN, 0xf20)
1089EXC_COMMON_BEGIN(altivec_unavailable_common)
1090 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1091#ifdef CONFIG_ALTIVEC
1092BEGIN_FTR_SECTION
1093 beq 1f
1094#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1095 BEGIN_FTR_SECTION_NESTED(69)
1096 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1097 * transaction), go do TM stuff
1098 */
1099 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1100 bne- 2f
1101 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1102#endif
1103 bl load_up_altivec
1104 b fast_exception_return
1105#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
11062: /* User process was in a transaction */
1107 bl save_nvgprs
1108 RECONCILE_IRQ_STATE(r10, r11)
1109 addi r3,r1,STACK_FRAME_OVERHEAD
1110 bl altivec_unavailable_tm
1111 b ret_from_except
1112#endif
11131:
1114END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1115#endif
1116 bl save_nvgprs
1117 RECONCILE_IRQ_STATE(r10, r11)
1118 addi r3,r1,STACK_FRAME_OVERHEAD
1119 bl altivec_unavailable_exception
1120 b ret_from_except
1121
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001122
Nicholas Piggina33532a2016-09-21 17:44:06 +10001123EXC_REAL_OOL(vsx_unavailable, 0xf40, 0xf60)
1124EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x4f60, 0xf40)
Nicholas Piggin792cbdd2016-09-21 17:43:55 +10001125TRAMP_KVM(PACA_EXGEN, 0xf40)
1126EXC_COMMON_BEGIN(vsx_unavailable_common)
1127 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1128#ifdef CONFIG_VSX
1129BEGIN_FTR_SECTION
1130 beq 1f
1131#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1132 BEGIN_FTR_SECTION_NESTED(69)
1133 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1134 * transaction), go do TM stuff
1135 */
1136 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1137 bne- 2f
1138 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1139#endif
1140 b load_up_vsx
1141#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
11422: /* User process was in a transaction */
1143 bl save_nvgprs
1144 RECONCILE_IRQ_STATE(r10, r11)
1145 addi r3,r1,STACK_FRAME_OVERHEAD
1146 bl vsx_unavailable_tm
1147 b ret_from_except
1148#endif
11491:
1150END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1151#endif
1152 bl save_nvgprs
1153 RECONCILE_IRQ_STATE(r10, r11)
1154 addi r3,r1,STACK_FRAME_OVERHEAD
1155 bl vsx_unavailable_exception
1156 b ret_from_except
1157
Michael Neulingd0c0c9a2013-02-13 16:21:38 +00001158
Nicholas Piggina33532a2016-09-21 17:44:06 +10001159EXC_REAL_OOL(facility_unavailable, 0xf60, 0xf80)
1160EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x4f80, 0xf60)
Nicholas Piggin11347132016-09-21 17:43:56 +10001161TRAMP_KVM(PACA_EXGEN, 0xf60)
1162EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
1163
Michael Ellermanda2bc462016-09-30 19:43:18 +10001164
Nicholas Piggina33532a2016-09-21 17:44:06 +10001165EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0xfa0)
1166EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x4fa0, 0xf80)
Nicholas Piggin14b00722016-09-21 17:43:57 +10001167TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
1168EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
1169
Michael Ellermanda2bc462016-09-30 19:43:18 +10001170
1171EXC_REAL_NONE(0xfa0, 0x1200)
Nicholas Piggine46b9642016-09-21 17:43:58 +10001172EXC_VIRT_NONE(0x4fa0, 0x5200)
Michael Ellermanda2bc462016-09-30 19:43:18 +10001173
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001174#ifdef CONFIG_CBE_RAS
Michael Ellermanda2bc462016-09-30 19:43:18 +10001175EXC_REAL_HV(cbe_system_error, 0x1200, 0x1300)
Nicholas Pigginff1b3202016-09-21 17:43:59 +10001176EXC_VIRT_NONE(0x5200, 0x5300)
Michael Ellermanda2bc462016-09-30 19:43:18 +10001177TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
Nicholas Pigginff1b3202016-09-21 17:43:59 +10001178EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
Michael Ellermanda2bc462016-09-30 19:43:18 +10001179#else /* CONFIG_CBE_RAS */
1180EXC_REAL_NONE(0x1200, 0x1300)
Nicholas Piggine0319822016-09-21 17:44:07 +10001181EXC_VIRT_NONE(0x5200, 0x5300)
Michael Ellermanda2bc462016-09-30 19:43:18 +10001182#endif
1183
Nicholas Pigginff1b3202016-09-21 17:43:59 +10001184
Michael Ellermanda2bc462016-09-30 19:43:18 +10001185EXC_REAL(instruction_breakpoint, 0x1300, 0x1400)
Nicholas Piggin4e96dbb2016-09-21 17:44:00 +10001186EXC_VIRT(instruction_breakpoint, 0x5300, 0x5400, 0x1300)
Michael Ellermanda2bc462016-09-30 19:43:18 +10001187TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
Nicholas Piggin4e96dbb2016-09-21 17:44:00 +10001188EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
1189
Nicholas Piggine0319822016-09-21 17:44:07 +10001190EXC_REAL_NONE(0x1400, 0x1500)
1191EXC_VIRT_NONE(0x5400, 0x5500)
Michael Ellermanda2bc462016-09-30 19:43:18 +10001192
1193EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x1600)
Michael Neulingb92a66a2012-09-10 00:35:26 +00001194 mtspr SPRN_SPRG_HSCRATCH0,r13
Paul Mackerras1707dd12013-02-04 18:10:15 +00001195 EXCEPTION_PROLOG_0(PACA_EXGEN)
Paul Mackerras630573c2013-08-12 16:12:06 +10001196 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
Michael Neulingb92a66a2012-09-10 00:35:26 +00001197
1198#ifdef CONFIG_PPC_DENORMALISATION
1199 mfspr r10,SPRN_HSRR1
1200 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
1201 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
1202 addi r11,r11,-4 /* HSRR0 is next instruction */
1203 bne+ denorm_assist
1204#endif
1205
Michael Ellermanda2bc462016-09-30 19:43:18 +10001206 KVMTEST_PR(0x1500)
Michael Neulingb92a66a2012-09-10 00:35:26 +00001207 EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
Michael Ellermanda2bc462016-09-30 19:43:18 +10001208EXC_REAL_END(denorm_exception_hv, 0x1500, 0x1600)
1209
Nicholas Piggind7e89842016-09-21 17:44:01 +10001210#ifdef CONFIG_PPC_DENORMALISATION
1211EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x5600)
1212 b exc_real_0x1500_denorm_exception_hv
1213EXC_VIRT_END(denorm_exception, 0x5500, 0x5600)
1214#else
1215EXC_VIRT_NONE(0x5500, 0x5600)
1216#endif
1217
Michael Ellermanda2bc462016-09-30 19:43:18 +10001218TRAMP_KVM_SKIP(PACA_EXGEN, 0x1500)
Michael Neulingb92a66a2012-09-10 00:35:26 +00001219
Michael Neulingb92a66a2012-09-10 00:35:26 +00001220#ifdef CONFIG_PPC_DENORMALISATION
Michael Ellermanda2bc462016-09-30 19:43:18 +10001221TRAMP_REAL_BEGIN(denorm_assist)
Michael Neulingb92a66a2012-09-10 00:35:26 +00001222BEGIN_FTR_SECTION
1223/*
1224 * To denormalise we need to move a copy of the register to itself.
1225 * For POWER6 do that here for all FP regs.
1226 */
1227 mfmsr r10
1228 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
1229 xori r10,r10,(MSR_FE0|MSR_FE1)
1230 mtmsrd r10
1231 sync
Michael Neulingd7c67fb2013-05-29 21:33:18 +00001232
1233#define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
1234#define FMR4(n) FMR2(n) ; FMR2(n+2)
1235#define FMR8(n) FMR4(n) ; FMR4(n+4)
1236#define FMR16(n) FMR8(n) ; FMR8(n+8)
1237#define FMR32(n) FMR16(n) ; FMR16(n+16)
1238 FMR32(0)
1239
Michael Neulingb92a66a2012-09-10 00:35:26 +00001240FTR_SECTION_ELSE
1241/*
1242 * To denormalise we need to move a copy of the register to itself.
1243 * For POWER7 do that here for the first 32 VSX registers only.
1244 */
1245 mfmsr r10
1246 oris r10,r10,MSR_VSX@h
1247 mtmsrd r10
1248 sync
Michael Neulingd7c67fb2013-05-29 21:33:18 +00001249
1250#define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
1251#define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
1252#define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
1253#define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
1254#define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
1255 XVCPSGNDP32(0)
1256
Michael Neulingb92a66a2012-09-10 00:35:26 +00001257ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
Michael Neulingfb0fce32013-05-29 21:33:19 +00001258
1259BEGIN_FTR_SECTION
1260 b denorm_done
1261END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
1262/*
1263 * To denormalise we need to move a copy of the register to itself.
1264 * For POWER8 we need to do that for all 64 VSX registers
1265 */
1266 XVCPSGNDP32(32)
1267denorm_done:
Michael Neulingb92a66a2012-09-10 00:35:26 +00001268 mtspr SPRN_HSRR0,r11
1269 mtcrf 0x80,r9
1270 ld r9,PACA_EXGEN+EX_R9(r13)
Haren Myneni44e93092012-12-06 21:51:04 +00001271 RESTORE_PPR_PACA(PACA_EXGEN, r10)
Paul Mackerras630573c2013-08-12 16:12:06 +10001272BEGIN_FTR_SECTION
1273 ld r10,PACA_EXGEN+EX_CFAR(r13)
1274 mtspr SPRN_CFAR,r10
1275END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
Michael Neulingb92a66a2012-09-10 00:35:26 +00001276 ld r10,PACA_EXGEN+EX_R10(r13)
1277 ld r11,PACA_EXGEN+EX_R11(r13)
1278 ld r12,PACA_EXGEN+EX_R12(r13)
1279 ld r13,PACA_EXGEN+EX_R13(r13)
Nicholas Pigginefe8bc02018-02-22 23:35:44 +11001280 HRFI_TO_UNKNOWN
Michael Neulingb92a66a2012-09-10 00:35:26 +00001281 b .
1282#endif
1283
Nicholas Piggind7e89842016-09-21 17:44:01 +10001284EXC_COMMON_HV(denorm_common, 0x1500, unknown_exception)
1285
1286
1287#ifdef CONFIG_CBE_RAS
1288EXC_REAL_HV(cbe_maintenance, 0x1600, 0x1700)
Nicholas Piggin69a79342016-09-21 17:44:02 +10001289EXC_VIRT_NONE(0x5600, 0x5700)
Nicholas Piggind7e89842016-09-21 17:44:01 +10001290TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
Nicholas Piggin69a79342016-09-21 17:44:02 +10001291EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
Nicholas Piggind7e89842016-09-21 17:44:01 +10001292#else /* CONFIG_CBE_RAS */
1293EXC_REAL_NONE(0x1600, 0x1700)
Nicholas Piggine0319822016-09-21 17:44:07 +10001294EXC_VIRT_NONE(0x5600, 0x5700)
Nicholas Piggind7e89842016-09-21 17:44:01 +10001295#endif
1296
Nicholas Piggin69a79342016-09-21 17:44:02 +10001297
Nicholas Piggind7e89842016-09-21 17:44:01 +10001298EXC_REAL(altivec_assist, 0x1700, 0x1800)
Nicholas Pigginb51c0792016-09-21 17:44:03 +10001299EXC_VIRT(altivec_assist, 0x5700, 0x5800, 0x1700)
Nicholas Piggind7e89842016-09-21 17:44:01 +10001300TRAMP_KVM(PACA_EXGEN, 0x1700)
Nicholas Pigginb51c0792016-09-21 17:44:03 +10001301#ifdef CONFIG_ALTIVEC
1302EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
1303#else
1304EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
1305#endif
1306
Nicholas Piggind7e89842016-09-21 17:44:01 +10001307
1308#ifdef CONFIG_CBE_RAS
1309EXC_REAL_HV(cbe_thermal, 0x1800, 0x1900)
Nicholas Piggin3965f8a2016-09-21 17:44:04 +10001310EXC_VIRT_NONE(0x5800, 0x5900)
Nicholas Piggind7e89842016-09-21 17:44:01 +10001311TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
Nicholas Piggin3965f8a2016-09-21 17:44:04 +10001312EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
Nicholas Piggind7e89842016-09-21 17:44:01 +10001313#else /* CONFIG_CBE_RAS */
1314EXC_REAL_NONE(0x1800, 0x1900)
Nicholas Piggine0319822016-09-21 17:44:07 +10001315EXC_VIRT_NONE(0x5800, 0x5900)
Nicholas Piggind7e89842016-09-21 17:44:01 +10001316#endif
1317
1318
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001319/*
Ian Munsiefe9e1d52012-11-14 18:49:48 +00001320 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
1321 * - If it was a decrementer interrupt, we bump the dec to max and and return.
1322 * - If it was a doorbell we return immediately since doorbells are edge
1323 * triggered and won't automatically refire.
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +05301324 * - If it was a HMI we return immediately since we handled it in realmode
1325 * and it won't refire.
Ian Munsiefe9e1d52012-11-14 18:49:48 +00001326 * - else we hard disable and return.
1327 * This is called with r10 containing the value to OR to the paca field.
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001328 */
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +11001329#define MASKED_INTERRUPT(_H) \
1330masked_##_H##interrupt: \
1331 std r11,PACA_EXGEN+EX_R11(r13); \
1332 lbz r11,PACAIRQHAPPENED(r13); \
1333 or r11,r11,r10; \
1334 stb r11,PACAIRQHAPPENED(r13); \
Ian Munsiefe9e1d52012-11-14 18:49:48 +00001335 cmpwi r10,PACA_IRQ_DEC; \
1336 bne 1f; \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +11001337 lis r10,0x7fff; \
1338 ori r10,r10,0xffff; \
1339 mtspr SPRN_DEC,r10; \
1340 b 2f; \
Ian Munsiefe9e1d52012-11-14 18:49:48 +000013411: cmpwi r10,PACA_IRQ_DBELL; \
1342 beq 2f; \
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +05301343 cmpwi r10,PACA_IRQ_HMI; \
1344 beq 2f; \
Ian Munsiefe9e1d52012-11-14 18:49:48 +00001345 mfspr r10,SPRN_##_H##SRR1; \
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +11001346 rldicl r10,r10,48,1; /* clear MSR_EE */ \
1347 rotldi r10,r10,16; \
1348 mtspr SPRN_##_H##SRR1,r10; \
13492: mtcrf 0x80,r9; \
1350 ld r9,PACA_EXGEN+EX_R9(r13); \
1351 ld r10,PACA_EXGEN+EX_R10(r13); \
1352 ld r11,PACA_EXGEN+EX_R11(r13); \
1353 GET_SCRATCH0(r13); \
Nicholas Pigginefe8bc02018-02-22 23:35:44 +11001354 ##_H##RFI_TO_KERNEL; \
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001355 b .
Nicholas Piggin57f26642016-09-28 11:31:48 +10001356
Nicholas Piggine9b911a2018-06-02 21:09:08 +10001357TRAMP_REAL_BEGIN(stf_barrier_fallback)
1358 std r9,PACA_EXRFI+EX_R9(r13)
1359 std r10,PACA_EXRFI+EX_R10(r13)
1360 sync
1361 ld r9,PACA_EXRFI+EX_R9(r13)
1362 ld r10,PACA_EXRFI+EX_R10(r13)
1363 ori 31,31,0
1364 .rept 14
1365 b 1f
13661:
1367 .endr
1368 blr
1369
Nicholas Piggin57f26642016-09-28 11:31:48 +10001370/*
1371 * Real mode exceptions actually use this too, but alternate
1372 * instruction code patches (which end up in the common .text area)
1373 * cannot reach these if they are put there.
1374 */
1375USE_FIXED_SECTION(virt_trampolines)
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +11001376 MASKED_INTERRUPT()
1377 MASKED_INTERRUPT(H)
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001378
Paul Mackerras4f6c11d2013-09-20 14:52:50 +10001379#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
Michael Ellermanda2bc462016-09-30 19:43:18 +10001380TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
Paul Mackerras4f6c11d2013-09-20 14:52:50 +10001381 /*
1382 * Here all GPRs are unchanged from when the interrupt happened
1383 * except for r13, which is saved in SPRG_SCRATCH0.
1384 */
1385 mfspr r13, SPRN_SRR0
1386 addi r13, r13, 4
1387 mtspr SPRN_SRR0, r13
1388 GET_SCRATCH0(r13)
Nicholas Pigginefe8bc02018-02-22 23:35:44 +11001389 RFI_TO_KERNEL
Paul Mackerras4f6c11d2013-09-20 14:52:50 +10001390 b .
1391
Michael Ellermanda2bc462016-09-30 19:43:18 +10001392TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
Paul Mackerras4f6c11d2013-09-20 14:52:50 +10001393 /*
1394 * Here all GPRs are unchanged from when the interrupt happened
1395 * except for r13, which is saved in SPRG_SCRATCH0.
1396 */
1397 mfspr r13, SPRN_HSRR0
1398 addi r13, r13, 4
1399 mtspr SPRN_HSRR0, r13
1400 GET_SCRATCH0(r13)
Nicholas Pigginefe8bc02018-02-22 23:35:44 +11001401 HRFI_TO_KERNEL
Paul Mackerras4f6c11d2013-09-20 14:52:50 +10001402 b .
1403#endif
1404
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001405/*
Hari Bathini057b6d72016-04-08 03:30:34 +05301406 * Ensure that any handlers that get invoked from the exception prologs
1407 * above are below the first 64KB (0x10000) of the kernel image because
1408 * the prologs assemble the addresses of these handlers using the
1409 * LOAD_HANDLER macro, which uses an ori instruction.
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001410 */
1411
1412/*** Common interrupt handlers ***/
1413
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001414
Michael Neulingc1fb6812012-11-02 17:21:43 +11001415 /*
1416 * Relocation-on interrupts: A subset of the interrupts can be delivered
1417 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
1418 * it. Addresses are the same as the original interrupt addresses, but
1419 * offset by 0xc000000000004000.
1420 * It's impossible to receive interrupts below 0x300 via this mechanism.
1421 * KVM: None of these traps are from the guest ; anything that escalated
1422 * to HV=1 from HV=0 is delivered via real mode handlers.
1423 */
1424
1425 /*
1426 * This uses the standard macro, since the original 0x300 vector
1427 * only has extra guff for STAB-based processors -- which never
1428 * come here.
1429 */
Michael Ellermanda2bc462016-09-30 19:43:18 +10001430
Nicholas Piggin57f26642016-09-28 11:31:48 +10001431EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
Anton Blanchardb1576fe2014-02-04 16:04:35 +11001432 b __ppc64_runlatch_on
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +11001433
Nicholas Piggin57f26642016-09-28 11:31:48 +10001434USE_FIXED_SECTION(virt_trampolines)
Hari Bathini8ed8ab42016-04-15 22:48:02 +10001435 /*
1436 * The __end_interrupts marker must be past the out-of-line (OOL)
1437 * handlers, so that they are copied to real address 0x100 when running
1438 * a relocatable kernel. This ensures they can be reached from the short
1439 * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
1440 * directly, without using LOAD_HANDLER().
1441 */
1442 .align 7
1443 .globl __end_interrupts
1444__end_interrupts:
Nicholas Piggin57f26642016-09-28 11:31:48 +10001445DEFINE_FIXED_SYMBOL(__end_interrupts)
Benjamin Herrenschmidt61383402013-01-10 17:44:19 +11001446
Chen Gang087aa032013-03-25 09:31:31 +08001447#ifdef CONFIG_PPC_970_NAP
Nicholas Piggin7c8cb4b2016-10-11 18:47:56 +11001448EXC_COMMON_BEGIN(power4_fixup_nap)
Chen Gang087aa032013-03-25 09:31:31 +08001449 andc r9,r9,r10
1450 std r9,TI_LOCAL_FLAGS(r11)
1451 ld r10,_LINK(r1) /* make idle task do the */
1452 std r10,_NIP(r1) /* equivalent of a blr */
1453 blr
1454#endif
1455
Nicholas Piggin57f26642016-09-28 11:31:48 +10001456CLOSE_FIXED_SECTION(real_vectors);
1457CLOSE_FIXED_SECTION(real_trampolines);
1458CLOSE_FIXED_SECTION(virt_vectors);
1459CLOSE_FIXED_SECTION(virt_trampolines);
1460
1461USE_TEXT_SECTION()
1462
Chen Gang087aa032013-03-25 09:31:31 +08001463/*
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001464 * Hash table stuff
1465 */
1466 .align 7
Anton Blanchard6a3bab92014-02-04 16:06:11 +11001467do_hash_page:
Aneesh Kumar K.Vcaca2852016-04-29 23:26:07 +10001468#ifdef CONFIG_PPC_STD_MMU_64
Naveen N. Rao8eaa4812017-06-14 00:12:00 +05301469 andis. r0,r4,0xa450 /* weird error? */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001470 bne- handle_page_fault /* if not, try to insert a HPTE */
Stuart Yoder9778b692012-07-05 04:41:35 +00001471 CURRENT_THREAD_INFO(r11, r1)
Paul Mackerras9c1e1052009-08-17 15:17:54 +10001472 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
1473 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
1474 bne 77f /* then don't call hash_page now */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001475
1476 /*
1477 * r3 contains the faulting address
Aneesh Kumar K.V106713a2015-12-01 09:06:44 +05301478 * r4 msr
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001479 * r5 contains the trap number
Aneesh Kumar K.Vaefa5682014-12-04 11:00:14 +05301480 * r6 contains dsisr
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001481 *
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +11001482 * at return r3 = 0 for success, 1 for page fault, negative for error
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001483 */
Aneesh Kumar K.V106713a2015-12-01 09:06:44 +05301484 mr r4,r12
Aneesh Kumar K.Vaefa5682014-12-04 11:00:14 +05301485 ld r6,_DSISR(r1)
Aneesh Kumar K.V106713a2015-12-01 09:06:44 +05301486 bl __hash_page /* build HPTE if possible */
1487 cmpdi r3,0 /* see if __hash_page succeeded */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001488
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +11001489 /* Success */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001490 beq fast_exc_return_irq /* Return from exception on success */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001491
Benjamin Herrenschmidt7230c562012-03-06 18:27:59 +11001492 /* Error */
1493 blt- 13f
Naveen N. Rao8eaa4812017-06-14 00:12:00 +05301494
1495 /* Reload DSISR into r4 for the DABR check below */
1496 ld r4,_DSISR(r1)
Aneesh Kumar K.Vcaca2852016-04-29 23:26:07 +10001497#endif /* CONFIG_PPC_STD_MMU_64 */
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001498
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +11001499/* Here we have a page fault that hash_page can't handle. */
1500handle_page_fault:
Naveen N. Rao8eaa4812017-06-14 00:12:00 +0530150111: andis. r0,r4,DSISR_DABRMATCH@h
1502 bne- handle_dabr_fault
1503 ld r4,_DAR(r1)
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +11001504 ld r5,_DSISR(r1)
1505 addi r3,r1,STACK_FRAME_OVERHEAD
Anton Blanchardb1576fe2014-02-04 16:04:35 +11001506 bl do_page_fault
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +11001507 cmpdi r3,0
1508 beq+ 12f
Anton Blanchardb1576fe2014-02-04 16:04:35 +11001509 bl save_nvgprs
Benjamin Herrenschmidta5464982012-03-07 16:48:45 +11001510 mr r5,r3
1511 addi r3,r1,STACK_FRAME_OVERHEAD
1512 lwz r4,_DAR(r1)
Anton Blanchardb1576fe2014-02-04 16:04:35 +11001513 bl bad_page_fault
1514 b ret_from_except
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001515
K.Prasad9c7cc232010-03-29 23:59:25 +00001516/* We have a data breakpoint exception - handle it */
1517handle_dabr_fault:
Anton Blanchardb1576fe2014-02-04 16:04:35 +11001518 bl save_nvgprs
K.Prasad9c7cc232010-03-29 23:59:25 +00001519 ld r4,_DAR(r1)
1520 ld r5,_DSISR(r1)
1521 addi r3,r1,STACK_FRAME_OVERHEAD
Anton Blanchardb1576fe2014-02-04 16:04:35 +11001522 bl do_break
152312: b ret_from_except_lite
K.Prasad9c7cc232010-03-29 23:59:25 +00001524
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001525
Aneesh Kumar K.Vcaca2852016-04-29 23:26:07 +10001526#ifdef CONFIG_PPC_STD_MMU_64
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001527/* We have a page fault that hash_page could handle but HV refused
1528 * the PTE insertion
1529 */
Anton Blanchardb1576fe2014-02-04 16:04:35 +1100153013: bl save_nvgprs
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001531 mr r5,r3
1532 addi r3,r1,STACK_FRAME_OVERHEAD
1533 ld r4,_DAR(r1)
Anton Blanchardb1576fe2014-02-04 16:04:35 +11001534 bl low_hash_fault
1535 b ret_from_except
Aneesh Kumar K.Vcaca2852016-04-29 23:26:07 +10001536#endif
Benjamin Herrenschmidt0ebc4cd2009-06-02 21:17:38 +00001537
Paul Mackerras9c1e1052009-08-17 15:17:54 +10001538/*
1539 * We come here as a result of a DSI at a point where we don't want
1540 * to call hash_page, such as when we are accessing memory (possibly
1541 * user memory) inside a PMU interrupt that occurred while interrupts
1542 * were soft-disabled. We want to invoke the exception handler for
1543 * the access, or panic if there isn't a handler.
1544 */
Anton Blanchardb1576fe2014-02-04 16:04:35 +1100154577: bl save_nvgprs
Paul Mackerras9c1e1052009-08-17 15:17:54 +10001546 mr r4,r3
1547 addi r3,r1,STACK_FRAME_OVERHEAD
1548 li r5,SIGSEGV
Anton Blanchardb1576fe2014-02-04 16:04:35 +11001549 bl bad_page_fault
1550 b ret_from_except
Michael Ellerman4e2bf012014-07-15 20:25:02 +10001551
1552/*
1553 * Here we have detected that the kernel stack pointer is bad.
1554 * R9 contains the saved CR, r13 points to the paca,
1555 * r10 contains the (bad) kernel stack pointer,
1556 * r11 and r12 contain the saved SRR0 and SRR1.
1557 * We switch to using an emergency stack, save the registers there,
1558 * and call kernel_bad_stack(), which panics.
1559 */
1560bad_stack:
1561 ld r1,PACAEMERGSP(r13)
1562 subi r1,r1,64+INT_FRAME_SIZE
1563 std r9,_CCR(r1)
1564 std r10,GPR1(r1)
1565 std r11,_NIP(r1)
1566 std r12,_MSR(r1)
1567 mfspr r11,SPRN_DAR
1568 mfspr r12,SPRN_DSISR
1569 std r11,_DAR(r1)
1570 std r12,_DSISR(r1)
1571 mflr r10
1572 mfctr r11
1573 mfxer r12
1574 std r10,_LINK(r1)
1575 std r11,_CTR(r1)
1576 std r12,_XER(r1)
1577 SAVE_GPR(0,r1)
1578 SAVE_GPR(2,r1)
1579 ld r10,EX_R3(r3)
1580 std r10,GPR3(r1)
1581 SAVE_GPR(4,r1)
1582 SAVE_4GPRS(5,r1)
1583 ld r9,EX_R9(r3)
1584 ld r10,EX_R10(r3)
1585 SAVE_2GPRS(9,r1)
1586 ld r9,EX_R11(r3)
1587 ld r10,EX_R12(r3)
1588 ld r11,EX_R13(r3)
1589 std r9,GPR11(r1)
1590 std r10,GPR12(r1)
1591 std r11,GPR13(r1)
1592BEGIN_FTR_SECTION
1593 ld r10,EX_CFAR(r3)
1594 std r10,ORIG_GPR3(r1)
1595END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1596 SAVE_8GPRS(14,r1)
1597 SAVE_10GPRS(22,r1)
1598 lhz r12,PACA_TRAP_SAVE(r13)
1599 std r12,_TRAP(r1)
1600 addi r11,r1,INT_FRAME_SIZE
1601 std r11,0(r1)
1602 li r12,0
1603 std r12,0(r11)
1604 ld r2,PACATOC(r13)
1605 ld r11,exception_marker@toc(r2)
1606 std r12,RESULT(r1)
1607 std r11,STACK_FRAME_OVERHEAD-16(r1)
16081: addi r3,r1,STACK_FRAME_OVERHEAD
1609 bl kernel_bad_stack
1610 b 1b
Nicholas Piggin0f0c6ca2016-09-21 17:44:05 +10001611
Michael Ellermanc3b82eb2018-01-10 03:07:15 +11001612 .globl rfi_flush_fallback
1613rfi_flush_fallback:
1614 SET_SCRATCH0(r13);
1615 GET_PACA(r13);
1616 std r9,PACA_EXRFI+EX_R9(r13)
1617 std r10,PACA_EXRFI+EX_R10(r13)
1618 std r11,PACA_EXRFI+EX_R11(r13)
Michael Ellermanc3b82eb2018-01-10 03:07:15 +11001619 mfctr r9
1620 ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
Nicholas Pigginec0084d2018-02-22 23:35:45 +11001621 ld r11,PACA_L1D_FLUSH_SIZE(r13)
1622 srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
Michael Ellermanc3b82eb2018-01-10 03:07:15 +11001623 mtctr r11
1624 DCBT_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
1625
1626 /* order ld/st prior to dcbt stop all streams with flushing */
1627 sync
Nicholas Pigginec0084d2018-02-22 23:35:45 +11001628
1629 /*
1630 * The load adresses are at staggered offsets within cachelines,
1631 * which suits some pipelines better (on others it should not
1632 * hurt).
1633 */
16341:
1635 ld r11,(0x80 + 8)*0(r10)
1636 ld r11,(0x80 + 8)*1(r10)
1637 ld r11,(0x80 + 8)*2(r10)
1638 ld r11,(0x80 + 8)*3(r10)
1639 ld r11,(0x80 + 8)*4(r10)
1640 ld r11,(0x80 + 8)*5(r10)
1641 ld r11,(0x80 + 8)*6(r10)
1642 ld r11,(0x80 + 8)*7(r10)
1643 addi r10,r10,0x80*8
Michael Ellermanc3b82eb2018-01-10 03:07:15 +11001644 bdnz 1b
1645
1646 mtctr r9
1647 ld r9,PACA_EXRFI+EX_R9(r13)
1648 ld r10,PACA_EXRFI+EX_R10(r13)
1649 ld r11,PACA_EXRFI+EX_R11(r13)
Michael Ellermanc3b82eb2018-01-10 03:07:15 +11001650 GET_SCRATCH0(r13);
1651 rfid
1652
1653 .globl hrfi_flush_fallback
1654hrfi_flush_fallback:
1655 SET_SCRATCH0(r13);
1656 GET_PACA(r13);
1657 std r9,PACA_EXRFI+EX_R9(r13)
1658 std r10,PACA_EXRFI+EX_R10(r13)
1659 std r11,PACA_EXRFI+EX_R11(r13)
Michael Ellermanc3b82eb2018-01-10 03:07:15 +11001660 mfctr r9
1661 ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
Nicholas Pigginec0084d2018-02-22 23:35:45 +11001662 ld r11,PACA_L1D_FLUSH_SIZE(r13)
1663 srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
Michael Ellermanc3b82eb2018-01-10 03:07:15 +11001664 mtctr r11
1665 DCBT_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
1666
1667 /* order ld/st prior to dcbt stop all streams with flushing */
1668 sync
Nicholas Pigginec0084d2018-02-22 23:35:45 +11001669
1670 /*
1671 * The load adresses are at staggered offsets within cachelines,
1672 * which suits some pipelines better (on others it should not
1673 * hurt).
1674 */
16751:
1676 ld r11,(0x80 + 8)*0(r10)
1677 ld r11,(0x80 + 8)*1(r10)
1678 ld r11,(0x80 + 8)*2(r10)
1679 ld r11,(0x80 + 8)*3(r10)
1680 ld r11,(0x80 + 8)*4(r10)
1681 ld r11,(0x80 + 8)*5(r10)
1682 ld r11,(0x80 + 8)*6(r10)
1683 ld r11,(0x80 + 8)*7(r10)
1684 addi r10,r10,0x80*8
Michael Ellermanc3b82eb2018-01-10 03:07:15 +11001685 bdnz 1b
1686
1687 mtctr r9
1688 ld r9,PACA_EXRFI+EX_R9(r13)
1689 ld r10,PACA_EXRFI+EX_R10(r13)
1690 ld r11,PACA_EXRFI+EX_R11(r13)
Michael Ellermanc3b82eb2018-01-10 03:07:15 +11001691 GET_SCRATCH0(r13);
1692 hrfid
1693
Nicholas Piggin0f0c6ca2016-09-21 17:44:05 +10001694/*
1695 * Called from arch_local_irq_enable when an interrupt needs
1696 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
1697 * which kind of interrupt. MSR:EE is already off. We generate a
1698 * stackframe like if a real interrupt had happened.
1699 *
1700 * Note: While MSR:EE is off, we need to make sure that _MSR
1701 * in the generated frame has EE set to 1 or the exception
1702 * handler will not properly re-enable them.
1703 */
1704_GLOBAL(__replay_interrupt)
1705 /* We are going to jump to the exception common code which
1706 * will retrieve various register values from the PACA which
1707 * we don't give a damn about, so we don't bother storing them.
1708 */
1709 mfmsr r12
1710 mflr r11
1711 mfcr r9
1712 ori r12,r12,MSR_EE
1713 cmpwi r3,0x900
1714 beq decrementer_common
1715 cmpwi r3,0x500
1716 beq hardware_interrupt_common
1717BEGIN_FTR_SECTION
1718 cmpwi r3,0xe80
1719 beq h_doorbell_common
1720 cmpwi r3,0xea0
1721 beq h_virt_irq_common
1722 cmpwi r3,0xe60
1723 beq hmi_exception_common
1724FTR_SECTION_ELSE
1725 cmpwi r3,0xa00
1726 beq doorbell_super_common
1727ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1728 blr