xref: /kvm-unit-tests/lib/x86/fault_test.h (revision 2bac62497563c072d0325ad5841008e68033eced)
1*2bac6249SArbel Moshe #ifndef __FAULT_TEST__
2*2bac6249SArbel Moshe #define __FAULT_TEST__
3*2bac6249SArbel Moshe 
4*2bac6249SArbel Moshe #include "x86/msr.h"
5*2bac6249SArbel Moshe #include "x86/processor.h"
6*2bac6249SArbel Moshe #include "x86/apic-defs.h"
7*2bac6249SArbel Moshe #include "x86/apic.h"
8*2bac6249SArbel Moshe #include "x86/desc.h"
9*2bac6249SArbel Moshe #include "x86/isr.h"
10*2bac6249SArbel Moshe #include "alloc.h"
11*2bac6249SArbel Moshe #include "setjmp.h"
12*2bac6249SArbel Moshe #include "usermode.h"
13*2bac6249SArbel Moshe 
14*2bac6249SArbel Moshe #include "libcflat.h"
15*2bac6249SArbel Moshe #include <stdint.h>
16*2bac6249SArbel Moshe 
17*2bac6249SArbel Moshe #define FAULT_TEST(nm, a) { .name = nm, .arg = a}
18*2bac6249SArbel Moshe 
19*2bac6249SArbel Moshe struct fault_test_arg;
20*2bac6249SArbel Moshe 
21*2bac6249SArbel Moshe typedef uint64_t (*test_fault_func)(uint64_t arg1, uint64_t arg2,
22*2bac6249SArbel Moshe 		uint64_t arg3, uint64_t arg4);
23*2bac6249SArbel Moshe typedef bool (*test_fault_callback)(struct fault_test_arg *arg);
24*2bac6249SArbel Moshe 
25*2bac6249SArbel Moshe struct fault_test_arg {
26*2bac6249SArbel Moshe 	bool usermode;
27*2bac6249SArbel Moshe 	unsigned int fault_vector;
28*2bac6249SArbel Moshe 	bool should_fault;
29*2bac6249SArbel Moshe 	uint64_t arg[4];
30*2bac6249SArbel Moshe 	uint64_t retval;
31*2bac6249SArbel Moshe 	test_fault_func func;
32*2bac6249SArbel Moshe 	test_fault_callback callback;
33*2bac6249SArbel Moshe };
34*2bac6249SArbel Moshe 
35*2bac6249SArbel Moshe struct fault_test {
36*2bac6249SArbel Moshe 	const char *name;
37*2bac6249SArbel Moshe 	struct fault_test_arg arg;
38*2bac6249SArbel Moshe };
39*2bac6249SArbel Moshe 
40*2bac6249SArbel Moshe void test_run(struct fault_test *test);
41*2bac6249SArbel Moshe 
42*2bac6249SArbel Moshe #endif
43