VirtualBox

source: vbox/trunk/include/VBox/vmm/cpum.h@ 93593

Last change on this file since 93593 was 93518, checked in by vboxsync, 3 years ago

vmm/cpum.h: x86 build fix. bugref:9898

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 107.2 KB
Line 
1/** @file
2 * CPUM - CPU Monitor(/ Manager).
3 */
4
5/*
6 * Copyright (C) 2006-2022 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_INCLUDED_vmm_cpum_h
27#define VBOX_INCLUDED_vmm_cpum_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/x86.h>
33#include <VBox/types.h>
34#include <VBox/vmm/cpumctx.h>
35#include <VBox/vmm/stam.h>
36#include <VBox/vmm/vmapi.h>
37#include <VBox/vmm/hm_svm.h>
38#include <VBox/vmm/hm_vmx.h>
39
40RT_C_DECLS_BEGIN
41
42/** @defgroup grp_cpum The CPU Monitor / Manager API
43 * @ingroup grp_vmm
44 * @{
45 */
46
47/**
48 * CPUID feature to set or clear.
49 */
50typedef enum CPUMCPUIDFEATURE
51{
52 CPUMCPUIDFEATURE_INVALID = 0,
53 /** The APIC feature bit. (Std+Ext)
54 * Note! There is a per-cpu flag for masking this CPUID feature bit when the
55 * APICBASE.ENABLED bit is zero. So, this feature is only set/cleared
56 * at VM construction time like all the others. This didn't used to be
57 * that way, this is new with 5.1. */
58 CPUMCPUIDFEATURE_APIC,
59 /** The sysenter/sysexit feature bit. (Std) */
60 CPUMCPUIDFEATURE_SEP,
61 /** The SYSCALL/SYSEXIT feature bit (64 bits mode only for Intel CPUs). (Ext) */
62 CPUMCPUIDFEATURE_SYSCALL,
63 /** The PAE feature bit. (Std+Ext) */
64 CPUMCPUIDFEATURE_PAE,
65 /** The NX feature bit. (Ext) */
66 CPUMCPUIDFEATURE_NX,
67 /** The LAHF/SAHF feature bit (64 bits mode only). (Ext) */
68 CPUMCPUIDFEATURE_LAHF,
69 /** The LONG MODE feature bit. (Ext) */
70 CPUMCPUIDFEATURE_LONG_MODE,
71 /** The x2APIC feature bit. (Std) */
72 CPUMCPUIDFEATURE_X2APIC,
73 /** The RDTSCP feature bit. (Ext) */
74 CPUMCPUIDFEATURE_RDTSCP,
75 /** The Hypervisor Present bit. (Std) */
76 CPUMCPUIDFEATURE_HVP,
77 /** The speculation control feature bits. (StExt) */
78 CPUMCPUIDFEATURE_SPEC_CTRL,
79 /** 32bit hackishness. */
80 CPUMCPUIDFEATURE_32BIT_HACK = 0x7fffffff
81} CPUMCPUIDFEATURE;
82
83/**
84 * CPU Vendor.
85 */
86typedef enum CPUMCPUVENDOR
87{
88 CPUMCPUVENDOR_INVALID = 0,
89 CPUMCPUVENDOR_INTEL,
90 CPUMCPUVENDOR_AMD,
91 CPUMCPUVENDOR_VIA,
92 CPUMCPUVENDOR_CYRIX,
93 CPUMCPUVENDOR_SHANGHAI,
94 CPUMCPUVENDOR_HYGON,
95 CPUMCPUVENDOR_UNKNOWN,
96 /** 32bit hackishness. */
97 CPUMCPUVENDOR_32BIT_HACK = 0x7fffffff
98} CPUMCPUVENDOR;
99
100
101/**
102 * X86 and AMD64 CPU microarchitectures and in processor generations.
103 *
104 * @remarks The separation here is sometimes a little bit too finely grained,
105 * and the differences is more like processor generation than micro
106 * arch. This can be useful, so we'll provide functions for getting at
107 * more coarse grained info.
108 */
109typedef enum CPUMMICROARCH
110{
111 kCpumMicroarch_Invalid = 0,
112
113 kCpumMicroarch_Intel_First,
114
115 kCpumMicroarch_Intel_8086 = kCpumMicroarch_Intel_First,
116 kCpumMicroarch_Intel_80186,
117 kCpumMicroarch_Intel_80286,
118 kCpumMicroarch_Intel_80386,
119 kCpumMicroarch_Intel_80486,
120 kCpumMicroarch_Intel_P5,
121
122 kCpumMicroarch_Intel_P6_Core_Atom_First,
123 kCpumMicroarch_Intel_P6 = kCpumMicroarch_Intel_P6_Core_Atom_First,
124 kCpumMicroarch_Intel_P6_II,
125 kCpumMicroarch_Intel_P6_III,
126
127 kCpumMicroarch_Intel_P6_M_Banias,
128 kCpumMicroarch_Intel_P6_M_Dothan,
129 kCpumMicroarch_Intel_Core_Yonah, /**< Core, also known as Enhanced Pentium M. */
130
131 kCpumMicroarch_Intel_Core2_First,
132 kCpumMicroarch_Intel_Core2_Merom = kCpumMicroarch_Intel_Core2_First, /**< 65nm, Merom/Conroe/Kentsfield/Tigerton */
133 kCpumMicroarch_Intel_Core2_Penryn, /**< 45nm, Penryn/Wolfdale/Yorkfield/Harpertown */
134 kCpumMicroarch_Intel_Core2_End,
135
136 kCpumMicroarch_Intel_Core7_First,
137 kCpumMicroarch_Intel_Core7_Nehalem = kCpumMicroarch_Intel_Core7_First,
138 kCpumMicroarch_Intel_Core7_Westmere,
139 kCpumMicroarch_Intel_Core7_SandyBridge,
140 kCpumMicroarch_Intel_Core7_IvyBridge,
141 kCpumMicroarch_Intel_Core7_Haswell,
142 kCpumMicroarch_Intel_Core7_Broadwell,
143 kCpumMicroarch_Intel_Core7_Skylake,
144 kCpumMicroarch_Intel_Core7_KabyLake,
145 kCpumMicroarch_Intel_Core7_CoffeeLake,
146 kCpumMicroarch_Intel_Core7_WhiskeyLake,
147 kCpumMicroarch_Intel_Core7_CascadeLake,
148 kCpumMicroarch_Intel_Core7_CannonLake, /**< Limited 10nm. */
149 kCpumMicroarch_Intel_Core7_CometLake, /**< 10th gen, 14nm desktop + high power mobile. */
150 kCpumMicroarch_Intel_Core7_IceLake, /**< 10th gen, 10nm mobile and some Xeons. Actually 'Sunny Cove' march. */
151 kCpumMicroarch_Intel_Core7_SunnyCove = kCpumMicroarch_Intel_Core7_IceLake,
152 kCpumMicroarch_Intel_Core7_RocketLake, /**< 11th gen, 14nm desktop + high power mobile. Aka 'Cypress Cove', backport of 'Willow Cove' to 14nm. */
153 kCpumMicroarch_Intel_Core7_CypressCove = kCpumMicroarch_Intel_Core7_RocketLake,
154 kCpumMicroarch_Intel_Core7_TigerLake, /**< 11th gen, 10nm mobile. Actually 'Willow Cove' march. */
155 kCpumMicroarch_Intel_Core7_WillowCove = kCpumMicroarch_Intel_Core7_TigerLake,
156 kCpumMicroarch_Intel_Core7_AlderLake, /**< 12th gen, 10nm all platforms(?). */
157 kCpumMicroarch_Intel_Core7_SapphireRapids, /**< 12th? gen, 10nm server? */
158 kCpumMicroarch_Intel_Core7_End,
159
160 kCpumMicroarch_Intel_Atom_First,
161 kCpumMicroarch_Intel_Atom_Bonnell = kCpumMicroarch_Intel_Atom_First,
162 kCpumMicroarch_Intel_Atom_Lincroft, /**< Second generation bonnell (44nm). */
163 kCpumMicroarch_Intel_Atom_Saltwell, /**< 32nm shrink of Bonnell. */
164 kCpumMicroarch_Intel_Atom_Silvermont, /**< 22nm */
165 kCpumMicroarch_Intel_Atom_Airmount, /**< 14nm */
166 kCpumMicroarch_Intel_Atom_Goldmont, /**< 14nm */
167 kCpumMicroarch_Intel_Atom_GoldmontPlus, /**< 14nm */
168 kCpumMicroarch_Intel_Atom_Unknown,
169 kCpumMicroarch_Intel_Atom_End,
170
171
172 kCpumMicroarch_Intel_Phi_First,
173 kCpumMicroarch_Intel_Phi_KnightsFerry = kCpumMicroarch_Intel_Phi_First,
174 kCpumMicroarch_Intel_Phi_KnightsCorner,
175 kCpumMicroarch_Intel_Phi_KnightsLanding,
176 kCpumMicroarch_Intel_Phi_KnightsHill,
177 kCpumMicroarch_Intel_Phi_KnightsMill,
178 kCpumMicroarch_Intel_Phi_End,
179
180 kCpumMicroarch_Intel_P6_Core_Atom_End,
181
182 kCpumMicroarch_Intel_NB_First,
183 kCpumMicroarch_Intel_NB_Willamette = kCpumMicroarch_Intel_NB_First, /**< 180nm */
184 kCpumMicroarch_Intel_NB_Northwood, /**< 130nm */
185 kCpumMicroarch_Intel_NB_Prescott, /**< 90nm */
186 kCpumMicroarch_Intel_NB_Prescott2M, /**< 90nm */
187 kCpumMicroarch_Intel_NB_CedarMill, /**< 65nm */
188 kCpumMicroarch_Intel_NB_Gallatin, /**< 90nm Xeon, Pentium 4 Extreme Edition ("Emergency Edition"). */
189 kCpumMicroarch_Intel_NB_Unknown,
190 kCpumMicroarch_Intel_NB_End,
191
192 kCpumMicroarch_Intel_Unknown,
193 kCpumMicroarch_Intel_End,
194
195 kCpumMicroarch_AMD_First,
196 kCpumMicroarch_AMD_Am286 = kCpumMicroarch_AMD_First,
197 kCpumMicroarch_AMD_Am386,
198 kCpumMicroarch_AMD_Am486,
199 kCpumMicroarch_AMD_Am486Enh, /**< Covers Am5x86 as well. */
200 kCpumMicroarch_AMD_K5,
201 kCpumMicroarch_AMD_K6,
202
203 kCpumMicroarch_AMD_K7_First,
204 kCpumMicroarch_AMD_K7_Palomino = kCpumMicroarch_AMD_K7_First,
205 kCpumMicroarch_AMD_K7_Spitfire,
206 kCpumMicroarch_AMD_K7_Thunderbird,
207 kCpumMicroarch_AMD_K7_Morgan,
208 kCpumMicroarch_AMD_K7_Thoroughbred,
209 kCpumMicroarch_AMD_K7_Barton,
210 kCpumMicroarch_AMD_K7_Unknown,
211 kCpumMicroarch_AMD_K7_End,
212
213 kCpumMicroarch_AMD_K8_First,
214 kCpumMicroarch_AMD_K8_130nm = kCpumMicroarch_AMD_K8_First, /**< 130nm Clawhammer, Sledgehammer, Newcastle, Paris, Odessa, Dublin */
215 kCpumMicroarch_AMD_K8_90nm, /**< 90nm shrink */
216 kCpumMicroarch_AMD_K8_90nm_DualCore, /**< 90nm with two cores. */
217 kCpumMicroarch_AMD_K8_90nm_AMDV, /**< 90nm with AMD-V (usually) and two cores (usually). */
218 kCpumMicroarch_AMD_K8_65nm, /**< 65nm shrink. */
219 kCpumMicroarch_AMD_K8_End,
220
221 kCpumMicroarch_AMD_K10,
222 kCpumMicroarch_AMD_K10_Lion,
223 kCpumMicroarch_AMD_K10_Llano,
224 kCpumMicroarch_AMD_Bobcat,
225 kCpumMicroarch_AMD_Jaguar,
226
227 kCpumMicroarch_AMD_15h_First,
228 kCpumMicroarch_AMD_15h_Bulldozer = kCpumMicroarch_AMD_15h_First,
229 kCpumMicroarch_AMD_15h_Piledriver,
230 kCpumMicroarch_AMD_15h_Steamroller, /**< Yet to be released, might have different family. */
231 kCpumMicroarch_AMD_15h_Excavator, /**< Yet to be released, might have different family. */
232 kCpumMicroarch_AMD_15h_Unknown,
233 kCpumMicroarch_AMD_15h_End,
234
235 kCpumMicroarch_AMD_16h_First,
236 kCpumMicroarch_AMD_16h_End,
237
238 kCpumMicroarch_AMD_Zen_First,
239 kCpumMicroarch_AMD_Zen_Ryzen = kCpumMicroarch_AMD_Zen_First,
240 kCpumMicroarch_AMD_Zen_End,
241
242 kCpumMicroarch_AMD_Unknown,
243 kCpumMicroarch_AMD_End,
244
245 kCpumMicroarch_Hygon_First,
246 kCpumMicroarch_Hygon_Dhyana = kCpumMicroarch_Hygon_First,
247 kCpumMicroarch_Hygon_Unknown,
248 kCpumMicroarch_Hygon_End,
249
250 kCpumMicroarch_VIA_First,
251 kCpumMicroarch_Centaur_C6 = kCpumMicroarch_VIA_First,
252 kCpumMicroarch_Centaur_C2,
253 kCpumMicroarch_Centaur_C3,
254 kCpumMicroarch_VIA_C3_M2,
255 kCpumMicroarch_VIA_C3_C5A, /**< 180nm Samuel - Cyrix III, C3, 1GigaPro. */
256 kCpumMicroarch_VIA_C3_C5B, /**< 150nm Samuel 2 - Cyrix III, C3, 1GigaPro, Eden ESP, XP 2000+. */
257 kCpumMicroarch_VIA_C3_C5C, /**< 130nm Ezra - C3, Eden ESP. */
258 kCpumMicroarch_VIA_C3_C5N, /**< 130nm Ezra-T - C3. */
259 kCpumMicroarch_VIA_C3_C5XL, /**< 130nm Nehemiah - C3, Eden ESP, Eden-N. */
260 kCpumMicroarch_VIA_C3_C5P, /**< 130nm Nehemiah+ - C3. */
261 kCpumMicroarch_VIA_C7_C5J, /**< 90nm Esther - C7, C7-D, C7-M, Eden, Eden ULV. */
262 kCpumMicroarch_VIA_Isaiah,
263 kCpumMicroarch_VIA_Unknown,
264 kCpumMicroarch_VIA_End,
265
266 kCpumMicroarch_Shanghai_First,
267 kCpumMicroarch_Shanghai_Wudaokou = kCpumMicroarch_Shanghai_First,
268 kCpumMicroarch_Shanghai_Unknown,
269 kCpumMicroarch_Shanghai_End,
270
271 kCpumMicroarch_Cyrix_First,
272 kCpumMicroarch_Cyrix_5x86 = kCpumMicroarch_Cyrix_First,
273 kCpumMicroarch_Cyrix_M1,
274 kCpumMicroarch_Cyrix_MediaGX,
275 kCpumMicroarch_Cyrix_MediaGXm,
276 kCpumMicroarch_Cyrix_M2,
277 kCpumMicroarch_Cyrix_Unknown,
278 kCpumMicroarch_Cyrix_End,
279
280 kCpumMicroarch_NEC_First,
281 kCpumMicroarch_NEC_V20 = kCpumMicroarch_NEC_First,
282 kCpumMicroarch_NEC_V30,
283 kCpumMicroarch_NEC_End,
284
285 kCpumMicroarch_Unknown,
286
287 kCpumMicroarch_32BitHack = 0x7fffffff
288} CPUMMICROARCH;
289
290
291/** Predicate macro for catching netburst CPUs. */
292#define CPUMMICROARCH_IS_INTEL_NETBURST(a_enmMicroarch) \
293 ((a_enmMicroarch) >= kCpumMicroarch_Intel_NB_First && (a_enmMicroarch) <= kCpumMicroarch_Intel_NB_End)
294
295/** Predicate macro for catching Core7 CPUs. */
296#define CPUMMICROARCH_IS_INTEL_CORE7(a_enmMicroarch) \
297 ((a_enmMicroarch) >= kCpumMicroarch_Intel_Core7_First && (a_enmMicroarch) <= kCpumMicroarch_Intel_Core7_End)
298
299/** Predicate macro for catching Core 2 CPUs. */
300#define CPUMMICROARCH_IS_INTEL_CORE2(a_enmMicroarch) \
301 ((a_enmMicroarch) >= kCpumMicroarch_Intel_Core2_First && (a_enmMicroarch) <= kCpumMicroarch_Intel_Core2_End)
302
303/** Predicate macro for catching Atom CPUs, Silvermont and upwards. */
304#define CPUMMICROARCH_IS_INTEL_SILVERMONT_PLUS(a_enmMicroarch) \
305 ((a_enmMicroarch) >= kCpumMicroarch_Intel_Atom_Silvermont && (a_enmMicroarch) <= kCpumMicroarch_Intel_Atom_End)
306
307/** Predicate macro for catching AMD Family OFh CPUs (aka K8). */
308#define CPUMMICROARCH_IS_AMD_FAM_0FH(a_enmMicroarch) \
309 ((a_enmMicroarch) >= kCpumMicroarch_AMD_K8_First && (a_enmMicroarch) <= kCpumMicroarch_AMD_K8_End)
310
311/** Predicate macro for catching AMD Family 10H CPUs (aka K10). */
312#define CPUMMICROARCH_IS_AMD_FAM_10H(a_enmMicroarch) ((a_enmMicroarch) == kCpumMicroarch_AMD_K10)
313
314/** Predicate macro for catching AMD Family 11H CPUs (aka Lion). */
315#define CPUMMICROARCH_IS_AMD_FAM_11H(a_enmMicroarch) ((a_enmMicroarch) == kCpumMicroarch_AMD_K10_Lion)
316
317/** Predicate macro for catching AMD Family 12H CPUs (aka Llano). */
318#define CPUMMICROARCH_IS_AMD_FAM_12H(a_enmMicroarch) ((a_enmMicroarch) == kCpumMicroarch_AMD_K10_Llano)
319
320/** Predicate macro for catching AMD Family 14H CPUs (aka Bobcat). */
321#define CPUMMICROARCH_IS_AMD_FAM_14H(a_enmMicroarch) ((a_enmMicroarch) == kCpumMicroarch_AMD_Bobcat)
322
323/** Predicate macro for catching AMD Family 15H CPUs (bulldozer and it's
324 * decendants). */
325#define CPUMMICROARCH_IS_AMD_FAM_15H(a_enmMicroarch) \
326 ((a_enmMicroarch) >= kCpumMicroarch_AMD_15h_First && (a_enmMicroarch) <= kCpumMicroarch_AMD_15h_End)
327
328/** Predicate macro for catching AMD Family 16H CPUs. */
329#define CPUMMICROARCH_IS_AMD_FAM_16H(a_enmMicroarch) \
330 ((a_enmMicroarch) >= kCpumMicroarch_AMD_16h_First && (a_enmMicroarch) <= kCpumMicroarch_AMD_16h_End)
331
332/** Predicate macro for catching AMD Zen Family CPUs. */
333#define CPUMMICROARCH_IS_AMD_FAM_ZEN(a_enmMicroarch) \
334 ((a_enmMicroarch) >= kCpumMicroarch_AMD_Zen_First && (a_enmMicroarch) <= kCpumMicroarch_AMD_Zen_End)
335
336
337/**
338 * CPUID leaf.
339 *
340 * @remarks This structure is used by the patch manager and is therefore
341 * more or less set in stone.
342 */
343typedef struct CPUMCPUIDLEAF
344{
345 /** The leaf number. */
346 uint32_t uLeaf;
347 /** The sub-leaf number. */
348 uint32_t uSubLeaf;
349 /** Sub-leaf mask. This is 0 when sub-leaves aren't used. */
350 uint32_t fSubLeafMask;
351
352 /** The EAX value. */
353 uint32_t uEax;
354 /** The EBX value. */
355 uint32_t uEbx;
356 /** The ECX value. */
357 uint32_t uEcx;
358 /** The EDX value. */
359 uint32_t uEdx;
360
361 /** Flags. */
362 uint32_t fFlags;
363} CPUMCPUIDLEAF;
364#ifndef VBOX_FOR_DTRACE_LIB
365AssertCompileSize(CPUMCPUIDLEAF, 32);
366#endif
367/** Pointer to a CPUID leaf. */
368typedef CPUMCPUIDLEAF *PCPUMCPUIDLEAF;
369/** Pointer to a const CPUID leaf. */
370typedef CPUMCPUIDLEAF const *PCCPUMCPUIDLEAF;
371
372/** @name CPUMCPUIDLEAF::fFlags
373 * @{ */
374/** Indicates working intel leaf 0xb where the lower 8 ECX bits are not modified
375 * and EDX containing the extended APIC ID. */
376#define CPUMCPUIDLEAF_F_INTEL_TOPOLOGY_SUBLEAVES RT_BIT_32(0)
377/** The leaf contains an APIC ID that needs changing to that of the current CPU. */
378#define CPUMCPUIDLEAF_F_CONTAINS_APIC_ID RT_BIT_32(1)
379/** The leaf contains an OSXSAVE which needs individual handling on each CPU. */
380#define CPUMCPUIDLEAF_F_CONTAINS_OSXSAVE RT_BIT_32(2)
381/** The leaf contains an APIC feature bit which is tied to APICBASE.EN. */
382#define CPUMCPUIDLEAF_F_CONTAINS_APIC RT_BIT_32(3)
383/** Mask of the valid flags. */
384#define CPUMCPUIDLEAF_F_VALID_MASK UINT32_C(0xf)
385/** @} */
386
387/**
388 * Method used to deal with unknown CPUID leaves.
389 * @remarks Used in patch code.
390 */
391typedef enum CPUMUNKNOWNCPUID
392{
393 /** Invalid zero value. */
394 CPUMUNKNOWNCPUID_INVALID = 0,
395 /** Use given default values (DefCpuId). */
396 CPUMUNKNOWNCPUID_DEFAULTS,
397 /** Return the last standard leaf.
398 * Intel Sandy Bridge has been observed doing this. */
399 CPUMUNKNOWNCPUID_LAST_STD_LEAF,
400 /** Return the last standard leaf, with ecx observed.
401 * Intel Sandy Bridge has been observed doing this. */
402 CPUMUNKNOWNCPUID_LAST_STD_LEAF_WITH_ECX,
403 /** The register values are passed thru unmodified. */
404 CPUMUNKNOWNCPUID_PASSTHRU,
405 /** End of valid value. */
406 CPUMUNKNOWNCPUID_END,
407 /** Ensure 32-bit type. */
408 CPUMUNKNOWNCPUID_32BIT_HACK = 0x7fffffff
409} CPUMUNKNOWNCPUID;
410/** Pointer to unknown CPUID leaf method. */
411typedef CPUMUNKNOWNCPUID *PCPUMUNKNOWNCPUID;
412
413
414/**
415 * The register set returned by a CPUID operation.
416 */
417typedef struct CPUMCPUID
418{
419 uint32_t uEax;
420 uint32_t uEbx;
421 uint32_t uEcx;
422 uint32_t uEdx;
423} CPUMCPUID;
424/** Pointer to a CPUID leaf. */
425typedef CPUMCPUID *PCPUMCPUID;
426/** Pointer to a const CPUID leaf. */
427typedef const CPUMCPUID *PCCPUMCPUID;
428
429
430/**
431 * MSR read functions.
432 */
433typedef enum CPUMMSRRDFN
434{
435 /** Invalid zero value. */
436 kCpumMsrRdFn_Invalid = 0,
437 /** Return the CPUMMSRRANGE::uValue. */
438 kCpumMsrRdFn_FixedValue,
439 /** Alias to the MSR range starting at the MSR given by
440 * CPUMMSRRANGE::uValue. Must be used in pair with
441 * kCpumMsrWrFn_MsrAlias. */
442 kCpumMsrRdFn_MsrAlias,
443 /** Write only register, GP all read attempts. */
444 kCpumMsrRdFn_WriteOnly,
445
446 kCpumMsrRdFn_Ia32P5McAddr,
447 kCpumMsrRdFn_Ia32P5McType,
448 kCpumMsrRdFn_Ia32TimestampCounter,
449 kCpumMsrRdFn_Ia32PlatformId, /**< Takes real CPU value for reference. */
450 kCpumMsrRdFn_Ia32ApicBase,
451 kCpumMsrRdFn_Ia32FeatureControl,
452 kCpumMsrRdFn_Ia32BiosSignId, /**< Range value returned. */
453 kCpumMsrRdFn_Ia32SmmMonitorCtl,
454 kCpumMsrRdFn_Ia32PmcN,
455 kCpumMsrRdFn_Ia32MonitorFilterLineSize,
456 kCpumMsrRdFn_Ia32MPerf,
457 kCpumMsrRdFn_Ia32APerf,
458 kCpumMsrRdFn_Ia32MtrrCap, /**< Takes real CPU value for reference. */
459 kCpumMsrRdFn_Ia32MtrrPhysBaseN, /**< Takes register number. */
460 kCpumMsrRdFn_Ia32MtrrPhysMaskN, /**< Takes register number. */
461 kCpumMsrRdFn_Ia32MtrrFixed, /**< Takes CPUMCPU offset. */
462 kCpumMsrRdFn_Ia32MtrrDefType,
463 kCpumMsrRdFn_Ia32Pat,
464 kCpumMsrRdFn_Ia32SysEnterCs,
465 kCpumMsrRdFn_Ia32SysEnterEsp,
466 kCpumMsrRdFn_Ia32SysEnterEip,
467 kCpumMsrRdFn_Ia32McgCap,
468 kCpumMsrRdFn_Ia32McgStatus,
469 kCpumMsrRdFn_Ia32McgCtl,
470 kCpumMsrRdFn_Ia32DebugCtl,
471 kCpumMsrRdFn_Ia32SmrrPhysBase,
472 kCpumMsrRdFn_Ia32SmrrPhysMask,
473 kCpumMsrRdFn_Ia32PlatformDcaCap,
474 kCpumMsrRdFn_Ia32CpuDcaCap,
475 kCpumMsrRdFn_Ia32Dca0Cap,
476 kCpumMsrRdFn_Ia32PerfEvtSelN, /**< Range value indicates the register number. */
477 kCpumMsrRdFn_Ia32PerfStatus, /**< Range value returned. */
478 kCpumMsrRdFn_Ia32PerfCtl, /**< Range value returned. */
479 kCpumMsrRdFn_Ia32FixedCtrN, /**< Takes register number of start of range. */
480 kCpumMsrRdFn_Ia32PerfCapabilities, /**< Takes reference value. */
481 kCpumMsrRdFn_Ia32FixedCtrCtrl,
482 kCpumMsrRdFn_Ia32PerfGlobalStatus, /**< Takes reference value. */
483 kCpumMsrRdFn_Ia32PerfGlobalCtrl,
484 kCpumMsrRdFn_Ia32PerfGlobalOvfCtrl,
485 kCpumMsrRdFn_Ia32PebsEnable,
486 kCpumMsrRdFn_Ia32ClockModulation, /**< Range value returned. */
487 kCpumMsrRdFn_Ia32ThermInterrupt, /**< Range value returned. */
488 kCpumMsrRdFn_Ia32ThermStatus, /**< Range value returned. */
489 kCpumMsrRdFn_Ia32Therm2Ctl, /**< Range value returned. */
490 kCpumMsrRdFn_Ia32MiscEnable, /**< Range value returned. */
491 kCpumMsrRdFn_Ia32McCtlStatusAddrMiscN, /**< Takes bank number. */
492 kCpumMsrRdFn_Ia32McNCtl2, /**< Takes register number of start of range. */
493 kCpumMsrRdFn_Ia32DsArea,
494 kCpumMsrRdFn_Ia32TscDeadline,
495 kCpumMsrRdFn_Ia32X2ApicN,
496 kCpumMsrRdFn_Ia32DebugInterface,
497 kCpumMsrRdFn_Ia32VmxBasic, /**< Takes real value as reference. */
498 kCpumMsrRdFn_Ia32VmxPinbasedCtls, /**< Takes real value as reference. */
499 kCpumMsrRdFn_Ia32VmxProcbasedCtls, /**< Takes real value as reference. */
500 kCpumMsrRdFn_Ia32VmxExitCtls, /**< Takes real value as reference. */
501 kCpumMsrRdFn_Ia32VmxEntryCtls, /**< Takes real value as reference. */
502 kCpumMsrRdFn_Ia32VmxMisc, /**< Takes real value as reference. */
503 kCpumMsrRdFn_Ia32VmxCr0Fixed0, /**< Takes real value as reference. */
504 kCpumMsrRdFn_Ia32VmxCr0Fixed1, /**< Takes real value as reference. */
505 kCpumMsrRdFn_Ia32VmxCr4Fixed0, /**< Takes real value as reference. */
506 kCpumMsrRdFn_Ia32VmxCr4Fixed1, /**< Takes real value as reference. */
507 kCpumMsrRdFn_Ia32VmxVmcsEnum, /**< Takes real value as reference. */
508 kCpumMsrRdFn_Ia32VmxProcBasedCtls2, /**< Takes real value as reference. */
509 kCpumMsrRdFn_Ia32VmxEptVpidCap, /**< Takes real value as reference. */
510 kCpumMsrRdFn_Ia32VmxTruePinbasedCtls, /**< Takes real value as reference. */
511 kCpumMsrRdFn_Ia32VmxTrueProcbasedCtls, /**< Takes real value as reference. */
512 kCpumMsrRdFn_Ia32VmxTrueExitCtls, /**< Takes real value as reference. */
513 kCpumMsrRdFn_Ia32VmxTrueEntryCtls, /**< Takes real value as reference. */
514 kCpumMsrRdFn_Ia32VmxVmFunc, /**< Takes real value as reference. */
515 kCpumMsrRdFn_Ia32SpecCtrl,
516 kCpumMsrRdFn_Ia32ArchCapabilities,
517
518 kCpumMsrRdFn_Amd64Efer,
519 kCpumMsrRdFn_Amd64SyscallTarget,
520 kCpumMsrRdFn_Amd64LongSyscallTarget,
521 kCpumMsrRdFn_Amd64CompSyscallTarget,
522 kCpumMsrRdFn_Amd64SyscallFlagMask,
523 kCpumMsrRdFn_Amd64FsBase,
524 kCpumMsrRdFn_Amd64GsBase,
525 kCpumMsrRdFn_Amd64KernelGsBase,
526 kCpumMsrRdFn_Amd64TscAux,
527
528 kCpumMsrRdFn_IntelEblCrPowerOn,
529 kCpumMsrRdFn_IntelI7CoreThreadCount,
530 kCpumMsrRdFn_IntelP4EbcHardPowerOn,
531 kCpumMsrRdFn_IntelP4EbcSoftPowerOn,
532 kCpumMsrRdFn_IntelP4EbcFrequencyId,
533 kCpumMsrRdFn_IntelP6FsbFrequency, /**< Takes real value as reference. */
534 kCpumMsrRdFn_IntelPlatformInfo,
535 kCpumMsrRdFn_IntelFlexRatio, /**< Takes real value as reference. */
536 kCpumMsrRdFn_IntelPkgCStConfigControl,
537 kCpumMsrRdFn_IntelPmgIoCaptureBase,
538 kCpumMsrRdFn_IntelLastBranchFromToN,
539 kCpumMsrRdFn_IntelLastBranchFromN,
540 kCpumMsrRdFn_IntelLastBranchToN,
541 kCpumMsrRdFn_IntelLastBranchTos,
542 kCpumMsrRdFn_IntelBblCrCtl,
543 kCpumMsrRdFn_IntelBblCrCtl3,
544 kCpumMsrRdFn_IntelI7TemperatureTarget, /**< Range value returned. */
545 kCpumMsrRdFn_IntelI7MsrOffCoreResponseN,/**< Takes register number. */
546 kCpumMsrRdFn_IntelI7MiscPwrMgmt,
547 kCpumMsrRdFn_IntelP6CrN,
548 kCpumMsrRdFn_IntelCpuId1FeatureMaskEcdx,
549 kCpumMsrRdFn_IntelCpuId1FeatureMaskEax,
550 kCpumMsrRdFn_IntelCpuId80000001FeatureMaskEcdx,
551 kCpumMsrRdFn_IntelI7SandyAesNiCtl,
552 kCpumMsrRdFn_IntelI7TurboRatioLimit, /**< Returns range value. */
553 kCpumMsrRdFn_IntelI7LbrSelect,
554 kCpumMsrRdFn_IntelI7SandyErrorControl,
555 kCpumMsrRdFn_IntelI7VirtualLegacyWireCap,/**< Returns range value. */
556 kCpumMsrRdFn_IntelI7PowerCtl,
557 kCpumMsrRdFn_IntelI7SandyPebsNumAlt,
558 kCpumMsrRdFn_IntelI7PebsLdLat,
559 kCpumMsrRdFn_IntelI7PkgCnResidencyN, /**< Takes C-state number. */
560 kCpumMsrRdFn_IntelI7CoreCnResidencyN, /**< Takes C-state number. */
561 kCpumMsrRdFn_IntelI7SandyVrCurrentConfig,/**< Takes real value as reference. */
562 kCpumMsrRdFn_IntelI7SandyVrMiscConfig, /**< Takes real value as reference. */
563 kCpumMsrRdFn_IntelI7SandyRaplPowerUnit, /**< Takes real value as reference. */
564 kCpumMsrRdFn_IntelI7SandyPkgCnIrtlN, /**< Takes real value as reference. */
565 kCpumMsrRdFn_IntelI7SandyPkgC2Residency, /**< Takes real value as reference. */
566 kCpumMsrRdFn_IntelI7RaplPkgPowerLimit, /**< Takes real value as reference. */
567 kCpumMsrRdFn_IntelI7RaplPkgEnergyStatus, /**< Takes real value as reference. */
568 kCpumMsrRdFn_IntelI7RaplPkgPerfStatus, /**< Takes real value as reference. */
569 kCpumMsrRdFn_IntelI7RaplPkgPowerInfo, /**< Takes real value as reference. */
570 kCpumMsrRdFn_IntelI7RaplDramPowerLimit, /**< Takes real value as reference. */
571 kCpumMsrRdFn_IntelI7RaplDramEnergyStatus,/**< Takes real value as reference. */
572 kCpumMsrRdFn_IntelI7RaplDramPerfStatus, /**< Takes real value as reference. */
573 kCpumMsrRdFn_IntelI7RaplDramPowerInfo, /**< Takes real value as reference. */
574 kCpumMsrRdFn_IntelI7RaplPp0PowerLimit, /**< Takes real value as reference. */
575 kCpumMsrRdFn_IntelI7RaplPp0EnergyStatus, /**< Takes real value as reference. */
576 kCpumMsrRdFn_IntelI7RaplPp0Policy, /**< Takes real value as reference. */
577 kCpumMsrRdFn_IntelI7RaplPp0PerfStatus, /**< Takes real value as reference. */
578 kCpumMsrRdFn_IntelI7RaplPp1PowerLimit, /**< Takes real value as reference. */
579 kCpumMsrRdFn_IntelI7RaplPp1EnergyStatus, /**< Takes real value as reference. */
580 kCpumMsrRdFn_IntelI7RaplPp1Policy, /**< Takes real value as reference. */
581 kCpumMsrRdFn_IntelI7IvyConfigTdpNominal, /**< Takes real value as reference. */
582 kCpumMsrRdFn_IntelI7IvyConfigTdpLevel1, /**< Takes real value as reference. */
583 kCpumMsrRdFn_IntelI7IvyConfigTdpLevel2, /**< Takes real value as reference. */
584 kCpumMsrRdFn_IntelI7IvyConfigTdpControl,
585 kCpumMsrRdFn_IntelI7IvyTurboActivationRatio,
586 kCpumMsrRdFn_IntelI7UncPerfGlobalCtrl,
587 kCpumMsrRdFn_IntelI7UncPerfGlobalStatus,
588 kCpumMsrRdFn_IntelI7UncPerfGlobalOvfCtrl,
589 kCpumMsrRdFn_IntelI7UncPerfFixedCtrCtrl,
590 kCpumMsrRdFn_IntelI7UncPerfFixedCtr,
591 kCpumMsrRdFn_IntelI7UncCBoxConfig,
592 kCpumMsrRdFn_IntelI7UncArbPerfCtrN,
593 kCpumMsrRdFn_IntelI7UncArbPerfEvtSelN,
594 kCpumMsrRdFn_IntelI7SmiCount,
595 kCpumMsrRdFn_IntelCore2EmttmCrTablesN, /**< Range value returned. */
596 kCpumMsrRdFn_IntelCore2SmmCStMiscInfo,
597 kCpumMsrRdFn_IntelCore1ExtConfig,
598 kCpumMsrRdFn_IntelCore1DtsCalControl,
599 kCpumMsrRdFn_IntelCore2PeciControl,
600 kCpumMsrRdFn_IntelAtSilvCoreC1Recidency,
601
602 kCpumMsrRdFn_P6LastBranchFromIp,
603 kCpumMsrRdFn_P6LastBranchToIp,
604 kCpumMsrRdFn_P6LastIntFromIp,
605 kCpumMsrRdFn_P6LastIntToIp,
606
607 kCpumMsrRdFn_AmdFam15hTscRate,
608 kCpumMsrRdFn_AmdFam15hLwpCfg,
609 kCpumMsrRdFn_AmdFam15hLwpCbAddr,
610 kCpumMsrRdFn_AmdFam10hMc4MiscN,
611 kCpumMsrRdFn_AmdK8PerfCtlN,
612 kCpumMsrRdFn_AmdK8PerfCtrN,
613 kCpumMsrRdFn_AmdK8SysCfg, /**< Range value returned. */
614 kCpumMsrRdFn_AmdK8HwCr,
615 kCpumMsrRdFn_AmdK8IorrBaseN,
616 kCpumMsrRdFn_AmdK8IorrMaskN,
617 kCpumMsrRdFn_AmdK8TopOfMemN,
618 kCpumMsrRdFn_AmdK8NbCfg1,
619 kCpumMsrRdFn_AmdK8McXcptRedir,
620 kCpumMsrRdFn_AmdK8CpuNameN,
621 kCpumMsrRdFn_AmdK8HwThermalCtrl, /**< Range value returned. */
622 kCpumMsrRdFn_AmdK8SwThermalCtrl,
623 kCpumMsrRdFn_AmdK8FidVidControl, /**< Range value returned. */
624 kCpumMsrRdFn_AmdK8FidVidStatus, /**< Range value returned. */
625 kCpumMsrRdFn_AmdK8McCtlMaskN,
626 kCpumMsrRdFn_AmdK8SmiOnIoTrapN,
627 kCpumMsrRdFn_AmdK8SmiOnIoTrapCtlSts,
628 kCpumMsrRdFn_AmdK8IntPendingMessage,
629 kCpumMsrRdFn_AmdK8SmiTriggerIoCycle,
630 kCpumMsrRdFn_AmdFam10hMmioCfgBaseAddr,
631 kCpumMsrRdFn_AmdFam10hTrapCtlMaybe,
632 kCpumMsrRdFn_AmdFam10hPStateCurLimit, /**< Returns range value. */
633 kCpumMsrRdFn_AmdFam10hPStateControl, /**< Returns range value. */
634 kCpumMsrRdFn_AmdFam10hPStateStatus, /**< Returns range value. */
635 kCpumMsrRdFn_AmdFam10hPStateN, /**< Returns range value. This isn't an register index! */
636 kCpumMsrRdFn_AmdFam10hCofVidControl, /**< Returns range value. */
637 kCpumMsrRdFn_AmdFam10hCofVidStatus, /**< Returns range value. */
638 kCpumMsrRdFn_AmdFam10hCStateIoBaseAddr,
639 kCpumMsrRdFn_AmdFam10hCpuWatchdogTimer,
640 kCpumMsrRdFn_AmdK8SmmBase,
641 kCpumMsrRdFn_AmdK8SmmAddr,
642 kCpumMsrRdFn_AmdK8SmmMask,
643 kCpumMsrRdFn_AmdK8VmCr,
644 kCpumMsrRdFn_AmdK8IgnNe,
645 kCpumMsrRdFn_AmdK8SmmCtl,
646 kCpumMsrRdFn_AmdK8VmHSavePa,
647 kCpumMsrRdFn_AmdFam10hVmLockKey,
648 kCpumMsrRdFn_AmdFam10hSmmLockKey,
649 kCpumMsrRdFn_AmdFam10hLocalSmiStatus,
650 kCpumMsrRdFn_AmdFam10hOsVisWrkIdLength,
651 kCpumMsrRdFn_AmdFam10hOsVisWrkStatus,
652 kCpumMsrRdFn_AmdFam16hL2IPerfCtlN,
653 kCpumMsrRdFn_AmdFam16hL2IPerfCtrN,
654 kCpumMsrRdFn_AmdFam15hNorthbridgePerfCtlN,
655 kCpumMsrRdFn_AmdFam15hNorthbridgePerfCtrN,
656 kCpumMsrRdFn_AmdK7MicrocodeCtl, /**< Returns range value. */
657 kCpumMsrRdFn_AmdK7ClusterIdMaybe, /**< Returns range value. */
658 kCpumMsrRdFn_AmdK8CpuIdCtlStd07hEbax,
659 kCpumMsrRdFn_AmdK8CpuIdCtlStd06hEcx,
660 kCpumMsrRdFn_AmdK8CpuIdCtlStd01hEdcx,
661 kCpumMsrRdFn_AmdK8CpuIdCtlExt01hEdcx,
662 kCpumMsrRdFn_AmdK8PatchLevel, /**< Returns range value. */
663 kCpumMsrRdFn_AmdK7DebugStatusMaybe,
664 kCpumMsrRdFn_AmdK7BHTraceBaseMaybe,
665 kCpumMsrRdFn_AmdK7BHTracePtrMaybe,
666 kCpumMsrRdFn_AmdK7BHTraceLimitMaybe,
667 kCpumMsrRdFn_AmdK7HardwareDebugToolCfgMaybe,
668 kCpumMsrRdFn_AmdK7FastFlushCountMaybe,
669 kCpumMsrRdFn_AmdK7NodeId,
670 kCpumMsrRdFn_AmdK7DrXAddrMaskN, /**< Takes register index. */
671 kCpumMsrRdFn_AmdK7Dr0DataMatchMaybe,
672 kCpumMsrRdFn_AmdK7Dr0DataMaskMaybe,
673 kCpumMsrRdFn_AmdK7LoadStoreCfg,
674 kCpumMsrRdFn_AmdK7InstrCacheCfg,
675 kCpumMsrRdFn_AmdK7DataCacheCfg,
676 kCpumMsrRdFn_AmdK7BusUnitCfg,
677 kCpumMsrRdFn_AmdK7DebugCtl2Maybe,
678 kCpumMsrRdFn_AmdFam15hFpuCfg,
679 kCpumMsrRdFn_AmdFam15hDecoderCfg,
680 kCpumMsrRdFn_AmdFam10hBusUnitCfg2,
681 kCpumMsrRdFn_AmdFam15hCombUnitCfg,
682 kCpumMsrRdFn_AmdFam15hCombUnitCfg2,
683 kCpumMsrRdFn_AmdFam15hCombUnitCfg3,
684 kCpumMsrRdFn_AmdFam15hExecUnitCfg,
685 kCpumMsrRdFn_AmdFam15hLoadStoreCfg2,
686 kCpumMsrRdFn_AmdFam10hIbsFetchCtl,
687 kCpumMsrRdFn_AmdFam10hIbsFetchLinAddr,
688 kCpumMsrRdFn_AmdFam10hIbsFetchPhysAddr,
689 kCpumMsrRdFn_AmdFam10hIbsOpExecCtl,
690 kCpumMsrRdFn_AmdFam10hIbsOpRip,
691 kCpumMsrRdFn_AmdFam10hIbsOpData,
692 kCpumMsrRdFn_AmdFam10hIbsOpData2,
693 kCpumMsrRdFn_AmdFam10hIbsOpData3,
694 kCpumMsrRdFn_AmdFam10hIbsDcLinAddr,
695 kCpumMsrRdFn_AmdFam10hIbsDcPhysAddr,
696 kCpumMsrRdFn_AmdFam10hIbsCtl,
697 kCpumMsrRdFn_AmdFam14hIbsBrTarget,
698
699 kCpumMsrRdFn_Gim,
700
701 /** End of valid MSR read function indexes. */
702 kCpumMsrRdFn_End
703} CPUMMSRRDFN;
704
705/**
706 * MSR write functions.
707 */
708typedef enum CPUMMSRWRFN
709{
710 /** Invalid zero value. */
711 kCpumMsrWrFn_Invalid = 0,
712 /** Writes are ignored, the fWrGpMask is observed though. */
713 kCpumMsrWrFn_IgnoreWrite,
714 /** Writes cause GP(0) to be raised, the fWrGpMask should be UINT64_MAX. */
715 kCpumMsrWrFn_ReadOnly,
716 /** Alias to the MSR range starting at the MSR given by
717 * CPUMMSRRANGE::uValue. Must be used in pair with
718 * kCpumMsrRdFn_MsrAlias. */
719 kCpumMsrWrFn_MsrAlias,
720
721 kCpumMsrWrFn_Ia32P5McAddr,
722 kCpumMsrWrFn_Ia32P5McType,
723 kCpumMsrWrFn_Ia32TimestampCounter,
724 kCpumMsrWrFn_Ia32ApicBase,
725 kCpumMsrWrFn_Ia32FeatureControl,
726 kCpumMsrWrFn_Ia32BiosSignId,
727 kCpumMsrWrFn_Ia32BiosUpdateTrigger,
728 kCpumMsrWrFn_Ia32SmmMonitorCtl,
729 kCpumMsrWrFn_Ia32PmcN,
730 kCpumMsrWrFn_Ia32MonitorFilterLineSize,
731 kCpumMsrWrFn_Ia32MPerf,
732 kCpumMsrWrFn_Ia32APerf,
733 kCpumMsrWrFn_Ia32MtrrPhysBaseN, /**< Takes register number. */
734 kCpumMsrWrFn_Ia32MtrrPhysMaskN, /**< Takes register number. */
735 kCpumMsrWrFn_Ia32MtrrFixed, /**< Takes CPUMCPU offset. */
736 kCpumMsrWrFn_Ia32MtrrDefType,
737 kCpumMsrWrFn_Ia32Pat,
738 kCpumMsrWrFn_Ia32SysEnterCs,
739 kCpumMsrWrFn_Ia32SysEnterEsp,
740 kCpumMsrWrFn_Ia32SysEnterEip,
741 kCpumMsrWrFn_Ia32McgStatus,
742 kCpumMsrWrFn_Ia32McgCtl,
743 kCpumMsrWrFn_Ia32DebugCtl,
744 kCpumMsrWrFn_Ia32SmrrPhysBase,
745 kCpumMsrWrFn_Ia32SmrrPhysMask,
746 kCpumMsrWrFn_Ia32PlatformDcaCap,
747 kCpumMsrWrFn_Ia32Dca0Cap,
748 kCpumMsrWrFn_Ia32PerfEvtSelN, /**< Range value indicates the register number. */
749 kCpumMsrWrFn_Ia32PerfStatus,
750 kCpumMsrWrFn_Ia32PerfCtl,
751 kCpumMsrWrFn_Ia32FixedCtrN, /**< Takes register number of start of range. */
752 kCpumMsrWrFn_Ia32PerfCapabilities,
753 kCpumMsrWrFn_Ia32FixedCtrCtrl,
754 kCpumMsrWrFn_Ia32PerfGlobalStatus,
755 kCpumMsrWrFn_Ia32PerfGlobalCtrl,
756 kCpumMsrWrFn_Ia32PerfGlobalOvfCtrl,
757 kCpumMsrWrFn_Ia32PebsEnable,
758 kCpumMsrWrFn_Ia32ClockModulation,
759 kCpumMsrWrFn_Ia32ThermInterrupt,
760 kCpumMsrWrFn_Ia32ThermStatus,
761 kCpumMsrWrFn_Ia32Therm2Ctl,
762 kCpumMsrWrFn_Ia32MiscEnable,
763 kCpumMsrWrFn_Ia32McCtlStatusAddrMiscN, /**< Takes bank number. */
764 kCpumMsrWrFn_Ia32McNCtl2, /**< Takes register number of start of range. */
765 kCpumMsrWrFn_Ia32DsArea,
766 kCpumMsrWrFn_Ia32TscDeadline,
767 kCpumMsrWrFn_Ia32X2ApicN,
768 kCpumMsrWrFn_Ia32DebugInterface,
769 kCpumMsrWrFn_Ia32SpecCtrl,
770 kCpumMsrWrFn_Ia32PredCmd,
771 kCpumMsrWrFn_Ia32FlushCmd,
772
773 kCpumMsrWrFn_Amd64Efer,
774 kCpumMsrWrFn_Amd64SyscallTarget,
775 kCpumMsrWrFn_Amd64LongSyscallTarget,
776 kCpumMsrWrFn_Amd64CompSyscallTarget,
777 kCpumMsrWrFn_Amd64SyscallFlagMask,
778 kCpumMsrWrFn_Amd64FsBase,
779 kCpumMsrWrFn_Amd64GsBase,
780 kCpumMsrWrFn_Amd64KernelGsBase,
781 kCpumMsrWrFn_Amd64TscAux,
782 kCpumMsrWrFn_IntelEblCrPowerOn,
783 kCpumMsrWrFn_IntelP4EbcHardPowerOn,
784 kCpumMsrWrFn_IntelP4EbcSoftPowerOn,
785 kCpumMsrWrFn_IntelP4EbcFrequencyId,
786 kCpumMsrWrFn_IntelFlexRatio,
787 kCpumMsrWrFn_IntelPkgCStConfigControl,
788 kCpumMsrWrFn_IntelPmgIoCaptureBase,
789 kCpumMsrWrFn_IntelLastBranchFromToN,
790 kCpumMsrWrFn_IntelLastBranchFromN,
791 kCpumMsrWrFn_IntelLastBranchToN,
792 kCpumMsrWrFn_IntelLastBranchTos,
793 kCpumMsrWrFn_IntelBblCrCtl,
794 kCpumMsrWrFn_IntelBblCrCtl3,
795 kCpumMsrWrFn_IntelI7TemperatureTarget,
796 kCpumMsrWrFn_IntelI7MsrOffCoreResponseN, /**< Takes register number. */
797 kCpumMsrWrFn_IntelI7MiscPwrMgmt,
798 kCpumMsrWrFn_IntelP6CrN,
799 kCpumMsrWrFn_IntelCpuId1FeatureMaskEcdx,
800 kCpumMsrWrFn_IntelCpuId1FeatureMaskEax,
801 kCpumMsrWrFn_IntelCpuId80000001FeatureMaskEcdx,
802 kCpumMsrWrFn_IntelI7SandyAesNiCtl,
803 kCpumMsrWrFn_IntelI7TurboRatioLimit,
804 kCpumMsrWrFn_IntelI7LbrSelect,
805 kCpumMsrWrFn_IntelI7SandyErrorControl,
806 kCpumMsrWrFn_IntelI7PowerCtl,
807 kCpumMsrWrFn_IntelI7SandyPebsNumAlt,
808 kCpumMsrWrFn_IntelI7PebsLdLat,
809 kCpumMsrWrFn_IntelI7SandyVrCurrentConfig,
810 kCpumMsrWrFn_IntelI7SandyVrMiscConfig,
811 kCpumMsrWrFn_IntelI7SandyRaplPowerUnit, /**< R/O but found writable bits on a Silvermont CPU here. */
812 kCpumMsrWrFn_IntelI7SandyPkgCnIrtlN,
813 kCpumMsrWrFn_IntelI7SandyPkgC2Residency, /**< R/O but found writable bits on a Silvermont CPU here. */
814 kCpumMsrWrFn_IntelI7RaplPkgPowerLimit,
815 kCpumMsrWrFn_IntelI7RaplDramPowerLimit,
816 kCpumMsrWrFn_IntelI7RaplPp0PowerLimit,
817 kCpumMsrWrFn_IntelI7RaplPp0Policy,
818 kCpumMsrWrFn_IntelI7RaplPp1PowerLimit,
819 kCpumMsrWrFn_IntelI7RaplPp1Policy,
820 kCpumMsrWrFn_IntelI7IvyConfigTdpControl,
821 kCpumMsrWrFn_IntelI7IvyTurboActivationRatio,
822 kCpumMsrWrFn_IntelI7UncPerfGlobalCtrl,
823 kCpumMsrWrFn_IntelI7UncPerfGlobalStatus,
824 kCpumMsrWrFn_IntelI7UncPerfGlobalOvfCtrl,
825 kCpumMsrWrFn_IntelI7UncPerfFixedCtrCtrl,
826 kCpumMsrWrFn_IntelI7UncPerfFixedCtr,
827 kCpumMsrWrFn_IntelI7UncArbPerfCtrN,
828 kCpumMsrWrFn_IntelI7UncArbPerfEvtSelN,
829 kCpumMsrWrFn_IntelCore2EmttmCrTablesN,
830 kCpumMsrWrFn_IntelCore2SmmCStMiscInfo,
831 kCpumMsrWrFn_IntelCore1ExtConfig,
832 kCpumMsrWrFn_IntelCore1DtsCalControl,
833 kCpumMsrWrFn_IntelCore2PeciControl,
834
835 kCpumMsrWrFn_P6LastIntFromIp,
836 kCpumMsrWrFn_P6LastIntToIp,
837
838 kCpumMsrWrFn_AmdFam15hTscRate,
839 kCpumMsrWrFn_AmdFam15hLwpCfg,
840 kCpumMsrWrFn_AmdFam15hLwpCbAddr,
841 kCpumMsrWrFn_AmdFam10hMc4MiscN,
842 kCpumMsrWrFn_AmdK8PerfCtlN,
843 kCpumMsrWrFn_AmdK8PerfCtrN,
844 kCpumMsrWrFn_AmdK8SysCfg,
845 kCpumMsrWrFn_AmdK8HwCr,
846 kCpumMsrWrFn_AmdK8IorrBaseN,
847 kCpumMsrWrFn_AmdK8IorrMaskN,
848 kCpumMsrWrFn_AmdK8TopOfMemN,
849 kCpumMsrWrFn_AmdK8NbCfg1,
850 kCpumMsrWrFn_AmdK8McXcptRedir,
851 kCpumMsrWrFn_AmdK8CpuNameN,
852 kCpumMsrWrFn_AmdK8HwThermalCtrl,
853 kCpumMsrWrFn_AmdK8SwThermalCtrl,
854 kCpumMsrWrFn_AmdK8FidVidControl,
855 kCpumMsrWrFn_AmdK8McCtlMaskN,
856 kCpumMsrWrFn_AmdK8SmiOnIoTrapN,
857 kCpumMsrWrFn_AmdK8SmiOnIoTrapCtlSts,
858 kCpumMsrWrFn_AmdK8IntPendingMessage,
859 kCpumMsrWrFn_AmdK8SmiTriggerIoCycle,
860 kCpumMsrWrFn_AmdFam10hMmioCfgBaseAddr,
861 kCpumMsrWrFn_AmdFam10hTrapCtlMaybe,
862 kCpumMsrWrFn_AmdFam10hPStateControl,
863 kCpumMsrWrFn_AmdFam10hPStateStatus,
864 kCpumMsrWrFn_AmdFam10hPStateN,
865 kCpumMsrWrFn_AmdFam10hCofVidControl,
866 kCpumMsrWrFn_AmdFam10hCofVidStatus,
867 kCpumMsrWrFn_AmdFam10hCStateIoBaseAddr,
868 kCpumMsrWrFn_AmdFam10hCpuWatchdogTimer,
869 kCpumMsrWrFn_AmdK8SmmBase,
870 kCpumMsrWrFn_AmdK8SmmAddr,
871 kCpumMsrWrFn_AmdK8SmmMask,
872 kCpumMsrWrFn_AmdK8VmCr,
873 kCpumMsrWrFn_AmdK8IgnNe,
874 kCpumMsrWrFn_AmdK8SmmCtl,
875 kCpumMsrWrFn_AmdK8VmHSavePa,
876 kCpumMsrWrFn_AmdFam10hVmLockKey,
877 kCpumMsrWrFn_AmdFam10hSmmLockKey,
878 kCpumMsrWrFn_AmdFam10hLocalSmiStatus,
879 kCpumMsrWrFn_AmdFam10hOsVisWrkIdLength,
880 kCpumMsrWrFn_AmdFam10hOsVisWrkStatus,
881 kCpumMsrWrFn_AmdFam16hL2IPerfCtlN,
882 kCpumMsrWrFn_AmdFam16hL2IPerfCtrN,
883 kCpumMsrWrFn_AmdFam15hNorthbridgePerfCtlN,
884 kCpumMsrWrFn_AmdFam15hNorthbridgePerfCtrN,
885 kCpumMsrWrFn_AmdK7MicrocodeCtl,
886 kCpumMsrWrFn_AmdK7ClusterIdMaybe,
887 kCpumMsrWrFn_AmdK8CpuIdCtlStd07hEbax,
888 kCpumMsrWrFn_AmdK8CpuIdCtlStd06hEcx,
889 kCpumMsrWrFn_AmdK8CpuIdCtlStd01hEdcx,
890 kCpumMsrWrFn_AmdK8CpuIdCtlExt01hEdcx,
891 kCpumMsrWrFn_AmdK8PatchLoader,
892 kCpumMsrWrFn_AmdK7DebugStatusMaybe,
893 kCpumMsrWrFn_AmdK7BHTraceBaseMaybe,
894 kCpumMsrWrFn_AmdK7BHTracePtrMaybe,
895 kCpumMsrWrFn_AmdK7BHTraceLimitMaybe,
896 kCpumMsrWrFn_AmdK7HardwareDebugToolCfgMaybe,
897 kCpumMsrWrFn_AmdK7FastFlushCountMaybe,
898 kCpumMsrWrFn_AmdK7NodeId,
899 kCpumMsrWrFn_AmdK7DrXAddrMaskN, /**< Takes register index. */
900 kCpumMsrWrFn_AmdK7Dr0DataMatchMaybe,
901 kCpumMsrWrFn_AmdK7Dr0DataMaskMaybe,
902 kCpumMsrWrFn_AmdK7LoadStoreCfg,
903 kCpumMsrWrFn_AmdK7InstrCacheCfg,
904 kCpumMsrWrFn_AmdK7DataCacheCfg,
905 kCpumMsrWrFn_AmdK7BusUnitCfg,
906 kCpumMsrWrFn_AmdK7DebugCtl2Maybe,
907 kCpumMsrWrFn_AmdFam15hFpuCfg,
908 kCpumMsrWrFn_AmdFam15hDecoderCfg,
909 kCpumMsrWrFn_AmdFam10hBusUnitCfg2,
910 kCpumMsrWrFn_AmdFam15hCombUnitCfg,
911 kCpumMsrWrFn_AmdFam15hCombUnitCfg2,
912 kCpumMsrWrFn_AmdFam15hCombUnitCfg3,
913 kCpumMsrWrFn_AmdFam15hExecUnitCfg,
914 kCpumMsrWrFn_AmdFam15hLoadStoreCfg2,
915 kCpumMsrWrFn_AmdFam10hIbsFetchCtl,
916 kCpumMsrWrFn_AmdFam10hIbsFetchLinAddr,
917 kCpumMsrWrFn_AmdFam10hIbsFetchPhysAddr,
918 kCpumMsrWrFn_AmdFam10hIbsOpExecCtl,
919 kCpumMsrWrFn_AmdFam10hIbsOpRip,
920 kCpumMsrWrFn_AmdFam10hIbsOpData,
921 kCpumMsrWrFn_AmdFam10hIbsOpData2,
922 kCpumMsrWrFn_AmdFam10hIbsOpData3,
923 kCpumMsrWrFn_AmdFam10hIbsDcLinAddr,
924 kCpumMsrWrFn_AmdFam10hIbsDcPhysAddr,
925 kCpumMsrWrFn_AmdFam10hIbsCtl,
926 kCpumMsrWrFn_AmdFam14hIbsBrTarget,
927
928 kCpumMsrWrFn_Gim,
929
930 /** End of valid MSR write function indexes. */
931 kCpumMsrWrFn_End
932} CPUMMSRWRFN;
933
934/**
935 * MSR range.
936 */
937typedef struct CPUMMSRRANGE
938{
939 /** The first MSR. [0] */
940 uint32_t uFirst;
941 /** The last MSR. [4] */
942 uint32_t uLast;
943 /** The read function (CPUMMSRRDFN). [8] */
944 uint16_t enmRdFn;
945 /** The write function (CPUMMSRWRFN). [10] */
946 uint16_t enmWrFn;
947 /** The offset of the 64-bit MSR value relative to the start of CPUMCPU.
948 * UINT16_MAX if not used by the read and write functions. [12] */
949 uint32_t offCpumCpu : 24;
950 /** Reserved for future hacks. [15] */
951 uint32_t fReserved : 8;
952 /** The init/read value. [16]
953 * When enmRdFn is kCpumMsrRdFn_INIT_VALUE, this is the value returned on RDMSR.
954 * offCpumCpu must be UINT16_MAX in that case, otherwise it must be a valid
955 * offset into CPUM. */
956 uint64_t uValue;
957 /** The bits to ignore when writing. [24] */
958 uint64_t fWrIgnMask;
959 /** The bits that will cause a GP(0) when writing. [32]
960 * This is always checked prior to calling the write function. Using
961 * UINT64_MAX effectively marks the MSR as read-only. */
962 uint64_t fWrGpMask;
963 /** The register name, if applicable. [40] */
964 char szName[56];
965
966 /** The number of reads. */
967 STAMCOUNTER cReads;
968 /** The number of writes. */
969 STAMCOUNTER cWrites;
970 /** The number of times ignored bits were written. */
971 STAMCOUNTER cIgnoredBits;
972 /** The number of GPs generated. */
973 STAMCOUNTER cGps;
974} CPUMMSRRANGE;
975#ifndef VBOX_FOR_DTRACE_LIB
976AssertCompileSize(CPUMMSRRANGE, 128);
977#endif
978/** Pointer to an MSR range. */
979typedef CPUMMSRRANGE *PCPUMMSRRANGE;
980/** Pointer to a const MSR range. */
981typedef CPUMMSRRANGE const *PCCPUMMSRRANGE;
982
983
984/**
985 * MSRs which are required while exploding features.
986 */
987typedef struct CPUMMSRS
988{
989 union
990 {
991 VMXMSRS vmx;
992 SVMMSRS svm;
993 } hwvirt;
994} CPUMMSRS;
995/** Pointer to an CPUMMSRS struct. */
996typedef CPUMMSRS *PCPUMMSRS;
997/** Pointer to a const CPUMMSRS struct. */
998typedef CPUMMSRS const *PCCPUMMSRS;
999
1000
1001/**
1002 * CPU features and quirks.
1003 * This is mostly exploded CPUID info.
1004 */
1005typedef struct CPUMFEATURES
1006{
1007 /** The CPU vendor (CPUMCPUVENDOR). */
1008 uint8_t enmCpuVendor;
1009 /** The CPU family. */
1010 uint8_t uFamily;
1011 /** The CPU model. */
1012 uint8_t uModel;
1013 /** The CPU stepping. */
1014 uint8_t uStepping;
1015 /** The microarchitecture. */
1016#ifndef VBOX_FOR_DTRACE_LIB
1017 CPUMMICROARCH enmMicroarch;
1018#else
1019 uint32_t enmMicroarch;
1020#endif
1021 /** The maximum physical address width of the CPU. */
1022 uint8_t cMaxPhysAddrWidth;
1023 /** The maximum linear address width of the CPU. */
1024 uint8_t cMaxLinearAddrWidth;
1025 /** Max size of the extended state (or FPU state if no XSAVE). */
1026 uint16_t cbMaxExtendedState;
1027
1028 /** Supports MSRs. */
1029 uint32_t fMsr : 1;
1030 /** Supports the page size extension (4/2 MB pages). */
1031 uint32_t fPse : 1;
1032 /** Supports 36-bit page size extension (4 MB pages can map memory above
1033 * 4GB). */
1034 uint32_t fPse36 : 1;
1035 /** Supports physical address extension (PAE). */
1036 uint32_t fPae : 1;
1037 /** Supports page-global extension (PGE). */
1038 uint32_t fPge : 1;
1039 /** Page attribute table (PAT) support (page level cache control). */
1040 uint32_t fPat : 1;
1041 /** Supports the FXSAVE and FXRSTOR instructions. */
1042 uint32_t fFxSaveRstor : 1;
1043 /** Supports the XSAVE and XRSTOR instructions. */
1044 uint32_t fXSaveRstor : 1;
1045 /** The XSAVE/XRSTOR bit in CR4 has been set (only applicable for host!). */
1046 uint32_t fOpSysXSaveRstor : 1;
1047 /** Supports MMX. */
1048 uint32_t fMmx : 1;
1049 /** Supports AMD extensions to MMX instructions. */
1050 uint32_t fAmdMmxExts : 1;
1051 /** Supports SSE. */
1052 uint32_t fSse : 1;
1053 /** Supports SSE2. */
1054 uint32_t fSse2 : 1;
1055 /** Supports SSE3. */
1056 uint32_t fSse3 : 1;
1057 /** Supports SSSE3. */
1058 uint32_t fSsse3 : 1;
1059 /** Supports SSE4.1. */
1060 uint32_t fSse41 : 1;
1061 /** Supports SSE4.2. */
1062 uint32_t fSse42 : 1;
1063 /** Supports AVX. */
1064 uint32_t fAvx : 1;
1065 /** Supports AVX2. */
1066 uint32_t fAvx2 : 1;
1067 /** Supports AVX512 foundation. */
1068 uint32_t fAvx512Foundation : 1;
1069 /** Supports RDTSC. */
1070 uint32_t fTsc : 1;
1071 /** Intel SYSENTER/SYSEXIT support */
1072 uint32_t fSysEnter : 1;
1073 /** First generation APIC. */
1074 uint32_t fApic : 1;
1075 /** Second generation APIC. */
1076 uint32_t fX2Apic : 1;
1077 /** Hypervisor present. */
1078 uint32_t fHypervisorPresent : 1;
1079 /** MWAIT & MONITOR instructions supported. */
1080 uint32_t fMonitorMWait : 1;
1081 /** MWAIT Extensions present. */
1082 uint32_t fMWaitExtensions : 1;
1083 /** Supports CMPXCHG16B in 64-bit mode. */
1084 uint32_t fMovCmpXchg16b : 1;
1085 /** Supports CLFLUSH. */
1086 uint32_t fClFlush : 1;
1087 /** Supports CLFLUSHOPT. */
1088 uint32_t fClFlushOpt : 1;
1089 /** Supports IA32_PRED_CMD.IBPB. */
1090 uint32_t fIbpb : 1;
1091 /** Supports IA32_SPEC_CTRL.IBRS. */
1092 uint32_t fIbrs : 1;
1093 /** Supports IA32_SPEC_CTRL.STIBP. */
1094 uint32_t fStibp : 1;
1095 /** Supports IA32_FLUSH_CMD. */
1096 uint32_t fFlushCmd : 1;
1097 /** Supports IA32_ARCH_CAP. */
1098 uint32_t fArchCap : 1;
1099 /** Supports MD_CLEAR functionality (VERW, IA32_FLUSH_CMD). */
1100 uint32_t fMdsClear : 1;
1101 /** Supports PCID. */
1102 uint32_t fPcid : 1;
1103 /** Supports INVPCID. */
1104 uint32_t fInvpcid : 1;
1105 /** Supports read/write FSGSBASE instructions. */
1106 uint32_t fFsGsBase : 1;
1107
1108 /** Supports AMD 3DNow instructions. */
1109 uint32_t f3DNow : 1;
1110 /** Supports the 3DNow/AMD64 prefetch instructions (could be nops). */
1111 uint32_t f3DNowPrefetch : 1;
1112
1113 /** AMD64: Supports long mode. */
1114 uint32_t fLongMode : 1;
1115 /** AMD64: SYSCALL/SYSRET support. */
1116 uint32_t fSysCall : 1;
1117 /** AMD64: No-execute page table bit. */
1118 uint32_t fNoExecute : 1;
1119 /** AMD64: Supports LAHF & SAHF instructions in 64-bit mode. */
1120 uint32_t fLahfSahf : 1;
1121 /** AMD64: Supports RDTSCP. */
1122 uint32_t fRdTscP : 1;
1123 /** AMD64: Supports MOV CR8 in 32-bit code (lock prefix hack). */
1124 uint32_t fMovCr8In32Bit : 1;
1125 /** AMD64: Supports XOP (similar to VEX3/AVX). */
1126 uint32_t fXop : 1;
1127
1128 /** Indicates that FPU instruction and data pointers may leak.
1129 * This generally applies to recent AMD CPUs, where the FPU IP and DP pointer
1130 * is only saved and restored if an exception is pending. */
1131 uint32_t fLeakyFxSR : 1;
1132
1133 /** AMD64: Supports AMD SVM. */
1134 uint32_t fSvm : 1;
1135
1136 /** Support for Intel VMX. */
1137 uint32_t fVmx : 1;
1138
1139 /** Indicates that speculative execution control CPUID bits and MSRs are exposed.
1140 * The details are different for Intel and AMD but both have similar
1141 * functionality. */
1142 uint32_t fSpeculationControl : 1;
1143
1144 /** MSR_IA32_ARCH_CAPABILITIES: RDCL_NO (bit 0).
1145 * @remarks Only safe use after CPUM ring-0 init! */
1146 uint32_t fArchRdclNo : 1;
1147 /** MSR_IA32_ARCH_CAPABILITIES: IBRS_ALL (bit 1).
1148 * @remarks Only safe use after CPUM ring-0 init! */
1149 uint32_t fArchIbrsAll : 1;
1150 /** MSR_IA32_ARCH_CAPABILITIES: RSB Override (bit 2).
1151 * @remarks Only safe use after CPUM ring-0 init! */
1152 uint32_t fArchRsbOverride : 1;
1153 /** MSR_IA32_ARCH_CAPABILITIES: RSB Override (bit 3).
1154 * @remarks Only safe use after CPUM ring-0 init! */
1155 uint32_t fArchVmmNeedNotFlushL1d : 1;
1156 /** MSR_IA32_ARCH_CAPABILITIES: MDS_NO (bit 4).
1157 * @remarks Only safe use after CPUM ring-0 init! */
1158 uint32_t fArchMdsNo : 1;
1159
1160 /** Alignment padding / reserved for future use. */
1161 uint32_t fPadding : 7;
1162
1163 /** SVM: Supports Nested-paging. */
1164 uint32_t fSvmNestedPaging : 1;
1165 /** SVM: Support LBR (Last Branch Record) virtualization. */
1166 uint32_t fSvmLbrVirt : 1;
1167 /** SVM: Supports SVM lock. */
1168 uint32_t fSvmSvmLock : 1;
1169 /** SVM: Supports Next RIP save. */
1170 uint32_t fSvmNextRipSave : 1;
1171 /** SVM: Supports TSC rate MSR. */
1172 uint32_t fSvmTscRateMsr : 1;
1173 /** SVM: Supports VMCB clean bits. */
1174 uint32_t fSvmVmcbClean : 1;
1175 /** SVM: Supports Flush-by-ASID. */
1176 uint32_t fSvmFlusbByAsid : 1;
1177 /** SVM: Supports decode assist. */
1178 uint32_t fSvmDecodeAssists : 1;
1179 /** SVM: Supports Pause filter. */
1180 uint32_t fSvmPauseFilter : 1;
1181 /** SVM: Supports Pause filter threshold. */
1182 uint32_t fSvmPauseFilterThreshold : 1;
1183 /** SVM: Supports AVIC (Advanced Virtual Interrupt Controller). */
1184 uint32_t fSvmAvic : 1;
1185 /** SVM: Supports Virtualized VMSAVE/VMLOAD. */
1186 uint32_t fSvmVirtVmsaveVmload : 1;
1187 /** SVM: Supports VGIF (Virtual Global Interrupt Flag). */
1188 uint32_t fSvmVGif : 1;
1189 /** SVM: Supports GMET (Guest Mode Execute Trap Extension). */
1190 uint32_t fSvmGmet : 1;
1191 /** SVM: Padding / reserved for future features. */
1192 uint32_t fSvmPadding0 : 18;
1193 /** SVM: Maximum supported ASID. */
1194 uint32_t uSvmMaxAsid;
1195
1196 /** VMX: Maximum physical address width. */
1197 uint8_t cVmxMaxPhysAddrWidth;
1198 /** VMX: Padding / reserved for future. */
1199 uint8_t abVmxPadding[3];
1200 /** VMX: Padding / reserved for future. */
1201 uint32_t fVmxPadding0;
1202
1203 /** @name VMX basic controls.
1204 * @{ */
1205 /** VMX: Supports INS/OUTS VM-exit instruction info. */
1206 uint32_t fVmxInsOutInfo : 1;
1207 /** @} */
1208
1209 /** @name VMX Pin-based controls.
1210 * @{ */
1211 /** VMX: Supports external interrupt VM-exit. */
1212 uint32_t fVmxExtIntExit : 1;
1213 /** VMX: Supports NMI VM-exit. */
1214 uint32_t fVmxNmiExit : 1;
1215 /** VMX: Supports Virtual NMIs. */
1216 uint32_t fVmxVirtNmi : 1;
1217 /** VMX: Supports preemption timer. */
1218 uint32_t fVmxPreemptTimer : 1;
1219 /** VMX: Supports posted interrupts. */
1220 uint32_t fVmxPostedInt : 1;
1221 /** @} */
1222
1223 /** @name VMX Processor-based controls.
1224 * @{ */
1225 /** VMX: Supports Interrupt-window exiting. */
1226 uint32_t fVmxIntWindowExit : 1;
1227 /** VMX: Supports TSC offsetting. */
1228 uint32_t fVmxTscOffsetting : 1;
1229 /** VMX: Supports HLT exiting. */
1230 uint32_t fVmxHltExit : 1;
1231 /** VMX: Supports INVLPG exiting. */
1232 uint32_t fVmxInvlpgExit : 1;
1233 /** VMX: Supports MWAIT exiting. */
1234 uint32_t fVmxMwaitExit : 1;
1235 /** VMX: Supports RDPMC exiting. */
1236 uint32_t fVmxRdpmcExit : 1;
1237 /** VMX: Supports RDTSC exiting. */
1238 uint32_t fVmxRdtscExit : 1;
1239 /** VMX: Supports CR3-load exiting. */
1240 uint32_t fVmxCr3LoadExit : 1;
1241 /** VMX: Supports CR3-store exiting. */
1242 uint32_t fVmxCr3StoreExit : 1;
1243 /** VMX: Supports tertiary processor-based VM-execution controls. */
1244 uint32_t fVmxTertiaryExecCtls : 1;
1245 /** VMX: Supports CR8-load exiting. */
1246 uint32_t fVmxCr8LoadExit : 1;
1247 /** VMX: Supports CR8-store exiting. */
1248 uint32_t fVmxCr8StoreExit : 1;
1249 /** VMX: Supports TPR shadow. */
1250 uint32_t fVmxUseTprShadow : 1;
1251 /** VMX: Supports NMI-window exiting. */
1252 uint32_t fVmxNmiWindowExit : 1;
1253 /** VMX: Supports Mov-DRx exiting. */
1254 uint32_t fVmxMovDRxExit : 1;
1255 /** VMX: Supports Unconditional I/O exiting. */
1256 uint32_t fVmxUncondIoExit : 1;
1257 /** VMX: Supportgs I/O bitmaps. */
1258 uint32_t fVmxUseIoBitmaps : 1;
1259 /** VMX: Supports Monitor Trap Flag. */
1260 uint32_t fVmxMonitorTrapFlag : 1;
1261 /** VMX: Supports MSR bitmap. */
1262 uint32_t fVmxUseMsrBitmaps : 1;
1263 /** VMX: Supports MONITOR exiting. */
1264 uint32_t fVmxMonitorExit : 1;
1265 /** VMX: Supports PAUSE exiting. */
1266 uint32_t fVmxPauseExit : 1;
1267 /** VMX: Supports secondary processor-based VM-execution controls. */
1268 uint32_t fVmxSecondaryExecCtls : 1;
1269 /** @} */
1270
1271 /** @name VMX Secondary processor-based controls.
1272 * @{ */
1273 /** VMX: Supports virtualize-APIC access. */
1274 uint32_t fVmxVirtApicAccess : 1;
1275 /** VMX: Supports EPT (Extended Page Tables). */
1276 uint32_t fVmxEpt : 1;
1277 /** VMX: Supports descriptor-table exiting. */
1278 uint32_t fVmxDescTableExit : 1;
1279 /** VMX: Supports RDTSCP. */
1280 uint32_t fVmxRdtscp : 1;
1281 /** VMX: Supports virtualize-x2APIC mode. */
1282 uint32_t fVmxVirtX2ApicMode : 1;
1283 /** VMX: Supports VPID. */
1284 uint32_t fVmxVpid : 1;
1285 /** VMX: Supports WBIND exiting. */
1286 uint32_t fVmxWbinvdExit : 1;
1287 /** VMX: Supports Unrestricted guest. */
1288 uint32_t fVmxUnrestrictedGuest : 1;
1289 /** VMX: Supports APIC-register virtualization. */
1290 uint32_t fVmxApicRegVirt : 1;
1291 /** VMX: Supports virtual-interrupt delivery. */
1292 uint32_t fVmxVirtIntDelivery : 1;
1293 /** VMX: Supports Pause-loop exiting. */
1294 uint32_t fVmxPauseLoopExit : 1;
1295 /** VMX: Supports RDRAND exiting. */
1296 uint32_t fVmxRdrandExit : 1;
1297 /** VMX: Supports INVPCID. */
1298 uint32_t fVmxInvpcid : 1;
1299 /** VMX: Supports VM functions. */
1300 uint32_t fVmxVmFunc : 1;
1301 /** VMX: Supports VMCS shadowing. */
1302 uint32_t fVmxVmcsShadowing : 1;
1303 /** VMX: Supports RDSEED exiting. */
1304 uint32_t fVmxRdseedExit : 1;
1305 /** VMX: Supports PML. */
1306 uint32_t fVmxPml : 1;
1307 /** VMX: Supports EPT-violations \#VE. */
1308 uint32_t fVmxEptXcptVe : 1;
1309 /** VMX: Supports conceal VMX from PT. */
1310 uint32_t fVmxConcealVmxFromPt : 1;
1311 /** VMX: Supports XSAVES/XRSTORS. */
1312 uint32_t fVmxXsavesXrstors : 1;
1313 /** VMX: Supports mode-based execute control for EPT. */
1314 uint32_t fVmxModeBasedExecuteEpt : 1;
1315 /** VMX: Supports sub-page write permissions for EPT. */
1316 uint32_t fVmxSppEpt : 1;
1317 /** VMX: Supports Intel PT to output guest-physical addresses for EPT. */
1318 uint32_t fVmxPtEpt : 1;
1319 /** VMX: Supports TSC scaling. */
1320 uint32_t fVmxUseTscScaling : 1;
1321 /** VMX: Supports TPAUSE, UMONITOR, or UMWAIT. */
1322 uint32_t fVmxUserWaitPause : 1;
1323 /** VMX: Supports enclave (ENCLV) exiting. */
1324 uint32_t fVmxEnclvExit : 1;
1325 /** @} */
1326
1327 /** @name VMX Tertiary processor-based controls.
1328 * @{ */
1329 /** VMX: Supports LOADIWKEY exiting. */
1330 uint32_t fVmxLoadIwKeyExit : 1;
1331 /** @} */
1332
1333 /** @name VMX VM-entry controls.
1334 * @{ */
1335 /** VMX: Supports load-debug controls on VM-entry. */
1336 uint32_t fVmxEntryLoadDebugCtls : 1;
1337 /** VMX: Supports IA32e mode guest. */
1338 uint32_t fVmxIa32eModeGuest : 1;
1339 /** VMX: Supports load guest EFER MSR on VM-entry. */
1340 uint32_t fVmxEntryLoadEferMsr : 1;
1341 /** VMX: Supports load guest PAT MSR on VM-entry. */
1342 uint32_t fVmxEntryLoadPatMsr : 1;
1343 /** @} */
1344
1345 /** @name VMX VM-exit controls.
1346 * @{ */
1347 /** VMX: Supports save debug controls on VM-exit. */
1348 uint32_t fVmxExitSaveDebugCtls : 1;
1349 /** VMX: Supports host-address space size. */
1350 uint32_t fVmxHostAddrSpaceSize : 1;
1351 /** VMX: Supports acknowledge external interrupt on VM-exit. */
1352 uint32_t fVmxExitAckExtInt : 1;
1353 /** VMX: Supports save guest PAT MSR on VM-exit. */
1354 uint32_t fVmxExitSavePatMsr : 1;
1355 /** VMX: Supports load hsot PAT MSR on VM-exit. */
1356 uint32_t fVmxExitLoadPatMsr : 1;
1357 /** VMX: Supports save guest EFER MSR on VM-exit. */
1358 uint32_t fVmxExitSaveEferMsr : 1;
1359 /** VMX: Supports load host EFER MSR on VM-exit. */
1360 uint32_t fVmxExitLoadEferMsr : 1;
1361 /** VMX: Supports save VMX preemption timer on VM-exit. */
1362 uint32_t fVmxSavePreemptTimer : 1;
1363 /** @} */
1364
1365 /** @name VMX Miscellaneous data.
1366 * @{ */
1367 /** VMX: Supports storing EFER.LMA into IA32e-mode guest field on VM-exit. */
1368 uint32_t fVmxExitSaveEferLma : 1;
1369 /** VMX: Whether Intel PT (Processor Trace) is supported in VMX mode or not. */
1370 uint32_t fVmxPt : 1;
1371 /** VMX: Supports VMWRITE to any valid VMCS field incl. read-only fields, otherwise
1372 * VMWRITE cannot modify read-only VM-exit information fields. */
1373 uint32_t fVmxVmwriteAll : 1;
1374 /** VMX: Supports injection of software interrupts, ICEBP on VM-entry for zero
1375 * length instructions. */
1376 uint32_t fVmxEntryInjectSoftInt : 1;
1377 /** @} */
1378
1379 /** VMX: Padding / reserved for future features. */
1380 uint32_t fVmxPadding1 : 25;
1381} CPUMFEATURES;
1382#ifndef VBOX_FOR_DTRACE_LIB
1383AssertCompileSize(CPUMFEATURES, 48);
1384#endif
1385/** Pointer to a CPU feature structure. */
1386typedef CPUMFEATURES *PCPUMFEATURES;
1387/** Pointer to a const CPU feature structure. */
1388typedef CPUMFEATURES const *PCCPUMFEATURES;
1389
1390
1391/**
1392 * CPU database entry.
1393 */
1394typedef struct CPUMDBENTRY
1395{
1396 /** The CPU name. */
1397 const char *pszName;
1398 /** The full CPU name. */
1399 const char *pszFullName;
1400 /** The CPU vendor (CPUMCPUVENDOR). */
1401 uint8_t enmVendor;
1402 /** The CPU family. */
1403 uint8_t uFamily;
1404 /** The CPU model. */
1405 uint8_t uModel;
1406 /** The CPU stepping. */
1407 uint8_t uStepping;
1408 /** The microarchitecture. */
1409 CPUMMICROARCH enmMicroarch;
1410 /** Scalable bus frequency used for reporting other frequencies. */
1411 uint64_t uScalableBusFreq;
1412 /** Flags - CPUMDB_F_XXX. */
1413 uint32_t fFlags;
1414 /** The maximum physical address with of the CPU. This should correspond to
1415 * the value in CPUID leaf 0x80000008 when present. */
1416 uint8_t cMaxPhysAddrWidth;
1417 /** The MXCSR mask. */
1418 uint32_t fMxCsrMask;
1419 /** Pointer to an array of CPUID leaves. */
1420 PCCPUMCPUIDLEAF paCpuIdLeaves;
1421 /** The number of CPUID leaves in the array paCpuIdLeaves points to. */
1422 uint32_t cCpuIdLeaves;
1423 /** The method used to deal with unknown CPUID leaves. */
1424 CPUMUNKNOWNCPUID enmUnknownCpuId;
1425 /** The default unknown CPUID value. */
1426 CPUMCPUID DefUnknownCpuId;
1427
1428 /** MSR mask. Several microarchitectures ignore the higher bits of ECX in
1429 * the RDMSR and WRMSR instructions. */
1430 uint32_t fMsrMask;
1431
1432 /** The number of ranges in the table pointed to b paMsrRanges. */
1433 uint32_t cMsrRanges;
1434 /** MSR ranges for this CPU. */
1435 PCCPUMMSRRANGE paMsrRanges;
1436} CPUMDBENTRY;
1437/** Pointer to a const CPU database entry. */
1438typedef CPUMDBENTRY const *PCCPUMDBENTRY;
1439
1440/** @name CPUMDB_F_XXX - CPUDBENTRY::fFlags
1441 * @{ */
1442/** Should execute all in IEM.
1443 * @todo Implement this - currently done in Main... */
1444#define CPUMDB_F_EXECUTE_ALL_IN_IEM RT_BIT_32(0)
1445/** @} */
1446
1447
1448
1449#ifndef VBOX_FOR_DTRACE_LIB
1450
1451/** @name Guest Register Getters.
1452 * @{ */
1453VMMDECL(void) CPUMGetGuestGDTR(PCVMCPU pVCpu, PVBOXGDTR pGDTR);
1454VMMDECL(RTGCPTR) CPUMGetGuestIDTR(PCVMCPU pVCpu, uint16_t *pcbLimit);
1455VMMDECL(RTSEL) CPUMGetGuestTR(PCVMCPU pVCpu, PCPUMSELREGHID pHidden);
1456VMMDECL(RTSEL) CPUMGetGuestLDTR(PCVMCPU pVCpu);
1457VMMDECL(RTSEL) CPUMGetGuestLdtrEx(PCVMCPU pVCpu, uint64_t *pGCPtrBase, uint32_t *pcbLimit);
1458VMMDECL(uint64_t) CPUMGetGuestCR0(PCVMCPU pVCpu);
1459VMMDECL(uint64_t) CPUMGetGuestCR2(PCVMCPU pVCpu);
1460VMMDECL(uint64_t) CPUMGetGuestCR3(PCVMCPU pVCpu);
1461VMMDECL(uint64_t) CPUMGetGuestCR4(PCVMCPU pVCpu);
1462VMMDECL(uint64_t) CPUMGetGuestCR8(PCVMCPUCC pVCpu);
1463VMMDECL(int) CPUMGetGuestCRx(PCVMCPUCC pVCpu, unsigned iReg, uint64_t *pValue);
1464VMMDECL(uint32_t) CPUMGetGuestEFlags(PCVMCPU pVCpu);
1465VMMDECL(uint32_t) CPUMGetGuestEIP(PCVMCPU pVCpu);
1466VMMDECL(uint64_t) CPUMGetGuestRIP(PCVMCPU pVCpu);
1467VMMDECL(uint32_t) CPUMGetGuestEAX(PCVMCPU pVCpu);
1468VMMDECL(uint32_t) CPUMGetGuestEBX(PCVMCPU pVCpu);
1469VMMDECL(uint32_t) CPUMGetGuestECX(PCVMCPU pVCpu);
1470VMMDECL(uint32_t) CPUMGetGuestEDX(PCVMCPU pVCpu);
1471VMMDECL(uint32_t) CPUMGetGuestESI(PCVMCPU pVCpu);
1472VMMDECL(uint32_t) CPUMGetGuestEDI(PCVMCPU pVCpu);
1473VMMDECL(uint32_t) CPUMGetGuestESP(PCVMCPU pVCpu);
1474VMMDECL(uint32_t) CPUMGetGuestEBP(PCVMCPU pVCpu);
1475VMMDECL(RTSEL) CPUMGetGuestCS(PCVMCPU pVCpu);
1476VMMDECL(RTSEL) CPUMGetGuestDS(PCVMCPU pVCpu);
1477VMMDECL(RTSEL) CPUMGetGuestES(PCVMCPU pVCpu);
1478VMMDECL(RTSEL) CPUMGetGuestFS(PCVMCPU pVCpu);
1479VMMDECL(RTSEL) CPUMGetGuestGS(PCVMCPU pVCpu);
1480VMMDECL(RTSEL) CPUMGetGuestSS(PCVMCPU pVCpu);
1481VMMDECL(uint64_t) CPUMGetGuestFlatPC(PVMCPU pVCpu);
1482VMMDECL(uint64_t) CPUMGetGuestFlatSP(PVMCPU pVCpu);
1483VMMDECL(uint64_t) CPUMGetGuestDR0(PCVMCPU pVCpu);
1484VMMDECL(uint64_t) CPUMGetGuestDR1(PCVMCPU pVCpu);
1485VMMDECL(uint64_t) CPUMGetGuestDR2(PCVMCPU pVCpu);
1486VMMDECL(uint64_t) CPUMGetGuestDR3(PCVMCPU pVCpu);
1487VMMDECL(uint64_t) CPUMGetGuestDR6(PCVMCPU pVCpu);
1488VMMDECL(uint64_t) CPUMGetGuestDR7(PCVMCPU pVCpu);
1489VMMDECL(int) CPUMGetGuestDRx(PCVMCPU pVCpu, uint32_t iReg, uint64_t *pValue);
1490VMMDECL(void) CPUMGetGuestCpuId(PVMCPUCC pVCpu, uint32_t iLeaf, uint32_t iSubLeaf,
1491 uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx);
1492VMMDECL(uint64_t) CPUMGetGuestEFER(PCVMCPU pVCpu);
1493VMM_INT_DECL(uint64_t) CPUMGetGuestIa32FeatCtrl(PCVMCPUCC pVCpu);
1494VMM_INT_DECL(uint64_t) CPUMGetGuestIa32MtrrCap(PCVMCPU pVCpu);
1495VMM_INT_DECL(uint64_t) CPUMGetGuestIa32SmmMonitorCtl(PCVMCPUCC pVCpu);
1496VMM_INT_DECL(uint64_t) CPUMGetGuestIa32VmxEptVpidCap(PCVMCPUCC pVCpu);
1497VMMDECL(VBOXSTRICTRC) CPUMQueryGuestMsr(PVMCPUCC pVCpu, uint32_t idMsr, uint64_t *puValue);
1498VMMDECL(VBOXSTRICTRC) CPUMSetGuestMsr(PVMCPUCC pVCpu, uint32_t idMsr, uint64_t uValue);
1499VMMDECL(CPUMCPUVENDOR) CPUMGetGuestCpuVendor(PVM pVM);
1500VMMDECL(CPUMMICROARCH) CPUMGetGuestMicroarch(PCVM pVM);
1501VMMDECL(void) CPUMGetGuestAddrWidths(PCVM pVM, uint8_t *pcPhysAddrWidth, uint8_t *pcLinearAddrWidth);
1502VMMDECL(CPUMCPUVENDOR) CPUMGetHostCpuVendor(PVM pVM);
1503VMMDECL(CPUMMICROARCH) CPUMGetHostMicroarch(PCVM pVM);
1504/** @} */
1505
1506/** @name Guest Register Setters.
1507 * @{ */
1508VMMDECL(int) CPUMSetGuestGDTR(PVMCPU pVCpu, uint64_t GCPtrBase, uint16_t cbLimit);
1509VMMDECL(int) CPUMSetGuestIDTR(PVMCPU pVCpu, uint64_t GCPtrBase, uint16_t cbLimit);
1510VMMDECL(int) CPUMSetGuestTR(PVMCPU pVCpu, uint16_t tr);
1511VMMDECL(int) CPUMSetGuestLDTR(PVMCPU pVCpu, uint16_t ldtr);
1512VMMDECL(int) CPUMSetGuestCR0(PVMCPUCC pVCpu, uint64_t cr0);
1513VMMDECL(int) CPUMSetGuestCR2(PVMCPU pVCpu, uint64_t cr2);
1514VMMDECL(int) CPUMSetGuestCR3(PVMCPU pVCpu, uint64_t cr3);
1515VMMDECL(int) CPUMSetGuestCR4(PVMCPU pVCpu, uint64_t cr4);
1516VMMDECL(int) CPUMSetGuestDR0(PVMCPUCC pVCpu, uint64_t uDr0);
1517VMMDECL(int) CPUMSetGuestDR1(PVMCPUCC pVCpu, uint64_t uDr1);
1518VMMDECL(int) CPUMSetGuestDR2(PVMCPUCC pVCpu, uint64_t uDr2);
1519VMMDECL(int) CPUMSetGuestDR3(PVMCPUCC pVCpu, uint64_t uDr3);
1520VMMDECL(int) CPUMSetGuestDR6(PVMCPU pVCpu, uint64_t uDr6);
1521VMMDECL(int) CPUMSetGuestDR7(PVMCPUCC pVCpu, uint64_t uDr7);
1522VMMDECL(int) CPUMSetGuestDRx(PVMCPUCC pVCpu, uint32_t iReg, uint64_t Value);
1523VMM_INT_DECL(int) CPUMSetGuestXcr0(PVMCPUCC pVCpu, uint64_t uNewValue);
1524VMMDECL(int) CPUMSetGuestEFlags(PVMCPU pVCpu, uint32_t eflags);
1525VMMDECL(int) CPUMSetGuestEIP(PVMCPU pVCpu, uint32_t eip);
1526VMMDECL(int) CPUMSetGuestEAX(PVMCPU pVCpu, uint32_t eax);
1527VMMDECL(int) CPUMSetGuestEBX(PVMCPU pVCpu, uint32_t ebx);
1528VMMDECL(int) CPUMSetGuestECX(PVMCPU pVCpu, uint32_t ecx);
1529VMMDECL(int) CPUMSetGuestEDX(PVMCPU pVCpu, uint32_t edx);
1530VMMDECL(int) CPUMSetGuestESI(PVMCPU pVCpu, uint32_t esi);
1531VMMDECL(int) CPUMSetGuestEDI(PVMCPU pVCpu, uint32_t edi);
1532VMMDECL(int) CPUMSetGuestESP(PVMCPU pVCpu, uint32_t esp);
1533VMMDECL(int) CPUMSetGuestEBP(PVMCPU pVCpu, uint32_t ebp);
1534VMMDECL(int) CPUMSetGuestCS(PVMCPU pVCpu, uint16_t cs);
1535VMMDECL(int) CPUMSetGuestDS(PVMCPU pVCpu, uint16_t ds);
1536VMMDECL(int) CPUMSetGuestES(PVMCPU pVCpu, uint16_t es);
1537VMMDECL(int) CPUMSetGuestFS(PVMCPU pVCpu, uint16_t fs);
1538VMMDECL(int) CPUMSetGuestGS(PVMCPU pVCpu, uint16_t gs);
1539VMMDECL(int) CPUMSetGuestSS(PVMCPU pVCpu, uint16_t ss);
1540VMMDECL(void) CPUMSetGuestEFER(PVMCPU pVCpu, uint64_t val);
1541VMMR3_INT_DECL(void) CPUMR3SetGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature);
1542VMMR3_INT_DECL(void) CPUMR3ClearGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature);
1543VMMR3_INT_DECL(bool) CPUMR3GetGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature);
1544VMMDECL(bool) CPUMSetGuestCpuIdPerCpuApicFeature(PVMCPU pVCpu, bool fVisible);
1545VMMDECL(void) CPUMSetGuestCtx(PVMCPU pVCpu, const PCPUMCTX pCtx);
1546VMM_INT_DECL(void) CPUMSetGuestTscAux(PVMCPUCC pVCpu, uint64_t uValue);
1547VMM_INT_DECL(uint64_t) CPUMGetGuestTscAux(PVMCPUCC pVCpu);
1548VMM_INT_DECL(void) CPUMSetGuestSpecCtrl(PVMCPUCC pVCpu, uint64_t uValue);
1549VMM_INT_DECL(uint64_t) CPUMGetGuestSpecCtrl(PVMCPUCC pVCpu);
1550VMM_INT_DECL(uint64_t) CPUMGetGuestCR4ValidMask(PVM pVM);
1551VMM_INT_DECL(void) CPUMSetGuestPaePdpes(PVMCPU pVCpu, PCX86PDPE paPaePdpes);
1552VMM_INT_DECL(void) CPUMGetGuestPaePdpes(PVMCPU pVCpu, PX86PDPE paPaePdpes);
1553/** @} */
1554
1555
1556/** @name Misc Guest Predicate Functions.
1557 * @{ */
1558VMMDECL(bool) CPUMIsGuestIn64BitCode(PVMCPU pVCpu);
1559VMMDECL(bool) CPUMIsGuestNXEnabled(PCVMCPU pVCpu);
1560VMMDECL(bool) CPUMIsGuestPageSizeExtEnabled(PCVMCPU pVCpu);
1561VMMDECL(bool) CPUMIsGuestPagingEnabled(PCVMCPU pVCpu);
1562VMMDECL(bool) CPUMIsGuestR0WriteProtEnabled(PCVMCPU pVCpu);
1563VMMDECL(bool) CPUMIsGuestInRealMode(PCVMCPU pVCpu);
1564VMMDECL(bool) CPUMIsGuestInRealOrV86Mode(PCVMCPU pVCpu);
1565VMMDECL(bool) CPUMIsGuestInProtectedMode(PCVMCPU pVCpu);
1566VMMDECL(bool) CPUMIsGuestInPagedProtectedMode(PCVMCPU pVCpu);
1567VMMDECL(bool) CPUMIsGuestInLongMode(PCVMCPU pVCpu);
1568VMMDECL(bool) CPUMIsGuestInPAEMode(PCVMCPU pVCpu);
1569/** @} */
1570
1571/** @name Nested Hardware-Virtualization Helpers.
1572 * @{ */
1573VMM_INT_DECL(bool) CPUMIsGuestPhysIntrEnabled(PVMCPU pVCpu);
1574VMM_INT_DECL(bool) CPUMIsGuestVirtIntrEnabled(PVMCPU pVCpu);
1575VMM_INT_DECL(uint64_t) CPUMApplyNestedGuestTscOffset(PCVMCPU pVCpu, uint64_t uTscValue);
1576VMM_INT_DECL(uint64_t) CPUMRemoveNestedGuestTscOffset(PCVMCPU pVCpu, uint64_t uTscValue);
1577
1578/* SVM helpers. */
1579VMM_INT_DECL(bool) CPUMIsGuestSvmPhysIntrEnabled(PCVMCPU pVCpu, PCCPUMCTX pCtx);
1580VMM_INT_DECL(bool) CPUMIsGuestSvmVirtIntrEnabled(PCVMCPU pVCpu, PCCPUMCTX pCtx);
1581VMM_INT_DECL(uint8_t) CPUMGetGuestSvmVirtIntrVector(PCCPUMCTX pCtx);
1582VMM_INT_DECL(void) CPUMSvmVmExitRestoreHostState(PVMCPUCC pVCpu, PCPUMCTX pCtx);
1583VMM_INT_DECL(void) CPUMSvmVmRunSaveHostState(PCPUMCTX pCtx, uint8_t cbInstr);
1584VMM_INT_DECL(bool) CPUMIsSvmIoInterceptSet(void *pvIoBitmap, uint16_t u16Port, SVMIOIOTYPE enmIoType, uint8_t cbReg,
1585 uint8_t cAddrSizeBits, uint8_t iEffSeg, bool fRep, bool fStrIo,
1586 PSVMIOIOEXITINFO pIoExitInfo);
1587VMM_INT_DECL(int) CPUMGetSvmMsrpmOffsetAndBit(uint32_t idMsr, uint16_t *pbOffMsrpm, uint8_t *puMsrpmBit);
1588
1589/* VMX helpers. */
1590VMM_INT_DECL(bool) CPUMIsGuestVmxVmcsFieldValid(PVMCC pVM, uint64_t u64VmcsField);
1591VMM_INT_DECL(bool) CPUMIsGuestVmxIoInterceptSet(PCVMCPU pVCpu, uint16_t u16Port, uint8_t cbAccess);
1592VMM_INT_DECL(bool) CPUMIsGuestVmxMovToCr3InterceptSet(PVMCPU pVCpu, uint64_t uNewCr3);
1593VMM_INT_DECL(bool) CPUMIsGuestVmxVmreadVmwriteInterceptSet(PCVMCPU pVCpu, uint32_t uExitReason, uint64_t u64FieldEnc);
1594VMM_INT_DECL(int) CPUMStartGuestVmxPremptTimer(PVMCPUCC pVCpu, uint32_t uTimer, uint8_t cShift, uint64_t *pu64EntryTick);
1595VMM_INT_DECL(int) CPUMStopGuestVmxPremptTimer(PVMCPUCC pVCpu);
1596VMM_INT_DECL(uint32_t) CPUMGetVmxMsrPermission(void const *pvMsrBitmap, uint32_t idMsr);
1597VMM_INT_DECL(bool) CPUMIsGuestVmxEptPagingEnabled(PCVMCPUCC pVCpu);
1598VMM_INT_DECL(bool) CPUMIsGuestVmxEptPaePagingEnabled(PCVMCPUCC pVCpu);
1599/** @} */
1600
1601/** @name Externalized State Helpers.
1602 * @{ */
1603/** @def CPUM_ASSERT_NOT_EXTRN
1604 * Macro for asserting that @a a_fNotExtrn are present.
1605 *
1606 * @param a_pVCpu The cross context virtual CPU structure of the calling EMT.
1607 * @param a_fNotExtrn Mask of CPUMCTX_EXTRN_XXX bits to check.
1608 *
1609 * @remarks Requires VMCPU_INCL_CPUM_GST_CTX to be defined.
1610 */
1611#define CPUM_ASSERT_NOT_EXTRN(a_pVCpu, a_fNotExtrn) \
1612 AssertMsg(!((a_pVCpu)->cpum.GstCtx.fExtrn & (a_fNotExtrn)), \
1613 ("%#RX64; a_fNotExtrn=%#RX64\n", (a_pVCpu)->cpum.GstCtx.fExtrn, (a_fNotExtrn)))
1614
1615/** @def CPUM_IMPORT_EXTRN_RET
1616 * Macro for making sure the state specified by @a fExtrnImport is present,
1617 * calling CPUMImportGuestStateOnDemand() to get it if necessary.
1618 *
1619 * Will return if CPUMImportGuestStateOnDemand() fails.
1620 *
1621 * @param a_pVCpu The cross context virtual CPU structure of the calling EMT.
1622 * @param a_fExtrnImport Mask of CPUMCTX_EXTRN_XXX bits to get.
1623 * @thread EMT(a_pVCpu)
1624 *
1625 * @remarks Requires VMCPU_INCL_CPUM_GST_CTX to be defined.
1626 */
1627#define CPUM_IMPORT_EXTRN_RET(a_pVCpu, a_fExtrnImport) \
1628 do { \
1629 if (!((a_pVCpu)->cpum.GstCtx.fExtrn & (a_fExtrnImport))) \
1630 { /* already present, consider this likely */ } \
1631 else \
1632 { \
1633 int rcCpumImport = CPUMImportGuestStateOnDemand(a_pVCpu, a_fExtrnImport); \
1634 AssertRCReturn(rcCpumImport, rcCpumImport); \
1635 } \
1636 } while (0)
1637
1638/** @def CPUM_IMPORT_EXTRN_RCSTRICT
1639 * Macro for making sure the state specified by @a fExtrnImport is present,
1640 * calling CPUMImportGuestStateOnDemand() to get it if necessary.
1641 *
1642 * Will update a_rcStrict if CPUMImportGuestStateOnDemand() fails.
1643 *
1644 * @param a_pVCpu The cross context virtual CPU structure of the calling EMT.
1645 * @param a_fExtrnImport Mask of CPUMCTX_EXTRN_XXX bits to get.
1646 * @param a_rcStrict Strict status code variable to update on failure.
1647 * @thread EMT(a_pVCpu)
1648 *
1649 * @remarks Requires VMCPU_INCL_CPUM_GST_CTX to be defined.
1650 */
1651#define CPUM_IMPORT_EXTRN_RCSTRICT(a_pVCpu, a_fExtrnImport, a_rcStrict) \
1652 do { \
1653 if (!((a_pVCpu)->cpum.GstCtx.fExtrn & (a_fExtrnImport))) \
1654 { /* already present, consider this likely */ } \
1655 else \
1656 { \
1657 int rcCpumImport = CPUMImportGuestStateOnDemand(a_pVCpu, a_fExtrnImport); \
1658 AssertStmt(RT_SUCCESS(rcCpumImport) || RT_FAILURE_NP(a_rcStrict), a_rcStrict = rcCpumImport); \
1659 } \
1660 } while (0)
1661
1662VMM_INT_DECL(int) CPUMImportGuestStateOnDemand(PVMCPUCC pVCpu, uint64_t fExtrnImport);
1663/** @} */
1664
1665#if !defined(IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS) || defined(DOXYGEN_RUNNING)
1666/** @name Inlined Guest Getters and predicates Functions.
1667 * @{ */
1668
1669/**
1670 * Gets valid CR0 bits for the guest.
1671 *
1672 * @returns Valid CR0 bits.
1673 */
1674DECLINLINE(uint64_t) CPUMGetGuestCR0ValidMask(void)
1675{
1676 return ( X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS
1677 | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM
1678 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG);
1679}
1680
1681/**
1682 * Tests if the guest is running in real mode or not.
1683 *
1684 * @returns true if in real mode, otherwise false.
1685 * @param pCtx Current CPU context.
1686 */
1687DECLINLINE(bool) CPUMIsGuestInRealModeEx(PCCPUMCTX pCtx)
1688{
1689 return !(pCtx->cr0 & X86_CR0_PE);
1690}
1691
1692/**
1693 * Tests if the guest is running in real or virtual 8086 mode.
1694 *
1695 * @returns @c true if it is, @c false if not.
1696 * @param pCtx Current CPU context.
1697 */
1698DECLINLINE(bool) CPUMIsGuestInRealOrV86ModeEx(PCCPUMCTX pCtx)
1699{
1700 return !(pCtx->cr0 & X86_CR0_PE)
1701 || pCtx->eflags.Bits.u1VM; /* Cannot be set in long mode. Intel spec 2.3.1 "System Flags and Fields in IA-32e Mode". */
1702}
1703
1704/**
1705 * Tests if the guest is running in virtual 8086 mode.
1706 *
1707 * @returns @c true if it is, @c false if not.
1708 * @param pCtx Current CPU context.
1709 */
1710DECLINLINE(bool) CPUMIsGuestInV86ModeEx(PCCPUMCTX pCtx)
1711{
1712 return (pCtx->eflags.Bits.u1VM == 1);
1713}
1714
1715/**
1716 * Tests if the guest is running in paged protected or not.
1717 *
1718 * @returns true if in paged protected mode, otherwise false.
1719 * @param pCtx Current CPU context.
1720 */
1721DECLINLINE(bool) CPUMIsGuestInPagedProtectedModeEx(PCPUMCTX pCtx)
1722{
1723 return (pCtx->cr0 & (X86_CR0_PE | X86_CR0_PG)) == (X86_CR0_PE | X86_CR0_PG);
1724}
1725
1726/**
1727 * Tests if the guest is running in long mode or not.
1728 *
1729 * @returns true if in long mode, otherwise false.
1730 * @param pCtx Current CPU context.
1731 */
1732DECLINLINE(bool) CPUMIsGuestInLongModeEx(PCCPUMCTX pCtx)
1733{
1734 return (pCtx->msrEFER & MSR_K6_EFER_LMA) == MSR_K6_EFER_LMA;
1735}
1736
1737VMM_INT_DECL(bool) CPUMIsGuestIn64BitCodeSlow(PCPUMCTX pCtx);
1738
1739/**
1740 * Tests if the guest is running in 64 bits mode or not.
1741 *
1742 * @returns true if in 64 bits protected mode, otherwise false.
1743 * @param pCtx Current CPU context.
1744 */
1745DECLINLINE(bool) CPUMIsGuestIn64BitCodeEx(PCPUMCTX pCtx)
1746{
1747 if (!(pCtx->msrEFER & MSR_K6_EFER_LMA))
1748 return false;
1749 if (!CPUMSELREG_ARE_HIDDEN_PARTS_VALID(NULL, &pCtx->cs))
1750 return CPUMIsGuestIn64BitCodeSlow(pCtx);
1751 return pCtx->cs.Attr.n.u1Long;
1752}
1753
1754/**
1755 * Tests if the guest has paging enabled or not.
1756 *
1757 * @returns true if paging is enabled, otherwise false.
1758 * @param pCtx Current CPU context.
1759 */
1760DECLINLINE(bool) CPUMIsGuestPagingEnabledEx(PCCPUMCTX pCtx)
1761{
1762 return !!(pCtx->cr0 & X86_CR0_PG);
1763}
1764
1765/**
1766 * Tests if PAE paging is enabled given the relevant control registers.
1767 *
1768 * @returns @c true if in PAE mode, @c false otherwise.
1769 * @param uCr0 The CR0 value.
1770 * @param uCr4 The CR4 value.
1771 * @param uEferMsr The EFER value.
1772 */
1773DECLINLINE(bool) CPUMIsPaePagingEnabled(uint64_t uCr0, uint64_t uCr4, uint64_t uEferMsr)
1774{
1775 /* Intel mentions EFER.LMA and EFER.LME in different parts of their spec. We shall use EFER.LMA rather
1776 than EFER.LME as it reflects if the CPU has entered paging with EFER.LME set. */
1777 return ( (uCr4 & X86_CR4_PAE)
1778 && (uCr0 & X86_CR0_PG)
1779 && !(uEferMsr & MSR_K6_EFER_LMA));
1780}
1781
1782/**
1783 * Tests if the guest is running in PAE mode or not.
1784 *
1785 * @returns @c true if in PAE mode, @c false otherwise.
1786 * @param pCtx Current CPU context.
1787 */
1788DECLINLINE(bool) CPUMIsGuestInPAEModeEx(PCCPUMCTX pCtx)
1789{
1790 return CPUMIsPaePagingEnabled(pCtx->cr0, pCtx->cr4, pCtx->msrEFER);
1791}
1792
1793/**
1794 * Tests if the guest has AMD SVM enabled or not.
1795 *
1796 * @returns true if SMV is enabled, otherwise false.
1797 * @param pCtx Current CPU context.
1798 */
1799DECLINLINE(bool) CPUMIsGuestSvmEnabled(PCCPUMCTX pCtx)
1800{
1801 return RT_BOOL(pCtx->msrEFER & MSR_K6_EFER_SVME);
1802}
1803
1804/**
1805 * Tests if the guest has Intel VT-x enabled or not.
1806 *
1807 * @returns true if VMX is enabled, otherwise false.
1808 * @param pCtx Current CPU context.
1809 */
1810DECLINLINE(bool) CPUMIsGuestVmxEnabled(PCCPUMCTX pCtx)
1811{
1812 return RT_BOOL(pCtx->cr4 & X86_CR4_VMXE);
1813}
1814
1815/**
1816 * Returns the guest's global-interrupt (GIF) flag.
1817 *
1818 * @returns true when global-interrupts are enabled, otherwise false.
1819 * @param pCtx Current CPU context.
1820 */
1821DECLINLINE(bool) CPUMGetGuestGif(PCCPUMCTX pCtx)
1822{
1823 return pCtx->hwvirt.fGif;
1824}
1825
1826/**
1827 * Sets the guest's global-interrupt flag (GIF).
1828 *
1829 * @param pCtx Current CPU context.
1830 * @param fGif The value to set.
1831 */
1832DECLINLINE(void) CPUMSetGuestGif(PCPUMCTX pCtx, bool fGif)
1833{
1834 pCtx->hwvirt.fGif = fGif;
1835}
1836
1837/**
1838 * Checks if we are executing inside an SVM nested hardware-virtualized guest.
1839 *
1840 * @returns @c true if in SVM nested-guest mode, @c false otherwise.
1841 * @param pCtx Current CPU context.
1842 */
1843DECLINLINE(bool) CPUMIsGuestInSvmNestedHwVirtMode(PCCPUMCTX pCtx)
1844{
1845 /*
1846 * With AMD-V, the VMRUN intercept is a pre-requisite to entering SVM guest-mode.
1847 * See AMD spec. 15.5 "VMRUN instruction" subsection "Canonicalization and Consistency Checks".
1848 */
1849#ifndef IN_RC
1850 if ( pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM
1851 || !(pCtx->hwvirt.svm.Vmcb.ctrl.u64InterceptCtrl & SVM_CTRL_INTERCEPT_VMRUN))
1852 return false;
1853 return true;
1854#else
1855 NOREF(pCtx);
1856 return false;
1857#endif
1858}
1859
1860/**
1861 * Checks if the guest is in VMX non-root operation.
1862 *
1863 * @returns @c true if in VMX non-root operation, @c false otherwise.
1864 * @param pCtx Current CPU context.
1865 */
1866DECLINLINE(bool) CPUMIsGuestInVmxNonRootMode(PCCPUMCTX pCtx)
1867{
1868#ifndef IN_RC
1869 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_VMX)
1870 return false;
1871 Assert(!pCtx->hwvirt.vmx.fInVmxNonRootMode || pCtx->hwvirt.vmx.fInVmxRootMode);
1872 return pCtx->hwvirt.vmx.fInVmxNonRootMode;
1873#else
1874 NOREF(pCtx);
1875 return false;
1876#endif
1877}
1878
1879/**
1880 * Checks if we are executing inside an SVM or VMX nested hardware-virtualized
1881 * guest.
1882 *
1883 * @returns @c true if in nested-guest mode, @c false otherwise.
1884 * @param pCtx Current CPU context.
1885 */
1886DECLINLINE(bool) CPUMIsGuestInNestedHwvirtMode(PCCPUMCTX pCtx)
1887{
1888 return CPUMIsGuestInVmxNonRootMode(pCtx) || CPUMIsGuestInSvmNestedHwVirtMode(pCtx);
1889}
1890
1891/**
1892 * Checks if the guest is in VMX root operation.
1893 *
1894 * @returns @c true if in VMX root operation, @c false otherwise.
1895 * @param pCtx Current CPU context.
1896 */
1897DECLINLINE(bool) CPUMIsGuestInVmxRootMode(PCCPUMCTX pCtx)
1898{
1899#ifndef IN_RC
1900 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_VMX)
1901 return false;
1902 return pCtx->hwvirt.vmx.fInVmxRootMode;
1903#else
1904 NOREF(pCtx);
1905 return false;
1906#endif
1907}
1908
1909# ifndef IN_RC
1910
1911/**
1912 * Checks if the nested-guest VMCB has the specified ctrl/instruction intercept
1913 * active.
1914 *
1915 * @returns @c true if in intercept is set, @c false otherwise.
1916 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
1917 * @param pCtx Current CPU context.
1918 * @param fIntercept The SVM control/instruction intercept, see
1919 * SVM_CTRL_INTERCEPT_*.
1920 */
1921DECLINLINE(bool) CPUMIsGuestSvmCtrlInterceptSet(PCVMCPU pVCpu, PCCPUMCTX pCtx, uint64_t fIntercept)
1922{
1923 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM)
1924 return false;
1925 uint64_t u64Intercepts;
1926 if (!HMGetGuestSvmCtrlIntercepts(pVCpu, &u64Intercepts))
1927 u64Intercepts = pCtx->hwvirt.svm.Vmcb.ctrl.u64InterceptCtrl;
1928 return RT_BOOL(u64Intercepts & fIntercept);
1929}
1930
1931/**
1932 * Checks if the nested-guest VMCB has the specified CR read intercept active.
1933 *
1934 * @returns @c true if in intercept is set, @c false otherwise.
1935 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
1936 * @param pCtx Current CPU context.
1937 * @param uCr The CR register number (0 to 15).
1938 */
1939DECLINLINE(bool) CPUMIsGuestSvmReadCRxInterceptSet(PCVMCPU pVCpu, PCCPUMCTX pCtx, uint8_t uCr)
1940{
1941 Assert(uCr < 16);
1942 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM)
1943 return false;
1944 uint16_t u16Intercepts;
1945 if (!HMGetGuestSvmReadCRxIntercepts(pVCpu, &u16Intercepts))
1946 u16Intercepts = pCtx->hwvirt.svm.Vmcb.ctrl.u16InterceptRdCRx;
1947 return RT_BOOL(u16Intercepts & (UINT16_C(1) << uCr));
1948}
1949
1950/**
1951 * Checks if the nested-guest VMCB has the specified CR write intercept active.
1952 *
1953 * @returns @c true if in intercept is set, @c false otherwise.
1954 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
1955 * @param pCtx Current CPU context.
1956 * @param uCr The CR register number (0 to 15).
1957 */
1958DECLINLINE(bool) CPUMIsGuestSvmWriteCRxInterceptSet(PCVMCPU pVCpu, PCCPUMCTX pCtx, uint8_t uCr)
1959{
1960 Assert(uCr < 16);
1961 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM)
1962 return false;
1963 uint16_t u16Intercepts;
1964 if (!HMGetGuestSvmWriteCRxIntercepts(pVCpu, &u16Intercepts))
1965 u16Intercepts = pCtx->hwvirt.svm.Vmcb.ctrl.u16InterceptWrCRx;
1966 return RT_BOOL(u16Intercepts & (UINT16_C(1) << uCr));
1967}
1968
1969/**
1970 * Checks if the nested-guest VMCB has the specified DR read intercept active.
1971 *
1972 * @returns @c true if in intercept is set, @c false otherwise.
1973 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
1974 * @param pCtx Current CPU context.
1975 * @param uDr The DR register number (0 to 15).
1976 */
1977DECLINLINE(bool) CPUMIsGuestSvmReadDRxInterceptSet(PCVMCPU pVCpu, PCCPUMCTX pCtx, uint8_t uDr)
1978{
1979 Assert(uDr < 16);
1980 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM)
1981 return false;
1982 uint16_t u16Intercepts;
1983 if (!HMGetGuestSvmReadDRxIntercepts(pVCpu, &u16Intercepts))
1984 u16Intercepts = pCtx->hwvirt.svm.Vmcb.ctrl.u16InterceptRdDRx;
1985 return RT_BOOL(u16Intercepts & (UINT16_C(1) << uDr));
1986}
1987
1988/**
1989 * Checks if the nested-guest VMCB has the specified DR write intercept active.
1990 *
1991 * @returns @c true if in intercept is set, @c false otherwise.
1992 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
1993 * @param pCtx Current CPU context.
1994 * @param uDr The DR register number (0 to 15).
1995 */
1996DECLINLINE(bool) CPUMIsGuestSvmWriteDRxInterceptSet(PCVMCPU pVCpu, PCCPUMCTX pCtx, uint8_t uDr)
1997{
1998 Assert(uDr < 16);
1999 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM)
2000 return false;
2001 uint16_t u16Intercepts;
2002 if (!HMGetGuestSvmWriteDRxIntercepts(pVCpu, &u16Intercepts))
2003 u16Intercepts = pCtx->hwvirt.svm.Vmcb.ctrl.u16InterceptWrDRx;
2004 return RT_BOOL(u16Intercepts & (UINT16_C(1) << uDr));
2005}
2006
2007/**
2008 * Checks if the nested-guest VMCB has the specified exception intercept active.
2009 *
2010 * @returns @c true if in intercept is active, @c false otherwise.
2011 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
2012 * @param pCtx Current CPU context.
2013 * @param uVector The exception / interrupt vector.
2014 */
2015DECLINLINE(bool) CPUMIsGuestSvmXcptInterceptSet(PCVMCPU pVCpu, PCCPUMCTX pCtx, uint8_t uVector)
2016{
2017 Assert(uVector <= X86_XCPT_LAST);
2018 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM)
2019 return false;
2020 uint32_t u32Intercepts;
2021 if (!HMGetGuestSvmXcptIntercepts(pVCpu, &u32Intercepts))
2022 u32Intercepts = pCtx->hwvirt.svm.Vmcb.ctrl.u32InterceptXcpt;
2023 return RT_BOOL(u32Intercepts & RT_BIT(uVector));
2024}
2025
2026/**
2027 * Checks if the nested-guest VMCB has virtual-interrupt masking enabled.
2028 *
2029 * @returns @c true if virtual-interrupts are masked, @c false otherwise.
2030 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
2031 * @param pCtx Current CPU context.
2032 *
2033 * @remarks Should only be called when SVM feature is exposed to the guest.
2034 */
2035DECLINLINE(bool) CPUMIsGuestSvmVirtIntrMasking(PCVMCPU pVCpu, PCCPUMCTX pCtx)
2036{
2037 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM)
2038 return false;
2039 bool fVIntrMasking;
2040 if (!HMGetGuestSvmVirtIntrMasking(pVCpu, &fVIntrMasking))
2041 fVIntrMasking = pCtx->hwvirt.svm.Vmcb.ctrl.IntCtrl.n.u1VIntrMasking;
2042 return fVIntrMasking;
2043}
2044
2045/**
2046 * Checks if the nested-guest VMCB has nested-paging enabled.
2047 *
2048 * @returns @c true if nested-paging is enabled, @c false otherwise.
2049 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
2050 * @param pCtx Current CPU context.
2051 *
2052 * @remarks Should only be called when SVM feature is exposed to the guest.
2053 */
2054DECLINLINE(bool) CPUMIsGuestSvmNestedPagingEnabled(PCVMCPU pVCpu, PCCPUMCTX pCtx)
2055{
2056 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM)
2057 return false;
2058 bool fNestedPaging;
2059 if (!HMGetGuestSvmNestedPaging(pVCpu, &fNestedPaging))
2060 fNestedPaging = pCtx->hwvirt.svm.Vmcb.ctrl.NestedPagingCtrl.n.u1NestedPaging;
2061 return fNestedPaging;
2062}
2063
2064/**
2065 * Gets the nested-guest VMCB pause-filter count.
2066 *
2067 * @returns The pause-filter count.
2068 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
2069 * @param pCtx Current CPU context.
2070 *
2071 * @remarks Should only be called when SVM feature is exposed to the guest.
2072 */
2073DECLINLINE(uint16_t) CPUMGetGuestSvmPauseFilterCount(PCVMCPU pVCpu, PCCPUMCTX pCtx)
2074{
2075 if (pCtx->hwvirt.enmHwvirt != CPUMHWVIRT_SVM)
2076 return false;
2077 uint16_t u16PauseFilterCount;
2078 if (!HMGetGuestSvmPauseFilterCount(pVCpu, &u16PauseFilterCount))
2079 u16PauseFilterCount = pCtx->hwvirt.svm.Vmcb.ctrl.u16PauseFilterCount;
2080 return u16PauseFilterCount;
2081}
2082
2083/**
2084 * Updates the NextRIP (NRIP) field in the nested-guest VMCB.
2085 *
2086 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
2087 * @param pCtx Current CPU context.
2088 * @param cbInstr The length of the current instruction in bytes.
2089 *
2090 * @remarks Should only be called when SVM feature is exposed to the guest.
2091 */
2092DECLINLINE(void) CPUMGuestSvmUpdateNRip(PVMCPU pVCpu, PCPUMCTX pCtx, uint8_t cbInstr)
2093{
2094 RT_NOREF(pVCpu);
2095 Assert(pCtx->hwvirt.enmHwvirt == CPUMHWVIRT_SVM);
2096 pCtx->hwvirt.svm.Vmcb.ctrl.u64NextRIP = pCtx->rip + cbInstr;
2097}
2098
2099/**
2100 * Checks whether one of the given Pin-based VM-execution controls are set when
2101 * executing a nested-guest.
2102 *
2103 * @returns @c true if set, @c false otherwise.
2104 * @param pCtx Current CPU context.
2105 * @param uPinCtls The Pin-based VM-execution controls to check.
2106 *
2107 * @remarks This does not check if all given controls are set if more than one
2108 * control is passed in @a uPinCtl.
2109 */
2110DECLINLINE(bool) CPUMIsGuestVmxPinCtlsSet(PCCPUMCTX pCtx, uint32_t uPinCtls)
2111{
2112 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2113 return RT_BOOL(pCtx->hwvirt.vmx.Vmcs.u32PinCtls & uPinCtls);
2114}
2115
2116/**
2117 * Checks whether one of the given Processor-based VM-execution controls are set
2118 * when executing a nested-guest.
2119 *
2120 * @returns @c true if set, @c false otherwise.
2121 * @param pCtx Current CPU context.
2122 * @param uProcCtls The Processor-based VM-execution controls to check.
2123 *
2124 * @remarks This does not check if all given controls are set if more than one
2125 * control is passed in @a uProcCtls.
2126 */
2127DECLINLINE(bool) CPUMIsGuestVmxProcCtlsSet(PCCPUMCTX pCtx, uint32_t uProcCtls)
2128{
2129 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2130 return RT_BOOL(pCtx->hwvirt.vmx.Vmcs.u32ProcCtls & uProcCtls);
2131}
2132
2133/**
2134 * Checks whether one of the given Secondary Processor-based VM-execution controls
2135 * are set when executing a nested-guest.
2136 *
2137 * @returns @c true if set, @c false otherwise.
2138 * @param pCtx Current CPU context.
2139 * @param uProcCtls2 The Secondary Processor-based VM-execution controls to
2140 * check.
2141 *
2142 * @remarks This does not check if all given controls are set if more than one
2143 * control is passed in @a uProcCtls2.
2144 */
2145DECLINLINE(bool) CPUMIsGuestVmxProcCtls2Set(PCCPUMCTX pCtx, uint32_t uProcCtls2)
2146{
2147 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2148 return RT_BOOL(pCtx->hwvirt.vmx.Vmcs.u32ProcCtls2 & uProcCtls2);
2149}
2150
2151/**
2152 * Checks whether one of the given Tertiary Processor-based VM-execution controls
2153 * are set when executing a nested-guest.
2154 *
2155 * @returns @c true if set, @c false otherwise.
2156 * @param pCtx Current CPU context.
2157 * @param uProcCtls3 The Tertiary Processor-based VM-execution controls to
2158 * check.
2159 *
2160 * @remarks This does not check if all given controls are set if more than one
2161 * control is passed in @a uProcCtls3.
2162 */
2163DECLINLINE(bool) CPUMIsGuestVmxProcCtls3Set(PCCPUMCTX pCtx, uint64_t uProcCtls3)
2164{
2165 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2166 return RT_BOOL(pCtx->hwvirt.vmx.Vmcs.u64ProcCtls3.u & uProcCtls3);
2167}
2168
2169/**
2170 * Checks whether one of the given VM-exit controls are set when executing a
2171 * nested-guest.
2172 *
2173 * @returns @c true if set, @c false otherwise.
2174 * @param pCtx Current CPU context.
2175 * @param uExitCtls The VM-exit controls to check.
2176 *
2177 * @remarks This does not check if all given controls are set if more than one
2178 * control is passed in @a uExitCtls.
2179 */
2180DECLINLINE(bool) CPUMIsGuestVmxExitCtlsSet(PCCPUMCTX pCtx, uint32_t uExitCtls)
2181{
2182 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2183 return RT_BOOL(pCtx->hwvirt.vmx.Vmcs.u32ExitCtls & uExitCtls);
2184}
2185
2186/**
2187 * Checks whether one of the given VM-entry controls are set when executing a
2188 * nested-guest.
2189 *
2190 * @returns @c true if set, @c false otherwise.
2191 * @param pCtx Current CPU context.
2192 * @param uEntryCtls The VM-entry controls to check.
2193 *
2194 * @remarks This does not check if all given controls are set if more than one
2195 * control is passed in @a uEntryCtls.
2196 */
2197DECLINLINE(bool) CPUMIsGuestVmxEntryCtlsSet(PCCPUMCTX pCtx, uint32_t uEntryCtls)
2198{
2199 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2200 return RT_BOOL(pCtx->hwvirt.vmx.Vmcs.u32EntryCtls & uEntryCtls);
2201}
2202
2203/**
2204 * Checks whether events injected in the nested-guest are subject to VM-exit checks.
2205 *
2206 * @returns @c true if set, @c false otherwise.
2207 * @param pCtx Current CPU context.
2208 */
2209DECLINLINE(bool) CPUMIsGuestVmxInterceptEvents(PCCPUMCTX pCtx)
2210{
2211 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2212 return pCtx->hwvirt.vmx.fInterceptEvents;
2213}
2214
2215/**
2216 * Sets whether events injected in the nested-guest are subject to VM-exit checks.
2217 *
2218 * @param pCtx Current CPU context.
2219 * @param fIntercept Whether to subject injected events to VM-exits or not.
2220 */
2221DECLINLINE(void) CPUMSetGuestVmxInterceptEvents(PCPUMCTX pCtx, bool fInterceptEvents)
2222{
2223 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2224 pCtx->hwvirt.vmx.fInterceptEvents = fInterceptEvents;
2225}
2226
2227/**
2228 * Checks whether the given exception causes a VM-exit.
2229 *
2230 * The exception type include hardware exceptions, software exceptions (#BP, #OF)
2231 * and privileged software exceptions (#DB generated by INT1/ICEBP).
2232 *
2233 * Software interrupts do -not- cause VM-exits and hence must not be used with this
2234 * function.
2235 *
2236 * @returns @c true if the exception causes a VM-exit, @c false otherwise.
2237 * @param pCtx Current CPU context.
2238 * @param uVector The exception vector.
2239 * @param uErrCode The error code associated with the exception. Pass 0 if not
2240 * applicable.
2241 */
2242DECLINLINE(bool) CPUMIsGuestVmxXcptInterceptSet(PCCPUMCTX pCtx, uint8_t uVector, uint32_t uErrCode)
2243{
2244 Assert(uVector <= X86_XCPT_LAST);
2245
2246 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2247
2248 /* NMIs have a dedicated VM-execution control for causing VM-exits. */
2249 if (uVector == X86_XCPT_NMI)
2250 return RT_BOOL(pCtx->hwvirt.vmx.Vmcs.u32PinCtls & VMX_PIN_CTLS_NMI_EXIT);
2251
2252 /* Page-faults are subject to masking using its error code. */
2253 uint32_t fXcptBitmap = pCtx->hwvirt.vmx.Vmcs.u32XcptBitmap;
2254 if (uVector == X86_XCPT_PF)
2255 {
2256 uint32_t const fXcptPFMask = pCtx->hwvirt.vmx.Vmcs.u32XcptPFMask;
2257 uint32_t const fXcptPFMatch = pCtx->hwvirt.vmx.Vmcs.u32XcptPFMatch;
2258 if ((uErrCode & fXcptPFMask) != fXcptPFMatch)
2259 fXcptBitmap ^= RT_BIT(X86_XCPT_PF);
2260 }
2261
2262 /* Consult the exception bitmap for all other exceptions. */
2263 if (fXcptBitmap & RT_BIT(uVector))
2264 return true;
2265 return false;
2266}
2267
2268
2269/**
2270 * Checks whether the guest is in VMX non-root mode and using EPT paging.
2271 *
2272 * @returns @c true if in VMX non-root operation with EPT, @c false otherwise.
2273 * @param pCtx Current CPU context.
2274 */
2275DECLINLINE(bool) CPUMIsGuestVmxEptPagingEnabledEx(PCCPUMCTX pCtx)
2276{
2277 return CPUMIsGuestInVmxNonRootMode(pCtx)
2278 && CPUMIsGuestVmxProcCtls2Set(pCtx, VMX_PROC_CTLS2_EPT);
2279}
2280
2281
2282/**
2283 * Implements VMSucceed for VMX instruction success.
2284 *
2285 * @param pCtx Current CPU context.
2286 */
2287DECLINLINE(void) CPUMSetGuestVmxVmSucceed(PCPUMCTX pCtx)
2288{
2289 pCtx->eflags.u32 &= ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF);
2290}
2291
2292/**
2293 * Implements VMFailInvalid for VMX instruction failure.
2294 *
2295 * @param pCtx Current CPU context.
2296 */
2297DECLINLINE(void) CPUMSetGuestVmxVmFailInvalid(PCPUMCTX pCtx)
2298{
2299 pCtx->eflags.u32 &= ~(X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF);
2300 pCtx->eflags.u32 |= X86_EFL_CF;
2301}
2302
2303/**
2304 * Implements VMFailValid for VMX instruction failure.
2305 *
2306 * @param pCtx Current CPU context.
2307 * @param enmInsErr The VM instruction error.
2308 */
2309DECLINLINE(void) CPUMSetGuestVmxVmFailValid(PCPUMCTX pCtx, VMXINSTRERR enmInsErr)
2310{
2311 pCtx->eflags.u32 &= ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF);
2312 pCtx->eflags.u32 |= X86_EFL_ZF;
2313 pCtx->hwvirt.vmx.Vmcs.u32RoVmInstrError = enmInsErr;
2314}
2315
2316/**
2317 * Implements VMFail for VMX instruction failure.
2318 *
2319 * @param pCtx Current CPU context.
2320 * @param enmInsErr The VM instruction error.
2321 */
2322DECLINLINE(void) CPUMSetGuestVmxVmFail(PCPUMCTX pCtx, VMXINSTRERR enmInsErr)
2323{
2324 if (pCtx->hwvirt.vmx.GCPhysVmcs != NIL_RTGCPHYS)
2325 CPUMSetGuestVmxVmFailValid(pCtx, enmInsErr);
2326 else
2327 CPUMSetGuestVmxVmFailInvalid(pCtx);
2328}
2329
2330/**
2331 * Returns the guest-physical address of the APIC-access page when executing a
2332 * nested-guest.
2333 *
2334 * @returns The APIC-access page guest-physical address.
2335 * @param pCtx Current CPU context.
2336 */
2337DECLINLINE(uint64_t) CPUMGetGuestVmxApicAccessPageAddr(PCCPUMCTX pCtx)
2338{
2339 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2340 return pCtx->hwvirt.vmx.Vmcs.u64AddrApicAccess.u;
2341}
2342
2343/**
2344 * Gets the nested-guest CR0 subject to the guest/host mask and the read-shadow.
2345 *
2346 * @returns The nested-guest CR0.
2347 * @param pCtx Current CPU context.
2348 * @param fGstHostMask The CR0 guest/host mask to use.
2349 */
2350DECLINLINE(uint64_t) CPUMGetGuestVmxMaskedCr0(PCCPUMCTX pCtx, uint64_t fGstHostMask)
2351{
2352 /*
2353 * For each CR0 bit owned by the host, the corresponding bit from the
2354 * CR0 read shadow is loaded. For each CR0 bit that is not owned by the host,
2355 * the corresponding bit from the guest CR0 is loaded.
2356 *
2357 * See Intel Spec. 25.3 "Changes To Instruction Behavior In VMX Non-root Operation".
2358 */
2359 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2360 uint64_t const uGstCr0 = pCtx->cr0;
2361 uint64_t const fReadShadow = pCtx->hwvirt.vmx.Vmcs.u64Cr0ReadShadow.u;
2362 return (fReadShadow & fGstHostMask) | (uGstCr0 & ~fGstHostMask);
2363}
2364
2365/**
2366 * Gets the nested-guest CR4 subject to the guest/host mask and the read-shadow.
2367 *
2368 * @returns The nested-guest CR4.
2369 * @param pCtx Current CPU context.
2370 * @param fGstHostMask The CR4 guest/host mask to use.
2371 */
2372DECLINLINE(uint64_t) CPUMGetGuestVmxMaskedCr4(PCCPUMCTX pCtx, uint64_t fGstHostMask)
2373{
2374 /*
2375 * For each CR4 bit owned by the host, the corresponding bit from the
2376 * CR4 read shadow is loaded. For each CR4 bit that is not owned by the host,
2377 * the corresponding bit from the guest CR4 is loaded.
2378 *
2379 * See Intel Spec. 25.3 "Changes To Instruction Behavior In VMX Non-root Operation".
2380 */
2381 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2382 uint64_t const uGstCr4 = pCtx->cr4;
2383 uint64_t const fReadShadow = pCtx->hwvirt.vmx.Vmcs.u64Cr4ReadShadow.u;
2384 return (fReadShadow & fGstHostMask) | (uGstCr4 & ~fGstHostMask);
2385}
2386
2387/**
2388 * Checks whether the LMSW access causes a VM-exit or not.
2389 *
2390 * @returns @c true if the LMSW access causes a VM-exit, @c false otherwise.
2391 * @param pCtx Current CPU context.
2392 * @param uNewMsw The LMSW source operand (the Machine Status Word).
2393 */
2394DECLINLINE(bool) CPUMIsGuestVmxLmswInterceptSet(PCCPUMCTX pCtx, uint16_t uNewMsw)
2395{
2396 /*
2397 * LMSW VM-exits are subject to the CR0 guest/host mask and the CR0 read shadow.
2398 *
2399 * See Intel spec. 24.6.6 "Guest/Host Masks and Read Shadows for CR0 and CR4".
2400 * See Intel spec. 25.1.3 "Instructions That Cause VM Exits Conditionally".
2401 */
2402 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2403
2404 uint32_t const fGstHostMask = (uint32_t)pCtx->hwvirt.vmx.Vmcs.u64Cr0Mask.u;
2405 uint32_t const fReadShadow = (uint32_t)pCtx->hwvirt.vmx.Vmcs.u64Cr0ReadShadow.u;
2406
2407 /*
2408 * LMSW can never clear CR0.PE but it may set it. Hence, we handle the
2409 * CR0.PE case first, before the rest of the bits in the MSW.
2410 *
2411 * If CR0.PE is owned by the host and CR0.PE differs between the
2412 * MSW (source operand) and the read-shadow, we must cause a VM-exit.
2413 */
2414 if ( (fGstHostMask & X86_CR0_PE)
2415 && (uNewMsw & X86_CR0_PE)
2416 && !(fReadShadow & X86_CR0_PE))
2417 return true;
2418
2419 /*
2420 * If CR0.MP, CR0.EM or CR0.TS is owned by the host, and the corresponding
2421 * bits differ between the MSW (source operand) and the read-shadow, we must
2422 * cause a VM-exit.
2423 */
2424 uint32_t const fGstHostLmswMask = fGstHostMask & (X86_CR0_MP | X86_CR0_EM | X86_CR0_TS);
2425 if ((fReadShadow & fGstHostLmswMask) != (uNewMsw & fGstHostLmswMask))
2426 return true;
2427
2428 return false;
2429}
2430
2431/**
2432 * Checks whether the Mov-to-CR0/CR4 access causes a VM-exit or not.
2433 *
2434 * @returns @c true if the Mov CRX access causes a VM-exit, @c false otherwise.
2435 * @param pCtx Current CPU context.
2436 * @param iCrReg The control register number (must be 0 or 4).
2437 * @param uNewCrX The CR0/CR4 value being written.
2438 */
2439DECLINLINE(bool) CPUMIsGuestVmxMovToCr0Cr4InterceptSet(PCCPUMCTX pCtx, uint8_t iCrReg, uint64_t uNewCrX)
2440{
2441 /*
2442 * For any CR0/CR4 bit owned by the host (in the CR0/CR4 guest/host mask), if the
2443 * corresponding bits differ between the source operand and the read-shadow,
2444 * we must cause a VM-exit.
2445 *
2446 * See Intel spec. 25.1.3 "Instructions That Cause VM Exits Conditionally".
2447 */
2448 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2449 Assert(iCrReg == 0 || iCrReg == 4);
2450
2451 uint64_t fGstHostMask;
2452 uint64_t fReadShadow;
2453 if (iCrReg == 0)
2454 {
2455 fGstHostMask = pCtx->hwvirt.vmx.Vmcs.u64Cr0Mask.u;
2456 fReadShadow = pCtx->hwvirt.vmx.Vmcs.u64Cr0ReadShadow.u;
2457 }
2458 else
2459 {
2460 fGstHostMask = pCtx->hwvirt.vmx.Vmcs.u64Cr4Mask.u;
2461 fReadShadow = pCtx->hwvirt.vmx.Vmcs.u64Cr4ReadShadow.u;
2462 }
2463
2464 if ((fReadShadow & fGstHostMask) != (uNewCrX & fGstHostMask))
2465 {
2466 Assert(fGstHostMask != 0);
2467 return true;
2468 }
2469
2470 return false;
2471}
2472
2473/**
2474 * Returns whether the guest has an active, current VMCS.
2475 *
2476 * @returns @c true if the guest has an active, current VMCS, @c false otherwise.
2477 * @param pCtx Current CPU context.
2478 */
2479DECLINLINE(bool) CPUMIsGuestVmxCurrentVmcsValid(PCCPUMCTX pCtx)
2480{
2481 RTGCPHYS const GCPhysVmcs = pCtx->hwvirt.vmx.GCPhysVmcs;
2482 return RT_BOOL(GCPhysVmcs != NIL_RTGCPHYS);
2483}
2484
2485# endif /* !IN_RC */
2486
2487/**
2488 * Checks whether the VMX nested-guest is in a state to receive physical (APIC)
2489 * interrupts.
2490 *
2491 * @returns @c true if it's ready, @c false otherwise.
2492 * @param pCtx The guest-CPU context.
2493 */
2494DECLINLINE(bool) CPUMIsGuestVmxPhysIntrEnabled(PCCPUMCTX pCtx)
2495{
2496#ifdef IN_RC
2497 AssertReleaseFailedReturn(false);
2498#else
2499 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2500 if (CPUMIsGuestVmxPinCtlsSet(pCtx, VMX_PIN_CTLS_EXT_INT_EXIT))
2501 return true;
2502 return RT_BOOL(pCtx->eflags.u & X86_EFL_IF);
2503#endif
2504}
2505
2506/**
2507 * Checks whether the VMX nested-guest is blocking virtual-NMIs.
2508 *
2509 * @returns @c true if it's blocked, @c false otherwise.
2510 * @param pCtx The guest-CPU context.
2511 */
2512DECLINLINE(bool) CPUMIsGuestVmxVirtNmiBlocking(PCCPUMCTX pCtx)
2513{
2514#ifdef IN_RC
2515 RT_NOREF(pCtx);
2516 AssertReleaseFailedReturn(false);
2517#else
2518 /*
2519 * Return the state of virtual-NMI blocking, if we are executing a
2520 * VMX nested-guest with virtual-NMIs enabled.
2521 */
2522 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2523 Assert(CPUMIsGuestVmxPinCtlsSet(pCtx, VMX_PIN_CTLS_VIRT_NMI));
2524 return pCtx->hwvirt.vmx.fVirtNmiBlocking;
2525#endif
2526}
2527
2528/**
2529 * Sets or clears VMX nested-guest virtual-NMI blocking.
2530 *
2531 * @param pCtx The guest-CPU context.
2532 * @param fBlocking Whether virtual-NMI blocking is in effect or not.
2533 */
2534DECLINLINE(void) CPUMSetGuestVmxVirtNmiBlocking(PCPUMCTX pCtx, bool fBlocking)
2535{
2536#ifdef IN_RC
2537 RT_NOREF2(pCtx, fBlocking);
2538 AssertReleaseFailedReturnVoid();
2539#else
2540 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2541 Assert(CPUMIsGuestVmxPinCtlsSet(pCtx, VMX_PIN_CTLS_VIRT_NMI));
2542 pCtx->hwvirt.vmx.fVirtNmiBlocking = fBlocking;
2543#endif
2544}
2545
2546/**
2547 * Checks whether the VMX nested-guest is in a state to receive virtual interrupts
2548 * (those injected with the "virtual-interrupt delivery" feature).
2549 *
2550 * @returns @c true if it's ready, @c false otherwise.
2551 * @param pCtx The guest-CPU context.
2552 */
2553DECLINLINE(bool) CPUMIsGuestVmxVirtIntrEnabled(PCCPUMCTX pCtx)
2554{
2555#ifdef IN_RC
2556 RT_NOREF2(pCtx);
2557 AssertReleaseFailedReturn(false);
2558#else
2559 Assert(CPUMIsGuestInVmxNonRootMode(pCtx));
2560 return RT_BOOL(pCtx->eflags.u & X86_EFL_IF);
2561#endif
2562}
2563
2564/** @} */
2565#endif /* !IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS || DOXYGEN_RUNNING */
2566
2567
2568
2569/** @name Hypervisor Register Getters.
2570 * @{ */
2571VMMDECL(RTGCUINTREG) CPUMGetHyperDR0(PVMCPU pVCpu);
2572VMMDECL(RTGCUINTREG) CPUMGetHyperDR1(PVMCPU pVCpu);
2573VMMDECL(RTGCUINTREG) CPUMGetHyperDR2(PVMCPU pVCpu);
2574VMMDECL(RTGCUINTREG) CPUMGetHyperDR3(PVMCPU pVCpu);
2575VMMDECL(RTGCUINTREG) CPUMGetHyperDR6(PVMCPU pVCpu);
2576VMMDECL(RTGCUINTREG) CPUMGetHyperDR7(PVMCPU pVCpu);
2577VMMDECL(uint32_t) CPUMGetHyperCR3(PVMCPU pVCpu);
2578/** @} */
2579
2580/** @name Hypervisor Register Setters.
2581 * @{ */
2582VMMDECL(void) CPUMSetHyperCR3(PVMCPU pVCpu, uint32_t cr3);
2583VMMDECL(void) CPUMSetHyperDR0(PVMCPU pVCpu, RTGCUINTREG uDr0);
2584VMMDECL(void) CPUMSetHyperDR1(PVMCPU pVCpu, RTGCUINTREG uDr1);
2585VMMDECL(void) CPUMSetHyperDR2(PVMCPU pVCpu, RTGCUINTREG uDr2);
2586VMMDECL(void) CPUMSetHyperDR3(PVMCPU pVCpu, RTGCUINTREG uDr3);
2587VMMDECL(void) CPUMSetHyperDR6(PVMCPU pVCpu, RTGCUINTREG uDr6);
2588VMMDECL(void) CPUMSetHyperDR7(PVMCPU pVCpu, RTGCUINTREG uDr7);
2589VMMDECL(int) CPUMRecalcHyperDRx(PVMCPUCC pVCpu, uint8_t iGstReg);
2590/** @} */
2591
2592VMMDECL(PCPUMCTX) CPUMQueryGuestCtxPtr(PVMCPU pVCpu);
2593#ifdef VBOX_INCLUDED_vmm_cpumctx_h
2594VMM_INT_DECL(PCPUMCTXMSRS) CPUMQueryGuestCtxMsrsPtr(PVMCPU pVCpu);
2595#endif
2596VMMDECL(PCCPUMCTXCORE) CPUMGetGuestCtxCore(PVMCPU pVCpu);
2597
2598/** @name Changed flags.
2599 * These flags are used to keep track of which important register that
2600 * have been changed since last they were reset. The only one allowed
2601 * to clear them is REM!
2602 *
2603 * @todo This is obsolete, but remains as it will be refactored for coordinating
2604 * IEM and NEM/HM later. Probably.
2605 * @{
2606 */
2607#define CPUM_CHANGED_FPU_REM RT_BIT(0)
2608#define CPUM_CHANGED_CR0 RT_BIT(1)
2609#define CPUM_CHANGED_CR4 RT_BIT(2)
2610#define CPUM_CHANGED_GLOBAL_TLB_FLUSH RT_BIT(3)
2611#define CPUM_CHANGED_CR3 RT_BIT(4)
2612#define CPUM_CHANGED_GDTR RT_BIT(5)
2613#define CPUM_CHANGED_IDTR RT_BIT(6)
2614#define CPUM_CHANGED_LDTR RT_BIT(7)
2615#define CPUM_CHANGED_TR RT_BIT(8) /**@< Currently unused. */
2616#define CPUM_CHANGED_SYSENTER_MSR RT_BIT(9)
2617#define CPUM_CHANGED_HIDDEN_SEL_REGS RT_BIT(10) /**@< Currently unused. */
2618#define CPUM_CHANGED_CPUID RT_BIT(11)
2619#define CPUM_CHANGED_ALL ( CPUM_CHANGED_FPU_REM \
2620 | CPUM_CHANGED_CR0 \
2621 | CPUM_CHANGED_CR4 \
2622 | CPUM_CHANGED_GLOBAL_TLB_FLUSH \
2623 | CPUM_CHANGED_CR3 \
2624 | CPUM_CHANGED_GDTR \
2625 | CPUM_CHANGED_IDTR \
2626 | CPUM_CHANGED_LDTR \
2627 | CPUM_CHANGED_TR \
2628 | CPUM_CHANGED_SYSENTER_MSR \
2629 | CPUM_CHANGED_HIDDEN_SEL_REGS \
2630 | CPUM_CHANGED_CPUID )
2631/** @} */
2632
2633VMMDECL(void) CPUMSetChangedFlags(PVMCPU pVCpu, uint32_t fChangedAdd);
2634VMMDECL(bool) CPUMSupportsXSave(PVM pVM);
2635VMMDECL(bool) CPUMIsHostUsingSysEnter(PVM pVM);
2636VMMDECL(bool) CPUMIsHostUsingSysCall(PVM pVM);
2637VMMDECL(bool) CPUMIsGuestFPUStateActive(PVMCPU pVCpu);
2638VMMDECL(bool) CPUMIsGuestFPUStateLoaded(PVMCPU pVCpu);
2639VMMDECL(bool) CPUMIsHostFPUStateSaved(PVMCPU pVCpu);
2640VMMDECL(bool) CPUMIsGuestDebugStateActive(PVMCPU pVCpu);
2641VMMDECL(void) CPUMDeactivateGuestDebugState(PVMCPU pVCpu);
2642VMMDECL(bool) CPUMIsHyperDebugStateActive(PVMCPU pVCpu);
2643VMMDECL(uint32_t) CPUMGetGuestCPL(PVMCPU pVCpu);
2644VMMDECL(CPUMMODE) CPUMGetGuestMode(PVMCPU pVCpu);
2645VMMDECL(uint32_t) CPUMGetGuestCodeBits(PVMCPU pVCpu);
2646VMMDECL(DISCPUMODE) CPUMGetGuestDisMode(PVMCPU pVCpu);
2647VMMDECL(uint32_t) CPUMGetGuestMxCsrMask(PVM pVM);
2648VMMDECL(uint64_t) CPUMGetGuestScalableBusFrequency(PVM pVM);
2649VMMDECL(uint64_t) CPUMGetGuestEferMsrValidMask(PVM pVM);
2650VMMDECL(int) CPUMIsGuestEferMsrWriteValid(PVM pVM, uint64_t uCr0, uint64_t uOldEfer, uint64_t uNewEfer,
2651 uint64_t *puValidEfer);
2652VMMDECL(void) CPUMSetGuestEferMsrNoChecks(PVMCPUCC pVCpu, uint64_t uOldEfer, uint64_t uValidEfer);
2653VMMDECL(bool) CPUMIsPatMsrValid(uint64_t uValue);
2654
2655
2656/** Guest CPU interruptibility level, see CPUMGetGuestInterruptibility(). */
2657typedef enum CPUMINTERRUPTIBILITY
2658{
2659 CPUMINTERRUPTIBILITY_INVALID = 0,
2660 CPUMINTERRUPTIBILITY_UNRESTRAINED,
2661 CPUMINTERRUPTIBILITY_VIRT_INT_DISABLED,
2662 CPUMINTERRUPTIBILITY_INT_DISABLED,
2663 CPUMINTERRUPTIBILITY_INT_INHIBITED,
2664 CPUMINTERRUPTIBILITY_NMI_INHIBIT,
2665 CPUMINTERRUPTIBILITY_GLOBAL_INHIBIT,
2666 CPUMINTERRUPTIBILITY_END,
2667 CPUMINTERRUPTIBILITY_32BIT_HACK = 0x7fffffff
2668} CPUMINTERRUPTIBILITY;
2669
2670VMM_INT_DECL(CPUMINTERRUPTIBILITY) CPUMGetGuestInterruptibility(PVMCPU pVCpu);
2671VMM_INT_DECL(bool) CPUMIsGuestNmiBlocking(PCVMCPU pVCpu);
2672VMM_INT_DECL(void) CPUMSetGuestNmiBlocking(PVMCPU pVCpu, bool fBlock);
2673
2674/** @name Typical scalable bus frequency values.
2675 * @{ */
2676/** Special internal value indicating that we don't know the frequency.
2677 * @internal */
2678#define CPUM_SBUSFREQ_UNKNOWN UINT64_C(1)
2679#define CPUM_SBUSFREQ_100MHZ UINT64_C(100000000)
2680#define CPUM_SBUSFREQ_133MHZ UINT64_C(133333333)
2681#define CPUM_SBUSFREQ_167MHZ UINT64_C(166666666)
2682#define CPUM_SBUSFREQ_200MHZ UINT64_C(200000000)
2683#define CPUM_SBUSFREQ_267MHZ UINT64_C(266666666)
2684#define CPUM_SBUSFREQ_333MHZ UINT64_C(333333333)
2685#define CPUM_SBUSFREQ_400MHZ UINT64_C(400000000)
2686/** @} */
2687
2688
2689#ifdef IN_RING3
2690/** @defgroup grp_cpum_r3 The CPUM ring-3 API
2691 * @{
2692 */
2693
2694VMMR3DECL(int) CPUMR3Init(PVM pVM);
2695VMMR3DECL(int) CPUMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
2696VMMR3DECL(void) CPUMR3LogCpuIdAndMsrFeatures(PVM pVM);
2697VMMR3DECL(void) CPUMR3Relocate(PVM pVM);
2698VMMR3DECL(int) CPUMR3Term(PVM pVM);
2699VMMR3DECL(void) CPUMR3Reset(PVM pVM);
2700VMMR3DECL(void) CPUMR3ResetCpu(PVM pVM, PVMCPU pVCpu);
2701VMMDECL(bool) CPUMR3IsStateRestorePending(PVM pVM);
2702VMMR3DECL(int) CPUMR3SetCR4Feature(PVM pVM, RTHCUINTREG fOr, RTHCUINTREG fAnd);
2703
2704VMMR3DECL(int) CPUMR3CpuIdInsert(PVM pVM, PCPUMCPUIDLEAF pNewLeaf);
2705VMMR3DECL(int) CPUMR3CpuIdGetLeaf(PVM pVM, PCPUMCPUIDLEAF pLeaf, uint32_t uLeaf, uint32_t uSubLeaf);
2706VMMR3_INT_DECL(PCCPUMCPUIDLEAF) CPUMR3CpuIdGetPtr(PVM pVM, uint32_t *pcLeaves);
2707VMMR3DECL(CPUMMICROARCH) CPUMR3CpuIdDetermineMicroarchEx(CPUMCPUVENDOR enmVendor, uint8_t bFamily,
2708 uint8_t bModel, uint8_t bStepping);
2709VMMR3DECL(const char *) CPUMR3MicroarchName(CPUMMICROARCH enmMicroarch);
2710VMMR3DECL(int) CPUMR3CpuIdCollectLeaves(PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves);
2711VMMR3DECL(int) CPUMR3CpuIdDetectUnknownLeafMethod(PCPUMUNKNOWNCPUID penmUnknownMethod, PCPUMCPUID pDefUnknown);
2712VMMR3DECL(const char *) CPUMR3CpuIdUnknownLeafMethodName(CPUMUNKNOWNCPUID enmUnknownMethod);
2713VMMR3DECL(CPUMCPUVENDOR) CPUMR3CpuIdDetectVendorEx(uint32_t uEAX, uint32_t uEBX, uint32_t uECX, uint32_t uEDX);
2714VMMR3DECL(const char *) CPUMR3CpuVendorName(CPUMCPUVENDOR enmVendor);
2715VMMR3DECL(uint32_t) CPUMR3DeterminHostMxCsrMask(void);
2716
2717VMMR3DECL(int) CPUMR3MsrRangesInsert(PVM pVM, PCCPUMMSRRANGE pNewRange);
2718
2719VMMR3DECL(uint32_t) CPUMR3DbGetEntries(void);
2720/** Pointer to CPUMR3DbGetEntries. */
2721typedef DECLCALLBACKPTR(uint32_t, PFNCPUMDBGETENTRIES, (void));
2722VMMR3DECL(PCCPUMDBENTRY) CPUMR3DbGetEntryByIndex(uint32_t idxCpuDb);
2723/** Pointer to CPUMR3DbGetEntryByIndex. */
2724typedef DECLCALLBACKPTR(PCCPUMDBENTRY, PFNCPUMDBGETENTRYBYINDEX, (uint32_t idxCpuDb));
2725VMMR3DECL(PCCPUMDBENTRY) CPUMR3DbGetEntryByName(const char *pszName);
2726/** Pointer to CPUMR3DbGetEntryByName. */
2727typedef DECLCALLBACKPTR(PCCPUMDBENTRY, PFNCPUMDBGETENTRYBYNAME, (const char *pszName));
2728/** @} */
2729#endif /* IN_RING3 */
2730
2731#ifdef IN_RING0
2732/** @defgroup grp_cpum_r0 The CPUM ring-0 API
2733 * @{
2734 */
2735VMMR0_INT_DECL(int) CPUMR0ModuleInit(void);
2736VMMR0_INT_DECL(int) CPUMR0ModuleTerm(void);
2737VMMR0_INT_DECL(int) CPUMR0InitVM(PVMCC pVM);
2738DECLASM(void) CPUMR0RegisterVCpuThread(PVMCPUCC pVCpu);
2739DECLASM(void) CPUMR0TouchHostFpu(void);
2740VMMR0_INT_DECL(int) CPUMR0Trap07Handler(PVMCC pVM, PVMCPUCC pVCpu);
2741VMMR0_INT_DECL(int) CPUMR0LoadGuestFPU(PVMCC pVM, PVMCPUCC pVCpu);
2742VMMR0_INT_DECL(bool) CPUMR0FpuStateMaybeSaveGuestAndRestoreHost(PVMCPUCC pVCpu);
2743VMMR0_INT_DECL(int) CPUMR0SaveHostDebugState(PVMCC pVM, PVMCPUCC pVCpu);
2744VMMR0_INT_DECL(bool) CPUMR0DebugStateMaybeSaveGuestAndRestoreHost(PVMCPUCC pVCpu, bool fDr6);
2745VMMR0_INT_DECL(bool) CPUMR0DebugStateMaybeSaveGuest(PVMCPUCC pVCpu, bool fDr6);
2746
2747VMMR0_INT_DECL(void) CPUMR0LoadGuestDebugState(PVMCPUCC pVCpu, bool fDr6);
2748VMMR0_INT_DECL(void) CPUMR0LoadHyperDebugState(PVMCPUCC pVCpu, bool fDr6);
2749#ifdef VBOX_WITH_VMMR0_DISABLE_LAPIC_NMI
2750VMMR0_INT_DECL(void) CPUMR0SetLApic(PVMCPUCC pVCpu, uint32_t iHostCpuSet);
2751#endif
2752
2753/** @} */
2754#endif /* IN_RING0 */
2755
2756/** @defgroup grp_cpum_rz The CPUM raw-mode and ring-0 context API
2757 * @{
2758 */
2759VMMRZ_INT_DECL(void) CPUMRZFpuStatePrepareHostCpuForUse(PVMCPUCC pVCpu);
2760VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeForRead(PVMCPUCC pVCpu);
2761VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeForChange(PVMCPUCC pVCpu);
2762VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeSseForRead(PVMCPUCC pVCpu);
2763VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeAvxForRead(PVMCPUCC pVCpu);
2764/** @} */
2765
2766
2767#endif /* !VBOX_FOR_DTRACE_LIB */
2768/** @} */
2769RT_C_DECLS_END
2770
2771
2772#endif /* !VBOX_INCLUDED_vmm_cpum_h */
2773
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