VMMInternal.h revision 9c2450ffd7e8a08cc596a2e4cc4d4e4dc9b382cf
/* $Id$ */
/** @file
* VMM - 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 ___VMMInternal_h
#define ___VMMInternal_h
#include <iprt/critsect.h>
# error "Not in VMM! This is an internal header!"
#endif
/** @defgroup grp_vmm_int Internals
* @ingroup grp_vmm
* @internal
* @{
*/
/** @def VBOX_WITH_RC_RELEASE_LOGGING
* Enables RC release logging. */
#define VBOX_WITH_RC_RELEASE_LOGGING
/** @def VBOX_WITH_R0_LOGGING
* Enables Ring-0 logging (non-release).
*
* Ring-0 logging isn't 100% safe yet (thread id reuse / process exit cleanup),
* so you have to sign up here by adding your defined(DEBUG_<userid>) to the
* #if, or by adding VBOX_WITH_R0_LOGGING to your LocalConfig.kmk.
*/
# define VBOX_WITH_R0_LOGGING
#endif
/** @def VBOX_STRICT_VMM_STACK
* Enables VMM stack guard pages to catch stack over- and underruns. */
#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
# define VBOX_STRICT_VMM_STACK
#endif
/**
* Converts a VMM pointer into a VM pointer.
* @returns Pointer to the VM structure the VMM is part of.
* @param pVMM Pointer to VMM instance data.
*/
/**
* Switcher function, HC to RC.
*
* @param pVM The VM handle.
* @returns Return code indicating the action to take.
*/
/** Pointer to switcher function. */
typedef FNVMMSWITCHERHC *PFNVMMSWITCHERHC;
/**
* Switcher function, RC to HC.
*
* @param rc VBox status code.
*/
/** Pointer to switcher function. */
typedef FNVMMSWITCHERRC *PFNVMMSWITCHERRC;
/**
* The ring-0 logger instance wrapper.
*
* We need to be able to find the VM handle from the logger instance, so we wrap
* it in this structure.
*/
typedef struct VMMR0LOGGER
{
/** Pointer to the VM handle. */
/** Size of the allocated logger instance (Logger). */
/** Flag indicating whether we've create the logger Ring-0 instance yet. */
bool fCreated;
/** Flag indicating whether we've disabled flushing (world switch) or not. */
bool fFlushingDisabled;
/** Flag indicating whether we've registered the instance already. */
bool fRegistered;
bool a8Alignment;
/** The CPU ID. */
#if HC_ARCH_BITS == 64
#endif
/** The ring-0 logger instance. This extends beyond the size. */
} VMMR0LOGGER;
/** Pointer to a ring-0 logger instance wrapper. */
typedef VMMR0LOGGER *PVMMR0LOGGER;
/**
* quickly 'call' back into Ring-3.
*/
typedef struct VMMR0JMPBUF
{
/** Traditional jmp_buf stuff
* @{ */
#if HC_ARCH_BITS == 32
#endif
#if HC_ARCH_BITS == 64
# ifdef RT_OS_WINDOWS
# endif
# ifdef RT_OS_WINDOWS
# endif
#endif
/** @} */
/** Flag that indicates that we've done a ring-3 call. */
bool fInRing3Call;
/** The number of bytes we've saved. */
/** Pointer to the buffer used to save the stack.
* This is assumed to be 8KB. */
/** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
/** The esp we should resume execution with after the restore. */
/** Stats: Max amount of stack used. */
/** Stats: Average stack usage. (Avg = cbUsedTotal / cUsedTotal) */
/** Stats: Total amount of stack used. */
/** Stats: Number of stack usages. */
} VMMR0JMPBUF;
/** Pointer to a ring-0 jump buffer. */
typedef VMMR0JMPBUF *PVMMR0JMPBUF;
/**
* VMM Data (part of VM)
*/
typedef struct VMM
{
/** Offset to the VM structure.
* See VMM2VM(). */
/** @name World Switcher and Related
* @{
*/
/** Size of the core code. */
/** Physical address of core code. */
/** Pointer to core code ring-3 mapping - contiguous memory.
* At present this only means the context switcher code. */
/** Pointer to core code ring-0 mapping - contiguous memory.
* At present this only means the context switcher code. */
/** Pointer to core code guest context mapping. */
#ifdef VBOX_WITH_NMI
/** The guest context address of the APIC (host) mapping. */
#endif
/** The current switcher.
* This will be set before the VMM is fully initialized. */
/** Flag to disable the switcher permanently (VMX) (boolean) */
bool fSwitcherDisabled;
/** Array of offsets to the different switchers within the core code. */
/** Resume Guest Execution. See CPUMGCResumeGuest(). */
/** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
/** Call Trampoline. See vmmGCCallTrampoline(). */
/** Guest to host switcher entry point. */
/** Host to guest switcher entry point. */
/** @} */
/** @name Logging
* @{
*/
/** Size of the allocated logger instance (pRCLoggerRC/pRCLoggerR3). */
/** Pointer to the RC logger instance - RC Ptr.
* This is NULL if logging is disabled. */
/** Pointer to the GC logger instance - R3 Ptr.
* This is NULL if logging is disabled. */
/** Pointer to the GC release logger instance - R3 Ptr. */
/** Pointer to the GC release logger instance - RC Ptr. */
/** Size of the allocated release logger instance (pRCRelLoggerRC/pRCRelLoggerR3).
* This may differ from cbRCLogger. */
/** Whether log flushing has been disabled or not. */
/** @} */
/** Whether the stack guard pages have been stationed or not. */
bool fStackGuardsStationed;
/** The EMT yield timer. */
/** The period to the next timeout when suspended or stopped.
* This is 0 when running. */
/** The EMT yield timer interval (milliseconds). */
/** The timestamp of the previous yield. (nano) */
/** Critical section.
* Use for synchronizing all VCPUs
*/
/** @name EMT Rendezvous
* @{ */
/** Semaphore to wait on upon entering ordered execution. */
/** Semaphore to wait on upon entering for one-by-one execution. */
/** Semaphore to wait on upon entering for all-at-once execution. */
/** Semaphore to wait on when done. */
/** Semaphore the VMMR3EmtRendezvous caller waits on at the end. */
/** Callback. */
/** The user argument for the callback. */
RTR3PTR volatile pvRendezvousUser;
/** Flags. */
volatile uint32_t fRendezvousFlags;
/** The number of EMTs that has entered. */
volatile uint32_t cRendezvousEmtsEntered;
/** The number of EMTs that has done their job. */
volatile uint32_t cRendezvousEmtsDone;
/** The number of EMTs that has returned. */
volatile uint32_t cRendezvousEmtsReturned;
/** The status code. */
volatile int32_t i32RendezvousStatus;
/** Spin lock. */
volatile uint32_t u32RendezvousLock;
/** @} */
#if HC_ARCH_BITS == 32
#endif
/** Buffer for storing the standard assertion message for a ring-0 assertion.
* Used for saving the assertion message text for the release log and guru
* meditation dump. */
char szRing0AssertMsg1[512];
/** Buffer for storing the custom message for a ring-0 assertion. */
char szRing0AssertMsg2[256];
/** Number of VMMR0_DO_RUN_GC calls. */
* @{ */
/** @} */
} VMM;
/** Pointer to VMM. */
/**
* VMMCPU Data (part of VMCPU)
*/
typedef struct VMMCPU
{
/** Offset to the VMCPU structure.
* See VMM2VMCPU(). */
/** VMM stack, pointer to the top of the stack in R3.
* Stack is allocated from the hypervisor heap and is page aligned
* and always writable in RC. */
/** Pointer to the bottom of the stack - needed for doing relocations. */
/** Pointer to the bottom of the stack - needed for doing relocations. */
#ifdef LOG_ENABLED
/** Pointer to the R0 logger instance - R3 Ptr.
* This is NULL if logging is disabled. */
/** Pointer to the R0 logger instance - R0 Ptr.
* This is NULL if logging is disabled. */
#endif
/** @name Call Ring-3
* Formerly known as host calls.
* @{ */
/** The disable counter. */
/** The pending operation. */
/** The result of the last operation. */
#if HC_ARCH_BITS == 64
#endif
/** The argument to the operation. */
/** The Ring-0 jmp buffer. */
/** @} */
} VMMCPU;
/** Pointer to VMMCPU. */
/**
* The VMMGCEntry() codes.
*/
typedef enum VMMGCOPERATION
{
/** Do GC module init. */
VMMGC_DO_VMMGC_INIT = 1,
/** The first Trap testcase. */
VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
/** Trap 0 testcases, uArg selects the variation. */
/** Trap 1 testcases, uArg selects the variation. */
/** Trap 2 testcases, uArg selects the variation. */
/** Trap 3 testcases, uArg selects the variation. */
/** Trap 4 testcases, uArg selects the variation. */
/** Trap 5 testcases, uArg selects the variation. */
/** Trap 6 testcases, uArg selects the variation. */
/** Trap 7 testcases, uArg selects the variation. */
/** Trap 8 testcases, uArg selects the variation. */
/** Trap 9 testcases, uArg selects the variation. */
/** Trap 0a testcases, uArg selects the variation. */
/** Trap 0b testcases, uArg selects the variation. */
/** Trap 0c testcases, uArg selects the variation. */
/** Trap 0d testcases, uArg selects the variation. */
/** Trap 0e testcases, uArg selects the variation. */
/** The last trap testcase (exclusive). */
/** Testcase for checking interrupt forwarding. */
/** Switching testing and profiling stub. */
/** Testcase for checking interrupt masking.. */
/** Switching testing and profiling stub. */
/** The usual 32-bit hack. */
VMMGC_DO_32_BIT_HACK = 0x7fffffff
#ifdef IN_RING3
#endif /* IN_RING3 */
#ifdef IN_RING0
/**
* World switcher assembly routine.
* It will call VMMGCEntry().
*
* @returns return code from VMMGCEntry().
* @param pVM The VM in question.
* @param uArg See VMMGCEntry().
* @internal
*/
/**
* Callback function for vmmR0CallRing3SetJmp.
*
* @returns VBox status code.
* @param pVM The VM handle.
*/
/** Pointer to FNVMMR0SETJMP(). */
typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
/**
* The setjmp variant used for calling Ring-3.
*
* This differs from the normal setjmp in that it will resume VMMRZCallRing3 if we're
* in the middle of a ring-3 call. Another differences is the function pointer and
* argument. This has to do with resuming code and the stack frame of the caller.
*
* @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
* @param pJmpBuf The jmp_buf to set.
* @param pfn The function to be called when not resuming..
* @param pVM The argument of that function.
*/
/**
* Callback function for vmmR0CallRing3SetJmpEx.
*
* @returns VBox status code.
* @param pvUser The user argument.
*/
/** Pointer to FNVMMR0SETJMP(). */
typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
/**
* Same as vmmR0CallRing3SetJmp except for the function signature.
*
* @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
* @param pJmpBuf The jmp_buf to set.
* @param pfn The function to be called when not resuming..
* @param pvUser The argument of that function.
*/
/**
* Worker for VMMRZCallRing3.
* This will save the stack and registers.
*
* @returns rc.
* @param pJmpBuf Pointer to the jump buffer.
* @param rc The return code.
*/
/**
* Internal R0 logger worker: Logger wrapper.
*/
/**
* Internal R0 logger worker: Flush logger.
*
* @param pLogger The logger instance to flush.
* @remark This function must be exported!
*/
/**
* Interal R0 logger worker: Custom prefix.
*
* @returns Number of chars written.
*
* @param pLogger The logger instance.
* @param pchBuf The output buffer.
* @param cchBuf The size of the buffer.
* @param pvUser User argument (ignored).
*/
#endif /* IN_RING0 */
#ifdef IN_RC
/**
* Internal GC logger worker: Logger wrapper.
*/
/**
* Internal GC release logger worker: Logger wrapper.
*/
/**
* Internal GC logger worker: Flush logger.
*
* @returns VINF_SUCCESS.
* @param pLogger The logger instance to flush.
* @remark This function must be exported!
*/
/** @name Trap testcases and related labels.
* @{ */
DECLASM(void) vmmGCEnableWP(void);
DECLASM(void) vmmGCDisableWP(void);
DECLASM(int) vmmGCTestTrap3(void);
DECLASM(int) vmmGCTestTrap8(void);
DECLASM(int) vmmGCTestTrap0d(void);
DECLASM(int) vmmGCTestTrap0e(void);
/** @} */
#endif /* IN_RC */
/** @} */
#endif