1 | /* $Id: SELMInternal.h 12989 2008-10-06 02:15:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * SELM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ___SELMInternal_h
|
---|
23 | #define ___SELMInternal_h
|
---|
24 |
|
---|
25 | #include <VBox/cdefs.h>
|
---|
26 | #include <VBox/types.h>
|
---|
27 | #include <VBox/stam.h>
|
---|
28 | #include <VBox/cpum.h>
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 | /** @defgroup grp_selm_int Internals
|
---|
33 | * @ingroup grp_selm
|
---|
34 | * @internal
|
---|
35 | * @{
|
---|
36 | */
|
---|
37 |
|
---|
38 | /** The number of GDTS allocated for our GDT. (full size) */
|
---|
39 | #define SELM_GDT_ELEMENTS 8192
|
---|
40 |
|
---|
41 | /** aHyperSel index to retrieve hypervisor selectors */
|
---|
42 | /** The Flat CS selector used by the VMM inside the GC. */
|
---|
43 | #define SELM_HYPER_SEL_CS 0
|
---|
44 | /** The Flat DS selector used by the VMM inside the GC. */
|
---|
45 | #define SELM_HYPER_SEL_DS 1
|
---|
46 | /** The 64-bit mode CS selector used by the VMM inside the GC. */
|
---|
47 | #define SELM_HYPER_SEL_CS64 2
|
---|
48 | /** The TSS selector used by the VMM inside the GC. */
|
---|
49 | #define SELM_HYPER_SEL_TSS 3
|
---|
50 | /** The TSS selector for taking trap 08 (\#DF). */
|
---|
51 | #define SELM_HYPER_SEL_TSS_TRAP08 4
|
---|
52 | /** Number of GDTs we need for internal use */
|
---|
53 | #define SELM_HYPER_SEL_MAX (SELM_HYPER_SEL_TSS_TRAP08 + 1)
|
---|
54 |
|
---|
55 |
|
---|
56 | /** Default GDT selectors we use for the hypervisor. */
|
---|
57 | #define SELM_HYPER_DEFAULT_SEL_CS ((SELM_GDT_ELEMENTS - 0x1) << 3)
|
---|
58 | #define SELM_HYPER_DEFAULT_SEL_DS ((SELM_GDT_ELEMENTS - 0x2) << 3)
|
---|
59 | #define SELM_HYPER_DEFAULT_SEL_CS64 ((SELM_GDT_ELEMENTS - 0x3) << 3)
|
---|
60 | #define SELM_HYPER_DEFAULT_SEL_TSS ((SELM_GDT_ELEMENTS - 0x4) << 3)
|
---|
61 | #define SELM_HYPER_DEFAULT_SEL_TSS_TRAP08 ((SELM_GDT_ELEMENTS - 0x5) << 3)
|
---|
62 | /** The lowest value default we use. */
|
---|
63 | #define SELM_HYPER_DEFAULT_BASE SELM_HYPER_DEFAULT_SEL_TSS_TRAP08
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Converts a SELM pointer into a VM pointer.
|
---|
67 | * @returns Pointer to the VM structure the SELM is part of.
|
---|
68 | * @param pSELM Pointer to SELM instance data.
|
---|
69 | */
|
---|
70 | #define SELM2VM(pSELM) ( (PVM)((char*)pSELM - pSELM->offVM) )
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * SELM Data (part of VM)
|
---|
76 | */
|
---|
77 | typedef struct SELM
|
---|
78 | {
|
---|
79 | /** Offset to the VM structure.
|
---|
80 | * See SELM2VM(). */
|
---|
81 | RTINT offVM;
|
---|
82 |
|
---|
83 | /* Flat CS, DS, 64 bit mode CS, TSS & trap 8 TSS. */
|
---|
84 | RTSEL aHyperSel[SELM_HYPER_SEL_MAX];
|
---|
85 |
|
---|
86 | /** Pointer to the GCs - HC Ptr.
|
---|
87 | * This size is governed by SELM_GDT_ELEMENTS. */
|
---|
88 | R3R0PTRTYPE(PX86DESC) paGdtHC;
|
---|
89 | /** Pointer to the GCs - GC Ptr.
|
---|
90 | * This is not initialized until the first relocation because it's used to
|
---|
91 | * check if the shadow GDT virtual handler requires deregistration. */
|
---|
92 | RCPTRTYPE(PX86DESC) paGdtGC;
|
---|
93 | /** Current (last) Guest's GDTR. */
|
---|
94 | VBOXGDTR GuestGdtr;
|
---|
95 | /** The current (last) effective Guest GDT size. */
|
---|
96 | RTUINT cbEffGuestGdtLimit;
|
---|
97 |
|
---|
98 | uint32_t padding0;
|
---|
99 |
|
---|
100 | /** HC Pointer to the LDT shadow area placed in Hypervisor memory arena. */
|
---|
101 | R3PTRTYPE(void *) HCPtrLdt;
|
---|
102 | /** GC Pointer to the LDT shadow area placed in Hypervisor memory arena. */
|
---|
103 | RCPTRTYPE(void *) GCPtrLdt;
|
---|
104 | #if GC_ARCH_BITS == 64
|
---|
105 | RTRCPTR padding1;
|
---|
106 | #endif
|
---|
107 | /** GC Pointer to the current Guest's LDT. */
|
---|
108 | RTGCPTR GCPtrGuestLdt;
|
---|
109 | /** Current LDT limit, both Guest and Shadow. */
|
---|
110 | RTUINT cbLdtLimit;
|
---|
111 | /** Current LDT offset relative to pvLdt*. */
|
---|
112 | RTUINT offLdtHyper;
|
---|
113 | #if HC_ARCH_BITS == 32 && GC_ARCH_BITS == 64
|
---|
114 | uint32_t padding2[2];
|
---|
115 | #endif
|
---|
116 | /** TSS. (This is 16 byte aligned!)
|
---|
117 | * @todo I/O bitmap & interrupt redirection table? */
|
---|
118 | VBOXTSS Tss;
|
---|
119 |
|
---|
120 | /** TSS for trap 08 (\#DF). */
|
---|
121 | VBOXTSS TssTrap08;
|
---|
122 |
|
---|
123 | /** GC Pointer to the TSS shadow area (Tss) placed in Hypervisor memory arena. */
|
---|
124 | RCPTRTYPE(void *) GCPtrTss;
|
---|
125 | #if GC_ARCH_BITS == 64
|
---|
126 | RTRCPTR padding3;
|
---|
127 | #endif
|
---|
128 | /** GC Pointer to the current Guest's TSS. */
|
---|
129 | RTGCPTR GCPtrGuestTss;
|
---|
130 | /** The size of the guest TSS. */
|
---|
131 | RTUINT cbGuestTss;
|
---|
132 | /** Set if it's a 32-bit TSS. */
|
---|
133 | bool fGuestTss32Bit;
|
---|
134 | /** The size of the Guest's TSS part we're monitoring. */
|
---|
135 | RTUINT cbMonitoredGuestTss;
|
---|
136 | /** GC shadow TSS selector */
|
---|
137 | RTSEL GCSelTss;
|
---|
138 |
|
---|
139 | /** Indicates that the Guest GDT access handler have been registered. */
|
---|
140 | bool fGDTRangeRegistered;
|
---|
141 |
|
---|
142 | /** Indicates whether LDT/GDT/TSS monitoring and syncing is disabled. */
|
---|
143 | bool fDisableMonitoring;
|
---|
144 |
|
---|
145 | /** Indicates whether the TSS stack selector & base address need to be refreshed. */
|
---|
146 | bool fSyncTSSRing0Stack;
|
---|
147 | /** alignment . */
|
---|
148 | RTUINT uPadding2;
|
---|
149 |
|
---|
150 | /** SELMR3UpdateFromCPUM() profiling. */
|
---|
151 | STAMPROFILE StatUpdateFromCPUM;
|
---|
152 | /** SELMR3SyncTSS() profiling. */
|
---|
153 | STAMPROFILE StatTSSSync;
|
---|
154 |
|
---|
155 | /** GC: The number of handled writes to the Guest's GDT. */
|
---|
156 | STAMCOUNTER StatGCWriteGuestGDTHandled;
|
---|
157 | /** GC: The number of unhandled write to the Guest's GDT. */
|
---|
158 | STAMCOUNTER StatGCWriteGuestGDTUnhandled;
|
---|
159 | /** GC: The number of times writes to Guest's LDT was detected. */
|
---|
160 | STAMCOUNTER StatGCWriteGuestLDT;
|
---|
161 | /** GC: The number of handled writes to the Guest's TSS. */
|
---|
162 | STAMCOUNTER StatGCWriteGuestTSSHandled;
|
---|
163 | /** GC: The number of handled writes to the Guest's TSS where we detected a change. */
|
---|
164 | STAMCOUNTER StatGCWriteGuestTSSHandledChanged;
|
---|
165 | /** GC: The number of handled redir writes to the Guest's TSS where we detected a change. */
|
---|
166 | STAMCOUNTER StatGCWriteGuestTSSRedir;
|
---|
167 | /** GC: The number of unhandled writes to the Guest's TSS. */
|
---|
168 | STAMCOUNTER StatGCWriteGuestTSSUnhandled;
|
---|
169 | /** The number of times we had to relocate our hypervisor selectors. */
|
---|
170 | STAMCOUNTER StatHyperSelsChanged;
|
---|
171 | /** The number of times we had find free hypervisor selectors. */
|
---|
172 | STAMCOUNTER StatScanForHyperSels;
|
---|
173 | } SELM, *PSELM;
|
---|
174 |
|
---|
175 | __BEGIN_DECLS
|
---|
176 |
|
---|
177 | VMMRCDECL(int) selmgcGuestGDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
|
---|
178 | VMMRCDECL(int) selmgcGuestLDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
|
---|
179 | VMMRCDECL(int) selmgcGuestTSSWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
|
---|
180 |
|
---|
181 | VMMRCDECL(int) selmgcShadowGDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
|
---|
182 | VMMRCDECL(int) selmgcShadowLDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
|
---|
183 | VMMRCDECL(int) selmgcShadowTSSWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
|
---|
184 |
|
---|
185 | __END_DECLS
|
---|
186 |
|
---|
187 | #ifdef IN_RING3
|
---|
188 |
|
---|
189 | #endif
|
---|
190 |
|
---|
191 | /** @} */
|
---|
192 |
|
---|
193 | #endif
|
---|