HWACCMInternal.h revision f85e422da05972b9b52a25550448def0b7f6e136
/* $Id$ */
/** @file
* HWACCM - Internal header file.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#ifndef ___HWACCMInternal_h
#define ___HWACCMInternal_h
#if HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBIRD_32BIT_KERNEL) // || defined (VBOX_WITH_64_BITS_GUESTS)
/* Enable 64 bits guest support. */
# define VBOX_ENABLE_64_BITS_GUESTS
#endif
#define VMX_USE_CACHED_VMCS_ACCESSES
#define HWACCM_VMX_EMULATE_REALMODE
#define HWACCM_VTX_WITH_EPT
#define HWACCM_VTX_WITH_VPID
/** @defgroup grp_hwaccm_int Internal
* @ingroup grp_hwaccm
* @internal
* @{
*/
/** Maximum number of exit reason statistics counters. */
#define MAX_EXITREASON_STAT 0x100
#define MASK_EXITREASON_STAT 0xff
/** @name Changed flags
* These flags are used to keep track of which important registers that
* have been changed since last they were reset.
* @{
*/
#define HWACCM_CHANGED_GUEST_FPU RT_BIT(0)
#define HWACCM_CHANGED_ALL ( HWACCM_CHANGED_GUEST_SEGMENT_REGS \
/** @} */
/** @name Intercepted traps
* Traps that need to be intercepted so we can correctly dispatch them to the guest if required.
* Currently #NM and #PF only
*/
#ifdef VBOX_STRICT
#define HWACCM_VMX_TRAP_MASK RT_BIT(X86_XCPT_DE) | RT_BIT(X86_XCPT_NM) | RT_BIT(X86_XCPT_PF) | RT_BIT(X86_XCPT_UD) | RT_BIT(X86_XCPT_NP) | RT_BIT(X86_XCPT_SS) | RT_BIT(X86_XCPT_GP) | RT_BIT(X86_XCPT_MF)
#else
#endif
/* All exceptions have to be intercept in emulated real-mode (minues NM & PF as they are always intercepted. */
#define HWACCM_VMX_TRAP_MASK_REALMODE RT_BIT(X86_XCPT_DE) | RT_BIT(X86_XCPT_DB) | RT_BIT(X86_XCPT_NMI) | RT_BIT(X86_XCPT_BP) | RT_BIT(X86_XCPT_OF) | RT_BIT(X86_XCPT_BR) | RT_BIT(X86_XCPT_UD) | RT_BIT(X86_XCPT_DF) | RT_BIT(X86_XCPT_CO_SEG_OVERRUN) | RT_BIT(X86_XCPT_TS) | RT_BIT(X86_XCPT_NP) | RT_BIT(X86_XCPT_SS) | RT_BIT(X86_XCPT_GP) | RT_BIT(X86_XCPT_MF) | RT_BIT(X86_XCPT_AC) | RT_BIT(X86_XCPT_MC) | RT_BIT(X86_XCPT_XF)
/** @} */
/** Maxium resume loops allowed in ring 0 (safety precaution) */
#define HWACCM_MAX_RESUME_LOOPS 1024
/** Size for the EPT identity page table (1024 4 MB pages to cover the entire address space). */
/** Size of the TSS structure + 2 pages for the IO bitmap + end byte. */
/** Total guest mapped memory needed. */
/** HWACCM SSM version
*/
#define HWACCM_SSM_VERSION 3
/* Per-cpu information. (host) */
typedef struct
{
/* Current ASID (AMD-V)/VPID (Intel) */
/* TLB flush count */
/* Set the first time a cpu is used to make sure we start with a clean TLB. */
bool fFlushTLB;
/** Configured for VT-x or AMD-V. */
bool fConfigured;
/** In use by our code. (for power suspend) */
volatile bool fInUse;
typedef HWACCM_CPUINFO *PHWACCM_CPUINFO;
/* VT-x capability qword. */
typedef union
{
struct
{
} n;
uint64_t u;
/**
* Switcher function, HC to RC.
*
* @param pVM The VM handle.
* @returns Return code indicating the action to take.
*/
/** Pointer to switcher function. */
typedef FNHWACCMSWITCHERHC *PFNHWACCMSWITCHERHC;
/**
* HWACCM VM Instance data.
* Changes to this must checked against the padding of the cfgm union in VM!
*/
typedef struct HWACCM
{
/** Set when we've initialized VMX or SVM. */
bool fInitialized;
bool fActive;
/** Set when hardware acceleration is allowed. */
bool fAllowed;
/** Set if nested paging is enabled. */
bool fNestedPaging;
/** Set if nested paging is allowed. */
bool fAllowNestedPaging;
/** Set if we're supposed to inject an NMI. */
bool fInjectNMI;
/** Set if we can support 64-bit guests or not. */
bool fAllow64BitGuests;
#endif
/** Explicit alignment padding to make 32-bit gcc align u64RegisterMask
* naturally. */
bool padding[1];
#else
bool padding[2];
#endif
/** And mask for copying register contents. */
/** Maximum ASID allowed. */
/** 32 to 64 bits switcher entrypoint. */
/* AMD-V 64 bits vmrun handler */
/* VT-x 64 bits vmlaunch handler */
/* RC handler to setup the 64 bits FPU state. */
/* RC handler to setup the 64 bits debug state. */
# ifdef DEBUG
/* Test handler */
# endif
#elif defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
#endif
struct
{
/** Set by the ring-0 driver to indicate VMX is supported by the CPU. */
bool fSupported;
/** Set when we've enabled VMX. */
bool fEnabled;
/** Set if VPID is supported. */
bool fVPID;
/** Set if VT-x VPID is allowed. */
bool fAllowVPID;
/** Virtual address of the TSS page used for real mode emulation. */
/** Virtual address of the identity page table used for real mode and protected mode without paging emulation in EPT mode. */
/** R0 memory object for the virtual APIC mmio cache. */
/** Physical address of the virtual APIC mmio cache. */
/** Virtual address of the virtual APIC mmio cache. */
/** R0 memory object for the MSR bitmap (1 page). */
/** Physical address of the MSR bitmap (1 page). */
/** Virtual address of the MSR bitmap (1 page). */
/** R0 memory object for the MSR entry load page (guest MSRs). */
/** Physical address of the MSR entry load page (guest MSRs). */
/** Virtual address of the MSR entry load page (guest MSRs). */
/** R0 memory object for the MSR exit store page (guest MSRs). */
/** Physical address of the MSR exit store page (guest MSRs). */
/** Virtual address of the MSR exit store page (guest MSRs). */
/** R0 memory object for the MSR exit load page (host MSRs). */
/** Physical address of the MSR exit load page (host MSRs). */
/** Virtual address of the MSR exit load page (host MSRs). */
/** Ring 0 handlers for VT-x. */
/** Host CR4 value (set by ring-0 VMX init) */
/** VMX MSR values */
struct
{
} msr;
/** Flush types for invept & invvpid; they depend on capabilities. */
} vmx;
struct
{
/** Set by the ring-0 driver to indicate SVM is supported by the CPU. */
bool fSupported;
/** Set when we've enabled SVM. */
bool fEnabled;
/** Set if erratum 170 affects the AMD cpu. */
bool fAlwaysFlushTLB;
/** Explicit alignment padding to make 32-bit gcc align u64RegisterMask
* naturally. */
bool padding[1];
/** R0 memory object for the host VM control block (VMCB). */
/** Physical address of the host VM control block (VMCB). */
/** Virtual address of the host VM control block (VMCB). */
/** R0 memory object for the IO bitmap (12kb). */
/** Physical address of the IO bitmap (12kb). */
/** Virtual address of the IO bitmap. */
/** R0 memory object for the MSR bitmap (8kb). */
/** Physical address of the MSR bitmap (8kb). */
/** Virtual address of the MSR bitmap. */
R0PTRTYPE(void *) pMSRBitmap;
/** SVM revision. */
/** SVM feature bits from cpuid 0x8000000a */
} svm;
struct
{
} cpuid;
/** Saved error from detection */
/** HWACCMR0Init was run */
bool fHWACCMR0Init;
} HWACCM;
/** Pointer to HWACCM VM instance data. */
/* Maximum number of cached entries. */
#define VMCSCACHE_MAX_ENTRY 256
/* Structure for storing read and write VMCS actions. */
typedef struct VMCSCACHE
{
struct
{
} Write;
struct
{
} Read;
#ifdef DEBUG
struct
{
} TestIn;
struct
{
} TestOut;
struct
{
} ScratchPad;
#endif
} VMCSCACHE;
/** Pointer to VMCSCACHE. */
typedef VMCSCACHE *PVMCSCACHE;
/**
* HWACCM VMCPU Instance data.
*/
typedef struct HWACCMCPU
{
/** Old style FPU reporting trap mask override performed (optimization) */
bool fFPUOldStyleOverride;
/** Set if we don't have to flush the TLB on VM entry. */
bool fResumeVM;
/** Set if we need to flush the TLB during the world switch. */
bool fForceTLBFlush;
/** Explicit alignment padding to make 32-bit gcc align u64RegisterMask
* naturally. */
bool padding[1];
/** HWACCM_CHANGED_* flags. */
/* Id of the last cpu we were executing code on (NIL_RTCPUID for the first time) */
/* TLB flush count */
/* Current ASID in use by the VM */
struct
{
/** R0 memory object for the VM control structure (VMCS). */
/** Physical address of the VM control structure (VMCS). */
/** Virtual address of the VM control structure (VMCS). */
/** Ring 0 handlers for VT-x. */
DECLR0CALLBACKMEMBER(int, pfnStartVM,(RTHCUINT fResume, PCPUMCTX pCtx, PVMCSCACHE pCache, PVM pVM, PVMCPU pVCpu));
/** Current VMX_VMCS_CTRL_PROC_EXEC_CONTROLS. */
/** Current CR0 mask. */
/** Current CR4 mask. */
/** Current EPTP. */
/** VMCS cache. */
/** Real-mode emulation state. */
struct
{
} RealMode;
struct
{
} lasterror;
/** The last known guest paging mode. */
} vmx;
struct
{
/** R0 memory object for the VM control block (VMCB). */
/** Physical address of the VM control block (VMCB). */
/** Virtual address of the VM control block (VMCB). */
/** Ring 0 handlers for VT-x. */
DECLR0CALLBACKMEMBER(int, pfnVMRun,(RTHCPHYS pVMCBHostPhys, RTHCPHYS pVMCBPhys, PCPUMCTX pCtx, PVM pVM, PVMCPU pVCpu));
} svm;
/** Event injection state. */
struct
{
} Event;
/** Currenty shadow paging mode. */
/** The CPU ID of the CPU currently owning the VMCS. Set in
* HWACCMR0Enter and cleared in HWACCMR0Leave. */
#if 1 /* temporary for tracking down darwin issues. */
#endif
} HWACCMCPU;
/** Pointer to HWACCM VM instance data. */
typedef HWACCMCPU *PHWACCMCPU;
#ifdef IN_RING0
#ifdef VBOX_STRICT
#else
#define HWACCMDumpRegs(a, b) do { } while (0)
#define HWACCMR0DumpDescriptor(a, b, c) do { } while (0)
#endif
/* Dummy callback handlers. */
VMMR0DECL(int) HWACCMR0DummyEnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
VMMR0DECL(int) HWACCMR0DummyDisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
# ifdef VBOX_WITH_HYBIRD_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.
*/
/**
* Gets 64-bit CR3 on darwin.
* @returns CR3
*/
# endif
#endif /* IN_RING0 */
/** @} */
#endif