]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/powerpc/kernel/exceptions-64s.S
powerpc/64s: Preserve r3 in slb_allocate_realmode()
[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)
0ebc4cda
BH
513 std r3,PACA_EXSLB+EX_R3(r13)
514 mfspr r3,SPRN_DAR
b01c8b54 515 mfspr r12,SPRN_SRR1
f0f558b1 516 crset 4*cr6+eq
0ebc4cda 517#ifndef CONFIG_RELOCATABLE
b1576fec 518 b slb_miss_realmode
0ebc4cda
BH
519#else
520 /*
ad0289e4 521 * We can't just use a direct branch to slb_miss_realmode
0ebc4cda
BH
522 * because the distance from here to there depends on where
523 * the kernel ends up being put.
524 */
525 mfctr r11
ad0289e4 526 LOAD_HANDLER(r10, slb_miss_realmode)
0ebc4cda
BH
527 mtctr r10
528 bctr
529#endif
1a6822d1 530EXC_REAL_END(data_access_slb, 0x380, 0x80)
0ebc4cda 531
1a6822d1 532EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
2b9af6e4
NP
533 SET_SCRATCH0(r13)
534 EXCEPTION_PROLOG_0(PACA_EXSLB)
535 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
536 std r3,PACA_EXSLB+EX_R3(r13)
537 mfspr r3,SPRN_DAR
538 mfspr r12,SPRN_SRR1
539 crset 4*cr6+eq
540#ifndef CONFIG_RELOCATABLE
541 b slb_miss_realmode
542#else
543 /*
544 * We can't just use a direct branch to slb_miss_realmode
545 * because the distance from here to there depends on where
546 * the kernel ends up being put.
547 */
548 mfctr r11
549 LOAD_HANDLER(r10, slb_miss_realmode)
550 mtctr r10
551 bctr
552#endif
1a6822d1 553EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
2b9af6e4
NP
554TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
555
556
1a6822d1
NP
557EXC_REAL(instruction_access, 0x400, 0x80)
558EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400)
27ce77df
NP
559TRAMP_KVM(PACA_EXGEN, 0x400)
560
561EXC_COMMON_BEGIN(instruction_access_common)
562 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
563 RECONCILE_IRQ_STATE(r10, r11)
564 ld r12,_MSR(r1)
565 ld r3,_NIP(r1)
566 andis. r4,r12,0x5820
567 li r5,0x400
568 std r3,_DAR(r1)
569 std r4,_DSISR(r1)
570BEGIN_MMU_FTR_SECTION
571 b do_hash_page /* Try to handle as hpte fault */
572MMU_FTR_SECTION_ELSE
573 b handle_page_fault
574ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
575
0ebc4cda 576
1a6822d1 577EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80)
673b189a 578 SET_SCRATCH0(r13)
1707dd16 579 EXCEPTION_PROLOG_0(PACA_EXSLB)
da2bc464 580 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
0ebc4cda
BH
581 std r3,PACA_EXSLB+EX_R3(r13)
582 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
b01c8b54 583 mfspr r12,SPRN_SRR1
f0f558b1 584 crclr 4*cr6+eq
0ebc4cda 585#ifndef CONFIG_RELOCATABLE
b1576fec 586 b slb_miss_realmode
0ebc4cda
BH
587#else
588 mfctr r11
ad0289e4 589 LOAD_HANDLER(r10, slb_miss_realmode)
0ebc4cda
BH
590 mtctr r10
591 bctr
592#endif
1a6822d1 593EXC_REAL_END(instruction_access_slb, 0x480, 0x80)
0ebc4cda 594
1a6822d1 595EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
8d04631a
NP
596 SET_SCRATCH0(r13)
597 EXCEPTION_PROLOG_0(PACA_EXSLB)
598 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
599 std r3,PACA_EXSLB+EX_R3(r13)
600 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
601 mfspr r12,SPRN_SRR1
602 crclr 4*cr6+eq
603#ifndef CONFIG_RELOCATABLE
604 b slb_miss_realmode
605#else
606 mfctr r11
607 LOAD_HANDLER(r10, slb_miss_realmode)
608 mtctr r10
609 bctr
610#endif
1a6822d1 611EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)
8d04631a
NP
612TRAMP_KVM(PACA_EXSLB, 0x480)
613
614
615/* This handler is used by both 0x380 and 0x480 slb miss interrupts */
616EXC_COMMON_BEGIN(slb_miss_realmode)
617 /*
618 * r13 points to the PACA, r9 contains the saved CR,
619 * r12 contain the saved SRR1, SRR0 is still ready for return
620 * r3 has the faulting address
621 * r9 - r13 are saved in paca->exslb.
622 * r3 is saved in paca->slb_r3
623 * cr6.eq is set for a D-SLB miss, clear for a I-SLB miss
624 * We assume we aren't going to take any exceptions during this
625 * procedure.
626 */
627 mflr r10
628#ifdef CONFIG_RELOCATABLE
629 mtctr r11
630#endif
631
632 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
633 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
634 std r3,PACA_EXSLB+EX_DAR(r13)
635
636 crset 4*cr0+eq
637#ifdef CONFIG_PPC_STD_MMU_64
638BEGIN_MMU_FTR_SECTION
639 bl slb_allocate_realmode
640END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
641#endif
642
643 ld r10,PACA_EXSLB+EX_LR(r13)
644 ld r3,PACA_EXSLB+EX_R3(r13)
645 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
646 mtlr r10
647
648 beq 8f /* if bad address, make full stack frame */
649
650 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
651 beq- 2f
652
653 /* All done -- return from exception. */
654
655.machine push
656.machine "power4"
657 mtcrf 0x80,r9
658 mtcrf 0x02,r9 /* I/D indication is in cr6 */
659 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
660.machine pop
661
662 RESTORE_PPR_PACA(PACA_EXSLB, r9)
663 ld r9,PACA_EXSLB+EX_R9(r13)
664 ld r10,PACA_EXSLB+EX_R10(r13)
665 ld r11,PACA_EXSLB+EX_R11(r13)
666 ld r12,PACA_EXSLB+EX_R12(r13)
667 ld r13,PACA_EXSLB+EX_R13(r13)
668 rfid
669 b . /* prevent speculative execution */
670
6712: mfspr r11,SPRN_SRR0
672 LOAD_HANDLER(r10,unrecov_slb)
673 mtspr SPRN_SRR0,r10
674 ld r10,PACAKMSR(r13)
675 mtspr SPRN_SRR1,r10
676 rfid
677 b .
678
6798: mfspr r11,SPRN_SRR0
680 LOAD_HANDLER(r10,bad_addr_slb)
681 mtspr SPRN_SRR0,r10
682 ld r10,PACAKMSR(r13)
683 mtspr SPRN_SRR1,r10
684 rfid
685 b .
686
687EXC_COMMON_BEGIN(unrecov_slb)
688 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
689 RECONCILE_IRQ_STATE(r10, r11)
690 bl save_nvgprs
6911: addi r3,r1,STACK_FRAME_OVERHEAD
692 bl unrecoverable_exception
693 b 1b
694
695EXC_COMMON_BEGIN(bad_addr_slb)
696 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
697 RECONCILE_IRQ_STATE(r10, r11)
698 ld r3, PACA_EXSLB+EX_DAR(r13)
699 std r3, _DAR(r1)
700 beq cr6, 2f
701 li r10, 0x480 /* fix trap number for I-SLB miss */
702 std r10, _TRAP(r1)
7032: bl save_nvgprs
704 addi r3, r1, STACK_FRAME_OVERHEAD
705 bl slb_miss_bad_addr
706 b ret_from_except
707
1a6822d1 708EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
b3e6b5df 709 .globl hardware_interrupt_hv;
b3e6b5df 710hardware_interrupt_hv:
a5d4f3ad 711 BEGIN_FTR_SECTION
da2bc464 712 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
b01c8b54 713 EXC_HV, SOFTEN_TEST_HV)
de56a948 714 FTR_SECTION_ELSE
da2bc464 715 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common,
31a40e2b 716 EXC_STD, SOFTEN_TEST_PR)
969391c5 717 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
1a6822d1 718EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
da2bc464 719
1a6822d1 720EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
c138e588
NP
721 .globl hardware_interrupt_relon_hv;
722hardware_interrupt_relon_hv:
723 BEGIN_FTR_SECTION
724 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_HV, SOFTEN_TEST_HV)
725 FTR_SECTION_ELSE
726 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_STD, SOFTEN_TEST_PR)
727 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1a6822d1 728EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
c138e588 729
7ede5317
NP
730TRAMP_KVM(PACA_EXGEN, 0x500)
731TRAMP_KVM_HV(PACA_EXGEN, 0x500)
c138e588
NP
732EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
733
734
1a6822d1
NP
735EXC_REAL(alignment, 0x600, 0x100)
736EXC_VIRT(alignment, 0x4600, 0x100, 0x600)
da2bc464 737TRAMP_KVM(PACA_EXGEN, 0x600)
f9aa6714
NP
738EXC_COMMON_BEGIN(alignment_common)
739 mfspr r10,SPRN_DAR
740 std r10,PACA_EXGEN+EX_DAR(r13)
741 mfspr r10,SPRN_DSISR
742 stw r10,PACA_EXGEN+EX_DSISR(r13)
743 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
744 ld r3,PACA_EXGEN+EX_DAR(r13)
745 lwz r4,PACA_EXGEN+EX_DSISR(r13)
746 std r3,_DAR(r1)
747 std r4,_DSISR(r1)
748 bl save_nvgprs
749 RECONCILE_IRQ_STATE(r10, r11)
750 addi r3,r1,STACK_FRAME_OVERHEAD
751 bl alignment_exception
752 b ret_from_except
753
da2bc464 754
1a6822d1
NP
755EXC_REAL(program_check, 0x700, 0x100)
756EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
da2bc464 757TRAMP_KVM(PACA_EXGEN, 0x700)
11e87346
NP
758EXC_COMMON_BEGIN(program_check_common)
759 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
760 bl save_nvgprs
761 RECONCILE_IRQ_STATE(r10, r11)
762 addi r3,r1,STACK_FRAME_OVERHEAD
763 bl program_check_exception
764 b ret_from_except
765
b01c8b54 766
1a6822d1
NP
767EXC_REAL(fp_unavailable, 0x800, 0x100)
768EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
da2bc464 769TRAMP_KVM(PACA_EXGEN, 0x800)
c78d9b97
NP
770EXC_COMMON_BEGIN(fp_unavailable_common)
771 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
772 bne 1f /* if from user, just load it up */
773 bl save_nvgprs
774 RECONCILE_IRQ_STATE(r10, r11)
775 addi r3,r1,STACK_FRAME_OVERHEAD
776 bl kernel_fp_unavailable_exception
777 BUG_OPCODE
7781:
779#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
780BEGIN_FTR_SECTION
781 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
782 * transaction), go do TM stuff
783 */
784 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
785 bne- 2f
786END_FTR_SECTION_IFSET(CPU_FTR_TM)
787#endif
788 bl load_up_fpu
789 b fast_exception_return
790#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
7912: /* User process was in a transaction */
792 bl save_nvgprs
793 RECONCILE_IRQ_STATE(r10, r11)
794 addi r3,r1,STACK_FRAME_OVERHEAD
795 bl fp_unavailable_tm
796 b ret_from_except
797#endif
798
a5d4f3ad 799
1a6822d1
NP
800EXC_REAL_MASKABLE(decrementer, 0x900, 0x80)
801EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900)
39c0da57
NP
802TRAMP_KVM(PACA_EXGEN, 0x900)
803EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
804
a485c709 805
1a6822d1
NP
806EXC_REAL_HV(hdecrementer, 0x980, 0x80)
807EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
facc6d74
NP
808TRAMP_KVM_HV(PACA_EXGEN, 0x980)
809EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
810
a5d4f3ad 811
1a6822d1
NP
812EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100)
813EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00)
da2bc464 814TRAMP_KVM(PACA_EXGEN, 0xa00)
ca243163
NP
815#ifdef CONFIG_PPC_DOORBELL
816EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
817#else
818EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
819#endif
820
0ebc4cda 821
1a6822d1
NP
822EXC_REAL(trap_0b, 0xb00, 0x100)
823EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
da2bc464 824TRAMP_KVM(PACA_EXGEN, 0xb00)
341215dc
NP
825EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
826
acd7d8ce
NP
827/*
828 * system call / hypercall (0xc00, 0x4c00)
829 *
830 * The system call exception is invoked with "sc 0" and does not alter HV bit.
831 * There is support for kernel code to invoke system calls but there are no
832 * in-tree users.
833 *
834 * The hypercall is invoked with "sc 1" and sets HV=1.
835 *
836 * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
837 * 0x4c00 virtual mode.
838 *
839 * Call convention:
840 *
841 * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
842 *
843 * For hypercalls, the register convention is as follows:
844 * r0 volatile
845 * r1-2 nonvolatile
846 * r3 volatile parameter and return value for status
847 * r4-r10 volatile input and output value
848 * r11 volatile hypercall number and output value
849 * r12 volatile
850 * r13-r31 nonvolatile
851 * LR nonvolatile
852 * CTR volatile
853 * XER volatile
854 * CR0-1 CR5-7 volatile
855 * CR2-4 nonvolatile
856 * Other registers nonvolatile
857 *
858 * The intersection of volatile registers that don't contain possible
859 * inputs is: r12, cr0, xer, ctr. We may use these as scratch regs
860 * upon entry without saving.
861 */
bc355125 862#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
acd7d8ce
NP
863 /*
864 * There is a little bit of juggling to get syscall and hcall
865 * working well. Save r10 in ctr to be restored in case it is a
866 * hcall.
867 *
868 * Userspace syscalls have already saved the PPR, hcalls must save
869 * it before setting HMT_MEDIUM.
870 */
bc355125 871#define SYSCALL_KVMTEST \
acd7d8ce 872 mr r12,r13; \
bc355125 873 GET_PACA(r13); \
acd7d8ce
NP
874 mtctr r10; \
875 KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
bc355125 876 HMT_MEDIUM; \
acd7d8ce 877 mr r9,r12; \
bc355125
PM
878
879#else
880#define SYSCALL_KVMTEST \
acd7d8ce
NP
881 HMT_MEDIUM; \
882 mr r9,r13; \
883 GET_PACA(r13);
bc355125
PM
884#endif
885
fb479e44
NP
886#define LOAD_SYSCALL_HANDLER(reg) \
887 __LOAD_HANDLER(reg, system_call_common)
d807ad37 888
acd7d8ce 889#define SYSCALL_FASTENDIAN_TEST \
d807ad37
NP
890BEGIN_FTR_SECTION \
891 cmpdi r0,0x1ebe ; \
892 beq- 1f ; \
893END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
d807ad37 894
acd7d8ce
NP
895/*
896 * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9,
897 * and HMT_MEDIUM.
898 */
899#define SYSCALL_REAL \
900 mfspr r11,SPRN_SRR0 ; \
d807ad37
NP
901 mfspr r12,SPRN_SRR1 ; \
902 LOAD_SYSCALL_HANDLER(r10) ; \
903 mtspr SPRN_SRR0,r10 ; \
904 ld r10,PACAKMSR(r13) ; \
905 mtspr SPRN_SRR1,r10 ; \
906 rfid ; \
907 b . ; /* prevent speculative execution */
908
acd7d8ce 909#define SYSCALL_FASTENDIAN \
d807ad37
NP
910 /* Fast LE/BE switch system call */ \
9111: mfspr r12,SPRN_SRR1 ; \
912 xori r12,r12,MSR_LE ; \
913 mtspr SPRN_SRR1,r12 ; \
acd7d8ce 914 mr r13,r9 ; \
d807ad37
NP
915 rfid ; /* return to userspace */ \
916 b . ; /* prevent speculative execution */
917
918#if defined(CONFIG_RELOCATABLE)
919 /*
920 * We can't branch directly so we do it via the CTR which
921 * is volatile across system calls.
922 */
acd7d8ce
NP
923#define SYSCALL_VIRT \
924 LOAD_SYSCALL_HANDLER(r10) ; \
925 mtctr r10 ; \
926 mfspr r11,SPRN_SRR0 ; \
d807ad37
NP
927 mfspr r12,SPRN_SRR1 ; \
928 li r10,MSR_RI ; \
929 mtmsrd r10,1 ; \
930 bctr ;
931#else
932 /* We can branch directly */
acd7d8ce
NP
933#define SYSCALL_VIRT \
934 mfspr r11,SPRN_SRR0 ; \
d807ad37
NP
935 mfspr r12,SPRN_SRR1 ; \
936 li r10,MSR_RI ; \
937 mtmsrd r10,1 ; /* Set RI (EE=0) */ \
938 b system_call_common ;
939#endif
940
1a6822d1 941EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
acd7d8ce
NP
942 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
943 SYSCALL_FASTENDIAN_TEST
944 SYSCALL_REAL
945 SYSCALL_FASTENDIAN
1a6822d1 946EXC_REAL_END(system_call, 0xc00, 0x100)
da2bc464 947
1a6822d1 948EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
acd7d8ce
NP
949 SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
950 SYSCALL_FASTENDIAN_TEST
951 SYSCALL_VIRT
952 SYSCALL_FASTENDIAN
1a6822d1 953EXC_VIRT_END(system_call, 0x4c00, 0x100)
d807ad37 954
acd7d8ce
NP
955#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
956 /*
957 * This is a hcall, so register convention is as above, with these
958 * differences:
959 * r13 = PACA
960 * r12 = orig r13
961 * ctr = orig r10
962 */
963TRAMP_KVM_BEGIN(do_kvm_0xc00)
964 /*
965 * Save the PPR (on systems that support it) before changing to
966 * HMT_MEDIUM. That allows the KVM code to save that value into the
967 * guest state (it is the guest's PPR value).
968 */
969 OPT_GET_SPR(r0, SPRN_PPR, CPU_FTR_HAS_PPR)
970 HMT_MEDIUM
971 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r0, CPU_FTR_HAS_PPR)
972 mfctr r10
973 SET_SCRATCH0(r12)
974 std r9,PACA_EXGEN+EX_R9(r13)
975 mfcr r9
976 std r10,PACA_EXGEN+EX_R10(r13)
977 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
978#endif
da2bc464 979
d807ad37 980
1a6822d1
NP
981EXC_REAL(single_step, 0xd00, 0x100)
982EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
da2bc464 983TRAMP_KVM(PACA_EXGEN, 0xd00)
bc6675c6 984EXC_COMMON(single_step_common, 0xd00, single_step_exception)
b01c8b54 985
1a6822d1 986EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
da0e7e62 987EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
f5c32c1d
NP
988TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
989EXC_COMMON_BEGIN(h_data_storage_common)
990 mfspr r10,SPRN_HDAR
991 std r10,PACA_EXGEN+EX_DAR(r13)
992 mfspr r10,SPRN_HDSISR
993 stw r10,PACA_EXGEN+EX_DSISR(r13)
994 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
995 bl save_nvgprs
996 RECONCILE_IRQ_STATE(r10, r11)
997 addi r3,r1,STACK_FRAME_OVERHEAD
998 bl unknown_exception
999 b ret_from_except
f5c32c1d 1000
1707dd16 1001
1a6822d1 1002EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
da0e7e62 1003EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
82517cab
NP
1004TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
1005EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
1006
1707dd16 1007
1a6822d1
NP
1008EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
1009EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
031b4026
NP
1010TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
1011EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
1012
1707dd16 1013
e0319829
NP
1014/*
1015 * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
1016 * first, and then eventaully from there to the trampoline to get into virtual
1017 * mode.
1018 */
1a6822d1 1019__EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
852e5da9 1020__TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60)
1a6822d1 1021EXC_VIRT_NONE(0x4e60, 0x20)
62f9b03b
NP
1022TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
1023TRAMP_REAL_BEGIN(hmi_exception_early)
1024 EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
a4087a4d
NP
1025 mr r10,r1 /* Save r1 */
1026 ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
62f9b03b 1027 subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
62f9b03b 1028 mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
a4087a4d
NP
1029 mfspr r12,SPRN_HSRR1 /* Save HSRR1 */
1030 EXCEPTION_PROLOG_COMMON_1()
62f9b03b
NP
1031 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1032 EXCEPTION_PROLOG_COMMON_3(0xe60)
1033 addi r3,r1,STACK_FRAME_OVERHEAD
be5c5e84 1034 BRANCH_LINK_TO_FAR(hmi_exception_realmode) /* Function call ABI */
62f9b03b
NP
1035 /* Windup the stack. */
1036 /* Move original HSRR0 and HSRR1 into the respective regs */
1037 ld r9,_MSR(r1)
1038 mtspr SPRN_HSRR1,r9
1039 ld r3,_NIP(r1)
1040 mtspr SPRN_HSRR0,r3
1041 ld r9,_CTR(r1)
1042 mtctr r9
1043 ld r9,_XER(r1)
1044 mtxer r9
1045 ld r9,_LINK(r1)
1046 mtlr r9
1047 REST_GPR(0, r1)
1048 REST_8GPRS(2, r1)
1049 REST_GPR(10, r1)
1050 ld r11,_CCR(r1)
1051 mtcr r11
1052 REST_GPR(11, r1)
1053 REST_2GPRS(12, r1)
1054 /* restore original r1. */
1055 ld r1,GPR1(r1)
1056
1057 /*
1058 * Go to virtual mode and pull the HMI event information from
1059 * firmware.
1060 */
1061 .globl hmi_exception_after_realmode
1062hmi_exception_after_realmode:
1063 SET_SCRATCH0(r13)
1064 EXCEPTION_PROLOG_0(PACA_EXGEN)
1065 b tramp_real_hmi_exception
1066
1067EXC_COMMON_ASYNC(hmi_exception_common, 0xe60, handle_hmi_exception)
1068
1707dd16 1069
1a6822d1
NP
1070EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20)
1071EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80)
9bcb81bf
NP
1072TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
1073#ifdef CONFIG_PPC_DOORBELL
1074EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
1075#else
1076EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
1077#endif
1078
0ebc4cda 1079
1a6822d1
NP
1080EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20)
1081EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0)
74408776
NP
1082TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
1083EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
1084
9baaef0a 1085
1a6822d1
NP
1086EXC_REAL_NONE(0xec0, 0x20)
1087EXC_VIRT_NONE(0x4ec0, 0x20)
1088EXC_REAL_NONE(0xee0, 0x20)
1089EXC_VIRT_NONE(0x4ee0, 0x20)
bda7fea2 1090
0ebc4cda 1091
1a6822d1
NP
1092EXC_REAL_OOL(performance_monitor, 0xf00, 0x20)
1093EXC_VIRT_OOL(performance_monitor, 0x4f00, 0x20, 0xf00)
b1c7f150
NP
1094TRAMP_KVM(PACA_EXGEN, 0xf00)
1095EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
1096
0ebc4cda 1097
1a6822d1
NP
1098EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
1099EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
d1a0ca9c
NP
1100TRAMP_KVM(PACA_EXGEN, 0xf20)
1101EXC_COMMON_BEGIN(altivec_unavailable_common)
1102 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1103#ifdef CONFIG_ALTIVEC
1104BEGIN_FTR_SECTION
1105 beq 1f
1106#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1107 BEGIN_FTR_SECTION_NESTED(69)
1108 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1109 * transaction), go do TM stuff
1110 */
1111 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1112 bne- 2f
1113 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1114#endif
1115 bl load_up_altivec
1116 b fast_exception_return
1117#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
11182: /* User process was in a transaction */
1119 bl save_nvgprs
1120 RECONCILE_IRQ_STATE(r10, r11)
1121 addi r3,r1,STACK_FRAME_OVERHEAD
1122 bl altivec_unavailable_tm
1123 b ret_from_except
1124#endif
11251:
1126END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1127#endif
1128 bl save_nvgprs
1129 RECONCILE_IRQ_STATE(r10, r11)
1130 addi r3,r1,STACK_FRAME_OVERHEAD
1131 bl altivec_unavailable_exception
1132 b ret_from_except
1133
0ebc4cda 1134
1a6822d1
NP
1135EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
1136EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
792cbddd
NP
1137TRAMP_KVM(PACA_EXGEN, 0xf40)
1138EXC_COMMON_BEGIN(vsx_unavailable_common)
1139 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1140#ifdef CONFIG_VSX
1141BEGIN_FTR_SECTION
1142 beq 1f
1143#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1144 BEGIN_FTR_SECTION_NESTED(69)
1145 /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
1146 * transaction), go do TM stuff
1147 */
1148 rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1149 bne- 2f
1150 END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1151#endif
1152 b load_up_vsx
1153#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
11542: /* User process was in a transaction */
1155 bl save_nvgprs
1156 RECONCILE_IRQ_STATE(r10, r11)
1157 addi r3,r1,STACK_FRAME_OVERHEAD
1158 bl vsx_unavailable_tm
1159 b ret_from_except
1160#endif
11611:
1162END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1163#endif
1164 bl save_nvgprs
1165 RECONCILE_IRQ_STATE(r10, r11)
1166 addi r3,r1,STACK_FRAME_OVERHEAD
1167 bl vsx_unavailable_exception
1168 b ret_from_except
1169
da2bc464 1170
1a6822d1
NP
1171EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
1172EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
1134713c
NP
1173TRAMP_KVM(PACA_EXGEN, 0xf60)
1174EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
1175
da2bc464 1176
1a6822d1
NP
1177EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
1178EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
14b0072c
NP
1179TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
1180EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
1181
da2bc464 1182
1a6822d1
NP
1183EXC_REAL_NONE(0xfa0, 0x20)
1184EXC_VIRT_NONE(0x4fa0, 0x20)
1185EXC_REAL_NONE(0xfc0, 0x20)
1186EXC_VIRT_NONE(0x4fc0, 0x20)
1187EXC_REAL_NONE(0xfe0, 0x20)
1188EXC_VIRT_NONE(0x4fe0, 0x20)
1189
1190EXC_REAL_NONE(0x1000, 0x100)
1191EXC_VIRT_NONE(0x5000, 0x100)
1192EXC_REAL_NONE(0x1100, 0x100)
1193EXC_VIRT_NONE(0x5100, 0x100)
d0c0c9a1 1194
0ebc4cda 1195#ifdef CONFIG_CBE_RAS
1a6822d1
NP
1196EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
1197EXC_VIRT_NONE(0x5200, 0x100)
da2bc464 1198TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
ff1b3206 1199EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
da2bc464 1200#else /* CONFIG_CBE_RAS */
1a6822d1
NP
1201EXC_REAL_NONE(0x1200, 0x100)
1202EXC_VIRT_NONE(0x5200, 0x100)
da2bc464 1203#endif
b01c8b54 1204
ff1b3206 1205
1a6822d1
NP
1206EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
1207EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
da2bc464 1208TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
4e96dbbf
NP
1209EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
1210
1a6822d1
NP
1211EXC_REAL_NONE(0x1400, 0x100)
1212EXC_VIRT_NONE(0x5400, 0x100)
da2bc464 1213
1a6822d1 1214EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
b92a66a6 1215 mtspr SPRN_SPRG_HSCRATCH0,r13
1707dd16 1216 EXCEPTION_PROLOG_0(PACA_EXGEN)
630573c1 1217 EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
b92a66a6
MN
1218
1219#ifdef CONFIG_PPC_DENORMALISATION
1220 mfspr r10,SPRN_HSRR1
1221 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
afcf0095
NP
1222 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
1223 addi r11,r11,-4 /* HSRR0 is next instruction */
1224 bne+ denorm_assist
1225#endif
1e9b4507 1226
afcf0095
NP
1227 KVMTEST_PR(0x1500)
1228 EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
1a6822d1 1229EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
a74599a5 1230
d7e89849 1231#ifdef CONFIG_PPC_DENORMALISATION
1a6822d1 1232EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
d7e89849 1233 b exc_real_0x1500_denorm_exception_hv
1a6822d1 1234EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
d7e89849 1235#else
1a6822d1 1236EXC_VIRT_NONE(0x5500, 0x100)
afcf0095
NP
1237#endif
1238
d7e89849 1239TRAMP_KVM_SKIP(PACA_EXGEN, 0x1500)
b01c8b54 1240
b92a66a6 1241#ifdef CONFIG_PPC_DENORMALISATION
da2bc464 1242TRAMP_REAL_BEGIN(denorm_assist)
b92a66a6
MN
1243BEGIN_FTR_SECTION
1244/*
1245 * To denormalise we need to move a copy of the register to itself.
1246 * For POWER6 do that here for all FP regs.
1247 */
1248 mfmsr r10
1249 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
1250 xori r10,r10,(MSR_FE0|MSR_FE1)
1251 mtmsrd r10
1252 sync
d7c67fb1
MN
1253
1254#define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
1255#define FMR4(n) FMR2(n) ; FMR2(n+2)
1256#define FMR8(n) FMR4(n) ; FMR4(n+4)
1257#define FMR16(n) FMR8(n) ; FMR8(n+8)
1258#define FMR32(n) FMR16(n) ; FMR16(n+16)
1259 FMR32(0)
1260
b92a66a6
MN
1261FTR_SECTION_ELSE
1262/*
1263 * To denormalise we need to move a copy of the register to itself.
1264 * For POWER7 do that here for the first 32 VSX registers only.
1265 */
1266 mfmsr r10
1267 oris r10,r10,MSR_VSX@h
1268 mtmsrd r10
1269 sync
d7c67fb1
MN
1270
1271#define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
1272#define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
1273#define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
1274#define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
1275#define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
1276 XVCPSGNDP32(0)
1277
b92a66a6 1278ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
fb0fce3e
MN
1279
1280BEGIN_FTR_SECTION
1281 b denorm_done
1282END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
1283/*
1284 * To denormalise we need to move a copy of the register to itself.
1285 * For POWER8 we need to do that for all 64 VSX registers
1286 */
1287 XVCPSGNDP32(32)
1288denorm_done:
b92a66a6
MN
1289 mtspr SPRN_HSRR0,r11
1290 mtcrf 0x80,r9
1291 ld r9,PACA_EXGEN+EX_R9(r13)
44e9309f 1292 RESTORE_PPR_PACA(PACA_EXGEN, r10)
630573c1
PM
1293BEGIN_FTR_SECTION
1294 ld r10,PACA_EXGEN+EX_CFAR(r13)
1295 mtspr SPRN_CFAR,r10
1296END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
b92a66a6
MN
1297 ld r10,PACA_EXGEN+EX_R10(r13)
1298 ld r11,PACA_EXGEN+EX_R11(r13)
1299 ld r12,PACA_EXGEN+EX_R12(r13)
1300 ld r13,PACA_EXGEN+EX_R13(r13)
1301 HRFID
1302 b .
1303#endif
1304
d7e89849
NP
1305EXC_COMMON_HV(denorm_common, 0x1500, unknown_exception)
1306
1307
1308#ifdef CONFIG_CBE_RAS
1a6822d1
NP
1309EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
1310EXC_VIRT_NONE(0x5600, 0x100)
d7e89849 1311TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
69a79344 1312EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
d7e89849 1313#else /* CONFIG_CBE_RAS */
1a6822d1
NP
1314EXC_REAL_NONE(0x1600, 0x100)
1315EXC_VIRT_NONE(0x5600, 0x100)
d7e89849
NP
1316#endif
1317
69a79344 1318
1a6822d1
NP
1319EXC_REAL(altivec_assist, 0x1700, 0x100)
1320EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
d7e89849 1321TRAMP_KVM(PACA_EXGEN, 0x1700)
b51c079e
NP
1322#ifdef CONFIG_ALTIVEC
1323EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
1324#else
1325EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
1326#endif
1327
d7e89849
NP
1328
1329#ifdef CONFIG_CBE_RAS
1a6822d1
NP
1330EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
1331EXC_VIRT_NONE(0x5800, 0x100)
d7e89849 1332TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
3965f8ab 1333EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
d7e89849 1334#else /* CONFIG_CBE_RAS */
1a6822d1
NP
1335EXC_REAL_NONE(0x1800, 0x100)
1336EXC_VIRT_NONE(0x5800, 0x100)
d7e89849
NP
1337#endif
1338
1339
0ebc4cda 1340/*
fe9e1d54
IM
1341 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
1342 * - If it was a decrementer interrupt, we bump the dec to max and and return.
1343 * - If it was a doorbell we return immediately since doorbells are edge
1344 * triggered and won't automatically refire.
0869b6fd
MS
1345 * - If it was a HMI we return immediately since we handled it in realmode
1346 * and it won't refire.
fe9e1d54
IM
1347 * - else we hard disable and return.
1348 * This is called with r10 containing the value to OR to the paca field.
0ebc4cda 1349 */
7230c564
BH
1350#define MASKED_INTERRUPT(_H) \
1351masked_##_H##interrupt: \
1352 std r11,PACA_EXGEN+EX_R11(r13); \
1353 lbz r11,PACAIRQHAPPENED(r13); \
1354 or r11,r11,r10; \
1355 stb r11,PACAIRQHAPPENED(r13); \
fe9e1d54
IM
1356 cmpwi r10,PACA_IRQ_DEC; \
1357 bne 1f; \
7230c564
BH
1358 lis r10,0x7fff; \
1359 ori r10,r10,0xffff; \
1360 mtspr SPRN_DEC,r10; \
1361 b 2f; \
fe9e1d54 13621: cmpwi r10,PACA_IRQ_DBELL; \
0869b6fd
MS
1363 beq 2f; \
1364 cmpwi r10,PACA_IRQ_HMI; \
fe9e1d54
IM
1365 beq 2f; \
1366 mfspr r10,SPRN_##_H##SRR1; \
7230c564
BH
1367 rldicl r10,r10,48,1; /* clear MSR_EE */ \
1368 rotldi r10,r10,16; \
1369 mtspr SPRN_##_H##SRR1,r10; \
13702: mtcrf 0x80,r9; \
1371 ld r9,PACA_EXGEN+EX_R9(r13); \
1372 ld r10,PACA_EXGEN+EX_R10(r13); \
1373 ld r11,PACA_EXGEN+EX_R11(r13); \
1374 GET_SCRATCH0(r13); \
1375 ##_H##rfid; \
0ebc4cda 1376 b .
57f26649
NP
1377
1378/*
1379 * Real mode exceptions actually use this too, but alternate
1380 * instruction code patches (which end up in the common .text area)
1381 * cannot reach these if they are put there.
1382 */
1383USE_FIXED_SECTION(virt_trampolines)
7230c564
BH
1384 MASKED_INTERRUPT()
1385 MASKED_INTERRUPT(H)
0ebc4cda 1386
4f6c11db 1387#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
da2bc464 1388TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
4f6c11db
PM
1389 /*
1390 * Here all GPRs are unchanged from when the interrupt happened
1391 * except for r13, which is saved in SPRG_SCRATCH0.
1392 */
1393 mfspr r13, SPRN_SRR0
1394 addi r13, r13, 4
1395 mtspr SPRN_SRR0, r13
1396 GET_SCRATCH0(r13)
1397 rfid
1398 b .
1399
da2bc464 1400TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
4f6c11db
PM
1401 /*
1402 * Here all GPRs are unchanged from when the interrupt happened
1403 * except for r13, which is saved in SPRG_SCRATCH0.
1404 */
1405 mfspr r13, SPRN_HSRR0
1406 addi r13, r13, 4
1407 mtspr SPRN_HSRR0, r13
1408 GET_SCRATCH0(r13)
1409 hrfid
1410 b .
1411#endif
1412
0ebc4cda 1413/*
057b6d7e
HB
1414 * Ensure that any handlers that get invoked from the exception prologs
1415 * above are below the first 64KB (0x10000) of the kernel image because
1416 * the prologs assemble the addresses of these handlers using the
1417 * LOAD_HANDLER macro, which uses an ori instruction.
0ebc4cda
BH
1418 */
1419
1420/*** Common interrupt handlers ***/
1421
0ebc4cda 1422
c1fb6816
MN
1423 /*
1424 * Relocation-on interrupts: A subset of the interrupts can be delivered
1425 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
1426 * it. Addresses are the same as the original interrupt addresses, but
1427 * offset by 0xc000000000004000.
1428 * It's impossible to receive interrupts below 0x300 via this mechanism.
1429 * KVM: None of these traps are from the guest ; anything that escalated
1430 * to HV=1 from HV=0 is delivered via real mode handlers.
1431 */
1432
1433 /*
1434 * This uses the standard macro, since the original 0x300 vector
1435 * only has extra guff for STAB-based processors -- which never
1436 * come here.
1437 */
da2bc464 1438
57f26649 1439EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
b1576fec 1440 b __ppc64_runlatch_on
fe1952fc 1441
57f26649 1442USE_FIXED_SECTION(virt_trampolines)
8ed8ab40
HB
1443 /*
1444 * The __end_interrupts marker must be past the out-of-line (OOL)
1445 * handlers, so that they are copied to real address 0x100 when running
1446 * a relocatable kernel. This ensures they can be reached from the short
1447 * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
1448 * directly, without using LOAD_HANDLER().
1449 */
1450 .align 7
1451 .globl __end_interrupts
1452__end_interrupts:
57f26649 1453DEFINE_FIXED_SYMBOL(__end_interrupts)
61383407 1454
087aa036 1455#ifdef CONFIG_PPC_970_NAP
7c8cb4b5 1456EXC_COMMON_BEGIN(power4_fixup_nap)
087aa036
CG
1457 andc r9,r9,r10
1458 std r9,TI_LOCAL_FLAGS(r11)
1459 ld r10,_LINK(r1) /* make idle task do the */
1460 std r10,_NIP(r1) /* equivalent of a blr */
1461 blr
1462#endif
1463
57f26649
NP
1464CLOSE_FIXED_SECTION(real_vectors);
1465CLOSE_FIXED_SECTION(real_trampolines);
1466CLOSE_FIXED_SECTION(virt_vectors);
1467CLOSE_FIXED_SECTION(virt_trampolines);
1468
1469USE_TEXT_SECTION()
1470
0ebc4cda
BH
1471/*
1472 * Hash table stuff
1473 */
f4329f2e 1474 .balign IFETCH_ALIGN_BYTES
6a3bab90 1475do_hash_page:
caca285e 1476#ifdef CONFIG_PPC_STD_MMU_64
9c7cc234 1477 andis. r0,r4,0xa410 /* weird error? */
0ebc4cda 1478 bne- handle_page_fault /* if not, try to insert a HPTE */
9c7cc234
P
1479 andis. r0,r4,DSISR_DABRMATCH@h
1480 bne- handle_dabr_fault
9778b696 1481 CURRENT_THREAD_INFO(r11, r1)
9c1e1052
PM
1482 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
1483 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
1484 bne 77f /* then don't call hash_page now */
0ebc4cda
BH
1485
1486 /*
1487 * r3 contains the faulting address
106713a1 1488 * r4 msr
0ebc4cda 1489 * r5 contains the trap number
aefa5688 1490 * r6 contains dsisr
0ebc4cda 1491 *
7230c564 1492 * at return r3 = 0 for success, 1 for page fault, negative for error
0ebc4cda 1493 */
106713a1 1494 mr r4,r12
aefa5688 1495 ld r6,_DSISR(r1)
106713a1
AK
1496 bl __hash_page /* build HPTE if possible */
1497 cmpdi r3,0 /* see if __hash_page succeeded */
0ebc4cda 1498
7230c564 1499 /* Success */
0ebc4cda 1500 beq fast_exc_return_irq /* Return from exception on success */
0ebc4cda 1501
7230c564
BH
1502 /* Error */
1503 blt- 13f
caca285e 1504#endif /* CONFIG_PPC_STD_MMU_64 */
9c7cc234 1505
0ebc4cda
BH
1506/* Here we have a page fault that hash_page can't handle. */
1507handle_page_fault:
0ebc4cda
BH
150811: ld r4,_DAR(r1)
1509 ld r5,_DSISR(r1)
1510 addi r3,r1,STACK_FRAME_OVERHEAD
b1576fec 1511 bl do_page_fault
0ebc4cda 1512 cmpdi r3,0
a546498f 1513 beq+ 12f
b1576fec 1514 bl save_nvgprs
0ebc4cda
BH
1515 mr r5,r3
1516 addi r3,r1,STACK_FRAME_OVERHEAD
1517 lwz r4,_DAR(r1)
b1576fec
AB
1518 bl bad_page_fault
1519 b ret_from_except
0ebc4cda 1520
a546498f
BH
1521/* We have a data breakpoint exception - handle it */
1522handle_dabr_fault:
b1576fec 1523 bl save_nvgprs
a546498f
BH
1524 ld r4,_DAR(r1)
1525 ld r5,_DSISR(r1)
1526 addi r3,r1,STACK_FRAME_OVERHEAD
b1576fec
AB
1527 bl do_break
152812: b ret_from_except_lite
a546498f 1529
0ebc4cda 1530
caca285e 1531#ifdef CONFIG_PPC_STD_MMU_64
0ebc4cda
BH
1532/* We have a page fault that hash_page could handle but HV refused
1533 * the PTE insertion
1534 */
b1576fec 153513: bl save_nvgprs
0ebc4cda
BH
1536 mr r5,r3
1537 addi r3,r1,STACK_FRAME_OVERHEAD
1538 ld r4,_DAR(r1)
b1576fec
AB
1539 bl low_hash_fault
1540 b ret_from_except
caca285e 1541#endif
0ebc4cda 1542
9c1e1052
PM
1543/*
1544 * We come here as a result of a DSI at a point where we don't want
1545 * to call hash_page, such as when we are accessing memory (possibly
1546 * user memory) inside a PMU interrupt that occurred while interrupts
1547 * were soft-disabled. We want to invoke the exception handler for
1548 * the access, or panic if there isn't a handler.
1549 */
b1576fec 155077: bl save_nvgprs
9c1e1052
PM
1551 mr r4,r3
1552 addi r3,r1,STACK_FRAME_OVERHEAD
1553 li r5,SIGSEGV
b1576fec
AB
1554 bl bad_page_fault
1555 b ret_from_except
4e2bf01b
ME
1556
1557/*
1558 * Here we have detected that the kernel stack pointer is bad.
1559 * R9 contains the saved CR, r13 points to the paca,
1560 * r10 contains the (bad) kernel stack pointer,
1561 * r11 and r12 contain the saved SRR0 and SRR1.
1562 * We switch to using an emergency stack, save the registers there,
1563 * and call kernel_bad_stack(), which panics.
1564 */
1565bad_stack:
1566 ld r1,PACAEMERGSP(r13)
1567 subi r1,r1,64+INT_FRAME_SIZE
1568 std r9,_CCR(r1)
1569 std r10,GPR1(r1)
1570 std r11,_NIP(r1)
1571 std r12,_MSR(r1)
1572 mfspr r11,SPRN_DAR
1573 mfspr r12,SPRN_DSISR
1574 std r11,_DAR(r1)
1575 std r12,_DSISR(r1)
1576 mflr r10
1577 mfctr r11
1578 mfxer r12
1579 std r10,_LINK(r1)
1580 std r11,_CTR(r1)
1581 std r12,_XER(r1)
1582 SAVE_GPR(0,r1)
1583 SAVE_GPR(2,r1)
1584 ld r10,EX_R3(r3)
1585 std r10,GPR3(r1)
1586 SAVE_GPR(4,r1)
1587 SAVE_4GPRS(5,r1)
1588 ld r9,EX_R9(r3)
1589 ld r10,EX_R10(r3)
1590 SAVE_2GPRS(9,r1)
1591 ld r9,EX_R11(r3)
1592 ld r10,EX_R12(r3)
1593 ld r11,EX_R13(r3)
1594 std r9,GPR11(r1)
1595 std r10,GPR12(r1)
1596 std r11,GPR13(r1)
1597BEGIN_FTR_SECTION
1598 ld r10,EX_CFAR(r3)
1599 std r10,ORIG_GPR3(r1)
1600END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1601 SAVE_8GPRS(14,r1)
1602 SAVE_10GPRS(22,r1)
1603 lhz r12,PACA_TRAP_SAVE(r13)
1604 std r12,_TRAP(r1)
1605 addi r11,r1,INT_FRAME_SIZE
1606 std r11,0(r1)
1607 li r12,0
1608 std r12,0(r11)
1609 ld r2,PACATOC(r13)
1610 ld r11,exception_marker@toc(r2)
1611 std r12,RESULT(r1)
1612 std r11,STACK_FRAME_OVERHEAD-16(r1)
16131: addi r3,r1,STACK_FRAME_OVERHEAD
1614 bl kernel_bad_stack
1615 b 1b
0f0c6ca1 1616
a9af97aa
NP
1617/*
1618 * When doorbell is triggered from system reset wakeup, the message is
1619 * not cleared, so it would fire again when EE is enabled.
1620 *
1621 * When coming from local_irq_enable, there may be the same problem if
1622 * we were hard disabled.
1623 *
1624 * Execute msgclr to clear pending exceptions before handling it.
1625 */
1626h_doorbell_common_msgclr:
1627 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1628 PPC_MSGCLR(3)
1629 b h_doorbell_common
1630
1631doorbell_super_common_msgclr:
1632 LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
1633 PPC_MSGCLRP(3)
1634 b doorbell_super_common
1635
0f0c6ca1
NP
1636/*
1637 * Called from arch_local_irq_enable when an interrupt needs
1638 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
1639 * which kind of interrupt. MSR:EE is already off. We generate a
1640 * stackframe like if a real interrupt had happened.
1641 *
1642 * Note: While MSR:EE is off, we need to make sure that _MSR
1643 * in the generated frame has EE set to 1 or the exception
1644 * handler will not properly re-enable them.
b48bbb82
NP
1645 *
1646 * Note that we don't specify LR as the NIP (return address) for
1647 * the interrupt because that would unbalance the return branch
1648 * predictor.
0f0c6ca1
NP
1649 */
1650_GLOBAL(__replay_interrupt)
1651 /* We are going to jump to the exception common code which
1652 * will retrieve various register values from the PACA which
1653 * we don't give a damn about, so we don't bother storing them.
1654 */
1655 mfmsr r12
b48bbb82 1656 LOAD_REG_ADDR(r11, .L__replay_interrupt_return)
0f0c6ca1
NP
1657 mfcr r9
1658 ori r12,r12,MSR_EE
1659 cmpwi r3,0x900
1660 beq decrementer_common
1661 cmpwi r3,0x500
1662 beq hardware_interrupt_common
1663BEGIN_FTR_SECTION
1664 cmpwi r3,0xe80
a9af97aa 1665 beq h_doorbell_common_msgclr
0f0c6ca1
NP
1666 cmpwi r3,0xea0
1667 beq h_virt_irq_common
1668 cmpwi r3,0xe60
1669 beq hmi_exception_common
1670FTR_SECTION_ELSE
1671 cmpwi r3,0xa00
a9af97aa 1672 beq doorbell_super_common_msgclr
0f0c6ca1 1673ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
b48bbb82 1674.L__replay_interrupt_return:
0f0c6ca1 1675 blr
b48bbb82 1676