VirtualBox

source: vbox/trunk/src/VBox/VMM/CPUMInternal.h@ 14683

Last change on this file since 14683 was 14411, checked in by vboxsync, 16 years ago

RDTSCP support added. Enabled only for AMD-V guests.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.6 KB
Line 
1/* $Id: CPUMInternal.h 14411 2008-11-20 13:26:47Z vboxsync $ */
2/** @file
3 * CPUM - 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 ___CPUMInternal_h
23#define ___CPUMInternal_h
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27#include <VBox/x86.h>
28
29
30
31/** @defgroup grp_cpum_int Internals
32 * @ingroup grp_cpum
33 * @internal
34 * @{
35 */
36
37/** Flags and types for CPUM fault handlers
38 * @{ */
39/** Type: Load DS */
40#define CPUM_HANDLER_DS 1
41/** Type: Load ES */
42#define CPUM_HANDLER_ES 2
43/** Type: Load FS */
44#define CPUM_HANDLER_FS 3
45/** Type: Load GS */
46#define CPUM_HANDLER_GS 4
47/** Type: IRET */
48#define CPUM_HANDLER_IRET 5
49/** Type mask. */
50#define CPUM_HANDLER_TYPEMASK 0xff
51/** If set EBP points to the CPUMCTXCORE that's being used. */
52#define CPUM_HANDLER_CTXCORE_IN_EBP RT_BIT(31)
53/** @} */
54
55
56/** Use flags (CPUM::fUseFlags).
57 * (Don't forget to sync this with CPUMInternal.mac!)
58 * @{ */
59/** Used the FPU, SSE or such stuff. */
60#define CPUM_USED_FPU RT_BIT(0)
61/** Used the FPU, SSE or such stuff since last we were in REM.
62 * REM syncing is clearing this, lazy FPU is setting it. */
63#define CPUM_USED_FPU_SINCE_REM RT_BIT(1)
64/** Host OS is using SYSENTER and we must NULL the CS. */
65#define CPUM_USE_SYSENTER RT_BIT(2)
66/** Host OS is using SYSENTER and we must NULL the CS. */
67#define CPUM_USE_SYSCALL RT_BIT(3)
68/** Debug registers are used by host and must be disabled. */
69#define CPUM_USE_DEBUG_REGS_HOST RT_BIT(4)
70/** Enabled use of debug registers in guest context. */
71#define CPUM_USE_DEBUG_REGS RT_BIT(5)
72/** The XMM state was manually restored. (AMD only) */
73#define CPUM_MANUAL_XMM_RESTORE RT_BIT(6)
74/** @} */
75
76/* Sanity check. */
77#if defined(VBOX_WITH_HYBIRD_32BIT_KERNEL) && (HC_ARCH_BITS != 32 || R0_ARCH_BITS != 32)
78# error "VBOX_WITH_HYBIRD_32BIT_KERNEL is only for 32 bit builds."
79#endif
80
81
82/**
83 * The saved host CPU state.
84 *
85 * @remark The special VBOX_WITH_HYBIRD_32BIT_KERNEL checks here are for the 10.4.x series
86 * of Mac OS X where the OS is essentially 32-bit but the cpu mode can be 64-bit.
87 */
88typedef struct CPUMHOSTCTX
89{
90 /** FPU state. (16-byte alignment)
91 * @remark On x86, the format isn't necessarily X86FXSTATE (not important). */
92 X86FXSTATE fpu;
93
94 /** General purpose register, selectors, flags and more
95 * @{ */
96#if HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
97 /** General purpose register ++
98 * { */
99 //uint64_t rax; - scratch
100 uint64_t rbx;
101 //uint64_t rcx; - scratch
102 //uint64_t rdx; - scratch
103 uint64_t rdi;
104 uint64_t rsi;
105 uint64_t rbp;
106 uint64_t rsp;
107 //uint64_t r8; - scratch
108 //uint64_t r9; - scratch
109 uint64_t r10;
110 uint64_t r11;
111 uint64_t r12;
112 uint64_t r13;
113 uint64_t r14;
114 uint64_t r15;
115 //uint64_t rip; - scratch
116 uint64_t rflags;
117#endif
118
119#if HC_ARCH_BITS == 32
120 //uint32_t eax; - scratch
121 uint32_t ebx;
122 //uint32_t ecx; - scratch
123 //uint32_t edx; - scratch
124 uint32_t edi;
125 uint32_t esi;
126 uint32_t ebp;
127 X86EFLAGS eflags;
128 //uint32_t eip; - scratch
129 /* lss pair! */
130 uint32_t esp;
131#endif
132 /** @} */
133
134 /** Selector registers
135 * @{ */
136 RTSEL ss;
137 RTSEL ssPadding;
138 RTSEL gs;
139 RTSEL gsPadding;
140 RTSEL fs;
141 RTSEL fsPadding;
142 RTSEL es;
143 RTSEL esPadding;
144 RTSEL ds;
145 RTSEL dsPadding;
146 RTSEL cs;
147 RTSEL csPadding;
148 /** @} */
149
150#if HC_ARCH_BITS == 32 && !defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
151 /** Control registers.
152 * @{ */
153 uint32_t cr0;
154 //uint32_t cr2; - scratch
155 uint32_t cr3;
156 uint32_t cr4;
157 /** @} */
158
159 /** Debug registers.
160 * @{ */
161 uint32_t dr0;
162 uint32_t dr1;
163 uint32_t dr2;
164 uint32_t dr3;
165 uint32_t dr6;
166 uint32_t dr7;
167 /** @} */
168
169 /** Global Descriptor Table register. */
170 X86XDTR32 gdtr;
171 uint16_t gdtrPadding;
172 /** Interrupt Descriptor Table register. */
173 X86XDTR32 idtr;
174 uint16_t idtrPadding;
175 /** The task register. */
176 RTSEL ldtr;
177 RTSEL ldtrPadding;
178 /** The task register. */
179 RTSEL tr;
180 RTSEL trPadding;
181 uint32_t SysEnterPadding;
182
183 /** The sysenter msr registers.
184 * This member is not used by the hypervisor context. */
185 CPUMSYSENTER SysEnter;
186
187 /* padding to get 64byte aligned size */
188 uint8_t auPadding[24+32];
189
190#elif HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
191
192 /** Control registers.
193 * @{ */
194 uint64_t cr0;
195 //uint64_t cr2; - scratch
196 uint64_t cr3;
197 uint64_t cr4;
198 uint64_t cr8;
199 /** @} */
200
201 /** Debug registers.
202 * @{ */
203 uint64_t dr0;
204 uint64_t dr1;
205 uint64_t dr2;
206 uint64_t dr3;
207 uint64_t dr6;
208 uint64_t dr7;
209 /** @} */
210
211 /** Global Descriptor Table register. */
212 X86XDTR64 gdtr;
213 uint16_t gdtrPadding;
214 /** Interrupt Descriptor Table register. */
215 X86XDTR64 idtr;
216 uint16_t idtrPadding;
217 /** The task register. */
218 RTSEL ldtr;
219 RTSEL ldtrPadding;
220 /** The task register. */
221 RTSEL tr;
222 RTSEL trPadding;
223
224 /** MSRs
225 * @{ */
226 CPUMSYSENTER SysEnter;
227 uint64_t FSbase;
228 uint64_t GSbase;
229 uint64_t efer;
230 /** @} */
231
232 /* padding to get 32byte aligned size */
233# ifdef VBOX_WITH_HYBIRD_32BIT_KERNEL
234 uint8_t auPadding[16];
235# else
236 uint8_t auPadding[8+32];
237# endif
238
239#else
240# error HC_ARCH_BITS not defined
241#endif
242} CPUMHOSTCTX;
243/** Pointer to the saved host CPU state. */
244typedef CPUMHOSTCTX *PCPUMHOSTCTX;
245
246
247/**
248 * CPUM Data (part of VM)
249 */
250typedef struct CPUM
251{
252 /**
253 * Hypervisor context.
254 * Aligned on a 64-byte boundrary.
255 */
256 CPUMCTX Hyper;
257
258 /** Pointer to the current hypervisor core context - R3Ptr. */
259 R3PTRTYPE(PCPUMCTXCORE) pHyperCoreR3;
260 /** Pointer to the current hypervisor core context - R0Ptr. */
261 R0PTRTYPE(PCPUMCTXCORE) pHyperCoreR0;
262 /** Pointer to the current hypervisor core context - RCPtr. */
263 RCPTRTYPE(PCPUMCTXCORE) pHyperCoreRC;
264
265 /* Offset from CPUM to CPUMCPU for the first CPU. */
266 uint32_t ulOffCPUMCPU;
267
268 /** Hidden selector registers state.
269 * Valid (hw accelerated raw mode) or not (normal raw mode)
270 */
271 uint32_t fValidHiddenSelRegs;
272
273 /** Host CPU Features - ECX */
274 struct
275 {
276 /** edx part */
277 X86CPUIDFEATEDX edx;
278 /** ecx part */
279 X86CPUIDFEATECX ecx;
280 } CPUFeatures;
281 /** Host extended CPU features. */
282 struct
283 {
284 /** edx part */
285 uint32_t edx;
286 /** ecx part */
287 uint32_t ecx;
288 } CPUFeaturesExt;
289
290 /* CPU manufacturer. */
291 CPUMCPUVENDOR enmCPUVendor;
292
293 /** CR4 mask */
294 struct
295 {
296 uint32_t AndMask;
297 uint32_t OrMask;
298 } CR4;
299
300 /** Have we entered rawmode? */
301 bool fRawEntered;
302 uint8_t abPadding[3 + (HC_ARCH_BITS == 64) * 4];
303
304 /** The standard set of CpuId leafs. */
305 CPUMCPUID aGuestCpuIdStd[6];
306 /** The extended set of CpuId leafs. */
307 CPUMCPUID aGuestCpuIdExt[10];
308 /** The centaur set of CpuId leafs. */
309 CPUMCPUID aGuestCpuIdCentaur[4];
310 /** The default set of CpuId leafs. */
311 CPUMCPUID GuestCpuIdDef;
312
313 /** Align the next member, and thereby the structure, on a 64-byte boundrary. */
314 uint8_t abPadding2[HC_ARCH_BITS == 32 ? 60 : 48];
315
316 /**
317 * Guest context on raw mode entry.
318 * This a debug feature, see CPUMR3SaveEntryCtx.
319 */
320 CPUMCTX GuestEntry;
321} CPUM;
322/** Pointer to the CPUM instance data residing in the shared VM structure. */
323typedef CPUM *PCPUM;
324
325/**
326 * CPUM Data (part of VMCPU)
327 */
328typedef struct CPUMCPU
329{
330 /**
331 * Saved host context. Only valid while inside GC.
332 * Aligned on a 64-byte boundrary.
333 */
334 CPUMHOSTCTX Host;
335
336 /**
337 * Guest context.
338 * Aligned on a 64-byte boundrary.
339 */
340 CPUMCTX Guest;
341
342 /**
343 * Guest context - misc MSRs
344 * Aligned on a 64-byte boundrary.
345 */
346 CPUMCTXMSR GuestMsr;
347
348 /** Use flags.
349 * These flags indicates both what is to be used and what has been used.
350 */
351 uint32_t fUseFlags;
352
353 /** Changed flags.
354 * These flags indicates to REM (and others) which important guest
355 * registers which has been changed since last time the flags were cleared.
356 * See the CPUM_CHANGED_* defines for what we keep track of.
357 */
358 uint32_t fChanged;
359
360 /* Offset to CPUM. (subtract from the pointer to get to CPUM) */
361 uint32_t ulOffCPUM;
362
363 /* Round to 16 byte size. */
364 uint32_t uPadding;
365} CPUMCPU, *PCPUMCPU;
366/** Pointer to the CPUMCPU instance data residing in the shared VMCPU structure. */
367typedef CPUMCPU *PCPUMCPU;
368
369__BEGIN_DECLS
370
371DECLASM(int) CPUMHandleLazyFPUAsm(PCPUMCPU pCPUM);
372DECLASM(int) CPUMRestoreHostFPUStateAsm(PCPUMCPU pCPUM);
373DECLASM(void) CPUMLoadFPUAsm(PCPUMCTX pCtx);
374DECLASM(void) CPUMSaveFPUAsm(PCPUMCTX pCtx);
375DECLASM(void) CPUMLoadXMMAsm(PCPUMCTX pCtx);
376DECLASM(void) CPUMSaveXMMAsm(PCPUMCTX pCtx);
377DECLASM(void) CPUMSetFCW(uint16_t u16FCW);
378DECLASM(uint16_t) CPUMGetFCW();
379DECLASM(void) CPUMSetMXCSR(uint32_t u32MXCSR);
380DECLASM(uint32_t) CPUMGetMXCSR();
381
382__END_DECLS
383
384/** @} */
385
386#endif
387
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette