new file mode 100644
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Commonly used checks for PV SIE intercept data
+ *
+ * Copyright IBM Corp. 2023
+ * Author: Janosch Frank <frankja@linux.ibm.com>
+ */
+
+#ifndef _S390X_PV_ICPTDATA_H_
+#define _S390X_PV_ICPTDATA_H_
+
+#include <sie.h>
+
+/*
+ * Checks the diagnose instruction intercept data for consistency with
+ * the constants defined by the PV SIE architecture
+ *
+ * Supports: 0x44, 0x9c, 0x288, 0x308, 0x500
+ */
+static bool pv_icptdata_check_diag(struct vm *vm, int diag)
+{
+ int icptcode;
+
+ switch (diag) {
+ case 0x44:
+ case 0x9c:
+ case 0x288:
+ case 0x308:
+ icptcode = ICPT_PV_NOTIFY;
+ break;
+ case 0x500:
+ icptcode = ICPT_PV_INSTR;
+ break;
+ default:
+ /* If a new diag is introduced add it to the cases above! */
+ assert(0);
+ }
+
+ return vm->sblk->icptcode == icptcode && vm->sblk->ipa == 0x8302 &&
+ vm->sblk->ipb == 0x50000000 && vm->save_area.guest.grs[5] == diag;
+}
+#endif
@@ -9,6 +9,7 @@
*/
#include <libcflat.h>
#include <snippet.h>
+#include <pv_icptdata.h>
#include <sie.h>
#include <sclp.h>
#include <asm/facility.h>
@@ -31,8 +32,7 @@ static void test_diag_500(void)
size_gbin, size_hdr, SNIPPET_UNPACK_OFF);
sie(&vm);
- report(vm.sblk->icptcode == ICPT_PV_INSTR && vm.sblk->ipa == 0x8302 &&
- vm.sblk->ipb == 0x50000000 && vm.save_area.guest.grs[5] == 0x500,
+ report(pv_icptdata_check_diag(&vm, 0x500),
"intercept values");
report(vm.save_area.guest.grs[1] == 1 &&
vm.save_area.guest.grs[2] == 2 &&
@@ -45,9 +45,8 @@ static void test_diag_500(void)
*/
vm.sblk->iictl = IICTL_CODE_OPERAND;
sie(&vm);
- report(vm.sblk->icptcode == ICPT_PV_NOTIFY && vm.sblk->ipa == 0x8302 &&
- vm.sblk->ipb == 0x50000000 && vm.save_area.guest.grs[5] == 0x9c
- && vm.save_area.guest.grs[0] == PGM_INT_CODE_OPERAND,
+ report(pv_icptdata_check_diag(&vm, 0x9c) &&
+ vm.save_area.guest.grs[0] == PGM_INT_CODE_OPERAND,
"operand exception");
/*
@@ -58,9 +57,8 @@ static void test_diag_500(void)
vm.sblk->iictl = IICTL_CODE_SPECIFICATION;
/* Inject PGM, next exit should be 9c */
sie(&vm);
- report(vm.sblk->icptcode == ICPT_PV_NOTIFY && vm.sblk->ipa == 0x8302 &&
- vm.sblk->ipb == 0x50000000 && vm.save_area.guest.grs[5] == 0x9c
- && vm.save_area.guest.grs[0] == PGM_INT_CODE_SPECIFICATION,
+ report(pv_icptdata_check_diag(&vm, 0x9c) &&
+ vm.save_area.guest.grs[0] == PGM_INT_CODE_SPECIFICATION,
"specification exception");
/* No need for cleanup, just tear down the VM */