3 ;; This file is part of the Palacios Virtual Machine Monitor developed
4 ;; by the V3VEE Project with funding from the United States National
5 ;; Science Foundation and the Department of Energy.
7 ;; The V3VEE Project is a joint project between Northwestern University
8 ;; and the University of New Mexico. You can find out more at
9 ;; http://www.v3vee.org
11 ;; Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
12 ;; Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
13 ;; All rights reserved.
15 ;; Author: Jack Lange <jarusl@cs.northwestern.edu>
17 ;; This is free software. You are permitted to use,
18 ;; redistribute, and modify it as specified in the file "V3VEE_LICENSE".
29 %include "vmcs_fields.asm"
31 VMX_SUCCESS equ 0x00000000
32 VMX_FAIL_INVALID equ 0x00000001
33 VMX_FAIL_VALID equ 0x00000002
34 VMM_ERROR equ 0x00000003
54 EXPORT Init_VMCS_HostState
55 EXPORT Init_VMCS_GuestState
58 ; Enable_VMX - Turn on VMX
66 or ebx, dword 0x00002000
69 or ebx, dword 0x80000021
76 mov eax, VMX_FAIL_INVALID
82 ; VMREAD - read a value from a VMCS
105 mov eax, VMX_FAIL_INVALID
108 mov eax, VMX_FAIL_VALID
113 ; VMWRITE - write a value to a VMCS
132 mov eax, VMX_FAIL_INVALID
135 mov eax, VMX_FAIL_VALID
140 ; VMCLEAR - Initializes a VMCS
151 mov eax, VMX_FAIL_INVALID
154 mov eax, VMX_FAIL_VALID
161 ; VMCS_LOAD - load a VMCS
172 mov eax, VMX_FAIL_INVALID
175 mov eax, VMX_FAIL_VALID
182 ; VMCS_STORE - Store a VMCS
194 mov eax, VMX_FAIL_INVALID
197 mov eax, VMX_FAIL_VALID
214 mov eax, VMX_FAIL_INVALID
217 mov eax, VMX_FAIL_VALID
235 mov eax, VMX_FAIL_INVALID
238 mov eax, VMX_FAIL_VALID
265 mov eax, VMX_FAIL_INVALID
268 mov eax, VMX_FAIL_VALID
294 popa ; we only get here if there is an error in the vmresume
295 ; we restore the host state and return an error code
303 mov eax, VMX_FAIL_INVALID
306 mov eax, VMX_FAIL_VALID
315 ; Setup_VMCS_GuestState
316 ; Copy all of the Guest registers into the guest state of a vmcs
326 mov ebx, VMCS_GUEST_ES_SELECTOR
332 mov ebx, VMCS_GUEST_CS_SELECTOR
338 mov ebx, VMCS_GUEST_SS_SELECTOR
344 mov ebx, VMCS_GUEST_DS_SELECTOR
350 mov ebx, VMCS_GUEST_FS_SELECTOR
356 mov ebx, VMCS_GUEST_GS_SELECTOR
364 mov ebx, VMCS_GUEST_TR_SELECTOR
372 mov eax, VMX_FAIL_INVALID
375 mov eax, VMX_FAIL_VALID
394 mov ebx, GUEST_GDTR_LIMIT
400 mov ebx, GUEST_GDTR_BASE
409 mov ebx, GUEST_IDTR_LIMIT
415 mov ebx, GUEST_IDTR_BASE
423 mov ebx, GUEST_LDTR_BASE
430 mov ebx, GUEST_LDTR_LIMIT
439 mov eax, VMX_FAIL_INVALID
442 mov eax, VMX_FAIL_VALID
462 mov ebx, GUEST_ES_BASE
468 mov ebx, GUEST_CS_BASE
474 mov ebx, GUEST_SS_BASE
480 mov ebx, GUEST_DS_BASE
486 mov ebx, GUEST_FS_BASE
492 mov ebx, GUEST_GS_BASE
499 mov ebx, GUEST_TR_BASE
507 mov eax, VMX_FAIL_INVALID
510 mov eax, VMX_FAIL_VALID
523 mov eax, 1100000010010011b
524 mov ebx, GUEST_ES_ACCESS
531 mov eax, 1100000010011001b
532 ; mov eax, 0x0000c099
533 mov ebx, GUEST_CS_ACCESS
538 ; mov eax, 1100000010010111b
539 mov eax, 1100000010010011b
540 mov ebx, GUEST_SS_ACCESS
545 mov eax, 1100000010010011b
546 mov ebx, GUEST_DS_ACCESS
552 mov eax, 1100000010010011b
553 mov ebx, GUEST_FS_ACCESS
559 mov eax, 1100000010010011b
560 mov ebx, GUEST_GS_ACCESS
566 mov ebx, GUEST_LDTR_ACCESS
571 mov eax, 01000000010001011b
572 mov ebx, GUEST_TR_ACCESS
582 mov eax, VMX_FAIL_INVALID
585 mov eax, VMX_FAIL_VALID
599 ; mov eax, 0xffffffff
601 mov ebx, GUEST_ES_LIMIT
606 ; mov eax, 0xffffffff
608 mov ebx, GUEST_CS_LIMIT
613 ; mov eax, 0xffffffff
615 mov ebx, GUEST_SS_LIMIT
620 ; mov eax, 0xffffffff
622 mov ebx, GUEST_DS_LIMIT
627 ; mov eax, 0xffffffff
629 mov ebx, GUEST_FS_LIMIT
634 ; mov eax, 0xffffffff
636 mov ebx, GUEST_GS_LIMIT
641 ; mov eax, 0xffffffff
643 mov ebx, GUEST_TR_LIMIT
651 mov eax, VMX_FAIL_INVALID
654 mov eax, VMX_FAIL_VALID
662 Init_VMCS_GuestState:
673 call InitGuestSelectors
679 call InitGuestDescRegs
685 call InitGuestSegBases
692 call InitGuestSegsLimits
698 call InitGuestSegsAccess
710 mov ebx, GUEST_RFLAGS
711 mov eax, dword 0x00000002
717 mov eax, dword 0x00000400
725 mov eax, VMX_FAIL_INVALID
728 mov eax, VMX_FAIL_VALID
735 ; Setup_VMCS_HostState
736 ; Copy all of the host registers into the host state of a vmcs
746 mov ebx, VMCS_HOST_ES_SELECTOR
752 mov ebx, VMCS_HOST_CS_SELECTOR
758 mov ebx, VMCS_HOST_SS_SELECTOR
764 mov ebx, VMCS_HOST_DS_SELECTOR
770 mov ebx, VMCS_HOST_FS_SELECTOR
776 mov ebx, VMCS_HOST_GS_SELECTOR
784 mov ebx, VMCS_HOST_TR_SELECTOR
792 mov eax, VMX_FAIL_INVALID
795 mov eax, VMX_FAIL_VALID
816 mov ebx, HOST_GDTR_BASE
823 mov ebx, HOST_IDTR_BASE
830 mov ebx, HOST_FS_BASE
836 mov ebx, HOST_GS_BASE
842 mov ebx, HOST_TR_BASE
850 mov eax, VMX_FAIL_INVALID
853 mov eax, VMX_FAIL_VALID
882 call InitHostSelectors
888 call InitHostBaseRegs
898 mov eax, VMX_FAIL_INVALID
901 mov eax, VMX_FAIL_VALID
908 ; Launch_VM - inits a vmcs with an ip and launches it
909 ; [eip = ebp + 8], [vmcs = ebp + 12]
910 ; int Launch_VM(ullont_t VMCS, uint_t eip);
925 mov eax, dword 0x0000681E
927 vmwrite eax, [ebp+16]
938 mov eax, VMX_FAIL_INVALID
943 mov eax, VMX_FAIL_VALID
945 mov ebx, dword 0x00004400