20e758ee704bb38e143aee65afd45814dc709a3b
[linux-2.6-block.git] / arch / powerpc / kernel / exceptions-64s.S
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * This file contains the 64-bit "server" PowerPC variant
4  * of the low level exception handling including exception
5  * vectors, exception return, part of the slb and stab
6  * handling and other fixed offset specific things.
7  *
8  * This file is meant to be #included from head_64.S due to
9  * position dependent assembly.
10  *
11  * Most of this originates from head_64.S and thus has the same
12  * copyright history.
13  *
14  */
15
16 #include <asm/hw_irq.h>
17 #include <asm/exception-64s.h>
18 #include <asm/ptrace.h>
19 #include <asm/cpuidle.h>
20 #include <asm/head-64.h>
21 #include <asm/feature-fixups.h>
22 #include <asm/kup.h>
23
24 /* PACA save area offsets (exgen, exmc, etc) */
25 #define EX_R9           0
26 #define EX_R10          8
27 #define EX_R11          16
28 #define EX_R12          24
29 #define EX_R13          32
30 #define EX_DAR          40
31 #define EX_DSISR        48
32 #define EX_CCR          52
33 #define EX_CFAR         56
34 #define EX_PPR          64
35 #if defined(CONFIG_RELOCATABLE)
36 #define EX_CTR          72
37 .if EX_SIZE != 10
38         .error "EX_SIZE is wrong"
39 .endif
40 #else
41 .if EX_SIZE != 9
42         .error "EX_SIZE is wrong"
43 .endif
44 #endif
45
46 /*
47  * We're short on space and time in the exception prolog, so we can't
48  * use the normal LOAD_REG_IMMEDIATE macro to load the address of label.
49  * Instead we get the base of the kernel from paca->kernelbase and or in the low
50  * part of label. This requires that the label be within 64KB of kernelbase, and
51  * that kernelbase be 64K aligned.
52  */
53 #define LOAD_HANDLER(reg, label)                                        \
54         ld      reg,PACAKBASE(r13);     /* get high part of &label */   \
55         ori     reg,reg,FIXED_SYMBOL_ABS_ADDR(label)
56
57 #define __LOAD_HANDLER(reg, label)                                      \
58         ld      reg,PACAKBASE(r13);                                     \
59         ori     reg,reg,(ABS_ADDR(label))@l
60
61 /*
62  * Branches from unrelocated code (e.g., interrupts) to labels outside
63  * head-y require >64K offsets.
64  */
65 #define __LOAD_FAR_HANDLER(reg, label)                                  \
66         ld      reg,PACAKBASE(r13);                                     \
67         ori     reg,reg,(ABS_ADDR(label))@l;                            \
68         addis   reg,reg,(ABS_ADDR(label))@h
69
70 /* Exception register prefixes */
71 #define EXC_HV          1
72 #define EXC_STD         0
73
74 #if defined(CONFIG_RELOCATABLE)
75 /*
76  * If we support interrupts with relocation on AND we're a relocatable kernel,
77  * we need to use CTR to get to the 2nd level handler.  So, save/restore it
78  * when required.
79  */
80 #define SAVE_CTR(reg, area)     mfctr   reg ;   std     reg,area+EX_CTR(r13)
81 #define GET_CTR(reg, area)                      ld      reg,area+EX_CTR(r13)
82 #define RESTORE_CTR(reg, area)  ld      reg,area+EX_CTR(r13) ; mtctr reg
83 #else
84 /* ...else CTR is unused and in register. */
85 #define SAVE_CTR(reg, area)
86 #define GET_CTR(reg, area)      mfctr   reg
87 #define RESTORE_CTR(reg, area)
88 #endif
89
90 /*
91  * PPR save/restore macros used in exceptions-64s.S
92  * Used for P7 or later processors
93  */
94 #define SAVE_PPR(area, ra)                                              \
95 BEGIN_FTR_SECTION_NESTED(940)                                           \
96         ld      ra,area+EX_PPR(r13);    /* Read PPR from paca */        \
97         std     ra,_PPR(r1);                                            \
98 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940)
99
100 #define RESTORE_PPR_PACA(area, ra)                                      \
101 BEGIN_FTR_SECTION_NESTED(941)                                           \
102         ld      ra,area+EX_PPR(r13);                                    \
103         mtspr   SPRN_PPR,ra;                                            \
104 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941)
105
106 /*
107  * Get an SPR into a register if the CPU has the given feature
108  */
109 #define OPT_GET_SPR(ra, spr, ftr)                                       \
110 BEGIN_FTR_SECTION_NESTED(943)                                           \
111         mfspr   ra,spr;                                                 \
112 END_FTR_SECTION_NESTED(ftr,ftr,943)
113
114 /*
115  * Set an SPR from a register if the CPU has the given feature
116  */
117 #define OPT_SET_SPR(ra, spr, ftr)                                       \
118 BEGIN_FTR_SECTION_NESTED(943)                                           \
119         mtspr   spr,ra;                                                 \
120 END_FTR_SECTION_NESTED(ftr,ftr,943)
121
122 /*
123  * Save a register to the PACA if the CPU has the given feature
124  */
125 #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr)                           \
126 BEGIN_FTR_SECTION_NESTED(943)                                           \
127         std     ra,offset(r13);                                         \
128 END_FTR_SECTION_NESTED(ftr,ftr,943)
129
130 .macro EXCEPTION_PROLOG_0 area
131         GET_PACA(r13)
132         std     r9,\area\()+EX_R9(r13)          /* save r9 */
133         OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR)
134         HMT_MEDIUM
135         std     r10,\area\()+EX_R10(r13)        /* save r10 - r12 */
136         OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR)
137 .endm
138
139 .macro EXCEPTION_PROLOG_1 hsrr, area, kvm, vec, bitmask
140         OPT_SAVE_REG_TO_PACA(\area\()+EX_PPR, r9, CPU_FTR_HAS_PPR)
141         OPT_SAVE_REG_TO_PACA(\area\()+EX_CFAR, r10, CPU_FTR_CFAR)
142         INTERRUPT_TO_KERNEL
143         SAVE_CTR(r10, \area\())
144         mfcr    r9
145         .if \kvm
146                 KVMTEST \hsrr \vec
147         .endif
148         .if \bitmask
149                 lbz     r10,PACAIRQSOFTMASK(r13)
150                 andi.   r10,r10,\bitmask
151                 /* Associate vector numbers with bits in paca->irq_happened */
152                 .if \vec == 0x500 || \vec == 0xea0
153                 li      r10,PACA_IRQ_EE
154                 .elseif \vec == 0x900
155                 li      r10,PACA_IRQ_DEC
156                 .elseif \vec == 0xa00 || \vec == 0xe80
157                 li      r10,PACA_IRQ_DBELL
158                 .elseif \vec == 0xe60
159                 li      r10,PACA_IRQ_HMI
160                 .elseif \vec == 0xf00
161                 li      r10,PACA_IRQ_PMI
162                 .else
163                 .abort "Bad maskable vector"
164                 .endif
165
166                 .if \hsrr
167                 bne     masked_Hinterrupt
168                 .else
169                 bne     masked_interrupt
170                 .endif
171         .endif
172
173         std     r11,\area\()+EX_R11(r13)
174         std     r12,\area\()+EX_R12(r13)
175         GET_SCRATCH0(r10)
176         std     r10,\area\()+EX_R13(r13)
177 .endm
178
179 .macro EXCEPTION_PROLOG_2_REAL label, hsrr, set_ri
180         ld      r10,PACAKMSR(r13)       /* get MSR value for kernel */
181         .if ! \set_ri
182         xori    r10,r10,MSR_RI          /* Clear MSR_RI */
183         .endif
184         .if \hsrr
185         mfspr   r11,SPRN_HSRR0          /* save HSRR0 */
186         mfspr   r12,SPRN_HSRR1          /* and HSRR1 */
187         mtspr   SPRN_HSRR1,r10
188         .else
189         mfspr   r11,SPRN_SRR0           /* save SRR0 */
190         mfspr   r12,SPRN_SRR1           /* and SRR1 */
191         mtspr   SPRN_SRR1,r10
192         .endif
193         LOAD_HANDLER(r10, \label\())
194         .if \hsrr
195         mtspr   SPRN_HSRR0,r10
196         HRFI_TO_KERNEL
197         .else
198         mtspr   SPRN_SRR0,r10
199         RFI_TO_KERNEL
200         .endif
201         b       .       /* prevent speculative execution */
202 .endm
203
204 .macro EXCEPTION_PROLOG_2_VIRT label, hsrr
205 #ifdef CONFIG_RELOCATABLE
206         .if \hsrr
207         mfspr   r11,SPRN_HSRR0  /* save HSRR0 */
208         .else
209         mfspr   r11,SPRN_SRR0   /* save SRR0 */
210         .endif
211         LOAD_HANDLER(r12, \label\())
212         mtctr   r12
213         .if \hsrr
214         mfspr   r12,SPRN_HSRR1  /* and HSRR1 */
215         .else
216         mfspr   r12,SPRN_SRR1   /* and HSRR1 */
217         .endif
218         li      r10,MSR_RI
219         mtmsrd  r10,1           /* Set RI (EE=0) */
220         bctr
221 #else
222         .if \hsrr
223         mfspr   r11,SPRN_HSRR0          /* save HSRR0 */
224         mfspr   r12,SPRN_HSRR1          /* and HSRR1 */
225         .else
226         mfspr   r11,SPRN_SRR0           /* save SRR0 */
227         mfspr   r12,SPRN_SRR1           /* and SRR1 */
228         .endif
229         li      r10,MSR_RI
230         mtmsrd  r10,1                   /* Set RI (EE=0) */
231         b       \label
232 #endif
233 .endm
234
235 /*
236  * Branch to label using its 0xC000 address. This results in instruction
237  * address suitable for MSR[IR]=0 or 1, which allows relocation to be turned
238  * on using mtmsr rather than rfid.
239  *
240  * This could set the 0xc bits for !RELOCATABLE as an immediate, rather than
241  * load KBASE for a slight optimisation.
242  */
243 #define BRANCH_TO_C000(reg, label)                                      \
244         __LOAD_HANDLER(reg, label);                                     \
245         mtctr   reg;                                                    \
246         bctr
247
248 #ifdef CONFIG_RELOCATABLE
249 #define BRANCH_LINK_TO_FAR(label)                                       \
250         __LOAD_FAR_HANDLER(r12, label);                                 \
251         mtctr   r12;                                                    \
252         bctrl
253
254 #else
255 #define BRANCH_LINK_TO_FAR(label)                                       \
256         bl      label
257 #endif
258
259 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
260 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
261 /*
262  * If hv is possible, interrupts come into to the hv version
263  * of the kvmppc_interrupt code, which then jumps to the PR handler,
264  * kvmppc_interrupt_pr, if the guest is a PR guest.
265  */
266 #define kvmppc_interrupt kvmppc_interrupt_hv
267 #else
268 #define kvmppc_interrupt kvmppc_interrupt_pr
269 #endif
270
271 .macro KVMTEST hsrr, n
272         lbz     r10,HSTATE_IN_GUEST(r13)
273         cmpwi   r10,0
274         .if \hsrr
275         bne     do_kvm_H\n
276         .else
277         bne     do_kvm_\n
278         .endif
279 .endm
280
281 .macro KVM_HANDLER area, hsrr, n, skip
282         .if \skip
283         cmpwi   r10,KVM_GUEST_MODE_SKIP
284         beq     89f
285         .else
286 BEGIN_FTR_SECTION_NESTED(947)
287         ld      r10,\area+EX_CFAR(r13)
288         std     r10,HSTATE_CFAR(r13)
289 END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947)
290         .endif
291
292 BEGIN_FTR_SECTION_NESTED(948)
293         ld      r10,\area+EX_PPR(r13)
294         std     r10,HSTATE_PPR(r13)
295 END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948)
296         ld      r10,\area+EX_R10(r13)
297         std     r12,HSTATE_SCRATCH0(r13)
298         sldi    r12,r9,32
299         /* HSRR variants have the 0x2 bit added to their trap number */
300         .if \hsrr
301         ori     r12,r12,(\n + 0x2)
302         .else
303         ori     r12,r12,(\n)
304         .endif
305
306 #ifdef CONFIG_RELOCATABLE
307         /*
308          * KVM requires __LOAD_FAR_HANDLER beause kvmppc_interrupt lives
309          * outside the head section. CONFIG_RELOCATABLE KVM expects CTR
310          * to be saved in HSTATE_SCRATCH1.
311          */
312         mfctr   r9
313         std     r9,HSTATE_SCRATCH1(r13)
314         __LOAD_FAR_HANDLER(r9, kvmppc_interrupt)
315         mtctr   r9
316         ld      r9,\area+EX_R9(r13)
317         bctr
318 #else
319         ld      r9,\area+EX_R9(r13)
320         b       kvmppc_interrupt
321 #endif
322
323
324         .if \skip
325 89:     mtocrf  0x80,r9
326         ld      r9,\area+EX_R9(r13)
327         ld      r10,\area+EX_R10(r13)
328         .if \hsrr
329         b       kvmppc_skip_Hinterrupt
330         .else
331         b       kvmppc_skip_interrupt
332         .endif
333         .endif
334 .endm
335
336 #else
337 .macro KVMTEST hsrr, n
338 .endm
339 .macro KVM_HANDLER area, hsrr, n, skip
340 .endm
341 #endif
342
343 #define EXCEPTION_PROLOG_COMMON_1()                                        \
344         std     r9,_CCR(r1);            /* save CR in stackframe        */ \
345         std     r11,_NIP(r1);           /* save SRR0 in stackframe      */ \
346         std     r12,_MSR(r1);           /* save SRR1 in stackframe      */ \
347         std     r10,0(r1);              /* make stack chain pointer     */ \
348         std     r0,GPR0(r1);            /* save r0 in stackframe        */ \
349         std     r10,GPR1(r1);           /* save r1 in stackframe        */ \
350
351 /* Save original regs values from save area to stack frame. */
352 #define EXCEPTION_PROLOG_COMMON_2(area)                                    \
353         ld      r9,area+EX_R9(r13);     /* move r9, r10 to stackframe   */ \
354         ld      r10,area+EX_R10(r13);                                      \
355         std     r9,GPR9(r1);                                               \
356         std     r10,GPR10(r1);                                             \
357         ld      r9,area+EX_R11(r13);    /* move r11 - r13 to stackframe */ \
358         ld      r10,area+EX_R12(r13);                                      \
359         ld      r11,area+EX_R13(r13);                                      \
360         std     r9,GPR11(r1);                                              \
361         std     r10,GPR12(r1);                                             \
362         std     r11,GPR13(r1);                                             \
363 BEGIN_FTR_SECTION_NESTED(66);                                              \
364         ld      r10,area+EX_CFAR(r13);                                     \
365         std     r10,ORIG_GPR3(r1);                                         \
366 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66);                    \
367         GET_CTR(r10, area);                                                \
368         std     r10,_CTR(r1);
369
370 #define EXCEPTION_PROLOG_COMMON_3(trap)                                    \
371         std     r2,GPR2(r1);            /* save r2 in stackframe        */ \
372         SAVE_4GPRS(3, r1);              /* save r3 - r6 in stackframe   */ \
373         SAVE_2GPRS(7, r1);              /* save r7, r8 in stackframe    */ \
374         mflr    r9;                     /* Get LR, later save to stack  */ \
375         ld      r2,PACATOC(r13);        /* get kernel TOC into r2       */ \
376         std     r9,_LINK(r1);                                              \
377         lbz     r10,PACAIRQSOFTMASK(r13);                                  \
378         mfspr   r11,SPRN_XER;           /* save XER in stackframe       */ \
379         std     r10,SOFTE(r1);                                             \
380         std     r11,_XER(r1);                                              \
381         li      r9,(trap)+1;                                               \
382         std     r9,_TRAP(r1);           /* set trap number              */ \
383         li      r10,0;                                                     \
384         ld      r11,exception_marker@toc(r2);                              \
385         std     r10,RESULT(r1);         /* clear regs->result           */ \
386         std     r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame      */
387
388 /*
389  * On entry r13 points to the paca, r9-r13 are saved in the paca,
390  * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
391  * SRR1, and relocation is on.
392  */
393 #define EXCEPTION_COMMON(area, trap)                                       \
394         andi.   r10,r12,MSR_PR;         /* See if coming from user      */ \
395         mr      r10,r1;                 /* Save r1                      */ \
396         subi    r1,r1,INT_FRAME_SIZE;   /* alloc frame on kernel stack  */ \
397         beq-    1f;                                                        \
398         ld      r1,PACAKSAVE(r13);      /* kernel stack to use          */ \
399 1:      cmpdi   cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace  */ \
400         blt+    cr1,3f;                 /* abort if it is               */ \
401         li      r1,(trap);              /* will be reloaded later       */ \
402         sth     r1,PACA_TRAP_SAVE(r13);                                    \
403         std     r3,area+EX_R3(r13);                                        \
404         addi    r3,r13,area;            /* r3 -> where regs are saved*/    \
405         RESTORE_CTR(r1, area);                                             \
406         b       bad_stack;                                                 \
407 3:      EXCEPTION_PROLOG_COMMON_1();                                       \
408         kuap_save_amr_and_lock r9, r10, cr1, cr0;                          \
409         beq     4f;                     /* if from kernel mode          */ \
410         ACCOUNT_CPU_USER_ENTRY(r13, r9, r10);                              \
411         SAVE_PPR(area, r9);                                                \
412 4:      EXCEPTION_PROLOG_COMMON_2(area);                                   \
413         EXCEPTION_PROLOG_COMMON_3(trap);                                   \
414         ACCOUNT_STOLEN_TIME
415
416
417 /*
418  * Exception where stack is already set in r1, r1 is saved in r10.
419  * PPR save and CPU accounting is not done (for some reason).
420  */
421 #define EXCEPTION_COMMON_STACK(area, trap)                      \
422         EXCEPTION_PROLOG_COMMON_1();                            \
423         kuap_save_amr_and_lock r9, r10, cr1;                    \
424         EXCEPTION_PROLOG_COMMON_2(area);                        \
425         EXCEPTION_PROLOG_COMMON_3(trap)
426
427 /*
428  * Restore all registers including H/SRR0/1 saved in a stack frame of a
429  * standard exception.
430  */
431 .macro EXCEPTION_RESTORE_REGS hsrr
432         /* Move original SRR0 and SRR1 into the respective regs */
433         ld      r9,_MSR(r1)
434         .if \hsrr
435         mtspr   SPRN_HSRR1,r9
436         .else
437         mtspr   SPRN_SRR1,r9
438         .endif
439         ld      r9,_NIP(r1)
440         .if \hsrr
441         mtspr   SPRN_HSRR0,r9
442         .else
443         mtspr   SPRN_SRR0,r9
444         .endif
445         ld      r9,_CTR(r1)
446         mtctr   r9
447         ld      r9,_XER(r1)
448         mtxer   r9
449         ld      r9,_LINK(r1)
450         mtlr    r9
451         ld      r9,_CCR(r1)
452         mtcr    r9
453         REST_8GPRS(2, r1)
454         REST_4GPRS(10, r1)
455         REST_GPR(0, r1)
456         /* restore original r1. */
457         ld      r1,GPR1(r1)
458 .endm
459
460 #define RUNLATCH_ON                             \
461 BEGIN_FTR_SECTION                               \
462         ld      r3, PACA_THREAD_INFO(r13);      \
463         ld      r4,TI_LOCAL_FLAGS(r3);          \
464         andi.   r0,r4,_TLF_RUNLATCH;            \
465         beql    ppc64_runlatch_on_trampoline;   \
466 END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
467
468 /*
469  * When the idle code in power4_idle puts the CPU into NAP mode,
470  * it has to do so in a loop, and relies on the external interrupt
471  * and decrementer interrupt entry code to get it out of the loop.
472  * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
473  * to signal that it is in the loop and needs help to get out.
474  */
475 #ifdef CONFIG_PPC_970_NAP
476 #define FINISH_NAP                              \
477 BEGIN_FTR_SECTION                               \
478         ld      r11, PACA_THREAD_INFO(r13);     \
479         ld      r9,TI_LOCAL_FLAGS(r11);         \
480         andi.   r10,r9,_TLF_NAPPING;            \
481         bnel    power4_fixup_nap;               \
482 END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
483 #else
484 #define FINISH_NAP
485 #endif
486
487 /*
488  * Following are the BOOK3S exception handler helper macros.
489  * Handlers come in a number of types, and each type has a number of varieties.
490  *
491  * EXC_REAL_*     - real, unrelocated exception vectors
492  * EXC_VIRT_*     - virt (AIL), unrelocated exception vectors
493  * TRAMP_REAL_*   - real, unrelocated helpers (virt can call these)
494  * TRAMP_VIRT_*   - virt, unreloc helpers (in practice, real can use)
495  * TRAMP_KVM      - KVM handlers that get put into real, unrelocated
496  * EXC_COMMON     - virt, relocated common handlers
497  *
498  * The EXC handlers are given a name, and branch to name_common, or the
499  * appropriate KVM or masking function. Vector handler verieties are as
500  * follows:
501  *
502  * EXC_{REAL|VIRT}_BEGIN/END - used to open-code the exception
503  *
504  * EXC_{REAL|VIRT}  - standard exception
505  *
506  * EXC_{REAL|VIRT}_suffix
507  *     where _suffix is:
508  *   - _MASKABLE               - maskable exception
509  *   - _OOL                    - out of line with trampoline to common handler
510  *   - _HV                     - HV exception
511  *
512  * There can be combinations, e.g., EXC_VIRT_OOL_MASKABLE_HV
513  *
514  * The one unusual case is __EXC_REAL_OOL_HV_DIRECT, which is
515  * an OOL vector that branches to a specified handler rather than the usual
516  * trampoline that goes to common. It, and other underscore macros, should
517  * be used with care.
518  *
519  * KVM handlers come in the following verieties:
520  * TRAMP_KVM
521  * TRAMP_KVM_SKIP
522  * TRAMP_KVM_HV
523  * TRAMP_KVM_HV_SKIP
524  *
525  * COMMON handlers come in the following verieties:
526  * EXC_COMMON_BEGIN/END - used to open-code the handler
527  * EXC_COMMON
528  * EXC_COMMON_ASYNC
529  *
530  * TRAMP_REAL and TRAMP_VIRT can be used with BEGIN/END. KVM
531  * and OOL handlers are implemented as types of TRAMP and TRAMP_VIRT handlers.
532  */
533
534 #define __EXC_REAL(name, start, size, area)                             \
535         EXC_REAL_BEGIN(name, start, size);                              \
536         SET_SCRATCH0(r13);              /* save r13 */                  \
537         EXCEPTION_PROLOG_0 area ;                                       \
538         EXCEPTION_PROLOG_1 EXC_STD, area, 1, start, 0 ;                 \
539         EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1 ;             \
540         EXC_REAL_END(name, start, size)
541
542 #define EXC_REAL(name, start, size)                                     \
543         __EXC_REAL(name, start, size, PACA_EXGEN)
544
545 #define __EXC_VIRT(name, start, size, realvec, area)                    \
546         EXC_VIRT_BEGIN(name, start, size);                              \
547         SET_SCRATCH0(r13);    /* save r13 */                            \
548         EXCEPTION_PROLOG_0 area ;                                       \
549         EXCEPTION_PROLOG_1 EXC_STD, area, 0, realvec, 0;                \
550         EXCEPTION_PROLOG_2_VIRT name##_common, EXC_STD ;                \
551         EXC_VIRT_END(name, start, size)
552
553 #define EXC_VIRT(name, start, size, realvec)                            \
554         __EXC_VIRT(name, start, size, realvec, PACA_EXGEN)
555
556 #define EXC_REAL_MASKABLE(name, start, size, bitmask)                   \
557         EXC_REAL_BEGIN(name, start, size);                              \
558         SET_SCRATCH0(r13);    /* save r13 */                            \
559         EXCEPTION_PROLOG_0 PACA_EXGEN ;                                 \
560         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, start, bitmask ;     \
561         EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1 ;             \
562         EXC_REAL_END(name, start, size)
563
564 #define EXC_VIRT_MASKABLE(name, start, size, realvec, bitmask)          \
565         EXC_VIRT_BEGIN(name, start, size);                              \
566         SET_SCRATCH0(r13);    /* save r13 */                            \
567         EXCEPTION_PROLOG_0 PACA_EXGEN ;                                 \
568         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, realvec, bitmask ;   \
569         EXCEPTION_PROLOG_2_VIRT name##_common, EXC_STD ;                \
570         EXC_VIRT_END(name, start, size)
571
572 #define EXC_REAL_HV(name, start, size)                                  \
573         EXC_REAL_BEGIN(name, start, size);                              \
574         SET_SCRATCH0(r13);              /* save r13 */                  \
575         EXCEPTION_PROLOG_0 PACA_EXGEN;                                  \
576         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, start, 0 ;            \
577         EXCEPTION_PROLOG_2_REAL name##_common, EXC_HV, 1 ;              \
578         EXC_REAL_END(name, start, size)
579
580 #define EXC_VIRT_HV(name, start, size, realvec)                         \
581         EXC_VIRT_BEGIN(name, start, size);                              \
582         SET_SCRATCH0(r13);              /* save r13 */                  \
583         EXCEPTION_PROLOG_0 PACA_EXGEN;                                  \
584         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, realvec, 0 ;          \
585         EXCEPTION_PROLOG_2_VIRT name##_common, EXC_HV ;                 \
586         EXC_VIRT_END(name, start, size)
587
588 #define __EXC_REAL_OOL(name, start, size)                               \
589         EXC_REAL_BEGIN(name, start, size);                              \
590         SET_SCRATCH0(r13);                                              \
591         EXCEPTION_PROLOG_0 PACA_EXGEN ;                                 \
592         b       tramp_real_##name ;                                     \
593         EXC_REAL_END(name, start, size)
594
595 #define __TRAMP_REAL_OOL(name, vec)                                     \
596         TRAMP_REAL_BEGIN(tramp_real_##name);                            \
597         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, vec, 0 ;     \
598         EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1
599
600 #define EXC_REAL_OOL(name, start, size)                                 \
601         __EXC_REAL_OOL(name, start, size);                              \
602         __TRAMP_REAL_OOL(name, start)
603
604 #define __EXC_REAL_OOL_MASKABLE(name, start, size)                      \
605         __EXC_REAL_OOL(name, start, size)
606
607 #define __TRAMP_REAL_OOL_MASKABLE(name, vec, bitmask)                   \
608         TRAMP_REAL_BEGIN(tramp_real_##name);                            \
609         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, vec, bitmask ;       \
610         EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1
611
612 #define EXC_REAL_OOL_MASKABLE(name, start, size, bitmask)               \
613         __EXC_REAL_OOL_MASKABLE(name, start, size);                     \
614         __TRAMP_REAL_OOL_MASKABLE(name, start, bitmask)
615
616 #define __EXC_REAL_OOL_HV_DIRECT(name, start, size, handler)            \
617         EXC_REAL_BEGIN(name, start, size);                              \
618         SET_SCRATCH0(r13);                                              \
619         EXCEPTION_PROLOG_0 PACA_EXGEN ;                                 \
620         b       handler;                                                \
621         EXC_REAL_END(name, start, size)
622
623 #define __EXC_REAL_OOL_HV(name, start, size)                            \
624         __EXC_REAL_OOL(name, start, size)
625
626 #define __TRAMP_REAL_OOL_HV(name, vec)                                  \
627         TRAMP_REAL_BEGIN(tramp_real_##name);                            \
628         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, vec, 0 ;      \
629         EXCEPTION_PROLOG_2_REAL name##_common, EXC_HV, 1
630
631 #define EXC_REAL_OOL_HV(name, start, size)                              \
632         __EXC_REAL_OOL_HV(name, start, size);                           \
633         __TRAMP_REAL_OOL_HV(name, start)
634
635 #define __EXC_REAL_OOL_MASKABLE_HV(name, start, size)                   \
636         __EXC_REAL_OOL(name, start, size)
637
638 #define __TRAMP_REAL_OOL_MASKABLE_HV(name, vec, bitmask)                \
639         TRAMP_REAL_BEGIN(tramp_real_##name);                            \
640         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, vec, bitmask ;        \
641         EXCEPTION_PROLOG_2_REAL name##_common, EXC_HV, 1
642
643 #define EXC_REAL_OOL_MASKABLE_HV(name, start, size, bitmask)            \
644         __EXC_REAL_OOL_MASKABLE_HV(name, start, size);                  \
645         __TRAMP_REAL_OOL_MASKABLE_HV(name, start, bitmask)
646
647 #define __EXC_VIRT_OOL(name, start, size)                               \
648         EXC_VIRT_BEGIN(name, start, size);                              \
649         SET_SCRATCH0(r13);                                              \
650         EXCEPTION_PROLOG_0 PACA_EXGEN ;                                 \
651         b       tramp_virt_##name;                                      \
652         EXC_VIRT_END(name, start, size)
653
654 #define __TRAMP_VIRT_OOL(name, realvec)                                 \
655         TRAMP_VIRT_BEGIN(tramp_virt_##name);                            \
656         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, vec, 0 ;             \
657         EXCEPTION_PROLOG_2_VIRT name##_common, EXC_STD
658
659 #define EXC_VIRT_OOL(name, start, size, realvec)                        \
660         __EXC_VIRT_OOL(name, start, size);                              \
661         __TRAMP_VIRT_OOL(name, realvec)
662
663 #define __EXC_VIRT_OOL_MASKABLE(name, start, size)                      \
664         __EXC_VIRT_OOL(name, start, size)
665
666 #define __TRAMP_VIRT_OOL_MASKABLE(name, realvec, bitmask)               \
667         TRAMP_VIRT_BEGIN(tramp_virt_##name);                            \
668         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, realvec, bitmask ;   \
669         EXCEPTION_PROLOG_2_REAL name##_common, EXC_STD, 1
670
671 #define EXC_VIRT_OOL_MASKABLE(name, start, size, realvec, bitmask)      \
672         __EXC_VIRT_OOL_MASKABLE(name, start, size);                     \
673         __TRAMP_VIRT_OOL_MASKABLE(name, realvec, bitmask)
674
675 #define __EXC_VIRT_OOL_HV(name, start, size)                            \
676         __EXC_VIRT_OOL(name, start, size)
677
678 #define __TRAMP_VIRT_OOL_HV(name, realvec)                              \
679         TRAMP_VIRT_BEGIN(tramp_virt_##name);                            \
680         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, realvec, 0 ;          \
681         EXCEPTION_PROLOG_2_VIRT name##_common, EXC_HV
682
683 #define EXC_VIRT_OOL_HV(name, start, size, realvec)                     \
684         __EXC_VIRT_OOL_HV(name, start, size);                           \
685         __TRAMP_VIRT_OOL_HV(name, realvec)
686
687 #define __EXC_VIRT_OOL_MASKABLE_HV(name, start, size)                   \
688         __EXC_VIRT_OOL(name, start, size)
689
690 #define __TRAMP_VIRT_OOL_MASKABLE_HV(name, realvec, bitmask)            \
691         TRAMP_VIRT_BEGIN(tramp_virt_##name);                            \
692         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, realvec, bitmask ;    \
693         EXCEPTION_PROLOG_2_VIRT name##_common, EXC_HV
694
695 #define EXC_VIRT_OOL_MASKABLE_HV(name, start, size, realvec, bitmask)   \
696         __EXC_VIRT_OOL_MASKABLE_HV(name, start, size);                  \
697         __TRAMP_VIRT_OOL_MASKABLE_HV(name, realvec, bitmask)
698
699 #define TRAMP_KVM(area, n)                                              \
700         TRAMP_KVM_BEGIN(do_kvm_##n);                                    \
701         KVM_HANDLER area, EXC_STD, n, 0
702
703 #define TRAMP_KVM_SKIP(area, n)                                         \
704         TRAMP_KVM_BEGIN(do_kvm_##n);                                    \
705         KVM_HANDLER area, EXC_STD, n, 1
706
707 #define TRAMP_KVM_HV(area, n)                                           \
708         TRAMP_KVM_BEGIN(do_kvm_H##n);                                   \
709         KVM_HANDLER area, EXC_HV, n, 0
710
711 #define TRAMP_KVM_HV_SKIP(area, n)                                      \
712         TRAMP_KVM_BEGIN(do_kvm_H##n);                                   \
713         KVM_HANDLER area, EXC_HV, n, 1
714
715 #define EXC_COMMON(name, realvec, hdlr)                                 \
716         EXC_COMMON_BEGIN(name);                                         \
717         EXCEPTION_COMMON(PACA_EXGEN, realvec);                          \
718         bl      save_nvgprs;                                            \
719         RECONCILE_IRQ_STATE(r10, r11);                                  \
720         addi    r3,r1,STACK_FRAME_OVERHEAD;                             \
721         bl      hdlr;                                                   \
722         b       ret_from_except
723
724 /*
725  * Like EXC_COMMON, but for exceptions that can occur in the idle task and
726  * therefore need the special idle handling (finish nap and runlatch)
727  */
728 #define EXC_COMMON_ASYNC(name, realvec, hdlr)                           \
729         EXC_COMMON_BEGIN(name);                                         \
730         EXCEPTION_COMMON(PACA_EXGEN, realvec);                          \
731         FINISH_NAP;                                                     \
732         RECONCILE_IRQ_STATE(r10, r11);                                  \
733         RUNLATCH_ON;                                                    \
734         addi    r3,r1,STACK_FRAME_OVERHEAD;                             \
735         bl      hdlr;                                                   \
736         b       ret_from_except_lite
737
738
739 /*
740  * There are a few constraints to be concerned with.
741  * - Real mode exceptions code/data must be located at their physical location.
742  * - Virtual mode exceptions must be mapped at their 0xc000... location.
743  * - Fixed location code must not call directly beyond the __end_interrupts
744  *   area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence
745  *   must be used.
746  * - LOAD_HANDLER targets must be within first 64K of physical 0 /
747  *   virtual 0xc00...
748  * - Conditional branch targets must be within +/-32K of caller.
749  *
750  * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and
751  * therefore don't have to run in physically located code or rfid to
752  * virtual mode kernel code. However on relocatable kernels they do have
753  * to branch to KERNELBASE offset because the rest of the kernel (outside
754  * the exception vectors) may be located elsewhere.
755  *
756  * Virtual exceptions correspond with physical, except their entry points
757  * are offset by 0xc000000000000000 and also tend to get an added 0x4000
758  * offset applied. Virtual exceptions are enabled with the Alternate
759  * Interrupt Location (AIL) bit set in the LPCR. However this does not
760  * guarantee they will be delivered virtually. Some conditions (see the ISA)
761  * cause exceptions to be delivered in real mode.
762  *
763  * It's impossible to receive interrupts below 0x300 via AIL.
764  *
765  * KVM: None of the virtual exceptions are from the guest. Anything that
766  * escalated to HV=1 from HV=0 is delivered via real mode handlers.
767  *
768  *
769  * We layout physical memory as follows:
770  * 0x0000 - 0x00ff : Secondary processor spin code
771  * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors
772  * 0x1900 - 0x3fff : Real mode trampolines
773  * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors
774  * 0x5900 - 0x6fff : Relon mode trampolines
775  * 0x7000 - 0x7fff : FWNMI data area
776  * 0x8000 -   .... : Common interrupt handlers, remaining early
777  *                   setup code, rest of kernel.
778  *
779  * We could reclaim 0x4000-0x42ff for real mode trampolines if the space
780  * is necessary. Until then it's more consistent to explicitly put VIRT_NONE
781  * vectors there.
782  */
783 OPEN_FIXED_SECTION(real_vectors,        0x0100, 0x1900)
784 OPEN_FIXED_SECTION(real_trampolines,    0x1900, 0x4000)
785 OPEN_FIXED_SECTION(virt_vectors,        0x4000, 0x5900)
786 OPEN_FIXED_SECTION(virt_trampolines,    0x5900, 0x7000)
787
788 #ifdef CONFIG_PPC_POWERNV
789         .globl start_real_trampolines
790         .globl end_real_trampolines
791         .globl start_virt_trampolines
792         .globl end_virt_trampolines
793 #endif
794
795 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
796 /*
797  * Data area reserved for FWNMI option.
798  * This address (0x7000) is fixed by the RPA.
799  * pseries and powernv need to keep the whole page from
800  * 0x7000 to 0x8000 free for use by the firmware
801  */
802 ZERO_FIXED_SECTION(fwnmi_page,          0x7000, 0x8000)
803 OPEN_TEXT_SECTION(0x8000)
804 #else
805 OPEN_TEXT_SECTION(0x7000)
806 #endif
807
808 USE_FIXED_SECTION(real_vectors)
809
810 /*
811  * This is the start of the interrupt handlers for pSeries
812  * This code runs with relocation off.
813  * Code from here to __end_interrupts gets copied down to real
814  * address 0x100 when we are running a relocatable kernel.
815  * Therefore any relative branches in this section must only
816  * branch to labels in this section.
817  */
818         .globl __start_interrupts
819 __start_interrupts:
820
821 /* No virt vectors corresponding with 0x0..0x100 */
822 EXC_VIRT_NONE(0x4000, 0x100)
823
824
825 EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
826         SET_SCRATCH0(r13)
827         EXCEPTION_PROLOG_0 PACA_EXNMI
828
829         /* This is EXCEPTION_PROLOG_1 with the idle feature section added */
830         OPT_SAVE_REG_TO_PACA(PACA_EXNMI+EX_PPR, r9, CPU_FTR_HAS_PPR)
831         OPT_SAVE_REG_TO_PACA(PACA_EXNMI+EX_CFAR, r10, CPU_FTR_CFAR)
832         INTERRUPT_TO_KERNEL
833         SAVE_CTR(r10, PACA_EXNMI)
834         mfcr    r9
835
836 #ifdef CONFIG_PPC_P7_NAP
837         /*
838          * If running native on arch 2.06 or later, check if we are waking up
839          * from nap/sleep/winkle, and branch to idle handler. This tests SRR1
840          * bits 46:47. A non-0 value indicates that we are coming from a power
841          * saving state. The idle wakeup handler initially runs in real mode,
842          * but we branch to the 0xc000... address so we can turn on relocation
843          * with mtmsr.
844          */
845 BEGIN_FTR_SECTION
846         mfspr   r10,SPRN_SRR1
847         rlwinm. r10,r10,47-31,30,31
848         beq-    1f
849         cmpwi   cr1,r10,2
850         mfspr   r3,SPRN_SRR1
851         bltlr   cr1     /* no state loss, return to idle caller */
852         BRANCH_TO_C000(r10, system_reset_idle_common)
853 1:
854 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
855 #endif
856
857         KVMTEST EXC_STD 0x100
858         std     r11,PACA_EXNMI+EX_R11(r13)
859         std     r12,PACA_EXNMI+EX_R12(r13)
860         GET_SCRATCH0(r10)
861         std     r10,PACA_EXNMI+EX_R13(r13)
862
863         EXCEPTION_PROLOG_2_REAL system_reset_common, EXC_STD, 0
864         /*
865          * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is
866          * being used, so a nested NMI exception would corrupt it.
867          */
868
869 EXC_REAL_END(system_reset, 0x100, 0x100)
870 EXC_VIRT_NONE(0x4100, 0x100)
871 TRAMP_KVM(PACA_EXNMI, 0x100)
872
873 #ifdef CONFIG_PPC_P7_NAP
874 EXC_COMMON_BEGIN(system_reset_idle_common)
875         /*
876          * This must be a direct branch (without linker branch stub) because
877          * we can not use TOC at this point as r2 may not be restored yet.
878          */
879         b       idle_return_gpr_loss
880 #endif
881
882 EXC_COMMON_BEGIN(system_reset_common)
883         /*
884          * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able
885          * to recover, but nested NMI will notice in_nmi and not recover
886          * because of the use of the NMI stack. in_nmi reentrancy is tested in
887          * system_reset_exception.
888          */
889         lhz     r10,PACA_IN_NMI(r13)
890         addi    r10,r10,1
891         sth     r10,PACA_IN_NMI(r13)
892         li      r10,MSR_RI
893         mtmsrd  r10,1
894
895         mr      r10,r1
896         ld      r1,PACA_NMI_EMERG_SP(r13)
897         subi    r1,r1,INT_FRAME_SIZE
898         EXCEPTION_COMMON_STACK(PACA_EXNMI, 0x100)
899         bl      save_nvgprs
900         /*
901          * Set IRQS_ALL_DISABLED unconditionally so arch_irqs_disabled does
902          * the right thing. We do not want to reconcile because that goes
903          * through irq tracing which we don't want in NMI.
904          *
905          * Save PACAIRQHAPPENED because some code will do a hard disable
906          * (e.g., xmon). So we want to restore this back to where it was
907          * when we return. DAR is unused in the stack, so save it there.
908          */
909         li      r10,IRQS_ALL_DISABLED
910         stb     r10,PACAIRQSOFTMASK(r13)
911         lbz     r10,PACAIRQHAPPENED(r13)
912         std     r10,_DAR(r1)
913
914         addi    r3,r1,STACK_FRAME_OVERHEAD
915         bl      system_reset_exception
916
917         /* Clear MSR_RI before setting SRR0 and SRR1. */
918         li      r9,0
919         mtmsrd  r9,1
920
921         /*
922          * MSR_RI is clear, now we can decrement paca->in_nmi.
923          */
924         lhz     r10,PACA_IN_NMI(r13)
925         subi    r10,r10,1
926         sth     r10,PACA_IN_NMI(r13)
927
928         /*
929          * Restore soft mask settings.
930          */
931         ld      r10,_DAR(r1)
932         stb     r10,PACAIRQHAPPENED(r13)
933         ld      r10,SOFTE(r1)
934         stb     r10,PACAIRQSOFTMASK(r13)
935
936         EXCEPTION_RESTORE_REGS EXC_STD
937         RFI_TO_USER_OR_KERNEL
938
939 #ifdef CONFIG_PPC_PSERIES
940 /*
941  * Vectors for the FWNMI option.  Share common code.
942  */
943 TRAMP_REAL_BEGIN(system_reset_fwnmi)
944         SET_SCRATCH0(r13)               /* save r13 */
945         /* See comment at system_reset exception, don't turn on RI */
946         EXCEPTION_PROLOG_0 PACA_EXNMI
947         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXNMI, 0, 0x100, 0
948         EXCEPTION_PROLOG_2_REAL system_reset_common, EXC_STD, 0
949
950 #endif /* CONFIG_PPC_PSERIES */
951
952
953 EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
954         /* This is moved out of line as it can be patched by FW, but
955          * some code path might still want to branch into the original
956          * vector
957          */
958         SET_SCRATCH0(r13)               /* save r13 */
959         EXCEPTION_PROLOG_0 PACA_EXMC
960 BEGIN_FTR_SECTION
961         b       machine_check_common_early
962 FTR_SECTION_ELSE
963         b       machine_check_pSeries_0
964 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
965 EXC_REAL_END(machine_check, 0x200, 0x100)
966 EXC_VIRT_NONE(0x4200, 0x100)
967 TRAMP_REAL_BEGIN(machine_check_common_early)
968         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 0, 0x200, 0
969         /*
970          * Register contents:
971          * R13          = PACA
972          * R9           = CR
973          * Original R9 to R13 is saved on PACA_EXMC
974          *
975          * Switch to mc_emergency stack and handle re-entrancy (we limit
976          * the nested MCE upto level 4 to avoid stack overflow).
977          * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
978          *
979          * We use paca->in_mce to check whether this is the first entry or
980          * nested machine check. We increment paca->in_mce to track nested
981          * machine checks.
982          *
983          * If this is the first entry then set stack pointer to
984          * paca->mc_emergency_sp, otherwise r1 is already pointing to
985          * stack frame on mc_emergency stack.
986          *
987          * NOTE: We are here with MSR_ME=0 (off), which means we risk a
988          * checkstop if we get another machine check exception before we do
989          * rfid with MSR_ME=1.
990          *
991          * This interrupt can wake directly from idle. If that is the case,
992          * the machine check is handled then the idle wakeup code is called
993          * to restore state.
994          */
995         mr      r11,r1                  /* Save r1 */
996         lhz     r10,PACA_IN_MCE(r13)
997         cmpwi   r10,0                   /* Are we in nested machine check */
998         bne     0f                      /* Yes, we are. */
999         /* First machine check entry */
1000         ld      r1,PACAMCEMERGSP(r13)   /* Use MC emergency stack */
1001 0:      subi    r1,r1,INT_FRAME_SIZE    /* alloc stack frame */
1002         addi    r10,r10,1               /* increment paca->in_mce */
1003         sth     r10,PACA_IN_MCE(r13)
1004         /* Limit nested MCE to level 4 to avoid stack overflow */
1005         cmpwi   r10,MAX_MCE_DEPTH
1006         bgt     2f                      /* Check if we hit limit of 4 */
1007         std     r11,GPR1(r1)            /* Save r1 on the stack. */
1008         std     r11,0(r1)               /* make stack chain pointer */
1009         mfspr   r11,SPRN_SRR0           /* Save SRR0 */
1010         std     r11,_NIP(r1)
1011         mfspr   r11,SPRN_SRR1           /* Save SRR1 */
1012         std     r11,_MSR(r1)
1013         mfspr   r11,SPRN_DAR            /* Save DAR */
1014         std     r11,_DAR(r1)
1015         mfspr   r11,SPRN_DSISR          /* Save DSISR */
1016         std     r11,_DSISR(r1)
1017         std     r9,_CCR(r1)             /* Save CR in stackframe */
1018         /* We don't touch AMR here, we never go to virtual mode */
1019         /* Save r9 through r13 from EXMC save area to stack frame. */
1020         EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
1021         mfmsr   r11                     /* get MSR value */
1022 BEGIN_FTR_SECTION
1023         ori     r11,r11,MSR_ME          /* turn on ME bit */
1024 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
1025         ori     r11,r11,MSR_RI          /* turn on RI bit */
1026         LOAD_HANDLER(r12, machine_check_handle_early)
1027 1:      mtspr   SPRN_SRR0,r12
1028         mtspr   SPRN_SRR1,r11
1029         RFI_TO_KERNEL
1030         b       .       /* prevent speculative execution */
1031 2:
1032         /* Stack overflow. Stay on emergency stack and panic.
1033          * Keep the ME bit off while panic-ing, so that if we hit
1034          * another machine check we checkstop.
1035          */
1036         addi    r1,r1,INT_FRAME_SIZE    /* go back to previous stack frame */
1037         ld      r11,PACAKMSR(r13)
1038         LOAD_HANDLER(r12, unrecover_mce)
1039         li      r10,MSR_ME
1040         andc    r11,r11,r10             /* Turn off MSR_ME */
1041         b       1b
1042         b       .       /* prevent speculative execution */
1043
1044 TRAMP_REAL_BEGIN(machine_check_pSeries)
1045         .globl machine_check_fwnmi
1046 machine_check_fwnmi:
1047         SET_SCRATCH0(r13)               /* save r13 */
1048         EXCEPTION_PROLOG_0 PACA_EXMC
1049 BEGIN_FTR_SECTION
1050         b       machine_check_common_early
1051 END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
1052 machine_check_pSeries_0:
1053         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 1, 0x200, 0
1054         /*
1055          * MSR_RI is not enabled, because PACA_EXMC is being used, so a
1056          * nested machine check corrupts it. machine_check_common enables
1057          * MSR_RI.
1058          */
1059         EXCEPTION_PROLOG_2_REAL machine_check_common, EXC_STD, 0
1060
1061 TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
1062
1063 EXC_COMMON_BEGIN(machine_check_common)
1064         /*
1065          * Machine check is different because we use a different
1066          * save area: PACA_EXMC instead of PACA_EXGEN.
1067          */
1068         mfspr   r10,SPRN_DAR
1069         std     r10,PACA_EXMC+EX_DAR(r13)
1070         mfspr   r10,SPRN_DSISR
1071         stw     r10,PACA_EXMC+EX_DSISR(r13)
1072         EXCEPTION_COMMON(PACA_EXMC, 0x200)
1073         FINISH_NAP
1074         RECONCILE_IRQ_STATE(r10, r11)
1075         ld      r3,PACA_EXMC+EX_DAR(r13)
1076         lwz     r4,PACA_EXMC+EX_DSISR(r13)
1077         /* Enable MSR_RI when finished with PACA_EXMC */
1078         li      r10,MSR_RI
1079         mtmsrd  r10,1
1080         std     r3,_DAR(r1)
1081         std     r4,_DSISR(r1)
1082         bl      save_nvgprs
1083         addi    r3,r1,STACK_FRAME_OVERHEAD
1084         bl      machine_check_exception
1085         b       ret_from_except
1086
1087 #define MACHINE_CHECK_HANDLER_WINDUP                    \
1088         /* Clear MSR_RI before setting SRR0 and SRR1. */\
1089         li      r9,0;                                   \
1090         mtmsrd  r9,1;           /* Clear MSR_RI */      \
1091         /* Decrement paca->in_mce now RI is clear. */   \
1092         lhz     r12,PACA_IN_MCE(r13);                   \
1093         subi    r12,r12,1;                              \
1094         sth     r12,PACA_IN_MCE(r13);                   \
1095         EXCEPTION_RESTORE_REGS EXC_STD
1096
1097 #ifdef CONFIG_PPC_P7_NAP
1098 /*
1099  * This is an idle wakeup. Low level machine check has already been
1100  * done. Queue the event then call the idle code to do the wake up.
1101  */
1102 EXC_COMMON_BEGIN(machine_check_idle_common)
1103         bl      machine_check_queue_event
1104
1105         /*
1106          * We have not used any non-volatile GPRs here, and as a rule
1107          * most exception code including machine check does not.
1108          * Therefore PACA_NAPSTATELOST does not need to be set. Idle
1109          * wakeup will restore volatile registers.
1110          *
1111          * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
1112          *
1113          * Then decrement MCE nesting after finishing with the stack.
1114          */
1115         ld      r3,_MSR(r1)
1116         ld      r4,_LINK(r1)
1117
1118         lhz     r11,PACA_IN_MCE(r13)
1119         subi    r11,r11,1
1120         sth     r11,PACA_IN_MCE(r13)
1121
1122         mtlr    r4
1123         rlwinm  r10,r3,47-31,30,31
1124         cmpwi   cr1,r10,2
1125         bltlr   cr1     /* no state loss, return to idle caller */
1126         b       idle_return_gpr_loss
1127 #endif
1128         /*
1129          * Handle machine check early in real mode. We come here with
1130          * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
1131          */
1132 EXC_COMMON_BEGIN(machine_check_handle_early)
1133         std     r0,GPR0(r1)     /* Save r0 */
1134         EXCEPTION_PROLOG_COMMON_3(0x200)
1135         bl      save_nvgprs
1136         addi    r3,r1,STACK_FRAME_OVERHEAD
1137         bl      machine_check_early
1138         std     r3,RESULT(r1)   /* Save result */
1139         ld      r12,_MSR(r1)
1140 BEGIN_FTR_SECTION
1141         b       4f
1142 END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
1143
1144 #ifdef  CONFIG_PPC_P7_NAP
1145         /*
1146          * Check if thread was in power saving mode. We come here when any
1147          * of the following is true:
1148          * a. thread wasn't in power saving mode
1149          * b. thread was in power saving mode with no state loss,
1150          *    supervisor state loss or hypervisor state loss.
1151          *
1152          * Go back to nap/sleep/winkle mode again if (b) is true.
1153          */
1154 BEGIN_FTR_SECTION
1155         rlwinm. r11,r12,47-31,30,31
1156         bne     machine_check_idle_common
1157 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
1158 #endif
1159
1160         /*
1161          * Check if we are coming from hypervisor userspace. If yes then we
1162          * continue in host kernel in V mode to deliver the MC event.
1163          */
1164         rldicl. r11,r12,4,63            /* See if MC hit while in HV mode. */
1165         beq     5f
1166 4:      andi.   r11,r12,MSR_PR          /* See if coming from user. */
1167         bne     9f                      /* continue in V mode if we are. */
1168
1169 5:
1170 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1171 BEGIN_FTR_SECTION
1172         /*
1173          * We are coming from kernel context. Check if we are coming from
1174          * guest. if yes, then we can continue. We will fall through
1175          * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
1176          */
1177         lbz     r11,HSTATE_IN_GUEST(r13)
1178         cmpwi   r11,0                   /* Check if coming from guest */
1179         bne     9f                      /* continue if we are. */
1180 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
1181 #endif
1182         /*
1183          * At this point we are not sure about what context we come from.
1184          * Queue up the MCE event and return from the interrupt.
1185          * But before that, check if this is an un-recoverable exception.
1186          * If yes, then stay on emergency stack and panic.
1187          */
1188         andi.   r11,r12,MSR_RI
1189         bne     2f
1190 1:      mfspr   r11,SPRN_SRR0
1191         LOAD_HANDLER(r10,unrecover_mce)
1192         mtspr   SPRN_SRR0,r10
1193         ld      r10,PACAKMSR(r13)
1194         /*
1195          * We are going down. But there are chances that we might get hit by
1196          * another MCE during panic path and we may run into unstable state
1197          * with no way out. Hence, turn ME bit off while going down, so that
1198          * when another MCE is hit during panic path, system will checkstop
1199          * and hypervisor will get restarted cleanly by SP.
1200          */
1201         li      r3,MSR_ME
1202         andc    r10,r10,r3              /* Turn off MSR_ME */
1203         mtspr   SPRN_SRR1,r10
1204         RFI_TO_KERNEL
1205         b       .
1206 2:
1207         /*
1208          * Check if we have successfully handled/recovered from error, if not
1209          * then stay on emergency stack and panic.
1210          */
1211         ld      r3,RESULT(r1)   /* Load result */
1212         cmpdi   r3,0            /* see if we handled MCE successfully */
1213
1214         beq     1b              /* if !handled then panic */
1215 BEGIN_FTR_SECTION
1216         /*
1217          * Return from MC interrupt.
1218          * Queue up the MCE event so that we can log it later, while
1219          * returning from kernel or opal call.
1220          */
1221         bl      machine_check_queue_event
1222         MACHINE_CHECK_HANDLER_WINDUP
1223         RFI_TO_USER_OR_KERNEL
1224 FTR_SECTION_ELSE
1225         /*
1226          * pSeries: Return from MC interrupt. Before that stay on emergency
1227          * stack and call machine_check_exception to log the MCE event.
1228          */
1229         LOAD_HANDLER(r10,mce_return)
1230         mtspr   SPRN_SRR0,r10
1231         ld      r10,PACAKMSR(r13)
1232         mtspr   SPRN_SRR1,r10
1233         RFI_TO_KERNEL
1234         b       .
1235 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1236 9:
1237         /* Deliver the machine check to host kernel in V mode. */
1238         MACHINE_CHECK_HANDLER_WINDUP
1239         SET_SCRATCH0(r13)               /* save r13 */
1240         EXCEPTION_PROLOG_0 PACA_EXMC
1241         b       machine_check_pSeries_0
1242
1243 EXC_COMMON_BEGIN(unrecover_mce)
1244         /* Invoke machine_check_exception to print MCE event and panic. */
1245         addi    r3,r1,STACK_FRAME_OVERHEAD
1246         bl      machine_check_exception
1247         /*
1248          * We will not reach here. Even if we did, there is no way out. Call
1249          * unrecoverable_exception and die.
1250          */
1251 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
1252         bl      unrecoverable_exception
1253         b       1b
1254
1255 EXC_COMMON_BEGIN(mce_return)
1256         /* Invoke machine_check_exception to print MCE event and return. */
1257         addi    r3,r1,STACK_FRAME_OVERHEAD
1258         bl      machine_check_exception
1259         MACHINE_CHECK_HANDLER_WINDUP
1260         RFI_TO_KERNEL
1261         b       .
1262
1263 EXC_REAL_BEGIN(data_access, 0x300, 0x80)
1264         SET_SCRATCH0(r13)               /* save r13 */
1265         EXCEPTION_PROLOG_0 PACA_EXGEN
1266         b       tramp_real_data_access
1267 EXC_REAL_END(data_access, 0x300, 0x80)
1268
1269 TRAMP_REAL_BEGIN(tramp_real_data_access)
1270         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x300, 0
1271         /*
1272          * DAR/DSISR must be read before setting MSR[RI], because
1273          * a d-side MCE will clobber those registers so is not
1274          * recoverable if they are live.
1275          */
1276         mfspr   r10,SPRN_DAR
1277         mfspr   r11,SPRN_DSISR
1278         std     r10,PACA_EXGEN+EX_DAR(r13)
1279         stw     r11,PACA_EXGEN+EX_DSISR(r13)
1280 EXCEPTION_PROLOG_2_REAL data_access_common, EXC_STD, 1
1281
1282 EXC_VIRT_BEGIN(data_access, 0x4300, 0x80)
1283         SET_SCRATCH0(r13)               /* save r13 */
1284         EXCEPTION_PROLOG_0 PACA_EXGEN
1285         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, 0x300, 0
1286         mfspr   r10,SPRN_DAR
1287         mfspr   r11,SPRN_DSISR
1288         std     r10,PACA_EXGEN+EX_DAR(r13)
1289         stw     r11,PACA_EXGEN+EX_DSISR(r13)
1290 EXCEPTION_PROLOG_2_VIRT data_access_common, EXC_STD
1291 EXC_VIRT_END(data_access, 0x4300, 0x80)
1292
1293 TRAMP_KVM_SKIP(PACA_EXGEN, 0x300)
1294
1295 EXC_COMMON_BEGIN(data_access_common)
1296         /*
1297          * Here r13 points to the paca, r9 contains the saved CR,
1298          * SRR0 and SRR1 are saved in r11 and r12,
1299          * r9 - r13 are saved in paca->exgen.
1300          * EX_DAR and EX_DSISR have saved DAR/DSISR
1301          */
1302         EXCEPTION_COMMON(PACA_EXGEN, 0x300)
1303         RECONCILE_IRQ_STATE(r10, r11)
1304         ld      r12,_MSR(r1)
1305         ld      r3,PACA_EXGEN+EX_DAR(r13)
1306         lwz     r4,PACA_EXGEN+EX_DSISR(r13)
1307         li      r5,0x300
1308         std     r3,_DAR(r1)
1309         std     r4,_DSISR(r1)
1310 BEGIN_MMU_FTR_SECTION
1311         b       do_hash_page            /* Try to handle as hpte fault */
1312 MMU_FTR_SECTION_ELSE
1313         b       handle_page_fault
1314 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1315
1316
1317 EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
1318         SET_SCRATCH0(r13)               /* save r13 */
1319         EXCEPTION_PROLOG_0 PACA_EXSLB
1320         b       tramp_real_data_access_slb
1321 EXC_REAL_END(data_access_slb, 0x380, 0x80)
1322
1323 TRAMP_REAL_BEGIN(tramp_real_data_access_slb)
1324         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXSLB, 1, 0x380, 0
1325         mfspr   r10,SPRN_DAR
1326         std     r10,PACA_EXSLB+EX_DAR(r13)
1327         EXCEPTION_PROLOG_2_REAL data_access_slb_common, EXC_STD, 1
1328
1329 EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
1330         SET_SCRATCH0(r13)               /* save r13 */
1331         EXCEPTION_PROLOG_0 PACA_EXSLB
1332         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXSLB, 0, 0x380, 0
1333         mfspr   r10,SPRN_DAR
1334         std     r10,PACA_EXSLB+EX_DAR(r13)
1335         EXCEPTION_PROLOG_2_VIRT data_access_slb_common, EXC_STD
1336 EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
1337
1338 TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
1339
1340 EXC_COMMON_BEGIN(data_access_slb_common)
1341         EXCEPTION_COMMON(PACA_EXSLB, 0x380)
1342         ld      r4,PACA_EXSLB+EX_DAR(r13)
1343         std     r4,_DAR(r1)
1344         addi    r3,r1,STACK_FRAME_OVERHEAD
1345 BEGIN_MMU_FTR_SECTION
1346         /* HPT case, do SLB fault */
1347         bl      do_slb_fault
1348         cmpdi   r3,0
1349         bne-    1f
1350         b       fast_exception_return
1351 1:      /* Error case */
1352 MMU_FTR_SECTION_ELSE
1353         /* Radix case, access is outside page table range */
1354         li      r3,-EFAULT
1355 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1356         std     r3,RESULT(r1)
1357         bl      save_nvgprs
1358         RECONCILE_IRQ_STATE(r10, r11)
1359         ld      r4,_DAR(r1)
1360         ld      r5,RESULT(r1)
1361         addi    r3,r1,STACK_FRAME_OVERHEAD
1362         bl      do_bad_slb_fault
1363         b       ret_from_except
1364
1365
1366 EXC_REAL(instruction_access, 0x400, 0x80)
1367 EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400)
1368 TRAMP_KVM(PACA_EXGEN, 0x400)
1369
1370 EXC_COMMON_BEGIN(instruction_access_common)
1371         EXCEPTION_COMMON(PACA_EXGEN, 0x400)
1372         RECONCILE_IRQ_STATE(r10, r11)
1373         ld      r12,_MSR(r1)
1374         ld      r3,_NIP(r1)
1375         andis.  r4,r12,DSISR_SRR1_MATCH_64S@h
1376         li      r5,0x400
1377         std     r3,_DAR(r1)
1378         std     r4,_DSISR(r1)
1379 BEGIN_MMU_FTR_SECTION
1380         b       do_hash_page            /* Try to handle as hpte fault */
1381 MMU_FTR_SECTION_ELSE
1382         b       handle_page_fault
1383 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1384
1385
1386 __EXC_REAL(instruction_access_slb, 0x480, 0x80, PACA_EXSLB)
1387 __EXC_VIRT(instruction_access_slb, 0x4480, 0x80, 0x480, PACA_EXSLB)
1388 TRAMP_KVM(PACA_EXSLB, 0x480)
1389
1390 EXC_COMMON_BEGIN(instruction_access_slb_common)
1391         EXCEPTION_COMMON(PACA_EXSLB, 0x480)
1392         ld      r4,_NIP(r1)
1393         addi    r3,r1,STACK_FRAME_OVERHEAD
1394 BEGIN_MMU_FTR_SECTION
1395         /* HPT case, do SLB fault */
1396         bl      do_slb_fault
1397         cmpdi   r3,0
1398         bne-    1f
1399         b       fast_exception_return
1400 1:      /* Error case */
1401 MMU_FTR_SECTION_ELSE
1402         /* Radix case, access is outside page table range */
1403         li      r3,-EFAULT
1404 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1405         std     r3,RESULT(r1)
1406         bl      save_nvgprs
1407         RECONCILE_IRQ_STATE(r10, r11)
1408         ld      r4,_NIP(r1)
1409         ld      r5,RESULT(r1)
1410         addi    r3,r1,STACK_FRAME_OVERHEAD
1411         bl      do_bad_slb_fault
1412         b       ret_from_except
1413
1414
1415 EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
1416         SET_SCRATCH0(r13)       /* save r13 */
1417         EXCEPTION_PROLOG_0 PACA_EXGEN
1418 BEGIN_FTR_SECTION
1419         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0x500, IRQS_DISABLED
1420         EXCEPTION_PROLOG_2_REAL hardware_interrupt_common, EXC_HV, 1
1421 FTR_SECTION_ELSE
1422         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x500, IRQS_DISABLED
1423         EXCEPTION_PROLOG_2_REAL hardware_interrupt_common, EXC_STD, 1
1424 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
1425 EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
1426
1427 EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
1428         SET_SCRATCH0(r13)       /* save r13 */
1429         EXCEPTION_PROLOG_0 PACA_EXGEN
1430 BEGIN_FTR_SECTION
1431         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0x500, IRQS_DISABLED
1432         EXCEPTION_PROLOG_2_VIRT hardware_interrupt_common, EXC_HV
1433 FTR_SECTION_ELSE
1434         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x500, IRQS_DISABLED
1435         EXCEPTION_PROLOG_2_VIRT hardware_interrupt_common, EXC_STD
1436 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
1437 EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
1438
1439 TRAMP_KVM(PACA_EXGEN, 0x500)
1440 TRAMP_KVM_HV(PACA_EXGEN, 0x500)
1441 EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
1442
1443
1444 EXC_REAL_BEGIN(alignment, 0x600, 0x100)
1445         SET_SCRATCH0(r13)               /* save r13 */
1446         EXCEPTION_PROLOG_0 PACA_EXGEN
1447         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 1, 0x600, 0
1448         mfspr   r10,SPRN_DAR
1449         mfspr   r11,SPRN_DSISR
1450         std     r10,PACA_EXGEN+EX_DAR(r13)
1451         stw     r11,PACA_EXGEN+EX_DSISR(r13)
1452         EXCEPTION_PROLOG_2_REAL alignment_common, EXC_STD, 1
1453 EXC_REAL_END(alignment, 0x600, 0x100)
1454
1455 EXC_VIRT_BEGIN(alignment, 0x4600, 0x100)
1456         SET_SCRATCH0(r13)               /* save r13 */
1457         EXCEPTION_PROLOG_0 PACA_EXGEN
1458         EXCEPTION_PROLOG_1 EXC_STD, PACA_EXGEN, 0, 0x600, 0
1459         mfspr   r10,SPRN_DAR
1460         mfspr   r11,SPRN_DSISR
1461         std     r10,PACA_EXGEN+EX_DAR(r13)
1462         stw     r11,PACA_EXGEN+EX_DSISR(r13)
1463         EXCEPTION_PROLOG_2_VIRT alignment_common, EXC_STD
1464 EXC_VIRT_END(alignment, 0x4600, 0x100)
1465
1466 TRAMP_KVM(PACA_EXGEN, 0x600)
1467 EXC_COMMON_BEGIN(alignment_common)
1468         EXCEPTION_COMMON(PACA_EXGEN, 0x600)
1469         ld      r3,PACA_EXGEN+EX_DAR(r13)
1470         lwz     r4,PACA_EXGEN+EX_DSISR(r13)
1471         std     r3,_DAR(r1)
1472         std     r4,_DSISR(r1)
1473         bl      save_nvgprs
1474         RECONCILE_IRQ_STATE(r10, r11)
1475         addi    r3,r1,STACK_FRAME_OVERHEAD
1476         bl      alignment_exception
1477         b       ret_from_except
1478
1479
1480 EXC_REAL(program_check, 0x700, 0x100)
1481 EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
1482 TRAMP_KVM(PACA_EXGEN, 0x700)
1483 EXC_COMMON_BEGIN(program_check_common)
1484         /*
1485          * It's possible to receive a TM Bad Thing type program check with
1486          * userspace register values (in particular r1), but with SRR1 reporting
1487          * that we came from the kernel. Normally that would confuse the bad
1488          * stack logic, and we would report a bad kernel stack pointer. Instead
1489          * we switch to the emergency stack if we're taking a TM Bad Thing from
1490          * the kernel.
1491          */
1492         li      r10,MSR_PR              /* Build a mask of MSR_PR ..    */
1493         oris    r10,r10,0x200000@h      /* .. and SRR1_PROGTM           */
1494         and     r10,r10,r12             /* Mask SRR1 with that.         */
1495         srdi    r10,r10,8               /* Shift it so we can compare   */
1496         cmpldi  r10,(0x200000 >> 8)     /* .. with an immediate.        */
1497         bne 1f                          /* If != go to normal path.     */
1498
1499         /* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack  */
1500         andi.   r10,r12,MSR_PR;         /* Set CR0 correctly for label  */
1501                                         /* 3 in EXCEPTION_PROLOG_COMMON */
1502         mr      r10,r1                  /* Save r1                      */
1503         ld      r1,PACAEMERGSP(r13)     /* Use emergency stack          */
1504         subi    r1,r1,INT_FRAME_SIZE    /* alloc stack frame            */
1505         b 3f                            /* Jump into the macro !!       */
1506 1:      EXCEPTION_COMMON(PACA_EXGEN, 0x700)
1507         bl      save_nvgprs
1508         RECONCILE_IRQ_STATE(r10, r11)
1509         addi    r3,r1,STACK_FRAME_OVERHEAD
1510         bl      program_check_exception
1511         b       ret_from_except
1512
1513
1514 EXC_REAL(fp_unavailable, 0x800, 0x100)
1515 EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
1516 TRAMP_KVM(PACA_EXGEN, 0x800)
1517 EXC_COMMON_BEGIN(fp_unavailable_common)
1518         EXCEPTION_COMMON(PACA_EXGEN, 0x800)
1519         bne     1f                      /* if from user, just load it up */
1520         bl      save_nvgprs
1521         RECONCILE_IRQ_STATE(r10, r11)
1522         addi    r3,r1,STACK_FRAME_OVERHEAD
1523         bl      kernel_fp_unavailable_exception
1524         BUG_OPCODE
1525 1:
1526 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1527 BEGIN_FTR_SECTION
1528         /* Test if 2 TM state bits are zero.  If non-zero (ie. userspace was in
1529          * transaction), go do TM stuff
1530          */
1531         rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1532         bne-    2f
1533 END_FTR_SECTION_IFSET(CPU_FTR_TM)
1534 #endif
1535         bl      load_up_fpu
1536         b       fast_exception_return
1537 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1538 2:      /* User process was in a transaction */
1539         bl      save_nvgprs
1540         RECONCILE_IRQ_STATE(r10, r11)
1541         addi    r3,r1,STACK_FRAME_OVERHEAD
1542         bl      fp_unavailable_tm
1543         b       ret_from_except
1544 #endif
1545
1546
1547 EXC_REAL_OOL_MASKABLE(decrementer, 0x900, 0x80, IRQS_DISABLED)
1548 EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900, IRQS_DISABLED)
1549 TRAMP_KVM(PACA_EXGEN, 0x900)
1550 EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
1551
1552
1553 EXC_REAL_HV(hdecrementer, 0x980, 0x80)
1554 EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980)
1555 TRAMP_KVM_HV(PACA_EXGEN, 0x980)
1556 EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
1557
1558
1559 EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100, IRQS_DISABLED)
1560 EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00, IRQS_DISABLED)
1561 TRAMP_KVM(PACA_EXGEN, 0xa00)
1562 #ifdef CONFIG_PPC_DOORBELL
1563 EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
1564 #else
1565 EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
1566 #endif
1567
1568
1569 EXC_REAL(trap_0b, 0xb00, 0x100)
1570 EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
1571 TRAMP_KVM(PACA_EXGEN, 0xb00)
1572 EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
1573
1574 /*
1575  * system call / hypercall (0xc00, 0x4c00)
1576  *
1577  * The system call exception is invoked with "sc 0" and does not alter HV bit.
1578  * There is support for kernel code to invoke system calls but there are no
1579  * in-tree users.
1580  *
1581  * The hypercall is invoked with "sc 1" and sets HV=1.
1582  *
1583  * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
1584  * 0x4c00 virtual mode.
1585  *
1586  * Call convention:
1587  *
1588  * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
1589  *
1590  * For hypercalls, the register convention is as follows:
1591  * r0 volatile
1592  * r1-2 nonvolatile
1593  * r3 volatile parameter and return value for status
1594  * r4-r10 volatile input and output value
1595  * r11 volatile hypercall number and output value
1596  * r12 volatile input and output value
1597  * r13-r31 nonvolatile
1598  * LR nonvolatile
1599  * CTR volatile
1600  * XER volatile
1601  * CR0-1 CR5-7 volatile
1602  * CR2-4 nonvolatile
1603  * Other registers nonvolatile
1604  *
1605  * The intersection of volatile registers that don't contain possible
1606  * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
1607  * without saving, though xer is not a good idea to use, as hardware may
1608  * interpret some bits so it may be costly to change them.
1609  */
1610 .macro SYSTEM_CALL virt
1611 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1612         /*
1613          * There is a little bit of juggling to get syscall and hcall
1614          * working well. Save r13 in ctr to avoid using SPRG scratch
1615          * register.
1616          *
1617          * Userspace syscalls have already saved the PPR, hcalls must save
1618          * it before setting HMT_MEDIUM.
1619          */
1620         mtctr   r13
1621         GET_PACA(r13)
1622         std     r10,PACA_EXGEN+EX_R10(r13)
1623         INTERRUPT_TO_KERNEL
1624         KVMTEST EXC_STD 0xc00 /* uses r10, branch to do_kvm_0xc00_system_call */
1625         mfctr   r9
1626 #else
1627         mr      r9,r13
1628         GET_PACA(r13)
1629         INTERRUPT_TO_KERNEL
1630 #endif
1631
1632 #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
1633 BEGIN_FTR_SECTION
1634         cmpdi   r0,0x1ebe
1635         beq-    1f
1636 END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
1637 #endif
1638
1639         /* We reach here with PACA in r13, r13 in r9. */
1640         mfspr   r11,SPRN_SRR0
1641         mfspr   r12,SPRN_SRR1
1642
1643         HMT_MEDIUM
1644
1645         .if ! \virt
1646         __LOAD_HANDLER(r10, system_call_common)
1647         mtspr   SPRN_SRR0,r10
1648         ld      r10,PACAKMSR(r13)
1649         mtspr   SPRN_SRR1,r10
1650         RFI_TO_KERNEL
1651         b       .       /* prevent speculative execution */
1652         .else
1653         li      r10,MSR_RI
1654         mtmsrd  r10,1                   /* Set RI (EE=0) */
1655 #ifdef CONFIG_RELOCATABLE
1656         __LOAD_HANDLER(r10, system_call_common)
1657         mtctr   r10
1658         bctr
1659 #else
1660         b       system_call_common
1661 #endif
1662         .endif
1663
1664 #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
1665         /* Fast LE/BE switch system call */
1666 1:      mfspr   r12,SPRN_SRR1
1667         xori    r12,r12,MSR_LE
1668         mtspr   SPRN_SRR1,r12
1669         mr      r13,r9
1670         RFI_TO_USER     /* return to userspace */
1671         b       .       /* prevent speculative execution */
1672 #endif
1673 .endm
1674
1675 EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
1676         SYSTEM_CALL 0
1677 EXC_REAL_END(system_call, 0xc00, 0x100)
1678
1679 EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
1680         SYSTEM_CALL 1
1681 EXC_VIRT_END(system_call, 0x4c00, 0x100)
1682
1683 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
1684         /*
1685          * This is a hcall, so register convention is as above, with these
1686          * differences:
1687          * r13 = PACA
1688          * ctr = orig r13
1689          * orig r10 saved in PACA
1690          */
1691 TRAMP_KVM_BEGIN(do_kvm_0xc00)
1692          /*
1693           * Save the PPR (on systems that support it) before changing to
1694           * HMT_MEDIUM. That allows the KVM code to save that value into the
1695           * guest state (it is the guest's PPR value).
1696           */
1697         OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
1698         HMT_MEDIUM
1699         OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
1700         mfctr   r10
1701         SET_SCRATCH0(r10)
1702         std     r9,PACA_EXGEN+EX_R9(r13)
1703         mfcr    r9
1704         KVM_HANDLER PACA_EXGEN, EXC_STD, 0xc00, 0
1705 #endif
1706
1707
1708 EXC_REAL(single_step, 0xd00, 0x100)
1709 EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
1710 TRAMP_KVM(PACA_EXGEN, 0xd00)
1711 EXC_COMMON(single_step_common, 0xd00, single_step_exception)
1712
1713 EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
1714 EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
1715 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
1716 EXC_COMMON_BEGIN(h_data_storage_common)
1717         mfspr   r10,SPRN_HDAR
1718         std     r10,PACA_EXGEN+EX_DAR(r13)
1719         mfspr   r10,SPRN_HDSISR
1720         stw     r10,PACA_EXGEN+EX_DSISR(r13)
1721         EXCEPTION_COMMON(PACA_EXGEN, 0xe00)
1722         bl      save_nvgprs
1723         RECONCILE_IRQ_STATE(r10, r11)
1724         addi    r3,r1,STACK_FRAME_OVERHEAD
1725 BEGIN_MMU_FTR_SECTION
1726         ld      r4,PACA_EXGEN+EX_DAR(r13)
1727         lwz     r5,PACA_EXGEN+EX_DSISR(r13)
1728         std     r4,_DAR(r1)
1729         std     r5,_DSISR(r1)
1730         li      r5,SIGSEGV
1731         bl      bad_page_fault
1732 MMU_FTR_SECTION_ELSE
1733         bl      unknown_exception
1734 ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX)
1735         b       ret_from_except
1736
1737
1738 EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
1739 EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
1740 TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
1741 EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
1742
1743
1744 EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
1745 EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
1746 TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
1747 EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
1748
1749
1750 /*
1751  * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
1752  * first, and then eventaully from there to the trampoline to get into virtual
1753  * mode.
1754  */
1755 __EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
1756 __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60, IRQS_DISABLED)
1757 EXC_VIRT_NONE(0x4e60, 0x20)
1758 TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
1759 TRAMP_REAL_BEGIN(hmi_exception_early)
1760         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0xe60, 0
1761         mr      r10,r1                  /* Save r1 */
1762         ld      r1,PACAEMERGSP(r13)     /* Use emergency stack for realmode */
1763         subi    r1,r1,INT_FRAME_SIZE    /* alloc stack frame            */
1764         mfspr   r11,SPRN_HSRR0          /* Save HSRR0 */
1765         mfspr   r12,SPRN_HSRR1          /* Save HSRR1 */
1766         EXCEPTION_PROLOG_COMMON_1()
1767         /* We don't touch AMR here, we never go to virtual mode */
1768         EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
1769         EXCEPTION_PROLOG_COMMON_3(0xe60)
1770         addi    r3,r1,STACK_FRAME_OVERHEAD
1771         BRANCH_LINK_TO_FAR(DOTSYM(hmi_exception_realmode)) /* Function call ABI */
1772         cmpdi   cr0,r3,0
1773         bne     1f
1774
1775         EXCEPTION_RESTORE_REGS EXC_HV
1776         HRFI_TO_USER_OR_KERNEL
1777
1778 1:
1779         /*
1780          * Go to virtual mode and pull the HMI event information from
1781          * firmware.
1782          */
1783         EXCEPTION_RESTORE_REGS EXC_HV
1784         SET_SCRATCH0(r13)
1785         EXCEPTION_PROLOG_0 PACA_EXGEN
1786         b       tramp_real_hmi_exception
1787
1788 EXC_COMMON_BEGIN(hmi_exception_common)
1789         EXCEPTION_COMMON(PACA_EXGEN, 0xe60)
1790         FINISH_NAP
1791         bl      save_nvgprs
1792         RECONCILE_IRQ_STATE(r10, r11)
1793         RUNLATCH_ON
1794         addi    r3,r1,STACK_FRAME_OVERHEAD
1795         bl      handle_hmi_exception
1796         b       ret_from_except
1797
1798 EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20, IRQS_DISABLED)
1799 EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80, IRQS_DISABLED)
1800 TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
1801 #ifdef CONFIG_PPC_DOORBELL
1802 EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
1803 #else
1804 EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
1805 #endif
1806
1807
1808 EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20, IRQS_DISABLED)
1809 EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0, IRQS_DISABLED)
1810 TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
1811 EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
1812
1813
1814 EXC_REAL_NONE(0xec0, 0x20)
1815 EXC_VIRT_NONE(0x4ec0, 0x20)
1816 EXC_REAL_NONE(0xee0, 0x20)
1817 EXC_VIRT_NONE(0x4ee0, 0x20)
1818
1819
1820 EXC_REAL_OOL_MASKABLE(performance_monitor, 0xf00, 0x20, IRQS_PMI_DISABLED)
1821 EXC_VIRT_OOL_MASKABLE(performance_monitor, 0x4f00, 0x20, 0xf00, IRQS_PMI_DISABLED)
1822 TRAMP_KVM(PACA_EXGEN, 0xf00)
1823 EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
1824
1825
1826 EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
1827 EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
1828 TRAMP_KVM(PACA_EXGEN, 0xf20)
1829 EXC_COMMON_BEGIN(altivec_unavailable_common)
1830         EXCEPTION_COMMON(PACA_EXGEN, 0xf20)
1831 #ifdef CONFIG_ALTIVEC
1832 BEGIN_FTR_SECTION
1833         beq     1f
1834 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1835   BEGIN_FTR_SECTION_NESTED(69)
1836         /* Test if 2 TM state bits are zero.  If non-zero (ie. userspace was in
1837          * transaction), go do TM stuff
1838          */
1839         rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1840         bne-    2f
1841   END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1842 #endif
1843         bl      load_up_altivec
1844         b       fast_exception_return
1845 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1846 2:      /* User process was in a transaction */
1847         bl      save_nvgprs
1848         RECONCILE_IRQ_STATE(r10, r11)
1849         addi    r3,r1,STACK_FRAME_OVERHEAD
1850         bl      altivec_unavailable_tm
1851         b       ret_from_except
1852 #endif
1853 1:
1854 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1855 #endif
1856         bl      save_nvgprs
1857         RECONCILE_IRQ_STATE(r10, r11)
1858         addi    r3,r1,STACK_FRAME_OVERHEAD
1859         bl      altivec_unavailable_exception
1860         b       ret_from_except
1861
1862
1863 EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
1864 EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
1865 TRAMP_KVM(PACA_EXGEN, 0xf40)
1866 EXC_COMMON_BEGIN(vsx_unavailable_common)
1867         EXCEPTION_COMMON(PACA_EXGEN, 0xf40)
1868 #ifdef CONFIG_VSX
1869 BEGIN_FTR_SECTION
1870         beq     1f
1871 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1872   BEGIN_FTR_SECTION_NESTED(69)
1873         /* Test if 2 TM state bits are zero.  If non-zero (ie. userspace was in
1874          * transaction), go do TM stuff
1875          */
1876         rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1877         bne-    2f
1878   END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1879 #endif
1880         b       load_up_vsx
1881 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1882 2:      /* User process was in a transaction */
1883         bl      save_nvgprs
1884         RECONCILE_IRQ_STATE(r10, r11)
1885         addi    r3,r1,STACK_FRAME_OVERHEAD
1886         bl      vsx_unavailable_tm
1887         b       ret_from_except
1888 #endif
1889 1:
1890 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1891 #endif
1892         bl      save_nvgprs
1893         RECONCILE_IRQ_STATE(r10, r11)
1894         addi    r3,r1,STACK_FRAME_OVERHEAD
1895         bl      vsx_unavailable_exception
1896         b       ret_from_except
1897
1898
1899 EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
1900 EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
1901 TRAMP_KVM(PACA_EXGEN, 0xf60)
1902 EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
1903
1904
1905 EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
1906 EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
1907 TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
1908 EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
1909
1910
1911 EXC_REAL_NONE(0xfa0, 0x20)
1912 EXC_VIRT_NONE(0x4fa0, 0x20)
1913 EXC_REAL_NONE(0xfc0, 0x20)
1914 EXC_VIRT_NONE(0x4fc0, 0x20)
1915 EXC_REAL_NONE(0xfe0, 0x20)
1916 EXC_VIRT_NONE(0x4fe0, 0x20)
1917
1918 EXC_REAL_NONE(0x1000, 0x100)
1919 EXC_VIRT_NONE(0x5000, 0x100)
1920 EXC_REAL_NONE(0x1100, 0x100)
1921 EXC_VIRT_NONE(0x5100, 0x100)
1922
1923 #ifdef CONFIG_CBE_RAS
1924 EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
1925 EXC_VIRT_NONE(0x5200, 0x100)
1926 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
1927 EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
1928 #else /* CONFIG_CBE_RAS */
1929 EXC_REAL_NONE(0x1200, 0x100)
1930 EXC_VIRT_NONE(0x5200, 0x100)
1931 #endif
1932
1933
1934 EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
1935 EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
1936 TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
1937 EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
1938
1939 EXC_REAL_NONE(0x1400, 0x100)
1940 EXC_VIRT_NONE(0x5400, 0x100)
1941
1942 EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
1943         mtspr   SPRN_SPRG_HSCRATCH0,r13
1944         EXCEPTION_PROLOG_0 PACA_EXGEN
1945         EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 0, 0x1500, 0
1946
1947 #ifdef CONFIG_PPC_DENORMALISATION
1948         mfspr   r10,SPRN_HSRR1
1949         andis.  r10,r10,(HSRR1_DENORM)@h /* denorm? */
1950         bne+    denorm_assist
1951 #endif
1952
1953         KVMTEST EXC_HV 0x1500
1954         EXCEPTION_PROLOG_2_REAL denorm_common, EXC_HV, 1
1955 EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
1956
1957 #ifdef CONFIG_PPC_DENORMALISATION
1958 EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
1959         b       exc_real_0x1500_denorm_exception_hv
1960 EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
1961 #else
1962 EXC_VIRT_NONE(0x5500, 0x100)
1963 #endif
1964
1965 TRAMP_KVM_HV(PACA_EXGEN, 0x1500)
1966
1967 #ifdef CONFIG_PPC_DENORMALISATION
1968 TRAMP_REAL_BEGIN(denorm_assist)
1969 BEGIN_FTR_SECTION
1970 /*
1971  * To denormalise we need to move a copy of the register to itself.
1972  * For POWER6 do that here for all FP regs.
1973  */
1974         mfmsr   r10
1975         ori     r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
1976         xori    r10,r10,(MSR_FE0|MSR_FE1)
1977         mtmsrd  r10
1978         sync
1979
1980         .Lreg=0
1981         .rept 32
1982         fmr     .Lreg,.Lreg
1983         .Lreg=.Lreg+1
1984         .endr
1985
1986 FTR_SECTION_ELSE
1987 /*
1988  * To denormalise we need to move a copy of the register to itself.
1989  * For POWER7 do that here for the first 32 VSX registers only.
1990  */
1991         mfmsr   r10
1992         oris    r10,r10,MSR_VSX@h
1993         mtmsrd  r10
1994         sync
1995
1996         .Lreg=0
1997         .rept 32
1998         XVCPSGNDP(.Lreg,.Lreg,.Lreg)
1999         .Lreg=.Lreg+1
2000         .endr
2001
2002 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
2003
2004 BEGIN_FTR_SECTION
2005         b       denorm_done
2006 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
2007 /*
2008  * To denormalise we need to move a copy of the register to itself.
2009  * For POWER8 we need to do that for all 64 VSX registers
2010  */
2011         .Lreg=32
2012         .rept 32
2013         XVCPSGNDP(.Lreg,.Lreg,.Lreg)
2014         .Lreg=.Lreg+1
2015         .endr
2016
2017 denorm_done:
2018         mfspr   r11,SPRN_HSRR0
2019         subi    r11,r11,4
2020         mtspr   SPRN_HSRR0,r11
2021         mtcrf   0x80,r9
2022         ld      r9,PACA_EXGEN+EX_R9(r13)
2023         RESTORE_PPR_PACA(PACA_EXGEN, r10)
2024 BEGIN_FTR_SECTION
2025         ld      r10,PACA_EXGEN+EX_CFAR(r13)
2026         mtspr   SPRN_CFAR,r10
2027 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
2028         ld      r10,PACA_EXGEN+EX_R10(r13)
2029         ld      r11,PACA_EXGEN+EX_R11(r13)
2030         ld      r12,PACA_EXGEN+EX_R12(r13)
2031         ld      r13,PACA_EXGEN+EX_R13(r13)
2032         HRFI_TO_UNKNOWN
2033         b       .
2034 #endif
2035
2036 EXC_COMMON(denorm_common, 0x1500, unknown_exception)
2037
2038
2039 #ifdef CONFIG_CBE_RAS
2040 EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
2041 EXC_VIRT_NONE(0x5600, 0x100)
2042 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
2043 EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
2044 #else /* CONFIG_CBE_RAS */
2045 EXC_REAL_NONE(0x1600, 0x100)
2046 EXC_VIRT_NONE(0x5600, 0x100)
2047 #endif
2048
2049
2050 EXC_REAL(altivec_assist, 0x1700, 0x100)
2051 EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
2052 TRAMP_KVM(PACA_EXGEN, 0x1700)
2053 #ifdef CONFIG_ALTIVEC
2054 EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
2055 #else
2056 EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
2057 #endif
2058
2059
2060 #ifdef CONFIG_CBE_RAS
2061 EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
2062 EXC_VIRT_NONE(0x5800, 0x100)
2063 TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
2064 EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
2065 #else /* CONFIG_CBE_RAS */
2066 EXC_REAL_NONE(0x1800, 0x100)
2067 EXC_VIRT_NONE(0x5800, 0x100)
2068 #endif
2069
2070 #ifdef CONFIG_PPC_WATCHDOG
2071
2072 #define MASKED_DEC_HANDLER_LABEL 3f
2073
2074 #define MASKED_DEC_HANDLER(_H)                          \
2075 3: /* soft-nmi */                                       \
2076         std     r12,PACA_EXGEN+EX_R12(r13);             \
2077         GET_SCRATCH0(r10);                              \
2078         std     r10,PACA_EXGEN+EX_R13(r13);             \
2079         EXCEPTION_PROLOG_2_REAL soft_nmi_common, _H, 1
2080
2081 /*
2082  * Branch to soft_nmi_interrupt using the emergency stack. The emergency
2083  * stack is one that is usable by maskable interrupts so long as MSR_EE
2084  * remains off. It is used for recovery when something has corrupted the
2085  * normal kernel stack, for example. The "soft NMI" must not use the process
2086  * stack because we want irq disabled sections to avoid touching the stack
2087  * at all (other than PMU interrupts), so use the emergency stack for this,
2088  * and run it entirely with interrupts hard disabled.
2089  */
2090 EXC_COMMON_BEGIN(soft_nmi_common)
2091         mr      r10,r1
2092         ld      r1,PACAEMERGSP(r13)
2093         subi    r1,r1,INT_FRAME_SIZE
2094         EXCEPTION_COMMON_STACK(PACA_EXGEN, 0x900)
2095         bl      save_nvgprs
2096         RECONCILE_IRQ_STATE(r10, r11)
2097         addi    r3,r1,STACK_FRAME_OVERHEAD
2098         bl      soft_nmi_interrupt
2099         b       ret_from_except
2100
2101 #else /* CONFIG_PPC_WATCHDOG */
2102 #define MASKED_DEC_HANDLER_LABEL 2f /* normal return */
2103 #define MASKED_DEC_HANDLER(_H)
2104 #endif /* CONFIG_PPC_WATCHDOG */
2105
2106 /*
2107  * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
2108  * - If it was a decrementer interrupt, we bump the dec to max and and return.
2109  * - If it was a doorbell we return immediately since doorbells are edge
2110  *   triggered and won't automatically refire.
2111  * - If it was a HMI we return immediately since we handled it in realmode
2112  *   and it won't refire.
2113  * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return.
2114  * This is called with r10 containing the value to OR to the paca field.
2115  */
2116 .macro MASKED_INTERRUPT hsrr
2117         .if \hsrr
2118 masked_Hinterrupt:
2119         .else
2120 masked_interrupt:
2121         .endif
2122         std     r11,PACA_EXGEN+EX_R11(r13)
2123         lbz     r11,PACAIRQHAPPENED(r13)
2124         or      r11,r11,r10
2125         stb     r11,PACAIRQHAPPENED(r13)
2126         cmpwi   r10,PACA_IRQ_DEC
2127         bne     1f
2128         lis     r10,0x7fff
2129         ori     r10,r10,0xffff
2130         mtspr   SPRN_DEC,r10
2131         b       MASKED_DEC_HANDLER_LABEL
2132 1:      andi.   r10,r10,PACA_IRQ_MUST_HARD_MASK
2133         beq     2f
2134         .if \hsrr
2135         mfspr   r10,SPRN_HSRR1
2136         xori    r10,r10,MSR_EE  /* clear MSR_EE */
2137         mtspr   SPRN_HSRR1,r10
2138         .else
2139         mfspr   r10,SPRN_SRR1
2140         xori    r10,r10,MSR_EE  /* clear MSR_EE */
2141         mtspr   SPRN_SRR1,r10
2142         .endif
2143         ori     r11,r11,PACA_IRQ_HARD_DIS
2144         stb     r11,PACAIRQHAPPENED(r13)
2145 2:      /* done */
2146         mtcrf   0x80,r9
2147         std     r1,PACAR1(r13)
2148         ld      r9,PACA_EXGEN+EX_R9(r13)
2149         ld      r10,PACA_EXGEN+EX_R10(r13)
2150         ld      r11,PACA_EXGEN+EX_R11(r13)
2151         /* returns to kernel where r13 must be set up, so don't restore it */
2152         .if \hsrr
2153         HRFI_TO_KERNEL
2154         .else
2155         RFI_TO_KERNEL
2156         .endif
2157         b       .
2158         MASKED_DEC_HANDLER(\hsrr\())
2159 .endm
2160
2161 TRAMP_REAL_BEGIN(stf_barrier_fallback)
2162         std     r9,PACA_EXRFI+EX_R9(r13)
2163         std     r10,PACA_EXRFI+EX_R10(r13)
2164         sync
2165         ld      r9,PACA_EXRFI+EX_R9(r13)
2166         ld      r10,PACA_EXRFI+EX_R10(r13)
2167         ori     31,31,0
2168         .rept 14
2169         b       1f
2170 1:
2171         .endr
2172         blr
2173
2174 TRAMP_REAL_BEGIN(rfi_flush_fallback)
2175         SET_SCRATCH0(r13);
2176         GET_PACA(r13);
2177         std     r1,PACA_EXRFI+EX_R12(r13)
2178         ld      r1,PACAKSAVE(r13)
2179         std     r9,PACA_EXRFI+EX_R9(r13)
2180         std     r10,PACA_EXRFI+EX_R10(r13)
2181         std     r11,PACA_EXRFI+EX_R11(r13)
2182         mfctr   r9
2183         ld      r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
2184         ld      r11,PACA_L1D_FLUSH_SIZE(r13)
2185         srdi    r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
2186         mtctr   r11
2187         DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
2188
2189         /* order ld/st prior to dcbt stop all streams with flushing */
2190         sync
2191
2192         /*
2193          * The load adresses are at staggered offsets within cachelines,
2194          * which suits some pipelines better (on others it should not
2195          * hurt).
2196          */
2197 1:
2198         ld      r11,(0x80 + 8)*0(r10)
2199         ld      r11,(0x80 + 8)*1(r10)
2200         ld      r11,(0x80 + 8)*2(r10)
2201         ld      r11,(0x80 + 8)*3(r10)
2202         ld      r11,(0x80 + 8)*4(r10)
2203         ld      r11,(0x80 + 8)*5(r10)
2204         ld      r11,(0x80 + 8)*6(r10)
2205         ld      r11,(0x80 + 8)*7(r10)
2206         addi    r10,r10,0x80*8
2207         bdnz    1b
2208
2209         mtctr   r9
2210         ld      r9,PACA_EXRFI+EX_R9(r13)
2211         ld      r10,PACA_EXRFI+EX_R10(r13)
2212         ld      r11,PACA_EXRFI+EX_R11(r13)
2213         ld      r1,PACA_EXRFI+EX_R12(r13)
2214         GET_SCRATCH0(r13);
2215         rfid
2216
2217 TRAMP_REAL_BEGIN(hrfi_flush_fallback)
2218         SET_SCRATCH0(r13);
2219         GET_PACA(r13);
2220         std     r1,PACA_EXRFI+EX_R12(r13)
2221         ld      r1,PACAKSAVE(r13)
2222         std     r9,PACA_EXRFI+EX_R9(r13)
2223         std     r10,PACA_EXRFI+EX_R10(r13)
2224         std     r11,PACA_EXRFI+EX_R11(r13)
2225         mfctr   r9
2226         ld      r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
2227         ld      r11,PACA_L1D_FLUSH_SIZE(r13)
2228         srdi    r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
2229         mtctr   r11
2230         DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
2231
2232         /* order ld/st prior to dcbt stop all streams with flushing */
2233         sync
2234
2235         /*
2236          * The load adresses are at staggered offsets within cachelines,
2237          * which suits some pipelines better (on others it should not
2238          * hurt).
2239          */
2240 1:
2241         ld      r11,(0x80 + 8)*0(r10)
2242         ld      r11,(0x80 + 8)*1(r10)
2243         ld      r11,(0x80 + 8)*2(r10)
2244         ld      r11,(0x80 + 8)*3(r10)
2245         ld      r11,(0x80 + 8)*4(r10)
2246         ld      r11,(0x80 + 8)*5(r10)
2247         ld      r11,(0x80 + 8)*6(r10)
2248         ld      r11,(0x80 + 8)*7(r10)
2249         addi    r10,r10,0x80*8
2250         bdnz    1b
2251
2252         mtctr   r9
2253         ld      r9,PACA_EXRFI+EX_R9(r13)
2254         ld      r10,PACA_EXRFI+EX_R10(r13)
2255         ld      r11,PACA_EXRFI+EX_R11(r13)
2256         ld      r1,PACA_EXRFI+EX_R12(r13)
2257         GET_SCRATCH0(r13);
2258         hrfid
2259
2260 /*
2261  * Real mode exceptions actually use this too, but alternate
2262  * instruction code patches (which end up in the common .text area)
2263  * cannot reach these if they are put there.
2264  */
2265 USE_FIXED_SECTION(virt_trampolines)
2266         MASKED_INTERRUPT EXC_STD
2267         MASKED_INTERRUPT EXC_HV
2268
2269 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
2270 TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
2271         /*
2272          * Here all GPRs are unchanged from when the interrupt happened
2273          * except for r13, which is saved in SPRG_SCRATCH0.
2274          */
2275         mfspr   r13, SPRN_SRR0
2276         addi    r13, r13, 4
2277         mtspr   SPRN_SRR0, r13
2278         GET_SCRATCH0(r13)
2279         RFI_TO_KERNEL
2280         b       .
2281
2282 TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
2283         /*
2284          * Here all GPRs are unchanged from when the interrupt happened
2285          * except for r13, which is saved in SPRG_SCRATCH0.
2286          */
2287         mfspr   r13, SPRN_HSRR0
2288         addi    r13, r13, 4
2289         mtspr   SPRN_HSRR0, r13
2290         GET_SCRATCH0(r13)
2291         HRFI_TO_KERNEL
2292         b       .
2293 #endif
2294
2295 /*
2296  * Ensure that any handlers that get invoked from the exception prologs
2297  * above are below the first 64KB (0x10000) of the kernel image because
2298  * the prologs assemble the addresses of these handlers using the
2299  * LOAD_HANDLER macro, which uses an ori instruction.
2300  */
2301
2302 /*** Common interrupt handlers ***/
2303
2304
2305         /*
2306          * Relocation-on interrupts: A subset of the interrupts can be delivered
2307          * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
2308          * it.  Addresses are the same as the original interrupt addresses, but
2309          * offset by 0xc000000000004000.
2310          * It's impossible to receive interrupts below 0x300 via this mechanism.
2311          * KVM: None of these traps are from the guest ; anything that escalated
2312          * to HV=1 from HV=0 is delivered via real mode handlers.
2313          */
2314
2315         /*
2316          * This uses the standard macro, since the original 0x300 vector
2317          * only has extra guff for STAB-based processors -- which never
2318          * come here.
2319          */
2320
2321 EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
2322         b       __ppc64_runlatch_on
2323
2324 USE_FIXED_SECTION(virt_trampolines)
2325         /*
2326          * The __end_interrupts marker must be past the out-of-line (OOL)
2327          * handlers, so that they are copied to real address 0x100 when running
2328          * a relocatable kernel. This ensures they can be reached from the short
2329          * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
2330          * directly, without using LOAD_HANDLER().
2331          */
2332         .align  7
2333         .globl  __end_interrupts
2334 __end_interrupts:
2335 DEFINE_FIXED_SYMBOL(__end_interrupts)
2336
2337 #ifdef CONFIG_PPC_970_NAP
2338 EXC_COMMON_BEGIN(power4_fixup_nap)
2339         andc    r9,r9,r10
2340         std     r9,TI_LOCAL_FLAGS(r11)
2341         ld      r10,_LINK(r1)           /* make idle task do the */
2342         std     r10,_NIP(r1)            /* equivalent of a blr */
2343         blr
2344 #endif
2345
2346 CLOSE_FIXED_SECTION(real_vectors);
2347 CLOSE_FIXED_SECTION(real_trampolines);
2348 CLOSE_FIXED_SECTION(virt_vectors);
2349 CLOSE_FIXED_SECTION(virt_trampolines);
2350
2351 USE_TEXT_SECTION()
2352
2353 /*
2354  * Hash table stuff
2355  */
2356         .balign IFETCH_ALIGN_BYTES
2357 do_hash_page:
2358 #ifdef CONFIG_PPC_BOOK3S_64
2359         lis     r0,(DSISR_BAD_FAULT_64S | DSISR_DABRMATCH | DSISR_KEYFAULT)@h
2360         ori     r0,r0,DSISR_BAD_FAULT_64S@l
2361         and.    r0,r4,r0                /* weird error? */
2362         bne-    handle_page_fault       /* if not, try to insert a HPTE */
2363         ld      r11, PACA_THREAD_INFO(r13)
2364         lwz     r0,TI_PREEMPT(r11)      /* If we're in an "NMI" */
2365         andis.  r0,r0,NMI_MASK@h        /* (i.e. an irq when soft-disabled) */
2366         bne     77f                     /* then don't call hash_page now */
2367
2368         /*
2369          * r3 contains the faulting address
2370          * r4 msr
2371          * r5 contains the trap number
2372          * r6 contains dsisr
2373          *
2374          * at return r3 = 0 for success, 1 for page fault, negative for error
2375          */
2376         mr      r4,r12
2377         ld      r6,_DSISR(r1)
2378         bl      __hash_page             /* build HPTE if possible */
2379         cmpdi   r3,0                    /* see if __hash_page succeeded */
2380
2381         /* Success */
2382         beq     fast_exc_return_irq     /* Return from exception on success */
2383
2384         /* Error */
2385         blt-    13f
2386
2387         /* Reload DSISR into r4 for the DABR check below */
2388         ld      r4,_DSISR(r1)
2389 #endif /* CONFIG_PPC_BOOK3S_64 */
2390
2391 /* Here we have a page fault that hash_page can't handle. */
2392 handle_page_fault:
2393 11:     andis.  r0,r4,DSISR_DABRMATCH@h
2394         bne-    handle_dabr_fault
2395         ld      r4,_DAR(r1)
2396         ld      r5,_DSISR(r1)
2397         addi    r3,r1,STACK_FRAME_OVERHEAD
2398         bl      do_page_fault
2399         cmpdi   r3,0
2400         beq+    ret_from_except_lite
2401         bl      save_nvgprs
2402         mr      r5,r3
2403         addi    r3,r1,STACK_FRAME_OVERHEAD
2404         lwz     r4,_DAR(r1)
2405         bl      bad_page_fault
2406         b       ret_from_except
2407
2408 /* We have a data breakpoint exception - handle it */
2409 handle_dabr_fault:
2410         bl      save_nvgprs
2411         ld      r4,_DAR(r1)
2412         ld      r5,_DSISR(r1)
2413         addi    r3,r1,STACK_FRAME_OVERHEAD
2414         bl      do_break
2415         /*
2416          * do_break() may have changed the NV GPRS while handling a breakpoint.
2417          * If so, we need to restore them with their updated values. Don't use
2418          * ret_from_except_lite here.
2419          */
2420         b       ret_from_except
2421
2422
2423 #ifdef CONFIG_PPC_BOOK3S_64
2424 /* We have a page fault that hash_page could handle but HV refused
2425  * the PTE insertion
2426  */
2427 13:     bl      save_nvgprs
2428         mr      r5,r3
2429         addi    r3,r1,STACK_FRAME_OVERHEAD
2430         ld      r4,_DAR(r1)
2431         bl      low_hash_fault
2432         b       ret_from_except
2433 #endif
2434
2435 /*
2436  * We come here as a result of a DSI at a point where we don't want
2437  * to call hash_page, such as when we are accessing memory (possibly
2438  * user memory) inside a PMU interrupt that occurred while interrupts
2439  * were soft-disabled.  We want to invoke the exception handler for
2440  * the access, or panic if there isn't a handler.
2441  */
2442 77:     bl      save_nvgprs
2443         mr      r4,r3
2444         addi    r3,r1,STACK_FRAME_OVERHEAD
2445         li      r5,SIGSEGV
2446         bl      bad_page_fault
2447         b       ret_from_except
2448
2449 /*
2450  * Here we have detected that the kernel stack pointer is bad.
2451  * R9 contains the saved CR, r13 points to the paca,
2452  * r10 contains the (bad) kernel stack pointer,
2453  * r11 and r12 contain the saved SRR0 and SRR1.
2454  * We switch to using an emergency stack, save the registers there,
2455  * and call kernel_bad_stack(), which panics.
2456  */
2457 bad_stack:
2458         ld      r1,PACAEMERGSP(r13)
2459         subi    r1,r1,64+INT_FRAME_SIZE
2460         std     r9,_CCR(r1)
2461         std     r10,GPR1(r1)
2462         std     r11,_NIP(r1)
2463         std     r12,_MSR(r1)
2464         mfspr   r11,SPRN_DAR
2465         mfspr   r12,SPRN_DSISR
2466         std     r11,_DAR(r1)
2467         std     r12,_DSISR(r1)
2468         mflr    r10
2469         mfctr   r11
2470         mfxer   r12
2471         std     r10,_LINK(r1)
2472         std     r11,_CTR(r1)
2473         std     r12,_XER(r1)
2474         SAVE_GPR(0,r1)
2475         SAVE_GPR(2,r1)
2476         ld      r10,EX_R3(r3)
2477         std     r10,GPR3(r1)
2478         SAVE_GPR(4,r1)
2479         SAVE_4GPRS(5,r1)
2480         ld      r9,EX_R9(r3)
2481         ld      r10,EX_R10(r3)
2482         SAVE_2GPRS(9,r1)
2483         ld      r9,EX_R11(r3)
2484         ld      r10,EX_R12(r3)
2485         ld      r11,EX_R13(r3)
2486         std     r9,GPR11(r1)
2487         std     r10,GPR12(r1)
2488         std     r11,GPR13(r1)
2489 BEGIN_FTR_SECTION
2490         ld      r10,EX_CFAR(r3)
2491         std     r10,ORIG_GPR3(r1)
2492 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
2493         SAVE_8GPRS(14,r1)
2494         SAVE_10GPRS(22,r1)
2495         lhz     r12,PACA_TRAP_SAVE(r13)
2496         std     r12,_TRAP(r1)
2497         addi    r11,r1,INT_FRAME_SIZE
2498         std     r11,0(r1)
2499         li      r12,0
2500         std     r12,0(r11)
2501         ld      r2,PACATOC(r13)
2502         ld      r11,exception_marker@toc(r2)
2503         std     r12,RESULT(r1)
2504         std     r11,STACK_FRAME_OVERHEAD-16(r1)
2505 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
2506         bl      kernel_bad_stack
2507         b       1b
2508 _ASM_NOKPROBE_SYMBOL(bad_stack);
2509
2510 /*
2511  * When doorbell is triggered from system reset wakeup, the message is
2512  * not cleared, so it would fire again when EE is enabled.
2513  *
2514  * When coming from local_irq_enable, there may be the same problem if
2515  * we were hard disabled.
2516  *
2517  * Execute msgclr to clear pending exceptions before handling it.
2518  */
2519 h_doorbell_common_msgclr:
2520         LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
2521         PPC_MSGCLR(3)
2522         b       h_doorbell_common
2523
2524 doorbell_super_common_msgclr:
2525         LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
2526         PPC_MSGCLRP(3)
2527         b       doorbell_super_common
2528
2529 /*
2530  * Called from arch_local_irq_enable when an interrupt needs
2531  * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
2532  * which kind of interrupt. MSR:EE is already off. We generate a
2533  * stackframe like if a real interrupt had happened.
2534  *
2535  * Note: While MSR:EE is off, we need to make sure that _MSR
2536  * in the generated frame has EE set to 1 or the exception
2537  * handler will not properly re-enable them.
2538  *
2539  * Note that we don't specify LR as the NIP (return address) for
2540  * the interrupt because that would unbalance the return branch
2541  * predictor.
2542  */
2543 _GLOBAL(__replay_interrupt)
2544         /* We are going to jump to the exception common code which
2545          * will retrieve various register values from the PACA which
2546          * we don't give a damn about, so we don't bother storing them.
2547          */
2548         mfmsr   r12
2549         LOAD_REG_ADDR(r11, replay_interrupt_return)
2550         mfcr    r9
2551         ori     r12,r12,MSR_EE
2552         cmpwi   r3,0x900
2553         beq     decrementer_common
2554         cmpwi   r3,0x500
2555 BEGIN_FTR_SECTION
2556         beq     h_virt_irq_common
2557 FTR_SECTION_ELSE
2558         beq     hardware_interrupt_common
2559 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300)
2560         cmpwi   r3,0xf00
2561         beq     performance_monitor_common
2562 BEGIN_FTR_SECTION
2563         cmpwi   r3,0xa00
2564         beq     h_doorbell_common_msgclr
2565         cmpwi   r3,0xe60
2566         beq     hmi_exception_common
2567 FTR_SECTION_ELSE
2568         cmpwi   r3,0xa00
2569         beq     doorbell_super_common_msgclr
2570 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
2571 replay_interrupt_return:
2572         blr
2573
2574 _ASM_NOKPROBE_SYMBOL(__replay_interrupt)