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