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