cpum.h revision 8e309081c4be44adb8de44d34fd7d9b0433e451c
/** @file
* CPUM - CPU Monitor(/ Manager).
*/
/*
* 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_cpum_h
#define ___VBox_cpum_h
/** @defgroup grp_cpum The CPU Monitor / Manager API
* @{
*/
/**
* Selector hidden registers.
*/
typedef struct CPUMSELREGHID
{
/** Base register.
*
* Long mode remarks:
* - Unused in long mode for CS, DS, ES, SS
* - 32 bits for FS & GS; FS(GS)_BASE msr used for the base address
* - 64 bits for TR & LDTR
*/
/** Limit (expanded). */
/** Flags.
* This is the high 32-bit word of the descriptor entry.
* Only the flags, dpl and type are used. */
/**
* The sysenter register set.
*/
typedef struct CPUMSYSENTER
{
/** Ring 0 cs.
* This value + 8 is the Ring 0 ss.
* This value + 16 is the Ring 3 cs.
* This value + 24 is the Ring 3 ss.
*/
/** Ring 0 eip. */
/** Ring 0 esp. */
} CPUMSYSENTER;
/**
* CPU context core.
*/
#pragma pack(1)
typedef struct CPUMCTXCORE
{
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
/* Note: lss esp, [] in the switcher needs some space, so we reserve it here instead of relying on the exact esp & ss layout as before. */
union
{
};
union
{
};
/** Hidden selector registers.
* @{ */
/** @} */
} CPUMCTXCORE;
#pragma pack()
/**
* CPU context.
*/
#pragma pack(1)
typedef struct CPUMCTX
{
/** FPU state. (16-byte alignment)
* @todo This doesn't have to be in X86FXSTATE on CPUs without fxsr - we need a type for the
* actual format or convert it (waste of time). */
/** CPUMCTXCORE Part.
* @{ */
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
/* Note: lss esp, [] in the switcher needs some space, so we reserve it here instead of relying on the exact esp & ss layout as before (prevented us from using a union with rsp). */
union
{
};
union
{
};
/** Hidden selector registers.
* @{ */
/** @} */
/** @} */
/** Control registers.
* @{ */
/** @} */
/** Debug registers.
* @remarks DR4 and DR5 should not be used since they are aliases for
* DR6 and DR7 respectively on both AMD and Intel CPUs.
* @remarks DR8-15 are currently not supported by AMD or Intel, so
* neither do we.
* @{ */
/** @} */
/** Global Descriptor Table register. */
/** Interrupt Descriptor Table register. */
/** The task register.
* Only the guest context uses all the members. */
/** The task register.
* Only the guest context uses all the members. */
/** The sysenter msr registers.
* This member is not used by the hypervisor context. */
/** System MSRs.
* @{ */
/** @} */
/** Hidden selector registers.
* @{ */
/** @} */
#if 0
/*& Padding to align the size on a 64 byte boundrary. */
#endif
} CPUMCTX;
#pragma pack()
/**
* Gets the CPUMCTXCORE part of a CPUMCTX.
*/
/**
* Selector hidden registers, for version 1.6 saved state.
*/
typedef struct CPUMSELREGHID_VER1_6
{
/** Base register. */
/** Limit (expanded). */
/** Flags.
* This is the high 32-bit word of the descriptor entry.
* Only the flags, dpl and type are used. */
/**
* CPU context, for version 1.6 saved state.
* @remarks PATM uses this, which is why it has to be here.
*/
#pragma pack(1)
typedef struct CPUMCTX_VER1_6
{
/** FPU state. (16-byte alignment)
* @todo This doesn't have to be in X86FXSTATE on CPUs without fxsr - we need a type for the
* actual format or convert it (waste of time). */
/** CPUMCTXCORE Part.
* @{ */
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
union
{
};
/* Note: we rely on the exact layout, because we use lss esp, [] in the switcher */
/* Note: no overlap with esp here. */
union
{
};
union
{
};
/** Hidden selector registers.
* @{ */
/** @} */
/** @} */
/** Control registers.
* @{ */
/** @} */
/** Debug registers.
* @{ */
/* DR8-15 are currently not supported */
/** @} */
/** Global Descriptor Table register. */
/** Interrupt Descriptor Table register. */
/** The task register.
* Only the guest context uses all the members. */
/** The task register.
* Only the guest context uses all the members. */
/** The sysenter msr registers.
* This member is not used by the hypervisor context. */
/** System MSRs.
* @{ */
/** @} */
/** Hidden selector registers.
* @{ */
/** @} */
/* padding to get 32byte aligned size */
#pragma pack()
/**
* The register set returned by a CPUID operation.
*/
typedef struct CPUMCPUID
{
} CPUMCPUID;
/** Pointer to a CPUID leaf. */
typedef CPUMCPUID *PCPUMCPUID;
/** Pointer to a const CPUID leaf. */
typedef const CPUMCPUID *PCCPUMCPUID;
/**
* CPUID feature to set or clear.
*/
typedef enum CPUMCPUIDFEATURE
{
/** The APIC feature bit. (Std+Ext) */
/** The PAE feature bit. (Std+Ext) */
/** The NXE feature bit. (Ext) */
/** The LONG MODE feature bit. (Ext) */
/** The PAT feature bit. (Std+Ext) */
/** The x2APIC feature bit. (Std) */
/** 32bit hackishness. */
CPUMCPUIDFEATURE_32BIT_HACK = 0x7fffffff
/**
* CPU Vendor.
*/
typedef enum CPUMCPUVENDOR
{
/** 32bit hackishness. */
CPUMCPUVENDOR_32BIT_HACK = 0x7fffffff
/** @name Guest Register Getters.
* @{ */
VMMDECL(void) CPUMGetGuestCpuId(PVM pVM, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx);
/** @} */
/** @name Guest Register Setters.
* @{ */
/** @} */
/** @name Misc Guest Predicate Functions.
* @{ */
/**
* Tests if the guest is running in real mode or not.
*
* @returns true if in real mode, otherwise false.
* @param pVM The VM handle.
*/
{
}
/**
* Tests if the guest is running in real mode or not.
*
* @returns true if in real mode, otherwise false.
* @param pCtx Current CPU context
*/
{
}
/**
* Tests if the guest is running in protected or not.
*
* @returns true if in protected mode, otherwise false.
* @param pVM The VM handle.
*/
{
}
/**
* Tests if the guest is running in paged protected or not.
*
* @returns true if in paged protected mode, otherwise false.
* @param pVM The VM handle.
*/
{
}
/**
* Tests if the guest is running in paged protected or not.
*
* @returns true if in paged protected mode, otherwise false.
* @param pVM The VM handle.
*/
{
}
/**
* Tests if the guest is running in long mode or not.
*
* @returns true if in long mode, otherwise false.
* @param pVM The VM handle.
*/
{
}
/**
* Tests if the guest is running in long mode or not.
*
* @returns true if in long mode, otherwise false.
* @param pCtx Current CPU context
*/
{
}
/**
* Tests if the guest is running in 64 bits mode or not.
*
* @returns true if in 64 bits protected mode, otherwise false.
* @param pVM The VM handle.
* @param pCtx Current CPU context
*/
{
if (!CPUMIsGuestInLongMode(pVM))
return false;
}
/**
* Tests if the guest is running in 64 bits mode or not.
*
* @returns true if in 64 bits protected mode, otherwise false.
* @param pVM The VM handle.
* @param pCtx Current CPU context
*/
{
return false;
}
/**
* Tests if the guest is running in PAE mode or not.
*
* @returns true if in PAE mode, otherwise false.
* @param pCtx Current CPU context
*/
{
return ( CPUMIsGuestInPagedProtectedModeEx(pCtx)
&& !CPUMIsGuestInLongModeEx(pCtx));
}
/** @} */
/** @name Hypervisor Register Getters.
* @{ */
#if 0 /* these are not correct. */
#endif
/** This register is only saved on fatal traps. */
/** This register is only saved on fatal traps. */
/** This register is only saved on fatal traps. */
/** @} */
/** @name Hypervisor Register Setters.
* @{ */
/** @} */
/** @name Changed flags
* These flags are used to keep track of which important register that
* have been changed since last they were reset. The only one allowed
* to clear them is REM!
* @{
*/
#define CPUM_CHANGED_FPU_REM RT_BIT(0)
#define CPUM_CHANGED_ALL (CPUM_CHANGED_FPU_REM|CPUM_CHANGED_CR0|CPUM_CHANGED_CR3|CPUM_CHANGED_CR4|CPUM_CHANGED_GDTR|CPUM_CHANGED_IDTR|CPUM_CHANGED_LDTR|CPUM_CHANGED_TR|CPUM_CHANGED_SYSENTER_MSR|CPUM_CHANGED_HIDDEN_SEL_REGS|CPUM_CHANGED_CPUID)
/** @} */
/**
* CPU modes.
*/
typedef enum CPUMMODE
{
/** The usual invalid zero entry. */
CPUMMODE_INVALID = 0,
/** Real mode. */
/** Protected mode (32-bit). */
/** Long mode (64-bit). */
} CPUMMODE;
#ifdef IN_RING3
/** @defgroup grp_cpum_r3 The CPU Monitor(/Manager) API
* @ingroup grp_cpum
* @{
*/
# ifdef DEBUG
# endif
/** @} */
#endif /* IN_RING3 */
#ifdef IN_GC
/** @defgroup grp_cpum_gc The CPU Monitor(/Manager) API
* @ingroup grp_cpum
* @{
*/
/**
* Assumes a trap stack frame has already been setup on the guest's stack!
*
* @param selCS Code selector of handler
* @param pHandler GC virtual address of handler
* @param eflags Callee's EFLAGS
* @param selSS Stack selector for handler
* @param pEsp Stack address for handler
*
* This function does not return!
*/
DECLASM(void) CPUMGCCallGuestTrapHandler(PCPUMCTXCORE pRegFrame, uint32_t selCS, RTRCPTR pHandler, uint32_t eflags, uint32_t selSS, RTRCPTR pEsp);
/** @} */
#endif /* IN_GC */
#ifdef IN_RING0
/** @defgroup grp_cpum_r0 The CPU Monitor(/Manager) API
* @ingroup grp_cpum
* @{
*/
/** @} */
#endif /* IN_RING0 */
/** @} */
#endif