]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/powerpc/kernel/exceptions-64s.S
Merge tag 'cpu-hotplug-3.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[karo-tx-linux.git] / arch / powerpc / kernel / exceptions-64s.S
1 /*
2  * This file contains the 64-bit "server" PowerPC variant
3  * of the low level exception handling including exception
4  * vectors, exception return, part of the slb and stab
5  * handling and other fixed offset specific things.
6  *
7  * This file is meant to be #included from head_64.S due to
8  * position dependent assembly.
9  *
10  * Most of this originates from head_64.S and thus has the same
11  * copyright history.
12  *
13  */
14
15 #include <asm/hw_irq.h>
16 #include <asm/exception-64s.h>
17 #include <asm/ptrace.h>
18
19 /*
20  * We layout physical memory as follows:
21  * 0x0000 - 0x00ff : Secondary processor spin code
22  * 0x0100 - 0x17ff : pSeries Interrupt prologs
23  * 0x1800 - 0x4000 : interrupt support common interrupt prologs
24  * 0x4000 - 0x5fff : pSeries interrupts with IR=1,DR=1
25  * 0x6000 - 0x6fff : more interrupt support including for IR=1,DR=1
26  * 0x7000 - 0x7fff : FWNMI data area
27  * 0x8000 - 0x8fff : Initial (CPU0) segment table
28  * 0x9000 -        : Early init and support code
29  */
30         /* Syscall routine is used twice, in reloc-off and reloc-on paths */
31 #define SYSCALL_PSERIES_1                                       \
32 BEGIN_FTR_SECTION                                               \
33         cmpdi   r0,0x1ebe ;                                     \
34         beq-    1f ;                                            \
35 END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)                          \
36         mr      r9,r13 ;                                        \
37         GET_PACA(r13) ;                                         \
38         mfspr   r11,SPRN_SRR0 ;                                 \
39 0:
40
41 #define SYSCALL_PSERIES_2_RFID                                  \
42         mfspr   r12,SPRN_SRR1 ;                                 \
43         ld      r10,PACAKBASE(r13) ;                            \
44         LOAD_HANDLER(r10, system_call_entry) ;                  \
45         mtspr   SPRN_SRR0,r10 ;                                 \
46         ld      r10,PACAKMSR(r13) ;                             \
47         mtspr   SPRN_SRR1,r10 ;                                 \
48         rfid ;                                                  \
49         b       . ;     /* prevent speculative execution */
50
51 #define SYSCALL_PSERIES_3                                       \
52         /* Fast LE/BE switch system call */                     \
53 1:      mfspr   r12,SPRN_SRR1 ;                                 \
54         xori    r12,r12,MSR_LE ;                                \
55         mtspr   SPRN_SRR1,r12 ;                                 \
56         rfid ;          /* return to userspace */               \
57         b       . ;                                             \
58 2:      mfspr   r12,SPRN_SRR1 ;                                 \
59         andi.   r12,r12,MSR_PR ;                                \
60         bne     0b ;                                            \
61         mtspr   SPRN_SRR0,r3 ;                                  \
62         mtspr   SPRN_SRR1,r4 ;                                  \
63         mtspr   SPRN_SDR1,r5 ;                                  \
64         rfid ;                                                  \
65         b       . ;     /* prevent speculative execution */
66
67 #if defined(CONFIG_RELOCATABLE)
68         /*
69          * We can't branch directly; in the direct case we use LR
70          * and system_call_entry restores LR.  (We thus need to move
71          * LR to r10 in the RFID case too.)
72          */
73 #define SYSCALL_PSERIES_2_DIRECT                                \
74         mflr    r10 ;                                           \
75         ld      r12,PACAKBASE(r13) ;                            \
76         LOAD_HANDLER(r12, system_call_entry_direct) ;           \
77         mtctr   r12 ;                                           \
78         mfspr   r12,SPRN_SRR1 ;                                 \
79         /* Re-use of r13... No spare regs to do this */ \
80         li      r13,MSR_RI ;                                    \
81         mtmsrd  r13,1 ;                                         \
82         GET_PACA(r13) ; /* get r13 back */                      \
83         bctr ;
84 #else
85         /* We can branch directly */
86 #define SYSCALL_PSERIES_2_DIRECT                                \
87         mfspr   r12,SPRN_SRR1 ;                                 \
88         li      r10,MSR_RI ;                                    \
89         mtmsrd  r10,1 ;                 /* Set RI (EE=0) */     \
90         b       system_call_entry_direct ;
91 #endif
92
93 /*
94  * This is the start of the interrupt handlers for pSeries
95  * This code runs with relocation off.
96  * Code from here to __end_interrupts gets copied down to real
97  * address 0x100 when we are running a relocatable kernel.
98  * Therefore any relative branches in this section must only
99  * branch to labels in this section.
100  */
101         . = 0x100
102         .globl __start_interrupts
103 __start_interrupts:
104
105         .globl system_reset_pSeries;
106 system_reset_pSeries:
107         HMT_MEDIUM_PPR_DISCARD
108         SET_SCRATCH0(r13)
109 #ifdef CONFIG_PPC_P7_NAP
110 BEGIN_FTR_SECTION
111         /* Running native on arch 2.06 or later, check if we are
112          * waking up from nap. We only handle no state loss and
113          * supervisor state loss. We do -not- handle hypervisor
114          * state loss at this time.
115          */
116         mfspr   r13,SPRN_SRR1
117         rlwinm. r13,r13,47-31,30,31
118         beq     9f
119
120         /* waking up from powersave (nap) state */
121         cmpwi   cr1,r13,2
122         /* Total loss of HV state is fatal, we could try to use the
123          * PIR to locate a PACA, then use an emergency stack etc...
124          * OPAL v3 based powernv platforms have new idle states
125          * which fall in this catagory.
126          */
127         bgt     cr1,8f
128         GET_PACA(r13)
129
130 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
131         li      r0,KVM_HWTHREAD_IN_KERNEL
132         stb     r0,HSTATE_HWTHREAD_STATE(r13)
133         /* Order setting hwthread_state vs. testing hwthread_req */
134         sync
135         lbz     r0,HSTATE_HWTHREAD_REQ(r13)
136         cmpwi   r0,0
137         beq     1f
138         b       kvm_start_guest
139 1:
140 #endif
141
142         beq     cr1,2f
143         b       .power7_wakeup_noloss
144 2:      b       .power7_wakeup_loss
145
146         /* Fast Sleep wakeup on PowerNV */
147 8:      GET_PACA(r13)
148         b       .power7_wakeup_tb_loss
149
150 9:
151 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
152 #endif /* CONFIG_PPC_P7_NAP */
153         EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
154                                  NOTEST, 0x100)
155
156         . = 0x200
157 machine_check_pSeries_1:
158         /* This is moved out of line as it can be patched by FW, but
159          * some code path might still want to branch into the original
160          * vector
161          */
162         HMT_MEDIUM_PPR_DISCARD
163         SET_SCRATCH0(r13)               /* save r13 */
164 #ifdef CONFIG_PPC_P7_NAP
165 BEGIN_FTR_SECTION
166         /* Running native on arch 2.06 or later, check if we are
167          * waking up from nap. We only handle no state loss and
168          * supervisor state loss. We do -not- handle hypervisor
169          * state loss at this time.
170          */
171         mfspr   r13,SPRN_SRR1
172         rlwinm. r13,r13,47-31,30,31
173         OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
174         beq     9f
175
176         mfspr   r13,SPRN_SRR1
177         rlwinm. r13,r13,47-31,30,31
178         /* waking up from powersave (nap) state */
179         cmpwi   cr1,r13,2
180         /* Total loss of HV state is fatal. let's just stay stuck here */
181         OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
182         bgt     cr1,.
183 9:
184         OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR)
185 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
186 #endif /* CONFIG_PPC_P7_NAP */
187         EXCEPTION_PROLOG_0(PACA_EXMC)
188 BEGIN_FTR_SECTION
189         b       machine_check_pSeries_early
190 FTR_SECTION_ELSE
191         b       machine_check_pSeries_0
192 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
193
194         . = 0x300
195         .globl data_access_pSeries
196 data_access_pSeries:
197         HMT_MEDIUM_PPR_DISCARD
198         SET_SCRATCH0(r13)
199 BEGIN_FTR_SECTION
200         b       data_access_check_stab
201 data_access_not_stab:
202 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
203         EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD,
204                                  KVMTEST, 0x300)
205
206         . = 0x380
207         .globl data_access_slb_pSeries
208 data_access_slb_pSeries:
209         HMT_MEDIUM_PPR_DISCARD
210         SET_SCRATCH0(r13)
211         EXCEPTION_PROLOG_0(PACA_EXSLB)
212         EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x380)
213         std     r3,PACA_EXSLB+EX_R3(r13)
214         mfspr   r3,SPRN_DAR
215 #ifdef __DISABLED__
216         /* Keep that around for when we re-implement dynamic VSIDs */
217         cmpdi   r3,0
218         bge     slb_miss_user_pseries
219 #endif /* __DISABLED__ */
220         mfspr   r12,SPRN_SRR1
221 #ifndef CONFIG_RELOCATABLE
222         b       .slb_miss_realmode
223 #else
224         /*
225          * We can't just use a direct branch to .slb_miss_realmode
226          * because the distance from here to there depends on where
227          * the kernel ends up being put.
228          */
229         mfctr   r11
230         ld      r10,PACAKBASE(r13)
231         LOAD_HANDLER(r10, .slb_miss_realmode)
232         mtctr   r10
233         bctr
234 #endif
235
236         STD_EXCEPTION_PSERIES(0x400, 0x400, instruction_access)
237
238         . = 0x480
239         .globl instruction_access_slb_pSeries
240 instruction_access_slb_pSeries:
241         HMT_MEDIUM_PPR_DISCARD
242         SET_SCRATCH0(r13)
243         EXCEPTION_PROLOG_0(PACA_EXSLB)
244         EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
245         std     r3,PACA_EXSLB+EX_R3(r13)
246         mfspr   r3,SPRN_SRR0            /* SRR0 is faulting address */
247 #ifdef __DISABLED__
248         /* Keep that around for when we re-implement dynamic VSIDs */
249         cmpdi   r3,0
250         bge     slb_miss_user_pseries
251 #endif /* __DISABLED__ */
252         mfspr   r12,SPRN_SRR1
253 #ifndef CONFIG_RELOCATABLE
254         b       .slb_miss_realmode
255 #else
256         mfctr   r11
257         ld      r10,PACAKBASE(r13)
258         LOAD_HANDLER(r10, .slb_miss_realmode)
259         mtctr   r10
260         bctr
261 #endif
262
263         /* We open code these as we can't have a ". = x" (even with
264          * x = "." within a feature section
265          */
266         . = 0x500;
267         .globl hardware_interrupt_pSeries;
268         .globl hardware_interrupt_hv;
269 hardware_interrupt_pSeries:
270 hardware_interrupt_hv:
271         HMT_MEDIUM_PPR_DISCARD
272         BEGIN_FTR_SECTION
273                 _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt,
274                                             EXC_HV, SOFTEN_TEST_HV)
275                 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
276         FTR_SECTION_ELSE
277                 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt,
278                                             EXC_STD, SOFTEN_TEST_HV_201)
279                 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
280         ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
281
282         STD_EXCEPTION_PSERIES(0x600, 0x600, alignment)
283         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x600)
284
285         STD_EXCEPTION_PSERIES(0x700, 0x700, program_check)
286         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x700)
287
288         STD_EXCEPTION_PSERIES(0x800, 0x800, fp_unavailable)
289         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x800)
290
291         . = 0x900
292         .globl decrementer_pSeries
293 decrementer_pSeries:
294         _MASKABLE_EXCEPTION_PSERIES(0x900, decrementer, EXC_STD, SOFTEN_TEST_PR)
295
296         STD_EXCEPTION_HV(0x980, 0x982, hdecrementer)
297
298         MASKABLE_EXCEPTION_PSERIES(0xa00, 0xa00, doorbell_super)
299         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xa00)
300
301         STD_EXCEPTION_PSERIES(0xb00, 0xb00, trap_0b)
302         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xb00)
303
304         . = 0xc00
305         .globl  system_call_pSeries
306 system_call_pSeries:
307         HMT_MEDIUM
308 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
309         SET_SCRATCH0(r13)
310         GET_PACA(r13)
311         std     r9,PACA_EXGEN+EX_R9(r13)
312         std     r10,PACA_EXGEN+EX_R10(r13)
313         mfcr    r9
314         KVMTEST(0xc00)
315         GET_SCRATCH0(r13)
316 #endif
317         SYSCALL_PSERIES_1
318         SYSCALL_PSERIES_2_RFID
319         SYSCALL_PSERIES_3
320         KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
321
322         STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
323         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
324
325         /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
326          * out of line to handle them
327          */
328         . = 0xe00
329 hv_data_storage_trampoline:
330         SET_SCRATCH0(r13)
331         EXCEPTION_PROLOG_0(PACA_EXGEN)
332         b       h_data_storage_hv
333
334         . = 0xe20
335 hv_instr_storage_trampoline:
336         SET_SCRATCH0(r13)
337         EXCEPTION_PROLOG_0(PACA_EXGEN)
338         b       h_instr_storage_hv
339
340         . = 0xe40
341 emulation_assist_trampoline:
342         SET_SCRATCH0(r13)
343         EXCEPTION_PROLOG_0(PACA_EXGEN)
344         b       emulation_assist_hv
345
346         . = 0xe60
347 hv_exception_trampoline:
348         SET_SCRATCH0(r13)
349         EXCEPTION_PROLOG_0(PACA_EXGEN)
350         b       hmi_exception_hv
351
352         . = 0xe80
353 hv_doorbell_trampoline:
354         SET_SCRATCH0(r13)
355         EXCEPTION_PROLOG_0(PACA_EXGEN)
356         b       h_doorbell_hv
357
358         /* We need to deal with the Altivec unavailable exception
359          * here which is at 0xf20, thus in the middle of the
360          * prolog code of the PerformanceMonitor one. A little
361          * trickery is thus necessary
362          */
363         . = 0xf00
364 performance_monitor_pseries_trampoline:
365         SET_SCRATCH0(r13)
366         EXCEPTION_PROLOG_0(PACA_EXGEN)
367         b       performance_monitor_pSeries
368
369         . = 0xf20
370 altivec_unavailable_pseries_trampoline:
371         SET_SCRATCH0(r13)
372         EXCEPTION_PROLOG_0(PACA_EXGEN)
373         b       altivec_unavailable_pSeries
374
375         . = 0xf40
376 vsx_unavailable_pseries_trampoline:
377         SET_SCRATCH0(r13)
378         EXCEPTION_PROLOG_0(PACA_EXGEN)
379         b       vsx_unavailable_pSeries
380
381         . = 0xf60
382 facility_unavailable_trampoline:
383         SET_SCRATCH0(r13)
384         EXCEPTION_PROLOG_0(PACA_EXGEN)
385         b       facility_unavailable_pSeries
386
387         . = 0xf80
388 hv_facility_unavailable_trampoline:
389         SET_SCRATCH0(r13)
390         EXCEPTION_PROLOG_0(PACA_EXGEN)
391         b       facility_unavailable_hv
392
393 #ifdef CONFIG_CBE_RAS
394         STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
395         KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1202)
396 #endif /* CONFIG_CBE_RAS */
397
398         STD_EXCEPTION_PSERIES(0x1300, 0x1300, instruction_breakpoint)
399         KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
400
401         . = 0x1500
402         .global denorm_exception_hv
403 denorm_exception_hv:
404         HMT_MEDIUM_PPR_DISCARD
405         mtspr   SPRN_SPRG_HSCRATCH0,r13
406         EXCEPTION_PROLOG_0(PACA_EXGEN)
407         EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
408
409 #ifdef CONFIG_PPC_DENORMALISATION
410         mfspr   r10,SPRN_HSRR1
411         mfspr   r11,SPRN_HSRR0          /* save HSRR0 */
412         andis.  r10,r10,(HSRR1_DENORM)@h /* denorm? */
413         addi    r11,r11,-4              /* HSRR0 is next instruction */
414         bne+    denorm_assist
415 #endif
416
417         KVMTEST(0x1500)
418         EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
419         KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x1500)
420
421 #ifdef CONFIG_CBE_RAS
422         STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
423         KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1602)
424 #endif /* CONFIG_CBE_RAS */
425
426         STD_EXCEPTION_PSERIES(0x1700, 0x1700, altivec_assist)
427         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x1700)
428
429 #ifdef CONFIG_CBE_RAS
430         STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
431         KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
432 #else
433         . = 0x1800
434 #endif /* CONFIG_CBE_RAS */
435
436
437 /*** Out of line interrupts support ***/
438
439         .align  7
440         /* moved from 0x200 */
441 machine_check_pSeries_early:
442 BEGIN_FTR_SECTION
443         EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
444         /*
445          * Register contents:
446          * R13          = PACA
447          * R9           = CR
448          * Original R9 to R13 is saved on PACA_EXMC
449          *
450          * Switch to mc_emergency stack and handle re-entrancy (though we
451          * currently don't test for overflow). Save MCE registers srr1,
452          * srr0, dar and dsisr and then set ME=1
453          *
454          * We use paca->in_mce to check whether this is the first entry or
455          * nested machine check. We increment paca->in_mce to track nested
456          * machine checks.
457          *
458          * If this is the first entry then set stack pointer to
459          * paca->mc_emergency_sp, otherwise r1 is already pointing to
460          * stack frame on mc_emergency stack.
461          *
462          * NOTE: We are here with MSR_ME=0 (off), which means we risk a
463          * checkstop if we get another machine check exception before we do
464          * rfid with MSR_ME=1.
465          */
466         mr      r11,r1                  /* Save r1 */
467         lhz     r10,PACA_IN_MCE(r13)
468         cmpwi   r10,0                   /* Are we in nested machine check */
469         bne     0f                      /* Yes, we are. */
470         /* First machine check entry */
471         ld      r1,PACAMCEMERGSP(r13)   /* Use MC emergency stack */
472 0:      subi    r1,r1,INT_FRAME_SIZE    /* alloc stack frame */
473         addi    r10,r10,1               /* increment paca->in_mce */
474         sth     r10,PACA_IN_MCE(r13)
475         std     r11,GPR1(r1)            /* Save r1 on the stack. */
476         std     r11,0(r1)               /* make stack chain pointer */
477         mfspr   r11,SPRN_SRR0           /* Save SRR0 */
478         std     r11,_NIP(r1)
479         mfspr   r11,SPRN_SRR1           /* Save SRR1 */
480         std     r11,_MSR(r1)
481         mfspr   r11,SPRN_DAR            /* Save DAR */
482         std     r11,_DAR(r1)
483         mfspr   r11,SPRN_DSISR          /* Save DSISR */
484         std     r11,_DSISR(r1)
485         std     r9,_CCR(r1)             /* Save CR in stackframe */
486         /* Save r9 through r13 from EXMC save area to stack frame. */
487         EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
488         mfmsr   r11                     /* get MSR value */
489         ori     r11,r11,MSR_ME          /* turn on ME bit */
490         ori     r11,r11,MSR_RI          /* turn on RI bit */
491         ld      r12,PACAKBASE(r13)      /* get high part of &label */
492         LOAD_HANDLER(r12, machine_check_handle_early)
493         mtspr   SPRN_SRR0,r12
494         mtspr   SPRN_SRR1,r11
495         rfid
496         b       .       /* prevent speculative execution */
497 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
498
499 machine_check_pSeries:
500         .globl machine_check_fwnmi
501 machine_check_fwnmi:
502         HMT_MEDIUM_PPR_DISCARD
503         SET_SCRATCH0(r13)               /* save r13 */
504         EXCEPTION_PROLOG_0(PACA_EXMC)
505 machine_check_pSeries_0:
506         EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST, 0x200)
507         EXCEPTION_PROLOG_PSERIES_1(machine_check_common, EXC_STD)
508         KVM_HANDLER_SKIP(PACA_EXMC, EXC_STD, 0x200)
509
510         /* moved from 0x300 */
511 data_access_check_stab:
512         GET_PACA(r13)
513         std     r9,PACA_EXSLB+EX_R9(r13)
514         std     r10,PACA_EXSLB+EX_R10(r13)
515         mfspr   r10,SPRN_DAR
516         mfspr   r9,SPRN_DSISR
517         srdi    r10,r10,60
518         rlwimi  r10,r9,16,0x20
519 #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
520         lbz     r9,HSTATE_IN_GUEST(r13)
521         rlwimi  r10,r9,8,0x300
522 #endif
523         mfcr    r9
524         cmpwi   r10,0x2c
525         beq     do_stab_bolted_pSeries
526         mtcrf   0x80,r9
527         ld      r9,PACA_EXSLB+EX_R9(r13)
528         ld      r10,PACA_EXSLB+EX_R10(r13)
529         b       data_access_not_stab
530 do_stab_bolted_pSeries:
531         std     r11,PACA_EXSLB+EX_R11(r13)
532         std     r12,PACA_EXSLB+EX_R12(r13)
533         GET_SCRATCH0(r10)
534         std     r10,PACA_EXSLB+EX_R13(r13)
535         EXCEPTION_PROLOG_PSERIES_1(.do_stab_bolted, EXC_STD)
536
537         KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x300)
538         KVM_HANDLER_SKIP(PACA_EXSLB, EXC_STD, 0x380)
539         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x400)
540         KVM_HANDLER_PR(PACA_EXSLB, EXC_STD, 0x480)
541         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x900)
542         KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x982)
543
544 #ifdef CONFIG_PPC_DENORMALISATION
545 denorm_assist:
546 BEGIN_FTR_SECTION
547 /*
548  * To denormalise we need to move a copy of the register to itself.
549  * For POWER6 do that here for all FP regs.
550  */
551         mfmsr   r10
552         ori     r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
553         xori    r10,r10,(MSR_FE0|MSR_FE1)
554         mtmsrd  r10
555         sync
556
557 #define FMR2(n)  fmr (n), (n) ; fmr n+1, n+1
558 #define FMR4(n)  FMR2(n) ; FMR2(n+2)
559 #define FMR8(n)  FMR4(n) ; FMR4(n+4)
560 #define FMR16(n) FMR8(n) ; FMR8(n+8)
561 #define FMR32(n) FMR16(n) ; FMR16(n+16)
562         FMR32(0)
563
564 FTR_SECTION_ELSE
565 /*
566  * To denormalise we need to move a copy of the register to itself.
567  * For POWER7 do that here for the first 32 VSX registers only.
568  */
569         mfmsr   r10
570         oris    r10,r10,MSR_VSX@h
571         mtmsrd  r10
572         sync
573
574 #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
575 #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
576 #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
577 #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
578 #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
579         XVCPSGNDP32(0)
580
581 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
582
583 BEGIN_FTR_SECTION
584         b       denorm_done
585 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
586 /*
587  * To denormalise we need to move a copy of the register to itself.
588  * For POWER8 we need to do that for all 64 VSX registers
589  */
590         XVCPSGNDP32(32)
591 denorm_done:
592         mtspr   SPRN_HSRR0,r11
593         mtcrf   0x80,r9
594         ld      r9,PACA_EXGEN+EX_R9(r13)
595         RESTORE_PPR_PACA(PACA_EXGEN, r10)
596 BEGIN_FTR_SECTION
597         ld      r10,PACA_EXGEN+EX_CFAR(r13)
598         mtspr   SPRN_CFAR,r10
599 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
600         ld      r10,PACA_EXGEN+EX_R10(r13)
601         ld      r11,PACA_EXGEN+EX_R11(r13)
602         ld      r12,PACA_EXGEN+EX_R12(r13)
603         ld      r13,PACA_EXGEN+EX_R13(r13)
604         HRFID
605         b       .
606 #endif
607
608         .align  7
609         /* moved from 0xe00 */
610         STD_EXCEPTION_HV_OOL(0xe02, h_data_storage)
611         KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0xe02)
612         STD_EXCEPTION_HV_OOL(0xe22, h_instr_storage)
613         KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe22)
614         STD_EXCEPTION_HV_OOL(0xe42, emulation_assist)
615         KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe42)
616         STD_EXCEPTION_HV_OOL(0xe62, hmi_exception) /* need to flush cache ? */
617         KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe62)
618         MASKABLE_EXCEPTION_HV_OOL(0xe82, h_doorbell)
619         KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe82)
620
621         /* moved from 0xf00 */
622         STD_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
623         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf00)
624         STD_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
625         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf20)
626         STD_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
627         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf40)
628         STD_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
629         KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf60)
630         STD_EXCEPTION_HV_OOL(0xf82, facility_unavailable)
631         KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xf82)
632
633 /*
634  * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
635  * - If it was a decrementer interrupt, we bump the dec to max and and return.
636  * - If it was a doorbell we return immediately since doorbells are edge
637  *   triggered and won't automatically refire.
638  * - else we hard disable and return.
639  * This is called with r10 containing the value to OR to the paca field.
640  */
641 #define MASKED_INTERRUPT(_H)                            \
642 masked_##_H##interrupt:                                 \
643         std     r11,PACA_EXGEN+EX_R11(r13);             \
644         lbz     r11,PACAIRQHAPPENED(r13);               \
645         or      r11,r11,r10;                            \
646         stb     r11,PACAIRQHAPPENED(r13);               \
647         cmpwi   r10,PACA_IRQ_DEC;                       \
648         bne     1f;                                     \
649         lis     r10,0x7fff;                             \
650         ori     r10,r10,0xffff;                         \
651         mtspr   SPRN_DEC,r10;                           \
652         b       2f;                                     \
653 1:      cmpwi   r10,PACA_IRQ_DBELL;                     \
654         beq     2f;                                     \
655         mfspr   r10,SPRN_##_H##SRR1;                    \
656         rldicl  r10,r10,48,1; /* clear MSR_EE */        \
657         rotldi  r10,r10,16;                             \
658         mtspr   SPRN_##_H##SRR1,r10;                    \
659 2:      mtcrf   0x80,r9;                                \
660         ld      r9,PACA_EXGEN+EX_R9(r13);               \
661         ld      r10,PACA_EXGEN+EX_R10(r13);             \
662         ld      r11,PACA_EXGEN+EX_R11(r13);             \
663         GET_SCRATCH0(r13);                              \
664         ##_H##rfid;                                     \
665         b       .
666         
667         MASKED_INTERRUPT()
668         MASKED_INTERRUPT(H)
669
670 /*
671  * Called from arch_local_irq_enable when an interrupt needs
672  * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
673  * which kind of interrupt. MSR:EE is already off. We generate a
674  * stackframe like if a real interrupt had happened.
675  *
676  * Note: While MSR:EE is off, we need to make sure that _MSR
677  * in the generated frame has EE set to 1 or the exception
678  * handler will not properly re-enable them.
679  */
680 _GLOBAL(__replay_interrupt)
681         /* We are going to jump to the exception common code which
682          * will retrieve various register values from the PACA which
683          * we don't give a damn about, so we don't bother storing them.
684          */
685         mfmsr   r12
686         mflr    r11
687         mfcr    r9
688         ori     r12,r12,MSR_EE
689         cmpwi   r3,0x900
690         beq     decrementer_common
691         cmpwi   r3,0x500
692         beq     hardware_interrupt_common
693 BEGIN_FTR_SECTION
694         cmpwi   r3,0xe80
695         beq     h_doorbell_common
696 FTR_SECTION_ELSE
697         cmpwi   r3,0xa00
698         beq     doorbell_super_common
699 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
700         blr
701
702 #ifdef CONFIG_PPC_PSERIES
703 /*
704  * Vectors for the FWNMI option.  Share common code.
705  */
706         .globl system_reset_fwnmi
707       .align 7
708 system_reset_fwnmi:
709         HMT_MEDIUM_PPR_DISCARD
710         SET_SCRATCH0(r13)               /* save r13 */
711         EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
712                                  NOTEST, 0x100)
713
714 #endif /* CONFIG_PPC_PSERIES */
715
716 #ifdef __DISABLED__
717 /*
718  * This is used for when the SLB miss handler has to go virtual,
719  * which doesn't happen for now anymore but will once we re-implement
720  * dynamic VSIDs for shared page tables
721  */
722 slb_miss_user_pseries:
723         std     r10,PACA_EXGEN+EX_R10(r13)
724         std     r11,PACA_EXGEN+EX_R11(r13)
725         std     r12,PACA_EXGEN+EX_R12(r13)
726         GET_SCRATCH0(r10)
727         ld      r11,PACA_EXSLB+EX_R9(r13)
728         ld      r12,PACA_EXSLB+EX_R3(r13)
729         std     r10,PACA_EXGEN+EX_R13(r13)
730         std     r11,PACA_EXGEN+EX_R9(r13)
731         std     r12,PACA_EXGEN+EX_R3(r13)
732         clrrdi  r12,r13,32
733         mfmsr   r10
734         mfspr   r11,SRR0                        /* save SRR0 */
735         ori     r12,r12,slb_miss_user_common@l  /* virt addr of handler */
736         ori     r10,r10,MSR_IR|MSR_DR|MSR_RI
737         mtspr   SRR0,r12
738         mfspr   r12,SRR1                        /* and SRR1 */
739         mtspr   SRR1,r10
740         rfid
741         b       .                               /* prevent spec. execution */
742 #endif /* __DISABLED__ */
743
744 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
745 kvmppc_skip_interrupt:
746         /*
747          * Here all GPRs are unchanged from when the interrupt happened
748          * except for r13, which is saved in SPRG_SCRATCH0.
749          */
750         mfspr   r13, SPRN_SRR0
751         addi    r13, r13, 4
752         mtspr   SPRN_SRR0, r13
753         GET_SCRATCH0(r13)
754         rfid
755         b       .
756
757 kvmppc_skip_Hinterrupt:
758         /*
759          * Here all GPRs are unchanged from when the interrupt happened
760          * except for r13, which is saved in SPRG_SCRATCH0.
761          */
762         mfspr   r13, SPRN_HSRR0
763         addi    r13, r13, 4
764         mtspr   SPRN_HSRR0, r13
765         GET_SCRATCH0(r13)
766         hrfid
767         b       .
768 #endif
769
770 /*
771  * Code from here down to __end_handlers is invoked from the
772  * exception prologs above.  Because the prologs assemble the
773  * addresses of these handlers using the LOAD_HANDLER macro,
774  * which uses an ori instruction, these handlers must be in
775  * the first 64k of the kernel image.
776  */
777
778 /*** Common interrupt handlers ***/
779
780         STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
781
782         STD_EXCEPTION_COMMON_ASYNC(0x500, hardware_interrupt, do_IRQ)
783         STD_EXCEPTION_COMMON_ASYNC(0x900, decrementer, .timer_interrupt)
784         STD_EXCEPTION_COMMON(0x980, hdecrementer, .hdec_interrupt)
785 #ifdef CONFIG_PPC_DOORBELL
786         STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, .doorbell_exception)
787 #else
788         STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, .unknown_exception)
789 #endif
790         STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
791         STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
792         STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
793         STD_EXCEPTION_COMMON(0xe40, emulation_assist, .emulation_assist_interrupt)
794         STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception)
795 #ifdef CONFIG_PPC_DOORBELL
796         STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, .doorbell_exception)
797 #else
798         STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, .unknown_exception)
799 #endif
800         STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, .performance_monitor_exception)
801         STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
802         STD_EXCEPTION_COMMON(0x1502, denorm, .unknown_exception)
803 #ifdef CONFIG_ALTIVEC
804         STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
805 #else
806         STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
807 #endif
808 #ifdef CONFIG_CBE_RAS
809         STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
810         STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
811         STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
812 #endif /* CONFIG_CBE_RAS */
813
814         /*
815          * Relocation-on interrupts: A subset of the interrupts can be delivered
816          * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
817          * it.  Addresses are the same as the original interrupt addresses, but
818          * offset by 0xc000000000004000.
819          * It's impossible to receive interrupts below 0x300 via this mechanism.
820          * KVM: None of these traps are from the guest ; anything that escalated
821          * to HV=1 from HV=0 is delivered via real mode handlers.
822          */
823
824         /*
825          * This uses the standard macro, since the original 0x300 vector
826          * only has extra guff for STAB-based processors -- which never
827          * come here.
828          */
829         STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
830         . = 0x4380
831         .globl data_access_slb_relon_pSeries
832 data_access_slb_relon_pSeries:
833         SET_SCRATCH0(r13)
834         EXCEPTION_PROLOG_0(PACA_EXSLB)
835         EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
836         std     r3,PACA_EXSLB+EX_R3(r13)
837         mfspr   r3,SPRN_DAR
838         mfspr   r12,SPRN_SRR1
839 #ifndef CONFIG_RELOCATABLE
840         b       .slb_miss_realmode
841 #else
842         /*
843          * We can't just use a direct branch to .slb_miss_realmode
844          * because the distance from here to there depends on where
845          * the kernel ends up being put.
846          */
847         mfctr   r11
848         ld      r10,PACAKBASE(r13)
849         LOAD_HANDLER(r10, .slb_miss_realmode)
850         mtctr   r10
851         bctr
852 #endif
853
854         STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
855         . = 0x4480
856         .globl instruction_access_slb_relon_pSeries
857 instruction_access_slb_relon_pSeries:
858         SET_SCRATCH0(r13)
859         EXCEPTION_PROLOG_0(PACA_EXSLB)
860         EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
861         std     r3,PACA_EXSLB+EX_R3(r13)
862         mfspr   r3,SPRN_SRR0            /* SRR0 is faulting address */
863         mfspr   r12,SPRN_SRR1
864 #ifndef CONFIG_RELOCATABLE
865         b       .slb_miss_realmode
866 #else
867         mfctr   r11
868         ld      r10,PACAKBASE(r13)
869         LOAD_HANDLER(r10, .slb_miss_realmode)
870         mtctr   r10
871         bctr
872 #endif
873
874         . = 0x4500
875         .globl hardware_interrupt_relon_pSeries;
876         .globl hardware_interrupt_relon_hv;
877 hardware_interrupt_relon_pSeries:
878 hardware_interrupt_relon_hv:
879         BEGIN_FTR_SECTION
880                 _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
881         FTR_SECTION_ELSE
882                 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
883         ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
884         STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
885         STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
886         STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
887         MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
888         STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
889         MASKABLE_RELON_EXCEPTION_PSERIES(0x4a00, 0xa00, doorbell_super)
890         STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
891
892         . = 0x4c00
893         .globl system_call_relon_pSeries
894 system_call_relon_pSeries:
895         HMT_MEDIUM
896         SYSCALL_PSERIES_1
897         SYSCALL_PSERIES_2_DIRECT
898         SYSCALL_PSERIES_3
899
900         STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
901
902         . = 0x4e00
903         b       .       /* Can't happen, see v2.07 Book III-S section 6.5 */
904
905         . = 0x4e20
906         b       .       /* Can't happen, see v2.07 Book III-S section 6.5 */
907
908         . = 0x4e40
909 emulation_assist_relon_trampoline:
910         SET_SCRATCH0(r13)
911         EXCEPTION_PROLOG_0(PACA_EXGEN)
912         b       emulation_assist_relon_hv
913
914         . = 0x4e60
915         b       .       /* Can't happen, see v2.07 Book III-S section 6.5 */
916
917         . = 0x4e80
918 h_doorbell_relon_trampoline:
919         SET_SCRATCH0(r13)
920         EXCEPTION_PROLOG_0(PACA_EXGEN)
921         b       h_doorbell_relon_hv
922
923         . = 0x4f00
924 performance_monitor_relon_pseries_trampoline:
925         SET_SCRATCH0(r13)
926         EXCEPTION_PROLOG_0(PACA_EXGEN)
927         b       performance_monitor_relon_pSeries
928
929         . = 0x4f20
930 altivec_unavailable_relon_pseries_trampoline:
931         SET_SCRATCH0(r13)
932         EXCEPTION_PROLOG_0(PACA_EXGEN)
933         b       altivec_unavailable_relon_pSeries
934
935         . = 0x4f40
936 vsx_unavailable_relon_pseries_trampoline:
937         SET_SCRATCH0(r13)
938         EXCEPTION_PROLOG_0(PACA_EXGEN)
939         b       vsx_unavailable_relon_pSeries
940
941         . = 0x4f60
942 facility_unavailable_relon_trampoline:
943         SET_SCRATCH0(r13)
944         EXCEPTION_PROLOG_0(PACA_EXGEN)
945         b       facility_unavailable_relon_pSeries
946
947         . = 0x4f80
948 hv_facility_unavailable_relon_trampoline:
949         SET_SCRATCH0(r13)
950         EXCEPTION_PROLOG_0(PACA_EXGEN)
951         b       hv_facility_unavailable_relon_hv
952
953         STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
954 #ifdef CONFIG_PPC_DENORMALISATION
955         . = 0x5500
956         b       denorm_exception_hv
957 #endif
958         STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
959
960         /* Other future vectors */
961         .align  7
962         .globl  __end_interrupts
963 __end_interrupts:
964
965         .align  7
966 system_call_entry_direct:
967 #if defined(CONFIG_RELOCATABLE)
968         /* The first level prologue may have used LR to get here, saving
969          * orig in r10.  To save hacking/ifdeffing common code, restore here.
970          */
971         mtlr    r10
972 #endif
973 system_call_entry:
974         b       system_call_common
975
976 ppc64_runlatch_on_trampoline:
977         b       .__ppc64_runlatch_on
978
979 /*
980  * Here we have detected that the kernel stack pointer is bad.
981  * R9 contains the saved CR, r13 points to the paca,
982  * r10 contains the (bad) kernel stack pointer,
983  * r11 and r12 contain the saved SRR0 and SRR1.
984  * We switch to using an emergency stack, save the registers there,
985  * and call kernel_bad_stack(), which panics.
986  */
987 bad_stack:
988         ld      r1,PACAEMERGSP(r13)
989         subi    r1,r1,64+INT_FRAME_SIZE
990         std     r9,_CCR(r1)
991         std     r10,GPR1(r1)
992         std     r11,_NIP(r1)
993         std     r12,_MSR(r1)
994         mfspr   r11,SPRN_DAR
995         mfspr   r12,SPRN_DSISR
996         std     r11,_DAR(r1)
997         std     r12,_DSISR(r1)
998         mflr    r10
999         mfctr   r11
1000         mfxer   r12
1001         std     r10,_LINK(r1)
1002         std     r11,_CTR(r1)
1003         std     r12,_XER(r1)
1004         SAVE_GPR(0,r1)
1005         SAVE_GPR(2,r1)
1006         ld      r10,EX_R3(r3)
1007         std     r10,GPR3(r1)
1008         SAVE_GPR(4,r1)
1009         SAVE_4GPRS(5,r1)
1010         ld      r9,EX_R9(r3)
1011         ld      r10,EX_R10(r3)
1012         SAVE_2GPRS(9,r1)
1013         ld      r9,EX_R11(r3)
1014         ld      r10,EX_R12(r3)
1015         ld      r11,EX_R13(r3)
1016         std     r9,GPR11(r1)
1017         std     r10,GPR12(r1)
1018         std     r11,GPR13(r1)
1019 BEGIN_FTR_SECTION
1020         ld      r10,EX_CFAR(r3)
1021         std     r10,ORIG_GPR3(r1)
1022 END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1023         SAVE_8GPRS(14,r1)
1024         SAVE_10GPRS(22,r1)
1025         lhz     r12,PACA_TRAP_SAVE(r13)
1026         std     r12,_TRAP(r1)
1027         addi    r11,r1,INT_FRAME_SIZE
1028         std     r11,0(r1)
1029         li      r12,0
1030         std     r12,0(r11)
1031         ld      r2,PACATOC(r13)
1032         ld      r11,exception_marker@toc(r2)
1033         std     r12,RESULT(r1)
1034         std     r11,STACK_FRAME_OVERHEAD-16(r1)
1035 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
1036         bl      .kernel_bad_stack
1037         b       1b
1038
1039 /*
1040  * Here r13 points to the paca, r9 contains the saved CR,
1041  * SRR0 and SRR1 are saved in r11 and r12,
1042  * r9 - r13 are saved in paca->exgen.
1043  */
1044         .align  7
1045         .globl data_access_common
1046 data_access_common:
1047         mfspr   r10,SPRN_DAR
1048         std     r10,PACA_EXGEN+EX_DAR(r13)
1049         mfspr   r10,SPRN_DSISR
1050         stw     r10,PACA_EXGEN+EX_DSISR(r13)
1051         EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
1052         DISABLE_INTS
1053         ld      r12,_MSR(r1)
1054         ld      r3,PACA_EXGEN+EX_DAR(r13)
1055         lwz     r4,PACA_EXGEN+EX_DSISR(r13)
1056         li      r5,0x300
1057         b       .do_hash_page           /* Try to handle as hpte fault */
1058
1059         .align  7
1060         .globl  h_data_storage_common
1061 h_data_storage_common:
1062         mfspr   r10,SPRN_HDAR
1063         std     r10,PACA_EXGEN+EX_DAR(r13)
1064         mfspr   r10,SPRN_HDSISR
1065         stw     r10,PACA_EXGEN+EX_DSISR(r13)
1066         EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
1067         bl      .save_nvgprs
1068         DISABLE_INTS
1069         addi    r3,r1,STACK_FRAME_OVERHEAD
1070         bl      .unknown_exception
1071         b       .ret_from_except
1072
1073         .align  7
1074         .globl instruction_access_common
1075 instruction_access_common:
1076         EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
1077         DISABLE_INTS
1078         ld      r12,_MSR(r1)
1079         ld      r3,_NIP(r1)
1080         andis.  r4,r12,0x5820
1081         li      r5,0x400
1082         b       .do_hash_page           /* Try to handle as hpte fault */
1083
1084         STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception)
1085
1086 /*
1087  * Here is the common SLB miss user that is used when going to virtual
1088  * mode for SLB misses, that is currently not used
1089  */
1090 #ifdef __DISABLED__
1091         .align  7
1092         .globl  slb_miss_user_common
1093 slb_miss_user_common:
1094         mflr    r10
1095         std     r3,PACA_EXGEN+EX_DAR(r13)
1096         stw     r9,PACA_EXGEN+EX_CCR(r13)
1097         std     r10,PACA_EXGEN+EX_LR(r13)
1098         std     r11,PACA_EXGEN+EX_SRR0(r13)
1099         bl      .slb_allocate_user
1100
1101         ld      r10,PACA_EXGEN+EX_LR(r13)
1102         ld      r3,PACA_EXGEN+EX_R3(r13)
1103         lwz     r9,PACA_EXGEN+EX_CCR(r13)
1104         ld      r11,PACA_EXGEN+EX_SRR0(r13)
1105         mtlr    r10
1106         beq-    slb_miss_fault
1107
1108         andi.   r10,r12,MSR_RI          /* check for unrecoverable exception */
1109         beq-    unrecov_user_slb
1110         mfmsr   r10
1111
1112 .machine push
1113 .machine "power4"
1114         mtcrf   0x80,r9
1115 .machine pop
1116
1117         clrrdi  r10,r10,2               /* clear RI before setting SRR0/1 */
1118         mtmsrd  r10,1
1119
1120         mtspr   SRR0,r11
1121         mtspr   SRR1,r12
1122
1123         ld      r9,PACA_EXGEN+EX_R9(r13)
1124         ld      r10,PACA_EXGEN+EX_R10(r13)
1125         ld      r11,PACA_EXGEN+EX_R11(r13)
1126         ld      r12,PACA_EXGEN+EX_R12(r13)
1127         ld      r13,PACA_EXGEN+EX_R13(r13)
1128         rfid
1129         b       .
1130
1131 slb_miss_fault:
1132         EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1133         ld      r4,PACA_EXGEN+EX_DAR(r13)
1134         li      r5,0
1135         std     r4,_DAR(r1)
1136         std     r5,_DSISR(r1)
1137         b       handle_page_fault
1138
1139 unrecov_user_slb:
1140         EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1141         DISABLE_INTS
1142         bl      .save_nvgprs
1143 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
1144         bl      .unrecoverable_exception
1145         b       1b
1146
1147 #endif /* __DISABLED__ */
1148
1149
1150         /*
1151          * Machine check is different because we use a different
1152          * save area: PACA_EXMC instead of PACA_EXGEN.
1153          */
1154         .align  7
1155         .globl machine_check_common
1156 machine_check_common:
1157
1158         mfspr   r10,SPRN_DAR
1159         std     r10,PACA_EXGEN+EX_DAR(r13)
1160         mfspr   r10,SPRN_DSISR
1161         stw     r10,PACA_EXGEN+EX_DSISR(r13)
1162         EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
1163         FINISH_NAP
1164         DISABLE_INTS
1165         ld      r3,PACA_EXGEN+EX_DAR(r13)
1166         lwz     r4,PACA_EXGEN+EX_DSISR(r13)
1167         std     r3,_DAR(r1)
1168         std     r4,_DSISR(r1)
1169         bl      .save_nvgprs
1170         addi    r3,r1,STACK_FRAME_OVERHEAD
1171         bl      .machine_check_exception
1172         b       .ret_from_except
1173
1174         .align  7
1175         .globl alignment_common
1176 alignment_common:
1177         mfspr   r10,SPRN_DAR
1178         std     r10,PACA_EXGEN+EX_DAR(r13)
1179         mfspr   r10,SPRN_DSISR
1180         stw     r10,PACA_EXGEN+EX_DSISR(r13)
1181         EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1182         ld      r3,PACA_EXGEN+EX_DAR(r13)
1183         lwz     r4,PACA_EXGEN+EX_DSISR(r13)
1184         std     r3,_DAR(r1)
1185         std     r4,_DSISR(r1)
1186         bl      .save_nvgprs
1187         DISABLE_INTS
1188         addi    r3,r1,STACK_FRAME_OVERHEAD
1189         bl      .alignment_exception
1190         b       .ret_from_except
1191
1192         .align  7
1193         .globl program_check_common
1194 program_check_common:
1195         EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1196         bl      .save_nvgprs
1197         DISABLE_INTS
1198         addi    r3,r1,STACK_FRAME_OVERHEAD
1199         bl      .program_check_exception
1200         b       .ret_from_except
1201
1202         .align  7
1203         .globl fp_unavailable_common
1204 fp_unavailable_common:
1205         EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1206         bne     1f                      /* if from user, just load it up */
1207         bl      .save_nvgprs
1208         DISABLE_INTS
1209         addi    r3,r1,STACK_FRAME_OVERHEAD
1210         bl      .kernel_fp_unavailable_exception
1211         BUG_OPCODE
1212 1:
1213 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1214 BEGIN_FTR_SECTION
1215         /* Test if 2 TM state bits are zero.  If non-zero (ie. userspace was in
1216          * transaction), go do TM stuff
1217          */
1218         rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1219         bne-    2f
1220 END_FTR_SECTION_IFSET(CPU_FTR_TM)
1221 #endif
1222         bl      .load_up_fpu
1223         b       fast_exception_return
1224 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1225 2:      /* User process was in a transaction */
1226         bl      .save_nvgprs
1227         DISABLE_INTS
1228         addi    r3,r1,STACK_FRAME_OVERHEAD
1229         bl      .fp_unavailable_tm
1230         b       .ret_from_except
1231 #endif
1232         .align  7
1233         .globl altivec_unavailable_common
1234 altivec_unavailable_common:
1235         EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1236 #ifdef CONFIG_ALTIVEC
1237 BEGIN_FTR_SECTION
1238         beq     1f
1239 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1240   BEGIN_FTR_SECTION_NESTED(69)
1241         /* Test if 2 TM state bits are zero.  If non-zero (ie. userspace was in
1242          * transaction), go do TM stuff
1243          */
1244         rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1245         bne-    2f
1246   END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1247 #endif
1248         bl      .load_up_altivec
1249         b       fast_exception_return
1250 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1251 2:      /* User process was in a transaction */
1252         bl      .save_nvgprs
1253         DISABLE_INTS
1254         addi    r3,r1,STACK_FRAME_OVERHEAD
1255         bl      .altivec_unavailable_tm
1256         b       .ret_from_except
1257 #endif
1258 1:
1259 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1260 #endif
1261         bl      .save_nvgprs
1262         DISABLE_INTS
1263         addi    r3,r1,STACK_FRAME_OVERHEAD
1264         bl      .altivec_unavailable_exception
1265         b       .ret_from_except
1266
1267         .align  7
1268         .globl vsx_unavailable_common
1269 vsx_unavailable_common:
1270         EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1271 #ifdef CONFIG_VSX
1272 BEGIN_FTR_SECTION
1273         beq     1f
1274 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1275   BEGIN_FTR_SECTION_NESTED(69)
1276         /* Test if 2 TM state bits are zero.  If non-zero (ie. userspace was in
1277          * transaction), go do TM stuff
1278          */
1279         rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
1280         bne-    2f
1281   END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
1282 #endif
1283         b       .load_up_vsx
1284 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1285 2:      /* User process was in a transaction */
1286         bl      .save_nvgprs
1287         DISABLE_INTS
1288         addi    r3,r1,STACK_FRAME_OVERHEAD
1289         bl      .vsx_unavailable_tm
1290         b       .ret_from_except
1291 #endif
1292 1:
1293 END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1294 #endif
1295         bl      .save_nvgprs
1296         DISABLE_INTS
1297         addi    r3,r1,STACK_FRAME_OVERHEAD
1298         bl      .vsx_unavailable_exception
1299         b       .ret_from_except
1300
1301         STD_EXCEPTION_COMMON(0xf60, facility_unavailable, .facility_unavailable_exception)
1302         STD_EXCEPTION_COMMON(0xf80, hv_facility_unavailable, .facility_unavailable_exception)
1303
1304         .align  7
1305         .globl  __end_handlers
1306 __end_handlers:
1307
1308         /* Equivalents to the above handlers for relocation-on interrupt vectors */
1309         STD_RELON_EXCEPTION_HV_OOL(0xe40, emulation_assist)
1310         MASKABLE_RELON_EXCEPTION_HV_OOL(0xe80, h_doorbell)
1311
1312         STD_RELON_EXCEPTION_PSERIES_OOL(0xf00, performance_monitor)
1313         STD_RELON_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
1314         STD_RELON_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
1315         STD_RELON_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
1316         STD_RELON_EXCEPTION_HV_OOL(0xf80, hv_facility_unavailable)
1317
1318 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
1319 /*
1320  * Data area reserved for FWNMI option.
1321  * This address (0x7000) is fixed by the RPA.
1322  */
1323         .= 0x7000
1324         .globl fwnmi_data_area
1325 fwnmi_data_area:
1326
1327         /* pseries and powernv need to keep the whole page from
1328          * 0x7000 to 0x8000 free for use by the firmware
1329          */
1330         . = 0x8000
1331 #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
1332
1333 /* Space for CPU0's segment table */
1334         .balign 4096
1335         .globl initial_stab
1336 initial_stab:
1337         .space  4096
1338
1339 #ifdef CONFIG_PPC_POWERNV
1340 _GLOBAL(opal_mc_secondary_handler)
1341         HMT_MEDIUM_PPR_DISCARD
1342         SET_SCRATCH0(r13)
1343         GET_PACA(r13)
1344         clrldi  r3,r3,2
1345         tovirt(r3,r3)
1346         std     r3,PACA_OPAL_MC_EVT(r13)
1347         ld      r13,OPAL_MC_SRR0(r3)
1348         mtspr   SPRN_SRR0,r13
1349         ld      r13,OPAL_MC_SRR1(r3)
1350         mtspr   SPRN_SRR1,r13
1351         ld      r3,OPAL_MC_GPR3(r3)
1352         GET_SCRATCH0(r13)
1353         b       machine_check_pSeries
1354 #endif /* CONFIG_PPC_POWERNV */
1355
1356
1357 #define MACHINE_CHECK_HANDLER_WINDUP                    \
1358         /* Clear MSR_RI before setting SRR0 and SRR1. */\
1359         li      r0,MSR_RI;                              \
1360         mfmsr   r9;             /* get MSR value */     \
1361         andc    r9,r9,r0;                               \
1362         mtmsrd  r9,1;           /* Clear MSR_RI */      \
1363         /* Move original SRR0 and SRR1 into the respective regs */      \
1364         ld      r9,_MSR(r1);                            \
1365         mtspr   SPRN_SRR1,r9;                           \
1366         ld      r3,_NIP(r1);                            \
1367         mtspr   SPRN_SRR0,r3;                           \
1368         ld      r9,_CTR(r1);                            \
1369         mtctr   r9;                                     \
1370         ld      r9,_XER(r1);                            \
1371         mtxer   r9;                                     \
1372         ld      r9,_LINK(r1);                           \
1373         mtlr    r9;                                     \
1374         REST_GPR(0, r1);                                \
1375         REST_8GPRS(2, r1);                              \
1376         REST_GPR(10, r1);                               \
1377         ld      r11,_CCR(r1);                           \
1378         mtcr    r11;                                    \
1379         /* Decrement paca->in_mce. */                   \
1380         lhz     r12,PACA_IN_MCE(r13);                   \
1381         subi    r12,r12,1;                              \
1382         sth     r12,PACA_IN_MCE(r13);                   \
1383         REST_GPR(11, r1);                               \
1384         REST_2GPRS(12, r1);                             \
1385         /* restore original r1. */                      \
1386         ld      r1,GPR1(r1)
1387
1388         /*
1389          * Handle machine check early in real mode. We come here with
1390          * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
1391          */
1392         .align  7
1393         .globl machine_check_handle_early
1394 machine_check_handle_early:
1395         std     r0,GPR0(r1)     /* Save r0 */
1396         EXCEPTION_PROLOG_COMMON_3(0x200)
1397         bl      .save_nvgprs
1398         addi    r3,r1,STACK_FRAME_OVERHEAD
1399         bl      .machine_check_early
1400         ld      r12,_MSR(r1)
1401 #ifdef  CONFIG_PPC_P7_NAP
1402         /*
1403          * Check if thread was in power saving mode. We come here when any
1404          * of the following is true:
1405          * a. thread wasn't in power saving mode
1406          * b. thread was in power saving mode with no state loss or
1407          *    supervisor state loss
1408          *
1409          * Go back to nap again if (b) is true.
1410          */
1411         rlwinm. r11,r12,47-31,30,31     /* Was it in power saving mode? */
1412         beq     4f                      /* No, it wasn;t */
1413         /* Thread was in power saving mode. Go back to nap again. */
1414         cmpwi   r11,2
1415         bne     3f
1416         /* Supervisor state loss */
1417         li      r0,1
1418         stb     r0,PACA_NAPSTATELOST(r13)
1419 3:      bl      .machine_check_queue_event
1420         MACHINE_CHECK_HANDLER_WINDUP
1421         GET_PACA(r13)
1422         ld      r1,PACAR1(r13)
1423         b       .power7_enter_nap_mode
1424 4:
1425 #endif
1426         /*
1427          * Check if we are coming from hypervisor userspace. If yes then we
1428          * continue in host kernel in V mode to deliver the MC event.
1429          */
1430         rldicl. r11,r12,4,63            /* See if MC hit while in HV mode. */
1431         beq     5f
1432         andi.   r11,r12,MSR_PR          /* See if coming from user. */
1433         bne     9f                      /* continue in V mode if we are. */
1434
1435 5:
1436 #ifdef CONFIG_KVM_BOOK3S_64_HV
1437         /*
1438          * We are coming from kernel context. Check if we are coming from
1439          * guest. if yes, then we can continue. We will fall through
1440          * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
1441          */
1442         lbz     r11,HSTATE_IN_GUEST(r13)
1443         cmpwi   r11,0                   /* Check if coming from guest */
1444         bne     9f                      /* continue if we are. */
1445 #endif
1446         /*
1447          * At this point we are not sure about what context we come from.
1448          * Queue up the MCE event and return from the interrupt.
1449          * But before that, check if this is an un-recoverable exception.
1450          * If yes, then stay on emergency stack and panic.
1451          */
1452         andi.   r11,r12,MSR_RI
1453         bne     2f
1454 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
1455         bl      .unrecoverable_exception
1456         b       1b
1457 2:
1458         /*
1459          * Return from MC interrupt.
1460          * Queue up the MCE event so that we can log it later, while
1461          * returning from kernel or opal call.
1462          */
1463         bl      .machine_check_queue_event
1464         MACHINE_CHECK_HANDLER_WINDUP
1465         rfid
1466 9:
1467         /* Deliver the machine check to host kernel in V mode. */
1468         MACHINE_CHECK_HANDLER_WINDUP
1469         b       machine_check_pSeries
1470
1471 /*
1472  * r13 points to the PACA, r9 contains the saved CR,
1473  * r12 contain the saved SRR1, SRR0 is still ready for return
1474  * r3 has the faulting address
1475  * r9 - r13 are saved in paca->exslb.
1476  * r3 is saved in paca->slb_r3
1477  * We assume we aren't going to take any exceptions during this procedure.
1478  */
1479 _GLOBAL(slb_miss_realmode)
1480         mflr    r10
1481 #ifdef CONFIG_RELOCATABLE
1482         mtctr   r11
1483 #endif
1484
1485         stw     r9,PACA_EXSLB+EX_CCR(r13)       /* save CR in exc. frame */
1486         std     r10,PACA_EXSLB+EX_LR(r13)       /* save LR */
1487
1488         bl      .slb_allocate_realmode
1489
1490         /* All done -- return from exception. */
1491
1492         ld      r10,PACA_EXSLB+EX_LR(r13)
1493         ld      r3,PACA_EXSLB+EX_R3(r13)
1494         lwz     r9,PACA_EXSLB+EX_CCR(r13)       /* get saved CR */
1495
1496         mtlr    r10
1497
1498         andi.   r10,r12,MSR_RI  /* check for unrecoverable exception */
1499         beq-    2f
1500
1501 .machine        push
1502 .machine        "power4"
1503         mtcrf   0x80,r9
1504         mtcrf   0x01,r9         /* slb_allocate uses cr0 and cr7 */
1505 .machine        pop
1506
1507         RESTORE_PPR_PACA(PACA_EXSLB, r9)
1508         ld      r9,PACA_EXSLB+EX_R9(r13)
1509         ld      r10,PACA_EXSLB+EX_R10(r13)
1510         ld      r11,PACA_EXSLB+EX_R11(r13)
1511         ld      r12,PACA_EXSLB+EX_R12(r13)
1512         ld      r13,PACA_EXSLB+EX_R13(r13)
1513         rfid
1514         b       .       /* prevent speculative execution */
1515
1516 2:      mfspr   r11,SPRN_SRR0
1517         ld      r10,PACAKBASE(r13)
1518         LOAD_HANDLER(r10,unrecov_slb)
1519         mtspr   SPRN_SRR0,r10
1520         ld      r10,PACAKMSR(r13)
1521         mtspr   SPRN_SRR1,r10
1522         rfid
1523         b       .
1524
1525 unrecov_slb:
1526         EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1527         DISABLE_INTS
1528         bl      .save_nvgprs
1529 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
1530         bl      .unrecoverable_exception
1531         b       1b
1532
1533
1534 #ifdef CONFIG_PPC_970_NAP
1535 power4_fixup_nap:
1536         andc    r9,r9,r10
1537         std     r9,TI_LOCAL_FLAGS(r11)
1538         ld      r10,_LINK(r1)           /* make idle task do the */
1539         std     r10,_NIP(r1)            /* equivalent of a blr */
1540         blr
1541 #endif
1542
1543 /*
1544  * Hash table stuff
1545  */
1546         .align  7
1547 _STATIC(do_hash_page)
1548         std     r3,_DAR(r1)
1549         std     r4,_DSISR(r1)
1550
1551         andis.  r0,r4,0xa410            /* weird error? */
1552         bne-    handle_page_fault       /* if not, try to insert a HPTE */
1553         andis.  r0,r4,DSISR_DABRMATCH@h
1554         bne-    handle_dabr_fault
1555
1556 BEGIN_FTR_SECTION
1557         andis.  r0,r4,0x0020            /* Is it a segment table fault? */
1558         bne-    do_ste_alloc            /* If so handle it */
1559 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
1560
1561         CURRENT_THREAD_INFO(r11, r1)
1562         lwz     r0,TI_PREEMPT(r11)      /* If we're in an "NMI" */
1563         andis.  r0,r0,NMI_MASK@h        /* (i.e. an irq when soft-disabled) */
1564         bne     77f                     /* then don't call hash_page now */
1565         /*
1566          * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1567          * accessing a userspace segment (even from the kernel). We assume
1568          * kernel addresses always have the high bit set.
1569          */
1570         rlwinm  r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1571         rotldi  r0,r3,15                /* Move high bit into MSR_PR posn */
1572         orc     r0,r12,r0               /* MSR_PR | ~high_bit */
1573         rlwimi  r4,r0,32-13,30,30       /* becomes _PAGE_USER access bit */
1574         ori     r4,r4,1                 /* add _PAGE_PRESENT */
1575         rlwimi  r4,r5,22+2,31-2,31-2    /* Set _PAGE_EXEC if trap is 0x400 */
1576
1577         /*
1578          * r3 contains the faulting address
1579          * r4 contains the required access permissions
1580          * r5 contains the trap number
1581          *
1582          * at return r3 = 0 for success, 1 for page fault, negative for error
1583          */
1584         bl      .hash_page              /* build HPTE if possible */
1585         cmpdi   r3,0                    /* see if hash_page succeeded */
1586
1587         /* Success */
1588         beq     fast_exc_return_irq     /* Return from exception on success */
1589
1590         /* Error */
1591         blt-    13f
1592
1593 /* Here we have a page fault that hash_page can't handle. */
1594 handle_page_fault:
1595 11:     ld      r4,_DAR(r1)
1596         ld      r5,_DSISR(r1)
1597         addi    r3,r1,STACK_FRAME_OVERHEAD
1598         bl      .do_page_fault
1599         cmpdi   r3,0
1600         beq+    12f
1601         bl      .save_nvgprs
1602         mr      r5,r3
1603         addi    r3,r1,STACK_FRAME_OVERHEAD
1604         lwz     r4,_DAR(r1)
1605         bl      .bad_page_fault
1606         b       .ret_from_except
1607
1608 /* We have a data breakpoint exception - handle it */
1609 handle_dabr_fault:
1610         bl      .save_nvgprs
1611         ld      r4,_DAR(r1)
1612         ld      r5,_DSISR(r1)
1613         addi    r3,r1,STACK_FRAME_OVERHEAD
1614         bl      .do_break
1615 12:     b       .ret_from_except_lite
1616
1617
1618 /* We have a page fault that hash_page could handle but HV refused
1619  * the PTE insertion
1620  */
1621 13:     bl      .save_nvgprs
1622         mr      r5,r3
1623         addi    r3,r1,STACK_FRAME_OVERHEAD
1624         ld      r4,_DAR(r1)
1625         bl      .low_hash_fault
1626         b       .ret_from_except
1627
1628 /*
1629  * We come here as a result of a DSI at a point where we don't want
1630  * to call hash_page, such as when we are accessing memory (possibly
1631  * user memory) inside a PMU interrupt that occurred while interrupts
1632  * were soft-disabled.  We want to invoke the exception handler for
1633  * the access, or panic if there isn't a handler.
1634  */
1635 77:     bl      .save_nvgprs
1636         mr      r4,r3
1637         addi    r3,r1,STACK_FRAME_OVERHEAD
1638         li      r5,SIGSEGV
1639         bl      .bad_page_fault
1640         b       .ret_from_except
1641
1642         /* here we have a segment miss */
1643 do_ste_alloc:
1644         bl      .ste_allocate           /* try to insert stab entry */
1645         cmpdi   r3,0
1646         bne-    handle_page_fault
1647         b       fast_exception_return
1648
1649 /*
1650  * r13 points to the PACA, r9 contains the saved CR,
1651  * r11 and r12 contain the saved SRR0 and SRR1.
1652  * r9 - r13 are saved in paca->exslb.
1653  * We assume we aren't going to take any exceptions during this procedure.
1654  * We assume (DAR >> 60) == 0xc.
1655  */
1656         .align  7
1657 _GLOBAL(do_stab_bolted)
1658         stw     r9,PACA_EXSLB+EX_CCR(r13)       /* save CR in exc. frame */
1659         std     r11,PACA_EXSLB+EX_SRR0(r13)     /* save SRR0 in exc. frame */
1660         mfspr   r11,SPRN_DAR                    /* ea */
1661
1662         /*
1663          * check for bad kernel/user address
1664          * (ea & ~REGION_MASK) >= PGTABLE_RANGE
1665          */
1666         rldicr. r9,r11,4,(63 - 46 - 4)
1667         li      r9,0    /* VSID = 0 for bad address */
1668         bne-    0f
1669
1670         /*
1671          * Calculate VSID:
1672          * This is the kernel vsid, we take the top for context from
1673          * the range. context = (MAX_USER_CONTEXT) + ((ea >> 60) - 0xc) + 1
1674          * Here we know that (ea >> 60) == 0xc
1675          */
1676         lis     r9,(MAX_USER_CONTEXT + 1)@ha
1677         addi    r9,r9,(MAX_USER_CONTEXT + 1)@l
1678
1679         srdi    r10,r11,SID_SHIFT
1680         rldimi  r10,r9,ESID_BITS,0 /* proto vsid */
1681         ASM_VSID_SCRAMBLE(r10, r9, 256M)
1682         rldic   r9,r10,12,16    /* r9 = vsid << 12 */
1683
1684 0:
1685         /* Hash to the primary group */
1686         ld      r10,PACASTABVIRT(r13)
1687         srdi    r11,r11,SID_SHIFT
1688         rldimi  r10,r11,7,52    /* r10 = first ste of the group */
1689
1690         /* Search the primary group for a free entry */
1691 1:      ld      r11,0(r10)      /* Test valid bit of the current ste    */
1692         andi.   r11,r11,0x80
1693         beq     2f
1694         addi    r10,r10,16
1695         andi.   r11,r10,0x70
1696         bne     1b
1697
1698         /* Stick for only searching the primary group for now.          */
1699         /* At least for now, we use a very simple random castout scheme */
1700         /* Use the TB as a random number ;  OR in 1 to avoid entry 0    */
1701         mftb    r11
1702         rldic   r11,r11,4,57    /* r11 = (r11 << 4) & 0x70 */
1703         ori     r11,r11,0x10
1704
1705         /* r10 currently points to an ste one past the group of interest */
1706         /* make it point to the randomly selected entry                 */
1707         subi    r10,r10,128
1708         or      r10,r10,r11     /* r10 is the entry to invalidate       */
1709
1710         isync                   /* mark the entry invalid               */
1711         ld      r11,0(r10)
1712         rldicl  r11,r11,56,1    /* clear the valid bit */
1713         rotldi  r11,r11,8
1714         std     r11,0(r10)
1715         sync
1716
1717         clrrdi  r11,r11,28      /* Get the esid part of the ste         */
1718         slbie   r11
1719
1720 2:      std     r9,8(r10)       /* Store the vsid part of the ste       */
1721         eieio
1722
1723         mfspr   r11,SPRN_DAR            /* Get the new esid                     */
1724         clrrdi  r11,r11,28      /* Permits a full 32b of ESID           */
1725         ori     r11,r11,0x90    /* Turn on valid and kp                 */
1726         std     r11,0(r10)      /* Put new entry back into the stab     */
1727
1728         sync
1729
1730         /* All done -- return from exception. */
1731         lwz     r9,PACA_EXSLB+EX_CCR(r13)       /* get saved CR */
1732         ld      r11,PACA_EXSLB+EX_SRR0(r13)     /* get saved SRR0 */
1733
1734         andi.   r10,r12,MSR_RI
1735         beq-    unrecov_slb
1736
1737         mtcrf   0x80,r9                 /* restore CR */
1738
1739         mfmsr   r10
1740         clrrdi  r10,r10,2
1741         mtmsrd  r10,1
1742
1743         mtspr   SPRN_SRR0,r11
1744         mtspr   SPRN_SRR1,r12
1745         ld      r9,PACA_EXSLB+EX_R9(r13)
1746         ld      r10,PACA_EXSLB+EX_R10(r13)
1747         ld      r11,PACA_EXSLB+EX_R11(r13)
1748         ld      r12,PACA_EXSLB+EX_R12(r13)
1749         ld      r13,PACA_EXSLB+EX_R13(r13)
1750         rfid
1751         b       .       /* prevent speculative execution */