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