xref: /kvm-unit-tests/lib/s390x/interrupt.c (revision a0e236bd3253ce700c917a84b218d8bfbf61248c)
16c9f99dfSJanosch Frank /* SPDX-License-Identifier: GPL-2.0-only */
24da93626SDavid Hildenbrand /*
34da93626SDavid Hildenbrand  * s390x interrupt handling
44da93626SDavid Hildenbrand  *
54da93626SDavid Hildenbrand  * Copyright (c) 2017 Red Hat Inc
64da93626SDavid Hildenbrand  *
74da93626SDavid Hildenbrand  * Authors:
84da93626SDavid Hildenbrand  *  David Hildenbrand <david@redhat.com>
94da93626SDavid Hildenbrand  */
104da93626SDavid Hildenbrand #include <libcflat.h>
114da93626SDavid Hildenbrand #include <asm/barrier.h>
12fedfd112SNico Boehr #include <asm/mem.h>
13cdc9bd7bSJanosch Frank #include <asm/asm-offsets.h>
148ead801eSJanosch Frank #include <sclp.h>
15adc7ff44SPierre Morel #include <interrupt.h>
163ae7f80fSJanosch Frank #include <sie.h>
171921c4c6SJanosch Frank #include <fault.h>
181921c4c6SJanosch Frank #include <asm/page.h>
1989ce5095SClaudio Imbrenda #include "smp.h"
204da93626SDavid Hildenbrand 
214e5dd758SClaudio Imbrenda /**
224e5dd758SClaudio Imbrenda  * expect_pgm_int - Expect a program interrupt on the current CPU.
234e5dd758SClaudio Imbrenda  */
expect_pgm_int(void)244da93626SDavid Hildenbrand void expect_pgm_int(void)
254da93626SDavid Hildenbrand {
264e5dd758SClaudio Imbrenda 	THIS_CPU->pgm_int_expected = true;
27cd719531SJanis Schoetterl-Glausch 	lowcore.pgm_int_code = 0;
28cd719531SJanis Schoetterl-Glausch 	lowcore.trans_exc_id = 0;
294da93626SDavid Hildenbrand 	mb();
304da93626SDavid Hildenbrand }
314da93626SDavid Hildenbrand 
324e5dd758SClaudio Imbrenda /**
334e5dd758SClaudio Imbrenda  * expect_ext_int - Expect an external interrupt on the current CPU.
344e5dd758SClaudio Imbrenda  */
expect_ext_int(void)35df121a0cSJanosch Frank void expect_ext_int(void)
36df121a0cSJanosch Frank {
374e5dd758SClaudio Imbrenda 	THIS_CPU->ext_int_expected = true;
38cd719531SJanis Schoetterl-Glausch 	lowcore.ext_int_code = 0;
39df121a0cSJanosch Frank 	mb();
40df121a0cSJanosch Frank }
41df121a0cSJanosch Frank 
424e5dd758SClaudio Imbrenda /**
434e5dd758SClaudio Imbrenda  * clear_pgm_int - Clear program interrupt information
444e5dd758SClaudio Imbrenda  *
454e5dd758SClaudio Imbrenda  * Clear program interrupt information, including the expected program
464e5dd758SClaudio Imbrenda  * interrupt flag.
474e5dd758SClaudio Imbrenda  * No program interrupts are expected after calling this function.
484e5dd758SClaudio Imbrenda  *
494e5dd758SClaudio Imbrenda  * Return: the program interrupt code before clearing
504e5dd758SClaudio Imbrenda  */
clear_pgm_int(void)513db880b6SDavid Hildenbrand uint16_t clear_pgm_int(void)
523db880b6SDavid Hildenbrand {
533db880b6SDavid Hildenbrand 	uint16_t code;
543db880b6SDavid Hildenbrand 
553db880b6SDavid Hildenbrand 	mb();
56cd719531SJanis Schoetterl-Glausch 	code = lowcore.pgm_int_code;
57cd719531SJanis Schoetterl-Glausch 	lowcore.pgm_int_code = 0;
58cd719531SJanis Schoetterl-Glausch 	lowcore.trans_exc_id = 0;
594e5dd758SClaudio Imbrenda 	THIS_CPU->pgm_int_expected = false;
603db880b6SDavid Hildenbrand 	return code;
613db880b6SDavid Hildenbrand }
623db880b6SDavid Hildenbrand 
634e5dd758SClaudio Imbrenda /**
644e5dd758SClaudio Imbrenda  * check_pgm_int_code - Check the program interrupt code on the current CPU.
65*a0e236bdSNico Boehr  * @code: the expected program interrupt code on the current CPU
664e5dd758SClaudio Imbrenda  *
674e5dd758SClaudio Imbrenda  * Check and report if the program interrupt on the current CPU matches the
684e5dd758SClaudio Imbrenda  * expected one.
694e5dd758SClaudio Imbrenda  */
check_pgm_int_code(uint16_t code)704da93626SDavid Hildenbrand void check_pgm_int_code(uint16_t code)
714da93626SDavid Hildenbrand {
724da93626SDavid Hildenbrand 	mb();
73cd719531SJanis Schoetterl-Glausch 	report(code == lowcore.pgm_int_code,
74a299895bSThomas Huth 	       "Program interrupt: expected(%d) == received(%d)", code,
75cd719531SJanis Schoetterl-Glausch 	       lowcore.pgm_int_code);
764da93626SDavid Hildenbrand }
774da93626SDavid Hildenbrand 
784e5dd758SClaudio Imbrenda /**
794e5dd758SClaudio Imbrenda  * register_pgm_cleanup_func - Register a cleanup function for progam
804e5dd758SClaudio Imbrenda  * interrupts for the current CPU.
81*a0e236bdSNico Boehr  * @f: the cleanup function to be registered on the current CPU
824e5dd758SClaudio Imbrenda  *
834e5dd758SClaudio Imbrenda  * Register a cleanup function to be called at the end of the normal
844e5dd758SClaudio Imbrenda  * interrupt handling for program interrupts for this CPU.
854e5dd758SClaudio Imbrenda  *
864e5dd758SClaudio Imbrenda  * Pass NULL to unregister a previously registered cleanup function.
874e5dd758SClaudio Imbrenda  */
register_pgm_cleanup_func(void (* f)(struct stack_frame_int *))884e5dd758SClaudio Imbrenda void register_pgm_cleanup_func(void (*f)(struct stack_frame_int *))
89cc7bed1bSJanosch Frank {
904e5dd758SClaudio Imbrenda 	THIS_CPU->pgm_cleanup_func = f;
914e5dd758SClaudio Imbrenda }
924e5dd758SClaudio Imbrenda 
934e5dd758SClaudio Imbrenda /**
944e5dd758SClaudio Imbrenda  * register_ext_cleanup_func - Register a cleanup function for external
954e5dd758SClaudio Imbrenda  * interrupts for the current CPU.
96*a0e236bdSNico Boehr  * @f: the cleanup function to be registered on the current CPU
974e5dd758SClaudio Imbrenda  *
984e5dd758SClaudio Imbrenda  * Register a cleanup function to be called at the end of the normal
994e5dd758SClaudio Imbrenda  * interrupt handling for external interrupts for this CPU.
1004e5dd758SClaudio Imbrenda  *
1014e5dd758SClaudio Imbrenda  * Pass NULL to unregister a previously registered cleanup function.
1024e5dd758SClaudio Imbrenda  */
register_ext_cleanup_func(void (* f)(struct stack_frame_int *))1034e5dd758SClaudio Imbrenda void register_ext_cleanup_func(void (*f)(struct stack_frame_int *))
1044e5dd758SClaudio Imbrenda {
1054e5dd758SClaudio Imbrenda 	THIS_CPU->ext_cleanup_func = f;
106cc7bed1bSJanosch Frank }
107cc7bed1bSJanosch Frank 
108fedfd112SNico Boehr /**
109fedfd112SNico Boehr  * irq_set_dat_mode - Set the DAT mode of all interrupt handlers, except for
110fedfd112SNico Boehr  * restart.
111fedfd112SNico Boehr  * @use_dat: specifies whether to use DAT or not
112fedfd112SNico Boehr  * @as: specifies the address space mode to use. Not set if use_dat is false.
113fedfd112SNico Boehr  *
114fedfd112SNico Boehr  * This will update the DAT mode and address space mode of all interrupt new
115fedfd112SNico Boehr  * PSWs.
116fedfd112SNico Boehr  *
117fedfd112SNico Boehr  * Since enabling DAT needs initialized CRs and the restart new PSW is often used
118fedfd112SNico Boehr  * to initialize CRs, the restart new PSW is never touched to avoid the chicken
119fedfd112SNico Boehr  * and egg situation.
120fedfd112SNico Boehr  */
irq_set_dat_mode(bool use_dat,enum address_space as)121fedfd112SNico Boehr void irq_set_dat_mode(bool use_dat, enum address_space as)
122fedfd112SNico Boehr {
123fedfd112SNico Boehr 	struct psw* irq_psws[] = {
124fedfd112SNico Boehr 		OPAQUE_PTR(GEN_LC_EXT_NEW_PSW),
125fedfd112SNico Boehr 		OPAQUE_PTR(GEN_LC_SVC_NEW_PSW),
126fedfd112SNico Boehr 		OPAQUE_PTR(GEN_LC_PGM_NEW_PSW),
127fedfd112SNico Boehr 		OPAQUE_PTR(GEN_LC_MCCK_NEW_PSW),
128fedfd112SNico Boehr 		OPAQUE_PTR(GEN_LC_IO_NEW_PSW),
129fedfd112SNico Boehr 	};
130fedfd112SNico Boehr 	struct psw *psw;
131fedfd112SNico Boehr 
132fedfd112SNico Boehr 	assert(as == AS_PRIM || as == AS_ACCR || as == AS_SECN || as == AS_HOME);
133fedfd112SNico Boehr 
134fedfd112SNico Boehr 	for (size_t i = 0; i < ARRAY_SIZE(irq_psws); i++) {
135fedfd112SNico Boehr 		psw = irq_psws[i];
136fedfd112SNico Boehr 		psw->dat = use_dat;
137fedfd112SNico Boehr 		if (use_dat)
138fedfd112SNico Boehr 			psw->as = as;
139fedfd112SNico Boehr 	}
140fedfd112SNico Boehr }
141fedfd112SNico Boehr 
fixup_pgm_int(struct stack_frame_int * stack)14236cfc0b7SJanosch Frank static void fixup_pgm_int(struct stack_frame_int *stack)
1434da93626SDavid Hildenbrand {
1443ae7f80fSJanosch Frank 	/* If we have an error on SIE we directly move to sie_exit */
145cd719531SJanis Schoetterl-Glausch 	if (lowcore.pgm_old_psw.addr >= (uint64_t)&sie_entry &&
146cd719531SJanis Schoetterl-Glausch 	    lowcore.pgm_old_psw.addr <= (uint64_t)&sie_exit) {
147cd719531SJanis Schoetterl-Glausch 		lowcore.pgm_old_psw.addr = (uint64_t)&sie_exit;
14864fa4199SNico Boehr 		return;
1493ae7f80fSJanosch Frank 	}
1503ae7f80fSJanosch Frank 
151cd719531SJanis Schoetterl-Glausch 	switch (lowcore.pgm_int_code) {
1524ef6f57dSJanosch Frank 	case PGM_INT_CODE_PRIVILEGED_OPERATION:
1534ef6f57dSJanosch Frank 		/* Normal operation is in supervisor state, so this exception
1544ef6f57dSJanosch Frank 		 * was produced intentionally and we should return to the
1554ef6f57dSJanosch Frank 		 * supervisor state.
1564ef6f57dSJanosch Frank 		 */
157cd719531SJanis Schoetterl-Glausch 		lowcore.pgm_old_psw.mask &= ~PSW_MASK_PSTATE;
1584ef6f57dSJanosch Frank 		break;
15949a732c7SJanosch Frank 	case PGM_INT_CODE_PROTECTION:
16049a732c7SJanosch Frank 		/* Handling for iep.c test case. */
161c2c1663aSJanis Schoetterl-Glausch 		if (prot_is_iep((union teid) { .val = lowcore.trans_exc_id }))
16236cfc0b7SJanosch Frank 			/*
16336cfc0b7SJanosch Frank 			 * We branched to the instruction that caused
16436cfc0b7SJanosch Frank 			 * the exception so we can use the return
16536cfc0b7SJanosch Frank 			 * address in GR14 to jump back and continue
16636cfc0b7SJanosch Frank 			 * executing test code.
16736cfc0b7SJanosch Frank 			 */
168cd719531SJanis Schoetterl-Glausch 			lowcore.pgm_old_psw.addr = stack->grs0[12];
16949a732c7SJanosch Frank 		break;
1704da93626SDavid Hildenbrand 	case PGM_INT_CODE_SEGMENT_TRANSLATION:
1714da93626SDavid Hildenbrand 	case PGM_INT_CODE_PAGE_TRANSLATION:
1724da93626SDavid Hildenbrand 	case PGM_INT_CODE_TRACE_TABLE:
1734da93626SDavid Hildenbrand 	case PGM_INT_CODE_AFX_TRANSLATION:
1744da93626SDavid Hildenbrand 	case PGM_INT_CODE_ASX_TRANSLATION:
1754da93626SDavid Hildenbrand 	case PGM_INT_CODE_LX_TRANSLATION:
1764da93626SDavid Hildenbrand 	case PGM_INT_CODE_EX_TRANSLATION:
1774da93626SDavid Hildenbrand 	case PGM_INT_CODE_PRIMARY_AUTHORITY:
1784da93626SDavid Hildenbrand 	case PGM_INT_CODE_SECONDARY_AUTHORITY:
1794da93626SDavid Hildenbrand 	case PGM_INT_CODE_LFX_TRANSLATION:
1804da93626SDavid Hildenbrand 	case PGM_INT_CODE_LSX_TRANSLATION:
1814da93626SDavid Hildenbrand 	case PGM_INT_CODE_ALEN_TRANSLATION:
1824da93626SDavid Hildenbrand 	case PGM_INT_CODE_ALE_SEQUENCE:
1834da93626SDavid Hildenbrand 	case PGM_INT_CODE_ASTE_VALIDITY:
1844da93626SDavid Hildenbrand 	case PGM_INT_CODE_ASTE_SEQUENCE:
1854da93626SDavid Hildenbrand 	case PGM_INT_CODE_EXTENDED_AUTHORITY:
1864da93626SDavid Hildenbrand 	case PGM_INT_CODE_LSTE_SEQUENCE:
1874da93626SDavid Hildenbrand 	case PGM_INT_CODE_ASTE_INSTANCE:
1884da93626SDavid Hildenbrand 	case PGM_INT_CODE_STACK_FULL:
1894da93626SDavid Hildenbrand 	case PGM_INT_CODE_STACK_EMPTY:
1904da93626SDavid Hildenbrand 	case PGM_INT_CODE_STACK_SPECIFICATION:
1914da93626SDavid Hildenbrand 	case PGM_INT_CODE_STACK_TYPE:
1924da93626SDavid Hildenbrand 	case PGM_INT_CODE_STACK_OPERATION:
1934da93626SDavid Hildenbrand 	case PGM_INT_CODE_ASCE_TYPE:
1944da93626SDavid Hildenbrand 	case PGM_INT_CODE_REGION_FIRST_TRANS:
1954da93626SDavid Hildenbrand 	case PGM_INT_CODE_REGION_SECOND_TRANS:
1964da93626SDavid Hildenbrand 	case PGM_INT_CODE_REGION_THIRD_TRANS:
1974da93626SDavid Hildenbrand 	case PGM_INT_CODE_PER:
1984da93626SDavid Hildenbrand 	case PGM_INT_CODE_CRYPTO_OPERATION:
19968721b97SJanosch Frank 	case PGM_INT_CODE_SECURE_STOR_ACCESS:
20068721b97SJanosch Frank 	case PGM_INT_CODE_NON_SECURE_STOR_ACCESS:
20168721b97SJanosch Frank 	case PGM_INT_CODE_SECURE_STOR_VIOLATION:
2024da93626SDavid Hildenbrand 		/* The interrupt was nullified, the old PSW points at the
2034da93626SDavid Hildenbrand 		 * responsible instruction. Forward the PSW so we don't loop.
2044da93626SDavid Hildenbrand 		 */
205cd719531SJanis Schoetterl-Glausch 		lowcore.pgm_old_psw.addr += lowcore.pgm_int_id;
2064da93626SDavid Hildenbrand 	}
2074da93626SDavid Hildenbrand 	/* suppressed/terminated/completed point already at the next address */
2084da93626SDavid Hildenbrand }
2094da93626SDavid Hildenbrand 
print_storage_exception_information(void)2101921c4c6SJanosch Frank static void print_storage_exception_information(void)
2111921c4c6SJanosch Frank {
212cd719531SJanis Schoetterl-Glausch 	switch (lowcore.pgm_int_code) {
2131921c4c6SJanosch Frank 	case PGM_INT_CODE_PROTECTION:
2141921c4c6SJanosch Frank 	case PGM_INT_CODE_PAGE_TRANSLATION:
2151921c4c6SJanosch Frank 	case PGM_INT_CODE_SEGMENT_TRANSLATION:
2161921c4c6SJanosch Frank 	case PGM_INT_CODE_ASCE_TYPE:
2171921c4c6SJanosch Frank 	case PGM_INT_CODE_REGION_FIRST_TRANS:
2181921c4c6SJanosch Frank 	case PGM_INT_CODE_REGION_SECOND_TRANS:
2191921c4c6SJanosch Frank 	case PGM_INT_CODE_REGION_THIRD_TRANS:
2201921c4c6SJanosch Frank 	case PGM_INT_CODE_SECURE_STOR_ACCESS:
2211921c4c6SJanosch Frank 	case PGM_INT_CODE_NON_SECURE_STOR_ACCESS:
2221921c4c6SJanosch Frank 	case PGM_INT_CODE_SECURE_STOR_VIOLATION:
223cd719531SJanis Schoetterl-Glausch 		print_decode_teid(lowcore.trans_exc_id);
2241921c4c6SJanosch Frank 		break;
2251921c4c6SJanosch Frank 	}
2261921c4c6SJanosch Frank }
2271921c4c6SJanosch Frank 
print_int_regs(struct stack_frame_int * stack,bool sie)228cdc9bd7bSJanosch Frank static void print_int_regs(struct stack_frame_int *stack, bool sie)
229f470061dSJanosch Frank {
230cdc9bd7bSJanosch Frank 	struct kvm_s390_sie_block *sblk;
231cdc9bd7bSJanosch Frank 
232f470061dSJanosch Frank 	printf("\n");
233cdc9bd7bSJanosch Frank 	printf("%s\n", sie ? "Guest registers:" : "Host registers:");
234f470061dSJanosch Frank 	printf("GPRS:\n");
235f470061dSJanosch Frank 	printf("%016lx %016lx %016lx %016lx\n",
236f470061dSJanosch Frank 	       stack->grs1[0], stack->grs1[1], stack->grs0[0], stack->grs0[1]);
237f470061dSJanosch Frank 	printf("%016lx %016lx %016lx %016lx\n",
238f470061dSJanosch Frank 	       stack->grs0[2], stack->grs0[3], stack->grs0[4], stack->grs0[5]);
239f470061dSJanosch Frank 	printf("%016lx %016lx %016lx %016lx\n",
240f470061dSJanosch Frank 	       stack->grs0[6], stack->grs0[7], stack->grs0[8], stack->grs0[9]);
241cdc9bd7bSJanosch Frank 
242cdc9bd7bSJanosch Frank 	if (sie) {
243cdc9bd7bSJanosch Frank 		sblk = (struct kvm_s390_sie_block *)stack->grs0[12];
244cdc9bd7bSJanosch Frank 		printf("%016lx %016lx %016lx %016lx\n",
245cdc9bd7bSJanosch Frank 		       stack->grs0[10], stack->grs0[11], sblk->gg14, sblk->gg15);
246cdc9bd7bSJanosch Frank 	} else {
247f470061dSJanosch Frank 		printf("%016lx %016lx %016lx %016lx\n",
248f470061dSJanosch Frank 		       stack->grs0[10], stack->grs0[11], stack->grs0[12], stack->grs0[13]);
249cdc9bd7bSJanosch Frank 	}
250cdc9bd7bSJanosch Frank 
251f470061dSJanosch Frank 	printf("\n");
252f470061dSJanosch Frank }
253f470061dSJanosch Frank 
print_pgm_info(struct stack_frame_int * stack)254f470061dSJanosch Frank static void print_pgm_info(struct stack_frame_int *stack)
255f470061dSJanosch Frank 
256f470061dSJanosch Frank {
257cdc9bd7bSJanosch Frank 	bool in_sie, in_sie_gregs;
258cdc9bd7bSJanosch Frank 	struct vm_save_area *vregs;
2597f5b10b7SJanosch Frank 
260cd719531SJanis Schoetterl-Glausch 	in_sie = (lowcore.pgm_old_psw.addr >= (uintptr_t)sie_entry &&
261cd719531SJanis Schoetterl-Glausch 		  lowcore.pgm_old_psw.addr <= (uintptr_t)sie_exit);
262cdc9bd7bSJanosch Frank 	in_sie_gregs = (lowcore.pgm_old_psw.addr >= (uintptr_t)sie_entry_gregs &&
263cdc9bd7bSJanosch Frank 			lowcore.pgm_old_psw.addr < (uintptr_t)sie_exit_gregs);
2647f5b10b7SJanosch Frank 
265f470061dSJanosch Frank 	printf("\n");
26661f45abaSJanosch Frank 	printf("Unexpected program interrupt %s: %#x on cpu %d at %#lx, ilen %d\n",
2677f5b10b7SJanosch Frank 	       in_sie ? "in SIE" : "",
268cd719531SJanis Schoetterl-Glausch 	       lowcore.pgm_int_code, stap(), lowcore.pgm_old_psw.addr, lowcore.pgm_int_id);
269cdc9bd7bSJanosch Frank 
270cdc9bd7bSJanosch Frank 	/*
271cdc9bd7bSJanosch Frank 	 * If we fall out of SIE before loading the host registers,
272cdc9bd7bSJanosch Frank 	 * then we need to do it here so we print the host registers
273cdc9bd7bSJanosch Frank 	 * and not the guest registers.
274cdc9bd7bSJanosch Frank 	 *
275cdc9bd7bSJanosch Frank 	 * Back tracing is actually not a problem since SIE restores gr15.
276cdc9bd7bSJanosch Frank 	 */
277cdc9bd7bSJanosch Frank 	if (in_sie_gregs) {
278cdc9bd7bSJanosch Frank 		print_int_regs(stack, true);
279cdc9bd7bSJanosch Frank 		vregs = *((struct vm_save_area **)(stack->grs0[13] + __SF_SIE_SAVEAREA));
280cdc9bd7bSJanosch Frank 
281cdc9bd7bSJanosch Frank 		/*
282cdc9bd7bSJanosch Frank 		 * The grs are not linear on the interrupt stack frame.
283cdc9bd7bSJanosch Frank 		 * We copy 0 and 1 here and 2 - 15 with the memcopy below.
284cdc9bd7bSJanosch Frank 		 */
285cdc9bd7bSJanosch Frank 		stack->grs1[0] = vregs->host.grs[0];
286cdc9bd7bSJanosch Frank 		stack->grs1[1] = vregs->host.grs[1];
287cdc9bd7bSJanosch Frank 		/*  2 - 15 */
288cdc9bd7bSJanosch Frank 		memcpy(stack->grs0, &vregs->host.grs[2], sizeof(stack->grs0) - 8);
289cdc9bd7bSJanosch Frank 	}
290cdc9bd7bSJanosch Frank 	print_int_regs(stack, false);
291f470061dSJanosch Frank 	dump_stack();
2921921c4c6SJanosch Frank 
2931921c4c6SJanosch Frank 	/* Dump stack doesn't end with a \n so we add it here instead */
2941921c4c6SJanosch Frank 	printf("\n");
2951921c4c6SJanosch Frank 	print_storage_exception_information();
296f470061dSJanosch Frank 	report_summary();
297f470061dSJanosch Frank 	abort();
298f470061dSJanosch Frank }
299f470061dSJanosch Frank 
handle_pgm_int(struct stack_frame_int * stack)30036cfc0b7SJanosch Frank void handle_pgm_int(struct stack_frame_int *stack)
3014da93626SDavid Hildenbrand {
30289ce5095SClaudio Imbrenda 	if (THIS_CPU->in_interrupt_handler) {
30389ce5095SClaudio Imbrenda 		/* Something went very wrong, stop everything now without printing anything */
30489ce5095SClaudio Imbrenda 		smp_teardown();
30589ce5095SClaudio Imbrenda 		disabled_wait(0xfa12edbad21);
30689ce5095SClaudio Imbrenda 	}
3074e5dd758SClaudio Imbrenda 	if (!THIS_CPU->pgm_int_expected) {
30847d7b1c0SClaudio Imbrenda 		/* Force sclp_busy to false, otherwise we will loop forever */
30947d7b1c0SClaudio Imbrenda 		sclp_handle_ext();
310f470061dSJanosch Frank 		print_pgm_info(stack);
31147d7b1c0SClaudio Imbrenda 	}
3124da93626SDavid Hildenbrand 
3134e5dd758SClaudio Imbrenda 	THIS_CPU->pgm_int_expected = false;
31489ce5095SClaudio Imbrenda 	THIS_CPU->in_interrupt_handler = true;
315cc7bed1bSJanosch Frank 
3164e5dd758SClaudio Imbrenda 	if (THIS_CPU->pgm_cleanup_func)
3174e5dd758SClaudio Imbrenda 		THIS_CPU->pgm_cleanup_func(stack);
318cc7bed1bSJanosch Frank 	else
31936cfc0b7SJanosch Frank 		fixup_pgm_int(stack);
32089ce5095SClaudio Imbrenda 	THIS_CPU->in_interrupt_handler = false;
3214da93626SDavid Hildenbrand }
3220f87a91aSJanosch Frank 
handle_ext_int(struct stack_frame_int * stack)32336cfc0b7SJanosch Frank void handle_ext_int(struct stack_frame_int *stack)
3240f87a91aSJanosch Frank {
32589ce5095SClaudio Imbrenda 	THIS_CPU->in_interrupt_handler = true;
3264e5dd758SClaudio Imbrenda 	if (!THIS_CPU->ext_int_expected && lowcore.ext_int_code != EXT_IRQ_SERVICE_SIG) {
327081f4662SJanosch Frank 		report_abort("Unexpected external call interrupt (code %#x): on cpu %d at %#lx",
328cd719531SJanis Schoetterl-Glausch 			     lowcore.ext_int_code, stap(), lowcore.ext_old_psw.addr);
329df121a0cSJanosch Frank 		return;
330df121a0cSJanosch Frank 	}
331df121a0cSJanosch Frank 
332cd719531SJanis Schoetterl-Glausch 	if (lowcore.ext_int_code == EXT_IRQ_SERVICE_SIG) {
33336cfc0b7SJanosch Frank 		stack->crs[0] &= ~(1UL << 9);
3348ead801eSJanosch Frank 		sclp_handle_ext();
335df121a0cSJanosch Frank 	} else {
3364e5dd758SClaudio Imbrenda 		THIS_CPU->ext_int_expected = false;
3378ead801eSJanosch Frank 	}
338df121a0cSJanosch Frank 
33936cfc0b7SJanosch Frank 	if (!(stack->crs[0] & CR0_EXTM_MASK))
340cd719531SJanis Schoetterl-Glausch 		lowcore.ext_old_psw.mask &= ~PSW_MASK_EXT;
3414e5dd758SClaudio Imbrenda 
3424e5dd758SClaudio Imbrenda 	if (THIS_CPU->ext_cleanup_func)
3434e5dd758SClaudio Imbrenda 		THIS_CPU->ext_cleanup_func(stack);
34489ce5095SClaudio Imbrenda 	THIS_CPU->in_interrupt_handler = false;
3450f87a91aSJanosch Frank }
3460f87a91aSJanosch Frank 
handle_mcck_int(void)3470f87a91aSJanosch Frank void handle_mcck_int(void)
3480f87a91aSJanosch Frank {
349081f4662SJanosch Frank 	report_abort("Unexpected machine check interrupt: on cpu %d at %#lx",
350cd719531SJanis Schoetterl-Glausch 		     stap(), lowcore.mcck_old_psw.addr);
3510f87a91aSJanosch Frank }
3520f87a91aSJanosch Frank 
353adc7ff44SPierre Morel static void (*io_int_func)(void);
354adc7ff44SPierre Morel 
handle_io_int(void)3550f87a91aSJanosch Frank void handle_io_int(void)
3560f87a91aSJanosch Frank {
35789ce5095SClaudio Imbrenda 	THIS_CPU->in_interrupt_handler = true;
358adc7ff44SPierre Morel 	if (io_int_func)
35989ce5095SClaudio Imbrenda 		io_int_func();
36089ce5095SClaudio Imbrenda 	else
361081f4662SJanosch Frank 		report_abort("Unexpected io interrupt: on cpu %d at %#lx",
362cd719531SJanis Schoetterl-Glausch 			     stap(), lowcore.io_old_psw.addr);
36389ce5095SClaudio Imbrenda 	THIS_CPU->in_interrupt_handler = false;
3640f87a91aSJanosch Frank }
3650f87a91aSJanosch Frank 
register_io_int_func(void (* f)(void))366adc7ff44SPierre Morel int register_io_int_func(void (*f)(void))
367adc7ff44SPierre Morel {
368adc7ff44SPierre Morel 	if (io_int_func)
369adc7ff44SPierre Morel 		return -1;
370adc7ff44SPierre Morel 	io_int_func = f;
371adc7ff44SPierre Morel 	return 0;
372adc7ff44SPierre Morel }
373adc7ff44SPierre Morel 
unregister_io_int_func(void (* f)(void))374adc7ff44SPierre Morel int unregister_io_int_func(void (*f)(void))
375adc7ff44SPierre Morel {
376adc7ff44SPierre Morel 	if (io_int_func != f)
377adc7ff44SPierre Morel 		return -1;
378adc7ff44SPierre Morel 	io_int_func = NULL;
379adc7ff44SPierre Morel 	return 0;
380adc7ff44SPierre Morel }
381adc7ff44SPierre Morel 
handle_svc_int(void)3820f87a91aSJanosch Frank void handle_svc_int(void)
3830f87a91aSJanosch Frank {
384cd719531SJanis Schoetterl-Glausch 	uint16_t code = lowcore.svc_int_code;
385b43c912fSClaudio Imbrenda 
386b43c912fSClaudio Imbrenda 	switch (code) {
387b43c912fSClaudio Imbrenda 	case SVC_LEAVE_PSTATE:
388cd719531SJanis Schoetterl-Glausch 		lowcore.svc_old_psw.mask &= ~PSW_MASK_PSTATE;
389b43c912fSClaudio Imbrenda 		break;
390b43c912fSClaudio Imbrenda 	default:
391b43c912fSClaudio Imbrenda 		report_abort("Unexpected supervisor call interrupt: code %#x on cpu %d at %#lx",
392cd719531SJanis Schoetterl-Glausch 			      code, stap(), lowcore.svc_old_psw.addr);
393b43c912fSClaudio Imbrenda 	}
3940f87a91aSJanosch Frank }
395