4 #define VMX_FAIL_INVALID 1
5 #define VMX_FAIL_VALID 2
8 #define VMCS_HOST_RSP 0x00006C14
9 #define VMCS_HOST_RIP 0x00006C16
11 #if defined(__V3_64BIT__)
13 #define save_registers(location) \
15 movq location, %rax; \
18 movq %rbp, 16(%rax); \
20 movq %rbx, 32(%rax); \
21 movq %rdx, 40(%rax); \
22 movq %rcx, 48(%rax); \
25 movq %rbx, 56(%rax); \
30 movq %r10, 80(%rax); \
31 movq %r11, 88(%rax); \
32 movq %r12, 96(%rax); \
33 movq %r13, 104(%rax); \
34 movq %r14, 112(%rax); \
35 movq %r15, 120(%rax); \
38 #define restore_registers(location) \
52 mov 104(%rax), %r13; \
53 mov 112(%rax), %r14; \
54 mov 120(%rax), %r15; \
56 movq 56(%rax), %rbx; \
60 #define save_ctrl_regs(location) \
63 movq location, %rax; \
69 #define restore_ctrl_regs(location) \
72 movq location, %rax; \
113 #define PRE_LAUNCH(return_target) \
120 movq $VMCS_HOST_RSP, %rbx; \
121 vmwrite %rax, %rbx; \
125 movq return_target, %rax; \
126 movq $VMCS_HOST_RIP, %rbx; \
127 vmwrite %rax, %rbx; \
131 restore_ctrl_regs(%rdx); \
132 restore_registers(%rdi);
139 // vm_regs = %rdi, guest_info * = %rsi, ctrl_regs = %rdx
142 PRE_LAUNCH($vmx_resume_ret);
154 // vm_regs = %rdi, guest_info * = %rsi, ctrl_regs = %rdx
157 PRE_LAUNCH($vmx_launch_ret);
173 movq $VMX_FAIL_VALID, %rax
180 movq $VMX_FAIL_INVALID, %rax
185 movq $VMM_FAILURE, %rax
190 save_registers(16(%rsp));
191 save_ctrl_regs(16(%rsp));
204 #define save_registers(location) \
206 movl location, %eax; \
208 movl %esi, 8(%eax); \
209 movl %ebp, 16(%eax); \
211 movl %ebx, 32(%eax); \
212 movl %edx, 40(%eax); \
213 movl %ecx, 48(%eax); \
215 movl 8(%esp), %ebx; \
216 movl %ebx, 56(%eax); \
221 #define restore_registers(location) \
223 movl location, %eax; \
225 movl 8(%eax), %esi; \
226 movl 16(%eax), %ebp; \
227 movl 32(%eax), %ebx; \
228 movl 40(%eax), %edx; \
229 movl 48(%eax), %ecx; \
233 #define save_ctrl_regs(location) \
236 movl location, %eax; \
238 movl %ebx, 8(%eax); \
242 #define restore_ctrl_regs(location) \
245 movl location, %eax; \
246 movl 8(%eax), %ebx; \
270 #define PRE_LAUNCH(return_target) \
276 movl 8(%ebp), %edi; \
277 movl 12(%ebp), %esi; \
278 movl 16(%ebp), %edx; \
281 movl $VMCS_HOST_RSP, %ebx; \
282 vmwrite %eax, %ebx; \
286 movl return_target, %eax; \
287 movl $VMCS_HOST_RIP, %ebx; \
288 vmwrite %eax, %ebx; \
292 restore_ctrl_regs(%edx); \
293 restore_registers(%edi);
296 // 32 bit GCC passes arguments via stack
302 PRE_LAUNCH($vmx_resume_ret);
316 PRE_LAUNCH($vmx_launch_ret);
329 movl $VMX_FAIL_VALID, %eax
336 movl $VMX_FAIL_INVALID, %eax
341 movl $VMM_FAILURE, %eax
346 save_registers(8(%esp));
347 save_ctrl_regs(8(%esp));