%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
; Load the NULL selector into DS, ES, FS and GS on 64-bit darwin so we don't
; risk loading a stale LDT value or something invalid.
%define HM_64_BIT_USE_NULL_SEL
;; The offset of the XMM registers in X86FXSTATE.
; Use define because I'm too lazy to convert the struct.
%define XMM_OFF_IN_X86FXSTATE 160
;; This is too risky wrt. stability, performance and correctness.
;%define VBOX_WITH_DR6_EXPERIMENT 1
; Macro generating an equivalent to pushad
; Macro generating an equivalent to popad
; Macro saving all segment registers on the stack.
; @param 1 full width register name
; @param 2 16-bit register name for \a 1.
; Macro restoring all segment registers on the stack
; @param 1 full width register name
; @param 2 16-bit register name for \a 1.
; Save a host and load the corresponding guest MSR (trashes rdx & rcx)
mov edx, dword [xSI + %2 + 4]
mov eax, dword [xSI + %2]
; Save a guest and load the corresponding host MSR (trashes rdx & rcx)
; Only really useful for gs kernel base as that one can be changed behind our back (swapgs)
mov dword [xSI + %2], eax
mov dword [xSI + %2 + 4], edx
; Load the corresponding host MSR (trashes rdx & rcx)
; trashes, rax, rdx & rcx
%ifndef HM_64_BIT_USE_NULL_SEL
; Special case for FS; Windows and Linux either don't use it or restore it when leaving kernel mode, Solaris OTOH doesn't and we must save it.
%ifndef HM_64_BIT_USE_NULL_SEL
; Special case for GS; OSes typically use swapgs to reset the hidden base register for GS on entry into the kernel. The same happens on exit
%ifndef HM_64_BIT_USE_NULL_SEL
; trashes, rax, rdx & rcx
; Note: do not step through this code with a debugger!
%ifndef HM_64_BIT_USE_NULL_SEL
%ifndef HM_64_BIT_USE_NULL_SEL
%ifndef HM_64_BIT_USE_NULL_SEL
; Now it's safe to step again
%ifndef HM_64_BIT_USE_NULL_SEL
;*******************************************************************************
;*******************************************************************************
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
extern NAME(SUPR0AbsIs64bit)
extern NAME(SUPR0Abs64bitKernelCS)
extern NAME(SUPR0Abs64bitKernelSS)
extern NAME(SUPR0Abs64bitKernelDS)
extern NAME(SUPR0AbsKernelCS)
%ifdef VBOX_WITH_KERNEL_USING_XMM
extern NAME(CPUMIsGuestFPUStateActive)
;*******************************************************************************
;*******************************************************************************
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
; Store the SUPR0AbsIs64bit absolute value here so we can
cmp/test without
; needing to clobber a register. (This trick doesn't quite work for PE btw.
; but that's not relevant atm.)
GLOBALNAME g_fVMXIs64bitHost
; * Executes VMWRITE, 64-bit value.
; * @returns VBox status code
; * @param idxField x86: [ebp + 08h] msc: rcx gcc: rdi VMCS index
; * @param u64Data x86: [ebp + 0ch] msc: rdx gcc: rsi VM field value
mov ecx, [esp + 4] ; idxField
lea edx, [esp + 8] ; &u64Data
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
vmwrite ecx, [edx] ; low dword
vmwrite ecx, [edx + 4] ; high dword
mov eax, VERR_VMX_INVALID_VMCS_PTR
mov eax, VERR_VMX_INVALID_VMCS_FIELD
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
mov r8d, VERR_VMX_INVALID_VMCS_FIELD
mov r9d, VERR_VMX_INVALID_VMCS_PTR
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; * Executes VMREAD, 64-bit value
; * @returns VBox status code
; * @param idxField VMCS index
; * @param pData Ptr to store VM field value
;DECLASM(int) VMXReadVmcs64(uint32_t idxField, uint64_t *pData);
mov ecx, [esp + 4] ; idxField
mov edx, [esp + 8] ; pData
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
vmread [edx], ecx ; low dword
vmread [edx + 4], ecx ; high dword
mov eax, VERR_VMX_INVALID_VMCS_PTR
mov eax, VERR_VMX_INVALID_VMCS_FIELD
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
mov r8d, VERR_VMX_INVALID_VMCS_FIELD
mov r9d, VERR_VMX_INVALID_VMCS_PTR
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; * Executes VMREAD, 32-bit value.
; * @returns VBox status code
; * @param idxField VMCS index
; * @param pu32Data Ptr to store VM field value
;DECLASM(int) VMXReadVmcs32(uint32_t idxField, uint32_t *pu32Data);
mov ecx, [esp + 4] ; idxField
mov edx, [esp + 8] ; pu32Data
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
mov eax, VERR_VMX_INVALID_VMCS_PTR
mov eax, VERR_VMX_INVALID_VMCS_FIELD
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
mov r8d, VERR_VMX_INVALID_VMCS_FIELD
mov r9d, VERR_VMX_INVALID_VMCS_PTR
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; * Executes VMWRITE, 32-bit value.
; * @returns VBox status code
; * @param idxField VMCS index
; * @param u32Data Ptr to store VM field value
;DECLASM(int) VMXWriteVmcs32(uint32_t idxField, uint32_t u32Data);
mov ecx, [esp + 4] ; idxField
mov edx, [esp + 8] ; u32Data
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
mov eax, VERR_VMX_INVALID_VMCS_PTR
mov eax, VERR_VMX_INVALID_VMCS_FIELD
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
mov r8d, VERR_VMX_INVALID_VMCS_FIELD
mov r9d, VERR_VMX_INVALID_VMCS_PTR
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; * @returns VBox status code
; * @param HCPhysVMXOn Physical address of VMXON structure
;DECLASM(int) VMXEnable(RTHCPHYS HCPhysVMXOn);
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
mov eax, VERR_VMX_INVALID_VMXON_PTR
mov eax, VERR_VMX_GENERIC
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
lea rdx, [rsp + 4] ; &HCPhysVMXOn.
mov r8d, VERR_INVALID_PARAMETER
mov r9d, VERR_VMX_INVALID_VMCS_PTR
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
;DECLASM(void) VMXDisable(void);
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; * @returns VBox status code
; * @param HCPhysVmcs Physical address of VM control structure
;DECLASM(int) VMXClearVMCS(RTHCPHYS HCPhysVmcs);
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
mov eax, VERR_VMX_INVALID_VMCS_PTR
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
lea rdx, [rsp + 4] ; &HCPhysVmcs
mov r9d, VERR_VMX_INVALID_VMCS_PTR
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
; * @returns VBox status code
; * @param HCPhysVmcs Physical address of VMCS structure
;DECLASM(int) VMXActivateVMCS(RTHCPHYS HCPhysVmcs);
BEGINPROC VMXActivateVMCS
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
mov eax, VERR_VMX_INVALID_VMCS_PTR
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
lea rdx, [rsp + 4] ; &HCPhysVmcs
mov r9d, VERR_VMX_INVALID_VMCS_PTR
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; * @returns VBox status code
; * @param [esp + 04h] gcc:rdi msc:rcx Param 1 - First parameter - Address that will receive the current pointer
;DECLASM(int) VMXGetActivateVMCS(RTHCPHYS *pVMCS);
BEGINPROC VMXGetActivateVMCS
mov eax, VERR_NOT_SUPPORTED
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
lea rdx, [rsp + 4] ; &HCPhysVmcs
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
ENDPROC VMXGetActivateVMCS
; * Invalidate a page using invept
; @param enmFlush msc:ecx gcc:edi x86:[esp+04] Type of flush
; @param pDescriptor msc:edx gcc:esi x86:[esp+08] Descriptor pointer
;DECLASM(int) VMXR0InvEPT(VMX_FLUSH enmFlush, uint64_t *pDescriptor);
; invept rdi, qword [rsi]
DB 0x66, 0x0F, 0x38, 0x80, 0x3E
; invept rcx, qword [rdx]
DB 0x66, 0x0F, 0x38, 0x80, 0xA
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; invept ecx, qword [edx]
DB 0x66, 0x0F, 0x38, 0x80, 0xA
mov eax, VERR_VMX_INVALID_VMCS_PTR
mov eax, VERR_INVALID_PARAMETER
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
mov ecx, [rsp + 4] ; enmFlush
mov edx, [rsp + 8] ; pDescriptor
; invept rcx, qword [rdx]
DB 0x66, 0x0F, 0x38, 0x80, 0xA
mov r8d, VERR_INVALID_PARAMETER
mov r9d, VERR_VMX_INVALID_VMCS_PTR
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; * Invalidate a page using invvpid
; @param enmFlush msc:ecx gcc:edi x86:[esp+04] Type of flush
; @param pDescriptor msc:edx gcc:esi x86:[esp+08] Descriptor pointer
;DECLASM(int) VMXR0InvVPID(VMX_FLUSH enmFlush, uint64_t *pDescriptor);
; invvpid rdi, qword [rsi]
DB 0x66, 0x0F, 0x38, 0x81, 0x3E
; invvpid rcx, qword [rdx]
DB 0x66, 0x0F, 0x38, 0x81, 0xA
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
cmp byte [NAME(g_fVMXIs64bitHost)], 0
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; invvpid ecx, qword [edx]
DB 0x66, 0x0F, 0x38, 0x81, 0xA
mov eax, VERR_VMX_INVALID_VMCS_PTR
mov eax, VERR_INVALID_PARAMETER
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
mov ecx, [rsp + 4] ; enmFlush
mov edx, [rsp + 8] ; pDescriptor
; invvpid rcx, qword [rdx]
DB 0x66, 0x0F, 0x38, 0x81, 0xA
mov r8d, VERR_INVALID_PARAMETER
mov r9d, VERR_VMX_INVALID_VMCS_PTR
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
; @param pPageGC msc:rcx gcc:rdi x86:[esp+04] Virtual page to invalidate
; @param uASID msc:rdx gcc:rsi x86:[esp+0C] Tagged TLB id
;DECLASM(void) SVMR0InvlpgA(RTGCPTR pPageGC, uint32_t uASID);
%else ; GC_ARCH_BITS != 64
; @param pPageGC msc:ecx gcc:edi x86:[esp+04] Virtual page to invalidate
; @param uASID msc:edx gcc:esi x86:[esp+08] Tagged TLB id
;DECLASM(void) SVMR0InvlpgA(RTGCPTR pPageGC, uint32_t uASID);
; ``Perhaps unexpectedly, instructions that move or generate 32-bit register
; values also set the upper 32 bits of the register to zero. Consequently
; there is no need for an instruction movzlq.''
%endif ; GC_ARCH_BITS != 64
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
; * Gets 64-bit GDTR and IDTR on darwin.
; * @param pGdtr Where to store the 64-bit GDTR.
; * @param pIdtr Where to store the 64-bit IDTR.
;DECLASM(void) hmR0Get64bitGdtrAndIdtr(PX86XDTR64 pGdtr, PX86XDTR64 pIdtr);
BEGINPROC hmR0Get64bitGdtrAndIdtr
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
mov ecx, [rsp + 4] ; pGdtr
mov edx, [rsp + 8] ; pIdtr
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
ENDPROC hmR0Get64bitGdtrAndIdtr
; * Gets 64-bit CR3 on darwin.
;DECLASM(uint64_t) hmR0Get64bitCR3(void);
BEGINPROC hmR0Get64bitCR3
db 0xea ; jmp far .sixtyfourbit_mode
dd .sixtyfourbit_mode, NAME(SUPR0Abs64bitKernelCS)
.fpret: ; 16:32 Pointer to .the_end.
dd .the_end, NAME(SUPR0AbsKernelCS)
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL
%ifdef VBOX_WITH_KERNEL_USING_XMM
; load the guest ones when necessary.
; @cproto DECLASM(int) hmR0VMXStartVMWrapXMM(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu, PFNHMVMXSTARTVM pfnStartVM);
; @param fResumeVM msc:rcx
; @param pVMCSCache msc:r8
; @param pVCpu msc:[rbp+30h]
; @param pfnStartVM msc:[rbp+38h]
; @remarks This is essentially the same code as hmR0SVMRunWrapXMM, only the parameters differ a little bit.
; ASSUMING 64-bit and windows for now.
BEGINPROC hmR0VMXStartVMWrapXMM
sub xSP, 0a0h + 040h ; Don't bother optimizing the frame size.
; spill input parameters.
mov [xBP + 010h], rcx ; fResumeVM
mov [xBP + 018h], rdx ; pCtx
mov [xBP + 020h], r8 ; pVMCSCache
mov [xBP + 028h], r9 ; pVM
; Ask CPUM whether we've started using the FPU yet.
mov rcx, [xBP + 30h] ; pVCpu
call NAME(CPUMIsGuestFPUStateActive)
jnz .guest_fpu_state_active
; No need to mess with XMM registers just call the start routine and return.
mov r11, [xBP + 38h] ; pfnStartVM
mov r10, [xBP + 30h] ; pVCpu
mov rcx, [xBP + 010h] ; fResumeVM
mov rdx, [xBP + 018h] ; pCtx
mov r8, [xBP + 020h] ; pVMCSCache
mov r9, [xBP + 028h] ; pVM
; Save the host XMM registers.
movdqa [rsp + 040h + 000h], xmm6
movdqa [rsp + 040h + 010h], xmm7
movdqa [rsp + 040h + 020h], xmm8
movdqa [rsp + 040h + 030h], xmm9
movdqa [rsp + 040h + 040h], xmm10
movdqa [rsp + 040h + 050h], xmm11
movdqa [rsp + 040h + 060h], xmm12
movdqa [rsp + 040h + 070h], xmm13
movdqa [rsp + 040h + 080h], xmm14
movdqa [rsp + 040h + 090h], xmm15
; Load the full guest XMM register state.
mov r10, [xBP + 018h] ; pCtx
lea r10, [r10 + XMM_OFF_IN_X86FXSTATE]
movdqa xmm0, [r10 + 000h]
movdqa xmm1, [r10 + 010h]
movdqa xmm2, [r10 + 020h]
movdqa xmm3, [r10 + 030h]
movdqa xmm4, [r10 + 040h]
movdqa xmm5, [r10 + 050h]
movdqa xmm6, [r10 + 060h]
movdqa xmm7, [r10 + 070h]
movdqa xmm8, [r10 + 080h]
movdqa xmm9, [r10 + 090h]
movdqa xmm10, [r10 + 0a0h]
movdqa xmm11, [r10 + 0b0h]
movdqa xmm12, [r10 + 0c0h]
movdqa xmm13, [r10 + 0d0h]
movdqa xmm14, [r10 + 0e0h]
movdqa xmm15, [r10 + 0f0h]
; Make the call (same as in the other case ).
mov r11, [xBP + 38h] ; pfnStartVM
mov r10, [xBP + 30h] ; pVCpu
mov rcx, [xBP + 010h] ; fResumeVM
mov rdx, [xBP + 018h] ; pCtx
mov r8, [xBP + 020h] ; pVMCSCache
mov r9, [xBP + 028h] ; pVM
; Save the guest XMM registers.
mov r10, [xBP + 018h] ; pCtx
lea r10, [r10 + XMM_OFF_IN_X86FXSTATE]
movdqa [r10 + 000h], xmm0
movdqa [r10 + 010h], xmm1
movdqa [r10 + 020h], xmm2
movdqa [r10 + 030h], xmm3
movdqa [r10 + 040h], xmm4
movdqa [r10 + 050h], xmm5
movdqa [r10 + 060h], xmm6
movdqa [r10 + 070h], xmm7
movdqa [r10 + 080h], xmm8
movdqa [r10 + 090h], xmm9
movdqa [r10 + 0a0h], xmm10
movdqa [r10 + 0b0h], xmm11
movdqa [r10 + 0c0h], xmm12
movdqa [r10 + 0d0h], xmm13
movdqa [r10 + 0e0h], xmm14
movdqa [r10 + 0f0h], xmm15
; Load the host XMM registers.
movdqa xmm6, [rsp + 040h + 000h]
movdqa xmm7, [rsp + 040h + 010h]
movdqa xmm8, [rsp + 040h + 020h]
movdqa xmm9, [rsp + 040h + 030h]
movdqa xmm10, [rsp + 040h + 040h]
movdqa xmm11, [rsp + 040h + 050h]
movdqa xmm12, [rsp + 040h + 060h]
movdqa xmm13, [rsp + 040h + 070h]
movdqa xmm14, [rsp + 040h + 080h]
movdqa xmm15, [rsp + 040h + 090h]
ENDPROC hmR0VMXStartVMWrapXMM
; Wrapper around
svm.pfnVMRun that preserves host XMM registers and
; load the guest ones when necessary.
; @cproto DECLASM(int) hmR0SVMRunWrapXMM(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu, PFNHMSVMVMRUN pfnVMRun);
; @param pVMCBHostPhys msc:rcx
; @param pVMCBPhys msc:rdx
; @param pVCpu msc:[rbp+30h]
; @param pfnVMRun msc:[rbp+38h]
; @remarks This is essentially the same code as hmR0VMXStartVMWrapXMM, only the parameters differ a little bit.
; ASSUMING 64-bit and windows for now.
BEGINPROC hmR0SVMRunWrapXMM
sub xSP, 0a0h + 040h ; Don't bother optimizing the frame size.
; spill input parameters.
mov [xBP + 010h], rcx ; pVMCBHostPhys
mov [xBP + 018h], rdx ; pVMCBPhys
mov [xBP + 020h], r8 ; pCtx
mov [xBP + 028h], r9 ; pVM
; Ask CPUM whether we've started using the FPU yet.
mov rcx, [xBP + 30h] ; pVCpu
call NAME(CPUMIsGuestFPUStateActive)
jnz .guest_fpu_state_active
; No need to mess with XMM registers just call the start routine and return.
mov r11, [xBP + 38h] ; pfnVMRun
mov r10, [xBP + 30h] ; pVCpu
mov rcx, [xBP + 010h] ; pVMCBHostPhys
mov rdx, [xBP + 018h] ; pVMCBPhys
mov r8, [xBP + 020h] ; pCtx
mov r9, [xBP + 028h] ; pVM
; Save the host XMM registers.
movdqa [rsp + 040h + 000h], xmm6
movdqa [rsp + 040h + 010h], xmm7
movdqa [rsp + 040h + 020h], xmm8
movdqa [rsp + 040h + 030h], xmm9
movdqa [rsp + 040h + 040h], xmm10
movdqa [rsp + 040h + 050h], xmm11
movdqa [rsp + 040h + 060h], xmm12
movdqa [rsp + 040h + 070h], xmm13
movdqa [rsp + 040h + 080h], xmm14
movdqa [rsp + 040h + 090h], xmm15
; Load the full guest XMM register state.
mov r10, [xBP + 020h] ; pCtx
lea r10, [r10 + XMM_OFF_IN_X86FXSTATE]
movdqa xmm0, [r10 + 000h]
movdqa xmm1, [r10 + 010h]
movdqa xmm2, [r10 + 020h]
movdqa xmm3, [r10 + 030h]
movdqa xmm4, [r10 + 040h]
movdqa xmm5, [r10 + 050h]
movdqa xmm6, [r10 + 060h]
movdqa xmm7, [r10 + 070h]
movdqa xmm8, [r10 + 080h]
movdqa xmm9, [r10 + 090h]
movdqa xmm10, [r10 + 0a0h]
movdqa xmm11, [r10 + 0b0h]
movdqa xmm12, [r10 + 0c0h]
movdqa xmm13, [r10 + 0d0h]
movdqa xmm14, [r10 + 0e0h]
movdqa xmm15, [r10 + 0f0h]
; Make the call (same as in the other case ).
mov r11, [xBP + 38h] ; pfnVMRun
mov r10, [xBP + 30h] ; pVCpu
mov rcx, [xBP + 010h] ; pVMCBHostPhys
mov rdx, [xBP + 018h] ; pVMCBPhys
mov r8, [xBP + 020h] ; pCtx
mov r9, [xBP + 028h] ; pVM
; Save the guest XMM registers.
mov r10, [xBP + 020h] ; pCtx
lea r10, [r10 + XMM_OFF_IN_X86FXSTATE]
movdqa [r10 + 000h], xmm0
movdqa [r10 + 010h], xmm1
movdqa [r10 + 020h], xmm2
movdqa [r10 + 030h], xmm3
movdqa [r10 + 040h], xmm4
movdqa [r10 + 050h], xmm5
movdqa [r10 + 060h], xmm6
movdqa [r10 + 070h], xmm7
movdqa [r10 + 080h], xmm8
movdqa [r10 + 090h], xmm9
movdqa [r10 + 0a0h], xmm10
movdqa [r10 + 0b0h], xmm11
movdqa [r10 + 0c0h], xmm12
movdqa [r10 + 0d0h], xmm13
movdqa [r10 + 0e0h], xmm14
movdqa [r10 + 0f0h], xmm15
; Load the host XMM registers.
movdqa xmm6, [rsp + 040h + 000h]
movdqa xmm7, [rsp + 040h + 010h]
movdqa xmm8, [rsp + 040h + 020h]
movdqa xmm9, [rsp + 040h + 030h]
movdqa xmm10, [rsp + 040h + 040h]
movdqa xmm11, [rsp + 040h + 050h]
movdqa xmm12, [rsp + 040h + 060h]
movdqa xmm13, [rsp + 040h + 070h]
movdqa xmm14, [rsp + 040h + 080h]
movdqa xmm15, [rsp + 040h + 090h]
ENDPROC hmR0SVMRunWrapXMM
%endif ; VBOX_WITH_KERNEL_USING_XMM
; The default setup of the StartVM routines.
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
%define MY_NAME(name) name %+ _32
%define MY_NAME(name) name
%define MYPUSHAD MYPUSHAD64
%define MYPOPAD MYPOPAD64
%define MYPUSHSEGS MYPUSHSEGS64
%define MYPOPSEGS MYPOPSEGS64
%define MYPUSHAD MYPUSHAD32
%define MYPOPAD MYPOPAD32
%define MYPUSHSEGS MYPUSHSEGS32
%define MYPOPSEGS MYPOPSEGS32
%ifdef VBOX_WITH_HYBRID_32BIT_KERNEL
; Write the wrapper procedures.
; These routines are probably being too paranoid about selector
; restoring, but better safe than sorry...
; DECLASM(int) VMXR0StartVM32(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache /*, PVM pVM, PVMCPU pVCpu*/);
cmp byte [NAME(g_fVMXIs64bitHost)], 0
je near NAME(VMXR0StartVM32_32)
dd .thunk64, NAME(SUPR0Abs64bitKernelCS)
mov edi, [rsp + 20h + 14h] ; fResume
mov esi, [rsp + 20h + 18h] ; pCtx
mov edx, [rsp + 20h + 1Ch] ; pCache
call NAME(VMXR0StartVM32_64)
jmp far [.fpthunk32 wrt rip]
.fpthunk32: ; 16:32 Pointer to .thunk32.
dd .thunk32, NAME(SUPR0AbsKernelCS)
; DECLASM(int) VMXR0StartVM64(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache /*, PVM pVM, PVMCPU pVCpu*/);
cmp byte [NAME(g_fVMXIs64bitHost)], 0
dd .thunk64, NAME(SUPR0Abs64bitKernelCS)
mov edi, [rsp + 20h + 14h] ; fResume
mov esi, [rsp + 20h + 18h] ; pCtx
mov edx, [rsp + 20h + 1Ch] ; pCache
call NAME(VMXR0StartVM64_64)
jmp far [.fpthunk32 wrt rip]
.fpthunk32: ; 16:32 Pointer to .thunk32.
dd .thunk32, NAME(SUPR0AbsKernelCS)
mov eax, VERR_PGM_UNSUPPORTED_SHADOW_PAGING_MODE
;DECLASM(int) SVMR0VMRun(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx /*, PVM pVM, PVMCPU pVCpu*/);
cmp byte [NAME(g_fVMXIs64bitHost)], 0
je near NAME(SVMR0VMRun_32)
dd .thunk64, NAME(SUPR0Abs64bitKernelCS)
mov rdi, [rsp + 20h + 14h] ; pVMCBHostPhys
mov rsi, [rsp + 20h + 1Ch] ; pVMCBPhys
mov edx, [rsp + 20h + 24h] ; pCtx
jmp far [.fpthunk32 wrt rip]
.fpthunk32: ; 16:32 Pointer to .thunk32.
dd .thunk32, NAME(SUPR0AbsKernelCS)
; DECLASM(int) SVMR0VMRun64(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx /*, PVM pVM, PVMCPU pVCpu*/);
cmp byte [NAME(g_fVMXIs64bitHost)], 0
dd .thunk64, NAME(SUPR0Abs64bitKernelCS)
mov rdi, [rbp + 20h + 14h] ; pVMCBHostPhys
mov rsi, [rbp + 20h + 1Ch] ; pVMCBPhys
mov edx, [rbp + 20h + 24h] ; pCtx
call NAME(SVMR0VMRun64_64)
jmp far [.fpthunk32 wrt rip]
.fpthunk32: ; 16:32 Pointer to .thunk32.
dd .thunk32, NAME(SUPR0AbsKernelCS)
mov eax, VERR_PGM_UNSUPPORTED_SHADOW_PAGING_MODE
; Do it a second time pretending we're a 64-bit host.
; This *HAS* to be done at the very end of the file to avoid restoring
; macros. So, add new code *BEFORE* this mess.
%define MY_NAME(name) name %+ _64
%define MYPUSHAD MYPUSHAD64
%define MYPOPAD MYPOPAD64
%define MYPUSHSEGS MYPUSHSEGS64
%define MYPOPSEGS MYPOPSEGS64
%endif ; VBOX_WITH_HYBRID_32BIT_KERNEL