1 | /* $Id: CPUMInternal.h 14870 2008-12-01 15:28:54Z 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 | /** Sync the FPU state on entry (32->64 switcher only). */
|
---|
75 | #define CPUM_SYNC_FPU_STATE RT_BIT(7)
|
---|
76 | /** Sync the debug state on entry (32->64 switcher only). */
|
---|
77 | #define CPUM_SYNC_DEBUG_STATE RT_BIT(8)
|
---|
78 | /** @} */
|
---|
79 |
|
---|
80 | /* Sanity check. */
|
---|
81 | #if defined(VBOX_WITH_HYBIRD_32BIT_KERNEL) && (HC_ARCH_BITS != 32 || R0_ARCH_BITS != 32)
|
---|
82 | # error "VBOX_WITH_HYBIRD_32BIT_KERNEL is only for 32 bit builds."
|
---|
83 | #endif
|
---|
84 |
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * The saved host CPU state.
|
---|
88 | *
|
---|
89 | * @remark The special VBOX_WITH_HYBIRD_32BIT_KERNEL checks here are for the 10.4.x series
|
---|
90 | * of Mac OS X where the OS is essentially 32-bit but the cpu mode can be 64-bit.
|
---|
91 | */
|
---|
92 | typedef struct CPUMHOSTCTX
|
---|
93 | {
|
---|
94 | /** FPU state. (16-byte alignment)
|
---|
95 | * @remark On x86, the format isn't necessarily X86FXSTATE (not important). */
|
---|
96 | X86FXSTATE fpu;
|
---|
97 |
|
---|
98 | /** General purpose register, selectors, flags and more
|
---|
99 | * @{ */
|
---|
100 | #if HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
|
---|
101 | /** General purpose register ++
|
---|
102 | * { */
|
---|
103 | //uint64_t rax; - scratch
|
---|
104 | uint64_t rbx;
|
---|
105 | //uint64_t rcx; - scratch
|
---|
106 | //uint64_t rdx; - scratch
|
---|
107 | uint64_t rdi;
|
---|
108 | uint64_t rsi;
|
---|
109 | uint64_t rbp;
|
---|
110 | uint64_t rsp;
|
---|
111 | //uint64_t r8; - scratch
|
---|
112 | //uint64_t r9; - scratch
|
---|
113 | uint64_t r10;
|
---|
114 | uint64_t r11;
|
---|
115 | uint64_t r12;
|
---|
116 | uint64_t r13;
|
---|
117 | uint64_t r14;
|
---|
118 | uint64_t r15;
|
---|
119 | //uint64_t rip; - scratch
|
---|
120 | uint64_t rflags;
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | #if HC_ARCH_BITS == 32
|
---|
124 | //uint32_t eax; - scratch
|
---|
125 | uint32_t ebx;
|
---|
126 | //uint32_t ecx; - scratch
|
---|
127 | //uint32_t edx; - scratch
|
---|
128 | uint32_t edi;
|
---|
129 | uint32_t esi;
|
---|
130 | uint32_t ebp;
|
---|
131 | X86EFLAGS eflags;
|
---|
132 | //uint32_t eip; - scratch
|
---|
133 | /* lss pair! */
|
---|
134 | uint32_t esp;
|
---|
135 | #endif
|
---|
136 | /** @} */
|
---|
137 |
|
---|
138 | /** Selector registers
|
---|
139 | * @{ */
|
---|
140 | RTSEL ss;
|
---|
141 | RTSEL ssPadding;
|
---|
142 | RTSEL gs;
|
---|
143 | RTSEL gsPadding;
|
---|
144 | RTSEL fs;
|
---|
145 | RTSEL fsPadding;
|
---|
146 | RTSEL es;
|
---|
147 | RTSEL esPadding;
|
---|
148 | RTSEL ds;
|
---|
149 | RTSEL dsPadding;
|
---|
150 | RTSEL cs;
|
---|
151 | RTSEL csPadding;
|
---|
152 | /** @} */
|
---|
153 |
|
---|
154 | #if HC_ARCH_BITS == 32 && !defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
|
---|
155 | /** Control registers.
|
---|
156 | * @{ */
|
---|
157 | uint32_t cr0;
|
---|
158 | //uint32_t cr2; - scratch
|
---|
159 | uint32_t cr3;
|
---|
160 | uint32_t cr4;
|
---|
161 | /** @} */
|
---|
162 |
|
---|
163 | /** Debug registers.
|
---|
164 | * @{ */
|
---|
165 | uint32_t dr0;
|
---|
166 | uint32_t dr1;
|
---|
167 | uint32_t dr2;
|
---|
168 | uint32_t dr3;
|
---|
169 | uint32_t dr6;
|
---|
170 | uint32_t dr7;
|
---|
171 | /** @} */
|
---|
172 |
|
---|
173 | /** Global Descriptor Table register. */
|
---|
174 | X86XDTR32 gdtr;
|
---|
175 | uint16_t gdtrPadding;
|
---|
176 | /** Interrupt Descriptor Table register. */
|
---|
177 | X86XDTR32 idtr;
|
---|
178 | uint16_t idtrPadding;
|
---|
179 | /** The task register. */
|
---|
180 | RTSEL ldtr;
|
---|
181 | RTSEL ldtrPadding;
|
---|
182 | /** The task register. */
|
---|
183 | RTSEL tr;
|
---|
184 | RTSEL trPadding;
|
---|
185 | uint32_t SysEnterPadding;
|
---|
186 |
|
---|
187 | /** The sysenter msr registers.
|
---|
188 | * This member is not used by the hypervisor context. */
|
---|
189 | CPUMSYSENTER SysEnter;
|
---|
190 |
|
---|
191 | /* padding to get 64byte aligned size */
|
---|
192 | uint8_t auPadding[24+32];
|
---|
193 |
|
---|
194 | #elif HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
|
---|
195 |
|
---|
196 | /** Control registers.
|
---|
197 | * @{ */
|
---|
198 | uint64_t cr0;
|
---|
199 | //uint64_t cr2; - scratch
|
---|
200 | uint64_t cr3;
|
---|
201 | uint64_t cr4;
|
---|
202 | uint64_t cr8;
|
---|
203 | /** @} */
|
---|
204 |
|
---|
205 | /** Debug registers.
|
---|
206 | * @{ */
|
---|
207 | uint64_t dr0;
|
---|
208 | uint64_t dr1;
|
---|
209 | uint64_t dr2;
|
---|
210 | uint64_t dr3;
|
---|
211 | uint64_t dr6;
|
---|
212 | uint64_t dr7;
|
---|
213 | /** @} */
|
---|
214 |
|
---|
215 | /** Global Descriptor Table register. */
|
---|
216 | X86XDTR64 gdtr;
|
---|
217 | uint16_t gdtrPadding;
|
---|
218 | /** Interrupt Descriptor Table register. */
|
---|
219 | X86XDTR64 idtr;
|
---|
220 | uint16_t idtrPadding;
|
---|
221 | /** The task register. */
|
---|
222 | RTSEL ldtr;
|
---|
223 | RTSEL ldtrPadding;
|
---|
224 | /** The task register. */
|
---|
225 | RTSEL tr;
|
---|
226 | RTSEL trPadding;
|
---|
227 |
|
---|
228 | /** MSRs
|
---|
229 | * @{ */
|
---|
230 | CPUMSYSENTER SysEnter;
|
---|
231 | uint64_t FSbase;
|
---|
232 | uint64_t GSbase;
|
---|
233 | uint64_t efer;
|
---|
234 | /** @} */
|
---|
235 |
|
---|
236 | /* padding to get 32byte aligned size */
|
---|
237 | # ifdef VBOX_WITH_HYBIRD_32BIT_KERNEL
|
---|
238 | uint8_t auPadding[16];
|
---|
239 | # else
|
---|
240 | uint8_t auPadding[8+32];
|
---|
241 | # endif
|
---|
242 |
|
---|
243 | #else
|
---|
244 | # error HC_ARCH_BITS not defined
|
---|
245 | #endif
|
---|
246 | } CPUMHOSTCTX;
|
---|
247 | /** Pointer to the saved host CPU state. */
|
---|
248 | typedef CPUMHOSTCTX *PCPUMHOSTCTX;
|
---|
249 |
|
---|
250 |
|
---|
251 | /**
|
---|
252 | * CPUM Data (part of VM)
|
---|
253 | */
|
---|
254 | typedef struct CPUM
|
---|
255 | {
|
---|
256 | /**
|
---|
257 | * Hypervisor context.
|
---|
258 | * Aligned on a 64-byte boundrary.
|
---|
259 | */
|
---|
260 | CPUMCTX Hyper;
|
---|
261 |
|
---|
262 | /** Pointer to the current hypervisor core context - R3Ptr. */
|
---|
263 | R3PTRTYPE(PCPUMCTXCORE) pHyperCoreR3;
|
---|
264 | /** Pointer to the current hypervisor core context - R0Ptr. */
|
---|
265 | R0PTRTYPE(PCPUMCTXCORE) pHyperCoreR0;
|
---|
266 | /** Pointer to the current hypervisor core context - RCPtr. */
|
---|
267 | RCPTRTYPE(PCPUMCTXCORE) pHyperCoreRC;
|
---|
268 |
|
---|
269 | /* Offset from CPUM to CPUMCPU for the first CPU. */
|
---|
270 | uint32_t ulOffCPUMCPU;
|
---|
271 |
|
---|
272 | /** Hidden selector registers state.
|
---|
273 | * Valid (hw accelerated raw mode) or not (normal raw mode)
|
---|
274 | */
|
---|
275 | uint32_t fValidHiddenSelRegs;
|
---|
276 |
|
---|
277 | /** Host CPU Features - ECX */
|
---|
278 | struct
|
---|
279 | {
|
---|
280 | /** edx part */
|
---|
281 | X86CPUIDFEATEDX edx;
|
---|
282 | /** ecx part */
|
---|
283 | X86CPUIDFEATECX ecx;
|
---|
284 | } CPUFeatures;
|
---|
285 | /** Host extended CPU features. */
|
---|
286 | struct
|
---|
287 | {
|
---|
288 | /** edx part */
|
---|
289 | uint32_t edx;
|
---|
290 | /** ecx part */
|
---|
291 | uint32_t ecx;
|
---|
292 | } CPUFeaturesExt;
|
---|
293 |
|
---|
294 | /* CPU manufacturer. */
|
---|
295 | CPUMCPUVENDOR enmCPUVendor;
|
---|
296 |
|
---|
297 | /** CR4 mask */
|
---|
298 | struct
|
---|
299 | {
|
---|
300 | uint32_t AndMask;
|
---|
301 | uint32_t OrMask;
|
---|
302 | } CR4;
|
---|
303 |
|
---|
304 | /** Have we entered rawmode? */
|
---|
305 | bool fRawEntered;
|
---|
306 | uint8_t abPadding[3 + (HC_ARCH_BITS == 64) * 4];
|
---|
307 |
|
---|
308 | /** The standard set of CpuId leafs. */
|
---|
309 | CPUMCPUID aGuestCpuIdStd[6];
|
---|
310 | /** The extended set of CpuId leafs. */
|
---|
311 | CPUMCPUID aGuestCpuIdExt[10];
|
---|
312 | /** The centaur set of CpuId leafs. */
|
---|
313 | CPUMCPUID aGuestCpuIdCentaur[4];
|
---|
314 | /** The default set of CpuId leafs. */
|
---|
315 | CPUMCPUID GuestCpuIdDef;
|
---|
316 |
|
---|
317 | /** Align the next member, and thereby the structure, on a 64-byte boundrary. */
|
---|
318 | uint8_t abPadding2[HC_ARCH_BITS == 32 ? 60 : 48];
|
---|
319 |
|
---|
320 | /**
|
---|
321 | * Guest context on raw mode entry.
|
---|
322 | * This a debug feature, see CPUMR3SaveEntryCtx.
|
---|
323 | */
|
---|
324 | CPUMCTX GuestEntry;
|
---|
325 | } CPUM;
|
---|
326 | /** Pointer to the CPUM instance data residing in the shared VM structure. */
|
---|
327 | typedef CPUM *PCPUM;
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * CPUM Data (part of VMCPU)
|
---|
331 | */
|
---|
332 | typedef struct CPUMCPU
|
---|
333 | {
|
---|
334 | /**
|
---|
335 | * Saved host context. Only valid while inside GC.
|
---|
336 | * Aligned on a 64-byte boundrary.
|
---|
337 | */
|
---|
338 | CPUMHOSTCTX Host;
|
---|
339 |
|
---|
340 | /**
|
---|
341 | * Guest context.
|
---|
342 | * Aligned on a 64-byte boundrary.
|
---|
343 | */
|
---|
344 | CPUMCTX Guest;
|
---|
345 |
|
---|
346 | /**
|
---|
347 | * Guest context - misc MSRs
|
---|
348 | * Aligned on a 64-byte boundrary.
|
---|
349 | */
|
---|
350 | CPUMCTXMSR GuestMsr;
|
---|
351 |
|
---|
352 | /** Use flags.
|
---|
353 | * These flags indicates both what is to be used and what has been used.
|
---|
354 | */
|
---|
355 | uint32_t fUseFlags;
|
---|
356 |
|
---|
357 | /** Changed flags.
|
---|
358 | * These flags indicates to REM (and others) which important guest
|
---|
359 | * registers which has been changed since last time the flags were cleared.
|
---|
360 | * See the CPUM_CHANGED_* defines for what we keep track of.
|
---|
361 | */
|
---|
362 | uint32_t fChanged;
|
---|
363 |
|
---|
364 | /* Offset to CPUM. (subtract from the pointer to get to CPUM) */
|
---|
365 | uint32_t ulOffCPUM;
|
---|
366 |
|
---|
367 | /* Temporary storage for the return code of the function called in the 32-64 switcher. */
|
---|
368 | uint32_t u32RetCode;
|
---|
369 |
|
---|
370 | /* Round to 16 byte size.
|
---|
371 | uint32_t uPadding;
|
---|
372 | */
|
---|
373 | } CPUMCPU, *PCPUMCPU;
|
---|
374 | /** Pointer to the CPUMCPU instance data residing in the shared VMCPU structure. */
|
---|
375 | typedef CPUMCPU *PCPUMCPU;
|
---|
376 |
|
---|
377 | __BEGIN_DECLS
|
---|
378 |
|
---|
379 | DECLASM(int) CPUMHandleLazyFPUAsm(PCPUMCPU pCPUM);
|
---|
380 |
|
---|
381 | #ifdef IN_RING0
|
---|
382 | DECLASM(int) CPUMR0SaveGuestRestoreHostFPUState(PCPUMCPU pCPUM);
|
---|
383 | DECLASM(int) CPUMR0RestoreHostFPUState(PCPUMCPU pCPUM);
|
---|
384 | DECLASM(void) CPUMR0LoadFPU(PCPUMCTX pCtx);
|
---|
385 | DECLASM(void) CPUMR0SaveFPU(PCPUMCTX pCtx);
|
---|
386 | DECLASM(void) CPUMR0LoadXMM(PCPUMCTX pCtx);
|
---|
387 | DECLASM(void) CPUMR0SaveXMM(PCPUMCTX pCtx);
|
---|
388 | DECLASM(void) CPUMR0SetFCW(uint16_t u16FCW);
|
---|
389 | DECLASM(uint16_t) CPUMR0GetFCW();
|
---|
390 | DECLASM(void) CPUMR0SetMXCSR(uint32_t u32MXCSR);
|
---|
391 | DECLASM(uint32_t) CPUMR0GetMXCSR();
|
---|
392 | #endif
|
---|
393 |
|
---|
394 | __END_DECLS
|
---|
395 |
|
---|
396 | /** @} */
|
---|
397 |
|
---|
398 | #endif
|
---|
399 |
|
---|