SELMInternal.h revision b4e71cf6c41e074860ef96c394f6708caa94deb5
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/* $Id$ */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** @file
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * SELM - Internal header file.
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync */
c90e13620d230b7e730878150ad468aac188ba0cvboxsync
c90e13620d230b7e730878150ad468aac188ba0cvboxsync/*
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync *
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * available from http://www.virtualbox.org. This file is free software;
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * you can redistribute it and/or modify it under the terms of the GNU
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * General Public License (GPL) as published by the Free Software
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync *
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * additional information or have any questions.
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#ifndef ___SELMInternal_h
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define ___SELMInternal_h
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#include <VBox/cdefs.h>
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#include <VBox/types.h>
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#include <VBox/stam.h>
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#include <VBox/cpum.h>
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#if !defined(IN_SELM_R3) && !defined(IN_SELM_R0) && !defined(IN_SELM_GC)
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync# error "Not in SELM! This is an internal header!"
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync#endif
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync/** @defgroup grp_selm_int Internals
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * @ingroup grp_selm
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync * @internal
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync * @{
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync */
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** The number of GDTS allocated for our GDT. (full size) */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_GDT_ELEMENTS 8192
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** aHyperSel index to retrieve hypervisor selectors */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** The Flat CS selector used by the VMM inside the GC. */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_SEL_CS 0
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** The Flat DS selector used by the VMM inside the GC. */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_SEL_DS 1
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** The 64-bit mode CS selector used by the VMM inside the GC. */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_SEL_CS64 2
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** The TSS selector used by the VMM inside the GC. */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_SEL_TSS 3
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** The TSS selector for taking trap 08 (\#DF). */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_SEL_TSS_TRAP08 4
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** Number of GDTs we need for internal use */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_SEL_MAX (SELM_HYPER_SEL_TSS_TRAP08 + 1)
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** Default GDT selectors we use for the hypervisor. */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_DEFAULT_SEL_CS ((SELM_GDT_ELEMENTS - 0x1) << 3)
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_DEFAULT_SEL_DS ((SELM_GDT_ELEMENTS - 0x2) << 3)
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_DEFAULT_SEL_CS64 ((SELM_GDT_ELEMENTS - 0x3) << 3)
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_DEFAULT_SEL_TSS ((SELM_GDT_ELEMENTS - 0x4) << 3)
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_DEFAULT_SEL_TSS_TRAP08 ((SELM_GDT_ELEMENTS - 0x5) << 3)
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync/** The lowest value default we use. */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync#define SELM_HYPER_DEFAULT_BASE SELM_HYPER_DEFAULT_SEL_TSS_TRAP08
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync/**
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync * Converts a SELM pointer into a VM pointer.
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync * @returns Pointer to the VM structure the SELM is part of.
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync * @param pSELM Pointer to SELM instance data.
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync */
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync#define SELM2VM(pSELM) ( (PVM)((char*)pSELM - pSELM->offVM) )
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync/**
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync * SELM Data (part of VM)
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync */
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsynctypedef struct SELM
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync{
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync /** Offset to the VM structure.
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync * See SELM2VM(). */
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync RTINT offVM;
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync /* Flat CS, DS, 64 bit mode CS, TSS & trap 8 TSS. */
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync RTSEL aHyperSel[SELM_HYPER_SEL_MAX];
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync /** Pointer to the GCs - HC Ptr.
0760bbd185c492c09d7ef61fdceb498b279e771cvboxsync * This size is governed by SELM_GDT_ELEMENTS. */
92304df70cde1a3a2f60358cab6f0c88702e0ea5vboxsync R3R0PTRTYPE(PX86DESC) paGdtHC;
/** Pointer to the GCs - GC Ptr.
* This is not initialized until the first relocation because it's used to
* check if the shadow GDT virtual handler requires deregistration. */
RCPTRTYPE(PX86DESC) paGdtGC;
/** Current (last) Guest's GDTR. */
VBOXGDTR GuestGdtr;
/** The current (last) effective Guest GDT size. */
RTUINT cbEffGuestGdtLimit;
uint32_t padding0;
/** HC Pointer to the LDT shadow area placed in Hypervisor memory arena. */
R3PTRTYPE(void *) HCPtrLdt;
/** GC Pointer to the LDT shadow area placed in Hypervisor memory arena. */
RCPTRTYPE(void *) GCPtrLdt;
#if GC_ARCH_BITS == 64
RTRCPTR padding1;
#endif
/** GC Pointer to the current Guest's LDT. */
RTGCPTR GCPtrGuestLdt;
/** Current LDT limit, both Guest and Shadow. */
RTUINT cbLdtLimit;
/** Current LDT offset relative to pvLdt*. */
RTUINT offLdtHyper;
#if HC_ARCH_BITS == 32 && GC_ARCH_BITS == 64
uint32_t padding2[2];
#endif
/** TSS. (This is 16 byte aligned!)
* @todo I/O bitmap & interrupt redirection table? */
VBOXTSS Tss;
/** TSS for trap 08 (\#DF). */
VBOXTSS TssTrap08;
/** GC Pointer to the TSS shadow area (Tss) placed in Hypervisor memory arena. */
RCPTRTYPE(void *) GCPtrTss;
#if GC_ARCH_BITS == 64
RTRCPTR padding3;
#endif
/** GC Pointer to the current Guest's TSS. */
RTGCPTR GCPtrGuestTss;
/** The size of the guest TSS. */
RTUINT cbGuestTss;
/** Set if it's a 32-bit TSS. */
bool fGuestTss32Bit;
/** The size of the Guest's TSS part we're monitoring. */
RTUINT cbMonitoredGuestTss;
/** GC shadow TSS selector */
RTSEL GCSelTss;
/** Indicates that the Guest GDT access handler have been registered. */
bool fGDTRangeRegistered;
/** Indicates whether LDT/GDT/TSS monitoring and syncing is disabled. */
bool fDisableMonitoring;
/** Indicates whether the TSS stack selector & base address need to be refreshed. */
bool fSyncTSSRing0Stack;
/** alignment . */
RTUINT uPadding2;
/** SELMR3UpdateFromCPUM() profiling. */
STAMPROFILE StatUpdateFromCPUM;
/** SELMR3SyncTSS() profiling. */
STAMPROFILE StatTSSSync;
/** GC: The number of handled writes to the Guest's GDT. */
STAMCOUNTER StatGCWriteGuestGDTHandled;
/** GC: The number of unhandled write to the Guest's GDT. */
STAMCOUNTER StatGCWriteGuestGDTUnhandled;
/** GC: The number of times writes to Guest's LDT was detected. */
STAMCOUNTER StatGCWriteGuestLDT;
/** GC: The number of handled writes to the Guest's TSS. */
STAMCOUNTER StatGCWriteGuestTSSHandled;
/** GC: The number of handled writes to the Guest's TSS where we detected a change. */
STAMCOUNTER StatGCWriteGuestTSSHandledChanged;
/** GC: The number of handled redir writes to the Guest's TSS where we detected a change. */
STAMCOUNTER StatGCWriteGuestTSSRedir;
/** GC: The number of unhandled writes to the Guest's TSS. */
STAMCOUNTER StatGCWriteGuestTSSUnhandled;
/** The number of times we had to relocate our hypervisor selectors. */
STAMCOUNTER StatHyperSelsChanged;
/** The number of times we had find free hypervisor selectors. */
STAMCOUNTER StatScanForHyperSels;
} SELM, *PSELM;
__BEGIN_DECLS
SELMGCDECL(int) selmgcGuestGDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
SELMGCDECL(int) selmgcGuestLDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
SELMGCDECL(int) selmgcGuestTSSWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
SELMGCDECL(int) selmgcShadowGDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
SELMGCDECL(int) selmgcShadowLDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
SELMGCDECL(int) selmgcShadowTSSWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
__END_DECLS
#ifdef IN_RING3
#endif
/** @} */
#endif