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) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, 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".
20 #ifndef __VMX_HANDLER_H__
21 #define __VMX_HANDLER_H__
25 #include <palacios/vm_guest.h>
27 /******************************************/
28 /* VMX Intercept Exit Codes */
29 /******************************************/
31 VMEXIT_INFO_EXCEPTION_OR_NMI = 0,
32 VMEXIT_EXTERNAL_INTR = 1,
33 VMEXIT_TRIPLE_FAULT = 2,
34 VMEXIT_INIT_SIGNAL = 3,
35 VMEXIT_STARTUP_IPI = 4,
38 VMEXIT_INTR_WINDOW = 7,
39 VMEXIT_NMI_WINDOW = 8,
40 VMEXIT_TASK_SWITCH = 9,
58 VMEXIT_CR_REG_ACCESSES = 28,
63 VMEXIT_ENTRY_FAIL_INVALID_GUEST_STATE = 33,
64 VMEXIT_ENTRY_FAIL_MSR_LOAD = 34,
68 VMEXIT_ENTRY_FAILURE_MACHINE_CHECK = 41,
69 VMEXIT_TPR_BELOW_THRESHOLD = 43,
71 VMEXIT_GDTR_IDTR = 46,
73 VMEXIT_EPT_VIOLATION = 48,
74 VMEXIT_EPT_CONFIG = 49,
77 VMEXIT_EXPIRED_PREEMPT_TIMER = 52,
83 /* VMCS Exit QUALIFICATIONs */
84 struct vmx_exit_io_qual {
88 uint32_t access_size : 3; // (0: 1 Byte ;; 1: 2 Bytes ;; 3: 4 Bytes)
89 uint32_t dir : 1; // (0: Out ;; 1: In)
90 uint32_t string : 1; // (0: not string ;; 1: string)
91 uint32_t rep : 1; // (0: not REP ;; 1: REP)
92 uint32_t op_enc : 1; // (0: DX ;; 1: immediate)
93 uint32_t rsvd : 9; // Set to 0
94 uint32_t port : 16; // IO Port Number
95 } __attribute__((packed));
96 } __attribute__((packed));
97 } __attribute__((packed));
99 struct vmx_exit_io_instr_info {
104 uint32_t addr_size : 3;
106 uint32_t seg_reg : 3;
107 uint32_t undef3 : 14;
108 } __attribute__((packed));
109 } __attribute__((packed));
110 } __attribute__((packed));
112 /* Exit Interrupt Vector Info */
113 struct vmx_exit_int_info {
117 uint32_t vector : 8; // IRQ number, exception vector, NMI = 2
118 uint32_t type : 3; // (0: ext. IRQ , 2: NMI , 3: hw exception , 6: sw exception
119 uint32_t error_code : 1; // 1: error Code present
120 uint32_t nmi_unblock : 1; // something to do with NMIs and IRETs (Intel 3B, sec. 23.2.2)
121 uint32_t rsvd : 18; // always 0
122 uint32_t valid : 1; // always 1 if valid
123 } __attribute__ ((packed));
124 } __attribute__ ((packed));
125 } __attribute__((packed));
127 /* VMX entry interrupt format */
128 struct vmx_entry_int_info {
132 uint32_t vector : 8; // IRQ/exception vector number
133 uint32_t type : 3; // (0: ext. IRQ, 2: NMI, 3: hw excp, 4: sw int, 5: priv. sw excp, 6: sw excp, 7: other
134 uint32_t error_code : 1; // 1: deliver error code
136 uint32_t valid : 1; // 1: valid
137 } __attribute__ ((packed));
138 } __attribute__ ((packed));
139 } __attribute__ ((packed));
144 struct VMExitDBGQual {
145 uint32_t B0 : 1; // Breakpoint 0 condition met
146 uint32_t B1 : 1; // Breakpoint 1 condition met
147 uint32_t B2 : 1; // Breakpoint 2 condition met
148 uint32_t B3 : 1; // Breakpoint 3 condition met
149 uint32_t rsvd : 9; // reserved to 0
150 uint32_t BD : 1; // detected DBG reg access
151 uint32_t BS : 1; // cause either single instr or taken branch
152 } __attribute__((packed));
155 struct VMExitTSQual {
156 uint32_t selector : 16; // selector of destination TSS
157 uint32_t rsvd : 14; // reserved to 0
158 uint32_t src : 2; // (0: CALL ; 1: IRET ; 2: JMP ; 3: Task gate in IDT)
159 } __attribute__((packed));
161 struct vmx_exit_cr_qual {
165 uint32_t cr_id : 4; // cr number (0 for CLTS and LMSW) (bit 3 always 0, on 32bit)
166 uint32_t access_type : 2; // (0: MOV to CR ; 1: MOV from CR ; 2: CLTS ; 3: LMSW)
167 uint32_t lmsw_op_type : 1; // (0: register ; 1: memory)
168 uint32_t rsvd1 : 1; // reserved to 0
169 uint32_t gpr : 4; // (0:RAX+[CLTS/LMSW], 1:RCX, 2:RDX, 3:RBX, 4:RSP, 5:RBP, 6:RSI, 6:RDI, 8-15:64bit regs)
170 uint32_t rsvd2 : 4; // reserved to 0
171 uint32_t lmsw_src : 16; // src data for lmsw
172 } __attribute__((packed));
173 } __attribute__((packed));
174 } __attribute__((packed));
176 struct VMExitMovDRQual {
177 uint32_t regID : 3; // debug register number
178 uint32_t rsvd1 : 1; // reserved to 0
179 uint32_t dir : 1; // (0: MOV to DR , 1: MOV from DR)
180 uint32_t rsvd2 : 3; // reserved to 0
181 uint32_t gpr : 4; // (0:RAX, 1:RCX, 2:RDX, 3:RBX, 4:RSP, 5:RBP, 6:RSI, 6:RDI, 8-15:64bit regs)
182 } __attribute__((packed));
184 /* End Exit Qualifications */
186 struct vmx_exit_idt_vec_info {
192 uint32_t error_code : 1;
196 } __attribute__ ((packed));
197 } __attribute__ ((packed));
198 } __attribute__ ((packed));
200 int v3_handle_vmx_exit(struct v3_gprs * gprs, struct guest_info * info, struct v3_ctrl_regs * ctrl_regs);
201 const char * v3_vmx_exit_code_to_str(vmx_exit_t exit);