Fixes file headers
[freebsd-src/fkvm-freebsd.git] / sys / amd64 / include / vmcb.h
blob5b6c726885ce1f38d666655fd59a8cedd5706883
1 /*-
2 * Copyright (c) 2008 Brent Stephens <brents@rice.edu>
3 * Copyright (c) 2008 Diego Ongaro <diego.ongaro@rice.edu>
4 * Copyright (c) 2008 Kaushik Kumar Ram <kaushik@rice.edu>
5 * Copyright (c) 2008 Oleg Pesok <olegpesok@gmail.com>
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
30 #ifndef VMCB_H
31 #define VMCB_H
33 struct __attribute__ ((__packed__)) vmcb_control_area {
34 uint16_t intercept_cr_reads;
35 uint16_t intercept_cr_writes;
36 uint16_t intercept_dr_reads;
37 uint16_t intercept_dr_writes;
38 uint32_t intercept_exceptions;
39 uint64_t intercepts;
40 uint8_t reserved_1[44]; /* Should be Zero */
41 uint64_t iopm_base_pa;
42 uint64_t msrpm_base_pa;
43 uint64_t tsc_offset;
44 uint32_t guest_asid;
45 uint8_t tlb_control;
46 uint8_t reserved_2[3]; /* Should be Zero */
47 uint8_t v_tpr;
48 uint8_t v_irq;
49 uint8_t v_intr;
50 uint8_t v_intr_masking;
51 uint8_t v_intr_vector;
52 uint8_t reserved_6[3]; /* Should be Zero */
53 uint8_t intr_shadow; /* Bits 7-1 Should be zero */
54 uint8_t reserved_7[7];
55 uint64_t exit_code; /* TODO: in kvm this is 2 uint32. figure out why */
56 uint64_t exit_info_1;
57 uint64_t exit_info_2;
58 uint32_t exit_int_info;
59 uint32_t exit_int_info_err_code;
60 uint64_t nested_ctl;
61 uint8_t reserved_8[16];
62 uint64_t event_inj; /* TODO: in kvm this is 2 uint32 */
63 uint64_t nested_cr3;
64 uint64_t lbr_virt_enable;
65 uint8_t reserved_9[832];
68 struct __attribute__ ((__packed__)) vmcb_seg {
69 uint16_t selector;
70 uint16_t attrib;
71 uint32_t limit;
72 uint64_t base;
75 struct __attribute__ ((__packed__)) vmcb_save_area {
76 struct vmcb_seg es;
77 struct vmcb_seg cs;
78 struct vmcb_seg ss;
79 struct vmcb_seg ds;
80 struct vmcb_seg fs;
81 struct vmcb_seg gs;
82 struct vmcb_seg gdtr;
83 struct vmcb_seg ldtr;
84 struct vmcb_seg idtr;
85 struct vmcb_seg tr;
86 uint8_t reserved_1[43];
87 uint8_t cpl;
88 uint8_t reserved_2[4];
89 uint64_t efer;
90 uint8_t reserved_3[112];
91 uint64_t cr4;
92 uint64_t cr3;
93 uint64_t cr0;
94 uint64_t dr7;
95 uint64_t dr6;
96 uint64_t rflags;
97 uint64_t rip;
98 uint8_t reserved_4[88];
99 uint64_t rsp;
100 uint8_t reserved_5[24];
101 uint64_t rax;
102 uint64_t star;
103 uint64_t lstar;
104 uint64_t cstar;
105 uint64_t sfmask;
106 uint64_t kernel_gs_base;
107 uint64_t sysenter_cs;
108 uint64_t sysenter_esp;
109 uint64_t sysenter_eip;
110 uint64_t cr2;
111 uint8_t reserved_6[32];
112 uint64_t g_pat;
113 uint64_t dbg_ctl;
114 uint64_t br_from;
115 uint64_t br_to;
116 uint64_t last_excp_from;
117 uint64_t last_excp_to;
120 struct __attribute__ ((__packed__)) vmcb {
121 struct vmcb_control_area control;
122 struct vmcb_save_area save;
125 /***********************************/
126 /************ Intercepts ***********/
127 /***********************************/
128 #define MAKE_INTERCEPT(x) (1ULL << (x))
129 #define INTERCEPT_NOTHING (0)
130 #define INTERCEPT_INTR MAKE_INTERCEPT(0)
131 #define INTERCEPT_NMI MAKE_INTERCEPT(1)
132 #define INTERCEPT_SMI MAKE_INTERCEPT(2)
133 #define INTERCEPT_INIT MAKE_INTERCEPT(3)
134 #define INTERCEPT_VINTR MAKE_INTERCEPT(4)
135 #define INTERCEPT_CR0 MAKE_INTERCEPT(5)
136 #define INTERCEPT_READ_IDTR MAKE_INTERCEPT(6)
137 #define INTERCEPT_READ_GDTR MAKE_INTERCEPT(7)
138 #define INTERCEPT_READ_LDTR MAKE_INTERCEPT(8)
139 #define INTERCEPT_READ_TR MAKE_INTERCEPT(9)
140 #define INTERCEPT_WRITE_IDTR MAKE_INTERCEPT(10)
141 #define INTERCEPT_WRITE_GDTR MAKE_INTERCEPT(11)
142 #define INTERCEPT_WRITE_LDTR MAKE_INTERCEPT(12)
143 #define INTERCEPT_WRITE_TR MAKE_INTERCEPT(13)
144 #define INTERCEPT_RDTSC MAKE_INTERCEPT(14)
145 #define INTERCEPT_RDPMC MAKE_INTERCEPT(15)
146 #define INTERCEPT_PUSHF MAKE_INTERCEPT(16)
147 #define INTERCEPT_POPF MAKE_INTERCEPT(17)
148 #define INTERCEPT_CPUID MAKE_INTERCEPT(18)
149 #define INTERCEPT_RSM MAKE_INTERCEPT(19)
150 #define INTERCEPT_IRET MAKE_INTERCEPT(20)
151 #define INTERCEPT_INTn MAKE_INTERCEPT(21)
152 #define INTERCEPT_INVD MAKE_INTERCEPT(22)
153 #define INTERCEPT_PAUSE MAKE_INTERCEPT(23)
154 #define INTERCEPT_HLT MAKE_INTERCEPT(24)
155 #define INTERCEPT_INVLPG MAKE_INTERCEPT(25)
156 #define INTERCEPT_INVLPGA MAKE_INTERCEPT(26)
157 #define INTERCEPT_IOIO_PROT MAKE_INTERCEPT(27)
158 #define INTERCEPT_MSR_PROT MAKE_INTERCEPT(28)
159 #define INTERCEPT_TASK_SWITCH MAKE_INTERCEPT(29)
160 #define INTERCEPT_FERR_FREEZE MAKE_INTERCEPT(30)
161 #define INTERCEPT_SHUTDOWN MAKE_INTERCEPT(31)
162 #define INTERCEPT_VMRUN MAKE_INTERCEPT(32)
163 #define INTERCEPT_VMMCALL MAKE_INTERCEPT(33)
164 #define INTERCEPT_VMLOAD MAKE_INTERCEPT(34)
165 #define INTERCEPT_VMSAVE MAKE_INTERCEPT(35)
166 #define INTERCEPT_STGI MAKE_INTERCEPT(36)
167 #define INTERCEPT_CLGI MAKE_INTERCEPT(37)
168 #define INTERCEPT_SKINIT MAKE_INTERCEPT(38)
169 #define INTERCEPT_RDTSCP MAKE_INTERCEPT(39)
170 #define INTERCEPT_ICEBP MAKE_INTERCEPT(40)
171 #define INTERCEPT_WBINVD MAKE_INTERCEPT(41)
172 #define INTERCEPT_MONITOR MAKE_INTERCEPT(42)
173 #define INTERCEPT_MWAIT_UNCOND MAKE_INTERCEPT(43)
174 #define INTERCEPT_MWAIT_COND MAKE_INTERCEPT(44)
176 #define INTERCEPT_CR0_MASK MAKE_INTERCEPT(0)
177 #define INTERCEPT_CR3_MASK MAKE_INTERCEPT(3)
178 #define INTERCEPT_CR4_MASK MAKE_INTERCEPT(4)
179 #define INTERCEPT_CR8_MASK MAKE_INTERCEPT(8)
181 #define INTERCEPT_DR0_MASK MAKE_INTERCEPT(0)
182 #define INTERCEPT_DR1_MASK MAKE_INTERCEPT(1)
183 #define INTERCEPT_DR2_MASK MAKE_INTERCEPT(2)
184 #define INTERCEPT_DR3_MASK MAKE_INTERCEPT(3)
185 #define INTERCEPT_DR4_MASK MAKE_INTERCEPT(4)
186 #define INTERCEPT_DR5_MASK MAKE_INTERCEPT(5)
187 #define INTERCEPT_DR6_MASK MAKE_INTERCEPT(6)
188 #define INTERCEPT_DR7_MASK MAKE_INTERCEPT(7)
190 /***********************************/
191 /************ Exit Codes ***********/
192 /***********************************/
193 #define VMCB_EXIT_READ_CR0 0x000
194 #define VMCB_EXIT_READ_CR3 0x003
195 #define VMCB_EXIT_READ_CR4 0x004
196 #define VMCB_EXIT_READ_CR8 0x008
197 #define VMCB_EXIT_WRITE_CR0 0x010
198 #define VMCB_EXIT_WRITE_CR3 0x013
199 #define VMCB_EXIT_WRITE_CR4 0x014
200 #define VMCB_EXIT_WRITE_CR8 0x018
201 #define VMCB_EXIT_READ_DR0 0x020
202 #define VMCB_EXIT_READ_DR1 0x021
203 #define VMCB_EXIT_READ_DR2 0x022
204 #define VMCB_EXIT_READ_DR3 0x023
205 #define VMCB_EXIT_READ_DR4 0x024
206 #define VMCB_EXIT_READ_DR5 0x025
207 #define VMCB_EXIT_READ_DR6 0x026
208 #define VMCB_EXIT_READ_DR7 0x027
209 #define VMCB_EXIT_WRITE_DR0 0x030
210 #define VMCB_EXIT_WRITE_DR1 0x031
211 #define VMCB_EXIT_WRITE_DR2 0x032
212 #define VMCB_EXIT_WRITE_DR3 0x033
213 #define VMCB_EXIT_WRITE_DR4 0x034
214 #define VMCB_EXIT_WRITE_DR5 0x035
215 #define VMCB_EXIT_WRITE_DR6 0x036
216 #define VMCB_EXIT_WRITE_DR7 0x037
217 #define VMCB_EXIT_EXCP_BASE 0x040
218 #define VMCB_EXIT_INTR 0x060
219 #define VMCB_EXIT_NMI 0x061
220 #define VMCB_EXIT_SMI 0x062
221 #define VMCB_EXIT_INIT 0x063
222 #define VMCB_EXIT_VINTR 0x064
223 #define VMCB_EXIT_CR0_SEL_WRITE 0x065
224 #define VMCB_EXIT_IDTR_READ 0x066
225 #define VMCB_EXIT_GDTR_READ 0x067
226 #define VMCB_EXIT_LDTR_READ 0x068
227 #define VMCB_EXIT_TR_READ 0x069
228 #define VMCB_EXIT_IDTR_WRITE 0x06a
229 #define VMCB_EXIT_GDTR_WRITE 0x06b
230 #define VMCB_EXIT_LDTR_WRITE 0x06c
231 #define VMCB_EXIT_TR_WRITE 0x06d
232 #define VMCB_EXIT_RDTSC 0x06e
233 #define VMCB_EXIT_RDPMC 0x06f
234 #define VMCB_EXIT_PUSHF 0x070
235 #define VMCB_EXIT_POPF 0x071
236 #define VMCB_EXIT_CPUID 0x072
237 #define VMCB_EXIT_RSM 0x073
238 #define VMCB_EXIT_IRET 0x074
239 #define VMCB_EXIT_SWINT 0x075
240 #define VMCB_EXIT_INVD 0x076
241 #define VMCB_EXIT_PAUSE 0x077
242 #define VMCB_EXIT_HLT 0x078
243 #define VMCB_EXIT_INVLPG 0x079
244 #define VMCB_EXIT_INVLPGA 0x07a
245 #define VMCB_EXIT_IOIO 0x07b
246 #define VMCB_EXIT_MSR 0x07c
247 #define VMCB_EXIT_TASK_SWITCH 0x07d
248 #define VMCB_EXIT_FERR_FREEZE 0x07e
249 #define VMCB_EXIT_SHUTDOWN 0x07f
250 #define VMCB_EXIT_VMRUN 0x080
251 #define VMCB_EXIT_VMMCALL 0x081
252 #define VMCB_EXIT_VMLOAD 0x082
253 #define VMCB_EXIT_VMSAVE 0x083
254 #define VMCB_EXIT_STGI 0x084
255 #define VMCB_EXIT_CLGI 0x085
256 #define VMCB_EXIT_SKINIT 0x086
257 #define VMCB_EXIT_RDTSCP 0x087
258 #define VMCB_EXIT_ICEBP 0x088
259 #define VMCB_EXIT_WBINVD 0x089
260 #define VMCB_EXIT_MONITOR 0x08a
261 #define VMCB_EXIT_MWAIT_UNCOND 0x08b
262 #define VMCB_EXIT_MWAIT_COND 0x08c
263 #define VMCB_EXIT_NPF 0x400
264 #define VMCB_EXIT_ERR -1
267 #define VMCB_MAKE_EXITINTINFO_TYPE(x) ((x) << 8)
268 #define VMCB_EXITINTINFO_VEC_MASK 0xff
269 #define VMCB_EXITINTINFO_TYPE_INTR VMCB_MAKE_EXITINTINFO_TYPE(0)
270 #define VMCB_EXITINTINFO_TYPE_NMI VMCB_MAKE_EXITINTINFO_TYPE(2)
271 #define VMCB_EXITINTINFO_TYPE_EXEPT VMCB_MAKE_EXITINTINFO_TYPE(3)
272 #define VMCB_EXITINTINFO_TYPE_SOFT VMCB_MAKE_EXITINTINFO_TYPE(4)
273 #define VMCB_EXITINTINFO_VALID (1 << 31)
274 #define VMCB_EXITINTINFO_ERR_VALID (1 << 11)
276 #define VMCB_EVTINJ_VEC_MASK VMCB_EXITINTINFO_VEC_MASK
277 #define VMCB_EVTINJ_TYPE_INTR VMCB_EXITINTINFO_TYPE_INTR
278 #define VMCB_EVTINJ_TYPE_NMI VMCB_EXITINTINFO_TYPE_NMI
279 #define VMCB_EVTINJ_TYPE_EXEPT VMCB_EXITINTINFO_TYPE_EXEPT
280 #define VMCB_EVTINJ_TYPE_SOFT VMCB_EXITINTINFO_TYPE_SOFT
281 #define VMCB_EVTINJ_VALID VMCB_EXITINTINFO_VALID
282 #define VMCB_EVTINJ_VALID_ERR VMCB_EXITINTINFO_ERR_VALID
284 /* TODO: finish making these error codes */
285 #define VMCB_EXITINFO_TS_MASK_IRET (1 << 36)
286 #define VMCB_EXITINFO_TS_MASK_JMP (1 << 38)
288 #define VMCB_TLB_CONTROL_DO_NOTHING 0
289 #define VMCB_TLB_CONTROL_FLUSH_ALL 1
291 #define VMCB_SELECTOR_S_SHIFT 4
292 #define VMCB_SELECTOR_DPL_SHIFT 5
293 #define VMCB_SELECTOR_P_SHIFT 7
294 #define VMCB_SELECTOR_AVL_SHIFT 8
295 #define VMCB_SELECTOR_L_SHIFT 9
296 #define VMCB_SELECTOR_DB_SHIFT 10
297 #define VMCB_SELECTOR_G_SHIFT 11
298 #define VMCB_SELECTOR_TYPE_MASK (0xf)
299 #define VMCB_SELECTOR_S_MASK (1 << VMCB_SELECTOR_S_SHIFT)
300 #define VMCB_SELECTOR_DPL_MASK (3 << VMCB_SELECTOR_DPL_SHIFT)
301 #define VMCB_SELECTOR_P_MASK (1 << VMCB_SELECTOR_P_SHIFT)
302 #define VMCB_SELECTOR_AVL_MASK (1 << VMCB_SELECTOR_AVL_SHIFT)
303 #define VMCB_SELECTOR_L_MASK (1 << VMCB_SELECTOR_L_SHIFT)
304 #define VMCB_SELECTOR_DB_MASK (1 << VMCB_SELECTOR_DB_SHIFT)
305 #define VMCB_SELECTOR_G_MASK (1 << VMCB_SELECTOR_G_SHIFT)
306 #define VMCB_SELECTOR_WRITE_MASK (1 << 1)
307 #define VMCB_SELECTOR_READ_MASK VMCB_SELECTOR_WRITE_MASK
308 #define VMCB_SELECTOR_CODE_MASK (1 << 3)
310 #endif /* VMCB_H */