VirtualBox

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

Last change on this file since 13333 was 12989, checked in by vboxsync, 16 years ago

VMM + VBox/cdefs.h: consolidated all the XYZ*DECLS of the VMM into VMM*DECL. Removed dead DECL and IN_XYZ* macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.0 KB
Line 
1/* $Id: CPUMInternal.h 12989 2008-10-06 02:15:39Z 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 * Saved host context. Only valid while inside GC.
254 * Aligned on a 64-byte boundrary.
255 */
256 CPUMHOSTCTX Host;
257
258 /**
259 * Hypervisor context.
260 * Aligned on a 64-byte boundrary.
261 */
262 CPUMCTX Hyper;
263
264 /**
265 * Guest context.
266 * Aligned on a 64-byte boundrary.
267 */
268 CPUMCTX Guest;
269
270
271 /** Pointer to the current hypervisor core context - R3Ptr. */
272 R3PTRTYPE(PCPUMCTXCORE) pHyperCoreR3;
273 /** Pointer to the current hypervisor core context - R3Ptr. */
274 R0PTRTYPE(PCPUMCTXCORE) pHyperCoreR0;
275 /** Pointer to the current hypervisor core context - RCPtr. */
276 RCPTRTYPE(PCPUMCTXCORE) pHyperCoreRC;
277
278 /** Use flags.
279 * These flags indicates both what is to be used and what have been used.
280 */
281 uint32_t fUseFlags;
282
283 /** Changed flags.
284 * These flags indicates to REM (and others) which important guest
285 * registers which has been changed since last time the flags were cleared.
286 * See the CPUM_CHANGED_* defines for what we keep track of.
287 */
288 uint32_t fChanged;
289
290 /** Hidden selector registers state.
291 * Valid (hw accelerated raw mode) or not (normal raw mode)
292 */
293 uint32_t fValidHiddenSelRegs;
294
295 /** Host CPU Features - ECX */
296 struct
297 {
298 /** edx part */
299 X86CPUIDFEATEDX edx;
300 /** ecx part */
301 X86CPUIDFEATECX ecx;
302 } CPUFeatures;
303 /** Host extended CPU features. */
304 struct
305 {
306 /** edx part */
307 uint32_t edx;
308 /** ecx part */
309 uint32_t ecx;
310 } CPUFeaturesExt;
311
312 /* CPU manufacturer. */
313 CPUMCPUVENDOR enmCPUVendor;
314
315 /** CR4 mask */
316 struct
317 {
318 uint32_t AndMask;
319 uint32_t OrMask;
320 } CR4;
321
322 /** Have we entered rawmode? */
323 bool fRawEntered;
324 uint8_t abPadding[3 + (HC_ARCH_BITS == 64) * 4];
325
326 /** The standard set of CpuId leafs. */
327 CPUMCPUID aGuestCpuIdStd[6];
328 /** The extended set of CpuId leafs. */
329 CPUMCPUID aGuestCpuIdExt[10];
330 /** The centaur set of CpuId leafs. */
331 CPUMCPUID aGuestCpuIdCentaur[4];
332 /** The default set of CpuId leafs. */
333 CPUMCPUID GuestCpuIdDef;
334
335 /** Align the next member, and thereby the structure, on a 64-byte boundrary. */
336 uint8_t abPadding2[HC_ARCH_BITS == 32 ? 56 : 44];
337
338 /**
339 * Guest context on raw mode entry.
340 * This a debug feature, see CPUMR3SaveEntryCtx.
341 */
342 CPUMCTX GuestEntry;
343} CPUM;
344/** Pointer to the CPUM instance data residing in the shared VM structure. */
345typedef CPUM *PCPUM;
346
347__BEGIN_DECLS
348
349DECLASM(int) CPUMHandleLazyFPUAsm(PCPUM pCPUM);
350DECLASM(int) CPUMRestoreHostFPUStateAsm(PCPUM pCPUM);
351DECLASM(void) CPUMLoadFPUAsm(PCPUMCTX pCtx);
352DECLASM(void) CPUMSaveFPUAsm(PCPUMCTX pCtx);
353DECLASM(void) CPUMLoadXMMAsm(PCPUMCTX pCtx);
354DECLASM(void) CPUMSaveXMMAsm(PCPUMCTX pCtx);
355DECLASM(void) CPUMSetFCW(uint16_t u16FCW);
356DECLASM(uint16_t) CPUMGetFCW();
357DECLASM(void) CPUMSetMXCSR(uint32_t u32MXCSR);
358DECLASM(uint32_t) CPUMGetMXCSR();
359
360__END_DECLS
361
362/** @} */
363
364#endif
365
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