1 #ifndef __SVM_HANDLER_H
2 #define __SVM_HANDLER_H
6 #include <palacios/svm.h>
7 #include <palacios/vmcb.h>
8 #include <palacios/vmm.h>
12 /******************************************/
13 /* SVM Intercept Exit Codes */
14 /* AMD Arch Vol 3, Appendix C, pg 477-478 */
15 /******************************************/
16 #define VMEXIT_CR_READ_MASK 0xfffffff0
17 #define VMEXIT_CR0_READ 0x00000000
18 #define VMEXIT_CR1_READ 0x00000001
19 #define VMEXIT_CR2_READ 0x00000002
20 #define VMEXIT_CR3_READ 0x00000003
21 #define VMEXIT_CR4_READ 0x00000004
22 #define VMEXIT_CR5_READ 0x00000005
23 #define VMEXIT_CR6_READ 0x00000006
24 #define VMEXIT_CR7_READ 0x00000007
25 #define VMEXIT_CR8_READ 0x00000008
26 #define VMEXIT_CR9_READ 0x00000009
27 #define VMEXIT_CR10_READ 0x0000000a
28 #define VMEXIT_CR11_READ 0x0000000b
29 #define VMEXIT_CR12_READ 0x0000000c
30 #define VMEXIT_CR13_READ 0x0000000d
31 #define VMEXIT_CR14_READ 0x0000000e
32 #define VMEXIT_CR15_READ 0x0000000f
34 #define VMEXIT_CR_WRITE_MASK 0xffffffe0
35 #define VMEXIT_CR0_WRITE 0x00000010
36 #define VMEXIT_CR1_WRITE 0x00000011
37 #define VMEXIT_CR2_WRITE 0x00000012
38 #define VMEXIT_CR3_WRITE 0x00000013
39 #define VMEXIT_CR4_WRITE 0x00000014
40 #define VMEXIT_CR5_WRITE 0x00000015
41 #define VMEXIT_CR6_WRITE 0x00000016
42 #define VMEXIT_CR7_WRITE 0x00000017
43 #define VMEXIT_CR8_WRITE 0x00000018
44 #define VMEXIT_CR9_WRITE 0x00000019
45 #define VMEXIT_CR10_WRITE 0x0000001a
46 #define VMEXIT_CR11_WRITE 0x0000001b
47 #define VMEXIT_CR12_WRITE 0x0000001c
48 #define VMEXIT_CR13_WRITE 0x0000001d
49 #define VMEXIT_CR14_WRITE 0x0000001e
50 #define VMEXIT_CR15_WRITE 0x0000001f
52 #define VMEXIT_DR_READ_MASK 0xffffffd0
53 #define VMEXIT_DR0_READ 0x00000020
54 #define VMEXIT_DR1_READ 0x00000021
55 #define VMEXIT_DR2_READ 0x00000022
56 #define VMEXIT_DR3_READ 0x00000023
57 #define VMEXIT_DR4_READ 0x00000024
58 #define VMEXIT_DR5_READ 0x00000025
59 #define VMEXIT_DR6_READ 0x00000026
60 #define VMEXIT_DR7_READ 0x00000027
61 #define VMEXIT_DR8_READ 0x00000028
62 #define VMEXIT_DR9_READ 0x00000029
63 #define VMEXIT_DR10_READ 0x0000002a
64 #define VMEXIT_DR11_READ 0x0000002b
65 #define VMEXIT_DR12_READ 0x0000002c
66 #define VMEXIT_DR13_READ 0x0000002d
67 #define VMEXIT_DR14_READ 0x0000002e
68 #define VMEXIT_DR15_READ 0x0000002f
70 #define VMEXIT_DR_WRITE_MASK 0xffffffc0
71 #define VMEXIT_DR0_WRITE 0x00000030 // ? this was previously 3f
72 #define VMEXIT_DR1_WRITE 0x00000031
73 #define VMEXIT_DR2_WRITE 0x00000032
74 #define VMEXIT_DR3_WRITE 0x00000033
75 #define VMEXIT_DR4_WRITE 0x00000034
76 #define VMEXIT_DR5_WRITE 0x00000035
77 #define VMEXIT_DR6_WRITE 0x00000036
78 #define VMEXIT_DR7_WRITE 0x00000037
79 #define VMEXIT_DR8_WRITE 0x00000038
80 #define VMEXIT_DR9_WRITE 0x00000039
81 #define VMEXIT_DR10_WRITE 0x0000003a
82 #define VMEXIT_DR11_WRITE 0x0000003b
83 #define VMEXIT_DR12_WRITE 0x0000003c
84 #define VMEXIT_DR13_WRITE 0x0000003d
85 #define VMEXIT_DR14_WRITE 0x0000003e
86 #define VMEXIT_DR15_WRITE 0x0000003f
88 #define VMEXIT_EXCP_MASK 0xffffffa0
89 #define VMEXIT_EXCP0 0x00000040
90 #define VMEXIT_EXCP1 0x00000041
91 #define VMEXIT_EXCP2 0x00000042
92 #define VMEXIT_EXCP3 0x00000043
93 #define VMEXIT_EXCP4 0x00000044
94 #define VMEXIT_EXCP5 0x00000045
95 #define VMEXIT_EXCP6 0x00000046
96 #define VMEXIT_EXCP7 0x00000047
97 #define VMEXIT_EXCP8 0x00000048
98 #define VMEXIT_EXCP9 0x00000049
99 #define VMEXIT_EXCP10 0x0000004a
100 #define VMEXIT_EXCP11 0x0000004b
101 #define VMEXIT_EXCP12 0x0000004c
102 #define VMEXIT_EXCP13 0x0000004d
103 #define VMEXIT_EXCP14 0x0000004e
104 #define VMEXIT_EXCP15 0x0000004f
105 #define VMEXIT_EXCP16 0x00000050
106 #define VMEXIT_EXCP17 0x00000051
107 #define VMEXIT_EXCP18 0x00000052
108 #define VMEXIT_EXCP19 0x00000053
109 #define VMEXIT_EXCP20 0x00000054
110 #define VMEXIT_EXCP21 0x00000055
111 #define VMEXIT_EXCP22 0x00000056
112 #define VMEXIT_EXCP23 0x00000057
113 #define VMEXIT_EXCP24 0x00000058
114 #define VMEXIT_EXCP25 0x00000059
115 #define VMEXIT_EXCP26 0x0000005a
116 #define VMEXIT_EXCP27 0x0000005b
117 #define VMEXIT_EXCP28 0x0000005c
118 #define VMEXIT_EXCP29 0x0000005d
119 #define VMEXIT_EXCP30 0x0000005e
120 #define VMEXIT_EXCP31 0x0000005f
123 #define VMEXIT_INTR 0x00000060
124 #define VMEXIT_NMI 0x00000061
125 #define VMEXIT_SMI 0x00000062
126 #define VMEXIT_INIT 0x00000063
127 #define VMEXIT_VINITR 0x00000064
128 #define VMEXIT_CR0_SEL_WRITE 0x00000065
129 #define VMEXIT_IDTR_READ 0x00000066
130 #define VMEXIT_GDTR_READ 0x00000067
131 #define VMEXIT_LDTR_READ 0x00000068
132 #define VMEXIT_TR_READ 0x00000069
133 #define VMEXIT_IDTR_WRITE 0x0000006a
134 #define VMEXIT_GDTR_WRITE 0x0000006b
135 #define VMEXIT_LDTR_WRITE 0x0000006c
136 #define VMEXIT_TR_WRITE 0x0000006d
137 #define VMEXIT_RDTSC 0x0000006e
138 #define VMEXIT_RDPMC 0x0000006f
139 #define VMEXIT_PUSHF 0x00000070
140 #define VMEXIT_POPF 0x00000071
141 #define VMEXIT_CPUID 0x00000072
142 #define VMEXIT_RSM 0x00000073
143 #define VMEXIT_IRET 0x00000074
144 #define VMEXIT_SWINT 0x00000075
145 #define VMEXIT_INVD 0x00000076
146 #define VMEXIT_PAUSE 0x00000077
147 #define VMEXIT_HLT 0x00000078
148 #define VMEXIT_INVLPG 0x00000079
149 #define VMEXIT_INVLPGA 0x0000007a
150 #define VMEXIT_IOIO 0x0000007b
151 #define VMEXIT_MSR 0x0000007c
152 #define VMEXIT_TASK_SWITCH 0x0000007d
153 #define VMEXIT_FERR_FREEZE 0x0000007e
154 #define VMEXIT_SHUTDOWN 0x0000007f
155 #define VMEXIT_VMRUN 0x00000080
156 #define VMEXIT_VMMCALL 0x00000081
157 #define VMEXIT_VMLOAD 0x00000082
158 #define VMEXIT_VMSAVE 0x00000083
159 #define VMEXIT_STGI 0x00000084
160 #define VMEXIT_CLGI 0x00000085
161 #define VMEXIT_SKINIT 0x00000086
162 #define VMEXIT_RDTSCP 0x00000087
163 #define VMEXIT_ICEBP 0x00000088
164 #define VMEXIT_WBINVD 0x00000089
165 #define VMEXIT_MONITOR 0x0000008a
166 #define VMEXIT_MWAIT 0x0000008b
167 #define VMEXIT_MWAIT_CONDITIONAL 0x0000008c
169 #define VMEXIT_NPF 0x00000400
171 #define VMEXIT_INVALID_VMCB -1
173 /******************************************/
178 static const uchar_t VMEXIT_CR0_READ_STR[] = "VMEXIT_CR0_READ";
179 static const uchar_t VMEXIT_CR1_READ_STR[] = "VMEXIT_CR1_READ";
180 static const uchar_t VMEXIT_CR2_READ_STR[] = "VMEXIT_CR2_READ";
181 static const uchar_t VMEXIT_CR3_READ_STR[] = "VMEXIT_CR3_READ";
182 static const uchar_t VMEXIT_CR4_READ_STR[] = "VMEXIT_CR4_READ";
183 static const uchar_t VMEXIT_CR5_READ_STR[] = "VMEXIT_CR5_READ";
184 static const uchar_t VMEXIT_CR6_READ_STR[] = "VMEXIT_CR6_READ";
185 static const uchar_t VMEXIT_CR7_READ_STR[] = "VMEXIT_CR7_READ";
186 static const uchar_t VMEXIT_CR8_READ_STR[] = "VMEXIT_CR8_READ";
187 static const uchar_t VMEXIT_CR9_READ_STR[] = "VMEXIT_CR9_READ";
188 static const uchar_t VMEXIT_CR10_READ_STR[] = "VMEXIT_CR10_READ";
189 static const uchar_t VMEXIT_CR11_READ_STR[] = "VMEXIT_CR11_READ";
190 static const uchar_t VMEXIT_CR12_READ_STR[] = "VMEXIT_CR12_READ";
191 static const uchar_t VMEXIT_CR13_READ_STR[] = "VMEXIT_CR13_READ";
192 static const uchar_t VMEXIT_CR14_READ_STR[] = "VMEXIT_CR14_READ";
193 static const uchar_t VMEXIT_CR15_READ_STR[] = "VMEXIT_CR15_READ";
194 static const uchar_t VMEXIT_CR0_WRITE_STR[] = "VMEXIT_CR0_WRITE";
195 static const uchar_t VMEXIT_CR1_WRITE_STR[] = "VMEXIT_CR1_WRITE";
196 static const uchar_t VMEXIT_CR2_WRITE_STR[] = "VMEXIT_CR2_WRITE";
197 static const uchar_t VMEXIT_CR3_WRITE_STR[] = "VMEXIT_CR3_WRITE";
198 static const uchar_t VMEXIT_CR4_WRITE_STR[] = "VMEXIT_CR4_WRITE";
199 static const uchar_t VMEXIT_CR5_WRITE_STR[] = "VMEXIT_CR5_WRITE";
200 static const uchar_t VMEXIT_CR6_WRITE_STR[] = "VMEXIT_CR6_WRITE";
201 static const uchar_t VMEXIT_CR7_WRITE_STR[] = "VMEXIT_CR7_WRITE";
202 static const uchar_t VMEXIT_CR8_WRITE_STR[] = "VMEXIT_CR8_WRITE";
203 static const uchar_t VMEXIT_CR9_WRITE_STR[] = "VMEXIT_CR9_WRITE";
204 static const uchar_t VMEXIT_CR10_WRITE_STR[] = "VMEXIT_CR10_WRITE";
205 static const uchar_t VMEXIT_CR11_WRITE_STR[] = "VMEXIT_CR11_WRITE";
206 static const uchar_t VMEXIT_CR12_WRITE_STR[] = "VMEXIT_CR12_WRITE";
207 static const uchar_t VMEXIT_CR13_WRITE_STR[] = "VMEXIT_CR13_WRITE";
208 static const uchar_t VMEXIT_CR14_WRITE_STR[] = "VMEXIT_CR14_WRITE";
209 static const uchar_t VMEXIT_CR15_WRITE_STR[] = "VMEXIT_CR15_WRITE";
210 static const uchar_t VMEXIT_DR0_READ_STR[] = "VMEXIT_DR0_READ";
211 static const uchar_t VMEXIT_DR1_READ_STR[] = "VMEXIT_DR1_READ";
212 static const uchar_t VMEXIT_DR2_READ_STR[] = "VMEXIT_DR2_READ";
213 static const uchar_t VMEXIT_DR3_READ_STR[] = "VMEXIT_DR3_READ";
214 static const uchar_t VMEXIT_DR4_READ_STR[] = "VMEXIT_DR4_READ";
215 static const uchar_t VMEXIT_DR5_READ_STR[] = "VMEXIT_DR5_READ";
216 static const uchar_t VMEXIT_DR6_READ_STR[] = "VMEXIT_DR6_READ";
217 static const uchar_t VMEXIT_DR7_READ_STR[] = "VMEXIT_DR7_READ";
218 static const uchar_t VMEXIT_DR8_READ_STR[] = "VMEXIT_DR8_READ";
219 static const uchar_t VMEXIT_DR9_READ_STR[] = "VMEXIT_DR9_READ";
220 static const uchar_t VMEXIT_DR10_READ_STR[] = "VMEXIT_DR10_READ";
221 static const uchar_t VMEXIT_DR11_READ_STR[] = "VMEXIT_DR11_READ";
222 static const uchar_t VMEXIT_DR12_READ_STR[] = "VMEXIT_DR12_READ";
223 static const uchar_t VMEXIT_DR13_READ_STR[] = "VMEXIT_DR13_READ";
224 static const uchar_t VMEXIT_DR14_READ_STR[] = "VMEXIT_DR14_READ";
225 static const uchar_t VMEXIT_DR15_READ_STR[] = "VMEXIT_DR15_READ";
226 static const uchar_t VMEXIT_DR0_WRITE_STR[] = "VMEXIT_DR0_WRITE";
227 static const uchar_t VMEXIT_DR1_WRITE_STR[] = "VMEXIT_DR1_WRITE";
228 static const uchar_t VMEXIT_DR2_WRITE_STR[] = "VMEXIT_DR2_WRITE";
229 static const uchar_t VMEXIT_DR3_WRITE_STR[] = "VMEXIT_DR3_WRITE";
230 static const uchar_t VMEXIT_DR4_WRITE_STR[] = "VMEXIT_DR4_WRITE";
231 static const uchar_t VMEXIT_DR5_WRITE_STR[] = "VMEXIT_DR5_WRITE";
232 static const uchar_t VMEXIT_DR6_WRITE_STR[] = "VMEXIT_DR6_WRITE";
233 static const uchar_t VMEXIT_DR7_WRITE_STR[] = "VMEXIT_DR7_WRITE";
234 static const uchar_t VMEXIT_DR8_WRITE_STR[] = "VMEXIT_DR8_WRITE";
235 static const uchar_t VMEXIT_DR9_WRITE_STR[] = "VMEXIT_DR9_WRITE";
236 static const uchar_t VMEXIT_DR10_WRITE_STR[] = "VMEXIT_DR10_WRITE";
237 static const uchar_t VMEXIT_DR11_WRITE_STR[] = "VMEXIT_DR11_WRITE";
238 static const uchar_t VMEXIT_DR12_WRITE_STR[] = "VMEXIT_DR12_WRITE";
239 static const uchar_t VMEXIT_DR13_WRITE_STR[] = "VMEXIT_DR13_WRITE";
240 static const uchar_t VMEXIT_DR14_WRITE_STR[] = "VMEXIT_DR14_WRITE";
241 static const uchar_t VMEXIT_DR15_WRITE_STR[] = "VMEXIT_DR15_WRITE";
242 static const uchar_t VMEXIT_EXCP0_STR[] = "VMEXIT_EXCP0";
243 static const uchar_t VMEXIT_EXCP1_STR[] = "VMEXIT_EXCP1";
244 static const uchar_t VMEXIT_EXCP2_STR[] = "VMEXIT_EXCP2";
245 static const uchar_t VMEXIT_EXCP3_STR[] = "VMEXIT_EXCP3";
246 static const uchar_t VMEXIT_EXCP4_STR[] = "VMEXIT_EXCP4";
247 static const uchar_t VMEXIT_EXCP5_STR[] = "VMEXIT_EXCP5";
248 static const uchar_t VMEXIT_EXCP6_STR[] = "VMEXIT_EXCP6";
249 static const uchar_t VMEXIT_EXCP7_STR[] = "VMEXIT_EXCP7";
250 static const uchar_t VMEXIT_EXCP8_STR[] = "VMEXIT_EXCP8";
251 static const uchar_t VMEXIT_EXCP9_STR[] = "VMEXIT_EXCP9";
252 static const uchar_t VMEXIT_EXCP10_STR[] = "VMEXIT_EXCP10";
253 static const uchar_t VMEXIT_EXCP11_STR[] = "VMEXIT_EXCP11";
254 static const uchar_t VMEXIT_EXCP12_STR[] = "VMEXIT_EXCP12";
255 static const uchar_t VMEXIT_EXCP13_STR[] = "VMEXIT_EXCP13";
256 static const uchar_t VMEXIT_EXCP14_STR[] = "VMEXIT_EXCP14";
257 static const uchar_t VMEXIT_EXCP15_STR[] = "VMEXIT_EXCP15";
258 static const uchar_t VMEXIT_EXCP16_STR[] = "VMEXIT_EXCP16";
259 static const uchar_t VMEXIT_EXCP17_STR[] = "VMEXIT_EXCP17";
260 static const uchar_t VMEXIT_EXCP18_STR[] = "VMEXIT_EXCP18";
261 static const uchar_t VMEXIT_EXCP19_STR[] = "VMEXIT_EXCP19";
262 static const uchar_t VMEXIT_EXCP20_STR[] = "VMEXIT_EXCP20";
263 static const uchar_t VMEXIT_EXCP21_STR[] = "VMEXIT_EXCP21";
264 static const uchar_t VMEXIT_EXCP22_STR[] = "VMEXIT_EXCP22";
265 static const uchar_t VMEXIT_EXCP23_STR[] = "VMEXIT_EXCP23";
266 static const uchar_t VMEXIT_EXCP24_STR[] = "VMEXIT_EXCP24";
267 static const uchar_t VMEXIT_EXCP25_STR[] = "VMEXIT_EXCP25";
268 static const uchar_t VMEXIT_EXCP26_STR[] = "VMEXIT_EXCP26";
269 static const uchar_t VMEXIT_EXCP27_STR[] = "VMEXIT_EXCP27";
270 static const uchar_t VMEXIT_EXCP28_STR[] = "VMEXIT_EXCP28";
271 static const uchar_t VMEXIT_EXCP29_STR[] = "VMEXIT_EXCP29";
272 static const uchar_t VMEXIT_EXCP30_STR[] = "VMEXIT_EXCP30";
273 static const uchar_t VMEXIT_EXCP31_STR[] = "VMEXIT_EXCP31";
274 static const uchar_t VMEXIT_INTR_STR[] = "VMEXIT_INTR";
275 static const uchar_t VMEXIT_NMI_STR[] = "VMEXIT_NMI";
276 static const uchar_t VMEXIT_SMI_STR[] = "VMEXIT_SMI";
277 static const uchar_t VMEXIT_INIT_STR[] = "VMEXIT_INIT";
278 static const uchar_t VMEXIT_VINITR_STR[] = "VMEXIT_VINITR";
279 static const uchar_t VMEXIT_CR0_SEL_WRITE_STR[] = "VMEXIT_CR0_SEL_WRITE";
280 static const uchar_t VMEXIT_IDTR_READ_STR[] = "VMEXIT_IDTR_READ";
281 static const uchar_t VMEXIT_GDTR_READ_STR[] = "VMEXIT_GDTR_READ";
282 static const uchar_t VMEXIT_LDTR_READ_STR[] = "VMEXIT_LDTR_READ";
283 static const uchar_t VMEXIT_TR_READ_STR[] = "VMEXIT_TR_READ";
284 static const uchar_t VMEXIT_IDTR_WRITE_STR[] = "VMEXIT_IDTR_WRITE";
285 static const uchar_t VMEXIT_GDTR_WRITE_STR[] = "VMEXIT_GDTR_WRITE";
286 static const uchar_t VMEXIT_LDTR_WRITE_STR[] = "VMEXIT_LDTR_WRITE";
287 static const uchar_t VMEXIT_TR_WRITE_STR[] = "VMEXIT_TR_WRITE";
288 static const uchar_t VMEXIT_RDTSC_STR[] = "VMEXIT_RDTSC";
289 static const uchar_t VMEXIT_RDPMC_STR[] = "VMEXIT_RDPMC";
290 static const uchar_t VMEXIT_PUSHF_STR[] = "VMEXIT_PUSHF";
291 static const uchar_t VMEXIT_POPF_STR[] = "VMEXIT_POPF";
292 static const uchar_t VMEXIT_CPUID_STR[] = "VMEXIT_CPUID";
293 static const uchar_t VMEXIT_RSM_STR[] = "VMEXIT_RSM";
294 static const uchar_t VMEXIT_IRET_STR[] = "VMEXIT_IRET";
295 static const uchar_t VMEXIT_SWINT_STR[] = "VMEXIT_SWINT";
296 static const uchar_t VMEXIT_INVD_STR[] = "VMEXIT_INVD";
297 static const uchar_t VMEXIT_PAUSE_STR[] = "VMEXIT_PAUSE";
298 static const uchar_t VMEXIT_HLT_STR[] = "VMEXIT_HLT";
299 static const uchar_t VMEXIT_INVLPG_STR[] = "VMEXIT_INVLPG";
300 static const uchar_t VMEXIT_INVLPGA_STR[] = "VMEXIT_INVLPGA";
301 static const uchar_t VMEXIT_IOIO_STR[] = "VMEXIT_IOIO";
302 static const uchar_t VMEXIT_MSR_STR[] = "VMEXIT_MSR";
303 static const uchar_t VMEXIT_TASK_SWITCH_STR[] = "VMEXIT_TASK_SWITCH";
304 static const uchar_t VMEXIT_FERR_FREEZE_STR[] = "VMEXIT_FERR_FREEZE";
305 static const uchar_t VMEXIT_SHUTDOWN_STR[] = "VMEXIT_SHUTDOWN";
306 static const uchar_t VMEXIT_VMRUN_STR[] = "VMEXIT_VMRUN";
307 static const uchar_t VMEXIT_VMMCALL_STR[] = "VMEXIT_VMMCALL";
308 static const uchar_t VMEXIT_VMLOAD_STR[] = "VMEXIT_VMLOAD";
309 static const uchar_t VMEXIT_VMSAVE_STR[] = "VMEXIT_VMSAVE";
310 static const uchar_t VMEXIT_STGI_STR[] = "VMEXIT_STGI";
311 static const uchar_t VMEXIT_CLGI_STR[] = "VMEXIT_CLGI";
312 static const uchar_t VMEXIT_SKINIT_STR[] = "VMEXIT_SKINIT";
313 static const uchar_t VMEXIT_RDTSCP_STR[] = "VMEXIT_RDTSCP";
314 static const uchar_t VMEXIT_ICEBP_STR[] = "VMEXIT_ICEBP";
315 static const uchar_t VMEXIT_WBINVD_STR[] = "VMEXIT_WBINVD";
316 static const uchar_t VMEXIT_MONITOR_STR[] = "VMEXIT_MONITOR";
317 static const uchar_t VMEXIT_MWAIT_STR[] = "VMEXIT_MWAIT";
318 static const uchar_t VMEXIT_MWAIT_CONDITIONAL_STR[] = "VMEXIT_MWAIT_CONDITIONAL";
319 static const uchar_t VMEXIT_NPF_STR[] = "VMEXIT_NPF";
320 static const uchar_t VMEXIT_INVALID_VMCB_STR[] = "VMEXIT_INVALID_VMCB";
323 const uchar_t * vmexit_code_to_str(uint_t exit_code);
327 int handle_shadow_paging(struct guest_info * info);
329 int handle_svm_intr(struct guest_info * info);
331 int handle_svm_exit(struct guest_info * info);
333 #endif // ! __V3VEE__