xref: /illumos-gate/usr/src/test/bhyve-tests/tests/common/payload_utils.h (revision 8ed63bc6926cb5db26dff2588e5d1622eda438ab)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2025 Oxide Computer Company
14  */
15 
16 #ifndef _PAYLOAD_UTILS_H_
17 #define	_PAYLOAD_UTILS_H_
18 
19 #include <sys/types.h>
20 #include <stdbool.h>
21 
22 void outb(uint16_t, uint8_t);
23 void outw(uint16_t, uint16_t);
24 void outl(uint16_t, uint32_t);
25 uint8_t inb(uint16_t);
26 uint16_t inw(uint16_t);
27 uint32_t inl(uint16_t);
28 uint64_t rdmsr(uint32_t);
29 void wrmsr(uint32_t, uint64_t);
30 void cpuid(uint32_t, uint32_t, uint32_t *);
31 uint64_t rdtsc(void);
32 void ud2a(void);
33 void setcr4(uint64_t);
34 uint64_t getcr4(void);
35 void setxcr(uint32_t, uint64_t);
36 uint64_t getxcr(uint32_t);
37 
38 void test_result_pass(void);
39 void test_result_fail(void);
40 void test_msg(const char *);
41 
42 #define	__STR2(x)	#x
43 #define	__STR(x)	__STR2(x)
44 
45 #define	TEST_ABORT(msg)							\
46 	do {								\
47 		test_msg(__FILE__ ":" __STR(__LINE__) " - " msg);	\
48 		test_result_fail();					\
49 	} while (0)
50 
51 #endif /* _PAYLOAD_UTILS_H_ */
52