2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2011, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
26 #include <palacios/vmm_types.h>
27 #include <palacios/vmcs.h>
28 #include <palacios/vmm.h>
29 #include <palacios/vm_guest.h>
33 #define VMX_FAIL_INVALID 1
34 #define VMX_FAIL_VALID 2
38 struct vmx_pin_ctrls {
42 uint_t ext_int_exit : 1;
47 uint_t active_preempt_timer : 1;
49 } __attribute__((packed));
50 } __attribute__((packed));
51 } __attribute__((packed));
54 struct vmx_pri_proc_ctrls {
59 uint_t int_wndw_exit : 1;
60 uint_t tsc_offset : 1;
64 uint_t invlpg_exit : 1;
65 uint_t mwait_exit : 1;
66 uint_t rdpmc_exit : 1;
67 uint_t rdtsc_exit : 1;
69 uint_t cr3_ld_exit : 1;
70 uint_t cr3_str_exit : 1;
72 uint_t cr8_ld_exit : 1;
73 uint_t cr8_str_exit : 1;
75 uint_t nmi_wndw_exit : 1;
76 uint_t mov_dr_exit : 1;
77 uint_t uncon_io_exit : 1;
78 uint_t use_io_bitmap : 1;
80 uint_t monitor_trap : 1;
81 uint_t use_msr_bitmap : 1;
82 uint_t monitor_exit : 1;
83 uint_t pause_exit : 1;
85 } __attribute__((packed));
86 } __attribute__((packed));
87 } __attribute__((packed));
89 struct vmx_sec_proc_ctrls {
93 uint_t virt_apic_acc : 1;
94 uint_t enable_ept : 1;
95 uint_t desc_table_exit : 1;
96 uint_t enable_rdtscp : 1;
97 uint_t virt_x2apic : 1;
98 uint_t enable_vpid : 1;
99 uint_t wbinvd_exit : 1;
100 uint_t unrstrct_guest : 1; /* un restricted guest (CAN RUN IN REAL MODE) */
102 uint_t pause_loop_exit : 1;
104 } __attribute__((packed));
105 } __attribute__((packed));
106 } __attribute__((packed));
108 struct vmx_exit_ctrls {
113 uint_t save_dbg_ctrls : 1;
115 uint_t host_64_on : 1;
117 uint_t ld_perf_glbl_ctrl : 1;
119 uint_t ack_int_on_exit : 1;
123 uint_t save_efer : 1;
125 uint_t save_preempt_timer : 1;
127 } __attribute__((packed));
128 } __attribute__((packed));
129 } __attribute__((packed));
131 struct vmx_entry_ctrls {
136 uint_t ld_dbg_ctrls : 1;
138 uint_t guest_ia32e : 1;
139 uint_t smm_entry : 1;
140 uint_t no_dual_monitor : 1;
142 uint_t ld_perf_glbl_ctrl : 1;
146 } __attribute__((packed));
147 } __attribute__((packed));
148 } __attribute__((packed));
162 struct tss_descriptor {
166 /* In IA32, type follows the form 10B1b, where B is the busy flag */
172 uint_t available : 1;
175 uint_t granularity : 1;
183 } __attribute__((packed));
185 struct vmcs_host_state {
186 struct v3_segment gdtr;
187 struct v3_segment idtr;
188 struct v3_segment tr;
192 struct vmcs_msr_save_area {
194 struct vmcs_msr_entry guest_msrs[4];
196 struct vmcs_msr_entry guest_star;
197 struct vmcs_msr_entry guest_lstar;
198 struct vmcs_msr_entry guest_fmask;
199 struct vmcs_msr_entry guest_kern_gs;
200 } __attribute__((packed));
201 } __attribute__((packed));
204 struct vmcs_msr_entry host_msrs[4];
206 struct vmcs_msr_entry host_star;
207 struct vmcs_msr_entry host_lstar;
208 struct vmcs_msr_entry host_fmask;
209 struct vmcs_msr_entry host_kern_gs;
210 } __attribute__((packed));
211 } __attribute__((packed));
213 } __attribute__((packed));
218 vmxassist_state_t assist_state;
219 struct vmcs_host_state host_state;
223 addr_t vmcs_ptr_phys;
225 v3_reg_t guest_cr4; /// corresponds to the CR4 Read shadow
228 /* VMX Control Fields */
229 struct vmx_pin_ctrls pin_ctrls;
230 struct vmx_pri_proc_ctrls pri_proc_ctrls;
231 struct vmx_sec_proc_ctrls sec_proc_ctrls;
232 struct vmx_exit_ctrls exit_ctrls;
233 struct vmx_entry_ctrls entry_ctrls;
235 struct vmx_exception_bitmap excp_bmap;
237 addr_t msr_area_paddr;
238 struct vmcs_msr_save_area * msr_area;
241 int v3_is_vmx_capable();
243 void v3_init_vmx_cpu(int cpu_id);
244 void v3_deinit_vmx_cpu(int cpu_id);
246 int v3_init_vmx_vmcs(struct guest_info * info, v3_vm_class_t vm_class);
247 int v3_deinit_vmx_vmcs(struct guest_info * core);
249 int v3_start_vmx_guest(struct guest_info* info);
250 int v3_reset_vmx_vm_core(struct guest_info * core, addr_t rip);
251 void v3_flush_vmx_vm_core(struct guest_info * core);
253 int v3_vmx_enter(struct guest_info * info);
255 int v3_vmx_load_core(struct guest_info * core, void * ctx);
256 int v3_vmx_save_core(struct guest_info * core, void * ctx);
262 #endif // ! __V3VEE__