PAEand32Bit.mac revision d0878249c440cb192560dca6a8bc28fbd42156bc
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; VMM - World Switchers, template for PAE and 32-Bit.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; Copyright (C) 2006-2007 Sun Microsystems, Inc.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; This file is part of VirtualBox Open Source Edition (OSE), as
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; available from http://www.virtualbox.org. This file is free software;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; you can redistribute it and/or modify it under the terms of the GNU
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; General Public License (GPL) as published by the Free Software
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; Foundation, in version 2 as it comes in the "COPYING" file of the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; Clara, CA 95054 USA or visit http://www.sun.com if you need
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync; additional information or have any questions.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync;%define DEBUG_STUFF 1
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync;*******************************************************************************
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync;* Header Files *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync;*******************************************************************************
%include "VBox/stam.mac"
%include "VBox/vm.mac"
%include "CPUMInternal.mac"
%include "VMMSwitcher/VMMSwitcher.mac"
FIXUP FIX_HC_VM_OFF, 1, VM.StatSwitcherToGC
FIXUP FIX_HC_VM_OFF, 1, VM.StatSwitcherToHC
mov [edx + CPUMCPU.Host.ebx], ebx
mov [edx + CPUMCPU.Host.edi], edi
mov [edx + CPUMCPU.Host.esi], esi
mov [edx + CPUMCPU.Host.esp], esp
mov [edx + CPUMCPU.Host.ebp], ebp
mov [edx + CPUMCPU.Host.ds], ds
mov [edx + CPUMCPU.Host.es], es
mov [edx + CPUMCPU.Host.fs], fs
mov [edx + CPUMCPU.Host.gs], gs
mov [edx + CPUMCPU.Host.ss], ss
sldt [edx + CPUMCPU.Host.ldtr]
sidt [edx + CPUMCPU.Host.idtr]
sgdt [edx + CPUMCPU.Host.gdtr]
str [edx + CPUMCPU.Host.tr]
pop dword [edx + CPUMCPU.Host.eflags]
FIXUP FIX_NO_SYSENTER_JMP, 0, htg_no_sysenter - NAME(Start) ; this will insert a jmp htg_no_sysenter if host doesn't use sysenter.
mov [ebx + CPUMCPU.Host.SysEnter.cs], eax
mov [ebx + CPUMCPU.Host.SysEnter.cs + 4], edx
FIXUP FIX_NO_SYSCALL_JMP, 0, htg_no_syscall - NAME(Start) ; this will insert a jmp htg_no_syscall if host doesn't use syscall.
mov esi, [edx + CPUMCPU.fUseFlags] ; esi == use flags.
and esi, ~CPUM_USED_FPU ; Clear CPUM_USED_* flags. ;;@todo FPU check can be optimized to use cr0 flags!
mov [edx + CPUMCPU.fUseFlags], esi
mov [edx + CPUMCPU.Host.cr0], eax
;mov [edx + CPUMCPU.Host.cr2], eax
mov [edx + CPUMCPU.Host.cr3], eax
mov [edx + CPUMCPU.Host.cr4], eax
; Change CR0 and CR4 so we can correctly emulate FPU/MMX/SSE[23] exceptions
mov ecx, [edx + CPUMCPU.Guest.cr4]
; in CPUMCPU.Hyper.cr4 (which isn't currently being used). That should
and ecx, [edx + CPUM.CR4.AndMask]
or eax, [edx + CPUM.CR4.OrMask]
mov eax, [edx + CPUMCPU.Guest.cr0]
lgdt [edx + CPUMCPU.Hyper.gdtr]
mov ebp, [edx + CPUMCPU.Hyper.cr3]
lidt [edx + CPUMCPU.Hyper.idtr]
mov eax, [edx + CPUMCPU.Hyper.esp]
mov [edx + CPUMCPU.Hyper.lss_esp], eax
lss esp, [edx + CPUMCPU.Hyper.lss_esp]
ltr word [edx + CPUMCPU.Hyper.tr]
lldt [edx + CPUMCPU.Hyper.ldtr]
mov esi, [edx + CPUMCPU.fUseFlags]
mov ebx, [edx + CPUMCPU.Hyper.ebx]
mov ebp, [edx + CPUMCPU.Hyper.ebp]
mov esi, [edx + CPUMCPU.Hyper.esi]
mov edi, [edx + CPUMCPU.Hyper.edi]
push dword [edx + CPUMCPU.Hyper.eflags]
mov eax, [edx + CPUMCPU.Hyper.eip]
mov eax, [edx + CPUMCPU.Hyper.eip]
FIXUP FIX_GC_VM_OFF, 1, VM.StatSwitcherToGC
mov [edx + CPUMCPU.Host.dr7], eax
mov [edx + CPUMCPU.Host.dr6], eax
mov [edx + CPUMCPU.Host.dr0], eax
mov [edx + CPUMCPU.Host.dr1], ebx
mov [edx + CPUMCPU.Host.dr2], ecx
mov [edx + CPUMCPU.Host.dr3], eax
mov ebx, [edx + CPUMCPU.Hyper.dr]
mov ecx, [edx + CPUMCPU.Hyper.dr + 8*1]
mov eax, [edx + CPUMCPU.Hyper.dr + 8*2]
mov ebx, [edx + CPUMCPU.Hyper.dr + 8*3]
;mov eax, [edx + CPUMCPU.Hyper.dr + 8*6]
mov eax, [edx + CPUMCPU.Hyper.dr + 8*7]
FIXUP FIX_GC_VM_OFF, 1, VM.StatTotalInGC
FIXUP FIX_GC_VM_OFF, 1, VM.StatTotalGCToQemu
FIXUP FIX_GC_VM_OFF, 1, VM.StatSwitcherToHC
mov eax, [esp + 4 + CPUMCTXCORE.eax]
mov [edx + CPUMCPU.Guest.eax], eax
mov eax, [esp + 4 + CPUMCTXCORE.ecx]
mov [edx + CPUMCPU.Guest.ecx], eax
mov eax, [esp + 4 + CPUMCTXCORE.edx]
mov [edx + CPUMCPU.Guest.edx], eax
mov eax, [esp + 4 + CPUMCTXCORE.ebx]
mov [edx + CPUMCPU.Guest.ebx], eax
mov eax, [esp + 4 + CPUMCTXCORE.esp]
mov [edx + CPUMCPU.Guest.esp], eax
mov eax, [esp + 4 + CPUMCTXCORE.ebp]
mov [edx + CPUMCPU.Guest.ebp], eax
mov eax, [esp + 4 + CPUMCTXCORE.esi]
mov [edx + CPUMCPU.Guest.esi], eax
mov eax, [esp + 4 + CPUMCTXCORE.edi]
mov [edx + CPUMCPU.Guest.edi], eax
mov eax, dword [esp + 4 + CPUMCTXCORE.es]
mov dword [edx + CPUMCPU.Guest.es], eax
mov eax, dword [esp + 4 + CPUMCTXCORE.cs]
mov dword [edx + CPUMCPU.Guest.cs], eax
mov eax, dword [esp + 4 + CPUMCTXCORE.ss]
mov dword [edx + CPUMCPU.Guest.ss], eax
mov eax, dword [esp + 4 + CPUMCTXCORE.ds]
mov dword [edx + CPUMCPU.Guest.ds], eax
mov eax, dword [esp + 4 + CPUMCTXCORE.fs]
mov dword [edx + CPUMCPU.Guest.fs], eax
mov eax, dword [esp + 4 + CPUMCTXCORE.gs]
mov dword [edx + CPUMCPU.Guest.gs], eax
mov eax, [esp + 4 + CPUMCTXCORE.eflags]
mov dword [edx + CPUMCPU.Guest.eflags], eax
mov eax, [esp + 4 + CPUMCTXCORE.eip]
mov dword [edx + CPUMCPU.Guest.eip], eax
FIXUP FIX_GC_VM_OFF, 1, VM.StatTotalInGC
FIXUP FIX_GC_VM_OFF, 1, VM.StatTotalGCToQemu
FIXUP FIX_GC_VM_OFF, 1, VM.StatSwitcherToHC
mov eax, [ecx + CPUMCTXCORE.edi]
mov [edx + CPUMCPU.Hyper.edi], eax
mov eax, [ecx + CPUMCTXCORE.esi]
mov [edx + CPUMCPU.Hyper.esi], eax
mov eax, [ecx + CPUMCTXCORE.ebp]
mov [edx + CPUMCPU.Hyper.ebp], eax
mov eax, [ecx + CPUMCTXCORE.eax]
mov [edx + CPUMCPU.Hyper.eax], eax
mov eax, [ecx + CPUMCTXCORE.ebx]
mov [edx + CPUMCPU.Hyper.ebx], eax
mov eax, [ecx + CPUMCTXCORE.edx]
mov [edx + CPUMCPU.Hyper.edx], eax
mov eax, [ecx + CPUMCTXCORE.ecx]
mov [edx + CPUMCPU.Hyper.ecx], eax
mov eax, [ecx + CPUMCTXCORE.esp]
mov [edx + CPUMCPU.Hyper.esp], eax
mov eax, [ecx + CPUMCTXCORE.ss]
mov [edx + CPUMCPU.Hyper.ss], eax
mov eax, [ecx + CPUMCTXCORE.gs]
mov [edx + CPUMCPU.Hyper.gs], eax
mov eax, [ecx + CPUMCTXCORE.fs]
mov [edx + CPUMCPU.Hyper.fs], eax
mov eax, [ecx + CPUMCTXCORE.es]
mov [edx + CPUMCPU.Hyper.es], eax
mov eax, [ecx + CPUMCTXCORE.ds]
mov [edx + CPUMCPU.Hyper.ds], eax
mov eax, [ecx + CPUMCTXCORE.cs]
mov [edx + CPUMCPU.Hyper.cs], eax
mov eax, [ecx + CPUMCTXCORE.eflags]
mov [edx + CPUMCPU.Hyper.eflags], eax
mov eax, [ecx + CPUMCTXCORE.eip]
mov [edx + CPUMCPU.Hyper.eip], eax
FIXUP FIX_GC_VM_OFF, 1, VM.StatTotalInGC
FIXUP FIX_GC_VM_OFF, 1, VM.StatTotalGCToQemu
FIXUP FIX_GC_VM_OFF, 1, VM.StatSwitcherToHC
pop dword [edx + CPUMCPU.Hyper.eip] ; call return from stack
mov dword [edx + CPUMCPU.Hyper.ebx], ebx
mov dword [edx + CPUMCPU.Hyper.esi], esi
mov dword [edx + CPUMCPU.Hyper.edi], edi
mov dword [edx + CPUMCPU.Hyper.ebp], ebp
mov dword [edx + CPUMCPU.Hyper.esp], esp
; str [edx + CPUMCPU.Hyper.tr] - double fault only, and it won't be right then either.
sldt [edx + CPUMCPU.Hyper.ldtr]
; No need to save CRx here. They are set dynamically according to Guest/Host requirements.
mov ecx, [edx + CPUMCPU.Host.cr3]
lgdt [edx + CPUMCPU.Host.gdtr]
lidt [edx + CPUMCPU.Host.idtr]
movzx eax, word [edx + CPUMCPU.Host.tr] ; eax <- TR
ltr word [edx + CPUMCPU.Host.tr]
movzx eax, word [edx + CPUMCPU.Host.tr] ; eax <- TR
ltr word [edx + CPUMCPU.Host.tr]
lldt [edx + CPUMCPU.Host.ldtr]
mov eax, [edx + CPUMCPU.Host.ds]
mov eax, [edx + CPUMCPU.Host.es]
mov eax, [edx + CPUMCPU.Host.fs]
mov eax, [edx + CPUMCPU.Host.gs]
lss esp, [edx + CPUMCPU.Host.esp]
FIXUP FIX_NO_SYSENTER_JMP, 0, gth_sysenter_no - NAME(Start) ; this will insert a jmp gth_sysenter_no if host doesn't use sysenter.
mov eax, [edx + CPUMCPU.Host.SysEnter.cs]
mov ebx, [edx + CPUMCPU.Host.SysEnter.cs + 4]
xchg edx, ebx ; save/load edx
FIXUP FIX_NO_SYSCALL_JMP, 0, gth_syscall_no - NAME(Start) ; this will insert a jmp gth_syscall_no if host doesn't use syscall.
mov esi, [edx + CPUMCPU.fUseFlags] ; esi == use flags.
FIXUP FIX_NO_FXSAVE_JMP, 0, gth_no_fxsave - NAME(Start) ; this will insert a jmp gth_no_fxsave if fxsave isn't supported.
fxsave [edx + CPUMCPU.Guest.fpu]
fxrstor [edx + CPUMCPU.Host.fpu]
fnsave [edx + CPUMCPU.Guest.fpu]
mov eax, [edx + CPUMCPU.Host.fpu] ; control word
test eax, [edx + CPUMCPU.Host.fpu + 4] ; status word
and dword [edx + CPUMCPU.Host.fpu + 4], ~03Fh
frstor [edx + CPUMCPU.Host.fpu]
mov ecx, [edx + CPUMCPU.Host.cr4]
mov ecx, [edx + CPUMCPU.Host.cr0]
;mov ecx, [edx + CPUMCPU.Host.cr2] ; assumes this is waste of time.
mov edi, [edx + CPUMCPU.Host.edi]
mov esi, [edx + CPUMCPU.Host.esi]
mov ebx, [edx + CPUMCPU.Host.ebx]
mov ebp, [edx + CPUMCPU.Host.ebp]
push dword [edx + CPUMCPU.Host.eflags]
mov eax, [edx + CPUMCPU.Host.dr0]
mov ebx, [edx + CPUMCPU.Host.dr1]
mov ecx, [edx + CPUMCPU.Host.dr2]
mov eax, [edx + CPUMCPU.Host.dr3]
mov ebx, [edx + CPUMCPU.Host.dr6]
mov ecx, [edx + CPUMCPU.Host.dr7]
at VMMSWITCHERDEF.pvCode, RTCCPTR_DEF NAME(Start)
at VMMSWITCHERDEF.pvFixups, RTCCPTR_DEF NAME(Fixups)
at VMMSWITCHERDEF.pszDesc, RTCCPTR_DEF NAME(Description)
at VMMSWITCHERDEF.pfnRelocate, RTCCPTR_DEF NAME(Relocate)
at VMMSWITCHERDEF.enmType, dd SWITCHER_TYPE
at VMMSWITCHERDEF.cbCode, dd NAME(End) - NAME(Start)
at VMMSWITCHERDEF.offR0HostToGuest, dd NAME(vmmR0HostToGuest) - NAME(Start)
at VMMSWITCHERDEF.offGCGuestToHost, dd NAME(vmmGCGuestToHost) - NAME(Start)
at VMMSWITCHERDEF.offGCCallTrampoline, dd NAME(vmmGCCallTrampoline) - NAME(Start)
at VMMSWITCHERDEF.offGCGuestToHostAsm, dd NAME(VMMGCGuestToHostAsm) - NAME(Start)
at VMMSWITCHERDEF.offGCGuestToHostAsmHyperCtx, dd NAME(VMMGCGuestToHostAsmHyperCtx)- NAME(Start)
at VMMSWITCHERDEF.offGCGuestToHostAsmGuestCtx, dd NAME(VMMGCGuestToHostAsmGuestCtx)- NAME(Start)
at VMMSWITCHERDEF.offHCCode0, dd 0
at VMMSWITCHERDEF.cbHCCode0, dd NAME(IDEnterTarget) - NAME(Start)
at VMMSWITCHERDEF.cbHCCode0, dd NAME(FarJmpGCTarget) - NAME(Start)
at VMMSWITCHERDEF.offHCCode1, dd NAME(HCExitTarget) - NAME(Start)
at VMMSWITCHERDEF.cbHCCode1, dd NAME(End) - NAME(HCExitTarget)
at VMMSWITCHERDEF.offIDCode0, dd NAME(IDEnterTarget) - NAME(Start)
at VMMSWITCHERDEF.cbIDCode0, dd NAME(FarJmpGCTarget) - NAME(IDEnterTarget)
at VMMSWITCHERDEF.offIDCode1, dd NAME(IDExitTarget) - NAME(Start)
at VMMSWITCHERDEF.cbIDCode1, dd NAME(HCExitTarget) - NAME(IDExitTarget)
at VMMSWITCHERDEF.offIDCode0, dd 0
at VMMSWITCHERDEF.cbIDCode0, dd 0
at VMMSWITCHERDEF.offIDCode1, dd 0
at VMMSWITCHERDEF.cbIDCode1, dd 0
at VMMSWITCHERDEF.offGCCode, dd NAME(FarJmpGCTarget) - NAME(Start)
at VMMSWITCHERDEF.cbGCCode, dd NAME(IDExitTarget) - NAME(FarJmpGCTarget)
at VMMSWITCHERDEF.cbGCCode, dd NAME(HCExitTarget) - NAME(FarJmpGCTarget)