vm.h revision 6406e7a354eb585e5503a926d765cdf98ff41f03
/** @file
* VM - The Virtual Machine, data.
*/
/*
* 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* 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 ___VBox_vm_h
#define ___VBox_vm_h
/** @defgroup grp_vm The Virtual Machine
* @{
*/
/**
* The state of a virtual CPU.
*
* The VM running states are a sub-states of the VMSTATE_RUNNING state. While
* VMCPUSTATE_NOT_RUNNING is a place holder for the other VM states.
*/
typedef enum VMCPUSTATE
{
/** The customary invalid zero. */
VMCPUSTATE_INVALID = 0,
/** Running guest code (VM running). */
/** Running guest code in the recompiler (VM running). */
/** Halted (VM running). */
/** All the other bits we do while running a VM (VM running). */
/** VM not running, we're servicing requests or whatever. */
/** The end of valid virtual CPU states. */
/** Ensure 32-bit type. */
VMCPUSTATE_32BIT_HACK = 0x7fffffff
} VMCPUSTATE;
/**
* Per virtual CPU data.
*/
typedef struct VMCPU
{
/** Per CPU forced action.
* See the VMCPU_FF_* \#defines. Updated atomically. */
uint32_t volatile fForcedActions;
/** The CPU state. */
VMCPUSTATE volatile enmState;
/** Ring-3 Host Context VM Pointer. */
/** Ring-0 Host Context VM Pointer. */
/** Raw-mode Context VM Pointer. */
/** The CPU ID.
* This is the index into the VM::aCpus array. */
/** The ring-3 thread handle of the emulation thread for this CPU.
* @todo Use the VM_IS_EMT() macro to check if executing in EMT? */
/** The native ring-3 handle. */
/** The native ring-0 handle. */
/** Align the next bit on a 64-byte boundrary. */
/** CPUM part. */
union
{
#if 0 /*def ___CPUMInternal_h */
struct VMCPUCPUM s;
#endif
char padding[64];
} cpum;
} VMCPU;
/** The name of the Guest Context VMM Core module. */
#define VMMGC_MAIN_MODULE_NAME "VMMGC.gc"
/** The name of the Ring 0 Context VMM Core module. */
#define VMMR0_MAIN_MODULE_NAME "VMMR0.r0"
/** VM Forced Action Flags.
*
* Use the VM_FF_SET() and VM_FF_CLEAR() macros to change the force
* action mask of a VM.
*
* @{
*/
/** This action forces the VM to service check and pending interrups on the APIC. */
#define VM_FF_INTERRUPT_APIC RT_BIT_32(0)
/** This action forces the VM to service check and pending interrups on the PIC. */
/** This action forces the VM to schedule and run pending timer (TM). */
/** PDM Queues are pending. */
/** PDM DMA transfers are pending. */
/** PDM critical section unlocking is pending, process promptly upon return to R3. */
/** This action forces the VM to call DBGF so DBGF can service debugger
* requests in the emulation thread.
* This action flag stays asserted till DBGF clears it.*/
/** This action forces the VM to service pending requests from other
* thread or requests which must be executed in another context. */
/** Terminate the VM immediately. */
/** Reset the VM. (postponed) */
/** This action forces the VM to resync the page tables before going
* back to execute guest code. (GLOBAL FLUSH) */
/** Same as VM_FF_PGM_SYNC_CR3 except that global pages can be skipped.
* (NON-GLOBAL FLUSH) */
/** PGM needs to allocate handy pages. */
/** Check the interupt and trap gates */
/** Check Guest's TSS ring 0 stack */
/** Check Guest's GDT table */
/** Check Guest's LDT table */
/** Inhibit interrupts pending. See EMGetInhibitInterruptsPC(). */
/** CSAM needs to scan the page that's being executed */
/** CSAM needs to do some homework. */
/** Force return to Ring-3. */
/** REM needs to be informed about handler changes. */
/** Suspend the VM - debug only. */
#define VM_FF_EXTERNAL_HALTED_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_TIMER | VM_FF_INTERRUPT_APIC | VM_FF_INTERRUPT_PIC | VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA)
/** High priority pre-execution actions. */
#define VM_FF_HIGH_PRIORITY_PRE_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_INTERRUPT_APIC | VM_FF_INTERRUPT_PIC | VM_FF_TIMER | VM_FF_DEBUG_SUSPEND \
| VM_FF_PGM_SYNC_CR3 | VM_FF_PGM_SYNC_CR3_NON_GLOBAL | VM_FF_SELM_SYNC_TSS | VM_FF_TRPM_SYNC_IDT | VM_FF_SELM_SYNC_GDT | VM_FF_SELM_SYNC_LDT | VM_FF_PGM_NEED_HANDY_PAGES)
/** High priority pre raw-mode execution mask. */
#define VM_FF_HIGH_PRIORITY_PRE_RAW_MASK (VM_FF_PGM_SYNC_CR3 | VM_FF_PGM_SYNC_CR3_NON_GLOBAL | VM_FF_SELM_SYNC_TSS | VM_FF_TRPM_SYNC_IDT | VM_FF_SELM_SYNC_GDT | VM_FF_SELM_SYNC_LDT | VM_FF_PGM_NEED_HANDY_PAGES \
/** High priority post-execution actions. */
/** Normal priority post-execution actions. */
#define VM_FF_NORMAL_PRIORITY_POST_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_RESET | VM_FF_CSAM_SCAN_PAGE)
/** Normal priority actions. */
#define VM_FF_NORMAL_PRIORITY_MASK (VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_REM_HANDLER_NOTIFY)
/** Flags to check before resuming guest execution. */
#define VM_FF_RESUME_GUEST_MASK (VM_FF_TO_R3)
/** All the forced flags. */
#define VM_FF_ALL_MASK (~0U)
/** All the forced flags. */
#define VM_FF_ALL_BUT_RAW_MASK (~(VM_FF_HIGH_PRIORITY_PRE_RAW_MASK | VM_FF_CSAM_PENDING_ACTION | VM_FF_PDM_CRITSECT))
/** @} */
/** @def VM_FF_SET
* Sets a force action flag.
*
* @param pVM VM Handle.
* @param fFlag The flag to set.
*/
#if 1
#else
RTLogPrintf("VM_FF_SET : %08x %s - %s(%d) %s\n", (pVM)->fForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
} while (0)
#endif
/** @def VM_FF_CLEAR
* Clears a force action flag.
*
* @param pVM VM Handle.
* @param fFlag The flag to clear.
*/
#if 1
#else
RTLogPrintf("VM_FF_CLEAR: %08x %s - %s(%d) %s\n", (pVM)->fForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
} while (0)
#endif
/** @def VM_FF_ISSET
* Checks if a force action flag is set.
*
* @param pVM VM Handle.
* @param fFlag The flag to check.
*/
/** @def VM_FF_ISPENDING
* Checks if one or more force action in the specified set is pending.
*
* @param pVM VM Handle.
* @param fFlags The flags to check for.
*/
/** @def VM_IS_EMT
* Checks if the current thread is the emulation thread (EMT).
*
* @remark The ring-0 variation will need attention if we expand the ring-0
* code to let threads other than EMT mess around with the VM.
*/
#ifdef IN_GC
#else
#endif
/** @def VM_ASSERT_EMT
* Asserts that the current thread IS the emulation thread (EMT).
*/
#ifdef IN_GC
#else
# define VM_ASSERT_EMT(pVM) \
("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), pVM->NativeThreadEMT))
#endif
/** @def VM_ASSERT_EMT_RETURN
* Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
*/
#ifdef IN_GC
#else
("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), pVM->NativeThreadEMT), \
(rc))
#endif
/**
* Asserts that the current thread is NOT the emulation thread.
*/
#define VM_ASSERT_OTHER_THREAD(pVM) \
/** @def VM_ASSERT_STATE_RETURN
* Asserts a certain VM state.
*/
/** @def VM_ASSERT_STATE_RETURN
* Asserts a certain VM state and returns if it doesn't match.
*/
(rc))
/** This is the VM structure.
*
* It contains (nearly?) all the VM data which have to be available in all
* contexts. Even if it contains all the data the idea is to use APIs not
* to modify all the members all around the place. Therefore we make use of
* unions to hide everything which isn't local to the current source module.
* This means we'll have to pay a little bit of attention when adding new
* members to structures in the unions and make sure to keep the padding sizes
* up to date.
*
* Run tstVMStructSize after update!
*/
typedef struct VM
{
/** The state of the VM.
* This field is read only to everyone except the VM and EM. */
/** Forced action flags.
* See the VM_FF_* \#defines. Updated atomically.
*/
volatile uint32_t fForcedActions;
/** Pointer to the array of page descriptors for the VM structure allocation. */
/** Session handle. For use when calling SUPR0 APIs. */
/** Pointer to the ring-3 VM structure. */
/** Ring-3 Host Context VM Pointer. */
/** Ring-0 Host Context VM Pointer. */
/** Guest Context VM Pointer. */
/** The GVM VM handle. Only the GVM should modify this field. */
/** Number of virtual CPUs. */
/** Current CPU id; @todo move to per CPU structure. */
/** Reserved; alignment. */
/** @name Public VMM Switcher APIs
* @{ */
/**
* Assembly switch entry point for returning to host context.
* This function will clean up the stack frame.
*
* @param eax The return code, register.
* @param Ctx The guest core context.
* @remark Assume interrupts disabled.
*/
/**
* Assembly switch entry point for returning to host context.
*
* This is an alternative entry point which we'll be using when the we have the
* hypervisor context and need to save that before going to the host.
*
* This is typically useful when abandoning the hypervisor because of a trap
* and want the trap state to be saved.
*
* @param eax The return code, register.
* @param ecx Pointer to the hypervisor core context, register.
* @remark Assume interrupts disabled.
*/
/**
* Assembly switch entry point for returning to host context.
*
* This is an alternative to the two *Ctx APIs and implies that the context has already
* been saved, or that it's just a brief return to HC and that the caller intends to resume
* whatever it is doing upon 'return' from this call.
*
* @param eax The return code, register.
* @remark Assume interrupts disabled.
*/
/** @} */
/** @name Various VM data owned by VM.
* @{ */
/** The thread handle of the emulation thread.
* Use the VM_IS_EMT() macro to check if executing in EMT. */
/** The native handle of ThreadEMT. Getting the native handle
* is generally faster than getting the IPRT one (except on OS/2 :-). */
/** @} */
/** @name Various items that are frequently accessed.
* @{ */
/** Raw ring-3 indicator. */
bool fRawR3Enabled;
/** Raw ring-0 indicator. */
bool fRawR0Enabled;
/** PATM enabled flag.
* This is placed here for performance reasons. */
bool fPATMEnabled;
/** CSAM enabled flag.
* This is placed here for performance reasons. */
bool fCSAMEnabled;
/** Hardware VM support is available and enabled.
* This is placed here for performance reasons. */
bool fHWACCMEnabled;
/** @} */
/* padding to make gnuc put the StatQemuToGC where msc does. */
#if HC_ARCH_BITS == 32
#endif
/** Profiling the total time from Qemu to GC. */
/** Profiling the total time from GC to Qemu. */
/** Profiling the total time spent in GC. */
/** Profiling the total time spent not in Qemu. */
/** Profiling the VMMSwitcher code for going to GC. */
/** Profiling the VMMSwitcher code for going to HC. */
/** @todo Realign everything on 64 byte boundraries to better match the
* cache-line size. */
/* padding - the unions must be aligned on 32 bytes boundraries. */
/** CPUM part. */
union
{
#ifdef ___CPUMInternal_h
struct CPUM s;
#endif
} cpum;
/** VMM part. */
union
{
#ifdef ___VMMInternal_h
struct VMM s;
#endif
} vmm;
/** PGM part. */
union
{
#ifdef ___PGMInternal_h
struct PGM s;
#endif
} pgm;
/** HWACCM part. */
union
{
#ifdef ___HWACCMInternal_h
struct HWACCM s;
#endif
} hwaccm;
/** TRPM part. */
union
{
#ifdef ___TRPMInternal_h
struct TRPM s;
#endif
} trpm;
/** SELM part. */
union
{
#ifdef ___SELMInternal_h
struct SELM s;
#endif
} selm;
/** MM part. */
union
{
#ifdef ___MMInternal_h
struct MM s;
#endif
} mm;
/** CFGM part. */
union
{
#ifdef ___CFGMInternal_h
struct CFGM s;
#endif
} cfgm;
/** PDM part. */
union
{
#ifdef ___PDMInternal_h
struct PDM s;
#endif
} pdm;
/** IOM part. */
union
{
#ifdef ___IOMInternal_h
struct IOM s;
#endif
} iom;
/** PATM part. */
union
{
#ifdef ___PATMInternal_h
struct PATM s;
#endif
} patm;
/** CSAM part. */
union
{
#ifdef ___CSAMInternal_h
struct CSAM s;
#endif
} csam;
/** EM part. */
union
{
#ifdef ___EMInternal_h
struct EM s;
#endif
} em;
/** TM part. */
union
{
#ifdef ___TMInternal_h
struct TM s;
#endif
} tm;
/** DBGF part. */
union
{
#ifdef ___DBGFInternal_h
struct DBGF s;
#endif
} dbgf;
/** SSM part. */
union
{
#ifdef ___SSMInternal_h
struct SSM s;
#endif
} ssm;
/** VM part. */
union
{
#ifdef ___VMInternal_h
struct VMINT s;
#endif
} vm;
/** REM part. */
union
{
#ifdef ___REMInternal_h
struct REM s;
#endif
#if GC_ARCH_BITS == 32
#else
#endif
} rem;
/** Padding for aligning the cpu array on a 64 byte boundrary. */
/**
* Per virtual CPU state.
*/
} VM;
/** Pointer to a VM. */
#ifndef ___VBox_types_h
#endif
#ifdef IN_GC
/** The VM structure.
* This is imported from the VMMGCBuiltin module, i.e. it's a one
* of those magic globals which we should avoid using.
*/
#endif
/** @} */
#endif