]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/powerpc/kernel/exceptions-64s.S
powerpc: Macros for saving/restore PPR
[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) ; \
77 mtlr 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 blr ;
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:
107 HMT_MEDIUM;
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
129#ifdef CONFIG_KVM_BOOK3S_64_HV
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 */
156 b machine_check_pSeries
0ebc4cda
BH
157
158 . = 0x300
159 .globl data_access_pSeries
160data_access_pSeries:
161 HMT_MEDIUM
673b189a 162 SET_SCRATCH0(r13)
0ebc4cda 163BEGIN_FTR_SECTION
b01c8b54
PM
164 b data_access_check_stab
165data_access_not_stab:
166END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
b01c8b54 167 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common, EXC_STD,
697d3899 168 KVMTEST, 0x300)
0ebc4cda
BH
169
170 . = 0x380
171 .globl data_access_slb_pSeries
172data_access_slb_pSeries:
173 HMT_MEDIUM
673b189a 174 SET_SCRATCH0(r13)
697d3899 175 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST, 0x380)
0ebc4cda
BH
176 std r3,PACA_EXSLB+EX_R3(r13)
177 mfspr r3,SPRN_DAR
0ebc4cda
BH
178#ifdef __DISABLED__
179 /* Keep that around for when we re-implement dynamic VSIDs */
180 cmpdi r3,0
181 bge slb_miss_user_pseries
182#endif /* __DISABLED__ */
b01c8b54 183 mfspr r12,SPRN_SRR1
0ebc4cda
BH
184#ifndef CONFIG_RELOCATABLE
185 b .slb_miss_realmode
186#else
187 /*
188 * We can't just use a direct branch to .slb_miss_realmode
189 * because the distance from here to there depends on where
190 * the kernel ends up being put.
191 */
192 mfctr r11
193 ld r10,PACAKBASE(r13)
194 LOAD_HANDLER(r10, .slb_miss_realmode)
195 mtctr r10
196 bctr
197#endif
198
b3e6b5df 199 STD_EXCEPTION_PSERIES(0x400, 0x400, instruction_access)
0ebc4cda
BH
200
201 . = 0x480
202 .globl instruction_access_slb_pSeries
203instruction_access_slb_pSeries:
204 HMT_MEDIUM
673b189a 205 SET_SCRATCH0(r13)
de56a948 206 EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
0ebc4cda
BH
207 std r3,PACA_EXSLB+EX_R3(r13)
208 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
0ebc4cda
BH
209#ifdef __DISABLED__
210 /* Keep that around for when we re-implement dynamic VSIDs */
211 cmpdi r3,0
212 bge slb_miss_user_pseries
213#endif /* __DISABLED__ */
b01c8b54 214 mfspr r12,SPRN_SRR1
0ebc4cda
BH
215#ifndef CONFIG_RELOCATABLE
216 b .slb_miss_realmode
217#else
218 mfctr r11
219 ld r10,PACAKBASE(r13)
220 LOAD_HANDLER(r10, .slb_miss_realmode)
221 mtctr r10
222 bctr
223#endif
224
b3e6b5df
BH
225 /* We open code these as we can't have a ". = x" (even with
226 * x = "." within a feature section
227 */
a5d4f3ad 228 . = 0x500;
b3e6b5df
BH
229 .globl hardware_interrupt_pSeries;
230 .globl hardware_interrupt_hv;
a5d4f3ad 231hardware_interrupt_pSeries:
b3e6b5df 232hardware_interrupt_hv:
a5d4f3ad 233 BEGIN_FTR_SECTION
b01c8b54
PM
234 _MASKABLE_EXCEPTION_PSERIES(0x502, hardware_interrupt,
235 EXC_HV, SOFTEN_TEST_HV)
236 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x502)
de56a948
PM
237 FTR_SECTION_ELSE
238 _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt,
9e368f29 239 EXC_STD, SOFTEN_TEST_HV_201)
de56a948 240 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0x500)
969391c5 241 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
a5d4f3ad 242
b3e6b5df 243 STD_EXCEPTION_PSERIES(0x600, 0x600, alignment)
de56a948 244 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x600)
b01c8b54 245
b3e6b5df 246 STD_EXCEPTION_PSERIES(0x700, 0x700, program_check)
de56a948 247 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x700)
b01c8b54 248
b3e6b5df 249 STD_EXCEPTION_PSERIES(0x800, 0x800, fp_unavailable)
de56a948 250 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x800)
a5d4f3ad 251
b3e6b5df 252 MASKABLE_EXCEPTION_PSERIES(0x900, 0x900, decrementer)
dabe859e 253 STD_EXCEPTION_HV(0x980, 0x982, hdecrementer)
a5d4f3ad 254
1dbdafec 255 MASKABLE_EXCEPTION_PSERIES(0xa00, 0xa00, doorbell_super)
de56a948 256 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xa00)
b01c8b54 257
b3e6b5df 258 STD_EXCEPTION_PSERIES(0xb00, 0xb00, trap_0b)
de56a948 259 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xb00)
0ebc4cda
BH
260
261 . = 0xc00
262 .globl system_call_pSeries
263system_call_pSeries:
264 HMT_MEDIUM
b01c8b54
PM
265#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
266 SET_SCRATCH0(r13)
267 GET_PACA(r13)
268 std r9,PACA_EXGEN+EX_R9(r13)
269 std r10,PACA_EXGEN+EX_R10(r13)
270 mfcr r9
271 KVMTEST(0xc00)
272 GET_SCRATCH0(r13)
273#endif
742415d6
MN
274 SYSCALL_PSERIES_1
275 SYSCALL_PSERIES_2_RFID
276 SYSCALL_PSERIES_3
b01c8b54
PM
277 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
278
b3e6b5df 279 STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
de56a948 280 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
b3e6b5df
BH
281
282 /* At 0xe??? we have a bunch of hypervisor exceptions, we branch
283 * out of line to handle them
284 */
285 . = 0xe00
e6a74c6e 286hv_exception_trampoline:
b3e6b5df
BH
287 b h_data_storage_hv
288 . = 0xe20
289 b h_instr_storage_hv
290 . = 0xe40
291 b emulation_assist_hv
292 . = 0xe50
293 b hmi_exception_hv
294 . = 0xe60
295 b hmi_exception_hv
655bb3f4
IM
296 . = 0xe80
297 b h_doorbell_hv
0ebc4cda
BH
298
299 /* We need to deal with the Altivec unavailable exception
300 * here which is at 0xf20, thus in the middle of the
301 * prolog code of the PerformanceMonitor one. A little
302 * trickery is thus necessary
303 */
c86e2ead 304performance_monitor_pSeries_1:
0ebc4cda
BH
305 . = 0xf00
306 b performance_monitor_pSeries
307
c86e2ead 308altivec_unavailable_pSeries_1:
0ebc4cda
BH
309 . = 0xf20
310 b altivec_unavailable_pSeries
311
c86e2ead 312vsx_unavailable_pSeries_1:
0ebc4cda
BH
313 . = 0xf40
314 b vsx_unavailable_pSeries
315
316#ifdef CONFIG_CBE_RAS
b3e6b5df 317 STD_EXCEPTION_HV(0x1200, 0x1202, cbe_system_error)
5ccf55dd 318 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1202)
0ebc4cda 319#endif /* CONFIG_CBE_RAS */
b01c8b54 320
b3e6b5df 321 STD_EXCEPTION_PSERIES(0x1300, 0x1300, instruction_breakpoint)
de56a948 322 KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
b01c8b54 323
b92a66a6 324 . = 0x1500
51cf2b30 325 .global denorm_exception_hv
b92a66a6
MN
326denorm_exception_hv:
327 HMT_MEDIUM
328 mtspr SPRN_SPRG_HSCRATCH0,r13
329 mfspr r13,SPRN_SPRG_HPACA
330 std r9,PACA_EXGEN+EX_R9(r13)
331 std r10,PACA_EXGEN+EX_R10(r13)
332 std r11,PACA_EXGEN+EX_R11(r13)
333 std r12,PACA_EXGEN+EX_R12(r13)
334 mfspr r9,SPRN_SPRG_HSCRATCH0
335 std r9,PACA_EXGEN+EX_R13(r13)
336 mfcr r9
337
338#ifdef CONFIG_PPC_DENORMALISATION
339 mfspr r10,SPRN_HSRR1
340 mfspr r11,SPRN_HSRR0 /* save HSRR0 */
341 andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
342 addi r11,r11,-4 /* HSRR0 is next instruction */
343 bne+ denorm_assist
344#endif
345
346 EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV)
347 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x1500)
348
0ebc4cda 349#ifdef CONFIG_CBE_RAS
b3e6b5df 350 STD_EXCEPTION_HV(0x1600, 0x1602, cbe_maintenance)
5ccf55dd 351 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1602)
0ebc4cda 352#endif /* CONFIG_CBE_RAS */
b01c8b54 353
b3e6b5df 354 STD_EXCEPTION_PSERIES(0x1700, 0x1700, altivec_assist)
de56a948 355 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x1700)
b01c8b54 356
0ebc4cda 357#ifdef CONFIG_CBE_RAS
b3e6b5df 358 STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
5ccf55dd 359 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
faab4dd2
MN
360#else
361 . = 0x1800
0ebc4cda
BH
362#endif /* CONFIG_CBE_RAS */
363
0ebc4cda 364
b3e6b5df
BH
365/*** Out of line interrupts support ***/
366
faab4dd2 367 .align 7
b01c8b54
PM
368 /* moved from 0x200 */
369machine_check_pSeries:
370 .globl machine_check_fwnmi
371machine_check_fwnmi:
372 HMT_MEDIUM
373 SET_SCRATCH0(r13) /* save r13 */
374 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common,
375 EXC_STD, KVMTEST, 0x200)
376 KVM_HANDLER_SKIP(PACA_EXMC, EXC_STD, 0x200)
377
b01c8b54
PM
378 /* moved from 0x300 */
379data_access_check_stab:
380 GET_PACA(r13)
381 std r9,PACA_EXSLB+EX_R9(r13)
382 std r10,PACA_EXSLB+EX_R10(r13)
383 mfspr r10,SPRN_DAR
384 mfspr r9,SPRN_DSISR
385 srdi r10,r10,60
386 rlwimi r10,r9,16,0x20
de56a948 387#ifdef CONFIG_KVM_BOOK3S_PR
3c42bf8a 388 lbz r9,HSTATE_IN_GUEST(r13)
b01c8b54
PM
389 rlwimi r10,r9,8,0x300
390#endif
391 mfcr r9
392 cmpwi r10,0x2c
393 beq do_stab_bolted_pSeries
394 mtcrf 0x80,r9
395 ld r9,PACA_EXSLB+EX_R9(r13)
396 ld r10,PACA_EXSLB+EX_R10(r13)
397 b data_access_not_stab
398do_stab_bolted_pSeries:
399 std r11,PACA_EXSLB+EX_R11(r13)
400 std r12,PACA_EXSLB+EX_R12(r13)
401 GET_SCRATCH0(r10)
402 std r10,PACA_EXSLB+EX_R13(r13)
403 EXCEPTION_PROLOG_PSERIES_1(.do_stab_bolted, EXC_STD)
b01c8b54 404
697d3899
PM
405 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_STD, 0x300)
406 KVM_HANDLER_SKIP(PACA_EXSLB, EXC_STD, 0x380)
de56a948
PM
407 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x400)
408 KVM_HANDLER_PR(PACA_EXSLB, EXC_STD, 0x480)
409 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0x900)
b01c8b54
PM
410 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0x982)
411
b92a66a6
MN
412#ifdef CONFIG_PPC_DENORMALISATION
413denorm_assist:
414BEGIN_FTR_SECTION
415/*
416 * To denormalise we need to move a copy of the register to itself.
417 * For POWER6 do that here for all FP regs.
418 */
419 mfmsr r10
420 ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
421 xori r10,r10,(MSR_FE0|MSR_FE1)
422 mtmsrd r10
423 sync
424 fmr 0,0
425 fmr 1,1
426 fmr 2,2
427 fmr 3,3
428 fmr 4,4
429 fmr 5,5
430 fmr 6,6
431 fmr 7,7
432 fmr 8,8
433 fmr 9,9
434 fmr 10,10
435 fmr 11,11
436 fmr 12,12
437 fmr 13,13
438 fmr 14,14
439 fmr 15,15
440 fmr 16,16
441 fmr 17,17
442 fmr 18,18
443 fmr 19,19
444 fmr 20,20
445 fmr 21,21
446 fmr 22,22
447 fmr 23,23
448 fmr 24,24
449 fmr 25,25
450 fmr 26,26
451 fmr 27,27
452 fmr 28,28
453 fmr 29,29
454 fmr 30,30
455 fmr 31,31
456FTR_SECTION_ELSE
457/*
458 * To denormalise we need to move a copy of the register to itself.
459 * For POWER7 do that here for the first 32 VSX registers only.
460 */
461 mfmsr r10
462 oris r10,r10,MSR_VSX@h
463 mtmsrd r10
464 sync
465 XVCPSGNDP(0,0,0)
466 XVCPSGNDP(1,1,1)
467 XVCPSGNDP(2,2,2)
468 XVCPSGNDP(3,3,3)
469 XVCPSGNDP(4,4,4)
470 XVCPSGNDP(5,5,5)
471 XVCPSGNDP(6,6,6)
472 XVCPSGNDP(7,7,7)
473 XVCPSGNDP(8,8,8)
474 XVCPSGNDP(9,9,9)
475 XVCPSGNDP(10,10,10)
476 XVCPSGNDP(11,11,11)
477 XVCPSGNDP(12,12,12)
478 XVCPSGNDP(13,13,13)
479 XVCPSGNDP(14,14,14)
480 XVCPSGNDP(15,15,15)
481 XVCPSGNDP(16,16,16)
482 XVCPSGNDP(17,17,17)
483 XVCPSGNDP(18,18,18)
484 XVCPSGNDP(19,19,19)
485 XVCPSGNDP(20,20,20)
486 XVCPSGNDP(21,21,21)
487 XVCPSGNDP(22,22,22)
488 XVCPSGNDP(23,23,23)
489 XVCPSGNDP(24,24,24)
490 XVCPSGNDP(25,25,25)
491 XVCPSGNDP(26,26,26)
492 XVCPSGNDP(27,27,27)
493 XVCPSGNDP(28,28,28)
494 XVCPSGNDP(29,29,29)
495 XVCPSGNDP(30,30,30)
496 XVCPSGNDP(31,31,31)
497ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
498 mtspr SPRN_HSRR0,r11
499 mtcrf 0x80,r9
500 ld r9,PACA_EXGEN+EX_R9(r13)
501 ld r10,PACA_EXGEN+EX_R10(r13)
502 ld r11,PACA_EXGEN+EX_R11(r13)
503 ld r12,PACA_EXGEN+EX_R12(r13)
504 ld r13,PACA_EXGEN+EX_R13(r13)
505 HRFID
506 b .
507#endif
508
b01c8b54 509 .align 7
b3e6b5df 510 /* moved from 0xe00 */
b01c8b54
PM
511 STD_EXCEPTION_HV(., 0xe02, h_data_storage)
512 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0xe02)
513 STD_EXCEPTION_HV(., 0xe22, h_instr_storage)
514 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe22)
515 STD_EXCEPTION_HV(., 0xe42, emulation_assist)
516 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe42)
517 STD_EXCEPTION_HV(., 0xe62, hmi_exception) /* need to flush cache ? */
518 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe62)
655bb3f4
IM
519 MASKABLE_EXCEPTION_HV(., 0xe82, h_doorbell)
520 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe82)
0ebc4cda
BH
521
522 /* moved from 0xf00 */
b3e6b5df 523 STD_EXCEPTION_PSERIES(., 0xf00, performance_monitor)
de56a948 524 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf00)
b3e6b5df 525 STD_EXCEPTION_PSERIES(., 0xf20, altivec_unavailable)
de56a948 526 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf20)
b3e6b5df 527 STD_EXCEPTION_PSERIES(., 0xf40, vsx_unavailable)
de56a948 528 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xf40)
0ebc4cda
BH
529
530/*
fe9e1d54
IM
531 * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
532 * - If it was a decrementer interrupt, we bump the dec to max and and return.
533 * - If it was a doorbell we return immediately since doorbells are edge
534 * triggered and won't automatically refire.
535 * - else we hard disable and return.
536 * This is called with r10 containing the value to OR to the paca field.
0ebc4cda 537 */
7230c564
BH
538#define MASKED_INTERRUPT(_H) \
539masked_##_H##interrupt: \
540 std r11,PACA_EXGEN+EX_R11(r13); \
541 lbz r11,PACAIRQHAPPENED(r13); \
542 or r11,r11,r10; \
543 stb r11,PACAIRQHAPPENED(r13); \
fe9e1d54
IM
544 cmpwi r10,PACA_IRQ_DEC; \
545 bne 1f; \
7230c564
BH
546 lis r10,0x7fff; \
547 ori r10,r10,0xffff; \
548 mtspr SPRN_DEC,r10; \
549 b 2f; \
fe9e1d54
IM
5501: cmpwi r10,PACA_IRQ_DBELL; \
551 beq 2f; \
552 mfspr r10,SPRN_##_H##SRR1; \
7230c564
BH
553 rldicl r10,r10,48,1; /* clear MSR_EE */ \
554 rotldi r10,r10,16; \
555 mtspr SPRN_##_H##SRR1,r10; \
5562: mtcrf 0x80,r9; \
557 ld r9,PACA_EXGEN+EX_R9(r13); \
558 ld r10,PACA_EXGEN+EX_R10(r13); \
559 ld r11,PACA_EXGEN+EX_R11(r13); \
560 GET_SCRATCH0(r13); \
561 ##_H##rfid; \
0ebc4cda 562 b .
7230c564
BH
563
564 MASKED_INTERRUPT()
565 MASKED_INTERRUPT(H)
0ebc4cda 566
7230c564
BH
567/*
568 * Called from arch_local_irq_enable when an interrupt needs
fe9e1d54
IM
569 * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
570 * which kind of interrupt. MSR:EE is already off. We generate a
7230c564
BH
571 * stackframe like if a real interrupt had happened.
572 *
573 * Note: While MSR:EE is off, we need to make sure that _MSR
574 * in the generated frame has EE set to 1 or the exception
575 * handler will not properly re-enable them.
576 */
577_GLOBAL(__replay_interrupt)
578 /* We are going to jump to the exception common code which
579 * will retrieve various register values from the PACA which
580 * we don't give a damn about, so we don't bother storing them.
581 */
582 mfmsr r12
583 mflr r11
584 mfcr r9
585 ori r12,r12,MSR_EE
fe9e1d54
IM
586 cmpwi r3,0x900
587 beq decrementer_common
588 cmpwi r3,0x500
589 beq hardware_interrupt_common
590BEGIN_FTR_SECTION
591 cmpwi r3,0xe80
592 beq h_doorbell_common
593FTR_SECTION_ELSE
594 cmpwi r3,0xa00
595 beq doorbell_super_common
596ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
597 blr
a5d4f3ad 598
0ebc4cda
BH
599#ifdef CONFIG_PPC_PSERIES
600/*
601 * Vectors for the FWNMI option. Share common code.
602 */
603 .globl system_reset_fwnmi
604 .align 7
605system_reset_fwnmi:
606 HMT_MEDIUM
673b189a 607 SET_SCRATCH0(r13) /* save r13 */
b01c8b54
PM
608 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
609 NOTEST, 0x100)
0ebc4cda
BH
610
611#endif /* CONFIG_PPC_PSERIES */
612
613#ifdef __DISABLED__
614/*
615 * This is used for when the SLB miss handler has to go virtual,
616 * which doesn't happen for now anymore but will once we re-implement
617 * dynamic VSIDs for shared page tables
618 */
619slb_miss_user_pseries:
620 std r10,PACA_EXGEN+EX_R10(r13)
621 std r11,PACA_EXGEN+EX_R11(r13)
622 std r12,PACA_EXGEN+EX_R12(r13)
673b189a 623 GET_SCRATCH0(r10)
0ebc4cda
BH
624 ld r11,PACA_EXSLB+EX_R9(r13)
625 ld r12,PACA_EXSLB+EX_R3(r13)
626 std r10,PACA_EXGEN+EX_R13(r13)
627 std r11,PACA_EXGEN+EX_R9(r13)
628 std r12,PACA_EXGEN+EX_R3(r13)
629 clrrdi r12,r13,32
630 mfmsr r10
631 mfspr r11,SRR0 /* save SRR0 */
632 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
633 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
634 mtspr SRR0,r12
635 mfspr r12,SRR1 /* and SRR1 */
636 mtspr SRR1,r10
637 rfid
638 b . /* prevent spec. execution */
639#endif /* __DISABLED__ */
640
0ebc4cda
BH
641/*
642 * Code from here down to __end_handlers is invoked from the
643 * exception prologs above. Because the prologs assemble the
644 * addresses of these handlers using the LOAD_HANDLER macro,
61e2390e
MN
645 * which uses an ori instruction, these handlers must be in
646 * the first 64k of the kernel image.
0ebc4cda
BH
647 */
648
649/*** Common interrupt handlers ***/
650
651 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
652
653 /*
654 * Machine check is different because we use a different
655 * save area: PACA_EXMC instead of PACA_EXGEN.
656 */
657 .align 7
658 .globl machine_check_common
659machine_check_common:
660 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
661 FINISH_NAP
662 DISABLE_INTS
663 bl .save_nvgprs
664 addi r3,r1,STACK_FRAME_OVERHEAD
665 bl .machine_check_exception
666 b .ret_from_except
667
7450f6f0
BH
668 STD_EXCEPTION_COMMON_ASYNC(0x500, hardware_interrupt, do_IRQ)
669 STD_EXCEPTION_COMMON_ASYNC(0x900, decrementer, .timer_interrupt)
dabe859e 670 STD_EXCEPTION_COMMON(0x980, hdecrementer, .hdec_interrupt)
1dbdafec
IM
671#ifdef CONFIG_PPC_DOORBELL
672 STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, .doorbell_exception)
673#else
674 STD_EXCEPTION_COMMON_ASYNC(0xa00, doorbell_super, .unknown_exception)
675#endif
0ebc4cda
BH
676 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
677 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
678 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
278a6cdc
MN
679 STD_EXCEPTION_COMMON(0xe40, emulation_assist, .program_check_exception)
680 STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception)
655bb3f4
IM
681#ifdef CONFIG_PPC_DOORBELL
682 STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, .doorbell_exception)
683#else
684 STD_EXCEPTION_COMMON_ASYNC(0xe80, h_doorbell, .unknown_exception)
685#endif
7450f6f0 686 STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, .performance_monitor_exception)
0ebc4cda 687 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
b92a66a6 688 STD_EXCEPTION_COMMON(0x1502, denorm, .unknown_exception)
0ebc4cda
BH
689#ifdef CONFIG_ALTIVEC
690 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
691#else
692 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
693#endif
694#ifdef CONFIG_CBE_RAS
695 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
696 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
697 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
698#endif /* CONFIG_CBE_RAS */
699
c1fb6816
MN
700 /*
701 * Relocation-on interrupts: A subset of the interrupts can be delivered
702 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
703 * it. Addresses are the same as the original interrupt addresses, but
704 * offset by 0xc000000000004000.
705 * It's impossible to receive interrupts below 0x300 via this mechanism.
706 * KVM: None of these traps are from the guest ; anything that escalated
707 * to HV=1 from HV=0 is delivered via real mode handlers.
708 */
709
710 /*
711 * This uses the standard macro, since the original 0x300 vector
712 * only has extra guff for STAB-based processors -- which never
713 * come here.
714 */
715 STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
716 . = 0x4380
717 .globl data_access_slb_relon_pSeries
718data_access_slb_relon_pSeries:
719 HMT_MEDIUM
720 SET_SCRATCH0(r13)
721 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
722 std r3,PACA_EXSLB+EX_R3(r13)
723 mfspr r3,SPRN_DAR
724 mfspr r12,SPRN_SRR1
725#ifndef CONFIG_RELOCATABLE
726 b .slb_miss_realmode
727#else
728 /*
729 * We can't just use a direct branch to .slb_miss_realmode
730 * because the distance from here to there depends on where
731 * the kernel ends up being put.
732 */
733 mfctr r11
734 ld r10,PACAKBASE(r13)
735 LOAD_HANDLER(r10, .slb_miss_realmode)
736 mtctr r10
737 bctr
738#endif
739
740 STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
741 . = 0x4480
742 .globl instruction_access_slb_relon_pSeries
743instruction_access_slb_relon_pSeries:
744 HMT_MEDIUM
745 SET_SCRATCH0(r13)
746 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
747 std r3,PACA_EXSLB+EX_R3(r13)
748 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
749 mfspr r12,SPRN_SRR1
750#ifndef CONFIG_RELOCATABLE
751 b .slb_miss_realmode
752#else
753 mfctr r11
754 ld r10,PACAKBASE(r13)
755 LOAD_HANDLER(r10, .slb_miss_realmode)
756 mtctr r10
757 bctr
758#endif
759
760 . = 0x4500
761 .globl hardware_interrupt_relon_pSeries;
762 .globl hardware_interrupt_relon_hv;
763hardware_interrupt_relon_pSeries:
764hardware_interrupt_relon_hv:
765 BEGIN_FTR_SECTION
766 _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
767 FTR_SECTION_ELSE
768 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
769 ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_206)
770 STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
771 STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
772 STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
773 MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
774 STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
1dbdafec 775 MASKABLE_RELON_EXCEPTION_PSERIES(0x4a00, 0xa00, doorbell_super)
c1fb6816
MN
776 STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
777
778 . = 0x4c00
779 .globl system_call_relon_pSeries
780system_call_relon_pSeries:
781 HMT_MEDIUM
782 SYSCALL_PSERIES_1
783 SYSCALL_PSERIES_2_DIRECT
784 SYSCALL_PSERIES_3
785
786 STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
787
788 . = 0x4e00
789 b h_data_storage_relon_hv
790
791 . = 0x4e20
792 b h_instr_storage_relon_hv
793
794 . = 0x4e40
795 b emulation_assist_relon_hv
796
797 . = 0x4e50
798 b hmi_exception_relon_hv
799
800 . = 0x4e60
801 b hmi_exception_relon_hv
802
655bb3f4
IM
803 . = 0x4e80
804 b h_doorbell_relon_hv
c1fb6816
MN
805
806performance_monitor_relon_pSeries_1:
807 . = 0x4f00
808 b performance_monitor_relon_pSeries
809
810altivec_unavailable_relon_pSeries_1:
811 . = 0x4f20
812 b altivec_unavailable_relon_pSeries
813
814vsx_unavailable_relon_pSeries_1:
815 . = 0x4f40
816 b vsx_unavailable_relon_pSeries
817
818#ifdef CONFIG_CBE_RAS
819 STD_RELON_EXCEPTION_HV(0x5200, 0x1202, cbe_system_error)
820#endif /* CONFIG_CBE_RAS */
821 STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
822#ifdef CONFIG_PPC_DENORMALISATION
823 . = 0x5500
824 b denorm_exception_hv
825#endif
826#ifdef CONFIG_CBE_RAS
827 STD_RELON_EXCEPTION_HV(0x5600, 0x1602, cbe_maintenance)
828#else
829#ifdef CONFIG_HVC_SCOM
830 STD_RELON_EXCEPTION_HV(0x5600, 0x1600, maintence_interrupt)
831 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1600)
832#endif /* CONFIG_HVC_SCOM */
833#endif /* CONFIG_CBE_RAS */
834 STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
835#ifdef CONFIG_CBE_RAS
836 STD_RELON_EXCEPTION_HV(0x5800, 0x1802, cbe_thermal)
837#endif /* CONFIG_CBE_RAS */
838
839 /* Other future vectors */
840 .align 7
841 .globl __end_interrupts
842__end_interrupts:
843
0ebc4cda 844 .align 7
c1fb6816
MN
845system_call_entry_direct:
846#if defined(CONFIG_RELOCATABLE)
847 /* The first level prologue may have used LR to get here, saving
848 * orig in r10. To save hacking/ifdeffing common code, restore here.
849 */
850 mtlr r10
851#endif
0ebc4cda
BH
852system_call_entry:
853 b system_call_common
854
fe1952fc
BH
855ppc64_runlatch_on_trampoline:
856 b .__ppc64_runlatch_on
857
0ebc4cda
BH
858/*
859 * Here we have detected that the kernel stack pointer is bad.
860 * R9 contains the saved CR, r13 points to the paca,
861 * r10 contains the (bad) kernel stack pointer,
862 * r11 and r12 contain the saved SRR0 and SRR1.
863 * We switch to using an emergency stack, save the registers there,
864 * and call kernel_bad_stack(), which panics.
865 */
866bad_stack:
867 ld r1,PACAEMERGSP(r13)
868 subi r1,r1,64+INT_FRAME_SIZE
869 std r9,_CCR(r1)
870 std r10,GPR1(r1)
871 std r11,_NIP(r1)
872 std r12,_MSR(r1)
873 mfspr r11,SPRN_DAR
874 mfspr r12,SPRN_DSISR
875 std r11,_DAR(r1)
876 std r12,_DSISR(r1)
877 mflr r10
878 mfctr r11
879 mfxer r12
880 std r10,_LINK(r1)
881 std r11,_CTR(r1)
882 std r12,_XER(r1)
883 SAVE_GPR(0,r1)
884 SAVE_GPR(2,r1)
1977b502
PM
885 ld r10,EX_R3(r3)
886 std r10,GPR3(r1)
887 SAVE_GPR(4,r1)
888 SAVE_4GPRS(5,r1)
889 ld r9,EX_R9(r3)
890 ld r10,EX_R10(r3)
891 SAVE_2GPRS(9,r1)
892 ld r9,EX_R11(r3)
893 ld r10,EX_R12(r3)
894 ld r11,EX_R13(r3)
895 std r9,GPR11(r1)
896 std r10,GPR12(r1)
897 std r11,GPR13(r1)
48404f2e
PM
898BEGIN_FTR_SECTION
899 ld r10,EX_CFAR(r3)
900 std r10,ORIG_GPR3(r1)
901END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
1977b502 902 SAVE_8GPRS(14,r1)
0ebc4cda
BH
903 SAVE_10GPRS(22,r1)
904 lhz r12,PACA_TRAP_SAVE(r13)
905 std r12,_TRAP(r1)
906 addi r11,r1,INT_FRAME_SIZE
907 std r11,0(r1)
908 li r12,0
909 std r12,0(r11)
910 ld r2,PACATOC(r13)
1977b502
PM
911 ld r11,exception_marker@toc(r2)
912 std r12,RESULT(r1)
913 std r11,STACK_FRAME_OVERHEAD-16(r1)
0ebc4cda
BH
9141: addi r3,r1,STACK_FRAME_OVERHEAD
915 bl .kernel_bad_stack
916 b 1b
917
918/*
919 * Here r13 points to the paca, r9 contains the saved CR,
920 * SRR0 and SRR1 are saved in r11 and r12,
921 * r9 - r13 are saved in paca->exgen.
922 */
923 .align 7
924 .globl data_access_common
925data_access_common:
926 mfspr r10,SPRN_DAR
927 std r10,PACA_EXGEN+EX_DAR(r13)
928 mfspr r10,SPRN_DSISR
929 stw r10,PACA_EXGEN+EX_DSISR(r13)
930 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
a546498f
BH
931 DISABLE_INTS
932 ld r12,_MSR(r1)
0ebc4cda
BH
933 ld r3,PACA_EXGEN+EX_DAR(r13)
934 lwz r4,PACA_EXGEN+EX_DSISR(r13)
935 li r5,0x300
278a6cdc 936 b .do_hash_page /* Try to handle as hpte fault */
0ebc4cda 937
b3e6b5df 938 .align 7
278a6cdc 939 .globl h_data_storage_common
b3e6b5df 940h_data_storage_common:
278a6cdc
MN
941 mfspr r10,SPRN_HDAR
942 std r10,PACA_EXGEN+EX_DAR(r13)
943 mfspr r10,SPRN_HDSISR
944 stw r10,PACA_EXGEN+EX_DSISR(r13)
945 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
946 bl .save_nvgprs
a546498f 947 DISABLE_INTS
278a6cdc
MN
948 addi r3,r1,STACK_FRAME_OVERHEAD
949 bl .unknown_exception
950 b .ret_from_except
b3e6b5df 951
0ebc4cda
BH
952 .align 7
953 .globl instruction_access_common
954instruction_access_common:
955 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
a546498f
BH
956 DISABLE_INTS
957 ld r12,_MSR(r1)
0ebc4cda
BH
958 ld r3,_NIP(r1)
959 andis. r4,r12,0x5820
960 li r5,0x400
961 b .do_hash_page /* Try to handle as hpte fault */
962
278a6cdc 963 STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception)
b3e6b5df 964
0ebc4cda
BH
965/*
966 * Here is the common SLB miss user that is used when going to virtual
967 * mode for SLB misses, that is currently not used
968 */
969#ifdef __DISABLED__
970 .align 7
971 .globl slb_miss_user_common
972slb_miss_user_common:
973 mflr r10
974 std r3,PACA_EXGEN+EX_DAR(r13)
975 stw r9,PACA_EXGEN+EX_CCR(r13)
976 std r10,PACA_EXGEN+EX_LR(r13)
977 std r11,PACA_EXGEN+EX_SRR0(r13)
978 bl .slb_allocate_user
979
980 ld r10,PACA_EXGEN+EX_LR(r13)
981 ld r3,PACA_EXGEN+EX_R3(r13)
982 lwz r9,PACA_EXGEN+EX_CCR(r13)
983 ld r11,PACA_EXGEN+EX_SRR0(r13)
984 mtlr r10
985 beq- slb_miss_fault
986
987 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
988 beq- unrecov_user_slb
989 mfmsr r10
990
991.machine push
992.machine "power4"
993 mtcrf 0x80,r9
994.machine pop
995
996 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
997 mtmsrd r10,1
998
999 mtspr SRR0,r11
1000 mtspr SRR1,r12
1001
1002 ld r9,PACA_EXGEN+EX_R9(r13)
1003 ld r10,PACA_EXGEN+EX_R10(r13)
1004 ld r11,PACA_EXGEN+EX_R11(r13)
1005 ld r12,PACA_EXGEN+EX_R12(r13)
1006 ld r13,PACA_EXGEN+EX_R13(r13)
1007 rfid
1008 b .
1009
1010slb_miss_fault:
1011 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
1012 ld r4,PACA_EXGEN+EX_DAR(r13)
1013 li r5,0
1014 std r4,_DAR(r1)
1015 std r5,_DSISR(r1)
1016 b handle_page_fault
1017
1018unrecov_user_slb:
1019 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
1020 DISABLE_INTS
1021 bl .save_nvgprs
10221: addi r3,r1,STACK_FRAME_OVERHEAD
1023 bl .unrecoverable_exception
1024 b 1b
1025
1026#endif /* __DISABLED__ */
1027
1028
1029/*
1030 * r13 points to the PACA, r9 contains the saved CR,
1031 * r12 contain the saved SRR1, SRR0 is still ready for return
1032 * r3 has the faulting address
1033 * r9 - r13 are saved in paca->exslb.
1034 * r3 is saved in paca->slb_r3
1035 * We assume we aren't going to take any exceptions during this procedure.
1036 */
1037_GLOBAL(slb_miss_realmode)
1038 mflr r10
1039#ifdef CONFIG_RELOCATABLE
1040 mtctr r11
1041#endif
1042
1043 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1044 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
1045
1046 bl .slb_allocate_realmode
1047
1048 /* All done -- return from exception. */
1049
1050 ld r10,PACA_EXSLB+EX_LR(r13)
1051 ld r3,PACA_EXSLB+EX_R3(r13)
1052 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
0ebc4cda
BH
1053
1054 mtlr r10
1055
1056 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
1057 beq- 2f
1058
1059.machine push
1060.machine "power4"
1061 mtcrf 0x80,r9
1062 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
1063.machine pop
1064
0ebc4cda
BH
1065 ld r9,PACA_EXSLB+EX_R9(r13)
1066 ld r10,PACA_EXSLB+EX_R10(r13)
1067 ld r11,PACA_EXSLB+EX_R11(r13)
1068 ld r12,PACA_EXSLB+EX_R12(r13)
1069 ld r13,PACA_EXSLB+EX_R13(r13)
1070 rfid
1071 b . /* prevent speculative execution */
1072
4f8cf36f 10732: mfspr r11,SPRN_SRR0
0ebc4cda
BH
1074 ld r10,PACAKBASE(r13)
1075 LOAD_HANDLER(r10,unrecov_slb)
1076 mtspr SPRN_SRR0,r10
1077 ld r10,PACAKMSR(r13)
1078 mtspr SPRN_SRR1,r10
1079 rfid
1080 b .
1081
1082unrecov_slb:
1083 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1084 DISABLE_INTS
1085 bl .save_nvgprs
10861: addi r3,r1,STACK_FRAME_OVERHEAD
1087 bl .unrecoverable_exception
1088 b 1b
1089
0ebc4cda
BH
1090
1091#ifdef CONFIG_PPC_970_NAP
1092power4_fixup_nap:
1093 andc r9,r9,r10
1094 std r9,TI_LOCAL_FLAGS(r11)
1095 ld r10,_LINK(r1) /* make idle task do the */
1096 std r10,_NIP(r1) /* equivalent of a blr */
1097 blr
1098#endif
1099
1100 .align 7
1101 .globl alignment_common
1102alignment_common:
1103 mfspr r10,SPRN_DAR
1104 std r10,PACA_EXGEN+EX_DAR(r13)
1105 mfspr r10,SPRN_DSISR
1106 stw r10,PACA_EXGEN+EX_DSISR(r13)
1107 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1108 ld r3,PACA_EXGEN+EX_DAR(r13)
1109 lwz r4,PACA_EXGEN+EX_DSISR(r13)
1110 std r3,_DAR(r1)
1111 std r4,_DSISR(r1)
1112 bl .save_nvgprs
a3512b2d 1113 DISABLE_INTS
0ebc4cda 1114 addi r3,r1,STACK_FRAME_OVERHEAD
0ebc4cda
BH
1115 bl .alignment_exception
1116 b .ret_from_except
1117
1118 .align 7
1119 .globl program_check_common
1120program_check_common:
1121 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1122 bl .save_nvgprs
54321242 1123 DISABLE_INTS
922b9f86 1124 addi r3,r1,STACK_FRAME_OVERHEAD
0ebc4cda
BH
1125 bl .program_check_exception
1126 b .ret_from_except
1127
1128 .align 7
1129 .globl fp_unavailable_common
1130fp_unavailable_common:
1131 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1132 bne 1f /* if from user, just load it up */
1133 bl .save_nvgprs
9f2f79e3 1134 DISABLE_INTS
0ebc4cda 1135 addi r3,r1,STACK_FRAME_OVERHEAD
0ebc4cda
BH
1136 bl .kernel_fp_unavailable_exception
1137 BUG_OPCODE
11381: bl .load_up_fpu
1139 b fast_exception_return
1140
1141 .align 7
1142 .globl altivec_unavailable_common
1143altivec_unavailable_common:
1144 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1145#ifdef CONFIG_ALTIVEC
1146BEGIN_FTR_SECTION
1147 beq 1f
1148 bl .load_up_altivec
1149 b fast_exception_return
11501:
1151END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1152#endif
1153 bl .save_nvgprs
9f2f79e3 1154 DISABLE_INTS
0ebc4cda 1155 addi r3,r1,STACK_FRAME_OVERHEAD
0ebc4cda
BH
1156 bl .altivec_unavailable_exception
1157 b .ret_from_except
1158
1159 .align 7
1160 .globl vsx_unavailable_common
1161vsx_unavailable_common:
1162 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
1163#ifdef CONFIG_VSX
1164BEGIN_FTR_SECTION
7230c564
BH
1165 beq 1f
1166 b .load_up_vsx
0ebc4cda
BH
11671:
1168END_FTR_SECTION_IFSET(CPU_FTR_VSX)
1169#endif
1170 bl .save_nvgprs
9f2f79e3 1171 DISABLE_INTS
0ebc4cda 1172 addi r3,r1,STACK_FRAME_OVERHEAD
0ebc4cda
BH
1173 bl .vsx_unavailable_exception
1174 b .ret_from_except
1175
1176 .align 7
1177 .globl __end_handlers
1178__end_handlers:
1179
0ebc4cda
BH
1180/*
1181 * Hash table stuff
1182 */
1183 .align 7
1184_STATIC(do_hash_page)
1185 std r3,_DAR(r1)
1186 std r4,_DSISR(r1)
1187
9c7cc234 1188 andis. r0,r4,0xa410 /* weird error? */
0ebc4cda 1189 bne- handle_page_fault /* if not, try to insert a HPTE */
9c7cc234
P
1190 andis. r0,r4,DSISR_DABRMATCH@h
1191 bne- handle_dabr_fault
1192
0ebc4cda
BH
1193BEGIN_FTR_SECTION
1194 andis. r0,r4,0x0020 /* Is it a segment table fault? */
1195 bne- do_ste_alloc /* If so handle it */
44ae3ab3 1196END_MMU_FTR_SECTION_IFCLR(MMU_FTR_SLB)
0ebc4cda 1197
9778b696 1198 CURRENT_THREAD_INFO(r11, r1)
9c1e1052
PM
1199 lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
1200 andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
1201 bne 77f /* then don't call hash_page now */
0ebc4cda
BH
1202 /*
1203 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1204 * accessing a userspace segment (even from the kernel). We assume
1205 * kernel addresses always have the high bit set.
1206 */
1207 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1208 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
1209 orc r0,r12,r0 /* MSR_PR | ~high_bit */
1210 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
1211 ori r4,r4,1 /* add _PAGE_PRESENT */
1212 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
1213
1214 /*
1215 * r3 contains the faulting address
1216 * r4 contains the required access permissions
1217 * r5 contains the trap number
1218 *
7230c564 1219 * at return r3 = 0 for success, 1 for page fault, negative for error
0ebc4cda
BH
1220 */
1221 bl .hash_page /* build HPTE if possible */
1222 cmpdi r3,0 /* see if hash_page succeeded */
1223
7230c564 1224 /* Success */
0ebc4cda 1225 beq fast_exc_return_irq /* Return from exception on success */
0ebc4cda 1226
7230c564
BH
1227 /* Error */
1228 blt- 13f
9c7cc234 1229
0ebc4cda
BH
1230/* Here we have a page fault that hash_page can't handle. */
1231handle_page_fault:
0ebc4cda
BH
123211: ld r4,_DAR(r1)
1233 ld r5,_DSISR(r1)
1234 addi r3,r1,STACK_FRAME_OVERHEAD
1235 bl .do_page_fault
1236 cmpdi r3,0
a546498f 1237 beq+ 12f
0ebc4cda
BH
1238 bl .save_nvgprs
1239 mr r5,r3
1240 addi r3,r1,STACK_FRAME_OVERHEAD
1241 lwz r4,_DAR(r1)
1242 bl .bad_page_fault
1243 b .ret_from_except
1244
a546498f
BH
1245/* We have a data breakpoint exception - handle it */
1246handle_dabr_fault:
1247 bl .save_nvgprs
1248 ld r4,_DAR(r1)
1249 ld r5,_DSISR(r1)
1250 addi r3,r1,STACK_FRAME_OVERHEAD
1251 bl .do_dabr
125212: b .ret_from_except_lite
1253
0ebc4cda
BH
1254
1255/* We have a page fault that hash_page could handle but HV refused
1256 * the PTE insertion
1257 */
a546498f 125813: bl .save_nvgprs
0ebc4cda
BH
1259 mr r5,r3
1260 addi r3,r1,STACK_FRAME_OVERHEAD
1261 ld r4,_DAR(r1)
1262 bl .low_hash_fault
1263 b .ret_from_except
1264
9c1e1052
PM
1265/*
1266 * We come here as a result of a DSI at a point where we don't want
1267 * to call hash_page, such as when we are accessing memory (possibly
1268 * user memory) inside a PMU interrupt that occurred while interrupts
1269 * were soft-disabled. We want to invoke the exception handler for
1270 * the access, or panic if there isn't a handler.
1271 */
127277: bl .save_nvgprs
1273 mr r4,r3
1274 addi r3,r1,STACK_FRAME_OVERHEAD
1275 li r5,SIGSEGV
1276 bl .bad_page_fault
1277 b .ret_from_except
1278
0ebc4cda
BH
1279 /* here we have a segment miss */
1280do_ste_alloc:
1281 bl .ste_allocate /* try to insert stab entry */
1282 cmpdi r3,0
1283 bne- handle_page_fault
1284 b fast_exception_return
1285
1286/*
1287 * r13 points to the PACA, r9 contains the saved CR,
1288 * r11 and r12 contain the saved SRR0 and SRR1.
1289 * r9 - r13 are saved in paca->exslb.
1290 * We assume we aren't going to take any exceptions during this procedure.
1291 * We assume (DAR >> 60) == 0xc.
1292 */
1293 .align 7
1294_GLOBAL(do_stab_bolted)
1295 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1296 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1297
1298 /* Hash to the primary group */
1299 ld r10,PACASTABVIRT(r13)
1300 mfspr r11,SPRN_DAR
1301 srdi r11,r11,28
1302 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1303
1304 /* Calculate VSID */
048ee099
AK
1305 /* This is a kernel address, so protovsid = ESID | 1 << 37 */
1306 li r9,0x1
1307 rldimi r11,r9,(CONTEXT_BITS + USER_ESID_BITS),0
0ebc4cda
BH
1308 ASM_VSID_SCRAMBLE(r11, r9, 256M)
1309 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1310
1311 /* Search the primary group for a free entry */
13121: ld r11,0(r10) /* Test valid bit of the current ste */
1313 andi. r11,r11,0x80
1314 beq 2f
1315 addi r10,r10,16
1316 andi. r11,r10,0x70
1317 bne 1b
1318
1319 /* Stick for only searching the primary group for now. */
1320 /* At least for now, we use a very simple random castout scheme */
1321 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1322 mftb r11
1323 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1324 ori r11,r11,0x10
1325
1326 /* r10 currently points to an ste one past the group of interest */
1327 /* make it point to the randomly selected entry */
1328 subi r10,r10,128
1329 or r10,r10,r11 /* r10 is the entry to invalidate */
1330
1331 isync /* mark the entry invalid */
1332 ld r11,0(r10)
1333 rldicl r11,r11,56,1 /* clear the valid bit */
1334 rotldi r11,r11,8
1335 std r11,0(r10)
1336 sync
1337
1338 clrrdi r11,r11,28 /* Get the esid part of the ste */
1339 slbie r11
1340
13412: std r9,8(r10) /* Store the vsid part of the ste */
1342 eieio
1343
1344 mfspr r11,SPRN_DAR /* Get the new esid */
1345 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1346 ori r11,r11,0x90 /* Turn on valid and kp */
1347 std r11,0(r10) /* Put new entry back into the stab */
1348
1349 sync
1350
1351 /* All done -- return from exception. */
1352 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1353 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1354
1355 andi. r10,r12,MSR_RI
1356 beq- unrecov_slb
1357
1358 mtcrf 0x80,r9 /* restore CR */
1359
1360 mfmsr r10
1361 clrrdi r10,r10,2
1362 mtmsrd r10,1
1363
1364 mtspr SPRN_SRR0,r11
1365 mtspr SPRN_SRR1,r12
1366 ld r9,PACA_EXSLB+EX_R9(r13)
1367 ld r10,PACA_EXSLB+EX_R10(r13)
1368 ld r11,PACA_EXSLB+EX_R11(r13)
1369 ld r12,PACA_EXSLB+EX_R12(r13)
1370 ld r13,PACA_EXSLB+EX_R13(r13)
1371 rfid
1372 b . /* prevent speculative execution */
1373
c1fb6816
MN
1374
1375 /* Equivalents to the above handlers for relocation-on interrupt vectors */
1376 STD_RELON_EXCEPTION_HV(., 0xe00, h_data_storage)
1377 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe00)
1378 STD_RELON_EXCEPTION_HV(., 0xe20, h_instr_storage)
1379 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe20)
1380 STD_RELON_EXCEPTION_HV(., 0xe40, emulation_assist)
1381 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe40)
1382 STD_RELON_EXCEPTION_HV(., 0xe60, hmi_exception)
1383 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe60)
655bb3f4
IM
1384 MASKABLE_RELON_EXCEPTION_HV(., 0xe80, h_doorbell)
1385 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe80)
c1fb6816
MN
1386
1387 STD_RELON_EXCEPTION_PSERIES(., 0xf00, performance_monitor)
1388 STD_RELON_EXCEPTION_PSERIES(., 0xf20, altivec_unavailable)
1389 STD_RELON_EXCEPTION_PSERIES(., 0xf40, vsx_unavailable)
1390
ed79ba9e 1391#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
0ebc4cda
BH
1392/*
1393 * Data area reserved for FWNMI option.
1394 * This address (0x7000) is fixed by the RPA.
1395 */
1396 .= 0x7000
1397 .globl fwnmi_data_area
1398fwnmi_data_area:
0ebc4cda 1399
ed79ba9e
BH
1400 /* pseries and powernv need to keep the whole page from
1401 * 0x7000 to 0x8000 free for use by the firmware
1402 */
278a6cdc 1403 . = 0x8000
ed79ba9e 1404#endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
84493804 1405
4f8cf36f
BH
1406/* Space for CPU0's segment table */
1407 .balign 4096
84493804
BH
1408 .globl initial_stab
1409initial_stab:
1410 .space 4096
4f8cf36f 1411
ed79ba9e
BH
1412#ifdef CONFIG_PPC_POWERNV
1413_GLOBAL(opal_mc_secondary_handler)
1414 HMT_MEDIUM
1415 SET_SCRATCH0(r13)
1416 GET_PACA(r13)
1417 clrldi r3,r3,2
1418 tovirt(r3,r3)
1419 std r3,PACA_OPAL_MC_EVT(r13)
1420 ld r13,OPAL_MC_SRR0(r3)
1421 mtspr SPRN_SRR0,r13
1422 ld r13,OPAL_MC_SRR1(r3)
1423 mtspr SPRN_SRR1,r13
1424 ld r3,OPAL_MC_GPR3(r3)
1425 GET_SCRATCH0(r13)
1426 b machine_check_pSeries
1427#endif /* CONFIG_PPC_POWERNV */