]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/powerpc/kernel/exceptions-64s.S
powerpc/64: Free up CPU_FTR_ICSWX
[mirror_ubuntu-bionic-kernel.git] / arch / powerpc / kernel / exceptions-64s.S
CommitLineData
0ebc4cda
BH
1/*
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
25985edc 8 * position dependent assembly.
0ebc4cda
BH
9 *
10 * Most of this originates from head_64.S and thus has the same
11 * copyright history.
12 *
13 */
14
7230c564 15#include <asm/hw_irq.h>
8aa34ab8 16#include <asm/exception-64s.h>
46f52210 17#include <asm/ptrace.h>
7cba160a 18#include <asm/cpuidle.h>
da2bc464 19#include <asm/head-64.h>
8aa34ab8 20
0ebc4cda 21/*
57f26649
NP
22 * 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 *
0ebc4cda
BH
51 * We layout physical memory as follows:
52 * 0x0000 - 0x00ff : Secondary processor spin code
57f26649
NP
53 * 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
0ebc4cda 57 * 0x7000 - 0x7fff : FWNMI data area
57f26649
NP
58 * 0x8000 - .... : Common interrupt handlers, remaining early
59 * setup code, rest of kernel.
e0319829
NP
60 *
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.
57f26649
NP
64 */
65OPEN_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
0ebc4cda 75 */
57f26649
NP
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
0ebc4cda
BH
84/*
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 */
0ebc4cda
BH
92 .globl __start_interrupts
93__start_interrupts:
94
e0319829 95/* No virt vectors corresponding with 0x0..0x100 */
1a6822d1 96EXC_VIRT_NONE(0x4000, 0x100)
e0319829 97
fb479e44 98
948cf67c 99#ifdef CONFIG_PPC_P7_NAP
fb479e44
NP
100 /*
101 * If running native on arch 2.06 or later, check if we are waking up
ba6d334a
BH
102 * from nap/sleep/winkle, and branch to idle handler. This tests SRR1
103 * bits 46:47. A non-0 value indicates that we are coming from a power
104 * saving state. The idle wakeup handler initially runs in real mode,
105 * but we branch to the 0xc000... address so we can turn on relocation
106 * with mtmsr.
948cf67c 107 */
fb479e44
NP
108#define IDLETEST(n) \
109 BEGIN_FTR_SECTION ; \
110 mfspr r10,SPRN_SRR1 ; \
111 rlwinm. r10,r10,47-31,30,31 ; \
112 beq- 1f ; \
113 cmpwi cr3,r10,2 ; \
b51351e2 114 BRANCH_TO_C000(r10, system_reset_idle_common) ; \
fb479e44 1151: \
6de6638b 116 KVMTEST_PR(n) ; \
fb479e44
NP
117 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
118#else
119#define IDLETEST NOTEST
120#endif
371fefd6 121
1a6822d1 122EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
fb479e44 123 SET_SCRATCH0(r13)
c4f3b52c
NP
124 /*
125 * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is
126 * being used, so a nested NMI exception would corrupt it.
127 */
128 EXCEPTION_PROLOG_PSERIES_NORI(PACA_EXNMI, system_reset_common, EXC_STD,
fb479e44
NP
129 IDLETEST, 0x100)
130
1a6822d1
NP
131EXC_REAL_END(system_reset, 0x100, 0x100)
132EXC_VIRT_NONE(0x4100, 0x100)
6de6638b 133TRAMP_KVM(PACA_EXNMI, 0x100)
fb479e44
NP
134
135#ifdef CONFIG_PPC_P7_NAP
136EXC_COMMON_BEGIN(system_reset_idle_common)
9d292501 137 mfspr r12,SPRN_SRR1
bf0153c1 138 b pnv_powersave_wakeup
371fefd6
PM
139#endif
140
a3d96f70 141EXC_COMMON_BEGIN(system_reset_common)
c4f3b52c
NP
142 /*
143 * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able
144 * to recover, but nested NMI will notice in_nmi and not recover
145 * because of the use of the NMI stack. in_nmi reentrancy is tested in
146 * system_reset_exception.
147 */
148 lhz r10,PACA_IN_NMI(r13)
149 addi r10,r10,1
150 sth r10,PACA_IN_NMI(r13)
151 li r10,MSR_RI
152 mtmsrd r10,1
aca79d2b 153
b1ee8a3d
NP
154 mr r10,r1
155 ld r1,PACA_NMI_EMERG_SP(r13)
156 subi r1,r1,INT_FRAME_SIZE
157 EXCEPTION_COMMON_NORET_STACK(PACA_EXNMI, 0x100,
158 system_reset, system_reset_exception,
c4f3b52c 159 ADD_NVGPRS;ADD_RECONCILE)
c4f3b52c
NP
160
161 /*
162 * The stack is no longer in use, decrement in_nmi.
163 */
164 lhz r10,PACA_IN_NMI(r13)
165 subi r10,r10,1
166 sth r10,PACA_IN_NMI(r13)
167
168 b ret_from_except
582baf44
NP
169
170#ifdef CONFIG_PPC_PSERIES
171/*
172 * Vectors for the FWNMI option. Share common code.
173 */
174TRAMP_REAL_BEGIN(system_reset_fwnmi)
175 SET_SCRATCH0(r13) /* save r13 */
c4f3b52c
NP
176 /* See comment at system_reset exception */
177 EXCEPTION_PROLOG_PSERIES_NORI(PACA_EXNMI, system_reset_common,
178 EXC_STD, NOTEST, 0x100)
582baf44
NP
179#endif /* CONFIG_PPC_PSERIES */
180
0ebc4cda 181
1a6822d1 182EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
b01c8b54
PM
183 /* This is moved out of line as it can be patched by FW, but
184 * some code path might still want to branch into the original
185 * vector
186 */
1707dd16
PM
187 SET_SCRATCH0(r13) /* save r13 */
188 EXCEPTION_PROLOG_0(PACA_EXMC)
1e9b4507 189BEGIN_FTR_SECTION
2513767d 190 b machine_check_powernv_early
1e9b4507 191FTR_SECTION_ELSE
1707dd16 192 b machine_check_pSeries_0
1e9b4507 193ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1a6822d1
NP
194EXC_REAL_END(machine_check, 0x200, 0x100)
195EXC_VIRT_NONE(0x4200, 0x100)
afcf0095
NP
196TRAMP_REAL_BEGIN(machine_check_powernv_early)
197BEGIN_FTR_SECTION
198 EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
199 /*
200 * Register contents:
201 * R13 = PACA
202 * R9 = CR
203 * Original R9 to R13 is saved on PACA_EXMC
204 *
205 * Switch to mc_emergency stack and handle re-entrancy (we limit
206 * the nested MCE upto level 4 to avoid stack overflow).
207 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
208 *
209 * We use paca->in_mce to check whether this is the first entry or
210 * nested machine check. We increment paca->in_mce to track nested
211 * machine checks.
212 *
213 * If this is the first entry then set stack pointer to
214 * paca->mc_emergency_sp, otherwise r1 is already pointing to
215 * stack frame on mc_emergency stack.
216 *
217 * NOTE: We are here with MSR_ME=0 (off), which means we risk a
218 * checkstop if we get another machine check exception before we do
219 * rfid with MSR_ME=1.
1945bc45
NP
220 *
221 * This interrupt can wake directly from idle. If that is the case,
222 * the machine check is handled then the idle wakeup code is called
223 * to restore state. In that case, the POWER9 DD1 idle PACA workaround
224 * is not applied in the early machine check code, which will cause
225 * bugs.
afcf0095
NP
226 */
227 mr r11,r1 /* Save r1 */
228 lhz r10,PACA_IN_MCE(r13)
229 cmpwi r10,0 /* Are we in nested machine check */
230 bne 0f /* Yes, we are. */
231 /* First machine check entry */
232 ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
2330: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
234 addi r10,r10,1 /* increment paca->in_mce */
235 sth r10,PACA_IN_MCE(r13)
236 /* Limit nested MCE to level 4 to avoid stack overflow */
ba41e1e1 237 cmpwi r10,MAX_MCE_DEPTH
afcf0095
NP
238 bgt 2f /* Check if we hit limit of 4 */
239 std r11,GPR1(r1) /* Save r1 on the stack. */
240 std r11,0(r1) /* make stack chain pointer */
241 mfspr r11,SPRN_SRR0 /* Save SRR0 */
242 std r11,_NIP(r1)
243 mfspr r11,SPRN_SRR1 /* Save SRR1 */
244 std r11,_MSR(r1)
245 mfspr r11,SPRN_DAR /* Save DAR */
246 std r11,_DAR(r1)
247 mfspr r11,SPRN_DSISR /* Save DSISR */
248 std r11,_DSISR(r1)
249 std r9,_CCR(r1) /* Save CR in stackframe */
250 /* Save r9 through r13 from EXMC save area to stack frame. */
251 EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
252 mfmsr r11 /* get MSR value */
253 ori r11,r11,MSR_ME /* turn on ME bit */
254 ori r11,r11,MSR_RI /* turn on RI bit */
255 LOAD_HANDLER(r12, machine_check_handle_early)
2561: mtspr SPRN_SRR0,r12
257 mtspr SPRN_SRR1,r11
258 rfid
259 b . /* prevent speculative execution */
2602:
261 /* Stack overflow. Stay on emergency stack and panic.
262 * Keep the ME bit off while panic-ing, so that if we hit
263 * another machine check we checkstop.
264 */
265 addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
266 ld r11,PACAKMSR(r13)
267 LOAD_HANDLER(r12, unrecover_mce)
268 li r10,MSR_ME
269 andc r11,r11,r10 /* Turn off MSR_ME */
270 b 1b
271 b . /* prevent speculative execution */
272END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
273
274TRAMP_REAL_BEGIN(machine_check_pSeries)
275 .globl machine_check_fwnmi
276machine_check_fwnmi:
277 SET_SCRATCH0(r13) /* save r13 */
278 EXCEPTION_PROLOG_0(PACA_EXMC)
279machine_check_pSeries_0:
280 EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST_PR, 0x200)
281 /*
83a980f7
NP
282 * MSR_RI is not enabled, because PACA_EXMC is being used, so a
283 * nested machine check corrupts it. machine_check_common enables
284 * MSR_RI.
afcf0095 285 */
83a980f7 286 EXCEPTION_PROLOG_PSERIES_1_NORI(machine_check_common, EXC_STD)
afcf0095
NP
287
288TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
289
290EXC_COMMON_BEGIN(machine_check_common)
291 /*
292 * Machine check is different because we use a different
293 * save area: PACA_EXMC instead of PACA_EXGEN.
294 */
295 mfspr r10,SPRN_DAR
296 std r10,PACA_EXMC+EX_DAR(r13)
297 mfspr r10,SPRN_DSISR
298 stw r10,PACA_EXMC+EX_DSISR(r13)
299 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
300 FINISH_NAP
301 RECONCILE_IRQ_STATE(r10, r11)
302 ld r3,PACA_EXMC+EX_DAR(r13)
303 lwz r4,PACA_EXMC+EX_DSISR(r13)
304 /* Enable MSR_RI when finished with PACA_EXMC */
305 li r10,MSR_RI
306 mtmsrd r10,1
307 std r3,_DAR(r1)
308 std r4,_DSISR(r1)
309 bl save_nvgprs
310 addi r3,r1,STACK_FRAME_OVERHEAD
311 bl machine_check_exception
312 b ret_from_except
313
314#define MACHINE_CHECK_HANDLER_WINDUP \
315 /* Clear MSR_RI before setting SRR0 and SRR1. */\
316 li r0,MSR_RI; \
317 mfmsr r9; /* get MSR value */ \
318 andc r9,r9,r0; \
319 mtmsrd r9,1; /* Clear MSR_RI */ \
320 /* Move original SRR0 and SRR1 into the respective regs */ \
321 ld r9,_MSR(r1); \
322 mtspr SPRN_SRR1,r9; \
323 ld r3,_NIP(r1); \
324 mtspr SPRN_SRR0,r3; \
325 ld r9,_CTR(r1); \
326 mtctr r9; \
327 ld r9,_XER(r1); \
328 mtxer r9; \
329 ld r9,_LINK(r1); \
330 mtlr r9; \
331 REST_GPR(0, r1); \
332 REST_8GPRS(2, r1); \
333 REST_GPR(10, r1); \
334 ld r11,_CCR(r1); \
335 mtcr r11; \
336 /* Decrement paca->in_mce. */ \
337 lhz r12,PACA_IN_MCE(r13); \
338 subi r12,r12,1; \
339 sth r12,PACA_IN_MCE(r13); \
340 REST_GPR(11, r1); \
341 REST_2GPRS(12, r1); \
342 /* restore original r1. */ \
343 ld r1,GPR1(r1)
344
1945bc45
NP
345#ifdef CONFIG_PPC_P7_NAP
346/*
347 * This is an idle wakeup. Low level machine check has already been
348 * done. Queue the event then call the idle code to do the wake up.
349 */
350EXC_COMMON_BEGIN(machine_check_idle_common)
351 bl machine_check_queue_event
352
353 /*
354 * We have not used any non-volatile GPRs here, and as a rule
355 * most exception code including machine check does not.
356 * Therefore PACA_NAPSTATELOST does not need to be set. Idle
357 * wakeup will restore volatile registers.
358 *
359 * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
360 *
361 * Then decrement MCE nesting after finishing with the stack.
362 */
363 ld r3,_MSR(r1)
364
365 lhz r11,PACA_IN_MCE(r13)
366 subi r11,r11,1
367 sth r11,PACA_IN_MCE(r13)
368
369 /* Turn off the RI bit because SRR1 is used by idle wakeup code. */
370 /* Recoverability could be improved by reducing the use of SRR1. */
371 li r11,0
372 mtmsrd r11,1
373
374 b pnv_powersave_wakeup_mce
375#endif
afcf0095
NP
376 /*
377 * Handle machine check early in real mode. We come here with
378 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
379 */
380EXC_COMMON_BEGIN(machine_check_handle_early)
381 std r0,GPR0(r1) /* Save r0 */
382 EXCEPTION_PROLOG_COMMON_3(0x200)
383 bl save_nvgprs
384 addi r3,r1,STACK_FRAME_OVERHEAD
385 bl machine_check_early
386 std r3,RESULT(r1) /* Save result */
387 ld r12,_MSR(r1)
1945bc45 388
afcf0095
NP
389#ifdef CONFIG_PPC_P7_NAP
390 /*
391 * Check if thread was in power saving mode. We come here when any
392 * of the following is true:
393 * a. thread wasn't in power saving mode
394 * b. thread was in power saving mode with no state loss,
395 * supervisor state loss or hypervisor state loss.
396 *
397 * Go back to nap/sleep/winkle mode again if (b) is true.
398 */
1945bc45
NP
399 BEGIN_FTR_SECTION
400 rlwinm. r11,r12,47-31,30,31
6102c005 401 bne machine_check_idle_common
1945bc45 402 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
afcf0095 403#endif
1945bc45 404
afcf0095
NP
405 /*
406 * Check if we are coming from hypervisor userspace. If yes then we
407 * continue in host kernel in V mode to deliver the MC event.
408 */
409 rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
410 beq 5f
411 andi. r11,r12,MSR_PR /* See if coming from user. */
412 bne 9f /* continue in V mode if we are. */
413
4145:
415#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
416 /*
417 * We are coming from kernel context. Check if we are coming from
418 * guest. if yes, then we can continue. We will fall through
419 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
420 */
421 lbz r11,HSTATE_IN_GUEST(r13)
422 cmpwi r11,0 /* Check if coming from guest */
423 bne 9f /* continue if we are. */
424#endif
425 /*
426 * At this point we are not sure about what context we come from.
427 * Queue up the MCE event and return from the interrupt.
428 * But before that, check if this is an un-recoverable exception.
429 * If yes, then stay on emergency stack and panic.
430 */
431 andi. r11,r12,MSR_RI
432 bne 2f
4331: mfspr r11,SPRN_SRR0
434 LOAD_HANDLER(r10,unrecover_mce)
435 mtspr SPRN_SRR0,r10
436 ld r10,PACAKMSR(r13)
437 /*
438 * We are going down. But there are chances that we might get hit by
439 * another MCE during panic path and we may run into unstable state
440 * with no way out. Hence, turn ME bit off while going down, so that
441 * when another MCE is hit during panic path, system will checkstop
442 * and hypervisor will get restarted cleanly by SP.
443 */
444 li r3,MSR_ME
445 andc r10,r10,r3 /* Turn off MSR_ME */
446 mtspr SPRN_SRR1,r10
447 rfid
448 b .
4492:
450 /*
451 * Check if we have successfully handled/recovered from error, if not
452 * then stay on emergency stack and panic.
453 */
454 ld r3,RESULT(r1) /* Load result */
455 cmpdi r3,0 /* see if we handled MCE successfully */
456
457 beq 1b /* if !handled then panic */
458 /*
459 * Return from MC interrupt.
460 * Queue up the MCE event so that we can log it later, while
461 * returning from kernel or opal call.
462 */
463 bl machine_check_queue_event
464 MACHINE_CHECK_HANDLER_WINDUP
465 rfid
4669:
467 /* Deliver the machine check to host kernel in V mode. */
468 MACHINE_CHECK_HANDLER_WINDUP
469 b machine_check_pSeries
470
471EXC_COMMON_BEGIN(unrecover_mce)
472 /* Invoke machine_check_exception to print MCE event and panic. */
473 addi r3,r1,STACK_FRAME_OVERHEAD
474 bl machine_check_exception
475 /*
476 * We will not reach here. Even if we did, there is no way out. Call
477 * unrecoverable_exception and die.
478 */
4791: addi r3,r1,STACK_FRAME_OVERHEAD
480 bl unrecoverable_exception
481 b 1b
482
0ebc4cda 483
1a6822d1
NP
484EXC_REAL(data_access, 0x300, 0x80)
485EXC_VIRT(data_access, 0x4300, 0x80, 0x300)
80795e6c
NP
486TRAMP_KVM_SKIP(PACA_EXGEN, 0x300)
487
488EXC_COMMON_BEGIN(data_access_common)
489 /*
490 * Here r13 points to the paca, r9 contains the saved CR,
491 * SRR0 and SRR1 are saved in r11 and r12,
492 * r9 - r13 are saved in paca->exgen.
493 */
494 mfspr r10,SPRN_DAR
495 std r10,PACA_EXGEN+EX_DAR(r13)
496 mfspr r10,SPRN_DSISR
497 stw r10,PACA_EXGEN+EX_DSISR(r13)
498 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
499 RECONCILE_IRQ_STATE(r10, r11)
500 ld r12,_MSR(r1)
501 ld r3,PACA_EXGEN+EX_DAR(r13)
502 lwz r4,PACA_EXGEN+EX_DSISR(r13)
503 li r5,0x300
504 std r3,_DAR(r1)
505 std r4,_DSISR(r1)
506BEGIN_MMU_FTR_SECTION
507 b do_hash_page /* Try to handle as hpte fault */
508MMU_FTR_SECTION_ELSE
509 b handle_page_fault
510ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
511
0ebc4cda 512
1a6822d1 513EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
673b189a 514 SET_SCRATCH0(r13)
1707dd16 515 EXCEPTION_PROLOG_0(PACA_EXSLB)
da2bc464 516 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x380)
4d7cd3b9 517 mr r12,r3 /* save r3 */
0ebc4cda 518 mfspr r3,SPRN_DAR
4d7cd3b9 519 mfspr r11,SPRN_SRR1
f0f558b1 520 crset 4*cr6+eq
442b6e8e 521 BRANCH_TO_COMMON(r10, slb_miss_common)
1a6822d1 522EXC_REAL_END(data_access_slb, 0x380, 0x80)
0ebc4cda 523
1a6822d1 524EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
2b9af6e4
NP
525 SET_SCRATCH0(r13)
526 EXCEPTION_PROLOG_0(PACA_EXSLB)
527 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
4d7cd3b9 528 mr r12,r3 /* save r3 */
2b9af6e4 529 mfspr r3,SPRN_DAR
4d7cd3b9 530 mfspr r11,SPRN_SRR1
2b9af6e4 531 crset 4*cr6+eq
442b6e8e 532 BRANCH_TO_COMMON(r10, slb_miss_common)
1a6822d1 533EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
2b9af6e4
NP
534TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
535
536
1a6822d1
NP
537EXC_REAL(instruction_access, 0x400, 0x80)
538EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400)
27ce77df
NP
539TRAMP_KVM(PACA_EXGEN, 0x400)
540
541EXC_COMMON_BEGIN(instruction_access_common)
542 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
543 RECONCILE_IRQ_STATE(r10, r11)
544 ld r12,_MSR(r1)
545 ld r3,_NIP(r1)
b4c001dc 546 andis. r4,r12,DSISR_BAD_FAULT_64S@h
27ce77df
NP
547 li r5,0x400
548 std r3,_DAR(r1)
549 std r4,_DSISR(r1)
550BEGIN_MMU_FTR_SECTION
551 b do_hash_page /* Try to handle as hpte fault */
552MMU_FTR_SECTION_ELSE
553 b handle_page_fault
554ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
555
0ebc4cda 556
1a6822d1 557EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80)
673b189a 558 SET_SCRATCH0(r13)
1707dd16 559 EXCEPTION_PROLOG_0(PACA_EXSLB)
da2bc464 560 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
4d7cd3b9 561 mr r12,r3 /* save r3 */
0ebc4cda 562 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
4d7cd3b9 563 mfspr r11,SPRN_SRR1
f0f558b1 564 crclr 4*cr6+eq
442b6e8e 565 BRANCH_TO_COMMON(r10, slb_miss_common)
1a6822d1 566EXC_REAL_END(instruction_access_slb, 0x480, 0x80)
0ebc4cda 567
1a6822d1 568EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
8d04631a
NP
569 SET_SCRATCH0(r13)
570 EXCEPTION_PROLOG_0(PACA_EXSLB)
571 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
4d7cd3b9 572 mr r12,r3 /* save r3 */
8d04631a 573 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
4d7cd3b9 574 mfspr r11,SPRN_SRR1
8d04631a 575 crclr 4*cr6+eq
442b6e8e 576 BRANCH_TO_COMMON(r10, slb_miss_common)
1a6822d1 577EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)
8d04631a
NP
578TRAMP_KVM(PACA_EXSLB, 0x480)
579
580
442b6e8e
ME
581/*
582 * This handler is used by the 0x380 and 0x480 SLB miss interrupts, as well as
583 * the virtual mode 0x4380 and 0x4480 interrupts if AIL is enabled.
584 */
585EXC_COMMON_BEGIN(slb_miss_common)
8d04631a
NP
586 /*
587 * r13 points to the PACA, r9 contains the saved CR,
4d7cd3b9
NP
588 * r12 contains the saved r3,
589 * r11 contain the saved SRR1, SRR0 is still ready for return
8d04631a
NP
590 * r3 has the faulting address
591 * r9 - r13 are saved in paca->exslb.
8d04631a
NP
592 * cr6.eq is set for a D-SLB miss, clear for a I-SLB miss
593 * We assume we aren't going to take any exceptions during this
594 * procedure.
595 */
596 mflr r10
8d04631a
NP
597 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
598 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
8d04631a 599
4d7cd3b9
NP
600 /*
601 * Test MSR_RI before calling slb_allocate_realmode, because the
602 * MSR in r11 gets clobbered. However we still want to allocate
603 * SLB in case MSR_RI=0, to minimise the risk of getting stuck in
604 * recursive SLB faults. So use cr5 for this, which is preserved.
605 */
606 andi. r11,r11,MSR_RI /* check for unrecoverable exception */
607 cmpdi cr5,r11,MSR_RI
608
8d04631a
NP
609 crset 4*cr0+eq
610#ifdef CONFIG_PPC_STD_MMU_64
611BEGIN_MMU_FTR_SECTION
fd88b945 612 bl slb_allocate
8d04631a
NP
613END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
614#endif
615
616 ld r10,PACA_EXSLB+EX_LR(r13)
8d04631a
NP
617 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
618 mtlr r10
619
7c28f048 620 beq- 8f /* if bad address, make full stack frame */
8d04631a 621
4d7cd3b9 622 bne- cr5,2f /* if unrecoverable exception, oops */
8d04631a
NP
623
624 /* All done -- return from exception. */
625
626.machine push
627.machine "power4"
628 mtcrf 0x80,r9
4d7cd3b9 629 mtcrf 0x04,r9 /* MSR[RI] indication is in cr5 */
8d04631a
NP
630 mtcrf 0x02,r9 /* I/D indication is in cr6 */
631 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
632.machine pop
633
fe5482c0 634 RESTORE_CTR(r9, PACA_EXSLB)
8d04631a 635 RESTORE_PPR_PACA(PACA_EXSLB, r9)
4d7cd3b9 636 mr r3,r12
8d04631a
NP
637 ld r9,PACA_EXSLB+EX_R9(r13)
638 ld r10,PACA_EXSLB+EX_R10(r13)
639 ld r11,PACA_EXSLB+EX_R11(r13)
640 ld r12,PACA_EXSLB+EX_R12(r13)
641 ld r13,PACA_EXSLB+EX_R13(r13)
642 rfid
643 b . /* prevent speculative execution */
644
7c28f048 6452: std r3,PACA_EXSLB+EX_DAR(r13)
4d7cd3b9 646 mr r3,r12
7c28f048 647 mfspr r11,SPRN_SRR0
4d7cd3b9 648 mfspr r12,SPRN_SRR1
8d04631a
NP
649 LOAD_HANDLER(r10,unrecov_slb)
650 mtspr SPRN_SRR0,r10
651 ld r10,PACAKMSR(r13)
652 mtspr SPRN_SRR1,r10
653 rfid
654 b .
655
7c28f048 6568: std r3,PACA_EXSLB+EX_DAR(r13)
4d7cd3b9 657 mr r3,r12
7c28f048 658 mfspr r11,SPRN_SRR0
4d7cd3b9 659 mfspr r12,SPRN_SRR1
8d04631a
NP
660 LOAD_HANDLER(r10,bad_addr_slb)
661 mtspr SPRN_SRR0,r10
662 ld r10,PACAKMSR(r13)
663 mtspr SPRN_SRR1,r10
664 rfid
665 b .
666
667EXC_COMMON_BEGIN(unrecov_slb)
668 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
669 RECONCILE_IRQ_STATE(r10, r11)
670 bl save_nvgprs
6711: addi r3,r1,STACK_FRAME_OVERHEAD
672 bl unrecoverable_exception
673 b 1b
674
675EXC_COMMON_BEGIN(bad_addr_slb)
676 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
677 RECONCILE_IRQ_STATE(r10, r11)
678 ld r3, PACA_EXSLB+EX_DAR(r13)
679 std r3, _DAR(r1)
680 beq cr6, 2f
681 li r10, 0x480 /* fix trap number for I-SLB miss */
682 std r10, _TRAP(r1)
6832: bl save_nvgprs
684 addi r3, r1, STACK_FRAME_OVERHEAD
685 bl slb_miss_bad_addr
686 b ret_from_except
687
1a6822d1 688EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
b3e6b5df 689 .globl hardware_interrupt_hv;
b3e6b5df 690hardware_interrupt_hv:
a5d4f3ad 691 BEGIN_FTR_SECTION
da2bc464 692 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
b01c8b54 693 EXC_HV, SOFTEN_TEST_HV)
de56a948 694 FTR_SECTION_ELSE
da2bc464 695 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
31a40e2b 696 EXC_STD, SOFTEN_TEST_PR)
969391c5 697 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
1a6822d1 698EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
da2bc464 699
1a6822d1 700EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
c138e588
NP
701 .globl hardware_interrupt_relon_hv;
702hardware_interrupt_relon_hv:
703 BEGIN_FTR_SECTION
704 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_HV, SOFTEN_TEST_HV)
705 FTR_SECTION_ELSE
706 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_STD, SOFTEN_TEST_PR)
707 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1a6822d1 708EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
c138e588 709
7ede5317
NP
710TRAMP_KVM(PACA_EXGEN, 0x500)
711TRAMP_KVM_HV(PACA_EXGEN, 0x500)
c138e588
NP
712EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
713
714
1a6822d1
NP
715EXC_REAL(alignment, 0x600, 0x100)
716EXC_VIRT(alignment, 0x4600, 0x100, 0x600)
da2bc464 717TRAMP_KVM(PACA_EXGEN, 0x600)
f9aa6714
NP
718EXC_COMMON_BEGIN(alignment_common)
719 mfspr r10,SPRN_DAR
720 std r10,PACA_EXGEN+EX_DAR(r13)
721 mfspr r10,SPRN_DSISR
722 stw r10,PACA_EXGEN+EX_DSISR(r13)
723 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
724 ld r3,PACA_EXGEN+EX_DAR(r13)
725 lwz r4,PACA_EXGEN+EX_DSISR(r13)
726 std r3,_DAR(r1)
727 std r4,_DSISR(r1)
728 bl save_nvgprs
729 RECONCILE_IRQ_STATE(r10, r11)
730 addi r3,r1,STACK_FRAME_OVERHEAD
731 bl alignment_exception
732 b ret_from_except
733
da2bc464 734
1a6822d1
NP
735EXC_REAL(program_check, 0x700, 0x100)
736EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
da2bc464 737TRAMP_KVM(PACA_EXGEN, 0x700)
11e87346
NP
738EXC_COMMON_BEGIN(program_check_common)
739 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
740 bl save_nvgprs
741 RECONCILE_IRQ_STATE(r10, r11)
742 addi r3,r1,STACK_FRAME_OVERHEAD
743 bl program_check_exception
744 b ret_from_except
745
b01c8b54 746
1a6822d1
NP
747EXC_REAL(fp_unavailable, 0x800, 0x100)
748EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
da2bc464 749TRAMP_KVM(PACA_EXGEN, 0x800)
c78d9b97
NP
750EXC_COMMON_BEGIN(fp_unavailable_common)
751 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
752 bne 1f /* if from user, just load it up */
753 bl save_nvgprs
754 RECONCILE_IRQ_STATE(r10, r11)
755 addi r3,r1,STACK_FRAME_OVERHEAD
756 bl kernel_fp_unavailable_exception
757 BUG_OPCODE
7581:
759#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
760BEGIN_FTR_SECTION
761 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
762 * transaction), go do TM stuff
763 */
764 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
765 bne- 2f
766END_FTR_SECTION_IFSET(CPU_FTR_TM)
767#endif
768 bl load_up_fpu
769 b fast_exception_return
770#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
7712: /* User process was in a transaction */
772 bl save_nvgprs
773 RECONCILE_IRQ_STATE(r10, r11)
774 addi r3,r1,STACK_FRAME_OVERHEAD
775 bl fp_unavailable_tm
776 b ret_from_except
777#endif
778
a5d4f3ad 779
1a6822d1
NP
780EXC_REAL_MASKABLE(decrementer, 0x900, 0x80)
781EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900)
39c0da57
NP
782TRAMP_KVM(PACA_EXGEN, 0x900)
783EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
784
a485c709 785
1a6822d1
NP
786EXC_REAL_HV(hdecrementer, 0x980, 0x80)
787EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
facc6d74
NP
788TRAMP_KVM_HV(PACA_EXGEN, 0x980)
789EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
790
a5d4f3ad 791
1a6822d1
NP
792EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100)
793EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00)
da2bc464 794TRAMP_KVM(PACA_EXGEN, 0xa00)
ca243163
NP
795#ifdef CONFIG_PPC_DOORBELL
796EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
797#else
798EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
799#endif
800
0ebc4cda 801
1a6822d1
NP
802EXC_REAL(trap_0b, 0xb00, 0x100)
803EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
da2bc464 804TRAMP_KVM(PACA_EXGEN, 0xb00)
341215dc
NP
805EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
806
acd7d8ce
NP
807/*
808 * system call / hypercall (0xc00, 0x4c00)
809 *
810 * The system call exception is invoked with "sc 0" and does not alter HV bit.
811 * There is support for kernel code to invoke system calls but there are no
812 * in-tree users.
813 *
814 * The hypercall is invoked with "sc 1" and sets HV=1.
815 *
816 * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
817 * 0x4c00 virtual mode.
818 *
819 * Call convention:
820 *
821 * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
822 *
823 * For hypercalls, the register convention is as follows:
824 * r0 volatile
825 * r1-2 nonvolatile
826 * r3 volatile parameter and return value for status
827 * r4-r10 volatile input and output value
828 * r11 volatile hypercall number and output value
76fc0cfc 829 * r12 volatile input and output value
acd7d8ce
NP
830 * r13-r31 nonvolatile
831 * LR nonvolatile
832 * CTR volatile
833 * XER volatile
834 * CR0-1 CR5-7 volatile
835 * CR2-4 nonvolatile
836 * Other registers nonvolatile
837 *
838 * The intersection of volatile registers that don't contain possible
76fc0cfc
NP
839 * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
840 * without saving, though xer is not a good idea to use, as hardware may
841 * interpret some bits so it may be costly to change them.
acd7d8ce 842 */
bc355125 843#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
acd7d8ce
NP
844 /*
845 * There is a little bit of juggling to get syscall and hcall
76fc0cfc
NP
846 * working well. Save r13 in ctr to avoid using SPRG scratch
847 * register.
acd7d8ce
NP
848 *
849 * Userspace syscalls have already saved the PPR, hcalls must save
850 * it before setting HMT_MEDIUM.
851 */
bc355125 852#define SYSCALL_KVMTEST \
76fc0cfc 853 mtctr r13; \
bc355125 854 GET_PACA(r13); \
76fc0cfc 855 std r10,PACA_EXGEN+EX_R10(r13); \
acd7d8ce 856 KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
bc355125 857 HMT_MEDIUM; \
76fc0cfc 858 mfctr r9;
bc355125
PM
859
860#else
861#define SYSCALL_KVMTEST \
acd7d8ce
NP
862 HMT_MEDIUM; \
863 mr r9,r13; \
864 GET_PACA(r13);
bc355125
PM
865#endif
866
fb479e44
NP
867#define LOAD_SYSCALL_HANDLER(reg) \
868 __LOAD_HANDLER(reg, system_call_common)
d807ad37 869
acd7d8ce
NP
870/*
871 * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9,
872 * and HMT_MEDIUM.
873 */
874#define SYSCALL_REAL \
875 mfspr r11,SPRN_SRR0 ; \
d807ad37
NP
876 mfspr r12,SPRN_SRR1 ; \
877 LOAD_SYSCALL_HANDLER(r10) ; \
878 mtspr SPRN_SRR0,r10 ; \
879 ld r10,PACAKMSR(r13) ; \
880 mtspr SPRN_SRR1,r10 ; \
881 rfid ; \
882 b . ; /* prevent speculative execution */
883
727f1361 884#ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
5c2511bf
ME
885#define SYSCALL_FASTENDIAN_TEST \
886BEGIN_FTR_SECTION \
887 cmpdi r0,0x1ebe ; \
888 beq- 1f ; \
889END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
890
acd7d8ce 891#define SYSCALL_FASTENDIAN \
d807ad37
NP
892 /* Fast LE/BE switch system call */ \
8931: mfspr r12,SPRN_SRR1 ; \
894 xori r12,r12,MSR_LE ; \
895 mtspr SPRN_SRR1,r12 ; \
acd7d8ce 896 mr r13,r9 ; \
d807ad37
NP
897 rfid ; /* return to userspace */ \
898 b . ; /* prevent speculative execution */
727f1361
ME
899#else
900#define SYSCALL_FASTENDIAN_TEST
901#define SYSCALL_FASTENDIAN
902#endif /* CONFIG_PPC_FAST_ENDIAN_SWITCH */
d807ad37
NP
903
904#if defined(CONFIG_RELOCATABLE)
905 /*
906 * We can't branch directly so we do it via the CTR which
907 * is volatile across system calls.
908 */
acd7d8ce
NP
909#define SYSCALL_VIRT \
910 LOAD_SYSCALL_HANDLER(r10) ; \
911 mtctr r10 ; \
912 mfspr r11,SPRN_SRR0 ; \
d807ad37
NP
913 mfspr r12,SPRN_SRR1 ; \
914 li r10,MSR_RI ; \
915 mtmsrd r10,1 ; \
916 bctr ;
917#else
918 /* We can branch directly */
acd7d8ce
NP
919#define SYSCALL_VIRT \
920 mfspr r11,SPRN_SRR0 ; \
d807ad37
NP
921 mfspr r12,SPRN_SRR1 ; \
922 li r10,MSR_RI ; \
923 mtmsrd r10,1 ; /* Set RI (EE=0) */ \
924 b system_call_common ;
925#endif
926
1a6822d1 927EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
acd7d8ce
NP
928 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
929 SYSCALL_FASTENDIAN_TEST
930 SYSCALL_REAL
931 SYSCALL_FASTENDIAN
1a6822d1 932EXC_REAL_END(system_call, 0xc00, 0x100)
da2bc464 933
1a6822d1 934EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
acd7d8ce
NP
935 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
936 SYSCALL_FASTENDIAN_TEST
937 SYSCALL_VIRT
938 SYSCALL_FASTENDIAN
1a6822d1 939EXC_VIRT_END(system_call, 0x4c00, 0x100)
d807ad37 940
acd7d8ce
NP
941#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
942 /*
943 * This is a hcall, so register convention is as above, with these
944 * differences:
945 * r13 = PACA
76fc0cfc
NP
946 * ctr = orig r13
947 * orig r10 saved in PACA
acd7d8ce
NP
948 */
949TRAMP_KVM_BEGIN(do_kvm_0xc00)
950 /*
951 * Save the PPR (on systems that support it) before changing to
952 * HMT_MEDIUM. That allows the KVM code to save that value into the
953 * guest state (it is the guest's PPR value).
954 */
76fc0cfc 955 OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
acd7d8ce 956 HMT_MEDIUM
76fc0cfc 957 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
acd7d8ce 958 mfctr r10
76fc0cfc 959 SET_SCRATCH0(r10)
acd7d8ce
NP
960 std r9,PACA_EXGEN+EX_R9(r13)
961 mfcr r9
acd7d8ce
NP
962 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
963#endif
da2bc464 964
d807ad37 965
1a6822d1
NP
966EXC_REAL(single_step, 0xd00, 0x100)
967EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
da2bc464 968TRAMP_KVM(PACA_EXGEN, 0xd00)
bc6675c6 969EXC_COMMON(single_step_common, 0xd00, single_step_exception)
b01c8b54 970
1a6822d1 971EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
da0e7e62 972EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
f5c32c1d
NP
973TRAMP_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
f5c32c1d 985
1707dd16 986
1a6822d1 987EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
da0e7e62 988EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
82517cab
NP
989TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
990EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
991
1707dd16 992
1a6822d1
NP
993EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
994EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
031b4026
NP
995TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
996EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
997
1707dd16 998
e0319829
NP
999/*
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 */
1a6822d1 1004__EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
852e5da9 1005__TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60)
1a6822d1 1006EXC_VIRT_NONE(0x4e60, 0x20)
62f9b03b
NP
1007TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
1008TRAMP_REAL_BEGIN(hmi_exception_early)
1009 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
a4087a4d
NP
1010 mr r10,r1 /* Save r1 */
1011 ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
62f9b03b 1012 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
62f9b03b 1013 mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
a4087a4d
NP
1014 mfspr r12,SPRN_HSRR1 /* Save HSRR1 */
1015 EXCEPTION_PROLOG_COMMON_1()
62f9b03b
NP
1016 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1017 EXCEPTION_PROLOG_COMMON_3(0xe60)
1018 addi r3,r1,STACK_FRAME_OVERHEAD
be5c5e84 1019 BRANCH_LINK_TO_FAR(hmi_exception_realmode) /* Function call ABI */
5080332c
MN
1020 cmpdi cr0,r3,0
1021
62f9b03b
NP
1022 /* Windup the stack. */
1023 /* Move original HSRR0 and HSRR1 into the respective regs */
1024 ld r9,_MSR(r1)
1025 mtspr SPRN_HSRR1,r9
1026 ld r3,_NIP(r1)
1027 mtspr SPRN_HSRR0,r3
1028 ld r9,_CTR(r1)
1029 mtctr r9
1030 ld r9,_XER(r1)
1031 mtxer r9
1032 ld r9,_LINK(r1)
1033 mtlr r9
1034 REST_GPR(0, r1)
1035 REST_8GPRS(2, r1)
1036 REST_GPR(10, r1)
1037 ld r11,_CCR(r1)
5080332c
MN
1038 REST_2GPRS(12, r1)
1039 bne 1f
62f9b03b
NP
1040 mtcr r11
1041 REST_GPR(11, r1)
5080332c
MN
1042 ld r1,GPR1(r1)
1043 hrfid
1044
10451: mtcr r11
1046 REST_GPR(11, r1)
62f9b03b
NP
1047 ld r1,GPR1(r1)
1048
1049 /*
1050 * Go to virtual mode and pull the HMI event information from
1051 * firmware.
1052 */
1053 .globl hmi_exception_after_realmode
1054hmi_exception_after_realmode:
1055 SET_SCRATCH0(r13)
1056 EXCEPTION_PROLOG_0(PACA_EXGEN)
1057 b tramp_real_hmi_exception
1058
5080332c
MN
1059EXC_COMMON_BEGIN(hmi_exception_common)
1060EXCEPTION_COMMON(PACA_EXGEN, 0xe60, hmi_exception_common, handle_hmi_exception,
1061 ret_from_except, FINISH_NAP;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON)
1707dd16 1062
1a6822d1
NP
1063EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20)
1064EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80)
9bcb81bf
NP
1065TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
1066#ifdef CONFIG_PPC_DOORBELL
1067EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
1068#else
1069EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
1070#endif
1071
0ebc4cda 1072
1a6822d1
NP
1073EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20)
1074EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0)
74408776
NP
1075TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
1076EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
1077
9baaef0a 1078
1a6822d1
NP
1079EXC_REAL_NONE(0xec0, 0x20)
1080EXC_VIRT_NONE(0x4ec0, 0x20)
1081EXC_REAL_NONE(0xee0, 0x20)
1082EXC_VIRT_NONE(0x4ee0, 0x20)
bda7fea2 1083
0ebc4cda 1084
1a6822d1
NP
1085EXC_REAL_OOL(performance_monitor, 0xf00, 0x20)
1086EXC_VIRT_OOL(performance_monitor, 0x4f00, 0x20, 0xf00)
b1c7f150
NP
1087TRAMP_KVM(PACA_EXGEN, 0xf00)
1088EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
1089
0ebc4cda 1090
1a6822d1
NP
1091EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
1092EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
d1a0ca9c
NP
1093TRAMP_KVM(PACA_EXGEN, 0xf20)
1094EXC_COMMON_BEGIN(altivec_unavailable_common)
1095 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1096#ifdef CONFIG_ALTIVEC
1097BEGIN_FTR_SECTION
1098 beq 1f
1099#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1100 BEGIN_FTR_SECTION_NESTED(69)
1101 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1102 * transaction), go do TM stuff
1103 */
1104 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1105 bne- 2f
1106 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1107#endif
1108 bl load_up_altivec
1109 b fast_exception_return
1110#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
11112: /* User process was in a transaction */
1112 bl save_nvgprs
1113 RECONCILE_IRQ_STATE(r10, r11)
1114 addi r3,r1,STACK_FRAME_OVERHEAD
1115 bl altivec_unavailable_tm
1116 b ret_from_except
1117#endif
11181:
1119END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1120#endif
1121 bl save_nvgprs
1122 RECONCILE_IRQ_STATE(r10, r11)
1123 addi r3,r1,STACK_FRAME_OVERHEAD
1124 bl altivec_unavailable_exception
1125 b ret_from_except
1126
0ebc4cda 1127
1a6822d1
NP
1128EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
1129EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
792cbddd
NP
1130TRAMP_KVM(PACA_EXGEN, 0xf40)
1131EXC_COMMON_BEGIN(vsx_unavailable_common)
1132 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1133#ifdef CONFIG_VSX
1134BEGIN_FTR_SECTION
1135 beq 1f
1136#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1137 BEGIN_FTR_SECTION_NESTED(69)
1138 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1139 * transaction), go do TM stuff
1140 */
1141 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1142 bne- 2f
1143 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1144#endif
1145 b load_up_vsx
1146#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
11472: /* User process was in a transaction */
1148 bl save_nvgprs
1149 RECONCILE_IRQ_STATE(r10, r11)
1150 addi r3,r1,STACK_FRAME_OVERHEAD
1151 bl vsx_unavailable_tm
1152 b ret_from_except
1153#endif
11541:
1155END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1156#endif
1157 bl save_nvgprs
1158 RECONCILE_IRQ_STATE(r10, r11)
1159 addi r3,r1,STACK_FRAME_OVERHEAD
1160 bl vsx_unavailable_exception
1161 b ret_from_except
1162
da2bc464 1163
1a6822d1
NP
1164EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
1165EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
1134713c
NP
1166TRAMP_KVM(PACA_EXGEN, 0xf60)
1167EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
1168
da2bc464 1169
1a6822d1
NP
1170EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
1171EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
14b0072c
NP
1172TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
1173EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
1174
da2bc464 1175
1a6822d1
NP
1176EXC_REAL_NONE(0xfa0, 0x20)
1177EXC_VIRT_NONE(0x4fa0, 0x20)
1178EXC_REAL_NONE(0xfc0, 0x20)
1179EXC_VIRT_NONE(0x4fc0, 0x20)
1180EXC_REAL_NONE(0xfe0, 0x20)
1181EXC_VIRT_NONE(0x4fe0, 0x20)
1182
1183EXC_REAL_NONE(0x1000, 0x100)
1184EXC_VIRT_NONE(0x5000, 0x100)
1185EXC_REAL_NONE(0x1100, 0x100)
1186EXC_VIRT_NONE(0x5100, 0x100)
d0c0c9a1 1187
0ebc4cda 1188#ifdef CONFIG_CBE_RAS
1a6822d1
NP
1189EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
1190EXC_VIRT_NONE(0x5200, 0x100)
da2bc464 1191TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
ff1b3206 1192EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
da2bc464 1193#else /* CONFIG_CBE_RAS */
1a6822d1
NP
1194EXC_REAL_NONE(0x1200, 0x100)
1195EXC_VIRT_NONE(0x5200, 0x100)
da2bc464 1196#endif
b01c8b54 1197
ff1b3206 1198
1a6822d1
NP
1199EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
1200EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
da2bc464 1201TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
4e96dbbf
NP
1202EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
1203
1a6822d1
NP
1204EXC_REAL_NONE(0x1400, 0x100)
1205EXC_VIRT_NONE(0x5400, 0x100)
da2bc464 1206
1a6822d1 1207EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
b92a66a6 1208 mtspr SPRN_SPRG_HSCRATCH0,r13
1707dd16 1209 EXCEPTION_PROLOG_0(PACA_EXGEN)
630573c1 1210 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
b92a66a6
MN
1211
1212#ifdef CONFIG_PPC_DENORMALISATION
1213 mfspr r10,SPRN_HSRR1
1214 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
afcf0095
NP
1215 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
1216 addi r11,r11,-4 /* HSRR0 is next instruction */
1217 bne+ denorm_assist
1218#endif
1e9b4507 1219
afcf0095
NP
1220 KVMTEST_PR(0x1500)
1221 EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
1a6822d1 1222EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
a74599a5 1223
d7e89849 1224#ifdef CONFIG_PPC_DENORMALISATION
1a6822d1 1225EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
d7e89849 1226 b exc_real_0x1500_denorm_exception_hv
1a6822d1 1227EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
d7e89849 1228#else
1a6822d1 1229EXC_VIRT_NONE(0x5500, 0x100)
afcf0095
NP
1230#endif
1231
d7e89849 1232TRAMP_KVM_SKIP(PACA_EXGEN, 0x1500)
b01c8b54 1233
b92a66a6 1234#ifdef CONFIG_PPC_DENORMALISATION
da2bc464 1235TRAMP_REAL_BEGIN(denorm_assist)
b92a66a6
MN
1236BEGIN_FTR_SECTION
1237/*
1238 * To denormalise we need to move a copy of the register to itself.
1239 * For POWER6 do that here for all FP regs.
1240 */
1241 mfmsr r10
1242 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
1243 xori r10,r10,(MSR_FE0|MSR_FE1)
1244 mtmsrd r10
1245 sync
d7c67fb1
MN
1246
1247#define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
1248#define FMR4(n) FMR2(n) ; FMR2(n+2)
1249#define FMR8(n) FMR4(n) ; FMR4(n+4)
1250#define FMR16(n) FMR8(n) ; FMR8(n+8)
1251#define FMR32(n) FMR16(n) ; FMR16(n+16)
1252 FMR32(0)
1253
b92a66a6
MN
1254FTR_SECTION_ELSE
1255/*
1256 * To denormalise we need to move a copy of the register to itself.
1257 * For POWER7 do that here for the first 32 VSX registers only.
1258 */
1259 mfmsr r10
1260 oris r10,r10,MSR_VSX@h
1261 mtmsrd r10
1262 sync
d7c67fb1
MN
1263
1264#define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
1265#define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
1266#define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
1267#define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
1268#define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
1269 XVCPSGNDP32(0)
1270
b92a66a6 1271ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
fb0fce3e
MN
1272
1273BEGIN_FTR_SECTION
1274 b denorm_done
1275END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
1276/*
1277 * To denormalise we need to move a copy of the register to itself.
1278 * For POWER8 we need to do that for all 64 VSX registers
1279 */
1280 XVCPSGNDP32(32)
1281denorm_done:
b92a66a6
MN
1282 mtspr SPRN_HSRR0,r11
1283 mtcrf 0x80,r9
1284 ld r9,PACA_EXGEN+EX_R9(r13)
44e9309f 1285 RESTORE_PPR_PACA(PACA_EXGEN, r10)
630573c1
PM
1286BEGIN_FTR_SECTION
1287 ld r10,PACA_EXGEN+EX_CFAR(r13)
1288 mtspr SPRN_CFAR,r10
1289END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
b92a66a6
MN
1290 ld r10,PACA_EXGEN+EX_R10(r13)
1291 ld r11,PACA_EXGEN+EX_R11(r13)
1292 ld r12,PACA_EXGEN+EX_R12(r13)
1293 ld r13,PACA_EXGEN+EX_R13(r13)
1294 HRFID
1295 b .
1296#endif
1297
d7e89849
NP
1298EXC_COMMON_HV(denorm_common, 0x1500, unknown_exception)
1299
1300
1301#ifdef CONFIG_CBE_RAS
1a6822d1
NP
1302EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
1303EXC_VIRT_NONE(0x5600, 0x100)
d7e89849 1304TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
69a79344 1305EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
d7e89849 1306#else /* CONFIG_CBE_RAS */
1a6822d1
NP
1307EXC_REAL_NONE(0x1600, 0x100)
1308EXC_VIRT_NONE(0x5600, 0x100)
d7e89849
NP
1309#endif
1310
69a79344 1311
1a6822d1
NP
1312EXC_REAL(altivec_assist, 0x1700, 0x100)
1313EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
d7e89849 1314TRAMP_KVM(PACA_EXGEN, 0x1700)
b51c079e
NP
1315#ifdef CONFIG_ALTIVEC
1316EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
1317#else
1318EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
1319#endif
1320
d7e89849
NP
1321
1322#ifdef CONFIG_CBE_RAS
1a6822d1
NP
1323EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
1324EXC_VIRT_NONE(0x5800, 0x100)
d7e89849 1325TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
3965f8ab 1326EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
d7e89849 1327#else /* CONFIG_CBE_RAS */
1a6822d1
NP
1328EXC_REAL_NONE(0x1800, 0x100)
1329EXC_VIRT_NONE(0x5800, 0x100)
d7e89849
NP
1330#endif
1331
75eb767e 1332#ifdef CONFIG_PPC_WATCHDOG
2104180a
NP
1333
1334#define MASKED_DEC_HANDLER_LABEL 3f
1335
1336#define MASKED_DEC_HANDLER(_H) \
13373: /* soft-nmi */ \
1338 std r12,PACA_EXGEN+EX_R12(r13); \
1339 GET_SCRATCH0(r10); \
1340 std r10,PACA_EXGEN+EX_R13(r13); \
1341 EXCEPTION_PROLOG_PSERIES_1(soft_nmi_common, _H)
1342
cc491f1d
NP
1343/*
1344 * Branch to soft_nmi_interrupt using the emergency stack. The emergency
1345 * stack is one that is usable by maskable interrupts so long as MSR_EE
1346 * remains off. It is used for recovery when something has corrupted the
1347 * normal kernel stack, for example. The "soft NMI" must not use the process
1348 * stack because we want irq disabled sections to avoid touching the stack
1349 * at all (other than PMU interrupts), so use the emergency stack for this,
1350 * and run it entirely with interrupts hard disabled.
1351 */
2104180a
NP
1352EXC_COMMON_BEGIN(soft_nmi_common)
1353 mr r10,r1
1354 ld r1,PACAEMERGSP(r13)
2104180a
NP
1355 subi r1,r1,INT_FRAME_SIZE
1356 EXCEPTION_COMMON_NORET_STACK(PACA_EXGEN, 0x900,
1357 system_reset, soft_nmi_interrupt,
1358 ADD_NVGPRS;ADD_RECONCILE)
1359 b ret_from_except
1360
75eb767e 1361#else /* CONFIG_PPC_WATCHDOG */
2104180a
NP
1362#define MASKED_DEC_HANDLER_LABEL 2f /* normal return */
1363#define MASKED_DEC_HANDLER(_H)
75eb767e 1364#endif /* CONFIG_PPC_WATCHDOG */
d7e89849 1365
0ebc4cda 1366/*
fe9e1d54
IM
1367 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
1368 * - If it was a decrementer interrupt, we bump the dec to max and and return.
1369 * - If it was a doorbell we return immediately since doorbells are edge
1370 * triggered and won't automatically refire.
0869b6fd
MS
1371 * - If it was a HMI we return immediately since we handled it in realmode
1372 * and it won't refire.
fe9e1d54
IM
1373 * - else we hard disable and return.
1374 * This is called with r10 containing the value to OR to the paca field.
0ebc4cda 1375 */
7230c564
BH
1376#define MASKED_INTERRUPT(_H) \
1377masked_##_H##interrupt: \
1378 std r11,PACA_EXGEN+EX_R11(r13); \
1379 lbz r11,PACAIRQHAPPENED(r13); \
1380 or r11,r11,r10; \
1381 stb r11,PACAIRQHAPPENED(r13); \
fe9e1d54
IM
1382 cmpwi r10,PACA_IRQ_DEC; \
1383 bne 1f; \
7230c564
BH
1384 lis r10,0x7fff; \
1385 ori r10,r10,0xffff; \
1386 mtspr SPRN_DEC,r10; \
2104180a 1387 b MASKED_DEC_HANDLER_LABEL; \
e0c827c0
NP
13881: andi. r10,r10,(PACA_IRQ_DBELL|PACA_IRQ_HMI); \
1389 bne 2f; \
fe9e1d54 1390 mfspr r10,SPRN_##_H##SRR1; \
6e9a2f6e 1391 xori r10,r10,MSR_EE; /* clear MSR_EE */ \
7230c564
BH
1392 mtspr SPRN_##_H##SRR1,r10; \
13932: mtcrf 0x80,r9; \
1394 ld r9,PACA_EXGEN+EX_R9(r13); \
1395 ld r10,PACA_EXGEN+EX_R10(r13); \
1396 ld r11,PACA_EXGEN+EX_R11(r13); \
c05f0be8 1397 /* returns to kernel where r13 must be set up, so don't restore it */ \
7230c564 1398 ##_H##rfid; \
2104180a
NP
1399 b .; \
1400 MASKED_DEC_HANDLER(_H)
57f26649
NP
1401
1402/*
1403 * Real mode exceptions actually use this too, but alternate
1404 * instruction code patches (which end up in the common .text area)
1405 * cannot reach these if they are put there.
1406 */
1407USE_FIXED_SECTION(virt_trampolines)
7230c564
BH
1408 MASKED_INTERRUPT()
1409 MASKED_INTERRUPT(H)
0ebc4cda 1410
4f6c11db 1411#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
da2bc464 1412TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
4f6c11db
PM
1413 /*
1414 * Here all GPRs are unchanged from when the interrupt happened
1415 * except for r13, which is saved in SPRG_SCRATCH0.
1416 */
1417 mfspr r13, SPRN_SRR0
1418 addi r13, r13, 4
1419 mtspr SPRN_SRR0, r13
1420 GET_SCRATCH0(r13)
1421 rfid
1422 b .
1423
da2bc464 1424TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
4f6c11db
PM
1425 /*
1426 * Here all GPRs are unchanged from when the interrupt happened
1427 * except for r13, which is saved in SPRG_SCRATCH0.
1428 */
1429 mfspr r13, SPRN_HSRR0
1430 addi r13, r13, 4
1431 mtspr SPRN_HSRR0, r13
1432 GET_SCRATCH0(r13)
1433 hrfid
1434 b .
1435#endif
1436
0ebc4cda 1437/*
057b6d7e
HB
1438 * Ensure that any handlers that get invoked from the exception prologs
1439 * above are below the first 64KB (0x10000) of the kernel image because
1440 * the prologs assemble the addresses of these handlers using the
1441 * LOAD_HANDLER macro, which uses an ori instruction.
0ebc4cda
BH
1442 */
1443
1444/*** Common interrupt handlers ***/
1445
0ebc4cda 1446
c1fb6816
MN
1447 /*
1448 * Relocation-on interrupts: A subset of the interrupts can be delivered
1449 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
1450 * it. Addresses are the same as the original interrupt addresses, but
1451 * offset by 0xc000000000004000.
1452 * It's impossible to receive interrupts below 0x300 via this mechanism.
1453 * KVM: None of these traps are from the guest ; anything that escalated
1454 * to HV=1 from HV=0 is delivered via real mode handlers.
1455 */
1456
1457 /*
1458 * This uses the standard macro, since the original 0x300 vector
1459 * only has extra guff for STAB-based processors -- which never
1460 * come here.
1461 */
da2bc464 1462
57f26649 1463EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
b1576fec 1464 b __ppc64_runlatch_on
fe1952fc 1465
57f26649 1466USE_FIXED_SECTION(virt_trampolines)
8ed8ab40
HB
1467 /*
1468 * The __end_interrupts marker must be past the out-of-line (OOL)
1469 * handlers, so that they are copied to real address 0x100 when running
1470 * a relocatable kernel. This ensures they can be reached from the short
1471 * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
1472 * directly, without using LOAD_HANDLER().
1473 */
1474 .align 7
1475 .globl __end_interrupts
1476__end_interrupts:
57f26649 1477DEFINE_FIXED_SYMBOL(__end_interrupts)
61383407 1478
087aa036 1479#ifdef CONFIG_PPC_970_NAP
7c8cb4b5 1480EXC_COMMON_BEGIN(power4_fixup_nap)
087aa036
CG
1481 andc r9,r9,r10
1482 std r9,TI_LOCAL_FLAGS(r11)
1483 ld r10,_LINK(r1) /* make idle task do the */
1484 std r10,_NIP(r1) /* equivalent of a blr */
1485 blr
1486#endif
1487
57f26649
NP
1488CLOSE_FIXED_SECTION(real_vectors);
1489CLOSE_FIXED_SECTION(real_trampolines);
1490CLOSE_FIXED_SECTION(virt_vectors);
1491CLOSE_FIXED_SECTION(virt_trampolines);
1492
1493USE_TEXT_SECTION()
1494
0ebc4cda
BH
1495/*
1496 * Hash table stuff
1497 */
f4329f2e 1498 .balign IFETCH_ALIGN_BYTES
6a3bab90 1499do_hash_page:
398a719d
BH
1500 #ifdef CONFIG_PPC_STD_MMU_64
1501 lis r0,DSISR_BAD_FAULT_64S@h
1502 ori r0,r0,DSISR_BAD_FAULT_64S@l
1503 and. r0,r4,r0 /* weird error? */
0ebc4cda 1504 bne- handle_page_fault /* if not, try to insert a HPTE */
9778b696 1505 CURRENT_THREAD_INFO(r11, r1)
9c1e1052
PM
1506 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
1507 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
1508 bne 77f /* then don't call hash_page now */
0ebc4cda
BH
1509
1510 /*
1511 * r3 contains the faulting address
106713a1 1512 * r4 msr
0ebc4cda 1513 * r5 contains the trap number
aefa5688 1514 * r6 contains dsisr
0ebc4cda 1515 *
7230c564 1516 * at return r3 = 0 for success, 1 for page fault, negative for error
0ebc4cda 1517 */
106713a1 1518 mr r4,r12
aefa5688 1519 ld r6,_DSISR(r1)
106713a1
AK
1520 bl __hash_page /* build HPTE if possible */
1521 cmpdi r3,0 /* see if __hash_page succeeded */
0ebc4cda 1522
7230c564 1523 /* Success */
0ebc4cda 1524 beq fast_exc_return_irq /* Return from exception on success */
0ebc4cda 1525
7230c564
BH
1526 /* Error */
1527 blt- 13f
d89ba535
NR
1528
1529 /* Reload DSISR into r4 for the DABR check below */
1530 ld r4,_DSISR(r1)
caca285e 1531#endif /* CONFIG_PPC_STD_MMU_64 */
9c7cc234 1532
0ebc4cda
BH
1533/* Here we have a page fault that hash_page can't handle. */
1534handle_page_fault:
d89ba535
NR
153511: andis. r0,r4,DSISR_DABRMATCH@h
1536 bne- handle_dabr_fault
1537 ld r4,_DAR(r1)
0ebc4cda
BH
1538 ld r5,_DSISR(r1)
1539 addi r3,r1,STACK_FRAME_OVERHEAD
b1576fec 1540 bl do_page_fault
0ebc4cda 1541 cmpdi r3,0
a546498f 1542 beq+ 12f
b1576fec 1543 bl save_nvgprs
0ebc4cda
BH
1544 mr r5,r3
1545 addi r3,r1,STACK_FRAME_OVERHEAD
1546 lwz r4,_DAR(r1)
b1576fec
AB
1547 bl bad_page_fault
1548 b ret_from_except
0ebc4cda 1549
a546498f
BH
1550/* We have a data breakpoint exception - handle it */
1551handle_dabr_fault:
b1576fec 1552 bl save_nvgprs
a546498f
BH
1553 ld r4,_DAR(r1)
1554 ld r5,_DSISR(r1)
1555 addi r3,r1,STACK_FRAME_OVERHEAD
b1576fec
AB
1556 bl do_break
155712: b ret_from_except_lite
a546498f 1558
0ebc4cda 1559
caca285e 1560#ifdef CONFIG_PPC_STD_MMU_64
0ebc4cda
BH
1561/* We have a page fault that hash_page could handle but HV refused
1562 * the PTE insertion
1563 */
b1576fec 156413: bl save_nvgprs
0ebc4cda
BH
1565 mr r5,r3
1566 addi r3,r1,STACK_FRAME_OVERHEAD
1567 ld r4,_DAR(r1)
b1576fec
AB
1568 bl low_hash_fault
1569 b ret_from_except
caca285e 1570#endif
0ebc4cda 1571
9c1e1052
PM
1572/*
1573 * We come here as a result of a DSI at a point where we don't want
1574 * to call hash_page, such as when we are accessing memory (possibly
1575 * user memory) inside a PMU interrupt that occurred while interrupts
1576 * were soft-disabled. We want to invoke the exception handler for
1577 * the access, or panic if there isn't a handler.
1578 */
b1576fec 157977: bl save_nvgprs
9c1e1052
PM
1580 mr r4,r3
1581 addi r3,r1,STACK_FRAME_OVERHEAD
1582 li r5,SIGSEGV
b1576fec
AB
1583 bl bad_page_fault
1584 b ret_from_except
4e2bf01b
ME
1585
1586/*
1587 * Here we have detected that the kernel stack pointer is bad.
1588 * R9 contains the saved CR, r13 points to the paca,
1589 * r10 contains the (bad) kernel stack pointer,
1590 * r11 and r12 contain the saved SRR0 and SRR1.
1591 * We switch to using an emergency stack, save the registers there,
1592 * and call kernel_bad_stack(), which panics.
1593 */
1594bad_stack:
1595 ld r1,PACAEMERGSP(r13)
1596 subi r1,r1,64+INT_FRAME_SIZE
1597 std r9,_CCR(r1)
1598 std r10,GPR1(r1)
1599 std r11,_NIP(r1)
1600 std r12,_MSR(r1)
1601 mfspr r11,SPRN_DAR
1602 mfspr r12,SPRN_DSISR
1603 std r11,_DAR(r1)
1604 std r12,_DSISR(r1)
1605 mflr r10
1606 mfctr r11
1607 mfxer r12
1608 std r10,_LINK(r1)
1609 std r11,_CTR(r1)
1610 std r12,_XER(r1)
1611 SAVE_GPR(0,r1)
1612 SAVE_GPR(2,r1)
1613 ld r10,EX_R3(r3)
1614 std r10,GPR3(r1)
1615 SAVE_GPR(4,r1)
1616 SAVE_4GPRS(5,r1)
1617 ld r9,EX_R9(r3)
1618 ld r10,EX_R10(r3)
1619 SAVE_2GPRS(9,r1)
1620 ld r9,EX_R11(r3)
1621 ld r10,EX_R12(r3)
1622 ld r11,EX_R13(r3)
1623 std r9,GPR11(r1)
1624 std r10,GPR12(r1)
1625 std r11,GPR13(r1)
1626BEGIN_FTR_SECTION
1627 ld r10,EX_CFAR(r3)
1628 std r10,ORIG_GPR3(r1)
1629END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1630 SAVE_8GPRS(14,r1)
1631 SAVE_10GPRS(22,r1)
1632 lhz r12,PACA_TRAP_SAVE(r13)
1633 std r12,_TRAP(r1)
1634 addi r11,r1,INT_FRAME_SIZE
1635 std r11,0(r1)
1636 li r12,0
1637 std r12,0(r11)
1638 ld r2,PACATOC(r13)
1639 ld r11,exception_marker@toc(r2)
1640 std r12,RESULT(r1)
1641 std r11,STACK_FRAME_OVERHEAD-16(r1)
16421: addi r3,r1,STACK_FRAME_OVERHEAD
1643 bl kernel_bad_stack
1644 b 1b
15770a13 1645_ASM_NOKPROBE_SYMBOL(bad_stack);
0f0c6ca1 1646
a9af97aa
NP
1647/*
1648 * When doorbell is triggered from system reset wakeup, the message is
1649 * not cleared, so it would fire again when EE is enabled.
1650 *
1651 * When coming from local_irq_enable, there may be the same problem if
1652 * we were hard disabled.
1653 *
1654 * Execute msgclr to clear pending exceptions before handling it.
1655 */
1656h_doorbell_common_msgclr:
1657 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1658 PPC_MSGCLR(3)
1659 b h_doorbell_common
1660
1661doorbell_super_common_msgclr:
1662 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1663 PPC_MSGCLRP(3)
1664 b doorbell_super_common
1665
0f0c6ca1
NP
1666/*
1667 * Called from arch_local_irq_enable when an interrupt needs
1668 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
1669 * which kind of interrupt. MSR:EE is already off. We generate a
1670 * stackframe like if a real interrupt had happened.
1671 *
1672 * Note: While MSR:EE is off, we need to make sure that _MSR
1673 * in the generated frame has EE set to 1 or the exception
1674 * handler will not properly re-enable them.
b48bbb82
NP
1675 *
1676 * Note that we don't specify LR as the NIP (return address) for
1677 * the interrupt because that would unbalance the return branch
1678 * predictor.
0f0c6ca1
NP
1679 */
1680_GLOBAL(__replay_interrupt)
1681 /* We are going to jump to the exception common code which
1682 * will retrieve various register values from the PACA which
1683 * we don't give a damn about, so we don't bother storing them.
1684 */
1685 mfmsr r12
3e23a12b 1686 LOAD_REG_ADDR(r11, replay_interrupt_return)
0f0c6ca1
NP
1687 mfcr r9
1688 ori r12,r12,MSR_EE
1689 cmpwi r3,0x900
1690 beq decrementer_common
1691 cmpwi r3,0x500
e6c1203d
NP
1692BEGIN_FTR_SECTION
1693 beq h_virt_irq_common
1694FTR_SECTION_ELSE
0f0c6ca1 1695 beq hardware_interrupt_common
e6c1203d 1696ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300)
0f0c6ca1 1697BEGIN_FTR_SECTION
d6f73fc6 1698 cmpwi r3,0xa00
a9af97aa 1699 beq h_doorbell_common_msgclr
0f0c6ca1
NP
1700 cmpwi r3,0xe60
1701 beq hmi_exception_common
1702FTR_SECTION_ELSE
1703 cmpwi r3,0xa00
a9af97aa 1704 beq doorbell_super_common_msgclr
0f0c6ca1 1705ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
3e23a12b 1706replay_interrupt_return:
0f0c6ca1 1707 blr
b48bbb82 1708
15770a13 1709_ASM_NOKPROBE_SYMBOL(__replay_interrupt)