Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


major VMX update
[palacios.git] / palacios / include / palacios / vmx_handler.h
1 /* 
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.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
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.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #ifndef __VMX_HANDLER_H__
21 #define __VMX_HANDLER_H__
22
23 #ifdef __V3VEE__
24
25 #include <palacios/vm_guest.h>
26
27
28 /******************************************/
29 /* VMX Intercept Exit Codes               */
30 /******************************************/
31 typedef enum {
32     VMEXIT_INFO_EXCEPTION_OR_NMI            = 0,
33     VMEXIT_EXTERNAL_INTR                    = 1,
34     VMEXIT_TRIPLE_FAULT                     = 2,
35     VMEXIT_INIT_SIGNAL                      = 3,
36     VMEXIT_STARTUP_IPI                      = 4,
37     VMEXIT_IO_SMI                           = 5,
38     VMEXIT_OTHER_SMI                        = 6,
39     VMEXIT_INTR_WINDOW                      = 7,
40     VMEXIT_NMI_WINDOW                       = 8,
41     VMEXIT_TASK_SWITCH                      = 9,
42     VMEXIT_CPUID                            = 10,
43     VMEXIT_HLT                              = 12,
44     VMEXIT_INVD                             = 13,
45     VMEXIT_INVLPG                           = 14,
46     VMEXIT_RDPMC                            = 15,
47     VMEXIT_RDTSC                            = 16,
48     VMEXIT_RSM                              = 17,
49     VMEXIT_VMCALL                           = 18,
50     VMEXIT_VMCLEAR                          = 19,
51     VMEXIT_VMLAUNCH                         = 20,
52     VMEXIT_VMPTRLD                          = 21,
53     VMEXIT_VMPTRST                          = 22,
54     VMEXIT_VMREAD                           = 23,
55     VMEXIT_VMRESUME                         = 24,
56     VMEXIT_VMWRITE                          = 25,
57     VMEXIT_VMXOFF                           = 26,
58     VMEXIT_VMXON                            = 27,
59     VMEXIT_CR_REG_ACCESSES                  = 28,
60     VMEXIT_MOV_DR                           = 29,
61     VMEXIT_IO_INSTR                         = 30,
62     VMEXIT_RDMSR                            = 31,
63     VMEXIT_WRMSR                            = 32,
64     VMEXIT_ENTRY_FAIL_INVALID_GUEST_STATE   = 33,
65     VMEXIT_ENTRY_FAIL_MSR_LOAD              = 34,
66     VMEXIT_MWAIT                            = 36,
67     VMEXIT_MONITOR                          = 39,
68     VMEXIT_PAUSE                            = 40,
69     VMEXIT_ENTRY_FAILURE_MACHINE_CHECK      = 41,
70     VMEXIT_TPR_BELOW_THRESHOLD              = 43,
71     VMEXIT_APIC                             = 44,
72     VMEXIT_GDTR_IDTR                        = 46,
73     VMEXIT_LDTR_TR                          = 47,
74     VMEXIT_EPT_VIOLATION                    = 48,
75     VMEXIT_EPT_CONFIG                       = 49,
76     VMEXIT_INVEPT                           = 50,
77     VMEXIT_RDTSCP                           = 51,
78     VMEXIT_EXPIRED_PREEMPT_TIMER            = 52,
79     VMEXIT_INVVPID                          = 53,
80     VMEXIT_WBINVD                           = 54,
81     VMEXIT_XSETBV                           = 55
82 } vmx_exit_t;
83
84 /* VMCS Exit QUALIFICATIONs */
85 struct vmx_exit_io_qual {
86     union {
87         uint32_t value;
88         struct {
89             uint32_t access_size : 3; // (0: 1 Byte ;; 1: 2 Bytes ;; 3: 4 Bytes)
90             uint32_t dir        : 1; // (0: Out ;; 1: In)
91             uint32_t string     : 1; // (0: not string ;; 1: string)
92             uint32_t rep        : 1; // (0: not REP ;; 1: REP)
93             uint32_t op_enc      : 1; // (0: DX ;; 1: immediate)
94             uint32_t rsvd       : 9; // Set to 0
95             uint32_t port       : 16; // IO Port Number
96         } __attribute__((packed));
97     } __attribute__((packed));
98 } __attribute__((packed));
99
100 struct vmx_exit_io_instr_info {
101     union {
102         uint32_t value;
103         struct {
104             uint32_t undef1     : 7;
105             uint32_t addr_size  : 3;
106             uint32_t undef2     : 5;
107             uint32_t seg_reg    : 3;
108             uint32_t undef3     : 14;
109         } __attribute__((packed));
110     } __attribute__((packed));
111 } __attribute__((packed));
112
113 /* Exit Interrupt Vector Info */
114 struct vmx_exit_int_info {
115     union {
116         uint32_t value;
117         struct {
118             uint32_t vector     : 8; // IRQ number, exception vector, NMI = 2 
119             uint32_t type       : 3; // (0: ext. IRQ , 2: NMI , 3: hw exception , 6: sw exception
120             uint32_t error_code : 1; // 1: error Code present
121             uint32_t nmi_unblock : 1; // something to do with NMIs and IRETs (Intel 3B, sec. 23.2.2) 
122             uint32_t rsvd       : 18; // always 0
123             uint32_t valid      : 1; // always 1 if valid
124         } __attribute__ ((packed));
125     } __attribute__ ((packed));
126 } __attribute__((packed));
127
128 /* VMX entry interrupt format */
129 struct vmx_entry_int_info {
130     union {
131         uint32_t value;
132         struct {
133             uint32_t vector     : 8; // IRQ/exception vector number
134             uint32_t type       : 3; // (0: ext. IRQ, 2: NMI, 3: hw excp, 4: sw int, 5: priv. sw excp, 6: sw excp, 7: other
135             uint32_t error_code : 1; // 1: deliver error code
136             uint32_t rsvd       : 19;
137             uint32_t valid      : 1; // 1: valid
138         } __attribute__ ((packed));
139     } __attribute__ ((packed));
140 } __attribute__ ((packed));
141
142
143
144
145 struct VMExitDBGQual {
146     uint32_t B0         : 1; // Breakpoint 0 condition met
147     uint32_t B1         : 1; // Breakpoint 1 condition met
148     uint32_t B2         : 1; // Breakpoint 2 condition met
149     uint32_t B3         : 1; // Breakpoint 3 condition met
150     uint32_t rsvd       : 9; // reserved to 0
151     uint32_t BD         : 1; // detected DBG reg access
152     uint32_t BS         : 1; // cause either single instr or taken branch
153 } __attribute__((packed));
154
155
156 struct VMExitTSQual {
157     uint32_t selector   : 16; // selector of destination TSS 
158     uint32_t rsvd       : 14; // reserved to 0
159     uint32_t src        : 2; // (0: CALL ; 1: IRET ; 2: JMP ; 3: Task gate in IDT)
160 } __attribute__((packed));
161
162 struct vmx_exit_cr_qual {
163     union {
164         uint32_t value;
165         struct {
166             uint32_t cr_id       : 4; // cr number (0 for CLTS and LMSW) (bit 3 always 0, on 32bit)
167             uint32_t access_type : 2; // (0: MOV to CR ; 1: MOV from CR ; 2: CLTS ; 3: LMSW)
168             uint32_t lmsw_op_type : 1; // (0: register ; 1: memory)
169             uint32_t rsvd1      : 1; // reserved to 0
170             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)
171             uint32_t rsvd2      : 4; // reserved to 0
172             uint32_t lmsw_src    : 16; // src data for lmsw
173         } __attribute__((packed));
174     } __attribute__((packed));
175 } __attribute__((packed));
176
177 struct VMExitMovDRQual {
178     uint32_t regID      : 3; // debug register number
179     uint32_t rsvd1      : 1; // reserved to 0
180     uint32_t dir        : 1; // (0: MOV to DR , 1: MOV from DR)
181     uint32_t rsvd2      : 3; // reserved to 0
182     uint32_t gpr        : 4; // (0:RAX, 1:RCX, 2:RDX, 3:RBX, 4:RSP, 5:RBP, 6:RSI, 6:RDI, 8-15:64bit regs)
183 } __attribute__((packed));
184
185 /* End Exit Qualifications */
186
187 struct vmx_exit_idt_vec_info {
188     union {
189         uint32_t value;
190         struct {
191             uint32_t vector     : 8;
192             uint32_t type       : 3;
193             uint32_t error_code : 1;
194             uint32_t undef      : 1;
195             uint32_t rsvd       : 18;
196             uint32_t valid      : 1;
197         } __attribute__ ((packed));
198     } __attribute__ ((packed));
199 } __attribute__ ((packed));
200
201
202
203
204 struct vmx_exit_info {
205     uint32_t instr_len;
206     uint32_t instr_info;
207
208     uint32_t exit_reason;
209     addr_t exit_qual;
210
211     uint32_t int_info;
212     uint32_t int_err;
213
214     addr_t guest_linear_addr;
215 };
216
217
218
219
220
221 int v3_handle_vmx_exit(struct guest_info * info, struct vmx_exit_info * exit_info);
222 const char * v3_vmx_exit_code_to_str(vmx_exit_t exit);
223
224 #endif
225
226 #endif