xref: /illumos-gate/usr/src/lib/libvmm/libvmm.h (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
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 2019 Joyent, Inc.
14  */
15 
16 #ifndef _LIBVMM_H
17 #define	_LIBVMM_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 typedef struct vmm vmm_t;
24 
25 typedef struct vmm_desc {
26 	uint64_t vd_base;
27 	uint32_t vd_lim;
28 	uint32_t vd_acc;
29 } vmm_desc_t;
30 
31 
32 /*
33  * This enum must be kept in sync with vmm_sys_regmap[] in libvmm.c.
34  */
35 #define	VMM_REG_OFFSET	0x100
36 enum vmm_regs {
37 	VMM_REG_CR0 = VMM_REG_OFFSET,
38 	VMM_REG_CR2,
39 	VMM_REG_CR3,
40 	VMM_REG_CR4,
41 	VMM_REG_DR0,
42 	VMM_REG_DR1,
43 	VMM_REG_DR2,
44 	VMM_REG_DR3,
45 	VMM_REG_DR6,
46 	VMM_REG_DR7,
47 	VMM_REG_EFER,
48 	VMM_REG_PDPTE0,
49 	VMM_REG_PDPTE1,
50 	VMM_REG_PDPTE2,
51 	VMM_REG_PDPTE3,
52 	VMM_REG_INTR_SHADOW
53 };
54 
55 /*
56  * This enum must be kept in sync with vmm_descmap[] in libvmm.c.
57  */
58 #define	VMM_DESC_OFFSET	0x200
59 enum vmm_descs {
60 	VMM_DESC_GDTR = VMM_DESC_OFFSET,
61 	VMM_DESC_LDTR,
62 	VMM_DESC_IDTR,
63 	VMM_DESC_TR,
64 	VMM_DESC_CS,
65 	VMM_DESC_DS,
66 	VMM_DESC_ES,
67 	VMM_DESC_FS,
68 	VMM_DESC_GS,
69 	VMM_DESC_SS
70 };
71 
72 typedef enum {
73 	VMM_MODE_UNKNOWN = 0,
74 	VMM_MODE_REAL,
75 	VMM_MODE_PROT,
76 	VMM_MODE_PAE,
77 	VMM_MODE_LONG
78 } vmm_mode_t;
79 
80 typedef enum {
81 	VMM_ISA_UNKNOWN = 0,
82 	VMM_ISA_16,
83 	VMM_ISA_32,
84 	VMM_ISA_64
85 } vmm_isa_t;
86 
87 vmm_t *vmm_open_vm(const char *);
88 void vmm_close_vm(vmm_t *);
89 
90 int vmm_map(vmm_t *, boolean_t);
91 void vmm_unmap(vmm_t *);
92 
93 ssize_t vmm_pread(vmm_t *, void *, size_t, uintptr_t);
94 ssize_t vmm_pwrite(vmm_t *, const void *, size_t, uintptr_t);
95 ssize_t vmm_vread(vmm_t *, int, int, void *, size_t, uintptr_t);
96 ssize_t vmm_vwrite(vmm_t *, int, int, const void *, size_t, uintptr_t);
97 
98 size_t vmm_ncpu(vmm_t *);
99 size_t vmm_memsize(vmm_t *);
100 
101 int vmm_cont(vmm_t *);
102 int vmm_step(vmm_t *, int);
103 int vmm_stop(vmm_t *);
104 
105 int vmm_getreg(vmm_t *, int, int, uint64_t *);
106 int vmm_setreg(vmm_t *, int, int, uint64_t);
107 int vmm_get_regset(vmm_t *, int, size_t, const int *, uint64_t *);
108 int vmm_set_regset(vmm_t *, int, size_t, const int *, uint64_t *);
109 
110 int vmm_get_desc(vmm_t *, int, int, vmm_desc_t *);
111 int vmm_set_desc(vmm_t *, int, int, vmm_desc_t *);
112 
113 vmm_mode_t vmm_vcpu_mode(vmm_t *, int);
114 vmm_isa_t vmm_vcpu_isa(vmm_t *, int);
115 int vmm_vtol(vmm_t *, int, int, uint64_t, uint64_t *);
116 int vmm_vtop(vmm_t *, int, int, uint64_t, uint64_t *);
117 
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif /* _LIBVMM_H */
123