VirtualBox

source: vbox/trunk/include/VBox/vmm/cpumctx.h@ 72891

Last change on this file since 72891 was 72880, checked in by vboxsync, 6 years ago

VMMGuruMeditation: Try get externalized guest state.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.9 KB
Line 
1/** @file
2 * CPUM - CPU Monitor(/ Manager), Context Structures.
3 */
4
5/*
6 * Copyright (C) 2006-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_vmm_cpumctx_h
27#define ___VBox_vmm_cpumctx_h
28
29#ifndef VBOX_FOR_DTRACE_LIB
30# include <iprt/x86.h>
31# include <VBox/types.h>
32# include <VBox/vmm/hm_svm.h>
33#else
34# pragma D depends_on library x86.d
35#endif
36
37
38RT_C_DECLS_BEGIN
39
40/** @defgroup grp_cpum_ctx The CPUM Context Structures
41 * @ingroup grp_cpum
42 * @{
43 */
44
45/**
46 * Selector hidden registers.
47 */
48typedef struct CPUMSELREG
49{
50 /** The selector register. */
51 RTSEL Sel;
52 /** Padding, don't use. */
53 RTSEL PaddingSel;
54 /** The selector which info resides in u64Base, u32Limit and Attr, provided
55 * that CPUMSELREG_FLAGS_VALID is set. */
56 RTSEL ValidSel;
57 /** Flags, see CPUMSELREG_FLAGS_XXX. */
58 uint16_t fFlags;
59
60 /** Base register.
61 *
62 * Long mode remarks:
63 * - Unused in long mode for CS, DS, ES, SS
64 * - 32 bits for FS & GS; FS(GS)_BASE msr used for the base address
65 * - 64 bits for TR & LDTR
66 */
67 uint64_t u64Base;
68 /** Limit (expanded). */
69 uint32_t u32Limit;
70 /** Flags.
71 * This is the high 32-bit word of the descriptor entry.
72 * Only the flags, dpl and type are used. */
73 X86DESCATTR Attr;
74} CPUMSELREG;
75#ifndef VBOX_FOR_DTRACE_LIB
76AssertCompileSize(CPUMSELREG, 24);
77#endif
78
79/** @name CPUMSELREG_FLAGS_XXX - CPUMSELREG::fFlags values.
80 * @{ */
81#define CPUMSELREG_FLAGS_VALID UINT16_C(0x0001)
82#define CPUMSELREG_FLAGS_STALE UINT16_C(0x0002)
83#define CPUMSELREG_FLAGS_VALID_MASK UINT16_C(0x0003)
84/** @} */
85
86/** Checks if the hidden parts of the selector register are valid. */
87#ifdef VBOX_WITH_RAW_MODE_NOT_R0
88# define CPUMSELREG_ARE_HIDDEN_PARTS_VALID(a_pVCpu, a_pSelReg) \
89 ( ((a_pSelReg)->fFlags & CPUMSELREG_FLAGS_VALID) \
90 && ( (a_pSelReg)->ValidSel == (a_pSelReg)->Sel \
91 || ( (a_pVCpu) /*!= NULL*/ \
92 && (a_pSelReg)->ValidSel == ((a_pSelReg)->Sel & X86_SEL_MASK_OFF_RPL) \
93 && ((a_pSelReg)->Sel & X86_SEL_RPL) == 1 \
94 && ((a_pSelReg)->ValidSel & X86_SEL_RPL) == 0 \
95 && CPUMIsGuestInRawMode(a_pVCpu) \
96 ) \
97 ) \
98 )
99#else
100# define CPUMSELREG_ARE_HIDDEN_PARTS_VALID(a_pVCpu, a_pSelReg) \
101 ( ((a_pSelReg)->fFlags & CPUMSELREG_FLAGS_VALID) \
102 && (a_pSelReg)->ValidSel == (a_pSelReg)->Sel )
103#endif
104
105/** Old type used for the hidden register part.
106 * @deprecated */
107typedef CPUMSELREG CPUMSELREGHID;
108
109/**
110 * The sysenter register set.
111 */
112typedef struct CPUMSYSENTER
113{
114 /** Ring 0 cs.
115 * This value + 8 is the Ring 0 ss.
116 * This value + 16 is the Ring 3 cs.
117 * This value + 24 is the Ring 3 ss.
118 */
119 uint64_t cs;
120 /** Ring 0 eip. */
121 uint64_t eip;
122 /** Ring 0 esp. */
123 uint64_t esp;
124} CPUMSYSENTER;
125
126/** @def CPUM_UNION_NM
127 * For compilers (like DTrace) that does not grok nameless unions, we have a
128 * little hack to make them palatable.
129 */
130/** @def CPUM_STRUCT_NM
131 * For compilers (like DTrace) that does not grok nameless structs (it is
132 * non-standard C++), we have a little hack to make them palatable.
133 */
134#ifdef VBOX_FOR_DTRACE_LIB
135# define CPUM_UNION_NM(a_Nm) a_Nm
136# define CPUM_STRUCT_NM(a_Nm) a_Nm
137#elif defined(IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS)
138# define CPUM_UNION_NM(a_Nm) a_Nm
139# define CPUM_STRUCT_NM(a_Nm) a_Nm
140#else
141# define CPUM_UNION_NM(a_Nm)
142# define CPUM_STRUCT_NM(a_Nm)
143#endif
144/** @def CPUM_UNION_STRUCT_NM
145 * Combines CPUM_UNION_NM and CPUM_STRUCT_NM to avoid hitting the right side of
146 * the screen in the compile time assertions.
147 */
148#define CPUM_UNION_STRUCT_NM(a_UnionNm, a_StructNm) CPUM_UNION_NM(a_UnionNm .) CPUM_STRUCT_NM(a_StructNm)
149
150/** A general register (union). */
151typedef union CPUMCTXGREG
152{
153 /** Natural unsigned integer view. */
154 uint64_t u;
155 /** 64-bit view. */
156 uint64_t u64;
157 /** 32-bit view. */
158 uint32_t u32;
159 /** 16-bit view. */
160 uint16_t u16;
161 /** 8-bit view. */
162 uint8_t u8;
163 /** 8-bit low/high view. */
164 RT_GCC_EXTENSION struct
165 {
166 /** Low byte (al, cl, dl, bl, ++). */
167 uint8_t bLo;
168 /** High byte in the first word - ah, ch, dh, bh. */
169 uint8_t bHi;
170 } CPUM_STRUCT_NM(s);
171} CPUMCTXGREG;
172#ifndef VBOX_FOR_DTRACE_LIB
173AssertCompileSize(CPUMCTXGREG, 8);
174AssertCompileMemberOffset(CPUMCTXGREG, CPUM_STRUCT_NM(s.) bLo, 0);
175AssertCompileMemberOffset(CPUMCTXGREG, CPUM_STRUCT_NM(s.) bHi, 1);
176#endif
177
178
179
180/**
181 * CPU context core.
182 *
183 * @todo Eliminate this structure!
184 * @deprecated We don't push any context cores any more in TRPM.
185 */
186#pragma pack(1)
187typedef struct CPUMCTXCORE
188{
189 /** @name General Register.
190 * @note These follow the encoding order (X86_GREG_XXX) and can be accessed as
191 * an array starting a rax.
192 * @{ */
193 union
194 {
195 uint8_t al;
196 uint16_t ax;
197 uint32_t eax;
198 uint64_t rax;
199 } CPUM_UNION_NM(rax);
200 union
201 {
202 uint8_t cl;
203 uint16_t cx;
204 uint32_t ecx;
205 uint64_t rcx;
206 } CPUM_UNION_NM(rcx);
207 union
208 {
209 uint8_t dl;
210 uint16_t dx;
211 uint32_t edx;
212 uint64_t rdx;
213 } CPUM_UNION_NM(rdx);
214 union
215 {
216 uint8_t bl;
217 uint16_t bx;
218 uint32_t ebx;
219 uint64_t rbx;
220 } CPUM_UNION_NM(rbx);
221 union
222 {
223 uint16_t sp;
224 uint32_t esp;
225 uint64_t rsp;
226 } CPUM_UNION_NM(rsp);
227 union
228 {
229 uint16_t bp;
230 uint32_t ebp;
231 uint64_t rbp;
232 } CPUM_UNION_NM(rbp);
233 union
234 {
235 uint8_t sil;
236 uint16_t si;
237 uint32_t esi;
238 uint64_t rsi;
239 } CPUM_UNION_NM(rsi);
240 union
241 {
242 uint8_t dil;
243 uint16_t di;
244 uint32_t edi;
245 uint64_t rdi;
246 } CPUM_UNION_NM(rdi);
247 uint64_t r8;
248 uint64_t r9;
249 uint64_t r10;
250 uint64_t r11;
251 uint64_t r12;
252 uint64_t r13;
253 uint64_t r14;
254 uint64_t r15;
255 /** @} */
256
257 /** @name Segment registers.
258 * @note These follow the encoding order (X86_SREG_XXX) and can be accessed as
259 * an array starting a es.
260 * @{ */
261 CPUMSELREG es;
262 CPUMSELREG cs;
263 CPUMSELREG ss;
264 CPUMSELREG ds;
265 CPUMSELREG fs;
266 CPUMSELREG gs;
267 /** @} */
268
269 /** The program counter. */
270 union
271 {
272 uint16_t ip;
273 uint32_t eip;
274 uint64_t rip;
275 } CPUM_UNION_NM(rip);
276
277 /** The flags register. */
278 union
279 {
280 X86EFLAGS eflags;
281 X86RFLAGS rflags;
282 } CPUM_UNION_NM(rflags);
283
284} CPUMCTXCORE;
285#pragma pack()
286
287
288/**
289 * SVM Host-state area (Nested Hw.virt - VirtualBox's layout).
290 *
291 * @warning Exercise caution while modifying the layout of this struct. It's
292 * part of VM saved states.
293 */
294#pragma pack(1)
295typedef struct SVMHOSTSTATE
296{
297 uint64_t uEferMsr;
298 uint64_t uCr0;
299 uint64_t uCr4;
300 uint64_t uCr3;
301 uint64_t uRip;
302 uint64_t uRsp;
303 uint64_t uRax;
304 X86RFLAGS rflags;
305 CPUMSELREG es;
306 CPUMSELREG cs;
307 CPUMSELREG ss;
308 CPUMSELREG ds;
309 VBOXGDTR gdtr;
310 VBOXIDTR idtr;
311 uint8_t abPadding[4];
312} SVMHOSTSTATE;
313#pragma pack()
314/** Pointer to the SVMHOSTSTATE structure. */
315typedef SVMHOSTSTATE *PSVMHOSTSTATE;
316/** Pointer to a const SVMHOSTSTATE structure. */
317typedef const SVMHOSTSTATE *PCSVMHOSTSTATE;
318#ifndef VBOX_FOR_DTRACE_LIB
319AssertCompileSizeAlignment(SVMHOSTSTATE, 8);
320AssertCompileSize(SVMHOSTSTATE, 184);
321#endif
322
323
324/**
325 * CPU context.
326 */
327#pragma pack(1) /* for VBOXIDTR / VBOXGDTR. */
328typedef struct CPUMCTX
329{
330 /** CPUMCTXCORE Part.
331 * @{ */
332
333 /** General purpose registers. */
334 union /* no tag! */
335 {
336 /** The general purpose register array view, indexed by X86_GREG_XXX. */
337 CPUMCTXGREG aGRegs[16];
338
339 /** 64-bit general purpose register view. */
340 RT_GCC_EXTENSION struct /* no tag! */
341 {
342 uint64_t rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15;
343 } CPUM_STRUCT_NM(qw);
344 /** 64-bit general purpose register view. */
345 RT_GCC_EXTENSION struct /* no tag! */
346 {
347 uint64_t r0, r1, r2, r3, r4, r5, r6, r7;
348 } CPUM_STRUCT_NM(qw2);
349 /** 32-bit general purpose register view. */
350 RT_GCC_EXTENSION struct /* no tag! */
351 {
352 uint32_t eax, u32Pad00, ecx, u32Pad01, edx, u32Pad02, ebx, u32Pad03,
353 esp, u32Pad04, ebp, u32Pad05, esi, u32Pad06, edi, u32Pad07,
354 r8d, u32Pad08, r9d, u32Pad09, r10d, u32Pad10, r11d, u32Pad11,
355 r12d, u32Pad12, r13d, u32Pad13, r14d, u32Pad14, r15d, u32Pad15;
356 } CPUM_STRUCT_NM(dw);
357 /** 16-bit general purpose register view. */
358 RT_GCC_EXTENSION struct /* no tag! */
359 {
360 uint16_t ax, au16Pad00[3], cx, au16Pad01[3], dx, au16Pad02[3], bx, au16Pad03[3],
361 sp, au16Pad04[3], bp, au16Pad05[3], si, au16Pad06[3], di, au16Pad07[3],
362 r8w, au16Pad08[3], r9w, au16Pad09[3], r10w, au16Pad10[3], r11w, au16Pad11[3],
363 r12w, au16Pad12[3], r13w, au16Pad13[3], r14w, au16Pad14[3], r15w, au16Pad15[3];
364 } CPUM_STRUCT_NM(w);
365 RT_GCC_EXTENSION struct /* no tag! */
366 {
367 uint8_t al, ah, abPad00[6], cl, ch, abPad01[6], dl, dh, abPad02[6], bl, bh, abPad03[6],
368 spl, abPad04[7], bpl, abPad05[7], sil, abPad06[7], dil, abPad07[7],
369 r8l, abPad08[7], r9l, abPad09[7], r10l, abPad10[7], r11l, abPad11[7],
370 r12l, abPad12[7], r13l, abPad13[7], r14l, abPad14[7], r15l, abPad15[7];
371 } CPUM_STRUCT_NM(b);
372 } CPUM_UNION_NM(g);
373
374 /** Segment registers. */
375 union /* no tag! */
376 {
377 /** The segment register array view, indexed by X86_SREG_XXX. */
378 CPUMSELREG aSRegs[6];
379 /** The named segment register view. */
380 RT_GCC_EXTENSION struct /* no tag! */
381 {
382 CPUMSELREG es, cs, ss, ds, fs, gs;
383 } CPUM_STRUCT_NM(n);
384 } CPUM_UNION_NM(s);
385
386 /** The program counter. */
387 union
388 {
389 uint16_t ip;
390 uint32_t eip;
391 uint64_t rip;
392 } CPUM_UNION_NM(rip);
393
394 /** The flags register. */
395 union
396 {
397 X86EFLAGS eflags;
398 X86RFLAGS rflags;
399 } CPUM_UNION_NM(rflags);
400
401 /** @} */ /*(CPUMCTXCORE)*/
402
403
404 /** @name Control registers.
405 * @{ */
406 uint64_t cr0;
407 uint64_t cr2;
408 uint64_t cr3;
409 uint64_t cr4;
410 /** @} */
411
412 /** Debug registers.
413 * @remarks DR4 and DR5 should not be used since they are aliases for
414 * DR6 and DR7 respectively on both AMD and Intel CPUs.
415 * @remarks DR8-15 are currently not supported by AMD or Intel, so
416 * neither do we.
417 */
418 uint64_t dr[8];
419
420 /** Padding before the structure so the 64-bit member is correctly aligned.
421 * @todo fix this structure! */
422 uint16_t gdtrPadding[3];
423 /** Global Descriptor Table register. */
424 VBOXGDTR gdtr;
425
426 /** Padding before the structure so the 64-bit member is correctly aligned.
427 * @todo fix this structure! */
428 uint16_t idtrPadding[3];
429 /** Interrupt Descriptor Table register. */
430 VBOXIDTR idtr;
431
432 /** The task register.
433 * Only the guest context uses all the members. */
434 CPUMSELREG ldtr;
435 /** The task register.
436 * Only the guest context uses all the members. */
437 CPUMSELREG tr;
438
439 /** The sysenter msr registers.
440 * This member is not used by the hypervisor context. */
441 CPUMSYSENTER SysEnter;
442
443 /** @name System MSRs.
444 * @{ */
445 uint64_t msrEFER;
446 uint64_t msrSTAR; /**< Legacy syscall eip, cs & ss. */
447 uint64_t msrPAT; /**< Page attribute table. */
448 uint64_t msrLSTAR; /**< 64 bits mode syscall rip. */
449 uint64_t msrCSTAR; /**< Compatibility mode syscall rip. */
450 uint64_t msrSFMASK; /**< syscall flag mask. */
451 uint64_t msrKERNELGSBASE; /**< swapgs exchange value. */
452 uint64_t uMsrPadding0; /**< no longer used (used to hold a copy of APIC base MSR). */
453 /** @} */
454
455 /** The XCR0..XCR1 registers. */
456 uint64_t aXcr[2];
457 /** The mask to pass to XSAVE/XRSTOR in EDX:EAX. If zero we use
458 * FXSAVE/FXRSTOR (since bit 0 will always be set, we only need to test it). */
459 uint64_t fXStateMask;
460
461 /** Pointer to the FPU/SSE/AVX/XXXX state ring-0 mapping. */
462 R0PTRTYPE(PX86XSAVEAREA) pXStateR0;
463#if HC_ARCH_BITS == 32
464 uint32_t uXStateR0Padding;
465#endif
466 /** Pointer to the FPU/SSE/AVX/XXXX state ring-3 mapping. */
467 R3PTRTYPE(PX86XSAVEAREA) pXStateR3;
468#if HC_ARCH_BITS == 32
469 uint32_t uXStateR3Padding;
470#endif
471 /** Pointer to the FPU/SSE/AVX/XXXX state raw-mode mapping. */
472 RCPTRTYPE(PX86XSAVEAREA) pXStateRC;
473 /** State component offsets into pXState, UINT16_MAX if not present. */
474 uint16_t aoffXState[64];
475
476 /** 0x2d4 - World switcher flags, CPUMCTX_WSF_XXX. */
477 uint32_t fWorldSwitcher;
478 /** 0x2d8 - Externalized state tracker, CPUMCTX_EXTRN_XXX.
479 * Currently only used internally in NEM/win. */
480 uint64_t fExtrn;
481
482 /** 0x2e0 - Hardware virtualization state. */
483 struct
484 {
485 union /* no tag! */
486 {
487 struct
488 {
489 /** 0x2e0 - MSR holding physical address of the Guest's Host-state. */
490 uint64_t uMsrHSavePa;
491 /** 0x2e8 - Guest physical address of the nested-guest VMCB. */
492 RTGCPHYS GCPhysVmcb;
493 /** 0x2f0 - Cache of the nested-guest VMCB - R0 ptr. */
494 R0PTRTYPE(PSVMVMCB) pVmcbR0;
495#if HC_ARCH_BITS == 32
496 uint32_t uVmcbR0Padding;
497#endif
498 /** 0x2f8 - Cache of the nested-guest VMCB - R3 ptr. */
499 R3PTRTYPE(PSVMVMCB) pVmcbR3;
500#if HC_ARCH_BITS == 32
501 uint32_t uVmcbR3Padding;
502#endif
503 /** 0x300 - Guest's host-state save area. */
504 SVMHOSTSTATE HostState;
505 /** 0x3b8 - Guest TSC time-stamp of when the previous PAUSE instr. was executed. */
506 uint64_t uPrevPauseTick;
507 /** 0x3c0 - Pause filter count. */
508 uint16_t cPauseFilter;
509 /** 0x3c2 - Pause filter threshold. */
510 uint16_t cPauseFilterThreshold;
511 /** 0x3c4 - Whether the injected event is subject to event intercepts. */
512 bool fInterceptEvents;
513 /** 0x3c5 - Padding. */
514 bool afPadding[3];
515 /** 0x3c8 - MSR permission bitmap - R0 ptr. */
516 R0PTRTYPE(void *) pvMsrBitmapR0;
517#if HC_ARCH_BITS == 32
518 uint32_t uvMsrBitmapR0Padding;
519#endif
520 /** 0x3d0 - MSR permission bitmap - R3 ptr. */
521 R3PTRTYPE(void *) pvMsrBitmapR3;
522#if HC_ARCH_BITS == 32
523 uint32_t uvMsrBitmapR3Padding;
524#endif
525 /** 0x3d8 - IO permission bitmap - R0 ptr. */
526 R0PTRTYPE(void *) pvIoBitmapR0;
527#if HC_ARCH_BITS == 32
528 uint32_t uIoBitmapR0Padding;
529#endif
530 /** 0x3e0 - IO permission bitmap - R3 ptr. */
531 R3PTRTYPE(void *) pvIoBitmapR3;
532#if HC_ARCH_BITS == 32
533 uint32_t uIoBitmapR3Padding;
534#endif
535 /** 0x3e8 - Host physical address of the nested-guest VMCB. */
536 RTHCPHYS HCPhysVmcb;
537 } svm;
538#if 0
539 struct
540 {
541 } vmx;
542#endif
543 } CPUM_UNION_NM(s);
544
545 /** 0x3f0 - A subset of force flags that are preserved while running the nested-guest. */
546 uint32_t fLocalForcedActions;
547 /** 0x3f4 - Global interrupt flag (always true on nested VMX). */
548 bool fGif;
549 /** 0x3f5 - Padding. */
550 uint8_t abPadding1[11];
551 } hwvirt;
552 /** @} */
553} CPUMCTX;
554#pragma pack()
555
556#ifndef VBOX_FOR_DTRACE_LIB
557AssertCompileSizeAlignment(CPUMCTX, 64);
558AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) rax, 0);
559AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) rcx, 8);
560AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) rdx, 16);
561AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) rbx, 24);
562AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) rsp, 32);
563AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) rbp, 40);
564AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) rsi, 48);
565AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) rdi, 56);
566AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) r8, 64);
567AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) r9, 72);
568AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) r10, 80);
569AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) r11, 88);
570AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) r12, 96);
571AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) r13, 104);
572AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) r14, 112);
573AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(g.) CPUM_STRUCT_NM(qw.) r15, 120);
574AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(s.) CPUM_STRUCT_NM(n.) es, 128);
575AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(s.) CPUM_STRUCT_NM(n.) cs, 152);
576AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(s.) CPUM_STRUCT_NM(n.) ss, 176);
577AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(s.) CPUM_STRUCT_NM(n.) ds, 200);
578AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(s.) CPUM_STRUCT_NM(n.) fs, 224);
579AssertCompileMemberOffset(CPUMCTX, CPUM_UNION_NM(s.) CPUM_STRUCT_NM(n.) gs, 248);
580AssertCompileMemberOffset(CPUMCTX, rip, 272);
581AssertCompileMemberOffset(CPUMCTX, rflags, 280);
582AssertCompileMemberOffset(CPUMCTX, cr0, 288);
583AssertCompileMemberOffset(CPUMCTX, cr2, 296);
584AssertCompileMemberOffset(CPUMCTX, cr3, 304);
585AssertCompileMemberOffset(CPUMCTX, cr4, 312);
586AssertCompileMemberOffset(CPUMCTX, dr, 320);
587AssertCompileMemberOffset(CPUMCTX, gdtr, 384+6);
588AssertCompileMemberOffset(CPUMCTX, idtr, 400+6);
589AssertCompileMemberOffset(CPUMCTX, ldtr, 416);
590AssertCompileMemberOffset(CPUMCTX, tr, 440);
591AssertCompileMemberOffset(CPUMCTX, SysEnter, 464);
592AssertCompileMemberOffset(CPUMCTX, msrEFER, 488);
593AssertCompileMemberOffset(CPUMCTX, msrSTAR, 496);
594AssertCompileMemberOffset(CPUMCTX, msrPAT, 504);
595AssertCompileMemberOffset(CPUMCTX, msrLSTAR, 512);
596AssertCompileMemberOffset(CPUMCTX, msrCSTAR, 520);
597AssertCompileMemberOffset(CPUMCTX, msrSFMASK, 528);
598AssertCompileMemberOffset(CPUMCTX, msrKERNELGSBASE, 536);
599AssertCompileMemberOffset(CPUMCTX, aXcr, 552);
600AssertCompileMemberOffset(CPUMCTX, fXStateMask, 568);
601AssertCompileMemberOffset(CPUMCTX, pXStateR0, 576);
602AssertCompileMemberOffset(CPUMCTX, pXStateR3, 584);
603AssertCompileMemberOffset(CPUMCTX, pXStateRC, 592);
604AssertCompileMemberOffset(CPUMCTX, aoffXState, 596);
605AssertCompileMemberOffset(CPUMCTX, hwvirt, 0x2e0);
606AssertCompileMemberOffset(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.uMsrHSavePa, 0x2e0);
607AssertCompileMemberOffset(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.pVmcbR0, 0x2f0);
608AssertCompileMemberOffset(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.pVmcbR3, 0x2f8);
609AssertCompileMemberOffset(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.HostState, 0x300);
610AssertCompileMemberOffset(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.cPauseFilter, 0x3c0);
611AssertCompileMemberOffset(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.pvMsrBitmapR0, 0x3c8);
612AssertCompileMemberOffset(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.pvIoBitmapR3, 0x3e0);
613AssertCompileMemberOffset(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.HCPhysVmcb, 0x3e8);
614AssertCompileMemberOffset(CPUMCTX, hwvirt.fLocalForcedActions, 0x3f0);
615AssertCompileMemberAlignment(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.pVmcbR0, 8);
616AssertCompileMemberAlignment(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.pvMsrBitmapR0, 8);
617AssertCompileMemberAlignment(CPUMCTX, hwvirt.CPUM_UNION_NM(s.) svm.pvIoBitmapR0, 8);
618
619AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rax, CPUMCTX, CPUM_UNION_NM(g.) aGRegs);
620AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rax, CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw2.) r0);
621AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rcx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw2.) r1);
622AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw2.) r2);
623AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw2.) r3);
624AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsp, CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw2.) r4);
625AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbp, CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw2.) r5);
626AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsi, CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw2.) r6);
627AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdi, CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw2.) r7);
628AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rax, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) eax);
629AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rcx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) ecx);
630AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) edx);
631AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) ebx);
632AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsp, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) esp);
633AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbp, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) ebp);
634AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsi, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) esi);
635AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdi, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) edi);
636AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r8, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) r8d);
637AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r9, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) r9d);
638AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r10, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) r10d);
639AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r11, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) r11d);
640AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r12, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) r12d);
641AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r13, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) r13d);
642AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r14, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) r14d);
643AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r15, CPUMCTX, CPUM_UNION_STRUCT_NM(g,dw.) r15d);
644AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rax, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) ax);
645AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rcx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) cx);
646AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) dx);
647AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) bx);
648AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsp, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) sp);
649AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbp, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) bp);
650AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsi, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) si);
651AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdi, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) di);
652AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r8, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) r8w);
653AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r9, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) r9w);
654AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r10, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) r10w);
655AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r11, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) r11w);
656AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r12, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) r12w);
657AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r13, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) r13w);
658AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r14, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) r14w);
659AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r15, CPUMCTX, CPUM_UNION_STRUCT_NM(g,w.) r15w);
660AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rax, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) al);
661AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rcx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) cl);
662AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) dl);
663AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbx, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) bl);
664AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsp, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) spl);
665AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbp, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) bpl);
666AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsi, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) sil);
667AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdi, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) dil);
668AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r8, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) r8l);
669AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r9, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) r9l);
670AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r10, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) r10l);
671AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r11, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) r11l);
672AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r12, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) r12l);
673AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r13, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) r13l);
674AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r14, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) r14l);
675AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r15, CPUMCTX, CPUM_UNION_STRUCT_NM(g,b.) r15l);
676AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_NM(s.) CPUM_STRUCT_NM(n.) es, CPUMCTX, CPUM_UNION_NM(s.) aSRegs);
677# ifndef _MSC_VER
678AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rax, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_xAX]);
679AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rcx, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_xCX]);
680AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdx, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_xDX]);
681AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbx, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_xBX]);
682AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsp, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_xSP]);
683AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rbp, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_xBP]);
684AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rsi, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_xSI]);
685AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) rdi, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_xDI]);
686AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r8, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_x8]);
687AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r9, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_x9]);
688AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r10, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_x10]);
689AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r11, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_x11]);
690AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r12, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_x12]);
691AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r13, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_x13]);
692AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r14, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_x14]);
693AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(g,qw.) r15, CPUMCTX, CPUM_UNION_NM(g.) aGRegs[X86_GREG_x15]);
694AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(s,n.) es, CPUMCTX, CPUM_UNION_NM(s.) aSRegs[X86_SREG_ES]);
695AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(s,n.) cs, CPUMCTX, CPUM_UNION_NM(s.) aSRegs[X86_SREG_CS]);
696AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(s,n.) ss, CPUMCTX, CPUM_UNION_NM(s.) aSRegs[X86_SREG_SS]);
697AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(s,n.) ds, CPUMCTX, CPUM_UNION_NM(s.) aSRegs[X86_SREG_DS]);
698AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(s,n.) fs, CPUMCTX, CPUM_UNION_NM(s.) aSRegs[X86_SREG_FS]);
699AssertCompileMembersAtSameOffset(CPUMCTX, CPUM_UNION_STRUCT_NM(s,n.) gs, CPUMCTX, CPUM_UNION_NM(s.) aSRegs[X86_SREG_GS]);
700# endif
701
702/**
703 * Calculates the pointer to the given extended state component.
704 *
705 * @returns Pointer of type @a a_PtrType
706 * @param a_pCtx Pointer to the context.
707 * @param a_iCompBit The extended state component bit number. This bit
708 * must be set in CPUMCTX::fXStateMask.
709 * @param a_PtrType The pointer type of the extended state component.
710 *
711 */
712#if defined(VBOX_STRICT) && defined(RT_COMPILER_SUPPORTS_LAMBDA)
713# define CPUMCTX_XSAVE_C_PTR(a_pCtx, a_iCompBit, a_PtrType) \
714 ([](PCCPUMCTX a_pLambdaCtx) -> a_PtrType \
715 { \
716 AssertCompile((a_iCompBit) < 64U); \
717 AssertMsg(a_pLambdaCtx->fXStateMask & RT_BIT_64(a_iCompBit), (#a_iCompBit "\n")); \
718 AssertMsg(a_pLambdaCtx->aoffXState[(a_iCompBit)] != UINT16_MAX, (#a_iCompBit "\n")); \
719 return (a_PtrType)((uint8_t *)a_pLambdaCtx->CTX_SUFF(pXState) + a_pLambdaCtx->aoffXState[(a_iCompBit)]); \
720 }(a_pCtx))
721#elif defined(VBOX_STRICT) && defined(__GNUC__)
722# define CPUMCTX_XSAVE_C_PTR(a_pCtx, a_iCompBit, a_PtrType) \
723 __extension__ (\
724 { \
725 AssertCompile((a_iCompBit) < 64U); \
726 AssertMsg((a_pCtx)->fXStateMask & RT_BIT_64(a_iCompBit), (#a_iCompBit "\n")); \
727 AssertMsg((a_pCtx)->aoffXState[(a_iCompBit)] != UINT16_MAX, (#a_iCompBit "\n")); \
728 (a_PtrType)((uint8_t *)(a_pCtx)->CTX_SUFF(pXState) + (a_pCtx)->aoffXState[(a_iCompBit)]); \
729 })
730#else
731# define CPUMCTX_XSAVE_C_PTR(a_pCtx, a_iCompBit, a_PtrType) \
732 ((a_PtrType)((uint8_t *)(a_pCtx)->CTX_SUFF(pXState) + (a_pCtx)->aoffXState[(a_iCompBit)]))
733#endif
734
735/**
736 * Gets the CPUMCTXCORE part of a CPUMCTX.
737 */
738# define CPUMCTX2CORE(pCtx) ((PCPUMCTXCORE)(void *)&(pCtx)->rax)
739
740/**
741 * Gets the CPUMCTX part from a CPUMCTXCORE.
742 */
743# define CPUMCTX_FROM_CORE(a_pCtxCore) RT_FROM_MEMBER(a_pCtxCore, CPUMCTX, rax)
744
745/**
746 * Gets the first selector register of a CPUMCTX.
747 *
748 * Use this with X86_SREG_COUNT to loop thru the selector registers.
749 */
750# define CPUMCTX_FIRST_SREG(a_pCtx) (&(a_pCtx)->es)
751
752#endif /* !VBOX_FOR_DTRACE_LIB */
753
754
755/** @name CPUMCTX_WSF_XXX
756 * @{ */
757/** Touch IA32_PRED_CMD.IBPB on VM exit. */
758#define CPUMCTX_WSF_IBPB_EXIT RT_BIT_32(0)
759/** Touch IA32_PRED_CMD.IBPB on VM entry. */
760#define CPUMCTX_WSF_IBPB_ENTRY RT_BIT_32(1)
761/** @} */
762
763/** @name CPUMCTX_EXTRN_XXX
764 * Used for parts of the CPUM state that is externalized and needs fetching
765 * before use.
766 *
767 * @{ */
768/** External state keeper: Invalid. */
769#define CPUMCTX_EXTRN_KEEPER_INVALID UINT64_C(0x0000000000000000)
770/** External state keeper: HM. */
771#define CPUMCTX_EXTRN_KEEPER_HM UINT64_C(0x0000000000000001)
772/** External state keeper: NEM. */
773#define CPUMCTX_EXTRN_KEEPER_NEM UINT64_C(0x0000000000000002)
774/** External state keeper: REM. */
775#define CPUMCTX_EXTRN_KEEPER_REM UINT64_C(0x0000000000000003)
776/** External state keeper mask. */
777#define CPUMCTX_EXTRN_KEEPER_MASK UINT64_C(0x0000000000000003)
778
779/** The RIP register value is kept externally. */
780#define CPUMCTX_EXTRN_RIP UINT64_C(0x0000000000000004)
781/** The RFLAGS register values are kept externally. */
782#define CPUMCTX_EXTRN_RFLAGS UINT64_C(0x0000000000000008)
783
784/** The RAX register value is kept externally. */
785#define CPUMCTX_EXTRN_RAX UINT64_C(0x0000000000000010)
786/** The RCX register value is kept externally. */
787#define CPUMCTX_EXTRN_RCX UINT64_C(0x0000000000000020)
788/** The RDX register value is kept externally. */
789#define CPUMCTX_EXTRN_RDX UINT64_C(0x0000000000000040)
790/** The RBX register value is kept externally. */
791#define CPUMCTX_EXTRN_RBX UINT64_C(0x0000000000000080)
792/** The RSP register value is kept externally. */
793#define CPUMCTX_EXTRN_RSP UINT64_C(0x0000000000000100)
794/** The RBP register value is kept externally. */
795#define CPUMCTX_EXTRN_RBP UINT64_C(0x0000000000000200)
796/** The RSI register value is kept externally. */
797#define CPUMCTX_EXTRN_RSI UINT64_C(0x0000000000000400)
798/** The RDI register value is kept externally. */
799#define CPUMCTX_EXTRN_RDI UINT64_C(0x0000000000000800)
800/** The R8 thru R15 register values are kept externally. */
801#define CPUMCTX_EXTRN_R8_R15 UINT64_C(0x0000000000001000)
802/** General purpose registers mask. */
803#define CPUMCTX_EXTRN_GPRS_MASK UINT64_C(0x0000000000001ff0)
804
805/** The ES register values are kept externally. */
806#define CPUMCTX_EXTRN_ES UINT64_C(0x0000000000002000)
807/** The CS register values are kept externally. */
808#define CPUMCTX_EXTRN_CS UINT64_C(0x0000000000004000)
809/** The SS register values are kept externally. */
810#define CPUMCTX_EXTRN_SS UINT64_C(0x0000000000008000)
811/** The DS register values are kept externally. */
812#define CPUMCTX_EXTRN_DS UINT64_C(0x0000000000010000)
813/** The FS register values are kept externally. */
814#define CPUMCTX_EXTRN_FS UINT64_C(0x0000000000020000)
815/** The GS register values are kept externally. */
816#define CPUMCTX_EXTRN_GS UINT64_C(0x0000000000040000)
817/** Segment registers (includes CS). */
818#define CPUMCTX_EXTRN_SREG_MASK UINT64_C(0x000000000007e000)
819/** Converts a X86_XREG_XXX index to a CPUMCTX_EXTRN_xS mask. */
820#define CPUMCTX_EXTRN_SREG_FROM_IDX(a_SRegIdx) RT_BIT_64((a_SRegIdx) + 13)
821#ifndef VBOX_FOR_DTRACE_LIB
822AssertCompile(CPUMCTX_EXTRN_SREG_FROM_IDX(X86_SREG_ES) == CPUMCTX_EXTRN_ES);
823AssertCompile(CPUMCTX_EXTRN_SREG_FROM_IDX(X86_SREG_CS) == CPUMCTX_EXTRN_CS);
824AssertCompile(CPUMCTX_EXTRN_SREG_FROM_IDX(X86_SREG_DS) == CPUMCTX_EXTRN_DS);
825AssertCompile(CPUMCTX_EXTRN_SREG_FROM_IDX(X86_SREG_FS) == CPUMCTX_EXTRN_FS);
826AssertCompile(CPUMCTX_EXTRN_SREG_FROM_IDX(X86_SREG_GS) == CPUMCTX_EXTRN_GS);
827#endif
828
829/** The GDTR register values are kept externally. */
830#define CPUMCTX_EXTRN_GDTR UINT64_C(0x0000000000080000)
831/** The IDTR register values are kept externally. */
832#define CPUMCTX_EXTRN_IDTR UINT64_C(0x0000000000100000)
833/** The LDTR register values are kept externally. */
834#define CPUMCTX_EXTRN_LDTR UINT64_C(0x0000000000200000)
835/** The TR register values are kept externally. */
836#define CPUMCTX_EXTRN_TR UINT64_C(0x0000000000400000)
837/** Table register mask. */
838#define CPUMCTX_EXTRN_TABLE_MASK UINT64_C(0x0000000000780000)
839
840/** The CR0 register value is kept externally. */
841#define CPUMCTX_EXTRN_CR0 UINT64_C(0x0000000000800000)
842/** The CR2 register value is kept externally. */
843#define CPUMCTX_EXTRN_CR2 UINT64_C(0x0000000001000000)
844/** The CR3 register value is kept externally. */
845#define CPUMCTX_EXTRN_CR3 UINT64_C(0x0000000002000000)
846/** The CR4 register value is kept externally. */
847#define CPUMCTX_EXTRN_CR4 UINT64_C(0x0000000004000000)
848/** Control register mask. */
849#define CPUMCTX_EXTRN_CR_MASK UINT64_C(0x0000000007800000)
850/** The TPR/CR8 register value is kept externally. */
851#define CPUMCTX_EXTRN_APIC_TPR UINT64_C(0x0000000008000000)
852/** The EFER register value is kept externally. */
853#define CPUMCTX_EXTRN_EFER UINT64_C(0x0000000010000000)
854
855/** The DR0, DR1, DR2 and DR3 register values are kept externally. */
856#define CPUMCTX_EXTRN_DR0_DR3 UINT64_C(0x0000000020000000)
857/** The DR6 register value is kept externally. */
858#define CPUMCTX_EXTRN_DR6 UINT64_C(0x0000000040000000)
859/** The DR7 register value is kept externally. */
860#define CPUMCTX_EXTRN_DR7 UINT64_C(0x0000000080000000)
861/** Debug register mask. */
862#define CPUMCTX_EXTRN_DR_MASK UINT64_C(0x00000000e0000000)
863
864/** The XSAVE_C_X87 state is kept externally. */
865#define CPUMCTX_EXTRN_X87 UINT64_C(0x0000000100000000)
866/** The XSAVE_C_SSE, XSAVE_C_YMM, XSAVE_C_ZMM_HI256, XSAVE_C_ZMM_16HI and
867 * XSAVE_C_OPMASK state is kept externally. */
868#define CPUMCTX_EXTRN_SSE_AVX UINT64_C(0x0000000200000000)
869/** The state of XSAVE components not covered by CPUMCTX_EXTRN_X87 and
870 * CPUMCTX_EXTRN_SEE_AVX is kept externally. */
871#define CPUMCTX_EXTRN_OTHER_XSAVE UINT64_C(0x0000000400000000)
872/** The state of XCR0 and XCR1 register values are kept externally. */
873#define CPUMCTX_EXTRN_XCRx UINT64_C(0x0000000800000000)
874
875
876/** The KERNEL GS BASE MSR value is kept externally. */
877#define CPUMCTX_EXTRN_KERNEL_GS_BASE UINT64_C(0x0000001000000000)
878/** The STAR, LSTAR, CSTAR and SFMASK MSR values are kept externally. */
879#define CPUMCTX_EXTRN_SYSCALL_MSRS UINT64_C(0x0000002000000000)
880/** The SYSENTER_CS, SYSENTER_EIP and SYSENTER_ESP MSR values are kept externally. */
881#define CPUMCTX_EXTRN_SYSENTER_MSRS UINT64_C(0x0000004000000000)
882/** The TSC_AUX MSR is kept externally. */
883#define CPUMCTX_EXTRN_TSC_AUX UINT64_C(0x0000008000000000)
884/** All other stateful MSRs not covered by CPUMCTX_EXTRN_EFER,
885 * CPUMCTX_EXTRN_KERNEL_GS_BASE, CPUMCTX_EXTRN_SYSCALL_MSRS,
886 * CPUMCTX_EXTRN_SYSENTER_MSRS, and CPUMCTX_EXTRN_TSC_AUX. */
887#define CPUMCTX_EXTRN_OTHER_MSRS UINT64_C(0x0000010000000000)
888
889/** Mask of all the MSRs. */
890#define CPUMCTX_EXTRN_ALL_MSRS ( CPUMCTX_EXTRN_EFER | CPUMCTX_EXTRN_KERNEL_GS_BASE | CPUMCTX_EXTRN_SYSCALL_MSRS \
891 | CPUMCTX_EXTRN_SYSENTER_MSRS | CPUMCTX_EXTRN_TSC_AUX | CPUMCTX_EXTRN_OTHER_MSRS)
892
893/** Hardware-virtualization (SVM or VMX) state is kept externally. */
894#define CPUMCTX_EXTRN_HWVIRT UINT64_C(0x0000020000000000)
895
896/** Mask of bits the keepers can use for state tracking. */
897#define CPUMCTX_EXTRN_KEEPER_STATE_MASK UINT64_C(0xffff000000000000)
898
899/** NEM/Win: Event injection (known was interruption) pending state. */
900#define CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT UINT64_C(0x0001000000000000)
901/** NEM/Win: Inhibit maskable interrupts (VMCPU_FF_INHIBIT_INTERRUPTS). */
902#define CPUMCTX_EXTRN_NEM_WIN_INHIBIT_INT UINT64_C(0x0002000000000000)
903/** NEM/Win: Inhibit non-maskable interrupts (VMCPU_FF_BLOCK_NMIS). */
904#define CPUMCTX_EXTRN_NEM_WIN_INHIBIT_NMI UINT64_C(0x0004000000000000)
905/** NEM/Win: Mask. */
906#define CPUMCTX_EXTRN_NEM_WIN_MASK UINT64_C(0x0007000000000000)
907
908/** HM/SVM: Inhibit maskable interrupts (VMCPU_FF_INHIBIT_INTERRUPTS). */
909#define CPUMCTX_EXTRN_HM_SVM_INT_SHADOW UINT64_C(0x0001000000000000)
910/** HM/SVM: Nested-guest interrupt pending (VMCPU_FF_INTERRUPT_NESTED_GUEST). */
911#define CPUMCTX_EXTRN_HM_SVM_HWVIRT_VIRQ UINT64_C(0x0002000000000000)
912/** HM/SVM: Mask. */
913#define CPUMCTX_EXTRN_HM_SVM_MASK UINT64_C(0x0003000000000000)
914
915/** HM/VMX: Guest-interruptibility state (VMCPU_FF_INHIBIT_INTERRUPTS,
916 * VMCPU_FF_BLOCK_NMIS). */
917#define CPUMCTX_EXTRN_HM_VMX_INT_STATE UINT64_C(0x0001000000000000)
918/** HM/VMX: Mask. */
919#define CPUMCTX_EXTRN_HM_VMX_MASK UINT64_C(0x0001000000000000)
920
921/** All CPUM state bits, not including keeper specific ones. */
922#define CPUMCTX_EXTRN_ALL UINT64_C(0x000003fffffffffc)
923/** All CPUM state bits, including keeper specific ones. */
924#define CPUMCTX_EXTRN_ABSOLUTELY_ALL UINT64_C(0xfffffffffffffffc)
925/** @} */
926
927
928/**
929 * Additional guest MSRs (i.e. not part of the CPU context structure).
930 *
931 * @remarks Never change the order here because of the saved stated! The size
932 * can in theory be changed, but keep older VBox versions in mind.
933 */
934typedef union CPUMCTXMSRS
935{
936 struct
937 {
938 uint64_t TscAux; /**< MSR_K8_TSC_AUX */
939 uint64_t MiscEnable; /**< MSR_IA32_MISC_ENABLE */
940 uint64_t MtrrDefType; /**< IA32_MTRR_DEF_TYPE */
941 uint64_t MtrrFix64K_00000; /**< IA32_MTRR_FIX16K_80000 */
942 uint64_t MtrrFix16K_80000; /**< IA32_MTRR_FIX16K_80000 */
943 uint64_t MtrrFix16K_A0000; /**< IA32_MTRR_FIX16K_A0000 */
944 uint64_t MtrrFix4K_C0000; /**< IA32_MTRR_FIX4K_C0000 */
945 uint64_t MtrrFix4K_C8000; /**< IA32_MTRR_FIX4K_C8000 */
946 uint64_t MtrrFix4K_D0000; /**< IA32_MTRR_FIX4K_D0000 */
947 uint64_t MtrrFix4K_D8000; /**< IA32_MTRR_FIX4K_D8000 */
948 uint64_t MtrrFix4K_E0000; /**< IA32_MTRR_FIX4K_E0000 */
949 uint64_t MtrrFix4K_E8000; /**< IA32_MTRR_FIX4K_E8000 */
950 uint64_t MtrrFix4K_F0000; /**< IA32_MTRR_FIX4K_F0000 */
951 uint64_t MtrrFix4K_F8000; /**< IA32_MTRR_FIX4K_F8000 */
952 uint64_t PkgCStateCfgCtrl; /**< MSR_PKG_CST_CONFIG_CONTROL */
953 uint64_t SpecCtrl; /**< IA32_SPEC_CTRL */
954 uint64_t ArchCaps; /**< IA32_ARCH_CAPABILITIES */
955 } msr;
956 uint64_t au64[64];
957} CPUMCTXMSRS;
958/** Pointer to the guest MSR state. */
959typedef CPUMCTXMSRS *PCPUMCTXMSRS;
960/** Pointer to the const guest MSR state. */
961typedef const CPUMCTXMSRS *PCCPUMCTXMSRS;
962
963/**
964 * The register set returned by a CPUID operation.
965 */
966typedef struct CPUMCPUID
967{
968 uint32_t uEax;
969 uint32_t uEbx;
970 uint32_t uEcx;
971 uint32_t uEdx;
972} CPUMCPUID;
973/** Pointer to a CPUID leaf. */
974typedef CPUMCPUID *PCPUMCPUID;
975/** Pointer to a const CPUID leaf. */
976typedef const CPUMCPUID *PCCPUMCPUID;
977
978/** @} */
979
980RT_C_DECLS_END
981
982#endif
983
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