vm.h revision c62173fa16e8d871c1530c6c55c60b48b5af92be
/** @file
* VM - The Virtual Machine, data.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
#ifndef __VBox_vm_h__
#define __VBox_vm_h__
/** @defgroup grp_vm The Virtual Machine
* @{
*/
/** 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 BIT(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) */
/** 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. */
/** 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)
/** 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_INHIBIT_INTERRUPTS)
/** 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. */
/** 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
/**
* Asserts that the current thread is NOT the emulation thread.
*/
#define VM_ASSERT_OTHER_THREAD(pVM) \
/** 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 next VM.
* We keep a per process list of VM for the event that a process could
* contain more than one VM.
*/
/** Host Context VM Pointer.
* @obsolete don't use in new code! */
/** Ring-3 Host Context VM Pointer. */
/** Ring-0 Host Context VM Pointer. */
/** Guest Context VM Pointer. */
/** @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
uint32_t padding0;
#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. */
/* padding - the unions must be aligned on 32 bytes boundraries. */
/** CPUM part. */
union
{
#ifdef __CPUMInternal_h__
struct CPUM s;
#endif
#else
#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;
/** STAM part. */
union
{
#ifdef __STAMInternal_h__
struct STAM s;
#endif
} stam;
/** 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
} rem;
} 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