VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/CPUMR3CpuId.cpp@ 93444

Last change on this file since 93444 was 93268, checked in by vboxsync, 3 years ago

VMM: Nested VMX: bugref:10092 True VMX controls MSR support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 342.4 KB
Line 
1/* $Id: CPUMR3CpuId.cpp 93268 2022-01-17 11:15:12Z vboxsync $ */
2/** @file
3 * CPUM - CPU ID part.
4 */
5
6/*
7 * Copyright (C) 2013-2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_CPUM
23#include <VBox/vmm/cpum.h>
24#include <VBox/vmm/dbgf.h>
25#include <VBox/vmm/hm.h>
26#include <VBox/vmm/nem.h>
27#include <VBox/vmm/ssm.h>
28#include "CPUMInternal.h"
29#include <VBox/vmm/vmcc.h>
30#include <VBox/sup.h>
31
32#include <VBox/err.h>
33#include <iprt/asm-amd64-x86.h>
34#include <iprt/ctype.h>
35#include <iprt/mem.h>
36#include <iprt/string.h>
37
38
39/*********************************************************************************************************************************
40* Defined Constants And Macros *
41*********************************************************************************************************************************/
42/** For sanity and avoid wasting hyper heap on buggy config / saved state. */
43#define CPUM_CPUID_MAX_LEAVES 2048
44/** Max size we accept for the XSAVE area.
45 * @see CPUMCTX::abXSave */
46#define CPUM_MAX_XSAVE_AREA_SIZE (0x4000 - 0x300)
47/* Min size we accept for the XSAVE area. */
48#define CPUM_MIN_XSAVE_AREA_SIZE 0x240
49
50
51/*********************************************************************************************************************************
52* Global Variables *
53*********************************************************************************************************************************/
54/**
55 * The intel pentium family.
56 */
57static const CPUMMICROARCH g_aenmIntelFamily06[] =
58{
59 /* [ 0(0x00)] = */ kCpumMicroarch_Intel_P6, /* Pentium Pro A-step (says sandpile.org). */
60 /* [ 1(0x01)] = */ kCpumMicroarch_Intel_P6, /* Pentium Pro */
61 /* [ 2(0x02)] = */ kCpumMicroarch_Intel_Unknown,
62 /* [ 3(0x03)] = */ kCpumMicroarch_Intel_P6_II, /* PII Klamath */
63 /* [ 4(0x04)] = */ kCpumMicroarch_Intel_Unknown,
64 /* [ 5(0x05)] = */ kCpumMicroarch_Intel_P6_II, /* PII Deschutes */
65 /* [ 6(0x06)] = */ kCpumMicroarch_Intel_P6_II, /* Celeron Mendocino. */
66 /* [ 7(0x07)] = */ kCpumMicroarch_Intel_P6_III, /* PIII Katmai. */
67 /* [ 8(0x08)] = */ kCpumMicroarch_Intel_P6_III, /* PIII Coppermine (includes Celeron). */
68 /* [ 9(0x09)] = */ kCpumMicroarch_Intel_P6_M_Banias, /* Pentium/Celeron M Banias. */
69 /* [10(0x0a)] = */ kCpumMicroarch_Intel_P6_III, /* PIII Xeon */
70 /* [11(0x0b)] = */ kCpumMicroarch_Intel_P6_III, /* PIII Tualatin (includes Celeron). */
71 /* [12(0x0c)] = */ kCpumMicroarch_Intel_Unknown,
72 /* [13(0x0d)] = */ kCpumMicroarch_Intel_P6_M_Dothan, /* Pentium/Celeron M Dothan. */
73 /* [14(0x0e)] = */ kCpumMicroarch_Intel_Core_Yonah, /* Core Yonah (Enhanced Pentium M). */
74 /* [15(0x0f)] = */ kCpumMicroarch_Intel_Core2_Merom, /* Merom */
75 /* [16(0x10)] = */ kCpumMicroarch_Intel_Unknown,
76 /* [17(0x11)] = */ kCpumMicroarch_Intel_Unknown,
77 /* [18(0x12)] = */ kCpumMicroarch_Intel_Unknown,
78 /* [19(0x13)] = */ kCpumMicroarch_Intel_Unknown,
79 /* [20(0x14)] = */ kCpumMicroarch_Intel_Unknown,
80 /* [21(0x15)] = */ kCpumMicroarch_Intel_P6_M_Dothan, /* Tolapai - System-on-a-chip. */
81 /* [22(0x16)] = */ kCpumMicroarch_Intel_Core2_Merom,
82 /* [23(0x17)] = */ kCpumMicroarch_Intel_Core2_Penryn,
83 /* [24(0x18)] = */ kCpumMicroarch_Intel_Unknown,
84 /* [25(0x19)] = */ kCpumMicroarch_Intel_Unknown,
85 /* [26(0x1a)] = */ kCpumMicroarch_Intel_Core7_Nehalem, /* Nehalem-EP */
86 /* [27(0x1b)] = */ kCpumMicroarch_Intel_Unknown,
87 /* [28(0x1c)] = */ kCpumMicroarch_Intel_Atom_Bonnell, /* Diamonville, Pineview, */
88 /* [29(0x1d)] = */ kCpumMicroarch_Intel_Core2_Penryn,
89 /* [30(0x1e)] = */ kCpumMicroarch_Intel_Core7_Nehalem, /* Clarksfield, Lynnfield, Jasper Forest. */
90 /* [31(0x1f)] = */ kCpumMicroarch_Intel_Core7_Nehalem, /* Only listed by sandpile.org. 2 cores ABD/HVD, whatever that means. */
91 /* [32(0x20)] = */ kCpumMicroarch_Intel_Unknown,
92 /* [33(0x21)] = */ kCpumMicroarch_Intel_Unknown,
93 /* [34(0x22)] = */ kCpumMicroarch_Intel_Unknown,
94 /* [35(0x23)] = */ kCpumMicroarch_Intel_Unknown,
95 /* [36(0x24)] = */ kCpumMicroarch_Intel_Unknown,
96 /* [37(0x25)] = */ kCpumMicroarch_Intel_Core7_Westmere, /* Arrandale, Clarksdale. */
97 /* [38(0x26)] = */ kCpumMicroarch_Intel_Atom_Lincroft,
98 /* [39(0x27)] = */ kCpumMicroarch_Intel_Atom_Saltwell,
99 /* [40(0x28)] = */ kCpumMicroarch_Intel_Unknown,
100 /* [41(0x29)] = */ kCpumMicroarch_Intel_Unknown,
101 /* [42(0x2a)] = */ kCpumMicroarch_Intel_Core7_SandyBridge,
102 /* [43(0x2b)] = */ kCpumMicroarch_Intel_Unknown,
103 /* [44(0x2c)] = */ kCpumMicroarch_Intel_Core7_Westmere, /* Gulftown, Westmere-EP. */
104 /* [45(0x2d)] = */ kCpumMicroarch_Intel_Core7_SandyBridge, /* SandyBridge-E, SandyBridge-EN, SandyBridge-EP. */
105 /* [46(0x2e)] = */ kCpumMicroarch_Intel_Core7_Nehalem, /* Beckton (Xeon). */
106 /* [47(0x2f)] = */ kCpumMicroarch_Intel_Core7_Westmere, /* Westmere-EX. */
107 /* [48(0x30)] = */ kCpumMicroarch_Intel_Unknown,
108 /* [49(0x31)] = */ kCpumMicroarch_Intel_Unknown,
109 /* [50(0x32)] = */ kCpumMicroarch_Intel_Unknown,
110 /* [51(0x33)] = */ kCpumMicroarch_Intel_Unknown,
111 /* [52(0x34)] = */ kCpumMicroarch_Intel_Unknown,
112 /* [53(0x35)] = */ kCpumMicroarch_Intel_Atom_Saltwell, /* ?? */
113 /* [54(0x36)] = */ kCpumMicroarch_Intel_Atom_Saltwell, /* Cedarview, ++ */
114 /* [55(0x37)] = */ kCpumMicroarch_Intel_Atom_Silvermont,
115 /* [56(0x38)] = */ kCpumMicroarch_Intel_Unknown,
116 /* [57(0x39)] = */ kCpumMicroarch_Intel_Unknown,
117 /* [58(0x3a)] = */ kCpumMicroarch_Intel_Core7_IvyBridge,
118 /* [59(0x3b)] = */ kCpumMicroarch_Intel_Unknown,
119 /* [60(0x3c)] = */ kCpumMicroarch_Intel_Core7_Haswell,
120 /* [61(0x3d)] = */ kCpumMicroarch_Intel_Core7_Broadwell,
121 /* [62(0x3e)] = */ kCpumMicroarch_Intel_Core7_IvyBridge,
122 /* [63(0x3f)] = */ kCpumMicroarch_Intel_Core7_Haswell,
123 /* [64(0x40)] = */ kCpumMicroarch_Intel_Unknown,
124 /* [65(0x41)] = */ kCpumMicroarch_Intel_Unknown,
125 /* [66(0x42)] = */ kCpumMicroarch_Intel_Unknown,
126 /* [67(0x43)] = */ kCpumMicroarch_Intel_Unknown,
127 /* [68(0x44)] = */ kCpumMicroarch_Intel_Unknown,
128 /* [69(0x45)] = */ kCpumMicroarch_Intel_Core7_Haswell,
129 /* [70(0x46)] = */ kCpumMicroarch_Intel_Core7_Haswell,
130 /* [71(0x47)] = */ kCpumMicroarch_Intel_Core7_Broadwell, /* i7-5775C */
131 /* [72(0x48)] = */ kCpumMicroarch_Intel_Unknown,
132 /* [73(0x49)] = */ kCpumMicroarch_Intel_Unknown,
133 /* [74(0x4a)] = */ kCpumMicroarch_Intel_Atom_Silvermont,
134 /* [75(0x4b)] = */ kCpumMicroarch_Intel_Unknown,
135 /* [76(0x4c)] = */ kCpumMicroarch_Intel_Atom_Airmount,
136 /* [77(0x4d)] = */ kCpumMicroarch_Intel_Atom_Silvermont,
137 /* [78(0x4e)] = */ kCpumMicroarch_Intel_Core7_Skylake,
138 /* [79(0x4f)] = */ kCpumMicroarch_Intel_Core7_Broadwell, /* Broadwell-E */
139 /* [80(0x50)] = */ kCpumMicroarch_Intel_Unknown,
140 /* [81(0x51)] = */ kCpumMicroarch_Intel_Unknown,
141 /* [82(0x52)] = */ kCpumMicroarch_Intel_Unknown,
142 /* [83(0x53)] = */ kCpumMicroarch_Intel_Unknown,
143 /* [84(0x54)] = */ kCpumMicroarch_Intel_Unknown,
144 /* [85(0x55)] = */ kCpumMicroarch_Intel_Core7_Skylake, /* server cpu; skylake <= 4, cascade lake > 5 */
145 /* [86(0x56)] = */ kCpumMicroarch_Intel_Core7_Broadwell, /* Xeon D-1540, Broadwell-DE */
146 /* [87(0x57)] = */ kCpumMicroarch_Intel_Phi_KnightsLanding,
147 /* [88(0x58)] = */ kCpumMicroarch_Intel_Unknown,
148 /* [89(0x59)] = */ kCpumMicroarch_Intel_Unknown,
149 /* [90(0x5a)] = */ kCpumMicroarch_Intel_Atom_Silvermont, /* Moorefield */
150 /* [91(0x5b)] = */ kCpumMicroarch_Intel_Unknown,
151 /* [92(0x5c)] = */ kCpumMicroarch_Intel_Atom_Goldmont, /* Apollo Lake */
152 /* [93(0x5d)] = */ kCpumMicroarch_Intel_Atom_Silvermont, /* x3-C3230 */
153 /* [94(0x5e)] = */ kCpumMicroarch_Intel_Core7_Skylake, /* i7-6700K */
154 /* [95(0x5f)] = */ kCpumMicroarch_Intel_Atom_Goldmont, /* Denverton */
155 /* [96(0x60)] = */ kCpumMicroarch_Intel_Unknown,
156 /* [97(0x61)] = */ kCpumMicroarch_Intel_Unknown,
157 /* [98(0x62)] = */ kCpumMicroarch_Intel_Unknown,
158 /* [99(0x63)] = */ kCpumMicroarch_Intel_Unknown,
159 /*[100(0x64)] = */ kCpumMicroarch_Intel_Unknown,
160 /*[101(0x65)] = */ kCpumMicroarch_Intel_Atom_Silvermont, /* SoFIA */
161 /*[102(0x66)] = */ kCpumMicroarch_Intel_Core7_CannonLake, /* unconfirmed */
162 /*[103(0x67)] = */ kCpumMicroarch_Intel_Unknown,
163 /*[104(0x68)] = */ kCpumMicroarch_Intel_Unknown,
164 /*[105(0x69)] = */ kCpumMicroarch_Intel_Unknown,
165 /*[106(0x6a)] = */ kCpumMicroarch_Intel_Core7_IceLake, /* unconfirmed server */
166 /*[107(0x6b)] = */ kCpumMicroarch_Intel_Unknown,
167 /*[108(0x6c)] = */ kCpumMicroarch_Intel_Core7_IceLake, /* unconfirmed server */
168 /*[109(0x6d)] = */ kCpumMicroarch_Intel_Unknown,
169 /*[110(0x6e)] = */ kCpumMicroarch_Intel_Atom_Airmount, /* or silvermount? */
170 /*[111(0x6f)] = */ kCpumMicroarch_Intel_Unknown,
171 /*[112(0x70)] = */ kCpumMicroarch_Intel_Unknown,
172 /*[113(0x71)] = */ kCpumMicroarch_Intel_Unknown,
173 /*[114(0x72)] = */ kCpumMicroarch_Intel_Unknown,
174 /*[115(0x73)] = */ kCpumMicroarch_Intel_Unknown,
175 /*[116(0x74)] = */ kCpumMicroarch_Intel_Unknown,
176 /*[117(0x75)] = */ kCpumMicroarch_Intel_Atom_Airmount, /* or silvermount? */
177 /*[118(0x76)] = */ kCpumMicroarch_Intel_Unknown,
178 /*[119(0x77)] = */ kCpumMicroarch_Intel_Unknown,
179 /*[120(0x78)] = */ kCpumMicroarch_Intel_Unknown,
180 /*[121(0x79)] = */ kCpumMicroarch_Intel_Unknown,
181 /*[122(0x7a)] = */ kCpumMicroarch_Intel_Atom_GoldmontPlus,
182 /*[123(0x7b)] = */ kCpumMicroarch_Intel_Unknown,
183 /*[124(0x7c)] = */ kCpumMicroarch_Intel_Unknown,
184 /*[125(0x7d)] = */ kCpumMicroarch_Intel_Core7_IceLake, /* unconfirmed */
185 /*[126(0x7e)] = */ kCpumMicroarch_Intel_Core7_IceLake, /* unconfirmed */
186 /*[127(0x7f)] = */ kCpumMicroarch_Intel_Unknown,
187 /*[128(0x80)] = */ kCpumMicroarch_Intel_Unknown,
188 /*[129(0x81)] = */ kCpumMicroarch_Intel_Unknown,
189 /*[130(0x82)] = */ kCpumMicroarch_Intel_Unknown,
190 /*[131(0x83)] = */ kCpumMicroarch_Intel_Unknown,
191 /*[132(0x84)] = */ kCpumMicroarch_Intel_Unknown,
192 /*[133(0x85)] = */ kCpumMicroarch_Intel_Phi_KnightsMill,
193 /*[134(0x86)] = */ kCpumMicroarch_Intel_Unknown,
194 /*[135(0x87)] = */ kCpumMicroarch_Intel_Unknown,
195 /*[136(0x88)] = */ kCpumMicroarch_Intel_Unknown,
196 /*[137(0x89)] = */ kCpumMicroarch_Intel_Unknown,
197 /*[138(0x8a)] = */ kCpumMicroarch_Intel_Unknown,
198 /*[139(0x8b)] = */ kCpumMicroarch_Intel_Unknown,
199 /*[140(0x8c)] = */ kCpumMicroarch_Intel_Core7_TigerLake, /* 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (bird) */
200 /*[141(0x8d)] = */ kCpumMicroarch_Intel_Core7_TigerLake, /* unconfirmed */
201 /*[142(0x8e)] = */ kCpumMicroarch_Intel_Core7_KabyLake, /* Stepping >= 0xB is Whiskey Lake, 0xA is CoffeeLake. */
202 /*[143(0x8f)] = */ kCpumMicroarch_Intel_Core7_SapphireRapids,
203 /*[144(0x90)] = */ kCpumMicroarch_Intel_Unknown,
204 /*[145(0x91)] = */ kCpumMicroarch_Intel_Unknown,
205 /*[146(0x92)] = */ kCpumMicroarch_Intel_Unknown,
206 /*[147(0x93)] = */ kCpumMicroarch_Intel_Unknown,
207 /*[148(0x94)] = */ kCpumMicroarch_Intel_Unknown,
208 /*[149(0x95)] = */ kCpumMicroarch_Intel_Unknown,
209 /*[150(0x96)] = */ kCpumMicroarch_Intel_Unknown,
210 /*[151(0x97)] = */ kCpumMicroarch_Intel_Core7_AlderLake, /* unconfirmed, unreleased */
211 /*[152(0x98)] = */ kCpumMicroarch_Intel_Unknown,
212 /*[153(0x99)] = */ kCpumMicroarch_Intel_Unknown,
213 /*[154(0x9a)] = */ kCpumMicroarch_Intel_Core7_AlderLake, /* unconfirmed, unreleased */
214 /*[155(0x9b)] = */ kCpumMicroarch_Intel_Unknown,
215 /*[156(0x9c)] = */ kCpumMicroarch_Intel_Unknown,
216 /*[157(0x9d)] = */ kCpumMicroarch_Intel_Unknown,
217 /*[158(0x9e)] = */ kCpumMicroarch_Intel_Core7_KabyLake, /* Stepping >= 0xB is Whiskey Lake, 0xA is CoffeeLake. */
218 /*[159(0x9f)] = */ kCpumMicroarch_Intel_Unknown,
219 /*[160(0xa0)] = */ kCpumMicroarch_Intel_Unknown,
220 /*[161(0xa1)] = */ kCpumMicroarch_Intel_Unknown,
221 /*[162(0xa2)] = */ kCpumMicroarch_Intel_Unknown,
222 /*[163(0xa3)] = */ kCpumMicroarch_Intel_Unknown,
223 /*[164(0xa4)] = */ kCpumMicroarch_Intel_Unknown,
224 /*[165(0xa5)] = */ kCpumMicroarch_Intel_Core7_CometLake, /* unconfirmed */
225 /*[166(0xa6)] = */ kCpumMicroarch_Intel_Unknown,
226 /*[167(0xa7)] = */ kCpumMicroarch_Intel_Core7_CypressCove, /* 14nm backport, unconfirmed */
227};
228AssertCompile(RT_ELEMENTS(g_aenmIntelFamily06) == 0xa7+1);
229
230
231/**
232 * Figures out the (sub-)micro architecture given a bit of CPUID info.
233 *
234 * @returns Micro architecture.
235 * @param enmVendor The CPU vendor.
236 * @param bFamily The CPU family.
237 * @param bModel The CPU model.
238 * @param bStepping The CPU stepping.
239 */
240VMMR3DECL(CPUMMICROARCH) CPUMR3CpuIdDetermineMicroarchEx(CPUMCPUVENDOR enmVendor, uint8_t bFamily,
241 uint8_t bModel, uint8_t bStepping)
242{
243 if (enmVendor == CPUMCPUVENDOR_AMD)
244 {
245 switch (bFamily)
246 {
247 case 0x02: return kCpumMicroarch_AMD_Am286; /* Not really kosher... */
248 case 0x03: return kCpumMicroarch_AMD_Am386;
249 case 0x23: return kCpumMicroarch_AMD_Am386; /* SX*/
250 case 0x04: return bModel < 14 ? kCpumMicroarch_AMD_Am486 : kCpumMicroarch_AMD_Am486Enh;
251 case 0x05: return bModel < 6 ? kCpumMicroarch_AMD_K5 : kCpumMicroarch_AMD_K6; /* Genode LX is 0x0a, lump it with K6. */
252 case 0x06:
253 switch (bModel)
254 {
255 case 0: return kCpumMicroarch_AMD_K7_Palomino;
256 case 1: return kCpumMicroarch_AMD_K7_Palomino;
257 case 2: return kCpumMicroarch_AMD_K7_Palomino;
258 case 3: return kCpumMicroarch_AMD_K7_Spitfire;
259 case 4: return kCpumMicroarch_AMD_K7_Thunderbird;
260 case 6: return kCpumMicroarch_AMD_K7_Palomino;
261 case 7: return kCpumMicroarch_AMD_K7_Morgan;
262 case 8: return kCpumMicroarch_AMD_K7_Thoroughbred;
263 case 10: return kCpumMicroarch_AMD_K7_Barton; /* Thorton too. */
264 }
265 return kCpumMicroarch_AMD_K7_Unknown;
266 case 0x0f:
267 /*
268 * This family is a friggin mess. Trying my best to make some
269 * sense out of it. Too much happened in the 0x0f family to
270 * lump it all together as K8 (130nm->90nm->65nm, AMD-V, ++).
271 *
272 * Emperical CPUID.01h.EAX evidence from revision guides, wikipedia,
273 * cpu-world.com, and other places:
274 * - 130nm:
275 * - ClawHammer: F7A/SH-CG, F5A/-CG, F4A/-CG, F50/-B0, F48/-C0, F58/-C0,
276 * - SledgeHammer: F50/SH-B0, F48/-C0, F58/-C0, F4A/-CG, F5A/-CG, F7A/-CG, F51/-B3
277 * - Newcastle: FC0/DH-CG (erratum #180: FE0/DH-CG), FF0/DH-CG
278 * - Dublin: FC0/-CG, FF0/-CG, F82/CH-CG, F4A/-CG, F48/SH-C0,
279 * - Odessa: FC0/DH-CG (erratum #180: FE0/DH-CG)
280 * - Paris: FF0/DH-CG, FC0/DH-CG (erratum #180: FE0/DH-CG),
281 * - 90nm:
282 * - Winchester: 10FF0/DH-D0, 20FF0/DH-E3.
283 * - Oakville: 10FC0/DH-D0.
284 * - Georgetown: 10FC0/DH-D0.
285 * - Sonora: 10FC0/DH-D0.
286 * - Venus: 20F71/SH-E4
287 * - Troy: 20F51/SH-E4
288 * - Athens: 20F51/SH-E4
289 * - San Diego: 20F71/SH-E4.
290 * - Lancaster: 20F42/SH-E5
291 * - Newark: 20F42/SH-E5.
292 * - Albany: 20FC2/DH-E6.
293 * - Roma: 20FC2/DH-E6.
294 * - Venice: 20FF0/DH-E3, 20FC2/DH-E6, 20FF2/DH-E6.
295 * - Palermo: 10FC0/DH-D0, 20FF0/DH-E3, 20FC0/DH-E3, 20FC2/DH-E6, 20FF2/DH-E6
296 * - 90nm introducing Dual core:
297 * - Denmark: 20F30/JH-E1, 20F32/JH-E6
298 * - Italy: 20F10/JH-E1, 20F12/JH-E6
299 * - Egypt: 20F10/JH-E1, 20F12/JH-E6
300 * - Toledo: 20F32/JH-E6, 30F72/DH-E6 (single code variant).
301 * - Manchester: 20FB1/BH-E4, 30FF2/BH-E4.
302 * - 90nm 2nd gen opteron ++, AMD-V introduced (might be missing in some cheaper models):
303 * - Santa Ana: 40F32/JH-F2, /-F3
304 * - Santa Rosa: 40F12/JH-F2, 40F13/JH-F3
305 * - Windsor: 40F32/JH-F2, 40F33/JH-F3, C0F13/JH-F3, 40FB2/BH-F2, ??20FB1/BH-E4??.
306 * - Manila: 50FF2/DH-F2, 40FF2/DH-F2
307 * - Orleans: 40FF2/DH-F2, 50FF2/DH-F2, 50FF3/DH-F3.
308 * - Keene: 40FC2/DH-F2.
309 * - Richmond: 40FC2/DH-F2
310 * - Taylor: 40F82/BH-F2
311 * - Trinidad: 40F82/BH-F2
312 *
313 * - 65nm:
314 * - Brisbane: 60FB1/BH-G1, 60FB2/BH-G2.
315 * - Tyler: 60F81/BH-G1, 60F82/BH-G2.
316 * - Sparta: 70FF1/DH-G1, 70FF2/DH-G2.
317 * - Lima: 70FF1/DH-G1, 70FF2/DH-G2.
318 * - Sherman: /-G1, 70FC2/DH-G2.
319 * - Huron: 70FF2/DH-G2.
320 */
321 if (bModel < 0x10)
322 return kCpumMicroarch_AMD_K8_130nm;
323 if (bModel >= 0x60 && bModel < 0x80)
324 return kCpumMicroarch_AMD_K8_65nm;
325 if (bModel >= 0x40)
326 return kCpumMicroarch_AMD_K8_90nm_AMDV;
327 switch (bModel)
328 {
329 case 0x21:
330 case 0x23:
331 case 0x2b:
332 case 0x2f:
333 case 0x37:
334 case 0x3f:
335 return kCpumMicroarch_AMD_K8_90nm_DualCore;
336 }
337 return kCpumMicroarch_AMD_K8_90nm;
338 case 0x10:
339 return kCpumMicroarch_AMD_K10;
340 case 0x11:
341 return kCpumMicroarch_AMD_K10_Lion;
342 case 0x12:
343 return kCpumMicroarch_AMD_K10_Llano;
344 case 0x14:
345 return kCpumMicroarch_AMD_Bobcat;
346 case 0x15:
347 switch (bModel)
348 {
349 case 0x00: return kCpumMicroarch_AMD_15h_Bulldozer; /* Any? prerelease? */
350 case 0x01: return kCpumMicroarch_AMD_15h_Bulldozer; /* Opteron 4200, FX-81xx. */
351 case 0x02: return kCpumMicroarch_AMD_15h_Piledriver; /* Opteron 4300, FX-83xx. */
352 case 0x10: return kCpumMicroarch_AMD_15h_Piledriver; /* A10-5800K for e.g. */
353 case 0x11: /* ?? */
354 case 0x12: /* ?? */
355 case 0x13: return kCpumMicroarch_AMD_15h_Piledriver; /* A10-6800K for e.g. */
356 }
357 return kCpumMicroarch_AMD_15h_Unknown;
358 case 0x16:
359 return kCpumMicroarch_AMD_Jaguar;
360 case 0x17:
361 return kCpumMicroarch_AMD_Zen_Ryzen;
362 }
363 return kCpumMicroarch_AMD_Unknown;
364 }
365
366 if (enmVendor == CPUMCPUVENDOR_INTEL)
367 {
368 switch (bFamily)
369 {
370 case 3:
371 return kCpumMicroarch_Intel_80386;
372 case 4:
373 return kCpumMicroarch_Intel_80486;
374 case 5:
375 return kCpumMicroarch_Intel_P5;
376 case 6:
377 if (bModel < RT_ELEMENTS(g_aenmIntelFamily06))
378 {
379 CPUMMICROARCH enmMicroArch = g_aenmIntelFamily06[bModel];
380 if (enmMicroArch == kCpumMicroarch_Intel_Core7_KabyLake)
381 {
382 if (bStepping >= 0xa && bStepping <= 0xc)
383 enmMicroArch = kCpumMicroarch_Intel_Core7_CoffeeLake;
384 else if (bStepping >= 0xc)
385 enmMicroArch = kCpumMicroarch_Intel_Core7_WhiskeyLake;
386 }
387 else if ( enmMicroArch == kCpumMicroarch_Intel_Core7_Skylake
388 && bModel == 0x55
389 && bStepping >= 5)
390 enmMicroArch = kCpumMicroarch_Intel_Core7_CascadeLake;
391 return enmMicroArch;
392 }
393 return kCpumMicroarch_Intel_Atom_Unknown;
394 case 15:
395 switch (bModel)
396 {
397 case 0: return kCpumMicroarch_Intel_NB_Willamette;
398 case 1: return kCpumMicroarch_Intel_NB_Willamette;
399 case 2: return kCpumMicroarch_Intel_NB_Northwood;
400 case 3: return kCpumMicroarch_Intel_NB_Prescott;
401 case 4: return kCpumMicroarch_Intel_NB_Prescott2M; /* ?? */
402 case 5: return kCpumMicroarch_Intel_NB_Unknown; /*??*/
403 case 6: return kCpumMicroarch_Intel_NB_CedarMill;
404 case 7: return kCpumMicroarch_Intel_NB_Gallatin;
405 default: return kCpumMicroarch_Intel_NB_Unknown;
406 }
407 break;
408 /* The following are not kosher but kind of follow intuitively from 6, 5 & 4. */
409 case 0:
410 return kCpumMicroarch_Intel_8086;
411 case 1:
412 return kCpumMicroarch_Intel_80186;
413 case 2:
414 return kCpumMicroarch_Intel_80286;
415 }
416 return kCpumMicroarch_Intel_Unknown;
417 }
418
419 if (enmVendor == CPUMCPUVENDOR_VIA)
420 {
421 switch (bFamily)
422 {
423 case 5:
424 switch (bModel)
425 {
426 case 1: return kCpumMicroarch_Centaur_C6;
427 case 4: return kCpumMicroarch_Centaur_C6;
428 case 8: return kCpumMicroarch_Centaur_C2;
429 case 9: return kCpumMicroarch_Centaur_C3;
430 }
431 break;
432
433 case 6:
434 switch (bModel)
435 {
436 case 5: return kCpumMicroarch_VIA_C3_M2;
437 case 6: return kCpumMicroarch_VIA_C3_C5A;
438 case 7: return bStepping < 8 ? kCpumMicroarch_VIA_C3_C5B : kCpumMicroarch_VIA_C3_C5C;
439 case 8: return kCpumMicroarch_VIA_C3_C5N;
440 case 9: return bStepping < 8 ? kCpumMicroarch_VIA_C3_C5XL : kCpumMicroarch_VIA_C3_C5P;
441 case 10: return kCpumMicroarch_VIA_C7_C5J;
442 case 15: return kCpumMicroarch_VIA_Isaiah;
443 }
444 break;
445 }
446 return kCpumMicroarch_VIA_Unknown;
447 }
448
449 if (enmVendor == CPUMCPUVENDOR_SHANGHAI)
450 {
451 switch (bFamily)
452 {
453 case 6:
454 case 7:
455 return kCpumMicroarch_Shanghai_Wudaokou;
456 default:
457 break;
458 }
459 return kCpumMicroarch_Shanghai_Unknown;
460 }
461
462 if (enmVendor == CPUMCPUVENDOR_CYRIX)
463 {
464 switch (bFamily)
465 {
466 case 4:
467 switch (bModel)
468 {
469 case 9: return kCpumMicroarch_Cyrix_5x86;
470 }
471 break;
472
473 case 5:
474 switch (bModel)
475 {
476 case 2: return kCpumMicroarch_Cyrix_M1;
477 case 4: return kCpumMicroarch_Cyrix_MediaGX;
478 case 5: return kCpumMicroarch_Cyrix_MediaGXm;
479 }
480 break;
481
482 case 6:
483 switch (bModel)
484 {
485 case 0: return kCpumMicroarch_Cyrix_M2;
486 }
487 break;
488
489 }
490 return kCpumMicroarch_Cyrix_Unknown;
491 }
492
493 if (enmVendor == CPUMCPUVENDOR_HYGON)
494 {
495 switch (bFamily)
496 {
497 case 0x18:
498 return kCpumMicroarch_Hygon_Dhyana;
499 default:
500 break;
501 }
502 return kCpumMicroarch_Hygon_Unknown;
503 }
504
505 return kCpumMicroarch_Unknown;
506}
507
508
509/**
510 * Translates a microarchitecture enum value to the corresponding string
511 * constant.
512 *
513 * @returns Read-only string constant (omits "kCpumMicroarch_" prefix). Returns
514 * NULL if the value is invalid.
515 *
516 * @param enmMicroarch The enum value to convert.
517 */
518VMMR3DECL(const char *) CPUMR3MicroarchName(CPUMMICROARCH enmMicroarch)
519{
520 switch (enmMicroarch)
521 {
522#define CASE_RET_STR(enmValue) case enmValue: return #enmValue + (sizeof("kCpumMicroarch_") - 1)
523 CASE_RET_STR(kCpumMicroarch_Intel_8086);
524 CASE_RET_STR(kCpumMicroarch_Intel_80186);
525 CASE_RET_STR(kCpumMicroarch_Intel_80286);
526 CASE_RET_STR(kCpumMicroarch_Intel_80386);
527 CASE_RET_STR(kCpumMicroarch_Intel_80486);
528 CASE_RET_STR(kCpumMicroarch_Intel_P5);
529
530 CASE_RET_STR(kCpumMicroarch_Intel_P6);
531 CASE_RET_STR(kCpumMicroarch_Intel_P6_II);
532 CASE_RET_STR(kCpumMicroarch_Intel_P6_III);
533
534 CASE_RET_STR(kCpumMicroarch_Intel_P6_M_Banias);
535 CASE_RET_STR(kCpumMicroarch_Intel_P6_M_Dothan);
536 CASE_RET_STR(kCpumMicroarch_Intel_Core_Yonah);
537
538 CASE_RET_STR(kCpumMicroarch_Intel_Core2_Merom);
539 CASE_RET_STR(kCpumMicroarch_Intel_Core2_Penryn);
540
541 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Nehalem);
542 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Westmere);
543 CASE_RET_STR(kCpumMicroarch_Intel_Core7_SandyBridge);
544 CASE_RET_STR(kCpumMicroarch_Intel_Core7_IvyBridge);
545 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Haswell);
546 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Broadwell);
547 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Skylake);
548 CASE_RET_STR(kCpumMicroarch_Intel_Core7_KabyLake);
549 CASE_RET_STR(kCpumMicroarch_Intel_Core7_CoffeeLake);
550 CASE_RET_STR(kCpumMicroarch_Intel_Core7_WhiskeyLake);
551 CASE_RET_STR(kCpumMicroarch_Intel_Core7_CascadeLake);
552 CASE_RET_STR(kCpumMicroarch_Intel_Core7_CannonLake);
553 CASE_RET_STR(kCpumMicroarch_Intel_Core7_CometLake);
554 CASE_RET_STR(kCpumMicroarch_Intel_Core7_IceLake);
555 CASE_RET_STR(kCpumMicroarch_Intel_Core7_RocketLake);
556 CASE_RET_STR(kCpumMicroarch_Intel_Core7_TigerLake);
557 CASE_RET_STR(kCpumMicroarch_Intel_Core7_AlderLake);
558 CASE_RET_STR(kCpumMicroarch_Intel_Core7_SapphireRapids);
559
560 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Bonnell);
561 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Lincroft);
562 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Saltwell);
563 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Silvermont);
564 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Airmount);
565 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Goldmont);
566 CASE_RET_STR(kCpumMicroarch_Intel_Atom_GoldmontPlus);
567 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Unknown);
568
569 CASE_RET_STR(kCpumMicroarch_Intel_Phi_KnightsFerry);
570 CASE_RET_STR(kCpumMicroarch_Intel_Phi_KnightsCorner);
571 CASE_RET_STR(kCpumMicroarch_Intel_Phi_KnightsLanding);
572 CASE_RET_STR(kCpumMicroarch_Intel_Phi_KnightsHill);
573 CASE_RET_STR(kCpumMicroarch_Intel_Phi_KnightsMill);
574
575 CASE_RET_STR(kCpumMicroarch_Intel_NB_Willamette);
576 CASE_RET_STR(kCpumMicroarch_Intel_NB_Northwood);
577 CASE_RET_STR(kCpumMicroarch_Intel_NB_Prescott);
578 CASE_RET_STR(kCpumMicroarch_Intel_NB_Prescott2M);
579 CASE_RET_STR(kCpumMicroarch_Intel_NB_CedarMill);
580 CASE_RET_STR(kCpumMicroarch_Intel_NB_Gallatin);
581 CASE_RET_STR(kCpumMicroarch_Intel_NB_Unknown);
582
583 CASE_RET_STR(kCpumMicroarch_Intel_Unknown);
584
585 CASE_RET_STR(kCpumMicroarch_AMD_Am286);
586 CASE_RET_STR(kCpumMicroarch_AMD_Am386);
587 CASE_RET_STR(kCpumMicroarch_AMD_Am486);
588 CASE_RET_STR(kCpumMicroarch_AMD_Am486Enh);
589 CASE_RET_STR(kCpumMicroarch_AMD_K5);
590 CASE_RET_STR(kCpumMicroarch_AMD_K6);
591
592 CASE_RET_STR(kCpumMicroarch_AMD_K7_Palomino);
593 CASE_RET_STR(kCpumMicroarch_AMD_K7_Spitfire);
594 CASE_RET_STR(kCpumMicroarch_AMD_K7_Thunderbird);
595 CASE_RET_STR(kCpumMicroarch_AMD_K7_Morgan);
596 CASE_RET_STR(kCpumMicroarch_AMD_K7_Thoroughbred);
597 CASE_RET_STR(kCpumMicroarch_AMD_K7_Barton);
598 CASE_RET_STR(kCpumMicroarch_AMD_K7_Unknown);
599
600 CASE_RET_STR(kCpumMicroarch_AMD_K8_130nm);
601 CASE_RET_STR(kCpumMicroarch_AMD_K8_90nm);
602 CASE_RET_STR(kCpumMicroarch_AMD_K8_90nm_DualCore);
603 CASE_RET_STR(kCpumMicroarch_AMD_K8_90nm_AMDV);
604 CASE_RET_STR(kCpumMicroarch_AMD_K8_65nm);
605
606 CASE_RET_STR(kCpumMicroarch_AMD_K10);
607 CASE_RET_STR(kCpumMicroarch_AMD_K10_Lion);
608 CASE_RET_STR(kCpumMicroarch_AMD_K10_Llano);
609 CASE_RET_STR(kCpumMicroarch_AMD_Bobcat);
610 CASE_RET_STR(kCpumMicroarch_AMD_Jaguar);
611
612 CASE_RET_STR(kCpumMicroarch_AMD_15h_Bulldozer);
613 CASE_RET_STR(kCpumMicroarch_AMD_15h_Piledriver);
614 CASE_RET_STR(kCpumMicroarch_AMD_15h_Steamroller);
615 CASE_RET_STR(kCpumMicroarch_AMD_15h_Excavator);
616 CASE_RET_STR(kCpumMicroarch_AMD_15h_Unknown);
617
618 CASE_RET_STR(kCpumMicroarch_AMD_16h_First);
619
620 CASE_RET_STR(kCpumMicroarch_AMD_Zen_Ryzen);
621
622 CASE_RET_STR(kCpumMicroarch_AMD_Unknown);
623
624 CASE_RET_STR(kCpumMicroarch_Hygon_Dhyana);
625 CASE_RET_STR(kCpumMicroarch_Hygon_Unknown);
626
627 CASE_RET_STR(kCpumMicroarch_Centaur_C6);
628 CASE_RET_STR(kCpumMicroarch_Centaur_C2);
629 CASE_RET_STR(kCpumMicroarch_Centaur_C3);
630 CASE_RET_STR(kCpumMicroarch_VIA_C3_M2);
631 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5A);
632 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5B);
633 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5C);
634 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5N);
635 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5XL);
636 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5P);
637 CASE_RET_STR(kCpumMicroarch_VIA_C7_C5J);
638 CASE_RET_STR(kCpumMicroarch_VIA_Isaiah);
639 CASE_RET_STR(kCpumMicroarch_VIA_Unknown);
640
641 CASE_RET_STR(kCpumMicroarch_Shanghai_Wudaokou);
642 CASE_RET_STR(kCpumMicroarch_Shanghai_Unknown);
643
644 CASE_RET_STR(kCpumMicroarch_Cyrix_5x86);
645 CASE_RET_STR(kCpumMicroarch_Cyrix_M1);
646 CASE_RET_STR(kCpumMicroarch_Cyrix_MediaGX);
647 CASE_RET_STR(kCpumMicroarch_Cyrix_MediaGXm);
648 CASE_RET_STR(kCpumMicroarch_Cyrix_M2);
649 CASE_RET_STR(kCpumMicroarch_Cyrix_Unknown);
650
651 CASE_RET_STR(kCpumMicroarch_NEC_V20);
652 CASE_RET_STR(kCpumMicroarch_NEC_V30);
653
654 CASE_RET_STR(kCpumMicroarch_Unknown);
655
656#undef CASE_RET_STR
657 case kCpumMicroarch_Invalid:
658 case kCpumMicroarch_Intel_End:
659 case kCpumMicroarch_Intel_Core2_End:
660 case kCpumMicroarch_Intel_Core7_End:
661 case kCpumMicroarch_Intel_Atom_End:
662 case kCpumMicroarch_Intel_P6_Core_Atom_End:
663 case kCpumMicroarch_Intel_Phi_End:
664 case kCpumMicroarch_Intel_NB_End:
665 case kCpumMicroarch_AMD_K7_End:
666 case kCpumMicroarch_AMD_K8_End:
667 case kCpumMicroarch_AMD_15h_End:
668 case kCpumMicroarch_AMD_16h_End:
669 case kCpumMicroarch_AMD_Zen_End:
670 case kCpumMicroarch_AMD_End:
671 case kCpumMicroarch_Hygon_End:
672 case kCpumMicroarch_VIA_End:
673 case kCpumMicroarch_Shanghai_End:
674 case kCpumMicroarch_Cyrix_End:
675 case kCpumMicroarch_NEC_End:
676 case kCpumMicroarch_32BitHack:
677 break;
678 /* no default! */
679 }
680
681 return NULL;
682}
683
684
685/**
686 * Determins the host CPU MXCSR mask.
687 *
688 * @returns MXCSR mask.
689 */
690VMMR3DECL(uint32_t) CPUMR3DeterminHostMxCsrMask(void)
691{
692 if ( ASMHasCpuId()
693 && ASMIsValidStdRange(ASMCpuId_EAX(0))
694 && ASMCpuId_EDX(1) & X86_CPUID_FEATURE_EDX_FXSR)
695 {
696 uint8_t volatile abBuf[sizeof(X86FXSTATE) + 64];
697 PX86FXSTATE pState = (PX86FXSTATE)&abBuf[64 - ((uintptr_t)&abBuf[0] & 63)];
698 RT_ZERO(*pState);
699 ASMFxSave(pState);
700 if (pState->MXCSR_MASK == 0)
701 return 0xffbf;
702 return pState->MXCSR_MASK;
703 }
704 return 0;
705}
706
707
708/**
709 * Gets a matching leaf in the CPUID leaf array.
710 *
711 * @returns Pointer to the matching leaf, or NULL if not found.
712 * @param paLeaves The CPUID leaves to search. This is sorted.
713 * @param cLeaves The number of leaves in the array.
714 * @param uLeaf The leaf to locate.
715 * @param uSubLeaf The subleaf to locate. Pass 0 if no sub-leaves.
716 */
717static PCPUMCPUIDLEAF cpumR3CpuIdGetLeaf(PCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf, uint32_t uSubLeaf)
718{
719 /* Lazy bird does linear lookup here since this is only used for the
720 occational CPUID overrides. */
721 for (uint32_t i = 0; i < cLeaves; i++)
722 if ( paLeaves[i].uLeaf == uLeaf
723 && paLeaves[i].uSubLeaf == (uSubLeaf & paLeaves[i].fSubLeafMask))
724 return &paLeaves[i];
725 return NULL;
726}
727
728
729#ifndef IN_VBOX_CPU_REPORT
730/**
731 * Gets a matching leaf in the CPUID leaf array, converted to a CPUMCPUID.
732 *
733 * @returns true if found, false it not.
734 * @param paLeaves The CPUID leaves to search. This is sorted.
735 * @param cLeaves The number of leaves in the array.
736 * @param uLeaf The leaf to locate.
737 * @param uSubLeaf The subleaf to locate. Pass 0 if no sub-leaves.
738 * @param pLegacy The legacy output leaf.
739 */
740static bool cpumR3CpuIdGetLeafLegacy(PCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf, uint32_t uSubLeaf,
741 PCPUMCPUID pLegacy)
742{
743 PCPUMCPUIDLEAF pLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, uLeaf, uSubLeaf);
744 if (pLeaf)
745 {
746 pLegacy->uEax = pLeaf->uEax;
747 pLegacy->uEbx = pLeaf->uEbx;
748 pLegacy->uEcx = pLeaf->uEcx;
749 pLegacy->uEdx = pLeaf->uEdx;
750 return true;
751 }
752 return false;
753}
754#endif /* IN_VBOX_CPU_REPORT */
755
756
757/**
758 * Ensures that the CPUID leaf array can hold one more leaf.
759 *
760 * @returns Pointer to the CPUID leaf array (*ppaLeaves) on success. NULL on
761 * failure.
762 * @param pVM The cross context VM structure. If NULL, use
763 * the process heap, otherwise the VM's hyper heap.
764 * @param ppaLeaves Pointer to the variable holding the array pointer
765 * (input/output).
766 * @param cLeaves The current array size.
767 *
768 * @remarks This function will automatically update the R0 and RC pointers when
769 * using the hyper heap, which means @a ppaLeaves and @a cLeaves must
770 * be the corresponding VM's CPUID arrays (which is asserted).
771 */
772static PCPUMCPUIDLEAF cpumR3CpuIdEnsureSpace(PVM pVM, PCPUMCPUIDLEAF *ppaLeaves, uint32_t cLeaves)
773{
774 /*
775 * If pVM is not specified, we're on the regular heap and can waste a
776 * little space to speed things up.
777 */
778 uint32_t cAllocated;
779 if (!pVM)
780 {
781 cAllocated = RT_ALIGN(cLeaves, 16);
782 if (cLeaves + 1 > cAllocated)
783 {
784 void *pvNew = RTMemRealloc(*ppaLeaves, (cAllocated + 16) * sizeof(**ppaLeaves));
785 if (pvNew)
786 *ppaLeaves = (PCPUMCPUIDLEAF)pvNew;
787 else
788 {
789 RTMemFree(*ppaLeaves);
790 *ppaLeaves = NULL;
791 }
792 }
793 }
794 /*
795 * Otherwise, we're on the hyper heap and are probably just inserting
796 * one or two leaves and should conserve space.
797 */
798 else
799 {
800#ifdef IN_VBOX_CPU_REPORT
801 AssertReleaseFailed();
802#else
803 Assert(ppaLeaves == &pVM->cpum.s.GuestInfo.paCpuIdLeavesR3);
804 Assert(*ppaLeaves == pVM->cpum.s.GuestInfo.aCpuIdLeaves);
805 Assert(cLeaves == pVM->cpum.s.GuestInfo.cCpuIdLeaves);
806
807 if (cLeaves + 1 <= RT_ELEMENTS(pVM->cpum.s.GuestInfo.aCpuIdLeaves))
808 { }
809 else
810 {
811 *ppaLeaves = NULL;
812 LogRel(("CPUM: cpumR3CpuIdEnsureSpace: Out of CPUID space!\n"));
813 }
814#endif
815 }
816 return *ppaLeaves;
817}
818
819
820/**
821 * Append a CPUID leaf or sub-leaf.
822 *
823 * ASSUMES linear insertion order, so we'll won't need to do any searching or
824 * replace anything. Use cpumR3CpuIdInsert() for those cases.
825 *
826 * @returns VINF_SUCCESS or VERR_NO_MEMORY. On error, *ppaLeaves is freed, so
827 * the caller need do no more work.
828 * @param ppaLeaves Pointer to the pointer to the array of sorted
829 * CPUID leaves and sub-leaves.
830 * @param pcLeaves Where we keep the leaf count for *ppaLeaves.
831 * @param uLeaf The leaf we're adding.
832 * @param uSubLeaf The sub-leaf number.
833 * @param fSubLeafMask The sub-leaf mask.
834 * @param uEax The EAX value.
835 * @param uEbx The EBX value.
836 * @param uEcx The ECX value.
837 * @param uEdx The EDX value.
838 * @param fFlags The flags.
839 */
840static int cpumR3CollectCpuIdInfoAddOne(PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves,
841 uint32_t uLeaf, uint32_t uSubLeaf, uint32_t fSubLeafMask,
842 uint32_t uEax, uint32_t uEbx, uint32_t uEcx, uint32_t uEdx, uint32_t fFlags)
843{
844 if (!cpumR3CpuIdEnsureSpace(NULL /* pVM */, ppaLeaves, *pcLeaves))
845 return VERR_NO_MEMORY;
846
847 PCPUMCPUIDLEAF pNew = &(*ppaLeaves)[*pcLeaves];
848 Assert( *pcLeaves == 0
849 || pNew[-1].uLeaf < uLeaf
850 || (pNew[-1].uLeaf == uLeaf && pNew[-1].uSubLeaf < uSubLeaf) );
851
852 pNew->uLeaf = uLeaf;
853 pNew->uSubLeaf = uSubLeaf;
854 pNew->fSubLeafMask = fSubLeafMask;
855 pNew->uEax = uEax;
856 pNew->uEbx = uEbx;
857 pNew->uEcx = uEcx;
858 pNew->uEdx = uEdx;
859 pNew->fFlags = fFlags;
860
861 *pcLeaves += 1;
862 return VINF_SUCCESS;
863}
864
865
866/**
867 * Checks that we've updated the CPUID leaves array correctly.
868 *
869 * This is a no-op in non-strict builds.
870 *
871 * @param paLeaves The leaves array.
872 * @param cLeaves The number of leaves.
873 */
874static void cpumR3CpuIdAssertOrder(PCPUMCPUIDLEAF paLeaves, uint32_t cLeaves)
875{
876#ifdef VBOX_STRICT
877 for (uint32_t i = 1; i < cLeaves; i++)
878 if (paLeaves[i].uLeaf != paLeaves[i - 1].uLeaf)
879 AssertMsg(paLeaves[i].uLeaf > paLeaves[i - 1].uLeaf, ("%#x vs %#x\n", paLeaves[i].uLeaf, paLeaves[i - 1].uLeaf));
880 else
881 {
882 AssertMsg(paLeaves[i].uSubLeaf > paLeaves[i - 1].uSubLeaf,
883 ("%#x: %#x vs %#x\n", paLeaves[i].uLeaf, paLeaves[i].uSubLeaf, paLeaves[i - 1].uSubLeaf));
884 AssertMsg(paLeaves[i].fSubLeafMask == paLeaves[i - 1].fSubLeafMask,
885 ("%#x/%#x: %#x vs %#x\n", paLeaves[i].uLeaf, paLeaves[i].uSubLeaf, paLeaves[i].fSubLeafMask, paLeaves[i - 1].fSubLeafMask));
886 AssertMsg(paLeaves[i].fFlags == paLeaves[i - 1].fFlags,
887 ("%#x/%#x: %#x vs %#x\n", paLeaves[i].uLeaf, paLeaves[i].uSubLeaf, paLeaves[i].fFlags, paLeaves[i - 1].fFlags));
888 }
889#else
890 NOREF(paLeaves);
891 NOREF(cLeaves);
892#endif
893}
894
895
896/**
897 * Inserts a CPU ID leaf, replacing any existing ones.
898 *
899 * When inserting a simple leaf where we already got a series of sub-leaves with
900 * the same leaf number (eax), the simple leaf will replace the whole series.
901 *
902 * When pVM is NULL, this ASSUMES that the leaves array is still on the normal
903 * host-context heap and has only been allocated/reallocated by the
904 * cpumR3CpuIdEnsureSpace function.
905 *
906 * @returns VBox status code.
907 * @param pVM The cross context VM structure. If NULL, use
908 * the process heap, otherwise the VM's hyper heap.
909 * @param ppaLeaves Pointer to the pointer to the array of sorted
910 * CPUID leaves and sub-leaves. Must be NULL if using
911 * the hyper heap.
912 * @param pcLeaves Where we keep the leaf count for *ppaLeaves. Must
913 * be NULL if using the hyper heap.
914 * @param pNewLeaf Pointer to the data of the new leaf we're about to
915 * insert.
916 */
917static int cpumR3CpuIdInsert(PVM pVM, PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves, PCPUMCPUIDLEAF pNewLeaf)
918{
919 /*
920 * Validate input parameters if we are using the hyper heap and use the VM's CPUID arrays.
921 */
922 if (pVM)
923 {
924 AssertReturn(!ppaLeaves, VERR_INVALID_PARAMETER);
925 AssertReturn(!pcLeaves, VERR_INVALID_PARAMETER);
926 AssertReturn(pVM->cpum.s.GuestInfo.paCpuIdLeavesR3 == pVM->cpum.s.GuestInfo.aCpuIdLeaves, VERR_INVALID_PARAMETER);
927
928 ppaLeaves = &pVM->cpum.s.GuestInfo.paCpuIdLeavesR3;
929 pcLeaves = &pVM->cpum.s.GuestInfo.cCpuIdLeaves;
930 }
931
932 PCPUMCPUIDLEAF paLeaves = *ppaLeaves;
933 uint32_t cLeaves = *pcLeaves;
934
935 /*
936 * Validate the new leaf a little.
937 */
938 AssertLogRelMsgReturn(!(pNewLeaf->fFlags & ~CPUMCPUIDLEAF_F_VALID_MASK),
939 ("%#x/%#x: %#x", pNewLeaf->uLeaf, pNewLeaf->uSubLeaf, pNewLeaf->fFlags),
940 VERR_INVALID_FLAGS);
941 AssertLogRelMsgReturn(pNewLeaf->fSubLeafMask != 0 || pNewLeaf->uSubLeaf == 0,
942 ("%#x/%#x: %#x", pNewLeaf->uLeaf, pNewLeaf->uSubLeaf, pNewLeaf->fSubLeafMask),
943 VERR_INVALID_PARAMETER);
944 AssertLogRelMsgReturn(RT_IS_POWER_OF_TWO(pNewLeaf->fSubLeafMask + 1),
945 ("%#x/%#x: %#x", pNewLeaf->uLeaf, pNewLeaf->uSubLeaf, pNewLeaf->fSubLeafMask),
946 VERR_INVALID_PARAMETER);
947 AssertLogRelMsgReturn((pNewLeaf->fSubLeafMask & pNewLeaf->uSubLeaf) == pNewLeaf->uSubLeaf,
948 ("%#x/%#x: %#x", pNewLeaf->uLeaf, pNewLeaf->uSubLeaf, pNewLeaf->fSubLeafMask),
949 VERR_INVALID_PARAMETER);
950
951 /*
952 * Find insertion point. The lazy bird uses the same excuse as in
953 * cpumR3CpuIdGetLeaf(), but optimizes for linear insertion (saved state).
954 */
955 uint32_t i;
956 if ( cLeaves > 0
957 && paLeaves[cLeaves - 1].uLeaf < pNewLeaf->uLeaf)
958 {
959 /* Add at end. */
960 i = cLeaves;
961 }
962 else if ( cLeaves > 0
963 && paLeaves[cLeaves - 1].uLeaf == pNewLeaf->uLeaf)
964 {
965 /* Either replacing the last leaf or dealing with sub-leaves. Spool
966 back to the first sub-leaf to pretend we did the linear search. */
967 i = cLeaves - 1;
968 while ( i > 0
969 && paLeaves[i - 1].uLeaf == pNewLeaf->uLeaf)
970 i--;
971 }
972 else
973 {
974 /* Linear search from the start. */
975 i = 0;
976 while ( i < cLeaves
977 && paLeaves[i].uLeaf < pNewLeaf->uLeaf)
978 i++;
979 }
980 if ( i < cLeaves
981 && paLeaves[i].uLeaf == pNewLeaf->uLeaf)
982 {
983 if (paLeaves[i].fSubLeafMask != pNewLeaf->fSubLeafMask)
984 {
985 /*
986 * The sub-leaf mask differs, replace all existing leaves with the
987 * same leaf number.
988 */
989 uint32_t c = 1;
990 while ( i + c < cLeaves
991 && paLeaves[i + c].uLeaf == pNewLeaf->uLeaf)
992 c++;
993 if (c > 1 && i + c < cLeaves)
994 {
995 memmove(&paLeaves[i + c], &paLeaves[i + 1], (cLeaves - i - c) * sizeof(paLeaves[0]));
996 *pcLeaves = cLeaves -= c - 1;
997 }
998
999 paLeaves[i] = *pNewLeaf;
1000 cpumR3CpuIdAssertOrder(*ppaLeaves, *pcLeaves);
1001 return VINF_SUCCESS;
1002 }
1003
1004 /* Find sub-leaf insertion point. */
1005 while ( i < cLeaves
1006 && paLeaves[i].uSubLeaf < pNewLeaf->uSubLeaf
1007 && paLeaves[i].uLeaf == pNewLeaf->uLeaf)
1008 i++;
1009
1010 /*
1011 * If we've got an exactly matching leaf, replace it.
1012 */
1013 if ( i < cLeaves
1014 && paLeaves[i].uLeaf == pNewLeaf->uLeaf
1015 && paLeaves[i].uSubLeaf == pNewLeaf->uSubLeaf)
1016 {
1017 paLeaves[i] = *pNewLeaf;
1018 cpumR3CpuIdAssertOrder(*ppaLeaves, *pcLeaves);
1019 return VINF_SUCCESS;
1020 }
1021 }
1022
1023 /*
1024 * Adding a new leaf at 'i'.
1025 */
1026 AssertLogRelReturn(cLeaves < CPUM_CPUID_MAX_LEAVES, VERR_TOO_MANY_CPUID_LEAVES);
1027 paLeaves = cpumR3CpuIdEnsureSpace(pVM, ppaLeaves, cLeaves);
1028 if (!paLeaves)
1029 return VERR_NO_MEMORY;
1030
1031 if (i < cLeaves)
1032 memmove(&paLeaves[i + 1], &paLeaves[i], (cLeaves - i) * sizeof(paLeaves[0]));
1033 *pcLeaves += 1;
1034 paLeaves[i] = *pNewLeaf;
1035
1036 cpumR3CpuIdAssertOrder(*ppaLeaves, *pcLeaves);
1037 return VINF_SUCCESS;
1038}
1039
1040
1041#ifndef IN_VBOX_CPU_REPORT
1042/**
1043 * Removes a range of CPUID leaves.
1044 *
1045 * This will not reallocate the array.
1046 *
1047 * @param paLeaves The array of sorted CPUID leaves and sub-leaves.
1048 * @param pcLeaves Where we keep the leaf count for @a paLeaves.
1049 * @param uFirst The first leaf.
1050 * @param uLast The last leaf.
1051 */
1052static void cpumR3CpuIdRemoveRange(PCPUMCPUIDLEAF paLeaves, uint32_t *pcLeaves, uint32_t uFirst, uint32_t uLast)
1053{
1054 uint32_t cLeaves = *pcLeaves;
1055
1056 Assert(uFirst <= uLast);
1057
1058 /*
1059 * Find the first one.
1060 */
1061 uint32_t iFirst = 0;
1062 while ( iFirst < cLeaves
1063 && paLeaves[iFirst].uLeaf < uFirst)
1064 iFirst++;
1065
1066 /*
1067 * Find the end (last + 1).
1068 */
1069 uint32_t iEnd = iFirst;
1070 while ( iEnd < cLeaves
1071 && paLeaves[iEnd].uLeaf <= uLast)
1072 iEnd++;
1073
1074 /*
1075 * Adjust the array if anything needs removing.
1076 */
1077 if (iFirst < iEnd)
1078 {
1079 if (iEnd < cLeaves)
1080 memmove(&paLeaves[iFirst], &paLeaves[iEnd], (cLeaves - iEnd) * sizeof(paLeaves[0]));
1081 *pcLeaves = cLeaves -= (iEnd - iFirst);
1082 }
1083
1084 cpumR3CpuIdAssertOrder(paLeaves, *pcLeaves);
1085}
1086#endif /* IN_VBOX_CPU_REPORT */
1087
1088
1089/**
1090 * Checks if ECX make a difference when reading a given CPUID leaf.
1091 *
1092 * @returns @c true if it does, @c false if it doesn't.
1093 * @param uLeaf The leaf we're reading.
1094 * @param pcSubLeaves Number of sub-leaves accessible via ECX.
1095 * @param pfFinalEcxUnchanged Whether ECX is passed thru when going beyond the
1096 * final sub-leaf (for leaf 0xb only).
1097 */
1098static bool cpumR3IsEcxRelevantForCpuIdLeaf(uint32_t uLeaf, uint32_t *pcSubLeaves, bool *pfFinalEcxUnchanged)
1099{
1100 *pfFinalEcxUnchanged = false;
1101
1102 uint32_t auCur[4];
1103 uint32_t auPrev[4];
1104 ASMCpuIdExSlow(uLeaf, 0, 0, 0, &auPrev[0], &auPrev[1], &auPrev[2], &auPrev[3]);
1105
1106 /* Look for sub-leaves. */
1107 uint32_t uSubLeaf = 1;
1108 for (;;)
1109 {
1110 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
1111 if (memcmp(auCur, auPrev, sizeof(auCur)))
1112 break;
1113
1114 /* Advance / give up. */
1115 uSubLeaf++;
1116 if (uSubLeaf >= 64)
1117 {
1118 *pcSubLeaves = 1;
1119 return false;
1120 }
1121 }
1122
1123 /* Count sub-leaves. */
1124 uint32_t cMinLeaves = uLeaf == 0xd ? 64 : 0;
1125 uint32_t cRepeats = 0;
1126 uSubLeaf = 0;
1127 for (;;)
1128 {
1129 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
1130
1131 /* Figuring out when to stop isn't entirely straight forward as we need
1132 to cover undocumented behavior up to a point and implementation shortcuts. */
1133
1134 /* 1. Look for more than 4 repeating value sets. */
1135 if ( auCur[0] == auPrev[0]
1136 && auCur[1] == auPrev[1]
1137 && ( auCur[2] == auPrev[2]
1138 || ( auCur[2] == uSubLeaf
1139 && auPrev[2] == uSubLeaf - 1) )
1140 && auCur[3] == auPrev[3])
1141 {
1142 if ( uLeaf != 0xd
1143 || uSubLeaf >= 64
1144 || ( auCur[0] == 0
1145 && auCur[1] == 0
1146 && auCur[2] == 0
1147 && auCur[3] == 0
1148 && auPrev[2] == 0) )
1149 cRepeats++;
1150 if (cRepeats > 4 && uSubLeaf >= cMinLeaves)
1151 break;
1152 }
1153 else
1154 cRepeats = 0;
1155
1156 /* 2. Look for zero values. */
1157 if ( auCur[0] == 0
1158 && auCur[1] == 0
1159 && (auCur[2] == 0 || auCur[2] == uSubLeaf)
1160 && (auCur[3] == 0 || uLeaf == 0xb /* edx is fixed */)
1161 && uSubLeaf >= cMinLeaves)
1162 {
1163 cRepeats = 0;
1164 break;
1165 }
1166
1167 /* 3. Leaf 0xb level type 0 check. */
1168 if ( uLeaf == 0xb
1169 && (auCur[2] & 0xff00) == 0
1170 && (auPrev[2] & 0xff00) == 0)
1171 {
1172 cRepeats = 0;
1173 break;
1174 }
1175
1176 /* 99. Give up. */
1177 if (uSubLeaf >= 128)
1178 {
1179#ifndef IN_VBOX_CPU_REPORT
1180 /* Ok, limit it according to the documentation if possible just to
1181 avoid annoying users with these detection issues. */
1182 uint32_t cDocLimit = UINT32_MAX;
1183 if (uLeaf == 0x4)
1184 cDocLimit = 4;
1185 else if (uLeaf == 0x7)
1186 cDocLimit = 1;
1187 else if (uLeaf == 0xd)
1188 cDocLimit = 63;
1189 else if (uLeaf == 0xf)
1190 cDocLimit = 2;
1191 if (cDocLimit != UINT32_MAX)
1192 {
1193 *pfFinalEcxUnchanged = auCur[2] == uSubLeaf && uLeaf == 0xb;
1194 *pcSubLeaves = cDocLimit + 3;
1195 return true;
1196 }
1197#endif
1198 *pcSubLeaves = UINT32_MAX;
1199 return true;
1200 }
1201
1202 /* Advance. */
1203 uSubLeaf++;
1204 memcpy(auPrev, auCur, sizeof(auCur));
1205 }
1206
1207 /* Standard exit. */
1208 *pfFinalEcxUnchanged = auCur[2] == uSubLeaf && uLeaf == 0xb;
1209 *pcSubLeaves = uSubLeaf + 1 - cRepeats;
1210 if (*pcSubLeaves == 0)
1211 *pcSubLeaves = 1;
1212 return true;
1213}
1214
1215
1216/**
1217 * Gets a CPU ID leaf.
1218 *
1219 * @returns VBox status code.
1220 * @param pVM The cross context VM structure.
1221 * @param pLeaf Where to store the found leaf.
1222 * @param uLeaf The leaf to locate.
1223 * @param uSubLeaf The subleaf to locate. Pass 0 if no sub-leaves.
1224 */
1225VMMR3DECL(int) CPUMR3CpuIdGetLeaf(PVM pVM, PCPUMCPUIDLEAF pLeaf, uint32_t uLeaf, uint32_t uSubLeaf)
1226{
1227 PCPUMCPUIDLEAF pcLeaf = cpumR3CpuIdGetLeaf(pVM->cpum.s.GuestInfo.paCpuIdLeavesR3, pVM->cpum.s.GuestInfo.cCpuIdLeaves,
1228 uLeaf, uSubLeaf);
1229 if (pcLeaf)
1230 {
1231 memcpy(pLeaf, pcLeaf, sizeof(*pLeaf));
1232 return VINF_SUCCESS;
1233 }
1234
1235 return VERR_NOT_FOUND;
1236}
1237
1238
1239/**
1240 * Gets all the leaves.
1241 *
1242 * This only works after the CPUID leaves have been initialized. The interface
1243 * is intended for NEM and configuring CPUID leaves for the native hypervisor.
1244 *
1245 * @returns Pointer to the array of leaves. NULL on failure.
1246 * @param pVM The cross context VM structure.
1247 * @param pcLeaves Where to return the number of leaves.
1248 */
1249VMMR3_INT_DECL(PCCPUMCPUIDLEAF) CPUMR3CpuIdGetPtr(PVM pVM, uint32_t *pcLeaves)
1250{
1251 *pcLeaves = pVM->cpum.s.GuestInfo.cCpuIdLeaves;
1252 return pVM->cpum.s.GuestInfo.paCpuIdLeavesR3;
1253}
1254
1255
1256/**
1257 * Inserts a CPU ID leaf, replacing any existing ones.
1258 *
1259 * @returns VBox status code.
1260 * @param pVM The cross context VM structure.
1261 * @param pNewLeaf Pointer to the leaf being inserted.
1262 */
1263VMMR3DECL(int) CPUMR3CpuIdInsert(PVM pVM, PCPUMCPUIDLEAF pNewLeaf)
1264{
1265 /*
1266 * Validate parameters.
1267 */
1268 AssertReturn(pVM, VERR_INVALID_PARAMETER);
1269 AssertReturn(pNewLeaf, VERR_INVALID_PARAMETER);
1270
1271 /*
1272 * Disallow replacing CPU ID leaves that this API currently cannot manage.
1273 * These leaves have dependencies on saved-states, see PATMCpuidReplacement().
1274 * If you want to modify these leaves, use CPUMSetGuestCpuIdFeature().
1275 */
1276 if ( pNewLeaf->uLeaf == UINT32_C(0x00000000) /* Standard */
1277 || pNewLeaf->uLeaf == UINT32_C(0x00000001)
1278 || pNewLeaf->uLeaf == UINT32_C(0x80000000) /* Extended */
1279 || pNewLeaf->uLeaf == UINT32_C(0x80000001)
1280 || pNewLeaf->uLeaf == UINT32_C(0xc0000000) /* Centaur */
1281 || pNewLeaf->uLeaf == UINT32_C(0xc0000001) )
1282 {
1283 return VERR_NOT_SUPPORTED;
1284 }
1285
1286 return cpumR3CpuIdInsert(pVM, NULL /* ppaLeaves */, NULL /* pcLeaves */, pNewLeaf);
1287}
1288
1289
1290/**
1291 * Collects CPUID leaves and sub-leaves, returning a sorted array of them.
1292 *
1293 * @returns VBox status code.
1294 * @param ppaLeaves Where to return the array pointer on success.
1295 * Use RTMemFree to release.
1296 * @param pcLeaves Where to return the size of the array on
1297 * success.
1298 */
1299VMMR3DECL(int) CPUMR3CpuIdCollectLeaves(PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves)
1300{
1301 *ppaLeaves = NULL;
1302 *pcLeaves = 0;
1303
1304 /*
1305 * Try out various candidates. This must be sorted!
1306 */
1307 static struct { uint32_t uMsr; bool fSpecial; } const s_aCandidates[] =
1308 {
1309 { UINT32_C(0x00000000), false },
1310 { UINT32_C(0x10000000), false },
1311 { UINT32_C(0x20000000), false },
1312 { UINT32_C(0x30000000), false },
1313 { UINT32_C(0x40000000), false },
1314 { UINT32_C(0x50000000), false },
1315 { UINT32_C(0x60000000), false },
1316 { UINT32_C(0x70000000), false },
1317 { UINT32_C(0x80000000), false },
1318 { UINT32_C(0x80860000), false },
1319 { UINT32_C(0x8ffffffe), true },
1320 { UINT32_C(0x8fffffff), true },
1321 { UINT32_C(0x90000000), false },
1322 { UINT32_C(0xa0000000), false },
1323 { UINT32_C(0xb0000000), false },
1324 { UINT32_C(0xc0000000), false },
1325 { UINT32_C(0xd0000000), false },
1326 { UINT32_C(0xe0000000), false },
1327 { UINT32_C(0xf0000000), false },
1328 };
1329
1330 for (uint32_t iOuter = 0; iOuter < RT_ELEMENTS(s_aCandidates); iOuter++)
1331 {
1332 uint32_t uLeaf = s_aCandidates[iOuter].uMsr;
1333 uint32_t uEax, uEbx, uEcx, uEdx;
1334 ASMCpuIdExSlow(uLeaf, 0, 0, 0, &uEax, &uEbx, &uEcx, &uEdx);
1335
1336 /*
1337 * Does EAX look like a typical leaf count value?
1338 */
1339 if ( uEax > uLeaf
1340 && uEax - uLeaf < UINT32_C(0xff)) /* Adjust 0xff limit when exceeded by real HW. */
1341 {
1342 /* Yes, dump them. */
1343 uint32_t cLeaves = uEax - uLeaf + 1;
1344 while (cLeaves-- > 0)
1345 {
1346 ASMCpuIdExSlow(uLeaf, 0, 0, 0, &uEax, &uEbx, &uEcx, &uEdx);
1347
1348 uint32_t fFlags = 0;
1349
1350 /* There are currently three known leaves containing an APIC ID
1351 that needs EMT specific attention */
1352 if (uLeaf == 1)
1353 fFlags |= CPUMCPUIDLEAF_F_CONTAINS_APIC_ID;
1354 else if (uLeaf == 0xb && uEcx != 0)
1355 fFlags |= CPUMCPUIDLEAF_F_CONTAINS_APIC_ID;
1356 else if ( uLeaf == UINT32_C(0x8000001e)
1357 && ( uEax
1358 || uEbx
1359 || uEdx
1360 || ASMIsAmdCpuEx((*ppaLeaves)[0].uEbx, (*ppaLeaves)[0].uEcx, (*ppaLeaves)[0].uEdx)
1361 || ASMIsHygonCpuEx((*ppaLeaves)[0].uEbx, (*ppaLeaves)[0].uEcx, (*ppaLeaves)[0].uEdx)) )
1362 fFlags |= CPUMCPUIDLEAF_F_CONTAINS_APIC_ID;
1363
1364 /* The APIC bit is per-VCpu and needs flagging. */
1365 if (uLeaf == 1)
1366 fFlags |= CPUMCPUIDLEAF_F_CONTAINS_APIC;
1367 else if ( uLeaf == UINT32_C(0x80000001)
1368 && ( (uEdx & X86_CPUID_AMD_FEATURE_EDX_APIC)
1369 || ASMIsAmdCpuEx((*ppaLeaves)[0].uEbx, (*ppaLeaves)[0].uEcx, (*ppaLeaves)[0].uEdx)
1370 || ASMIsHygonCpuEx((*ppaLeaves)[0].uEbx, (*ppaLeaves)[0].uEcx, (*ppaLeaves)[0].uEdx)) )
1371 fFlags |= CPUMCPUIDLEAF_F_CONTAINS_APIC;
1372
1373 /* Check three times here to reduce the chance of CPU migration
1374 resulting in false positives with things like the APIC ID. */
1375 uint32_t cSubLeaves;
1376 bool fFinalEcxUnchanged;
1377 if ( cpumR3IsEcxRelevantForCpuIdLeaf(uLeaf, &cSubLeaves, &fFinalEcxUnchanged)
1378 && cpumR3IsEcxRelevantForCpuIdLeaf(uLeaf, &cSubLeaves, &fFinalEcxUnchanged)
1379 && cpumR3IsEcxRelevantForCpuIdLeaf(uLeaf, &cSubLeaves, &fFinalEcxUnchanged))
1380 {
1381 if (cSubLeaves > (uLeaf == 0xd ? 68U : 16U))
1382 {
1383 /* This shouldn't happen. But in case it does, file all
1384 relevant details in the release log. */
1385 LogRel(("CPUM: VERR_CPUM_TOO_MANY_CPUID_SUBLEAVES! uLeaf=%#x cSubLeaves=%#x\n", uLeaf, cSubLeaves));
1386 LogRel(("------------------ dump of problematic sub-leaves -----------------\n"));
1387 for (uint32_t uSubLeaf = 0; uSubLeaf < 128; uSubLeaf++)
1388 {
1389 uint32_t auTmp[4];
1390 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &auTmp[0], &auTmp[1], &auTmp[2], &auTmp[3]);
1391 LogRel(("CPUM: %#010x, %#010x => %#010x %#010x %#010x %#010x\n",
1392 uLeaf, uSubLeaf, auTmp[0], auTmp[1], auTmp[2], auTmp[3]));
1393 }
1394 LogRel(("----------------- dump of what we've found so far -----------------\n"));
1395 for (uint32_t i = 0 ; i < *pcLeaves; i++)
1396 LogRel(("CPUM: %#010x, %#010x/%#010x => %#010x %#010x %#010x %#010x\n",
1397 (*ppaLeaves)[i].uLeaf, (*ppaLeaves)[i].uSubLeaf, (*ppaLeaves)[i].fSubLeafMask,
1398 (*ppaLeaves)[i].uEax, (*ppaLeaves)[i].uEbx, (*ppaLeaves)[i].uEcx, (*ppaLeaves)[i].uEdx));
1399 LogRel(("\nPlease create a defect on virtualbox.org and attach this log file!\n\n"));
1400 return VERR_CPUM_TOO_MANY_CPUID_SUBLEAVES;
1401 }
1402
1403 if (fFinalEcxUnchanged)
1404 fFlags |= CPUMCPUIDLEAF_F_INTEL_TOPOLOGY_SUBLEAVES;
1405
1406 for (uint32_t uSubLeaf = 0; uSubLeaf < cSubLeaves; uSubLeaf++)
1407 {
1408 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &uEax, &uEbx, &uEcx, &uEdx);
1409 int rc = cpumR3CollectCpuIdInfoAddOne(ppaLeaves, pcLeaves,
1410 uLeaf, uSubLeaf, UINT32_MAX, uEax, uEbx, uEcx, uEdx, fFlags);
1411 if (RT_FAILURE(rc))
1412 return rc;
1413 }
1414 }
1415 else
1416 {
1417 int rc = cpumR3CollectCpuIdInfoAddOne(ppaLeaves, pcLeaves,
1418 uLeaf, 0, 0, uEax, uEbx, uEcx, uEdx, fFlags);
1419 if (RT_FAILURE(rc))
1420 return rc;
1421 }
1422
1423 /* next */
1424 uLeaf++;
1425 }
1426 }
1427 /*
1428 * Special CPUIDs needs special handling as they don't follow the
1429 * leaf count principle used above.
1430 */
1431 else if (s_aCandidates[iOuter].fSpecial)
1432 {
1433 bool fKeep = false;
1434 if (uLeaf == 0x8ffffffe && uEax == UINT32_C(0x00494544))
1435 fKeep = true;
1436 else if ( uLeaf == 0x8fffffff
1437 && RT_C_IS_PRINT(RT_BYTE1(uEax))
1438 && RT_C_IS_PRINT(RT_BYTE2(uEax))
1439 && RT_C_IS_PRINT(RT_BYTE3(uEax))
1440 && RT_C_IS_PRINT(RT_BYTE4(uEax))
1441 && RT_C_IS_PRINT(RT_BYTE1(uEbx))
1442 && RT_C_IS_PRINT(RT_BYTE2(uEbx))
1443 && RT_C_IS_PRINT(RT_BYTE3(uEbx))
1444 && RT_C_IS_PRINT(RT_BYTE4(uEbx))
1445 && RT_C_IS_PRINT(RT_BYTE1(uEcx))
1446 && RT_C_IS_PRINT(RT_BYTE2(uEcx))
1447 && RT_C_IS_PRINT(RT_BYTE3(uEcx))
1448 && RT_C_IS_PRINT(RT_BYTE4(uEcx))
1449 && RT_C_IS_PRINT(RT_BYTE1(uEdx))
1450 && RT_C_IS_PRINT(RT_BYTE2(uEdx))
1451 && RT_C_IS_PRINT(RT_BYTE3(uEdx))
1452 && RT_C_IS_PRINT(RT_BYTE4(uEdx)) )
1453 fKeep = true;
1454 if (fKeep)
1455 {
1456 int rc = cpumR3CollectCpuIdInfoAddOne(ppaLeaves, pcLeaves,
1457 uLeaf, 0, 0, uEax, uEbx, uEcx, uEdx, 0);
1458 if (RT_FAILURE(rc))
1459 return rc;
1460 }
1461 }
1462 }
1463
1464 cpumR3CpuIdAssertOrder(*ppaLeaves, *pcLeaves);
1465 return VINF_SUCCESS;
1466}
1467
1468
1469/**
1470 * Determines the method the CPU uses to handle unknown CPUID leaves.
1471 *
1472 * @returns VBox status code.
1473 * @param penmUnknownMethod Where to return the method.
1474 * @param pDefUnknown Where to return default unknown values. This
1475 * will be set, even if the resulting method
1476 * doesn't actually needs it.
1477 */
1478VMMR3DECL(int) CPUMR3CpuIdDetectUnknownLeafMethod(PCPUMUNKNOWNCPUID penmUnknownMethod, PCPUMCPUID pDefUnknown)
1479{
1480 uint32_t uLastStd = ASMCpuId_EAX(0);
1481 uint32_t uLastExt = ASMCpuId_EAX(0x80000000);
1482 if (!ASMIsValidExtRange(uLastExt))
1483 uLastExt = 0x80000000;
1484
1485 uint32_t auChecks[] =
1486 {
1487 uLastStd + 1,
1488 uLastStd + 5,
1489 uLastStd + 8,
1490 uLastStd + 32,
1491 uLastStd + 251,
1492 uLastExt + 1,
1493 uLastExt + 8,
1494 uLastExt + 15,
1495 uLastExt + 63,
1496 uLastExt + 255,
1497 0x7fbbffcc,
1498 0x833f7872,
1499 0xefff2353,
1500 0x35779456,
1501 0x1ef6d33e,
1502 };
1503
1504 static const uint32_t s_auValues[] =
1505 {
1506 0xa95d2156,
1507 0x00000001,
1508 0x00000002,
1509 0x00000008,
1510 0x00000000,
1511 0x55773399,
1512 0x93401769,
1513 0x12039587,
1514 };
1515
1516 /*
1517 * Simple method, all zeros.
1518 */
1519 *penmUnknownMethod = CPUMUNKNOWNCPUID_DEFAULTS;
1520 pDefUnknown->uEax = 0;
1521 pDefUnknown->uEbx = 0;
1522 pDefUnknown->uEcx = 0;
1523 pDefUnknown->uEdx = 0;
1524
1525 /*
1526 * Intel has been observed returning the last standard leaf.
1527 */
1528 uint32_t auLast[4];
1529 ASMCpuIdExSlow(uLastStd, 0, 0, 0, &auLast[0], &auLast[1], &auLast[2], &auLast[3]);
1530
1531 uint32_t cChecks = RT_ELEMENTS(auChecks);
1532 while (cChecks > 0)
1533 {
1534 uint32_t auCur[4];
1535 ASMCpuIdExSlow(auChecks[cChecks - 1], 0, 0, 0, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
1536 if (memcmp(auCur, auLast, sizeof(auCur)))
1537 break;
1538 cChecks--;
1539 }
1540 if (cChecks == 0)
1541 {
1542 /* Now, what happens when the input changes? Esp. ECX. */
1543 uint32_t cTotal = 0;
1544 uint32_t cSame = 0;
1545 uint32_t cLastWithEcx = 0;
1546 uint32_t cNeither = 0;
1547 uint32_t cValues = RT_ELEMENTS(s_auValues);
1548 while (cValues > 0)
1549 {
1550 uint32_t uValue = s_auValues[cValues - 1];
1551 uint32_t auLastWithEcx[4];
1552 ASMCpuIdExSlow(uLastStd, uValue, uValue, uValue,
1553 &auLastWithEcx[0], &auLastWithEcx[1], &auLastWithEcx[2], &auLastWithEcx[3]);
1554
1555 cChecks = RT_ELEMENTS(auChecks);
1556 while (cChecks > 0)
1557 {
1558 uint32_t auCur[4];
1559 ASMCpuIdExSlow(auChecks[cChecks - 1], uValue, uValue, uValue, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
1560 if (!memcmp(auCur, auLast, sizeof(auCur)))
1561 {
1562 cSame++;
1563 if (!memcmp(auCur, auLastWithEcx, sizeof(auCur)))
1564 cLastWithEcx++;
1565 }
1566 else if (!memcmp(auCur, auLastWithEcx, sizeof(auCur)))
1567 cLastWithEcx++;
1568 else
1569 cNeither++;
1570 cTotal++;
1571 cChecks--;
1572 }
1573 cValues--;
1574 }
1575
1576 Log(("CPUM: cNeither=%d cSame=%d cLastWithEcx=%d cTotal=%d\n", cNeither, cSame, cLastWithEcx, cTotal));
1577 if (cSame == cTotal)
1578 *penmUnknownMethod = CPUMUNKNOWNCPUID_LAST_STD_LEAF;
1579 else if (cLastWithEcx == cTotal)
1580 *penmUnknownMethod = CPUMUNKNOWNCPUID_LAST_STD_LEAF_WITH_ECX;
1581 else
1582 *penmUnknownMethod = CPUMUNKNOWNCPUID_LAST_STD_LEAF;
1583 pDefUnknown->uEax = auLast[0];
1584 pDefUnknown->uEbx = auLast[1];
1585 pDefUnknown->uEcx = auLast[2];
1586 pDefUnknown->uEdx = auLast[3];
1587 return VINF_SUCCESS;
1588 }
1589
1590 /*
1591 * Unchanged register values?
1592 */
1593 cChecks = RT_ELEMENTS(auChecks);
1594 while (cChecks > 0)
1595 {
1596 uint32_t const uLeaf = auChecks[cChecks - 1];
1597 uint32_t cValues = RT_ELEMENTS(s_auValues);
1598 while (cValues > 0)
1599 {
1600 uint32_t uValue = s_auValues[cValues - 1];
1601 uint32_t auCur[4];
1602 ASMCpuIdExSlow(uLeaf, uValue, uValue, uValue, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
1603 if ( auCur[0] != uLeaf
1604 || auCur[1] != uValue
1605 || auCur[2] != uValue
1606 || auCur[3] != uValue)
1607 break;
1608 cValues--;
1609 }
1610 if (cValues != 0)
1611 break;
1612 cChecks--;
1613 }
1614 if (cChecks == 0)
1615 {
1616 *penmUnknownMethod = CPUMUNKNOWNCPUID_PASSTHRU;
1617 return VINF_SUCCESS;
1618 }
1619
1620 /*
1621 * Just go with the simple method.
1622 */
1623 return VINF_SUCCESS;
1624}
1625
1626
1627/**
1628 * Translates a unknow CPUID leaf method into the constant name (sans prefix).
1629 *
1630 * @returns Read only name string.
1631 * @param enmUnknownMethod The method to translate.
1632 */
1633VMMR3DECL(const char *) CPUMR3CpuIdUnknownLeafMethodName(CPUMUNKNOWNCPUID enmUnknownMethod)
1634{
1635 switch (enmUnknownMethod)
1636 {
1637 case CPUMUNKNOWNCPUID_DEFAULTS: return "DEFAULTS";
1638 case CPUMUNKNOWNCPUID_LAST_STD_LEAF: return "LAST_STD_LEAF";
1639 case CPUMUNKNOWNCPUID_LAST_STD_LEAF_WITH_ECX: return "LAST_STD_LEAF_WITH_ECX";
1640 case CPUMUNKNOWNCPUID_PASSTHRU: return "PASSTHRU";
1641
1642 case CPUMUNKNOWNCPUID_INVALID:
1643 case CPUMUNKNOWNCPUID_END:
1644 case CPUMUNKNOWNCPUID_32BIT_HACK:
1645 break;
1646 }
1647 return "Invalid-unknown-CPUID-method";
1648}
1649
1650
1651/**
1652 * Detect the CPU vendor give n the
1653 *
1654 * @returns The vendor.
1655 * @param uEAX EAX from CPUID(0).
1656 * @param uEBX EBX from CPUID(0).
1657 * @param uECX ECX from CPUID(0).
1658 * @param uEDX EDX from CPUID(0).
1659 */
1660VMMR3DECL(CPUMCPUVENDOR) CPUMR3CpuIdDetectVendorEx(uint32_t uEAX, uint32_t uEBX, uint32_t uECX, uint32_t uEDX)
1661{
1662 if (ASMIsValidStdRange(uEAX))
1663 {
1664 if (ASMIsAmdCpuEx(uEBX, uECX, uEDX))
1665 return CPUMCPUVENDOR_AMD;
1666
1667 if (ASMIsIntelCpuEx(uEBX, uECX, uEDX))
1668 return CPUMCPUVENDOR_INTEL;
1669
1670 if (ASMIsViaCentaurCpuEx(uEBX, uECX, uEDX))
1671 return CPUMCPUVENDOR_VIA;
1672
1673 if (ASMIsShanghaiCpuEx(uEBX, uECX, uEDX))
1674 return CPUMCPUVENDOR_SHANGHAI;
1675
1676 if ( uEBX == UINT32_C(0x69727943) /* CyrixInstead */
1677 && uECX == UINT32_C(0x64616574)
1678 && uEDX == UINT32_C(0x736E4978))
1679 return CPUMCPUVENDOR_CYRIX;
1680
1681 if (ASMIsHygonCpuEx(uEBX, uECX, uEDX))
1682 return CPUMCPUVENDOR_HYGON;
1683
1684 /* "Geode by NSC", example: family 5, model 9. */
1685
1686 /** @todo detect the other buggers... */
1687 }
1688
1689 return CPUMCPUVENDOR_UNKNOWN;
1690}
1691
1692
1693/**
1694 * Translates a CPU vendor enum value into the corresponding string constant.
1695 *
1696 * The named can be prefixed with 'CPUMCPUVENDOR_' to construct a valid enum
1697 * value name. This can be useful when generating code.
1698 *
1699 * @returns Read only name string.
1700 * @param enmVendor The CPU vendor value.
1701 */
1702VMMR3DECL(const char *) CPUMR3CpuVendorName(CPUMCPUVENDOR enmVendor)
1703{
1704 switch (enmVendor)
1705 {
1706 case CPUMCPUVENDOR_INTEL: return "INTEL";
1707 case CPUMCPUVENDOR_AMD: return "AMD";
1708 case CPUMCPUVENDOR_VIA: return "VIA";
1709 case CPUMCPUVENDOR_CYRIX: return "CYRIX";
1710 case CPUMCPUVENDOR_SHANGHAI: return "SHANGHAI";
1711 case CPUMCPUVENDOR_HYGON: return "HYGON";
1712 case CPUMCPUVENDOR_UNKNOWN: return "UNKNOWN";
1713
1714 case CPUMCPUVENDOR_INVALID:
1715 case CPUMCPUVENDOR_32BIT_HACK:
1716 break;
1717 }
1718 return "Invalid-cpu-vendor";
1719}
1720
1721
1722static PCCPUMCPUIDLEAF cpumR3CpuIdFindLeaf(PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf)
1723{
1724 /* Could do binary search, doing linear now because I'm lazy. */
1725 PCCPUMCPUIDLEAF pLeaf = paLeaves;
1726 while (cLeaves-- > 0)
1727 {
1728 if (pLeaf->uLeaf == uLeaf)
1729 return pLeaf;
1730 pLeaf++;
1731 }
1732 return NULL;
1733}
1734
1735
1736static PCCPUMCPUIDLEAF cpumR3CpuIdFindLeafEx(PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf, uint32_t uSubLeaf)
1737{
1738 PCCPUMCPUIDLEAF pLeaf = cpumR3CpuIdFindLeaf(paLeaves, cLeaves, uLeaf);
1739 if ( !pLeaf
1740 || pLeaf->uSubLeaf != (uSubLeaf & pLeaf->fSubLeafMask))
1741 return pLeaf;
1742
1743 /* Linear sub-leaf search. Lazy as usual. */
1744 cLeaves -= pLeaf - paLeaves;
1745 while ( cLeaves-- > 0
1746 && pLeaf->uLeaf == uLeaf)
1747 {
1748 if (pLeaf->uSubLeaf == (uSubLeaf & pLeaf->fSubLeafMask))
1749 return pLeaf;
1750 pLeaf++;
1751 }
1752
1753 return NULL;
1754}
1755
1756
1757static void cpumR3ExplodeVmxFeatures(PCVMXMSRS pVmxMsrs, PCPUMFEATURES pFeatures)
1758{
1759 Assert(pVmxMsrs);
1760 Assert(pFeatures);
1761 Assert(pFeatures->fVmx);
1762
1763 /* Basic information. */
1764 bool const fVmxTrueMsrs = RT_BOOL(pVmxMsrs->u64Basic & VMX_BF_BASIC_TRUE_CTLS_MASK);
1765 {
1766 uint64_t const u64Basic = pVmxMsrs->u64Basic;
1767 pFeatures->fVmxInsOutInfo = RT_BF_GET(u64Basic, VMX_BF_BASIC_VMCS_INS_OUTS);
1768 }
1769
1770 /* Pin-based VM-execution controls. */
1771 {
1772 uint32_t const fPinCtls = fVmxTrueMsrs ? pVmxMsrs->TruePinCtls.n.allowed1 : pVmxMsrs->PinCtls.n.allowed1;
1773 pFeatures->fVmxExtIntExit = RT_BOOL(fPinCtls & VMX_PIN_CTLS_EXT_INT_EXIT);
1774 pFeatures->fVmxNmiExit = RT_BOOL(fPinCtls & VMX_PIN_CTLS_NMI_EXIT);
1775 pFeatures->fVmxVirtNmi = RT_BOOL(fPinCtls & VMX_PIN_CTLS_VIRT_NMI);
1776 pFeatures->fVmxPreemptTimer = RT_BOOL(fPinCtls & VMX_PIN_CTLS_PREEMPT_TIMER);
1777 pFeatures->fVmxPostedInt = RT_BOOL(fPinCtls & VMX_PIN_CTLS_POSTED_INT);
1778 }
1779
1780 /* Processor-based VM-execution controls. */
1781 {
1782 uint32_t const fProcCtls = fVmxTrueMsrs ? pVmxMsrs->TrueProcCtls.n.allowed1 : pVmxMsrs->ProcCtls.n.allowed1;
1783 pFeatures->fVmxIntWindowExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_INT_WINDOW_EXIT);
1784 pFeatures->fVmxTscOffsetting = RT_BOOL(fProcCtls & VMX_PROC_CTLS_USE_TSC_OFFSETTING);
1785 pFeatures->fVmxHltExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_HLT_EXIT);
1786 pFeatures->fVmxInvlpgExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_INVLPG_EXIT);
1787 pFeatures->fVmxMwaitExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_MWAIT_EXIT);
1788 pFeatures->fVmxRdpmcExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_RDPMC_EXIT);
1789 pFeatures->fVmxRdtscExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_RDTSC_EXIT);
1790 pFeatures->fVmxCr3LoadExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_CR3_LOAD_EXIT);
1791 pFeatures->fVmxCr3StoreExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_CR3_STORE_EXIT);
1792 pFeatures->fVmxTertiaryExecCtls = RT_BOOL(fProcCtls & VMX_PROC_CTLS_USE_TERTIARY_CTLS);
1793 pFeatures->fVmxCr8LoadExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_CR8_LOAD_EXIT);
1794 pFeatures->fVmxCr8StoreExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_CR8_STORE_EXIT);
1795 pFeatures->fVmxUseTprShadow = RT_BOOL(fProcCtls & VMX_PROC_CTLS_USE_TPR_SHADOW);
1796 pFeatures->fVmxNmiWindowExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_NMI_WINDOW_EXIT);
1797 pFeatures->fVmxMovDRxExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_MOV_DR_EXIT);
1798 pFeatures->fVmxUncondIoExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_UNCOND_IO_EXIT);
1799 pFeatures->fVmxUseIoBitmaps = RT_BOOL(fProcCtls & VMX_PROC_CTLS_USE_IO_BITMAPS);
1800 pFeatures->fVmxMonitorTrapFlag = RT_BOOL(fProcCtls & VMX_PROC_CTLS_MONITOR_TRAP_FLAG);
1801 pFeatures->fVmxUseMsrBitmaps = RT_BOOL(fProcCtls & VMX_PROC_CTLS_USE_MSR_BITMAPS);
1802 pFeatures->fVmxMonitorExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_MONITOR_EXIT);
1803 pFeatures->fVmxPauseExit = RT_BOOL(fProcCtls & VMX_PROC_CTLS_PAUSE_EXIT);
1804 pFeatures->fVmxSecondaryExecCtls = RT_BOOL(fProcCtls & VMX_PROC_CTLS_USE_SECONDARY_CTLS);
1805 }
1806
1807 /* Secondary processor-based VM-execution controls. */
1808 {
1809 uint32_t const fProcCtls2 = pFeatures->fVmxSecondaryExecCtls ? pVmxMsrs->ProcCtls2.n.allowed1 : 0;
1810 pFeatures->fVmxVirtApicAccess = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_VIRT_APIC_ACCESS);
1811 pFeatures->fVmxEpt = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_EPT);
1812 pFeatures->fVmxDescTableExit = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_DESC_TABLE_EXIT);
1813 pFeatures->fVmxRdtscp = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_RDTSCP);
1814 pFeatures->fVmxVirtX2ApicMode = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_VIRT_X2APIC_MODE);
1815 pFeatures->fVmxVpid = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_VPID);
1816 pFeatures->fVmxWbinvdExit = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_WBINVD_EXIT);
1817 pFeatures->fVmxUnrestrictedGuest = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_UNRESTRICTED_GUEST);
1818 pFeatures->fVmxApicRegVirt = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_APIC_REG_VIRT);
1819 pFeatures->fVmxVirtIntDelivery = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_VIRT_INT_DELIVERY);
1820 pFeatures->fVmxPauseLoopExit = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_PAUSE_LOOP_EXIT);
1821 pFeatures->fVmxRdrandExit = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_RDRAND_EXIT);
1822 pFeatures->fVmxInvpcid = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_INVPCID);
1823 pFeatures->fVmxVmFunc = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_VMFUNC);
1824 pFeatures->fVmxVmcsShadowing = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_VMCS_SHADOWING);
1825 pFeatures->fVmxRdseedExit = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_RDSEED_EXIT);
1826 pFeatures->fVmxPml = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_PML);
1827 pFeatures->fVmxEptXcptVe = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_EPT_XCPT_VE);
1828 pFeatures->fVmxConcealVmxFromPt = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_CONCEAL_VMX_FROM_PT);
1829 pFeatures->fVmxXsavesXrstors = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_XSAVES_XRSTORS);
1830 pFeatures->fVmxModeBasedExecuteEpt = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_MODE_BASED_EPT_PERM);
1831 pFeatures->fVmxSppEpt = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_SPP_EPT);
1832 pFeatures->fVmxPtEpt = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_PT_EPT);
1833 pFeatures->fVmxUseTscScaling = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_TSC_SCALING);
1834 pFeatures->fVmxUserWaitPause = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_USER_WAIT_PAUSE);
1835 pFeatures->fVmxEnclvExit = RT_BOOL(fProcCtls2 & VMX_PROC_CTLS2_ENCLV_EXIT);
1836 }
1837
1838 /* Tertiary processor-based VM-execution controls. */
1839 {
1840 uint64_t const fProcCtls3 = pFeatures->fVmxTertiaryExecCtls ? pVmxMsrs->u64ProcCtls3 : 0;
1841 pFeatures->fVmxLoadIwKeyExit = RT_BOOL(fProcCtls3 & VMX_PROC_CTLS3_LOADIWKEY_EXIT);
1842 }
1843
1844 /* VM-exit controls. */
1845 {
1846 uint32_t const fExitCtls = fVmxTrueMsrs ? pVmxMsrs->TrueExitCtls.n.allowed1 : pVmxMsrs->ExitCtls.n.allowed1;
1847 pFeatures->fVmxExitSaveDebugCtls = RT_BOOL(fExitCtls & VMX_EXIT_CTLS_SAVE_DEBUG);
1848 pFeatures->fVmxHostAddrSpaceSize = RT_BOOL(fExitCtls & VMX_EXIT_CTLS_HOST_ADDR_SPACE_SIZE);
1849 pFeatures->fVmxExitAckExtInt = RT_BOOL(fExitCtls & VMX_EXIT_CTLS_ACK_EXT_INT);
1850 pFeatures->fVmxExitSavePatMsr = RT_BOOL(fExitCtls & VMX_EXIT_CTLS_SAVE_PAT_MSR);
1851 pFeatures->fVmxExitLoadPatMsr = RT_BOOL(fExitCtls & VMX_EXIT_CTLS_LOAD_PAT_MSR);
1852 pFeatures->fVmxExitSaveEferMsr = RT_BOOL(fExitCtls & VMX_EXIT_CTLS_SAVE_EFER_MSR);
1853 pFeatures->fVmxExitLoadEferMsr = RT_BOOL(fExitCtls & VMX_EXIT_CTLS_LOAD_EFER_MSR);
1854 pFeatures->fVmxSavePreemptTimer = RT_BOOL(fExitCtls & VMX_EXIT_CTLS_SAVE_PREEMPT_TIMER);
1855 }
1856
1857 /* VM-entry controls. */
1858 {
1859 uint32_t const fEntryCtls = fVmxTrueMsrs ? pVmxMsrs->TrueEntryCtls.n.allowed1 : pVmxMsrs->EntryCtls.n.allowed1;
1860 pFeatures->fVmxEntryLoadDebugCtls = RT_BOOL(fEntryCtls & VMX_ENTRY_CTLS_LOAD_DEBUG);
1861 pFeatures->fVmxIa32eModeGuest = RT_BOOL(fEntryCtls & VMX_ENTRY_CTLS_IA32E_MODE_GUEST);
1862 pFeatures->fVmxEntryLoadEferMsr = RT_BOOL(fEntryCtls & VMX_ENTRY_CTLS_LOAD_EFER_MSR);
1863 pFeatures->fVmxEntryLoadPatMsr = RT_BOOL(fEntryCtls & VMX_ENTRY_CTLS_LOAD_PAT_MSR);
1864 }
1865
1866 /* Miscellaneous data. */
1867 {
1868 uint32_t const fMiscData = pVmxMsrs->u64Misc;
1869 pFeatures->fVmxExitSaveEferLma = RT_BOOL(fMiscData & VMX_MISC_EXIT_SAVE_EFER_LMA);
1870 pFeatures->fVmxPt = RT_BOOL(fMiscData & VMX_MISC_INTEL_PT);
1871 pFeatures->fVmxVmwriteAll = RT_BOOL(fMiscData & VMX_MISC_VMWRITE_ALL);
1872 pFeatures->fVmxEntryInjectSoftInt = RT_BOOL(fMiscData & VMX_MISC_ENTRY_INJECT_SOFT_INT);
1873 }
1874}
1875
1876
1877int cpumR3CpuIdExplodeFeatures(PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, PCCPUMMSRS pMsrs, PCPUMFEATURES pFeatures)
1878{
1879 Assert(pMsrs);
1880 RT_ZERO(*pFeatures);
1881 if (cLeaves >= 2)
1882 {
1883 AssertLogRelReturn(paLeaves[0].uLeaf == 0, VERR_CPUM_IPE_1);
1884 AssertLogRelReturn(paLeaves[1].uLeaf == 1, VERR_CPUM_IPE_1);
1885 PCCPUMCPUIDLEAF const pStd0Leaf = cpumR3CpuIdFindLeafEx(paLeaves, cLeaves, 0, 0);
1886 AssertLogRelReturn(pStd0Leaf, VERR_CPUM_IPE_1);
1887 PCCPUMCPUIDLEAF const pStd1Leaf = cpumR3CpuIdFindLeafEx(paLeaves, cLeaves, 1, 0);
1888 AssertLogRelReturn(pStd1Leaf, VERR_CPUM_IPE_1);
1889
1890 pFeatures->enmCpuVendor = CPUMR3CpuIdDetectVendorEx(pStd0Leaf->uEax,
1891 pStd0Leaf->uEbx,
1892 pStd0Leaf->uEcx,
1893 pStd0Leaf->uEdx);
1894 pFeatures->uFamily = ASMGetCpuFamily(pStd1Leaf->uEax);
1895 pFeatures->uModel = ASMGetCpuModel(pStd1Leaf->uEax, pFeatures->enmCpuVendor == CPUMCPUVENDOR_INTEL);
1896 pFeatures->uStepping = ASMGetCpuStepping(pStd1Leaf->uEax);
1897 pFeatures->enmMicroarch = CPUMR3CpuIdDetermineMicroarchEx((CPUMCPUVENDOR)pFeatures->enmCpuVendor,
1898 pFeatures->uFamily,
1899 pFeatures->uModel,
1900 pFeatures->uStepping);
1901
1902 PCCPUMCPUIDLEAF const pExtLeaf8 = cpumR3CpuIdFindLeaf(paLeaves, cLeaves, 0x80000008);
1903 if (pExtLeaf8)
1904 {
1905 pFeatures->cMaxPhysAddrWidth = pExtLeaf8->uEax & 0xff;
1906 pFeatures->cMaxLinearAddrWidth = (pExtLeaf8->uEax >> 8) & 0xff;
1907 }
1908 else if (pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_PSE36)
1909 {
1910 pFeatures->cMaxPhysAddrWidth = 36;
1911 pFeatures->cMaxLinearAddrWidth = 36;
1912 }
1913 else
1914 {
1915 pFeatures->cMaxPhysAddrWidth = 32;
1916 pFeatures->cMaxLinearAddrWidth = 32;
1917 }
1918
1919 /* Standard features. */
1920 pFeatures->fMsr = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_MSR);
1921 pFeatures->fApic = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_APIC);
1922 pFeatures->fX2Apic = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_X2APIC);
1923 pFeatures->fPse = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_PSE);
1924 pFeatures->fPse36 = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_PSE36);
1925 pFeatures->fPae = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_PAE);
1926 pFeatures->fPge = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_PGE);
1927 pFeatures->fPat = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_PAT);
1928 pFeatures->fFxSaveRstor = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_FXSR);
1929 pFeatures->fXSaveRstor = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_XSAVE);
1930 pFeatures->fOpSysXSaveRstor = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_OSXSAVE);
1931 pFeatures->fMmx = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_MMX);
1932 pFeatures->fSse = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_SSE);
1933 pFeatures->fSse2 = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_SSE2);
1934 pFeatures->fSse3 = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_SSE3);
1935 pFeatures->fSsse3 = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_SSSE3);
1936 pFeatures->fSse41 = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_SSE4_1);
1937 pFeatures->fSse42 = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_SSE4_2);
1938 pFeatures->fAvx = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_AVX);
1939 pFeatures->fTsc = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_TSC);
1940 pFeatures->fSysEnter = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_SEP);
1941 pFeatures->fHypervisorPresent = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_HVP);
1942 pFeatures->fMonitorMWait = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_MONITOR);
1943 pFeatures->fMovCmpXchg16b = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_CX16);
1944 pFeatures->fClFlush = RT_BOOL(pStd1Leaf->uEdx & X86_CPUID_FEATURE_EDX_CLFSH);
1945 pFeatures->fPcid = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_PCID);
1946 pFeatures->fVmx = RT_BOOL(pStd1Leaf->uEcx & X86_CPUID_FEATURE_ECX_VMX);
1947 if (pFeatures->fVmx)
1948 cpumR3ExplodeVmxFeatures(&pMsrs->hwvirt.vmx, pFeatures);
1949
1950 /* Structured extended features. */
1951 PCCPUMCPUIDLEAF const pSxfLeaf0 = cpumR3CpuIdFindLeafEx(paLeaves, cLeaves, 7, 0);
1952 if (pSxfLeaf0)
1953 {
1954 pFeatures->fFsGsBase = RT_BOOL(pSxfLeaf0->uEbx & X86_CPUID_STEXT_FEATURE_EBX_FSGSBASE);
1955 pFeatures->fAvx2 = RT_BOOL(pSxfLeaf0->uEbx & X86_CPUID_STEXT_FEATURE_EBX_AVX2);
1956 pFeatures->fAvx512Foundation = RT_BOOL(pSxfLeaf0->uEbx & X86_CPUID_STEXT_FEATURE_EBX_AVX512F);
1957 pFeatures->fClFlushOpt = RT_BOOL(pSxfLeaf0->uEbx & X86_CPUID_STEXT_FEATURE_EBX_CLFLUSHOPT);
1958 pFeatures->fInvpcid = RT_BOOL(pSxfLeaf0->uEbx & X86_CPUID_STEXT_FEATURE_EBX_INVPCID);
1959
1960 pFeatures->fIbpb = RT_BOOL(pSxfLeaf0->uEdx & X86_CPUID_STEXT_FEATURE_EDX_IBRS_IBPB);
1961 pFeatures->fIbrs = pFeatures->fIbpb;
1962 pFeatures->fStibp = RT_BOOL(pSxfLeaf0->uEdx & X86_CPUID_STEXT_FEATURE_EDX_STIBP);
1963 pFeatures->fFlushCmd = RT_BOOL(pSxfLeaf0->uEdx & X86_CPUID_STEXT_FEATURE_EDX_FLUSH_CMD);
1964 pFeatures->fArchCap = RT_BOOL(pSxfLeaf0->uEdx & X86_CPUID_STEXT_FEATURE_EDX_ARCHCAP);
1965 pFeatures->fMdsClear = RT_BOOL(pSxfLeaf0->uEdx & X86_CPUID_STEXT_FEATURE_EDX_MD_CLEAR);
1966 }
1967
1968 /* MWAIT/MONITOR leaf. */
1969 PCCPUMCPUIDLEAF const pMWaitLeaf = cpumR3CpuIdFindLeaf(paLeaves, cLeaves, 5);
1970 if (pMWaitLeaf)
1971 pFeatures->fMWaitExtensions = (pMWaitLeaf->uEcx & (X86_CPUID_MWAIT_ECX_EXT | X86_CPUID_MWAIT_ECX_BREAKIRQIF0))
1972 == (X86_CPUID_MWAIT_ECX_EXT | X86_CPUID_MWAIT_ECX_BREAKIRQIF0);
1973
1974 /* Extended features. */
1975 PCCPUMCPUIDLEAF const pExtLeaf = cpumR3CpuIdFindLeaf(paLeaves, cLeaves, 0x80000001);
1976 if (pExtLeaf)
1977 {
1978 pFeatures->fLongMode = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_EXT_FEATURE_EDX_LONG_MODE);
1979 pFeatures->fSysCall = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_EXT_FEATURE_EDX_SYSCALL);
1980 pFeatures->fNoExecute = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_EXT_FEATURE_EDX_NX);
1981 pFeatures->fLahfSahf = RT_BOOL(pExtLeaf->uEcx & X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF);
1982 pFeatures->fRdTscP = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_EXT_FEATURE_EDX_RDTSCP);
1983 pFeatures->fMovCr8In32Bit = RT_BOOL(pExtLeaf->uEcx & X86_CPUID_AMD_FEATURE_ECX_CMPL);
1984 pFeatures->f3DNow = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_3DNOW);
1985 pFeatures->f3DNowPrefetch = (pExtLeaf->uEcx & X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF)
1986 || (pExtLeaf->uEdx & ( X86_CPUID_EXT_FEATURE_EDX_LONG_MODE
1987 | X86_CPUID_AMD_FEATURE_EDX_3DNOW));
1988 }
1989
1990 /* VMX (VMXON, VMCS region and related data structures) physical address width (depends on long-mode). */
1991 pFeatures->cVmxMaxPhysAddrWidth = pFeatures->fLongMode ? pFeatures->cMaxPhysAddrWidth : 32;
1992
1993 if ( pExtLeaf
1994 && ( pFeatures->enmCpuVendor == CPUMCPUVENDOR_AMD
1995 || pFeatures->enmCpuVendor == CPUMCPUVENDOR_HYGON))
1996 {
1997 /* AMD features. */
1998 pFeatures->fMsr |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_MSR);
1999 pFeatures->fApic |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_APIC);
2000 pFeatures->fPse |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_PSE);
2001 pFeatures->fPse36 |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_PSE36);
2002 pFeatures->fPae |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_PAE);
2003 pFeatures->fPge |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_PGE);
2004 pFeatures->fPat |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_PAT);
2005 pFeatures->fFxSaveRstor |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_FXSR);
2006 pFeatures->fMmx |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_MMX);
2007 pFeatures->fTsc |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_TSC);
2008 pFeatures->fIbpb |= pExtLeaf8 && (pExtLeaf8->uEbx & X86_CPUID_AMD_EFEID_EBX_IBPB);
2009 pFeatures->fAmdMmxExts = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_AXMMX);
2010 pFeatures->fXop = RT_BOOL(pExtLeaf->uEcx & X86_CPUID_AMD_FEATURE_ECX_XOP);
2011 pFeatures->fSvm = RT_BOOL(pExtLeaf->uEcx & X86_CPUID_AMD_FEATURE_ECX_SVM);
2012 if (pFeatures->fSvm)
2013 {
2014 PCCPUMCPUIDLEAF pSvmLeaf = cpumR3CpuIdFindLeaf(paLeaves, cLeaves, 0x8000000a);
2015 AssertLogRelReturn(pSvmLeaf, VERR_CPUM_IPE_1);
2016 pFeatures->fSvmNestedPaging = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_NESTED_PAGING);
2017 pFeatures->fSvmLbrVirt = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_LBR_VIRT);
2018 pFeatures->fSvmSvmLock = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_SVM_LOCK);
2019 pFeatures->fSvmNextRipSave = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_NRIP_SAVE);
2020 pFeatures->fSvmTscRateMsr = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_TSC_RATE_MSR);
2021 pFeatures->fSvmVmcbClean = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_VMCB_CLEAN);
2022 pFeatures->fSvmFlusbByAsid = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_FLUSH_BY_ASID);
2023 pFeatures->fSvmDecodeAssists = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_DECODE_ASSISTS);
2024 pFeatures->fSvmPauseFilter = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_PAUSE_FILTER);
2025 pFeatures->fSvmPauseFilterThreshold = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_PAUSE_FILTER_THRESHOLD);
2026 pFeatures->fSvmAvic = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_AVIC);
2027 pFeatures->fSvmVirtVmsaveVmload = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_VIRT_VMSAVE_VMLOAD);
2028 pFeatures->fSvmVGif = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_VGIF);
2029 pFeatures->fSvmGmet = RT_BOOL(pSvmLeaf->uEdx & X86_CPUID_SVM_FEATURE_EDX_GMET);
2030 pFeatures->uSvmMaxAsid = pSvmLeaf->uEbx;
2031 }
2032 }
2033
2034 /*
2035 * Quirks.
2036 */
2037 pFeatures->fLeakyFxSR = pExtLeaf
2038 && (pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_FFXSR)
2039 && ( ( pFeatures->enmCpuVendor == CPUMCPUVENDOR_AMD
2040 && pFeatures->uFamily >= 6 /* K7 and up */)
2041 || pFeatures->enmCpuVendor == CPUMCPUVENDOR_HYGON);
2042
2043 /*
2044 * Max extended (/FPU) state.
2045 */
2046 pFeatures->cbMaxExtendedState = pFeatures->fFxSaveRstor ? sizeof(X86FXSTATE) : sizeof(X86FPUSTATE);
2047 if (pFeatures->fXSaveRstor)
2048 {
2049 PCCPUMCPUIDLEAF const pXStateLeaf0 = cpumR3CpuIdFindLeafEx(paLeaves, cLeaves, 13, 0);
2050 if (pXStateLeaf0)
2051 {
2052 if ( pXStateLeaf0->uEcx >= sizeof(X86FXSTATE)
2053 && pXStateLeaf0->uEcx <= CPUM_MAX_XSAVE_AREA_SIZE
2054 && RT_ALIGN_32(pXStateLeaf0->uEcx, 8) == pXStateLeaf0->uEcx
2055 && pXStateLeaf0->uEbx >= sizeof(X86FXSTATE)
2056 && pXStateLeaf0->uEbx <= pXStateLeaf0->uEcx
2057 && RT_ALIGN_32(pXStateLeaf0->uEbx, 8) == pXStateLeaf0->uEbx)
2058 {
2059 pFeatures->cbMaxExtendedState = pXStateLeaf0->uEcx;
2060
2061 /* (paranoia:) */
2062 PCCPUMCPUIDLEAF const pXStateLeaf1 = cpumR3CpuIdFindLeafEx(paLeaves, cLeaves, 13, 1);
2063 if ( pXStateLeaf1
2064 && pXStateLeaf1->uEbx > pFeatures->cbMaxExtendedState
2065 && pXStateLeaf1->uEbx <= CPUM_MAX_XSAVE_AREA_SIZE
2066 && (pXStateLeaf1->uEcx || pXStateLeaf1->uEdx) )
2067 pFeatures->cbMaxExtendedState = pXStateLeaf1->uEbx;
2068 }
2069 else
2070 AssertLogRelMsgFailedStmt(("Unexpected max/cur XSAVE area sizes: %#x/%#x\n", pXStateLeaf0->uEcx, pXStateLeaf0->uEbx),
2071 pFeatures->fXSaveRstor = 0);
2072 }
2073 else
2074 AssertLogRelMsgFailedStmt(("Expected leaf eax=0xd/ecx=0 with the XSAVE/XRSTOR feature!\n"),
2075 pFeatures->fXSaveRstor = 0);
2076 }
2077 }
2078 else
2079 AssertLogRelReturn(cLeaves == 0, VERR_CPUM_IPE_1);
2080 return VINF_SUCCESS;
2081}
2082
2083
2084/*
2085 *
2086 * Init related code.
2087 * Init related code.
2088 * Init related code.
2089 *
2090 *
2091 */
2092#ifndef IN_VBOX_CPU_REPORT
2093
2094
2095/**
2096 * Gets an exactly matching leaf + sub-leaf in the CPUID leaf array.
2097 *
2098 * This ignores the fSubLeafMask.
2099 *
2100 * @returns Pointer to the matching leaf, or NULL if not found.
2101 * @param pCpum The CPUM instance data.
2102 * @param uLeaf The leaf to locate.
2103 * @param uSubLeaf The subleaf to locate.
2104 */
2105static PCPUMCPUIDLEAF cpumR3CpuIdGetExactLeaf(PCPUM pCpum, uint32_t uLeaf, uint32_t uSubLeaf)
2106{
2107 uint64_t uNeedle = RT_MAKE_U64(uSubLeaf, uLeaf);
2108 PCPUMCPUIDLEAF paLeaves = pCpum->GuestInfo.paCpuIdLeavesR3;
2109 uint32_t iEnd = pCpum->GuestInfo.cCpuIdLeaves;
2110 if (iEnd)
2111 {
2112 uint32_t iBegin = 0;
2113 for (;;)
2114 {
2115 uint32_t const i = (iEnd - iBegin) / 2 + iBegin;
2116 uint64_t const uCur = RT_MAKE_U64(paLeaves[i].uSubLeaf, paLeaves[i].uLeaf);
2117 if (uNeedle < uCur)
2118 {
2119 if (i > iBegin)
2120 iEnd = i;
2121 else
2122 break;
2123 }
2124 else if (uNeedle > uCur)
2125 {
2126 if (i + 1 < iEnd)
2127 iBegin = i + 1;
2128 else
2129 break;
2130 }
2131 else
2132 return &paLeaves[i];
2133 }
2134 }
2135 return NULL;
2136}
2137
2138
2139/**
2140 * Loads MSR range overrides.
2141 *
2142 * This must be called before the MSR ranges are moved from the normal heap to
2143 * the hyper heap!
2144 *
2145 * @returns VBox status code (VMSetError called).
2146 * @param pVM The cross context VM structure.
2147 * @param pMsrNode The CFGM node with the MSR overrides.
2148 */
2149static int cpumR3LoadMsrOverrides(PVM pVM, PCFGMNODE pMsrNode)
2150{
2151 for (PCFGMNODE pNode = CFGMR3GetFirstChild(pMsrNode); pNode; pNode = CFGMR3GetNextChild(pNode))
2152 {
2153 /*
2154 * Assemble a valid MSR range.
2155 */
2156 CPUMMSRRANGE MsrRange;
2157 MsrRange.offCpumCpu = 0;
2158 MsrRange.fReserved = 0;
2159
2160 int rc = CFGMR3GetName(pNode, MsrRange.szName, sizeof(MsrRange.szName));
2161 if (RT_FAILURE(rc))
2162 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid MSR entry (name is probably too long): %Rrc\n", rc);
2163
2164 rc = CFGMR3QueryU32(pNode, "First", &MsrRange.uFirst);
2165 if (RT_FAILURE(rc))
2166 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid MSR entry '%s': Error querying mandatory 'First' value: %Rrc\n",
2167 MsrRange.szName, rc);
2168
2169 rc = CFGMR3QueryU32Def(pNode, "Last", &MsrRange.uLast, MsrRange.uFirst);
2170 if (RT_FAILURE(rc))
2171 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid MSR entry '%s': Error querying 'Last' value: %Rrc\n",
2172 MsrRange.szName, rc);
2173
2174 char szType[32];
2175 rc = CFGMR3QueryStringDef(pNode, "Type", szType, sizeof(szType), "FixedValue");
2176 if (RT_FAILURE(rc))
2177 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid MSR entry '%s': Error querying 'Type' value: %Rrc\n",
2178 MsrRange.szName, rc);
2179 if (!RTStrICmp(szType, "FixedValue"))
2180 {
2181 MsrRange.enmRdFn = kCpumMsrRdFn_FixedValue;
2182 MsrRange.enmWrFn = kCpumMsrWrFn_IgnoreWrite;
2183
2184 rc = CFGMR3QueryU64Def(pNode, "Value", &MsrRange.uValue, 0);
2185 if (RT_FAILURE(rc))
2186 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid MSR entry '%s': Error querying 'Value' value: %Rrc\n",
2187 MsrRange.szName, rc);
2188
2189 rc = CFGMR3QueryU64Def(pNode, "WrGpMask", &MsrRange.fWrGpMask, 0);
2190 if (RT_FAILURE(rc))
2191 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid MSR entry '%s': Error querying 'WrGpMask' value: %Rrc\n",
2192 MsrRange.szName, rc);
2193
2194 rc = CFGMR3QueryU64Def(pNode, "WrIgnMask", &MsrRange.fWrIgnMask, 0);
2195 if (RT_FAILURE(rc))
2196 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid MSR entry '%s': Error querying 'WrIgnMask' value: %Rrc\n",
2197 MsrRange.szName, rc);
2198 }
2199 else
2200 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
2201 "Invalid MSR entry '%s': Unknown type '%s'\n", MsrRange.szName, szType);
2202
2203 /*
2204 * Insert the range into the table (replaces/splits/shrinks existing
2205 * MSR ranges).
2206 */
2207 rc = cpumR3MsrRangesInsert(NULL /* pVM */, &pVM->cpum.s.GuestInfo.paMsrRangesR3, &pVM->cpum.s.GuestInfo.cMsrRanges,
2208 &MsrRange);
2209 if (RT_FAILURE(rc))
2210 return VMSetError(pVM, rc, RT_SRC_POS, "Error adding MSR entry '%s': %Rrc\n", MsrRange.szName, rc);
2211 }
2212
2213 return VINF_SUCCESS;
2214}
2215
2216
2217/**
2218 * Loads CPUID leaf overrides.
2219 *
2220 * This must be called before the CPUID leaves are moved from the normal
2221 * heap to the hyper heap!
2222 *
2223 * @returns VBox status code (VMSetError called).
2224 * @param pVM The cross context VM structure.
2225 * @param pParentNode The CFGM node with the CPUID leaves.
2226 * @param pszLabel How to label the overrides we're loading.
2227 */
2228static int cpumR3LoadCpuIdOverrides(PVM pVM, PCFGMNODE pParentNode, const char *pszLabel)
2229{
2230 for (PCFGMNODE pNode = CFGMR3GetFirstChild(pParentNode); pNode; pNode = CFGMR3GetNextChild(pNode))
2231 {
2232 /*
2233 * Get the leaf and subleaf numbers.
2234 */
2235 char szName[128];
2236 int rc = CFGMR3GetName(pNode, szName, sizeof(szName));
2237 if (RT_FAILURE(rc))
2238 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid %s entry (name is probably too long): %Rrc\n", pszLabel, rc);
2239
2240 /* The leaf number is either specified directly or thru the node name. */
2241 uint32_t uLeaf;
2242 rc = CFGMR3QueryU32(pNode, "Leaf", &uLeaf);
2243 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
2244 {
2245 rc = RTStrToUInt32Full(szName, 16, &uLeaf);
2246 if (rc != VINF_SUCCESS)
2247 return VMSetError(pVM, VERR_INVALID_NAME, RT_SRC_POS,
2248 "Invalid %s entry: Invalid leaf number: '%s' \n", pszLabel, szName);
2249 }
2250 else if (RT_FAILURE(rc))
2251 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid %s entry '%s': Error querying 'Leaf' value: %Rrc\n",
2252 pszLabel, szName, rc);
2253
2254 uint32_t uSubLeaf;
2255 rc = CFGMR3QueryU32Def(pNode, "SubLeaf", &uSubLeaf, 0);
2256 if (RT_FAILURE(rc))
2257 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid %s entry '%s': Error querying 'SubLeaf' value: %Rrc\n",
2258 pszLabel, szName, rc);
2259
2260 uint32_t fSubLeafMask;
2261 rc = CFGMR3QueryU32Def(pNode, "SubLeafMask", &fSubLeafMask, 0);
2262 if (RT_FAILURE(rc))
2263 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid %s entry '%s': Error querying 'SubLeafMask' value: %Rrc\n",
2264 pszLabel, szName, rc);
2265
2266 /*
2267 * Look up the specified leaf, since the output register values
2268 * defaults to any existing values. This allows overriding a single
2269 * register, without needing to know the other values.
2270 */
2271 PCCPUMCPUIDLEAF pLeaf = cpumR3CpuIdGetExactLeaf(&pVM->cpum.s, uLeaf, uSubLeaf);
2272 CPUMCPUIDLEAF Leaf;
2273 if (pLeaf)
2274 Leaf = *pLeaf;
2275 else
2276 RT_ZERO(Leaf);
2277 Leaf.uLeaf = uLeaf;
2278 Leaf.uSubLeaf = uSubLeaf;
2279 Leaf.fSubLeafMask = fSubLeafMask;
2280
2281 rc = CFGMR3QueryU32Def(pNode, "eax", &Leaf.uEax, Leaf.uEax);
2282 if (RT_FAILURE(rc))
2283 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid %s entry '%s': Error querying 'eax' value: %Rrc\n",
2284 pszLabel, szName, rc);
2285 rc = CFGMR3QueryU32Def(pNode, "ebx", &Leaf.uEbx, Leaf.uEbx);
2286 if (RT_FAILURE(rc))
2287 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid %s entry '%s': Error querying 'ebx' value: %Rrc\n",
2288 pszLabel, szName, rc);
2289 rc = CFGMR3QueryU32Def(pNode, "ecx", &Leaf.uEcx, Leaf.uEcx);
2290 if (RT_FAILURE(rc))
2291 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid %s entry '%s': Error querying 'ecx' value: %Rrc\n",
2292 pszLabel, szName, rc);
2293 rc = CFGMR3QueryU32Def(pNode, "edx", &Leaf.uEdx, Leaf.uEdx);
2294 if (RT_FAILURE(rc))
2295 return VMSetError(pVM, rc, RT_SRC_POS, "Invalid %s entry '%s': Error querying 'edx' value: %Rrc\n",
2296 pszLabel, szName, rc);
2297
2298 /*
2299 * Insert the leaf into the table (replaces existing ones).
2300 */
2301 rc = cpumR3CpuIdInsert(NULL /* pVM */, &pVM->cpum.s.GuestInfo.paCpuIdLeavesR3, &pVM->cpum.s.GuestInfo.cCpuIdLeaves,
2302 &Leaf);
2303 if (RT_FAILURE(rc))
2304 return VMSetError(pVM, rc, RT_SRC_POS, "Error adding CPUID leaf entry '%s': %Rrc\n", szName, rc);
2305 }
2306
2307 return VINF_SUCCESS;
2308}
2309
2310
2311
2312/**
2313 * Fetches overrides for a CPUID leaf.
2314 *
2315 * @returns VBox status code.
2316 * @param pLeaf The leaf to load the overrides into.
2317 * @param pCfgNode The CFGM node containing the overrides
2318 * (/CPUM/HostCPUID/ or /CPUM/CPUID/).
2319 * @param iLeaf The CPUID leaf number.
2320 */
2321static int cpumR3CpuIdFetchLeafOverride(PCPUMCPUID pLeaf, PCFGMNODE pCfgNode, uint32_t iLeaf)
2322{
2323 PCFGMNODE pLeafNode = CFGMR3GetChildF(pCfgNode, "%RX32", iLeaf);
2324 if (pLeafNode)
2325 {
2326 uint32_t u32;
2327 int rc = CFGMR3QueryU32(pLeafNode, "eax", &u32);
2328 if (RT_SUCCESS(rc))
2329 pLeaf->uEax = u32;
2330 else
2331 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
2332
2333 rc = CFGMR3QueryU32(pLeafNode, "ebx", &u32);
2334 if (RT_SUCCESS(rc))
2335 pLeaf->uEbx = u32;
2336 else
2337 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
2338
2339 rc = CFGMR3QueryU32(pLeafNode, "ecx", &u32);
2340 if (RT_SUCCESS(rc))
2341 pLeaf->uEcx = u32;
2342 else
2343 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
2344
2345 rc = CFGMR3QueryU32(pLeafNode, "edx", &u32);
2346 if (RT_SUCCESS(rc))
2347 pLeaf->uEdx = u32;
2348 else
2349 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
2350
2351 }
2352 return VINF_SUCCESS;
2353}
2354
2355
2356/**
2357 * Load the overrides for a set of CPUID leaves.
2358 *
2359 * @returns VBox status code.
2360 * @param paLeaves The leaf array.
2361 * @param cLeaves The number of leaves.
2362 * @param uStart The start leaf number.
2363 * @param pCfgNode The CFGM node containing the overrides
2364 * (/CPUM/HostCPUID/ or /CPUM/CPUID/).
2365 */
2366static int cpumR3CpuIdInitLoadOverrideSet(uint32_t uStart, PCPUMCPUID paLeaves, uint32_t cLeaves, PCFGMNODE pCfgNode)
2367{
2368 for (uint32_t i = 0; i < cLeaves; i++)
2369 {
2370 int rc = cpumR3CpuIdFetchLeafOverride(&paLeaves[i], pCfgNode, uStart + i);
2371 if (RT_FAILURE(rc))
2372 return rc;
2373 }
2374
2375 return VINF_SUCCESS;
2376}
2377
2378
2379/**
2380 * Installs the CPUID leaves and explods the data into structures like
2381 * GuestFeatures and CPUMCTX::aoffXState.
2382 *
2383 * @returns VBox status code.
2384 * @param pVM The cross context VM structure.
2385 * @param pCpum The CPUM part of @a VM.
2386 * @param paLeaves The leaves. These will be copied (but not freed).
2387 * @param cLeaves The number of leaves.
2388 * @param pMsrs The MSRs.
2389 */
2390static int cpumR3CpuIdInstallAndExplodeLeaves(PVM pVM, PCPUM pCpum, PCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, PCCPUMMSRS pMsrs)
2391{
2392 cpumR3CpuIdAssertOrder(paLeaves, cLeaves);
2393
2394 /*
2395 * Install the CPUID information.
2396 */
2397 AssertLogRelMsgReturn(cLeaves <= RT_ELEMENTS(pVM->cpum.s.GuestInfo.aCpuIdLeaves),
2398 ("cLeaves=%u - max %u\n", cLeaves, RT_ELEMENTS(pVM->cpum.s.GuestInfo.aCpuIdLeaves)),
2399 VERR_CPUM_IPE_1); /** @todo better status! */
2400 if (paLeaves != pCpum->GuestInfo.aCpuIdLeaves)
2401 memcpy(pCpum->GuestInfo.aCpuIdLeaves, paLeaves, cLeaves * sizeof(paLeaves[0]));
2402 pCpum->GuestInfo.paCpuIdLeavesR3 = pCpum->GuestInfo.aCpuIdLeaves;
2403 pCpum->GuestInfo.cCpuIdLeaves = cLeaves;
2404
2405 /*
2406 * Update the default CPUID leaf if necessary.
2407 */
2408 switch (pCpum->GuestInfo.enmUnknownCpuIdMethod)
2409 {
2410 case CPUMUNKNOWNCPUID_LAST_STD_LEAF:
2411 case CPUMUNKNOWNCPUID_LAST_STD_LEAF_WITH_ECX:
2412 {
2413 /* We don't use CPUID(0).eax here because of the NT hack that only
2414 changes that value without actually removing any leaves. */
2415 uint32_t i = 0;
2416 if ( pCpum->GuestInfo.cCpuIdLeaves > 0
2417 && pCpum->GuestInfo.paCpuIdLeavesR3[0].uLeaf <= UINT32_C(0xff))
2418 {
2419 while ( i + 1 < pCpum->GuestInfo.cCpuIdLeaves
2420 && pCpum->GuestInfo.paCpuIdLeavesR3[i + 1].uLeaf <= UINT32_C(0xff))
2421 i++;
2422 pCpum->GuestInfo.DefCpuId.uEax = pCpum->GuestInfo.paCpuIdLeavesR3[i].uEax;
2423 pCpum->GuestInfo.DefCpuId.uEbx = pCpum->GuestInfo.paCpuIdLeavesR3[i].uEbx;
2424 pCpum->GuestInfo.DefCpuId.uEcx = pCpum->GuestInfo.paCpuIdLeavesR3[i].uEcx;
2425 pCpum->GuestInfo.DefCpuId.uEdx = pCpum->GuestInfo.paCpuIdLeavesR3[i].uEdx;
2426 }
2427 break;
2428 }
2429 default:
2430 break;
2431 }
2432
2433 /*
2434 * Explode the guest CPU features.
2435 */
2436 int rc = cpumR3CpuIdExplodeFeatures(pCpum->GuestInfo.paCpuIdLeavesR3, pCpum->GuestInfo.cCpuIdLeaves, pMsrs,
2437 &pCpum->GuestFeatures);
2438 AssertLogRelRCReturn(rc, rc);
2439
2440 /*
2441 * Adjust the scalable bus frequency according to the CPUID information
2442 * we're now using.
2443 */
2444 if (CPUMMICROARCH_IS_INTEL_CORE7(pVM->cpum.s.GuestFeatures.enmMicroarch))
2445 pCpum->GuestInfo.uScalableBusFreq = pCpum->GuestFeatures.enmMicroarch >= kCpumMicroarch_Intel_Core7_SandyBridge
2446 ? UINT64_C(100000000) /* 100MHz */
2447 : UINT64_C(133333333); /* 133MHz */
2448
2449 /*
2450 * Populate the legacy arrays. Currently used for everything, later only
2451 * for patch manager.
2452 */
2453 struct { PCPUMCPUID paCpuIds; uint32_t cCpuIds, uBase; } aOldRanges[] =
2454 {
2455 { pCpum->aGuestCpuIdPatmStd, RT_ELEMENTS(pCpum->aGuestCpuIdPatmStd), 0x00000000 },
2456 { pCpum->aGuestCpuIdPatmExt, RT_ELEMENTS(pCpum->aGuestCpuIdPatmExt), 0x80000000 },
2457 { pCpum->aGuestCpuIdPatmCentaur, RT_ELEMENTS(pCpum->aGuestCpuIdPatmCentaur), 0xc0000000 },
2458 };
2459 for (uint32_t i = 0; i < RT_ELEMENTS(aOldRanges); i++)
2460 {
2461 uint32_t cLeft = aOldRanges[i].cCpuIds;
2462 uint32_t uLeaf = aOldRanges[i].uBase + cLeft;
2463 PCPUMCPUID pLegacyLeaf = &aOldRanges[i].paCpuIds[cLeft];
2464 while (cLeft-- > 0)
2465 {
2466 uLeaf--;
2467 pLegacyLeaf--;
2468
2469 PCCPUMCPUIDLEAF pLeaf = cpumR3CpuIdGetExactLeaf(pCpum, uLeaf, 0 /* uSubLeaf */);
2470 if (pLeaf)
2471 {
2472 pLegacyLeaf->uEax = pLeaf->uEax;
2473 pLegacyLeaf->uEbx = pLeaf->uEbx;
2474 pLegacyLeaf->uEcx = pLeaf->uEcx;
2475 pLegacyLeaf->uEdx = pLeaf->uEdx;
2476 }
2477 else
2478 *pLegacyLeaf = pCpum->GuestInfo.DefCpuId;
2479 }
2480 }
2481
2482 /*
2483 * Configure XSAVE offsets according to the CPUID info and set the feature flags.
2484 */
2485 PVMCPU pVCpu0 = pVM->apCpusR3[0];
2486 AssertCompile(sizeof(pVCpu0->cpum.s.Guest.abXState) == CPUM_MAX_XSAVE_AREA_SIZE);
2487 memset(&pVCpu0->cpum.s.Guest.aoffXState[0], 0xff, sizeof(pVCpu0->cpum.s.Guest.aoffXState));
2488 pVCpu0->cpum.s.Guest.aoffXState[XSAVE_C_X87_BIT] = 0;
2489 pVCpu0->cpum.s.Guest.aoffXState[XSAVE_C_SSE_BIT] = 0;
2490 for (uint32_t iComponent = XSAVE_C_SSE_BIT + 1; iComponent < 63; iComponent++)
2491 if (pCpum->fXStateGuestMask & RT_BIT_64(iComponent))
2492 {
2493 PCPUMCPUIDLEAF pSubLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 0xd, iComponent);
2494 AssertLogRelMsgReturn(pSubLeaf, ("iComponent=%#x\n", iComponent), VERR_CPUM_IPE_1);
2495 AssertLogRelMsgReturn(pSubLeaf->fSubLeafMask >= iComponent, ("iComponent=%#x\n", iComponent), VERR_CPUM_IPE_1);
2496 AssertLogRelMsgReturn( pSubLeaf->uEax > 0
2497 && pSubLeaf->uEbx >= CPUM_MIN_XSAVE_AREA_SIZE
2498 && pSubLeaf->uEax <= pCpum->GuestFeatures.cbMaxExtendedState
2499 && pSubLeaf->uEbx <= pCpum->GuestFeatures.cbMaxExtendedState
2500 && pSubLeaf->uEbx + pSubLeaf->uEax <= pCpum->GuestFeatures.cbMaxExtendedState,
2501 ("iComponent=%#x eax=%#x ebx=%#x cbMax=%#x\n", iComponent, pSubLeaf->uEax, pSubLeaf->uEbx,
2502 pCpum->GuestFeatures.cbMaxExtendedState),
2503 VERR_CPUM_IPE_1);
2504 pVCpu0->cpum.s.Guest.aoffXState[iComponent] = pSubLeaf->uEbx;
2505 }
2506
2507 /* Copy the CPU #0 data to the other CPUs. */
2508 for (VMCPUID idCpu = 1; idCpu < pVM->cCpus; idCpu++)
2509 {
2510 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
2511 memcpy(&pVCpu->cpum.s.Guest.aoffXState[0], &pVCpu0->cpum.s.Guest.aoffXState[0], sizeof(pVCpu0->cpum.s.Guest.aoffXState));
2512 }
2513
2514 return VINF_SUCCESS;
2515}
2516
2517
2518/** @name Instruction Set Extension Options
2519 * @{ */
2520/** Configuration option type (extended boolean, really). */
2521typedef uint8_t CPUMISAEXTCFG;
2522/** Always disable the extension. */
2523#define CPUMISAEXTCFG_DISABLED false
2524/** Enable the extension if it's supported by the host CPU. */
2525#define CPUMISAEXTCFG_ENABLED_SUPPORTED true
2526/** Enable the extension if it's supported by the host CPU, but don't let
2527 * the portable CPUID feature disable it. */
2528#define CPUMISAEXTCFG_ENABLED_PORTABLE UINT8_C(127)
2529/** Always enable the extension. */
2530#define CPUMISAEXTCFG_ENABLED_ALWAYS UINT8_C(255)
2531/** @} */
2532
2533/**
2534 * CPUID Configuration (from CFGM).
2535 *
2536 * @remarks The members aren't document since we would only be duplicating the
2537 * \@cfgm entries in cpumR3CpuIdReadConfig.
2538 */
2539typedef struct CPUMCPUIDCONFIG
2540{
2541 bool fNt4LeafLimit;
2542 bool fInvariantTsc;
2543 bool fForceVme;
2544 bool fNestedHWVirt;
2545
2546 CPUMISAEXTCFG enmCmpXchg16b;
2547 CPUMISAEXTCFG enmMonitor;
2548 CPUMISAEXTCFG enmMWaitExtensions;
2549 CPUMISAEXTCFG enmSse41;
2550 CPUMISAEXTCFG enmSse42;
2551 CPUMISAEXTCFG enmAvx;
2552 CPUMISAEXTCFG enmAvx2;
2553 CPUMISAEXTCFG enmXSave;
2554 CPUMISAEXTCFG enmAesNi;
2555 CPUMISAEXTCFG enmPClMul;
2556 CPUMISAEXTCFG enmPopCnt;
2557 CPUMISAEXTCFG enmMovBe;
2558 CPUMISAEXTCFG enmRdRand;
2559 CPUMISAEXTCFG enmRdSeed;
2560 CPUMISAEXTCFG enmCLFlushOpt;
2561 CPUMISAEXTCFG enmFsGsBase;
2562 CPUMISAEXTCFG enmPcid;
2563 CPUMISAEXTCFG enmInvpcid;
2564 CPUMISAEXTCFG enmFlushCmdMsr;
2565 CPUMISAEXTCFG enmMdsClear;
2566 CPUMISAEXTCFG enmArchCapMsr;
2567
2568 CPUMISAEXTCFG enmAbm;
2569 CPUMISAEXTCFG enmSse4A;
2570 CPUMISAEXTCFG enmMisAlnSse;
2571 CPUMISAEXTCFG enm3dNowPrf;
2572 CPUMISAEXTCFG enmAmdExtMmx;
2573
2574 uint32_t uMaxStdLeaf;
2575 uint32_t uMaxExtLeaf;
2576 uint32_t uMaxCentaurLeaf;
2577 uint32_t uMaxIntelFamilyModelStep;
2578 char szCpuName[128];
2579} CPUMCPUIDCONFIG;
2580/** Pointer to CPUID config (from CFGM). */
2581typedef CPUMCPUIDCONFIG *PCPUMCPUIDCONFIG;
2582
2583
2584/**
2585 * Mini CPU selection support for making Mac OS X happy.
2586 *
2587 * Executes the /CPUM/MaxIntelFamilyModelStep config.
2588 *
2589 * @param pCpum The CPUM instance data.
2590 * @param pConfig The CPUID configuration we've read from CFGM.
2591 */
2592static void cpumR3CpuIdLimitIntelFamModStep(PCPUM pCpum, PCPUMCPUIDCONFIG pConfig)
2593{
2594 if (pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_INTEL)
2595 {
2596 PCPUMCPUIDLEAF pStdFeatureLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 1, 0);
2597 uint32_t uCurIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(ASMGetCpuStepping(pStdFeatureLeaf->uEax),
2598 ASMGetCpuModelIntel(pStdFeatureLeaf->uEax),
2599 ASMGetCpuFamily(pStdFeatureLeaf->uEax),
2600 0);
2601 uint32_t uMaxIntelFamilyModelStep = pConfig->uMaxIntelFamilyModelStep;
2602 if (pConfig->uMaxIntelFamilyModelStep < uCurIntelFamilyModelStep)
2603 {
2604 uint32_t uNew = pStdFeatureLeaf->uEax & UINT32_C(0xf0003000);
2605 uNew |= RT_BYTE1(uMaxIntelFamilyModelStep) & 0xf; /* stepping */
2606 uNew |= (RT_BYTE2(uMaxIntelFamilyModelStep) & 0xf) << 4; /* 4 low model bits */
2607 uNew |= (RT_BYTE2(uMaxIntelFamilyModelStep) >> 4) << 16; /* 4 high model bits */
2608 uNew |= (RT_BYTE3(uMaxIntelFamilyModelStep) & 0xf) << 8; /* 4 low family bits */
2609 if (RT_BYTE3(uMaxIntelFamilyModelStep) > 0xf) /* 8 high family bits, using intel's suggested calculation. */
2610 uNew |= ( (RT_BYTE3(uMaxIntelFamilyModelStep) - (RT_BYTE3(uMaxIntelFamilyModelStep) & 0xf)) & 0xff ) << 20;
2611 LogRel(("CPU: CPUID(0).EAX %#x -> %#x (uMaxIntelFamilyModelStep=%#x, uCurIntelFamilyModelStep=%#x\n",
2612 pStdFeatureLeaf->uEax, uNew, uMaxIntelFamilyModelStep, uCurIntelFamilyModelStep));
2613 pStdFeatureLeaf->uEax = uNew;
2614 }
2615 }
2616}
2617
2618
2619
2620/**
2621 * Limit it the number of entries, zapping the remainder.
2622 *
2623 * The limits are masking off stuff about power saving and similar, this
2624 * is perhaps a bit crudely done as there is probably some relatively harmless
2625 * info too in these leaves (like words about having a constant TSC).
2626 *
2627 * @param pCpum The CPUM instance data.
2628 * @param pConfig The CPUID configuration we've read from CFGM.
2629 */
2630static void cpumR3CpuIdLimitLeaves(PCPUM pCpum, PCPUMCPUIDCONFIG pConfig)
2631{
2632 /*
2633 * Standard leaves.
2634 */
2635 uint32_t uSubLeaf = 0;
2636 PCPUMCPUIDLEAF pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 0, uSubLeaf);
2637 if (pCurLeaf)
2638 {
2639 uint32_t uLimit = pCurLeaf->uEax;
2640 if (uLimit <= UINT32_C(0x000fffff))
2641 {
2642 if (uLimit > pConfig->uMaxStdLeaf)
2643 {
2644 pCurLeaf->uEax = uLimit = pConfig->uMaxStdLeaf;
2645 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
2646 uLimit + 1, UINT32_C(0x000fffff));
2647 }
2648
2649 /* NT4 hack, no zapping of extra leaves here. */
2650 if (pConfig->fNt4LeafLimit && uLimit > 3)
2651 pCurLeaf->uEax = uLimit = 3;
2652
2653 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x00000000), ++uSubLeaf)) != NULL)
2654 pCurLeaf->uEax = uLimit;
2655 }
2656 else
2657 {
2658 LogRel(("CPUID: Invalid standard range: %#x\n", uLimit));
2659 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
2660 UINT32_C(0x00000000), UINT32_C(0x0fffffff));
2661 }
2662 }
2663
2664 /*
2665 * Extended leaves.
2666 */
2667 uSubLeaf = 0;
2668 pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x80000000), uSubLeaf);
2669 if (pCurLeaf)
2670 {
2671 uint32_t uLimit = pCurLeaf->uEax;
2672 if ( uLimit >= UINT32_C(0x80000000)
2673 && uLimit <= UINT32_C(0x800fffff))
2674 {
2675 if (uLimit > pConfig->uMaxExtLeaf)
2676 {
2677 pCurLeaf->uEax = uLimit = pConfig->uMaxExtLeaf;
2678 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
2679 uLimit + 1, UINT32_C(0x800fffff));
2680 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x80000000), ++uSubLeaf)) != NULL)
2681 pCurLeaf->uEax = uLimit;
2682 }
2683 }
2684 else
2685 {
2686 LogRel(("CPUID: Invalid extended range: %#x\n", uLimit));
2687 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
2688 UINT32_C(0x80000000), UINT32_C(0x8ffffffd));
2689 }
2690 }
2691
2692 /*
2693 * Centaur leaves (VIA).
2694 */
2695 uSubLeaf = 0;
2696 pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0xc0000000), uSubLeaf);
2697 if (pCurLeaf)
2698 {
2699 uint32_t uLimit = pCurLeaf->uEax;
2700 if ( uLimit >= UINT32_C(0xc0000000)
2701 && uLimit <= UINT32_C(0xc00fffff))
2702 {
2703 if (uLimit > pConfig->uMaxCentaurLeaf)
2704 {
2705 pCurLeaf->uEax = uLimit = pConfig->uMaxCentaurLeaf;
2706 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
2707 uLimit + 1, UINT32_C(0xcfffffff));
2708 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0xc0000000), ++uSubLeaf)) != NULL)
2709 pCurLeaf->uEax = uLimit;
2710 }
2711 }
2712 else
2713 {
2714 LogRel(("CPUID: Invalid centaur range: %#x\n", uLimit));
2715 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
2716 UINT32_C(0xc0000000), UINT32_C(0xcfffffff));
2717 }
2718 }
2719}
2720
2721
2722/**
2723 * Clears a CPUID leaf and all sub-leaves (to zero).
2724 *
2725 * @param pCpum The CPUM instance data.
2726 * @param uLeaf The leaf to clear.
2727 */
2728static void cpumR3CpuIdZeroLeaf(PCPUM pCpum, uint32_t uLeaf)
2729{
2730 uint32_t uSubLeaf = 0;
2731 PCPUMCPUIDLEAF pCurLeaf;
2732 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, uLeaf, uSubLeaf)) != NULL)
2733 {
2734 pCurLeaf->uEax = 0;
2735 pCurLeaf->uEbx = 0;
2736 pCurLeaf->uEcx = 0;
2737 pCurLeaf->uEdx = 0;
2738 uSubLeaf++;
2739 }
2740}
2741
2742
2743/**
2744 * Used by cpumR3CpuIdSanitize to ensure that we don't have any sub-leaves for
2745 * the given leaf.
2746 *
2747 * @returns pLeaf.
2748 * @param pCpum The CPUM instance data.
2749 * @param pLeaf The leaf to ensure is alone with it's EAX input value.
2750 */
2751static PCPUMCPUIDLEAF cpumR3CpuIdMakeSingleLeaf(PCPUM pCpum, PCPUMCPUIDLEAF pLeaf)
2752{
2753 Assert((uintptr_t)(pLeaf - pCpum->GuestInfo.paCpuIdLeavesR3) < pCpum->GuestInfo.cCpuIdLeaves);
2754 if (pLeaf->fSubLeafMask != 0)
2755 {
2756 /*
2757 * Figure out how many sub-leaves in need of removal (we'll keep the first).
2758 * Log everything while we're at it.
2759 */
2760 LogRel(("CPUM:\n"
2761 "CPUM: Unexpected CPUID sub-leaves for leaf %#x; fSubLeafMask=%#x\n", pLeaf->uLeaf, pLeaf->fSubLeafMask));
2762 PCPUMCPUIDLEAF pLast = &pCpum->GuestInfo.paCpuIdLeavesR3[pCpum->GuestInfo.cCpuIdLeaves - 1];
2763 PCPUMCPUIDLEAF pSubLeaf = pLeaf;
2764 for (;;)
2765 {
2766 LogRel(("CPUM: %08x/%08x: %08x %08x %08x %08x; flags=%#x mask=%#x\n",
2767 pSubLeaf->uLeaf, pSubLeaf->uSubLeaf,
2768 pSubLeaf->uEax, pSubLeaf->uEbx, pSubLeaf->uEcx, pSubLeaf->uEdx,
2769 pSubLeaf->fFlags, pSubLeaf->fSubLeafMask));
2770 if (pSubLeaf == pLast || pSubLeaf[1].uLeaf != pLeaf->uLeaf)
2771 break;
2772 pSubLeaf++;
2773 }
2774 LogRel(("CPUM:\n"));
2775
2776 /*
2777 * Remove the offending sub-leaves.
2778 */
2779 if (pSubLeaf != pLeaf)
2780 {
2781 if (pSubLeaf != pLast)
2782 memmove(pLeaf + 1, pSubLeaf + 1, (uintptr_t)pLast - (uintptr_t)pSubLeaf);
2783 pCpum->GuestInfo.cCpuIdLeaves -= (uint32_t)(pSubLeaf - pLeaf);
2784 }
2785
2786 /*
2787 * Convert the first sub-leaf into a single leaf.
2788 */
2789 pLeaf->uSubLeaf = 0;
2790 pLeaf->fSubLeafMask = 0;
2791 }
2792 return pLeaf;
2793}
2794
2795
2796/**
2797 * Sanitizes and adjust the CPUID leaves.
2798 *
2799 * Drop features that aren't virtualized (or virtualizable). Adjust information
2800 * and capabilities to fit the virtualized hardware. Remove information the
2801 * guest shouldn't have (because it's wrong in the virtual world or because it
2802 * gives away host details) or that we don't have documentation for and no idea
2803 * what means.
2804 *
2805 * @returns VBox status code.
2806 * @param pVM The cross context VM structure (for cCpus).
2807 * @param pCpum The CPUM instance data.
2808 * @param pConfig The CPUID configuration we've read from CFGM.
2809 */
2810static int cpumR3CpuIdSanitize(PVM pVM, PCPUM pCpum, PCPUMCPUIDCONFIG pConfig)
2811{
2812#define PORTABLE_CLEAR_BITS_WHEN(Lvl, a_pLeafReg, FeatNm, fMask, uValue) \
2813 if ( pCpum->u8PortableCpuIdLevel >= (Lvl) && ((a_pLeafReg) & (fMask)) == (uValue) ) \
2814 { \
2815 LogRel(("PortableCpuId: " #a_pLeafReg "[" #FeatNm "]: %#x -> 0\n", (a_pLeafReg) & (fMask))); \
2816 (a_pLeafReg) &= ~(uint32_t)(fMask); \
2817 }
2818#define PORTABLE_DISABLE_FEATURE_BIT(Lvl, a_pLeafReg, FeatNm, fBitMask) \
2819 if ( pCpum->u8PortableCpuIdLevel >= (Lvl) && ((a_pLeafReg) & (fBitMask)) ) \
2820 { \
2821 LogRel(("PortableCpuId: " #a_pLeafReg "[" #FeatNm "]: 1 -> 0\n")); \
2822 (a_pLeafReg) &= ~(uint32_t)(fBitMask); \
2823 }
2824#define PORTABLE_DISABLE_FEATURE_BIT_CFG(Lvl, a_pLeafReg, FeatNm, fBitMask, enmConfig) \
2825 if ( pCpum->u8PortableCpuIdLevel >= (Lvl) \
2826 && ((a_pLeafReg) & (fBitMask)) \
2827 && (enmConfig) != CPUMISAEXTCFG_ENABLED_PORTABLE ) \
2828 { \
2829 LogRel(("PortableCpuId: " #a_pLeafReg "[" #FeatNm "]: 1 -> 0\n")); \
2830 (a_pLeafReg) &= ~(uint32_t)(fBitMask); \
2831 }
2832 Assert(pCpum->GuestFeatures.enmCpuVendor != CPUMCPUVENDOR_INVALID);
2833
2834 /* The CPUID entries we start with here isn't necessarily the ones of the host, so we
2835 must consult HostFeatures when processing CPUMISAEXTCFG variables. */
2836 PCCPUMFEATURES pHstFeat = &pCpum->HostFeatures;
2837#define PASSTHRU_FEATURE(enmConfig, fHostFeature, fConst) \
2838 ((enmConfig) && ((enmConfig) == CPUMISAEXTCFG_ENABLED_ALWAYS || (fHostFeature)) ? (fConst) : 0)
2839#define PASSTHRU_FEATURE_EX(enmConfig, fHostFeature, fAndExpr, fConst) \
2840 ((enmConfig) && ((enmConfig) == CPUMISAEXTCFG_ENABLED_ALWAYS || (fHostFeature)) && (fAndExpr) ? (fConst) : 0)
2841#define PASSTHRU_FEATURE_TODO(enmConfig, fConst) ((enmConfig) ? (fConst) : 0)
2842
2843 /* Cpuid 1:
2844 * EAX: CPU model, family and stepping.
2845 *
2846 * ECX + EDX: Supported features. Only report features we can support.
2847 * Note! When enabling new features the Synthetic CPU and Portable CPUID
2848 * options may require adjusting (i.e. stripping what was enabled).
2849 *
2850 * EBX: Branding, CLFLUSH line size, logical processors per package and
2851 * initial APIC ID.
2852 */
2853 PCPUMCPUIDLEAF pStdFeatureLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 1, 0); /* Note! Must refetch when used later. */
2854 AssertLogRelReturn(pStdFeatureLeaf, VERR_CPUM_IPE_2);
2855 pStdFeatureLeaf = cpumR3CpuIdMakeSingleLeaf(pCpum, pStdFeatureLeaf);
2856
2857 pStdFeatureLeaf->uEdx &= X86_CPUID_FEATURE_EDX_FPU
2858 | X86_CPUID_FEATURE_EDX_VME
2859 | X86_CPUID_FEATURE_EDX_DE
2860 | X86_CPUID_FEATURE_EDX_PSE
2861 | X86_CPUID_FEATURE_EDX_TSC
2862 | X86_CPUID_FEATURE_EDX_MSR
2863 //| X86_CPUID_FEATURE_EDX_PAE - set later if configured.
2864 | X86_CPUID_FEATURE_EDX_MCE
2865 | X86_CPUID_FEATURE_EDX_CX8
2866 //| X86_CPUID_FEATURE_EDX_APIC - set by the APIC device if present.
2867 //| RT_BIT_32(10) - not defined
2868 /* Note! we don't report sysenter/sysexit support due to our inability to keep the IOPL part of eflags in sync while in ring 1 (see @bugref{1757}) */
2869 //| X86_CPUID_FEATURE_EDX_SEP
2870 | X86_CPUID_FEATURE_EDX_MTRR
2871 | X86_CPUID_FEATURE_EDX_PGE
2872 | X86_CPUID_FEATURE_EDX_MCA
2873 | X86_CPUID_FEATURE_EDX_CMOV
2874 | X86_CPUID_FEATURE_EDX_PAT /* 16 */
2875 | X86_CPUID_FEATURE_EDX_PSE36
2876 //| X86_CPUID_FEATURE_EDX_PSN - no serial number.
2877 | X86_CPUID_FEATURE_EDX_CLFSH
2878 //| RT_BIT_32(20) - not defined
2879 //| X86_CPUID_FEATURE_EDX_DS - no debug store.
2880 //| X86_CPUID_FEATURE_EDX_ACPI - not supported (not DevAcpi, right?).
2881 | X86_CPUID_FEATURE_EDX_MMX
2882 | X86_CPUID_FEATURE_EDX_FXSR
2883 | X86_CPUID_FEATURE_EDX_SSE
2884 | X86_CPUID_FEATURE_EDX_SSE2
2885 //| X86_CPUID_FEATURE_EDX_SS - no self snoop.
2886 | X86_CPUID_FEATURE_EDX_HTT
2887 //| X86_CPUID_FEATURE_EDX_TM - no thermal monitor.
2888 //| RT_BIT_32(30) - not defined
2889 //| X86_CPUID_FEATURE_EDX_PBE - no pending break enabled.
2890 ;
2891 pStdFeatureLeaf->uEcx &= X86_CPUID_FEATURE_ECX_SSE3
2892 | PASSTHRU_FEATURE_TODO(pConfig->enmPClMul, X86_CPUID_FEATURE_ECX_PCLMUL)
2893 //| X86_CPUID_FEATURE_ECX_DTES64 - not implemented yet.
2894 /* Can't properly emulate monitor & mwait with guest SMP; force the guest to use hlt for idling VCPUs. */
2895 | PASSTHRU_FEATURE_EX(pConfig->enmMonitor, pHstFeat->fMonitorMWait, pVM->cCpus == 1, X86_CPUID_FEATURE_ECX_MONITOR)
2896 //| X86_CPUID_FEATURE_ECX_CPLDS - no CPL qualified debug store.
2897 | (pConfig->fNestedHWVirt ? X86_CPUID_FEATURE_ECX_VMX : 0)
2898 //| X86_CPUID_FEATURE_ECX_SMX - not virtualized yet.
2899 //| X86_CPUID_FEATURE_ECX_EST - no extended speed step.
2900 //| X86_CPUID_FEATURE_ECX_TM2 - no thermal monitor 2.
2901 | X86_CPUID_FEATURE_ECX_SSSE3
2902 //| X86_CPUID_FEATURE_ECX_CNTXID - no L1 context id (MSR++).
2903 //| X86_CPUID_FEATURE_ECX_FMA - not implemented yet.
2904 | PASSTHRU_FEATURE(pConfig->enmCmpXchg16b, pHstFeat->fMovCmpXchg16b, X86_CPUID_FEATURE_ECX_CX16)
2905 /* ECX Bit 14 - xTPR Update Control. Processor supports changing IA32_MISC_ENABLES[bit 23]. */
2906 //| X86_CPUID_FEATURE_ECX_TPRUPDATE
2907 //| X86_CPUID_FEATURE_ECX_PDCM - not implemented yet.
2908 | PASSTHRU_FEATURE(pConfig->enmPcid, pHstFeat->fPcid, X86_CPUID_FEATURE_ECX_PCID)
2909 //| X86_CPUID_FEATURE_ECX_DCA - not implemented yet.
2910 | PASSTHRU_FEATURE(pConfig->enmSse41, pHstFeat->fSse41, X86_CPUID_FEATURE_ECX_SSE4_1)
2911 | PASSTHRU_FEATURE(pConfig->enmSse42, pHstFeat->fSse42, X86_CPUID_FEATURE_ECX_SSE4_2)
2912 //| X86_CPUID_FEATURE_ECX_X2APIC - turned on later by the device if enabled.
2913 | PASSTHRU_FEATURE_TODO(pConfig->enmMovBe, X86_CPUID_FEATURE_ECX_MOVBE)
2914 | PASSTHRU_FEATURE_TODO(pConfig->enmPopCnt, X86_CPUID_FEATURE_ECX_POPCNT)
2915 //| X86_CPUID_FEATURE_ECX_TSCDEADL - not implemented yet.
2916 | PASSTHRU_FEATURE_TODO(pConfig->enmAesNi, X86_CPUID_FEATURE_ECX_AES)
2917 | PASSTHRU_FEATURE(pConfig->enmXSave, pHstFeat->fXSaveRstor, X86_CPUID_FEATURE_ECX_XSAVE)
2918 //| X86_CPUID_FEATURE_ECX_OSXSAVE - mirrors CR4.OSXSAVE state, set dynamically.
2919 | PASSTHRU_FEATURE(pConfig->enmAvx, pHstFeat->fAvx, X86_CPUID_FEATURE_ECX_AVX)
2920 //| X86_CPUID_FEATURE_ECX_F16C - not implemented yet.
2921 | PASSTHRU_FEATURE_TODO(pConfig->enmRdRand, X86_CPUID_FEATURE_ECX_RDRAND)
2922 //| X86_CPUID_FEATURE_ECX_HVP - Set explicitly later.
2923 ;
2924
2925 /* Mask out PCID unless FSGSBASE is exposed due to a bug in Windows 10 SMP guests, see @bugref{9089#c15}. */
2926 if ( !pVM->cpum.s.GuestFeatures.fFsGsBase
2927 && (pStdFeatureLeaf->uEcx & X86_CPUID_FEATURE_ECX_PCID))
2928 {
2929 pStdFeatureLeaf->uEcx &= ~X86_CPUID_FEATURE_ECX_PCID;
2930 LogRel(("CPUM: Disabled PCID without FSGSBASE to workaround buggy guests\n"));
2931 }
2932
2933 if (pCpum->u8PortableCpuIdLevel > 0)
2934 {
2935 PORTABLE_CLEAR_BITS_WHEN(1, pStdFeatureLeaf->uEax, ProcessorType, (UINT32_C(3) << 12), (UINT32_C(2) << 12));
2936 PORTABLE_DISABLE_FEATURE_BIT( 1, pStdFeatureLeaf->uEcx, SSSE3, X86_CPUID_FEATURE_ECX_SSSE3);
2937 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, PCID, X86_CPUID_FEATURE_ECX_PCID, pConfig->enmPcid);
2938 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, SSE4_1, X86_CPUID_FEATURE_ECX_SSE4_1, pConfig->enmSse41);
2939 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, SSE4_2, X86_CPUID_FEATURE_ECX_SSE4_2, pConfig->enmSse42);
2940 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, MOVBE, X86_CPUID_FEATURE_ECX_MOVBE, pConfig->enmMovBe);
2941 PORTABLE_DISABLE_FEATURE_BIT( 1, pStdFeatureLeaf->uEcx, AES, X86_CPUID_FEATURE_ECX_AES);
2942 PORTABLE_DISABLE_FEATURE_BIT( 1, pStdFeatureLeaf->uEcx, VMX, X86_CPUID_FEATURE_ECX_VMX);
2943 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, PCLMUL, X86_CPUID_FEATURE_ECX_PCLMUL, pConfig->enmPClMul);
2944 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, POPCNT, X86_CPUID_FEATURE_ECX_POPCNT, pConfig->enmPopCnt);
2945 PORTABLE_DISABLE_FEATURE_BIT( 1, pStdFeatureLeaf->uEcx, F16C, X86_CPUID_FEATURE_ECX_F16C);
2946 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, XSAVE, X86_CPUID_FEATURE_ECX_XSAVE, pConfig->enmXSave);
2947 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, AVX, X86_CPUID_FEATURE_ECX_AVX, pConfig->enmAvx);
2948 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, RDRAND, X86_CPUID_FEATURE_ECX_RDRAND, pConfig->enmRdRand);
2949 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pStdFeatureLeaf->uEcx, CX16, X86_CPUID_FEATURE_ECX_CX16, pConfig->enmCmpXchg16b);
2950 PORTABLE_DISABLE_FEATURE_BIT( 2, pStdFeatureLeaf->uEcx, SSE3, X86_CPUID_FEATURE_ECX_SSE3);
2951 PORTABLE_DISABLE_FEATURE_BIT( 3, pStdFeatureLeaf->uEdx, SSE2, X86_CPUID_FEATURE_EDX_SSE2);
2952 PORTABLE_DISABLE_FEATURE_BIT( 3, pStdFeatureLeaf->uEdx, SSE, X86_CPUID_FEATURE_EDX_SSE);
2953 PORTABLE_DISABLE_FEATURE_BIT( 3, pStdFeatureLeaf->uEdx, CLFSH, X86_CPUID_FEATURE_EDX_CLFSH);
2954 PORTABLE_DISABLE_FEATURE_BIT( 3, pStdFeatureLeaf->uEdx, CMOV, X86_CPUID_FEATURE_EDX_CMOV);
2955
2956 Assert(!(pStdFeatureLeaf->uEdx & ( X86_CPUID_FEATURE_EDX_SEP
2957 | X86_CPUID_FEATURE_EDX_PSN
2958 | X86_CPUID_FEATURE_EDX_DS
2959 | X86_CPUID_FEATURE_EDX_ACPI
2960 | X86_CPUID_FEATURE_EDX_SS
2961 | X86_CPUID_FEATURE_EDX_TM
2962 | X86_CPUID_FEATURE_EDX_PBE
2963 )));
2964 Assert(!(pStdFeatureLeaf->uEcx & ( X86_CPUID_FEATURE_ECX_DTES64
2965 | X86_CPUID_FEATURE_ECX_CPLDS
2966 | X86_CPUID_FEATURE_ECX_AES
2967 | X86_CPUID_FEATURE_ECX_VMX
2968 | X86_CPUID_FEATURE_ECX_SMX
2969 | X86_CPUID_FEATURE_ECX_EST
2970 | X86_CPUID_FEATURE_ECX_TM2
2971 | X86_CPUID_FEATURE_ECX_CNTXID
2972 | X86_CPUID_FEATURE_ECX_FMA
2973 | X86_CPUID_FEATURE_ECX_TPRUPDATE
2974 | X86_CPUID_FEATURE_ECX_PDCM
2975 | X86_CPUID_FEATURE_ECX_DCA
2976 | X86_CPUID_FEATURE_ECX_OSXSAVE
2977 )));
2978 }
2979
2980 /* Set up APIC ID for CPU 0, configure multi core/threaded smp. */
2981 pStdFeatureLeaf->uEbx &= UINT32_C(0x0000ffff); /* (APIC-ID := 0 and #LogCpus := 0) */
2982
2983 /* The HTT bit is architectural and does not directly indicate hyper-threading or multiple cores;
2984 * it was set even on single-core/non-HT Northwood P4s for example. The HTT bit only means that the
2985 * information in EBX[23:16] (max number of addressable logical processor IDs) is valid.
2986 */
2987#ifdef VBOX_WITH_MULTI_CORE
2988 if (pVM->cCpus > 1)
2989 pStdFeatureLeaf->uEdx |= X86_CPUID_FEATURE_EDX_HTT; /* Force if emulating a multi-core CPU. */
2990#endif
2991 if (pStdFeatureLeaf->uEdx & X86_CPUID_FEATURE_EDX_HTT)
2992 {
2993 /* If CPUID Fn0000_0001_EDX[HTT] = 1 then LogicalProcessorCount is the number of threads per CPU
2994 core times the number of CPU cores per processor */
2995#ifdef VBOX_WITH_MULTI_CORE
2996 pStdFeatureLeaf->uEbx |= pVM->cCpus <= 0xff ? (pVM->cCpus << 16) : UINT32_C(0x00ff0000);
2997#else
2998 /* Single logical processor in a package. */
2999 pStdFeatureLeaf->uEbx |= (1 << 16);
3000#endif
3001 }
3002
3003 uint32_t uMicrocodeRev;
3004 int rc = SUPR3QueryMicrocodeRev(&uMicrocodeRev);
3005 if (RT_SUCCESS(rc))
3006 {
3007 LogRel(("CPUM: Microcode revision 0x%08X\n", uMicrocodeRev));
3008 }
3009 else
3010 {
3011 uMicrocodeRev = 0;
3012 LogRel(("CPUM: Failed to query microcode revision. rc=%Rrc\n", rc));
3013 }
3014
3015 /* Mask out the VME capability on certain CPUs, unless overridden by fForceVme.
3016 * VME bug was fixed in AGESA 1.0.0.6, microcode patch level 8001126.
3017 */
3018 if ( ( pVM->cpum.s.GuestFeatures.enmMicroarch == kCpumMicroarch_AMD_Zen_Ryzen
3019 /** @todo The following ASSUMES that Hygon uses the same version numbering
3020 * as AMD and that they shipped buggy firmware. */
3021 || pVM->cpum.s.GuestFeatures.enmMicroarch == kCpumMicroarch_Hygon_Dhyana)
3022 && uMicrocodeRev < 0x8001126
3023 && !pConfig->fForceVme)
3024 {
3025 /** @todo The above is a very coarse test but at the moment we don't know any better (see @bugref{8852}). */
3026 LogRel(("CPUM: Zen VME workaround engaged\n"));
3027 pStdFeatureLeaf->uEdx &= ~X86_CPUID_FEATURE_EDX_VME;
3028 }
3029
3030 /* Force standard feature bits. */
3031 if (pConfig->enmPClMul == CPUMISAEXTCFG_ENABLED_ALWAYS)
3032 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_PCLMUL;
3033 if (pConfig->enmMonitor == CPUMISAEXTCFG_ENABLED_ALWAYS)
3034 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_MONITOR;
3035 if (pConfig->enmCmpXchg16b == CPUMISAEXTCFG_ENABLED_ALWAYS)
3036 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_CX16;
3037 if (pConfig->enmSse41 == CPUMISAEXTCFG_ENABLED_ALWAYS)
3038 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_SSE4_1;
3039 if (pConfig->enmSse42 == CPUMISAEXTCFG_ENABLED_ALWAYS)
3040 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_SSE4_2;
3041 if (pConfig->enmMovBe == CPUMISAEXTCFG_ENABLED_ALWAYS)
3042 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_MOVBE;
3043 if (pConfig->enmPopCnt == CPUMISAEXTCFG_ENABLED_ALWAYS)
3044 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_POPCNT;
3045 if (pConfig->enmAesNi == CPUMISAEXTCFG_ENABLED_ALWAYS)
3046 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_AES;
3047 if (pConfig->enmXSave == CPUMISAEXTCFG_ENABLED_ALWAYS)
3048 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_XSAVE;
3049 if (pConfig->enmAvx == CPUMISAEXTCFG_ENABLED_ALWAYS)
3050 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_AVX;
3051 if (pConfig->enmRdRand == CPUMISAEXTCFG_ENABLED_ALWAYS)
3052 pStdFeatureLeaf->uEcx |= X86_CPUID_FEATURE_ECX_RDRAND;
3053
3054 pStdFeatureLeaf = NULL; /* Must refetch! */
3055
3056 /* Cpuid 0x80000001: (Similar, but in no way identical to 0x00000001.)
3057 * AMD:
3058 * EAX: CPU model, family and stepping.
3059 *
3060 * ECX + EDX: Supported features. Only report features we can support.
3061 * Note! When enabling new features the Synthetic CPU and Portable CPUID
3062 * options may require adjusting (i.e. stripping what was enabled).
3063 * ASSUMES that this is ALWAYS the AMD defined feature set if present.
3064 *
3065 * EBX: Branding ID and package type (or reserved).
3066 *
3067 * Intel and probably most others:
3068 * EAX: 0
3069 * EBX: 0
3070 * ECX + EDX: Subset of AMD features, mainly for AMD64 support.
3071 */
3072 PCPUMCPUIDLEAF pExtFeatureLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x80000001), 0);
3073 if (pExtFeatureLeaf)
3074 {
3075 pExtFeatureLeaf = cpumR3CpuIdMakeSingleLeaf(pCpum, pExtFeatureLeaf);
3076
3077 pExtFeatureLeaf->uEdx &= X86_CPUID_AMD_FEATURE_EDX_FPU
3078 | X86_CPUID_AMD_FEATURE_EDX_VME
3079 | X86_CPUID_AMD_FEATURE_EDX_DE
3080 | X86_CPUID_AMD_FEATURE_EDX_PSE
3081 | X86_CPUID_AMD_FEATURE_EDX_TSC
3082 | X86_CPUID_AMD_FEATURE_EDX_MSR //?? this means AMD MSRs..
3083 //| X86_CPUID_AMD_FEATURE_EDX_PAE - turned on when necessary
3084 //| X86_CPUID_AMD_FEATURE_EDX_MCE - not virtualized yet.
3085 | X86_CPUID_AMD_FEATURE_EDX_CX8
3086 //| X86_CPUID_AMD_FEATURE_EDX_APIC - set by the APIC device if present.
3087 //| RT_BIT_32(10) - reserved
3088 /* Note! We don't report sysenter/sysexit support due to our inability to keep the IOPL part of
3089 eflags in sync while in ring 1 (see @bugref{1757}). HM enables them later. */
3090 //| X86_CPUID_EXT_FEATURE_EDX_SYSCALL
3091 | X86_CPUID_AMD_FEATURE_EDX_MTRR
3092 | X86_CPUID_AMD_FEATURE_EDX_PGE
3093 | X86_CPUID_AMD_FEATURE_EDX_MCA
3094 | X86_CPUID_AMD_FEATURE_EDX_CMOV
3095 | X86_CPUID_AMD_FEATURE_EDX_PAT
3096 | X86_CPUID_AMD_FEATURE_EDX_PSE36
3097 //| RT_BIT_32(18) - reserved
3098 //| RT_BIT_32(19) - reserved
3099 //| X86_CPUID_EXT_FEATURE_EDX_NX - enabled later by PGM
3100 //| RT_BIT_32(21) - reserved
3101 | PASSTHRU_FEATURE(pConfig->enmAmdExtMmx, pHstFeat->fAmdMmxExts, X86_CPUID_AMD_FEATURE_EDX_AXMMX)
3102 | X86_CPUID_AMD_FEATURE_EDX_MMX
3103 | X86_CPUID_AMD_FEATURE_EDX_FXSR
3104 | X86_CPUID_AMD_FEATURE_EDX_FFXSR
3105 //| X86_CPUID_EXT_FEATURE_EDX_PAGE1GB
3106 | X86_CPUID_EXT_FEATURE_EDX_RDTSCP
3107 //| RT_BIT_32(28) - reserved
3108 //| X86_CPUID_EXT_FEATURE_EDX_LONG_MODE - turned on when necessary
3109 | X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX
3110 | X86_CPUID_AMD_FEATURE_EDX_3DNOW
3111 ;
3112 pExtFeatureLeaf->uEcx &= X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF
3113 //| X86_CPUID_AMD_FEATURE_ECX_CMPL - set below if applicable.
3114 | (pConfig->fNestedHWVirt ? X86_CPUID_AMD_FEATURE_ECX_SVM : 0)
3115 //| X86_CPUID_AMD_FEATURE_ECX_EXT_APIC
3116 /* Note: This could prevent teleporting from AMD to Intel CPUs! */
3117 | X86_CPUID_AMD_FEATURE_ECX_CR8L /* expose lock mov cr0 = mov cr8 hack for guests that can use this feature to access the TPR. */
3118 | PASSTHRU_FEATURE_TODO(pConfig->enmAbm, X86_CPUID_AMD_FEATURE_ECX_ABM)
3119 | PASSTHRU_FEATURE_TODO(pConfig->enmSse4A, X86_CPUID_AMD_FEATURE_ECX_SSE4A)
3120 | PASSTHRU_FEATURE_TODO(pConfig->enmMisAlnSse, X86_CPUID_AMD_FEATURE_ECX_MISALNSSE)
3121 | PASSTHRU_FEATURE(pConfig->enm3dNowPrf, pHstFeat->f3DNowPrefetch, X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF)
3122 //| X86_CPUID_AMD_FEATURE_ECX_OSVW
3123 //| X86_CPUID_AMD_FEATURE_ECX_IBS
3124 //| X86_CPUID_AMD_FEATURE_ECX_XOP
3125 //| X86_CPUID_AMD_FEATURE_ECX_SKINIT
3126 //| X86_CPUID_AMD_FEATURE_ECX_WDT
3127 //| RT_BIT_32(14) - reserved
3128 //| X86_CPUID_AMD_FEATURE_ECX_LWP - not supported
3129 //| X86_CPUID_AMD_FEATURE_ECX_FMA4 - not yet virtualized.
3130 //| RT_BIT_32(17) - reserved
3131 //| RT_BIT_32(18) - reserved
3132 //| X86_CPUID_AMD_FEATURE_ECX_NODEID - not yet virtualized.
3133 //| RT_BIT_32(20) - reserved
3134 //| X86_CPUID_AMD_FEATURE_ECX_TBM - not yet virtualized.
3135 //| X86_CPUID_AMD_FEATURE_ECX_TOPOEXT - not yet virtualized.
3136 //| RT_BIT_32(23) - reserved
3137 //| RT_BIT_32(24) - reserved
3138 //| RT_BIT_32(25) - reserved
3139 //| RT_BIT_32(26) - reserved
3140 //| RT_BIT_32(27) - reserved
3141 //| RT_BIT_32(28) - reserved
3142 //| RT_BIT_32(29) - reserved
3143 //| RT_BIT_32(30) - reserved
3144 //| RT_BIT_32(31) - reserved
3145 ;
3146#ifdef VBOX_WITH_MULTI_CORE
3147 if ( pVM->cCpus > 1
3148 && ( pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_AMD
3149 || pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_HYGON))
3150 pExtFeatureLeaf->uEcx |= X86_CPUID_AMD_FEATURE_ECX_CMPL; /* CmpLegacy */
3151#endif
3152
3153 if (pCpum->u8PortableCpuIdLevel > 0)
3154 {
3155 PORTABLE_DISABLE_FEATURE_BIT( 1, pExtFeatureLeaf->uEcx, CR8L, X86_CPUID_AMD_FEATURE_ECX_CR8L);
3156 PORTABLE_DISABLE_FEATURE_BIT( 1, pExtFeatureLeaf->uEcx, SVM, X86_CPUID_AMD_FEATURE_ECX_SVM);
3157 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pExtFeatureLeaf->uEcx, ABM, X86_CPUID_AMD_FEATURE_ECX_ABM, pConfig->enmAbm);
3158 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pExtFeatureLeaf->uEcx, SSE4A, X86_CPUID_AMD_FEATURE_ECX_SSE4A, pConfig->enmSse4A);
3159 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pExtFeatureLeaf->uEcx, MISALNSSE, X86_CPUID_AMD_FEATURE_ECX_MISALNSSE, pConfig->enmMisAlnSse);
3160 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pExtFeatureLeaf->uEcx, 3DNOWPRF, X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF, pConfig->enm3dNowPrf);
3161 PORTABLE_DISABLE_FEATURE_BIT( 1, pExtFeatureLeaf->uEcx, XOP, X86_CPUID_AMD_FEATURE_ECX_XOP);
3162 PORTABLE_DISABLE_FEATURE_BIT( 1, pExtFeatureLeaf->uEcx, TBM, X86_CPUID_AMD_FEATURE_ECX_TBM);
3163 PORTABLE_DISABLE_FEATURE_BIT( 1, pExtFeatureLeaf->uEcx, FMA4, X86_CPUID_AMD_FEATURE_ECX_FMA4);
3164 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pExtFeatureLeaf->uEdx, AXMMX, X86_CPUID_AMD_FEATURE_EDX_AXMMX, pConfig->enmAmdExtMmx);
3165 PORTABLE_DISABLE_FEATURE_BIT( 1, pExtFeatureLeaf->uEdx, 3DNOW, X86_CPUID_AMD_FEATURE_EDX_3DNOW);
3166 PORTABLE_DISABLE_FEATURE_BIT( 1, pExtFeatureLeaf->uEdx, 3DNOW_EX, X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX);
3167 PORTABLE_DISABLE_FEATURE_BIT( 1, pExtFeatureLeaf->uEdx, FFXSR, X86_CPUID_AMD_FEATURE_EDX_FFXSR);
3168 PORTABLE_DISABLE_FEATURE_BIT( 1, pExtFeatureLeaf->uEdx, RDTSCP, X86_CPUID_EXT_FEATURE_EDX_RDTSCP);
3169 PORTABLE_DISABLE_FEATURE_BIT( 2, pExtFeatureLeaf->uEcx, LAHF_SAHF, X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF);
3170 PORTABLE_DISABLE_FEATURE_BIT( 3, pExtFeatureLeaf->uEcx, CMOV, X86_CPUID_AMD_FEATURE_EDX_CMOV);
3171
3172 Assert(!(pExtFeatureLeaf->uEcx & ( X86_CPUID_AMD_FEATURE_ECX_SVM
3173 | X86_CPUID_AMD_FEATURE_ECX_EXT_APIC
3174 | X86_CPUID_AMD_FEATURE_ECX_OSVW
3175 | X86_CPUID_AMD_FEATURE_ECX_IBS
3176 | X86_CPUID_AMD_FEATURE_ECX_SKINIT
3177 | X86_CPUID_AMD_FEATURE_ECX_WDT
3178 | X86_CPUID_AMD_FEATURE_ECX_LWP
3179 | X86_CPUID_AMD_FEATURE_ECX_NODEID
3180 | X86_CPUID_AMD_FEATURE_ECX_TOPOEXT
3181 | UINT32_C(0xff964000)
3182 )));
3183 Assert(!(pExtFeatureLeaf->uEdx & ( RT_BIT(10)
3184 | X86_CPUID_EXT_FEATURE_EDX_SYSCALL
3185 | RT_BIT(18)
3186 | RT_BIT(19)
3187 | RT_BIT(21)
3188 | X86_CPUID_AMD_FEATURE_EDX_AXMMX
3189 | X86_CPUID_EXT_FEATURE_EDX_PAGE1GB
3190 | RT_BIT(28)
3191 )));
3192 }
3193
3194 /* Force extended feature bits. */
3195 if (pConfig->enmAbm == CPUMISAEXTCFG_ENABLED_ALWAYS)
3196 pExtFeatureLeaf->uEcx |= X86_CPUID_AMD_FEATURE_ECX_ABM;
3197 if (pConfig->enmSse4A == CPUMISAEXTCFG_ENABLED_ALWAYS)
3198 pExtFeatureLeaf->uEcx |= X86_CPUID_AMD_FEATURE_ECX_SSE4A;
3199 if (pConfig->enmMisAlnSse == CPUMISAEXTCFG_ENABLED_ALWAYS)
3200 pExtFeatureLeaf->uEcx |= X86_CPUID_AMD_FEATURE_ECX_MISALNSSE;
3201 if (pConfig->enm3dNowPrf == CPUMISAEXTCFG_ENABLED_ALWAYS)
3202 pExtFeatureLeaf->uEcx |= X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF;
3203 if (pConfig->enmAmdExtMmx == CPUMISAEXTCFG_ENABLED_ALWAYS)
3204 pExtFeatureLeaf->uEdx |= X86_CPUID_AMD_FEATURE_EDX_AXMMX;
3205 }
3206 pExtFeatureLeaf = NULL; /* Must refetch! */
3207
3208
3209 /* Cpuid 2:
3210 * Intel: (Nondeterministic) Cache and TLB information
3211 * AMD: Reserved
3212 * VIA: Reserved
3213 * Safe to expose.
3214 */
3215 uint32_t uSubLeaf = 0;
3216 PCPUMCPUIDLEAF pCurLeaf;
3217 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 2, uSubLeaf)) != NULL)
3218 {
3219 if ((pCurLeaf->uEax & 0xff) > 1)
3220 {
3221 LogRel(("CpuId: Std[2].al: %d -> 1\n", pCurLeaf->uEax & 0xff));
3222 pCurLeaf->uEax &= UINT32_C(0xffffff01);
3223 }
3224 uSubLeaf++;
3225 }
3226
3227 /* Cpuid 3:
3228 * Intel: EAX, EBX - reserved (transmeta uses these)
3229 * ECX, EDX - Processor Serial Number if available, otherwise reserved
3230 * AMD: Reserved
3231 * VIA: Reserved
3232 * Safe to expose
3233 */
3234 pStdFeatureLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 1, 0);
3235 if (!(pStdFeatureLeaf->uEdx & X86_CPUID_FEATURE_EDX_PSN))
3236 {
3237 uSubLeaf = 0;
3238 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 3, uSubLeaf)) != NULL)
3239 {
3240 pCurLeaf->uEcx = pCurLeaf->uEdx = 0;
3241 if (pCpum->u8PortableCpuIdLevel > 0)
3242 pCurLeaf->uEax = pCurLeaf->uEbx = 0;
3243 uSubLeaf++;
3244 }
3245 }
3246
3247 /* Cpuid 4 + ECX:
3248 * Intel: Deterministic Cache Parameters Leaf.
3249 * AMD: Reserved
3250 * VIA: Reserved
3251 * Safe to expose, except for EAX:
3252 * Bits 25-14: Maximum number of addressable IDs for logical processors sharing this cache (see note)**
3253 * Bits 31-26: Maximum number of processor cores in this physical package**
3254 * Note: These SMP values are constant regardless of ECX
3255 */
3256 uSubLeaf = 0;
3257 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 4, uSubLeaf)) != NULL)
3258 {
3259 pCurLeaf->uEax &= UINT32_C(0x00003fff); /* Clear the #maxcores, #threads-sharing-cache (both are #-1).*/
3260#ifdef VBOX_WITH_MULTI_CORE
3261 if ( pVM->cCpus > 1
3262 && pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_INTEL)
3263 {
3264 AssertReturn(pVM->cCpus <= 64, VERR_TOO_MANY_CPUS);
3265 /* One logical processor with possibly multiple cores. */
3266 /* See http://www.intel.com/Assets/PDF/appnote/241618.pdf p. 29 */
3267 pCurLeaf->uEax |= pVM->cCpus <= 0x40 ? ((pVM->cCpus - 1) << 26) : UINT32_C(0xfc000000); /* 6 bits only -> 64 cores! */
3268 }
3269#endif
3270 uSubLeaf++;
3271 }
3272
3273 /* Cpuid 5: Monitor/mwait Leaf
3274 * Intel: ECX, EDX - reserved
3275 * EAX, EBX - Smallest and largest monitor line size
3276 * AMD: EDX - reserved
3277 * EAX, EBX - Smallest and largest monitor line size
3278 * ECX - extensions (ignored for now)
3279 * VIA: Reserved
3280 * Safe to expose
3281 */
3282 uSubLeaf = 0;
3283 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 5, uSubLeaf)) != NULL)
3284 {
3285 pStdFeatureLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 1, 0);
3286 if (!(pStdFeatureLeaf->uEcx & X86_CPUID_FEATURE_ECX_MONITOR))
3287 pCurLeaf->uEax = pCurLeaf->uEbx = 0;
3288
3289 pCurLeaf->uEcx = pCurLeaf->uEdx = 0;
3290 if (pConfig->enmMWaitExtensions)
3291 {
3292 pCurLeaf->uEcx = X86_CPUID_MWAIT_ECX_EXT | X86_CPUID_MWAIT_ECX_BREAKIRQIF0;
3293 /** @todo for now we just expose host's MWAIT C-states, although conceptually
3294 it shall be part of our power management virtualization model */
3295#if 0
3296 /* MWAIT sub C-states */
3297 pCurLeaf->uEdx =
3298 (0 << 0) /* 0 in C0 */ |
3299 (2 << 4) /* 2 in C1 */ |
3300 (2 << 8) /* 2 in C2 */ |
3301 (2 << 12) /* 2 in C3 */ |
3302 (0 << 16) /* 0 in C4 */
3303 ;
3304#endif
3305 }
3306 else
3307 pCurLeaf->uEcx = pCurLeaf->uEdx = 0;
3308 uSubLeaf++;
3309 }
3310
3311 /* Cpuid 6: Digital Thermal Sensor and Power Management Paramenters.
3312 * Intel: Various stuff.
3313 * AMD: EAX, EBX, EDX - reserved.
3314 * ECX - Bit zero is EffFreq, indicating MSR_0000_00e7 and MSR_0000_00e8
3315 * present. Same as intel.
3316 * VIA: ??
3317 *
3318 * We clear everything here for now.
3319 */
3320 cpumR3CpuIdZeroLeaf(pCpum, 6);
3321
3322 /* Cpuid 7 + ECX: Structured Extended Feature Flags Enumeration
3323 * EAX: Number of sub leaves.
3324 * EBX+ECX+EDX: Feature flags
3325 *
3326 * We only have documentation for one sub-leaf, so clear all other (no need
3327 * to remove them as such, just set them to zero).
3328 *
3329 * Note! When enabling new features the Synthetic CPU and Portable CPUID
3330 * options may require adjusting (i.e. stripping what was enabled).
3331 */
3332 uSubLeaf = 0;
3333 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 7, uSubLeaf)) != NULL)
3334 {
3335 switch (uSubLeaf)
3336 {
3337 case 0:
3338 {
3339 pCurLeaf->uEax = 0; /* Max ECX input is 0. */
3340 pCurLeaf->uEbx &= 0
3341 | PASSTHRU_FEATURE(pConfig->enmFsGsBase, pHstFeat->fFsGsBase, X86_CPUID_STEXT_FEATURE_EBX_FSGSBASE)
3342 //| X86_CPUID_STEXT_FEATURE_EBX_TSC_ADJUST RT_BIT(1)
3343 //| X86_CPUID_STEXT_FEATURE_EBX_SGX RT_BIT(2)
3344 //| X86_CPUID_STEXT_FEATURE_EBX_BMI1 RT_BIT(3)
3345 //| X86_CPUID_STEXT_FEATURE_EBX_HLE RT_BIT(4)
3346 | PASSTHRU_FEATURE(pConfig->enmAvx2, pHstFeat->fAvx2, X86_CPUID_STEXT_FEATURE_EBX_AVX2)
3347 | X86_CPUID_STEXT_FEATURE_EBX_FDP_EXCPTN_ONLY
3348 //| X86_CPUID_STEXT_FEATURE_EBX_SMEP RT_BIT(7)
3349 //| X86_CPUID_STEXT_FEATURE_EBX_BMI2 RT_BIT(8)
3350 //| X86_CPUID_STEXT_FEATURE_EBX_ERMS RT_BIT(9)
3351 | PASSTHRU_FEATURE(pConfig->enmInvpcid, pHstFeat->fInvpcid, X86_CPUID_STEXT_FEATURE_EBX_INVPCID)
3352 //| X86_CPUID_STEXT_FEATURE_EBX_RTM RT_BIT(11)
3353 //| X86_CPUID_STEXT_FEATURE_EBX_PQM RT_BIT(12)
3354 | X86_CPUID_STEXT_FEATURE_EBX_DEPR_FPU_CS_DS
3355 //| X86_CPUID_STEXT_FEATURE_EBX_MPE RT_BIT(14)
3356 //| X86_CPUID_STEXT_FEATURE_EBX_PQE RT_BIT(15)
3357 //| X86_CPUID_STEXT_FEATURE_EBX_AVX512F RT_BIT(16)
3358 //| RT_BIT(17) - reserved
3359 | PASSTHRU_FEATURE_TODO(pConfig->enmRdSeed, X86_CPUID_STEXT_FEATURE_EBX_RDSEED)
3360 //| X86_CPUID_STEXT_FEATURE_EBX_ADX RT_BIT(19)
3361 //| X86_CPUID_STEXT_FEATURE_EBX_SMAP RT_BIT(20)
3362 //| RT_BIT(21) - reserved
3363 //| RT_BIT(22) - reserved
3364 | PASSTHRU_FEATURE(pConfig->enmCLFlushOpt, pHstFeat->fClFlushOpt, X86_CPUID_STEXT_FEATURE_EBX_CLFLUSHOPT)
3365 //| RT_BIT(24) - reserved
3366 //| X86_CPUID_STEXT_FEATURE_EBX_INTEL_PT RT_BIT(25)
3367 //| X86_CPUID_STEXT_FEATURE_EBX_AVX512PF RT_BIT(26)
3368 //| X86_CPUID_STEXT_FEATURE_EBX_AVX512ER RT_BIT(27)
3369 //| X86_CPUID_STEXT_FEATURE_EBX_AVX512CD RT_BIT(28)
3370 //| X86_CPUID_STEXT_FEATURE_EBX_SHA RT_BIT(29)
3371 //| RT_BIT(30) - reserved
3372 //| RT_BIT(31) - reserved
3373 ;
3374 pCurLeaf->uEcx &= 0
3375 //| X86_CPUID_STEXT_FEATURE_ECX_PREFETCHWT1 - we do not do vector functions yet.
3376 ;
3377 pCurLeaf->uEdx &= 0
3378 | PASSTHRU_FEATURE(pConfig->enmMdsClear, pHstFeat->fMdsClear, X86_CPUID_STEXT_FEATURE_EDX_MD_CLEAR)
3379 //| X86_CPUID_STEXT_FEATURE_EDX_IBRS_IBPB RT_BIT(26)
3380 //| X86_CPUID_STEXT_FEATURE_EDX_STIBP RT_BIT(27)
3381 | PASSTHRU_FEATURE(pConfig->enmFlushCmdMsr, pHstFeat->fFlushCmd, X86_CPUID_STEXT_FEATURE_EDX_FLUSH_CMD)
3382 | PASSTHRU_FEATURE(pConfig->enmArchCapMsr, pHstFeat->fArchCap, X86_CPUID_STEXT_FEATURE_EDX_ARCHCAP)
3383 ;
3384
3385 /* Mask out INVPCID unless FSGSBASE is exposed due to a bug in Windows 10 SMP guests, see @bugref{9089#c15}. */
3386 if ( !pVM->cpum.s.GuestFeatures.fFsGsBase
3387 && (pCurLeaf->uEbx & X86_CPUID_STEXT_FEATURE_EBX_INVPCID))
3388 {
3389 pCurLeaf->uEbx &= ~X86_CPUID_STEXT_FEATURE_EBX_INVPCID;
3390 LogRel(("CPUM: Disabled INVPCID without FSGSBASE to work around buggy guests\n"));
3391 }
3392
3393 if (pCpum->u8PortableCpuIdLevel > 0)
3394 {
3395 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pCurLeaf->uEbx, FSGSBASE, X86_CPUID_STEXT_FEATURE_EBX_FSGSBASE, pConfig->enmFsGsBase);
3396 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEbx, SGX, X86_CPUID_STEXT_FEATURE_EBX_SGX);
3397 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pCurLeaf->uEbx, AVX2, X86_CPUID_STEXT_FEATURE_EBX_AVX2, pConfig->enmAvx2);
3398 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEbx, SMEP, X86_CPUID_STEXT_FEATURE_EBX_SMEP);
3399 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEbx, BMI2, X86_CPUID_STEXT_FEATURE_EBX_BMI2);
3400 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pCurLeaf->uEbx, INVPCID, X86_CPUID_STEXT_FEATURE_EBX_INVPCID, pConfig->enmInvpcid);
3401 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEbx, AVX512F, X86_CPUID_STEXT_FEATURE_EBX_AVX512F);
3402 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pCurLeaf->uEbx, RDSEED, X86_CPUID_STEXT_FEATURE_EBX_RDSEED, pConfig->enmRdSeed);
3403 PORTABLE_DISABLE_FEATURE_BIT_CFG(1, pCurLeaf->uEbx, CLFLUSHOPT, X86_CPUID_STEXT_FEATURE_EBX_RDSEED, pConfig->enmCLFlushOpt);
3404 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEbx, AVX512PF, X86_CPUID_STEXT_FEATURE_EBX_AVX512PF);
3405 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEbx, AVX512ER, X86_CPUID_STEXT_FEATURE_EBX_AVX512ER);
3406 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEbx, AVX512CD, X86_CPUID_STEXT_FEATURE_EBX_AVX512CD);
3407 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEbx, SMAP, X86_CPUID_STEXT_FEATURE_EBX_SMAP);
3408 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEbx, SHA, X86_CPUID_STEXT_FEATURE_EBX_SHA);
3409 PORTABLE_DISABLE_FEATURE_BIT( 1, pCurLeaf->uEcx, PREFETCHWT1, X86_CPUID_STEXT_FEATURE_ECX_PREFETCHWT1);
3410 PORTABLE_DISABLE_FEATURE_BIT_CFG(3, pCurLeaf->uEdx, FLUSH_CMD, X86_CPUID_STEXT_FEATURE_EDX_FLUSH_CMD, pConfig->enmFlushCmdMsr);
3411 PORTABLE_DISABLE_FEATURE_BIT_CFG(3, pCurLeaf->uEdx, MD_CLEAR, X86_CPUID_STEXT_FEATURE_EDX_MD_CLEAR, pConfig->enmMdsClear);
3412 PORTABLE_DISABLE_FEATURE_BIT_CFG(3, pCurLeaf->uEdx, ARCHCAP, X86_CPUID_STEXT_FEATURE_EDX_ARCHCAP, pConfig->enmArchCapMsr);
3413 }
3414
3415 /* Dependencies. */
3416 if (!(pCurLeaf->uEdx & X86_CPUID_STEXT_FEATURE_EDX_FLUSH_CMD))
3417 pCurLeaf->uEdx &= ~X86_CPUID_STEXT_FEATURE_EDX_MD_CLEAR;
3418
3419 /* Force standard feature bits. */
3420 if (pConfig->enmFsGsBase == CPUMISAEXTCFG_ENABLED_ALWAYS)
3421 pCurLeaf->uEbx |= X86_CPUID_STEXT_FEATURE_EBX_FSGSBASE;
3422 if (pConfig->enmAvx2 == CPUMISAEXTCFG_ENABLED_ALWAYS)
3423 pCurLeaf->uEbx |= X86_CPUID_STEXT_FEATURE_EBX_AVX2;
3424 if (pConfig->enmRdSeed == CPUMISAEXTCFG_ENABLED_ALWAYS)
3425 pCurLeaf->uEbx |= X86_CPUID_STEXT_FEATURE_EBX_RDSEED;
3426 if (pConfig->enmCLFlushOpt == CPUMISAEXTCFG_ENABLED_ALWAYS)
3427 pCurLeaf->uEbx |= X86_CPUID_STEXT_FEATURE_EBX_CLFLUSHOPT;
3428 if (pConfig->enmInvpcid == CPUMISAEXTCFG_ENABLED_ALWAYS)
3429 pCurLeaf->uEbx |= X86_CPUID_STEXT_FEATURE_EBX_INVPCID;
3430 if (pConfig->enmFlushCmdMsr == CPUMISAEXTCFG_ENABLED_ALWAYS)
3431 pCurLeaf->uEdx |= X86_CPUID_STEXT_FEATURE_EDX_FLUSH_CMD;
3432 if (pConfig->enmMdsClear == CPUMISAEXTCFG_ENABLED_ALWAYS)
3433 pCurLeaf->uEdx |= X86_CPUID_STEXT_FEATURE_EDX_MD_CLEAR;
3434 if (pConfig->enmArchCapMsr == CPUMISAEXTCFG_ENABLED_ALWAYS)
3435 pCurLeaf->uEdx |= X86_CPUID_STEXT_FEATURE_EDX_ARCHCAP;
3436 break;
3437 }
3438
3439 default:
3440 /* Invalid index, all values are zero. */
3441 pCurLeaf->uEax = 0;
3442 pCurLeaf->uEbx = 0;
3443 pCurLeaf->uEcx = 0;
3444 pCurLeaf->uEdx = 0;
3445 break;
3446 }
3447 uSubLeaf++;
3448 }
3449
3450 /* Cpuid 8: Marked as reserved by Intel and AMD.
3451 * We zero this since we don't know what it may have been used for.
3452 */
3453 cpumR3CpuIdZeroLeaf(pCpum, 8);
3454
3455 /* Cpuid 9: Direct Cache Access (DCA) Parameters
3456 * Intel: EAX - Value of PLATFORM_DCA_CAP bits.
3457 * EBX, ECX, EDX - reserved.
3458 * AMD: Reserved
3459 * VIA: ??
3460 *
3461 * We zero this.
3462 */
3463 cpumR3CpuIdZeroLeaf(pCpum, 9);
3464
3465 /* Cpuid 0xa: Architectural Performance Monitor Features
3466 * Intel: EAX - Value of PLATFORM_DCA_CAP bits.
3467 * EBX, ECX, EDX - reserved.
3468 * AMD: Reserved
3469 * VIA: ??
3470 *
3471 * We zero this, for now at least.
3472 */
3473 cpumR3CpuIdZeroLeaf(pCpum, 10);
3474
3475 /* Cpuid 0xb+ECX: x2APIC Features / Processor Topology.
3476 * Intel: EAX - APCI ID shift right for next level.
3477 * EBX - Factory configured cores/threads at this level.
3478 * ECX - Level number (same as input) and level type (1,2,0).
3479 * EDX - Extended initial APIC ID.
3480 * AMD: Reserved
3481 * VIA: ??
3482 */
3483 uSubLeaf = 0;
3484 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 11, uSubLeaf)) != NULL)
3485 {
3486 if (pCurLeaf->fFlags & CPUMCPUIDLEAF_F_CONTAINS_APIC_ID)
3487 {
3488 uint8_t bLevelType = RT_BYTE2(pCurLeaf->uEcx);
3489 if (bLevelType == 1)
3490 {
3491 /* Thread level - we don't do threads at the moment. */
3492 pCurLeaf->uEax = 0; /** @todo is this correct? Real CPUs never do 0 here, I think... */
3493 pCurLeaf->uEbx = 1;
3494 }
3495 else if (bLevelType == 2)
3496 {
3497 /* Core level. */
3498 pCurLeaf->uEax = 1; /** @todo real CPUs are supposed to be in the 4-6 range, not 1. Our APIC ID assignments are a little special... */
3499#ifdef VBOX_WITH_MULTI_CORE
3500 while (RT_BIT_32(pCurLeaf->uEax) < pVM->cCpus)
3501 pCurLeaf->uEax++;
3502#endif
3503 pCurLeaf->uEbx = pVM->cCpus;
3504 }
3505 else
3506 {
3507 AssertLogRelMsg(bLevelType == 0, ("bLevelType=%#x uSubLeaf=%#x\n", bLevelType, uSubLeaf));
3508 pCurLeaf->uEax = 0;
3509 pCurLeaf->uEbx = 0;
3510 pCurLeaf->uEcx = 0;
3511 }
3512 pCurLeaf->uEcx = (pCurLeaf->uEcx & UINT32_C(0xffffff00)) | (uSubLeaf & 0xff);
3513 pCurLeaf->uEdx = 0; /* APIC ID is filled in by CPUMGetGuestCpuId() at runtime. Init for EMT(0) as usual. */
3514 }
3515 else
3516 {
3517 pCurLeaf->uEax = 0;
3518 pCurLeaf->uEbx = 0;
3519 pCurLeaf->uEcx = 0;
3520 pCurLeaf->uEdx = 0;
3521 }
3522 uSubLeaf++;
3523 }
3524
3525 /* Cpuid 0xc: Marked as reserved by Intel and AMD.
3526 * We zero this since we don't know what it may have been used for.
3527 */
3528 cpumR3CpuIdZeroLeaf(pCpum, 12);
3529
3530 /* Cpuid 0xd + ECX: Processor Extended State Enumeration
3531 * ECX=0: EAX - Valid bits in XCR0[31:0].
3532 * EBX - Maximum state size as per current XCR0 value.
3533 * ECX - Maximum state size for all supported features.
3534 * EDX - Valid bits in XCR0[63:32].
3535 * ECX=1: EAX - Various X-features.
3536 * EBX - Maximum state size as per current XCR0|IA32_XSS value.
3537 * ECX - Valid bits in IA32_XSS[31:0].
3538 * EDX - Valid bits in IA32_XSS[63:32].
3539 * ECX=N, where N in 2..63 and indicates a bit in XCR0 and/or IA32_XSS,
3540 * if the bit invalid all four registers are set to zero.
3541 * EAX - The state size for this feature.
3542 * EBX - The state byte offset of this feature.
3543 * ECX - Bit 0 indicates whether this sub-leaf maps to a valid IA32_XSS bit (=1) or a valid XCR0 bit (=0).
3544 * EDX - Reserved, but is set to zero if invalid sub-leaf index.
3545 *
3546 * Clear them all as we don't currently implement extended CPU state.
3547 */
3548 /* Figure out the supported XCR0/XSS mask component and make sure CPUID[1].ECX[27] = CR4.OSXSAVE. */
3549 uint64_t fGuestXcr0Mask = 0;
3550 pStdFeatureLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 1, 0);
3551 if (pStdFeatureLeaf && (pStdFeatureLeaf->uEcx & X86_CPUID_FEATURE_ECX_XSAVE))
3552 {
3553 fGuestXcr0Mask = XSAVE_C_X87 | XSAVE_C_SSE;
3554 if (pStdFeatureLeaf && (pStdFeatureLeaf->uEcx & X86_CPUID_FEATURE_ECX_AVX))
3555 fGuestXcr0Mask |= XSAVE_C_YMM;
3556 pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 7, 0);
3557 if (pCurLeaf && (pCurLeaf->uEbx & X86_CPUID_STEXT_FEATURE_EBX_AVX512F))
3558 fGuestXcr0Mask |= XSAVE_C_ZMM_16HI | XSAVE_C_ZMM_HI256 | XSAVE_C_OPMASK;
3559 fGuestXcr0Mask &= pCpum->fXStateHostMask;
3560
3561 pStdFeatureLeaf->fFlags |= CPUMCPUIDLEAF_F_CONTAINS_OSXSAVE;
3562 }
3563 pStdFeatureLeaf = NULL;
3564 pCpum->fXStateGuestMask = fGuestXcr0Mask;
3565
3566 /* Work the sub-leaves. */
3567 uint32_t cbXSaveMaxActual = CPUM_MIN_XSAVE_AREA_SIZE;
3568 uint32_t cbXSaveMaxReport = CPUM_MIN_XSAVE_AREA_SIZE;
3569 for (uSubLeaf = 0; uSubLeaf < 63; uSubLeaf++)
3570 {
3571 pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 13, uSubLeaf);
3572 if (pCurLeaf)
3573 {
3574 if (fGuestXcr0Mask)
3575 {
3576 switch (uSubLeaf)
3577 {
3578 case 0:
3579 pCurLeaf->uEax &= RT_LO_U32(fGuestXcr0Mask);
3580 pCurLeaf->uEdx &= RT_HI_U32(fGuestXcr0Mask);
3581 AssertLogRelMsgReturn((pCurLeaf->uEax & (XSAVE_C_X87 | XSAVE_C_SSE)) == (XSAVE_C_X87 | XSAVE_C_SSE),
3582 ("CPUID(0xd/0).EAX missing mandatory X87 or SSE bits: %#RX32", pCurLeaf->uEax),
3583 VERR_CPUM_IPE_1);
3584 cbXSaveMaxActual = pCurLeaf->uEcx;
3585 AssertLogRelMsgReturn(cbXSaveMaxActual <= CPUM_MAX_XSAVE_AREA_SIZE && cbXSaveMaxActual >= CPUM_MIN_XSAVE_AREA_SIZE,
3586 ("%#x max=%#x\n", cbXSaveMaxActual, CPUM_MAX_XSAVE_AREA_SIZE), VERR_CPUM_IPE_2);
3587 AssertLogRelMsgReturn(pCurLeaf->uEbx >= CPUM_MIN_XSAVE_AREA_SIZE && pCurLeaf->uEbx <= cbXSaveMaxActual,
3588 ("ebx=%#x cbXSaveMaxActual=%#x\n", pCurLeaf->uEbx, cbXSaveMaxActual),
3589 VERR_CPUM_IPE_2);
3590 continue;
3591 case 1:
3592 pCurLeaf->uEax &= 0;
3593 pCurLeaf->uEcx &= 0;
3594 pCurLeaf->uEdx &= 0;
3595 /** @todo what about checking ebx? */
3596 continue;
3597 default:
3598 if (fGuestXcr0Mask & RT_BIT_64(uSubLeaf))
3599 {
3600 AssertLogRelMsgReturn( pCurLeaf->uEax <= cbXSaveMaxActual
3601 && pCurLeaf->uEax > 0
3602 && pCurLeaf->uEbx < cbXSaveMaxActual
3603 && pCurLeaf->uEbx >= CPUM_MIN_XSAVE_AREA_SIZE
3604 && pCurLeaf->uEbx + pCurLeaf->uEax <= cbXSaveMaxActual,
3605 ("%#x: eax=%#x ebx=%#x cbMax=%#x\n",
3606 uSubLeaf, pCurLeaf->uEax, pCurLeaf->uEbx, cbXSaveMaxActual),
3607 VERR_CPUM_IPE_2);
3608 AssertLogRel(!(pCurLeaf->uEcx & 1));
3609 pCurLeaf->uEcx = 0; /* Bit 0 should be zero (XCR0), the reset are reserved... */
3610 pCurLeaf->uEdx = 0; /* it's reserved... */
3611 if (pCurLeaf->uEbx + pCurLeaf->uEax > cbXSaveMaxReport)
3612 cbXSaveMaxReport = pCurLeaf->uEbx + pCurLeaf->uEax;
3613 continue;
3614 }
3615 break;
3616 }
3617 }
3618
3619 /* Clear the leaf. */
3620 pCurLeaf->uEax = 0;
3621 pCurLeaf->uEbx = 0;
3622 pCurLeaf->uEcx = 0;
3623 pCurLeaf->uEdx = 0;
3624 }
3625 }
3626
3627 /* Update the max and current feature sizes to shut up annoying Linux kernels. */
3628 if (cbXSaveMaxReport != cbXSaveMaxActual && fGuestXcr0Mask)
3629 {
3630 pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 13, 0);
3631 if (pCurLeaf)
3632 {
3633 LogRel(("CPUM: Changing leaf 13[0]: EBX=%#RX32 -> %#RX32, ECX=%#RX32 -> %#RX32\n",
3634 pCurLeaf->uEbx, cbXSaveMaxReport, pCurLeaf->uEcx, cbXSaveMaxReport));
3635 pCurLeaf->uEbx = cbXSaveMaxReport;
3636 pCurLeaf->uEcx = cbXSaveMaxReport;
3637 }
3638 }
3639
3640 /* Cpuid 0xe: Marked as reserved by Intel and AMD.
3641 * We zero this since we don't know what it may have been used for.
3642 */
3643 cpumR3CpuIdZeroLeaf(pCpum, 14);
3644
3645 /* Cpuid 0xf + ECX: Platform quality of service monitoring (PQM),
3646 * also known as Intel Resource Director Technology (RDT) Monitoring
3647 * We zero this as we don't currently virtualize PQM.
3648 */
3649 cpumR3CpuIdZeroLeaf(pCpum, 15);
3650
3651 /* Cpuid 0x10 + ECX: Platform quality of service enforcement (PQE),
3652 * also known as Intel Resource Director Technology (RDT) Allocation
3653 * We zero this as we don't currently virtualize PQE.
3654 */
3655 cpumR3CpuIdZeroLeaf(pCpum, 16);
3656
3657 /* Cpuid 0x11: Marked as reserved by Intel and AMD.
3658 * We zero this since we don't know what it may have been used for.
3659 */
3660 cpumR3CpuIdZeroLeaf(pCpum, 17);
3661
3662 /* Cpuid 0x12 + ECX: SGX resource enumeration.
3663 * We zero this as we don't currently virtualize this.
3664 */
3665 cpumR3CpuIdZeroLeaf(pCpum, 18);
3666
3667 /* Cpuid 0x13: Marked as reserved by Intel and AMD.
3668 * We zero this since we don't know what it may have been used for.
3669 */
3670 cpumR3CpuIdZeroLeaf(pCpum, 19);
3671
3672 /* Cpuid 0x14 + ECX: Processor Trace (PT) capability enumeration.
3673 * We zero this as we don't currently virtualize this.
3674 */
3675 cpumR3CpuIdZeroLeaf(pCpum, 20);
3676
3677 /* Cpuid 0x15: Timestamp Counter / Core Crystal Clock info.
3678 * Intel: uTscFrequency = uCoreCrystalClockFrequency * EBX / EAX.
3679 * EAX - denominator (unsigned).
3680 * EBX - numerator (unsigned).
3681 * ECX, EDX - reserved.
3682 * AMD: Reserved / undefined / not implemented.
3683 * VIA: Reserved / undefined / not implemented.
3684 * We zero this as we don't currently virtualize this.
3685 */
3686 cpumR3CpuIdZeroLeaf(pCpum, 21);
3687
3688 /* Cpuid 0x16: Processor frequency info
3689 * Intel: EAX - Core base frequency in MHz.
3690 * EBX - Core maximum frequency in MHz.
3691 * ECX - Bus (reference) frequency in MHz.
3692 * EDX - Reserved.
3693 * AMD: Reserved / undefined / not implemented.
3694 * VIA: Reserved / undefined / not implemented.
3695 * We zero this as we don't currently virtualize this.
3696 */
3697 cpumR3CpuIdZeroLeaf(pCpum, 22);
3698
3699 /* Cpuid 0x17..0x10000000: Unknown.
3700 * We don't know these and what they mean, so remove them. */
3701 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
3702 UINT32_C(0x00000017), UINT32_C(0x0fffffff));
3703
3704
3705 /* CpuId 0x40000000..0x4fffffff: Reserved for hypervisor/emulator.
3706 * We remove all these as we're a hypervisor and must provide our own.
3707 */
3708 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
3709 UINT32_C(0x40000000), UINT32_C(0x4fffffff));
3710
3711
3712 /* Cpuid 0x80000000 is harmless. */
3713
3714 /* Cpuid 0x80000001 is handled with cpuid 1 way up above. */
3715
3716 /* Cpuid 0x80000002...0x80000004 contains the processor name and is considered harmless. */
3717
3718 /* Cpuid 0x800000005 & 0x800000006 contain information about L1, L2 & L3 cache and TLB identifiers.
3719 * Safe to pass on to the guest.
3720 *
3721 * AMD: 0x800000005 L1 cache information
3722 * 0x800000006 L2/L3 cache information
3723 * Intel: 0x800000005 reserved
3724 * 0x800000006 L2 cache information
3725 * VIA: 0x800000005 TLB and L1 cache information
3726 * 0x800000006 L2 cache information
3727 */
3728
3729 /* Cpuid 0x800000007: Advanced Power Management Information.
3730 * AMD: EAX: Processor feedback capabilities.
3731 * EBX: RAS capabilites.
3732 * ECX: Advanced power monitoring interface.
3733 * EDX: Enhanced power management capabilities.
3734 * Intel: EAX, EBX, ECX - reserved.
3735 * EDX - Invariant TSC indicator supported (bit 8), the rest is reserved.
3736 * VIA: Reserved
3737 * We let the guest see EDX_TSCINVAR (and later maybe EDX_EFRO). Actually, we should set EDX_TSCINVAR.
3738 */
3739 uSubLeaf = 0;
3740 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x80000007), uSubLeaf)) != NULL)
3741 {
3742 pCurLeaf->uEax = pCurLeaf->uEbx = pCurLeaf->uEcx = 0;
3743 if ( pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_AMD
3744 || pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_HYGON)
3745 {
3746 /*
3747 * Older 64-bit linux kernels blindly assume that the AMD performance counters work
3748 * if X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR is set, see @bugref{7243#c85}. Exposing this
3749 * bit is now configurable.
3750 */
3751 pCurLeaf->uEdx &= 0
3752 //| X86_CPUID_AMD_ADVPOWER_EDX_TS
3753 //| X86_CPUID_AMD_ADVPOWER_EDX_FID
3754 //| X86_CPUID_AMD_ADVPOWER_EDX_VID
3755 //| X86_CPUID_AMD_ADVPOWER_EDX_TTP
3756 //| X86_CPUID_AMD_ADVPOWER_EDX_TM
3757 //| X86_CPUID_AMD_ADVPOWER_EDX_STC
3758 //| X86_CPUID_AMD_ADVPOWER_EDX_MC
3759 //| X86_CPUID_AMD_ADVPOWER_EDX_HWPSTATE
3760 | X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR
3761 //| X86_CPUID_AMD_ADVPOWER_EDX_CPB RT_BIT(9)
3762 //| X86_CPUID_AMD_ADVPOWER_EDX_EFRO RT_BIT(10)
3763 //| X86_CPUID_AMD_ADVPOWER_EDX_PFI RT_BIT(11)
3764 //| X86_CPUID_AMD_ADVPOWER_EDX_PA RT_BIT(12)
3765 | 0;
3766 }
3767 else
3768 pCurLeaf->uEdx &= X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR;
3769 if (!pConfig->fInvariantTsc)
3770 pCurLeaf->uEdx &= ~X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR;
3771 uSubLeaf++;
3772 }
3773
3774 /* Cpuid 0x80000008:
3775 * AMD: EBX, EDX - reserved
3776 * EAX: Virtual/Physical/Guest address Size
3777 * ECX: Number of cores + APICIdCoreIdSize
3778 * Intel: EAX: Virtual/Physical address Size
3779 * EBX, ECX, EDX - reserved
3780 * VIA: EAX: Virtual/Physical address Size
3781 * EBX, ECX, EDX - reserved
3782 *
3783 * We only expose the virtual+pysical address size to the guest atm.
3784 * On AMD we set the core count, but not the apic id stuff as we're
3785 * currently not doing the apic id assignments in a complatible manner.
3786 */
3787 uSubLeaf = 0;
3788 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x80000008), uSubLeaf)) != NULL)
3789 {
3790 pCurLeaf->uEax &= UINT32_C(0x0000ffff); /* Virtual & physical address sizes only. */
3791 pCurLeaf->uEbx = 0; /* reserved - [12] == IBPB */
3792 pCurLeaf->uEdx = 0; /* reserved */
3793
3794 /* Set APICIdCoreIdSize to zero (use legacy method to determine the number of cores per cpu).
3795 * Set core count to 0, indicating 1 core. Adjust if we're in multi core mode on AMD. */
3796 pCurLeaf->uEcx = 0;
3797#ifdef VBOX_WITH_MULTI_CORE
3798 if ( pVM->cCpus > 1
3799 && ( pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_AMD
3800 || pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_HYGON))
3801 pCurLeaf->uEcx |= (pVM->cCpus - 1) & UINT32_C(0xff);
3802#endif
3803 uSubLeaf++;
3804 }
3805
3806 /* Cpuid 0x80000009: Reserved
3807 * We zero this since we don't know what it may have been used for.
3808 */
3809 cpumR3CpuIdZeroLeaf(pCpum, UINT32_C(0x80000009));
3810
3811 /* Cpuid 0x8000000a: SVM information on AMD, invalid on Intel.
3812 * AMD: EAX - SVM revision.
3813 * EBX - Number of ASIDs.
3814 * ECX - Reserved.
3815 * EDX - SVM Feature identification.
3816 */
3817 if ( pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_AMD
3818 || pCpum->GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_HYGON)
3819 {
3820 pExtFeatureLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x80000001), 0);
3821 if ( pExtFeatureLeaf
3822 && (pExtFeatureLeaf->uEcx & X86_CPUID_AMD_FEATURE_ECX_SVM))
3823 {
3824 PCPUMCPUIDLEAF pSvmFeatureLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 0x8000000a, 0);
3825 if (pSvmFeatureLeaf)
3826 {
3827 pSvmFeatureLeaf->uEax = 0x1;
3828 pSvmFeatureLeaf->uEbx = 0x8000; /** @todo figure out virtual NASID. */
3829 pSvmFeatureLeaf->uEcx = 0;
3830 pSvmFeatureLeaf->uEdx &= ( X86_CPUID_SVM_FEATURE_EDX_NRIP_SAVE /** @todo Support other SVM features */
3831 | X86_CPUID_SVM_FEATURE_EDX_FLUSH_BY_ASID
3832 | X86_CPUID_SVM_FEATURE_EDX_DECODE_ASSISTS);
3833 }
3834 else
3835 {
3836 /* Should never happen. */
3837 LogRel(("CPUM: Warning! Expected CPUID leaf 0x8000000a not present! SVM features not exposed to the guest\n"));
3838 cpumR3CpuIdZeroLeaf(pCpum, UINT32_C(0x8000000a));
3839 }
3840 }
3841 else
3842 {
3843 /* If SVM is not supported, this is reserved, zero out. */
3844 cpumR3CpuIdZeroLeaf(pCpum, UINT32_C(0x8000000a));
3845 }
3846 }
3847 else
3848 {
3849 /* Cpuid 0x8000000a: Reserved on Intel.
3850 * We zero this since we don't know what it may have been used for.
3851 */
3852 cpumR3CpuIdZeroLeaf(pCpum, UINT32_C(0x8000000a));
3853 }
3854
3855 /* Cpuid 0x8000000b thru 0x80000018: Reserved
3856 * We clear these as we don't know what purpose they might have. */
3857 for (uint32_t uLeaf = UINT32_C(0x8000000b); uLeaf <= UINT32_C(0x80000018); uLeaf++)
3858 cpumR3CpuIdZeroLeaf(pCpum, uLeaf);
3859
3860 /* Cpuid 0x80000019: TLB configuration
3861 * Seems to be harmless, pass them thru as is. */
3862
3863 /* Cpuid 0x8000001a: Peformance optimization identifiers.
3864 * Strip anything we don't know what is or addresses feature we don't implement. */
3865 uSubLeaf = 0;
3866 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x8000001a), uSubLeaf)) != NULL)
3867 {
3868 pCurLeaf->uEax &= RT_BIT_32(0) /* FP128 - use 1x128-bit instead of 2x64-bit. */
3869 | RT_BIT_32(1) /* MOVU - Prefere unaligned MOV over MOVL + MOVH. */
3870 //| RT_BIT_32(2) /* FP256 - use 1x256-bit instead of 2x128-bit. */
3871 ;
3872 pCurLeaf->uEbx = 0; /* reserved */
3873 pCurLeaf->uEcx = 0; /* reserved */
3874 pCurLeaf->uEdx = 0; /* reserved */
3875 uSubLeaf++;
3876 }
3877
3878 /* Cpuid 0x8000001b: Instruct based sampling (IBS) information.
3879 * Clear this as we don't currently virtualize this feature. */
3880 cpumR3CpuIdZeroLeaf(pCpum, UINT32_C(0x8000001b));
3881
3882 /* Cpuid 0x8000001c: Lightweight profiling (LWP) information.
3883 * Clear this as we don't currently virtualize this feature. */
3884 cpumR3CpuIdZeroLeaf(pCpum, UINT32_C(0x8000001c));
3885
3886 /* Cpuid 0x8000001d+ECX: Get cache configuration descriptors.
3887 * We need to sanitize the cores per cache (EAX[25:14]).
3888 *
3889 * This is very much the same as Intel's CPUID(4) leaf, except EAX[31:26]
3890 * and EDX[2] are reserved here, and EAX[14:25] is documented having a
3891 * slightly different meaning.
3892 */
3893 uSubLeaf = 0;
3894 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x8000001d), uSubLeaf)) != NULL)
3895 {
3896#ifdef VBOX_WITH_MULTI_CORE
3897 uint32_t cCores = ((pCurLeaf->uEax >> 14) & 0xfff) + 1;
3898 if (cCores > pVM->cCpus)
3899 cCores = pVM->cCpus;
3900 pCurLeaf->uEax &= UINT32_C(0x00003fff);
3901 pCurLeaf->uEax |= ((cCores - 1) & 0xfff) << 14;
3902#else
3903 pCurLeaf->uEax &= UINT32_C(0x00003fff);
3904#endif
3905 uSubLeaf++;
3906 }
3907
3908 /* Cpuid 0x8000001e: Get APIC / unit / node information.
3909 * If AMD, we configure it for our layout (on EMT(0)). In the multi-core
3910 * setup, we have one compute unit with all the cores in it. Single node.
3911 */
3912 uSubLeaf = 0;
3913 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0x8000001e), uSubLeaf)) != NULL)
3914 {
3915 pCurLeaf->uEax = 0; /* Extended APIC ID = EMT(0).idApic (== 0). */
3916 if (pCurLeaf->fFlags & CPUMCPUIDLEAF_F_CONTAINS_APIC_ID)
3917 {
3918#ifdef VBOX_WITH_MULTI_CORE
3919 pCurLeaf->uEbx = pVM->cCpus < 0x100
3920 ? (pVM->cCpus - 1) << 8 : UINT32_C(0x0000ff00); /* Compute unit ID 0, core per unit. */
3921#else
3922 pCurLeaf->uEbx = 0; /* Compute unit ID 0, 1 core per unit. */
3923#endif
3924 pCurLeaf->uEcx = 0; /* Node ID 0, 1 node per CPU. */
3925 }
3926 else
3927 {
3928 Assert(pCpum->GuestFeatures.enmCpuVendor != CPUMCPUVENDOR_AMD);
3929 Assert(pCpum->GuestFeatures.enmCpuVendor != CPUMCPUVENDOR_HYGON);
3930 pCurLeaf->uEbx = 0; /* Reserved. */
3931 pCurLeaf->uEcx = 0; /* Reserved. */
3932 }
3933 pCurLeaf->uEdx = 0; /* Reserved. */
3934 uSubLeaf++;
3935 }
3936
3937 /* Cpuid 0x8000001f...0x8ffffffd: Unknown.
3938 * We don't know these and what they mean, so remove them. */
3939 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
3940 UINT32_C(0x8000001f), UINT32_C(0x8ffffffd));
3941
3942 /* Cpuid 0x8ffffffe: Mystery AMD K6 leaf.
3943 * Just pass it thru for now. */
3944
3945 /* Cpuid 0x8fffffff: Mystery hammer time leaf!
3946 * Just pass it thru for now. */
3947
3948 /* Cpuid 0xc0000000: Centaur stuff.
3949 * Harmless, pass it thru. */
3950
3951 /* Cpuid 0xc0000001: Centaur features.
3952 * VIA: EAX - Family, model, stepping.
3953 * EDX - Centaur extended feature flags. Nothing interesting, except may
3954 * FEMMS (bit 5), but VIA marks it as 'reserved', so never mind.
3955 * EBX, ECX - reserved.
3956 * We keep EAX but strips the rest.
3957 */
3958 uSubLeaf = 0;
3959 while ((pCurLeaf = cpumR3CpuIdGetExactLeaf(pCpum, UINT32_C(0xc0000001), uSubLeaf)) != NULL)
3960 {
3961 pCurLeaf->uEbx = 0;
3962 pCurLeaf->uEcx = 0;
3963 pCurLeaf->uEdx = 0; /* Bits 0 thru 9 are documented on sandpil.org, but we don't want them, except maybe 5 (FEMMS). */
3964 uSubLeaf++;
3965 }
3966
3967 /* Cpuid 0xc0000002: Old Centaur Current Performance Data.
3968 * We only have fixed stale values, but should be harmless. */
3969
3970 /* Cpuid 0xc0000003: Reserved.
3971 * We zero this since we don't know what it may have been used for.
3972 */
3973 cpumR3CpuIdZeroLeaf(pCpum, UINT32_C(0xc0000003));
3974
3975 /* Cpuid 0xc0000004: Centaur Performance Info.
3976 * We only have fixed stale values, but should be harmless. */
3977
3978
3979 /* Cpuid 0xc0000005...0xcfffffff: Unknown.
3980 * We don't know these and what they mean, so remove them. */
3981 cpumR3CpuIdRemoveRange(pCpum->GuestInfo.paCpuIdLeavesR3, &pCpum->GuestInfo.cCpuIdLeaves,
3982 UINT32_C(0xc0000005), UINT32_C(0xcfffffff));
3983
3984 return VINF_SUCCESS;
3985#undef PORTABLE_DISABLE_FEATURE_BIT
3986#undef PORTABLE_CLEAR_BITS_WHEN
3987}
3988
3989
3990/**
3991 * Reads a value in /CPUM/IsaExts/ node.
3992 *
3993 * @returns VBox status code (error message raised).
3994 * @param pVM The cross context VM structure. (For errors.)
3995 * @param pIsaExts The /CPUM/IsaExts node (can be NULL).
3996 * @param pszValueName The value / extension name.
3997 * @param penmValue Where to return the choice.
3998 * @param enmDefault The default choice.
3999 */
4000static int cpumR3CpuIdReadIsaExtCfg(PVM pVM, PCFGMNODE pIsaExts, const char *pszValueName,
4001 CPUMISAEXTCFG *penmValue, CPUMISAEXTCFG enmDefault)
4002{
4003 /*
4004 * Try integer encoding first.
4005 */
4006 uint64_t uValue;
4007 int rc = CFGMR3QueryInteger(pIsaExts, pszValueName, &uValue);
4008 if (RT_SUCCESS(rc))
4009 switch (uValue)
4010 {
4011 case 0: *penmValue = CPUMISAEXTCFG_DISABLED; break;
4012 case 1: *penmValue = CPUMISAEXTCFG_ENABLED_SUPPORTED; break;
4013 case 2: *penmValue = CPUMISAEXTCFG_ENABLED_ALWAYS; break;
4014 case 9: *penmValue = CPUMISAEXTCFG_ENABLED_PORTABLE; break;
4015 default:
4016 return VMSetError(pVM, VERR_CPUM_INVALID_CONFIG_VALUE, RT_SRC_POS,
4017 "Invalid config value for '/CPUM/IsaExts/%s': %llu (expected 0/'disabled', 1/'enabled', 2/'portable', or 9/'forced')",
4018 pszValueName, uValue);
4019 }
4020 /*
4021 * If missing, use default.
4022 */
4023 else if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
4024 *penmValue = enmDefault;
4025 else
4026 {
4027 if (rc == VERR_CFGM_NOT_INTEGER)
4028 {
4029 /*
4030 * Not an integer, try read it as a string.
4031 */
4032 char szValue[32];
4033 rc = CFGMR3QueryString(pIsaExts, pszValueName, szValue, sizeof(szValue));
4034 if (RT_SUCCESS(rc))
4035 {
4036 RTStrToLower(szValue);
4037 size_t cchValue = strlen(szValue);
4038#define EQ(a_str) (cchValue == sizeof(a_str) - 1U && memcmp(szValue, a_str, sizeof(a_str) - 1))
4039 if ( EQ("disabled") || EQ("disable") || EQ("off") || EQ("no"))
4040 *penmValue = CPUMISAEXTCFG_DISABLED;
4041 else if (EQ("enabled") || EQ("enable") || EQ("on") || EQ("yes"))
4042 *penmValue = CPUMISAEXTCFG_ENABLED_SUPPORTED;
4043 else if (EQ("forced") || EQ("force") || EQ("always"))
4044 *penmValue = CPUMISAEXTCFG_ENABLED_ALWAYS;
4045 else if (EQ("portable"))
4046 *penmValue = CPUMISAEXTCFG_ENABLED_PORTABLE;
4047 else if (EQ("default") || EQ("def"))
4048 *penmValue = enmDefault;
4049 else
4050 return VMSetError(pVM, VERR_CPUM_INVALID_CONFIG_VALUE, RT_SRC_POS,
4051 "Invalid config value for '/CPUM/IsaExts/%s': '%s' (expected 0/'disabled', 1/'enabled', 2/'portable', or 9/'forced')",
4052 pszValueName, uValue);
4053#undef EQ
4054 }
4055 }
4056 if (RT_FAILURE(rc))
4057 return VMSetError(pVM, rc, RT_SRC_POS, "Error reading config value '/CPUM/IsaExts/%s': %Rrc", pszValueName, rc);
4058 }
4059 return VINF_SUCCESS;
4060}
4061
4062
4063/**
4064 * Reads a value in /CPUM/IsaExts/ node, forcing it to DISABLED if wanted.
4065 *
4066 * @returns VBox status code (error message raised).
4067 * @param pVM The cross context VM structure. (For errors.)
4068 * @param pIsaExts The /CPUM/IsaExts node (can be NULL).
4069 * @param pszValueName The value / extension name.
4070 * @param penmValue Where to return the choice.
4071 * @param enmDefault The default choice.
4072 * @param fAllowed Allowed choice. Applied both to the result and to
4073 * the default value.
4074 */
4075static int cpumR3CpuIdReadIsaExtCfgEx(PVM pVM, PCFGMNODE pIsaExts, const char *pszValueName,
4076 CPUMISAEXTCFG *penmValue, CPUMISAEXTCFG enmDefault, bool fAllowed)
4077{
4078 int rc;
4079 if (fAllowed)
4080 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, pszValueName, penmValue, enmDefault);
4081 else
4082 {
4083 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, pszValueName, penmValue, false /*enmDefault*/);
4084 if (RT_SUCCESS(rc) && *penmValue == CPUMISAEXTCFG_ENABLED_ALWAYS)
4085 LogRel(("CPUM: Ignoring forced '%s'\n", pszValueName));
4086 *penmValue = CPUMISAEXTCFG_DISABLED;
4087 }
4088 return rc;
4089}
4090
4091
4092/**
4093 * Reads a value in /CPUM/IsaExts/ node that used to be located in /CPUM/.
4094 *
4095 * @returns VBox status code (error message raised).
4096 * @param pVM The cross context VM structure. (For errors.)
4097 * @param pIsaExts The /CPUM/IsaExts node (can be NULL).
4098 * @param pCpumCfg The /CPUM node (can be NULL).
4099 * @param pszValueName The value / extension name.
4100 * @param penmValue Where to return the choice.
4101 * @param enmDefault The default choice.
4102 */
4103static int cpumR3CpuIdReadIsaExtCfgLegacy(PVM pVM, PCFGMNODE pIsaExts, PCFGMNODE pCpumCfg, const char *pszValueName,
4104 CPUMISAEXTCFG *penmValue, CPUMISAEXTCFG enmDefault)
4105{
4106 if (CFGMR3Exists(pCpumCfg, pszValueName))
4107 {
4108 if (!CFGMR3Exists(pIsaExts, pszValueName))
4109 LogRel(("Warning: /CPUM/%s is deprecated, use /CPUM/IsaExts/%s instead.\n", pszValueName, pszValueName));
4110 else
4111 return VMSetError(pVM, VERR_DUPLICATE, RT_SRC_POS,
4112 "Duplicate config values '/CPUM/%s' and '/CPUM/IsaExts/%s' - please remove the former!",
4113 pszValueName, pszValueName);
4114
4115 bool fLegacy;
4116 int rc = CFGMR3QueryBoolDef(pCpumCfg, pszValueName, &fLegacy, enmDefault != CPUMISAEXTCFG_DISABLED);
4117 if (RT_SUCCESS(rc))
4118 {
4119 *penmValue = fLegacy;
4120 return VINF_SUCCESS;
4121 }
4122 return VMSetError(pVM, VERR_DUPLICATE, RT_SRC_POS, "Error querying '/CPUM/%s': %Rrc", pszValueName, rc);
4123 }
4124
4125 return cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, pszValueName, penmValue, enmDefault);
4126}
4127
4128
4129static int cpumR3CpuIdReadConfig(PVM pVM, PCPUMCPUIDCONFIG pConfig, PCFGMNODE pCpumCfg, bool fNestedPagingAndFullGuestExec)
4130{
4131 int rc;
4132
4133 /** @cfgm{/CPUM/PortableCpuIdLevel, 8-bit, 0, 3, 0}
4134 * When non-zero CPUID features that could cause portability issues will be
4135 * stripped. The higher the value the more features gets stripped. Higher
4136 * values should only be used when older CPUs are involved since it may
4137 * harm performance and maybe also cause problems with specific guests. */
4138 rc = CFGMR3QueryU8Def(pCpumCfg, "PortableCpuIdLevel", &pVM->cpum.s.u8PortableCpuIdLevel, 0);
4139 AssertLogRelRCReturn(rc, rc);
4140
4141 /** @cfgm{/CPUM/GuestCpuName, string}
4142 * The name of the CPU we're to emulate. The default is the host CPU.
4143 * Note! CPUs other than "host" one is currently unsupported. */
4144 rc = CFGMR3QueryStringDef(pCpumCfg, "GuestCpuName", pConfig->szCpuName, sizeof(pConfig->szCpuName), "host");
4145 AssertLogRelRCReturn(rc, rc);
4146
4147 /** @cfgm{/CPUM/NT4LeafLimit, boolean, false}
4148 * Limit the number of standard CPUID leaves to 0..3 to prevent NT4 from
4149 * bugchecking with MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED (0x3e).
4150 * This option corresponds somewhat to IA32_MISC_ENABLES.BOOT_NT4[bit 22].
4151 */
4152 rc = CFGMR3QueryBoolDef(pCpumCfg, "NT4LeafLimit", &pConfig->fNt4LeafLimit, false);
4153 AssertLogRelRCReturn(rc, rc);
4154
4155 /** @cfgm{/CPUM/InvariantTsc, boolean, true}
4156 * Pass-through the invariant TSC flag in 0x80000007 if available on the host
4157 * CPU. On AMD CPUs, users may wish to suppress it to avoid trouble from older
4158 * 64-bit linux guests which assume the presence of AMD performance counters
4159 * that we do not virtualize.
4160 */
4161 rc = CFGMR3QueryBoolDef(pCpumCfg, "InvariantTsc", &pConfig->fInvariantTsc, true);
4162 AssertLogRelRCReturn(rc, rc);
4163
4164 /** @cfgm{/CPUM/ForceVme, boolean, false}
4165 * Always expose the VME (Virtual-8086 Mode Extensions) capability if true.
4166 * By default the flag is passed thru as is from the host CPU, except
4167 * on AMD Ryzen CPUs where it's masked to avoid trouble with XP/Server 2003
4168 * guests and DOS boxes in general.
4169 */
4170 rc = CFGMR3QueryBoolDef(pCpumCfg, "ForceVme", &pConfig->fForceVme, false);
4171 AssertLogRelRCReturn(rc, rc);
4172
4173 /** @cfgm{/CPUM/MaxIntelFamilyModelStep, uint32_t, UINT32_MAX}
4174 * Restrict the reported CPU family+model+stepping of intel CPUs. This is
4175 * probably going to be a temporary hack, so don't depend on this.
4176 * The 1st byte of the value is the stepping, the 2nd byte value is the model
4177 * number and the 3rd byte value is the family, and the 4th value must be zero.
4178 */
4179 rc = CFGMR3QueryU32Def(pCpumCfg, "MaxIntelFamilyModelStep", &pConfig->uMaxIntelFamilyModelStep, UINT32_MAX);
4180 AssertLogRelRCReturn(rc, rc);
4181
4182 /** @cfgm{/CPUM/MaxStdLeaf, uint32_t, 0x00000016}
4183 * The last standard leaf to keep. The actual last value that is stored in EAX
4184 * is RT_MAX(CPUID[0].EAX,/CPUM/MaxStdLeaf). Leaves beyond the max leaf are
4185 * removed. (This works independently of and differently from NT4LeafLimit.)
4186 * The default is usually set to what we're able to reasonably sanitize.
4187 */
4188 rc = CFGMR3QueryU32Def(pCpumCfg, "MaxStdLeaf", &pConfig->uMaxStdLeaf, UINT32_C(0x00000016));
4189 AssertLogRelRCReturn(rc, rc);
4190
4191 /** @cfgm{/CPUM/MaxExtLeaf, uint32_t, 0x8000001e}
4192 * The last extended leaf to keep. The actual last value that is stored in EAX
4193 * is RT_MAX(CPUID[0x80000000].EAX,/CPUM/MaxStdLeaf). Leaves beyond the max
4194 * leaf are removed. The default is set to what we're able to sanitize.
4195 */
4196 rc = CFGMR3QueryU32Def(pCpumCfg, "MaxExtLeaf", &pConfig->uMaxExtLeaf, UINT32_C(0x8000001e));
4197 AssertLogRelRCReturn(rc, rc);
4198
4199 /** @cfgm{/CPUM/MaxCentaurLeaf, uint32_t, 0xc0000004}
4200 * The last extended leaf to keep. The actual last value that is stored in EAX
4201 * is RT_MAX(CPUID[0xc0000000].EAX,/CPUM/MaxCentaurLeaf). Leaves beyond the max
4202 * leaf are removed. The default is set to what we're able to sanitize.
4203 */
4204 rc = CFGMR3QueryU32Def(pCpumCfg, "MaxCentaurLeaf", &pConfig->uMaxCentaurLeaf, UINT32_C(0xc0000004));
4205 AssertLogRelRCReturn(rc, rc);
4206
4207 bool fQueryNestedHwvirt = false
4208#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
4209 || pVM->cpum.s.HostFeatures.enmCpuVendor == CPUMCPUVENDOR_AMD
4210 || pVM->cpum.s.HostFeatures.enmCpuVendor == CPUMCPUVENDOR_HYGON
4211#endif
4212#ifdef VBOX_WITH_NESTED_HWVIRT_VMX
4213 || pVM->cpum.s.HostFeatures.enmCpuVendor == CPUMCPUVENDOR_INTEL
4214 || pVM->cpum.s.HostFeatures.enmCpuVendor == CPUMCPUVENDOR_VIA
4215#endif
4216 ;
4217 if (fQueryNestedHwvirt)
4218 {
4219 /** @cfgm{/CPUM/NestedHWVirt, bool, false}
4220 * Whether to expose the hardware virtualization (VMX/SVM) feature to the guest.
4221 * The default is false, and when enabled requires a 64-bit CPU with support for
4222 * nested-paging and AMD-V or unrestricted guest mode.
4223 */
4224 rc = CFGMR3QueryBoolDef(pCpumCfg, "NestedHWVirt", &pConfig->fNestedHWVirt, false);
4225 AssertLogRelRCReturn(rc, rc);
4226 if (pConfig->fNestedHWVirt)
4227 {
4228 /** @todo Think about enabling this later with NEM/KVM. */
4229 if (VM_IS_NEM_ENABLED(pVM))
4230 {
4231 LogRel(("CPUM: WARNING! Can't turn on nested VT-x/AMD-V when NEM is used! (later)\n"));
4232 pConfig->fNestedHWVirt = false;
4233 }
4234 else if (!fNestedPagingAndFullGuestExec)
4235 return VMSetError(pVM, VERR_CPUM_INVALID_HWVIRT_CONFIG, RT_SRC_POS,
4236 "Cannot enable nested VT-x/AMD-V without nested-paging and unrestricted guest execution!\n");
4237 }
4238
4239 if (pConfig->fNestedHWVirt)
4240 {
4241 /** @cfgm{/CPUM/NestedVmxPreemptTimer, bool, true}
4242 * Whether to expose the VMX-preemption timer feature to the guest (if also
4243 * supported by the host hardware). When disabled will prevent exposing the
4244 * VMX-preemption timer feature to the guest even if the host supports it.
4245 *
4246 * @todo Currently disabled, see @bugref{9180#c108}.
4247 */
4248 rc = CFGMR3QueryBoolDef(pCpumCfg, "NestedVmxPreemptTimer", &pVM->cpum.s.fNestedVmxPreemptTimer, false);
4249 AssertLogRelRCReturn(rc, rc);
4250
4251 /** @cfgm{/CPUM/NestedVmxEpt, bool, true}
4252 * Whether to expose the EPT feature to the guest. The default is false. When
4253 * disabled will automatically prevent exposing features that rely on
4254 */
4255 rc = CFGMR3QueryBoolDef(pCpumCfg, "NestedVmxEpt", &pVM->cpum.s.fNestedVmxEpt, false);
4256 AssertLogRelRCReturn(rc, rc);
4257
4258 /** @cfgm{/CPUM/NestedVmxUnrestrictedGuest, bool, true}
4259 * Whether to expose the Unrestricted Guest feature to the guest. The default is
4260 * false. When disabled will automatically prevent exposing features that rely on
4261 * it.
4262 */
4263 rc = CFGMR3QueryBoolDef(pCpumCfg, "NestedVmxUnrestrictedGuest", &pVM->cpum.s.fNestedVmxUnrestrictedGuest, false);
4264 AssertLogRelRCReturn(rc, rc);
4265
4266 if ( pVM->cpum.s.fNestedVmxUnrestrictedGuest
4267 && !pVM->cpum.s.fNestedVmxEpt)
4268 {
4269 LogRel(("CPUM: WARNING! Can't expose \"Unrestricted Guest\" to the guest when EPT is not exposed!\n"));
4270 pVM->cpum.s.fNestedVmxUnrestrictedGuest = false;
4271 }
4272 }
4273 }
4274
4275 /*
4276 * Instruction Set Architecture (ISA) Extensions.
4277 */
4278 PCFGMNODE pIsaExts = CFGMR3GetChild(pCpumCfg, "IsaExts");
4279 if (pIsaExts)
4280 {
4281 rc = CFGMR3ValidateConfig(pIsaExts, "/CPUM/IsaExts/",
4282 "CMPXCHG16B"
4283 "|MONITOR"
4284 "|MWaitExtensions"
4285 "|SSE4.1"
4286 "|SSE4.2"
4287 "|XSAVE"
4288 "|AVX"
4289 "|AVX2"
4290 "|AESNI"
4291 "|PCLMUL"
4292 "|POPCNT"
4293 "|MOVBE"
4294 "|RDRAND"
4295 "|RDSEED"
4296 "|CLFLUSHOPT"
4297 "|FSGSBASE"
4298 "|PCID"
4299 "|INVPCID"
4300 "|FlushCmdMsr"
4301 "|ABM"
4302 "|SSE4A"
4303 "|MISALNSSE"
4304 "|3DNOWPRF"
4305 "|AXMMX"
4306 , "" /*pszValidNodes*/, "CPUM" /*pszWho*/, 0 /*uInstance*/);
4307 if (RT_FAILURE(rc))
4308 return rc;
4309 }
4310
4311 /** @cfgm{/CPUM/IsaExts/CMPXCHG16B, boolean, true}
4312 * Expose CMPXCHG16B to the guest if available. All host CPUs which support
4313 * hardware virtualization have it.
4314 */
4315 rc = cpumR3CpuIdReadIsaExtCfgLegacy(pVM, pIsaExts, pCpumCfg, "CMPXCHG16B", &pConfig->enmCmpXchg16b, true);
4316 AssertLogRelRCReturn(rc, rc);
4317
4318 /** @cfgm{/CPUM/IsaExts/MONITOR, boolean, true}
4319 * Expose MONITOR/MWAIT instructions to the guest.
4320 */
4321 rc = cpumR3CpuIdReadIsaExtCfgLegacy(pVM, pIsaExts, pCpumCfg, "MONITOR", &pConfig->enmMonitor, true);
4322 AssertLogRelRCReturn(rc, rc);
4323
4324 /** @cfgm{/CPUM/IsaExts/MWaitExtensions, boolean, false}
4325 * Expose MWAIT extended features to the guest. For now we expose just MWAIT
4326 * break on interrupt feature (bit 1).
4327 */
4328 rc = cpumR3CpuIdReadIsaExtCfgLegacy(pVM, pIsaExts, pCpumCfg, "MWaitExtensions", &pConfig->enmMWaitExtensions, false);
4329 AssertLogRelRCReturn(rc, rc);
4330
4331 /** @cfgm{/CPUM/IsaExts/SSE4.1, boolean, true}
4332 * Expose SSE4.1 to the guest if available.
4333 */
4334 rc = cpumR3CpuIdReadIsaExtCfgLegacy(pVM, pIsaExts, pCpumCfg, "SSE4.1", &pConfig->enmSse41, true);
4335 AssertLogRelRCReturn(rc, rc);
4336
4337 /** @cfgm{/CPUM/IsaExts/SSE4.2, boolean, true}
4338 * Expose SSE4.2 to the guest if available.
4339 */
4340 rc = cpumR3CpuIdReadIsaExtCfgLegacy(pVM, pIsaExts, pCpumCfg, "SSE4.2", &pConfig->enmSse42, true);
4341 AssertLogRelRCReturn(rc, rc);
4342
4343 bool const fMayHaveXSave = pVM->cpum.s.HostFeatures.fXSaveRstor
4344 && pVM->cpum.s.HostFeatures.fOpSysXSaveRstor
4345 && ( !VM_IS_NEM_ENABLED(pVM)
4346 ? fNestedPagingAndFullGuestExec
4347 : NEMHCGetFeatures(pVM) & NEM_FEAT_F_XSAVE_XRSTOR);
4348 uint64_t const fXStateHostMask = pVM->cpum.s.fXStateHostMask;
4349
4350 /** @cfgm{/CPUM/IsaExts/XSAVE, boolean, depends}
4351 * Expose XSAVE/XRSTOR to the guest if available. For the time being the
4352 * default is to only expose this to VMs with nested paging and AMD-V or
4353 * unrestricted guest execution mode. Not possible to force this one without
4354 * host support at the moment.
4355 */
4356 rc = cpumR3CpuIdReadIsaExtCfgEx(pVM, pIsaExts, "XSAVE", &pConfig->enmXSave, fNestedPagingAndFullGuestExec,
4357 fMayHaveXSave /*fAllowed*/);
4358 AssertLogRelRCReturn(rc, rc);
4359
4360 /** @cfgm{/CPUM/IsaExts/AVX, boolean, depends}
4361 * Expose the AVX instruction set extensions to the guest if available and
4362 * XSAVE is exposed too. For the time being the default is to only expose this
4363 * to VMs with nested paging and AMD-V or unrestricted guest execution mode.
4364 */
4365 rc = cpumR3CpuIdReadIsaExtCfgEx(pVM, pIsaExts, "AVX", &pConfig->enmAvx, fNestedPagingAndFullGuestExec,
4366 fMayHaveXSave && pConfig->enmXSave && (fXStateHostMask & XSAVE_C_YMM) /*fAllowed*/);
4367 AssertLogRelRCReturn(rc, rc);
4368
4369 /** @cfgm{/CPUM/IsaExts/AVX2, boolean, depends}
4370 * Expose the AVX2 instruction set extensions to the guest if available and
4371 * XSAVE is exposed too. For the time being the default is to only expose this
4372 * to VMs with nested paging and AMD-V or unrestricted guest execution mode.
4373 */
4374 rc = cpumR3CpuIdReadIsaExtCfgEx(pVM, pIsaExts, "AVX2", &pConfig->enmAvx2, fNestedPagingAndFullGuestExec /* temporarily */,
4375 fMayHaveXSave && pConfig->enmXSave && (fXStateHostMask & XSAVE_C_YMM) /*fAllowed*/);
4376 AssertLogRelRCReturn(rc, rc);
4377
4378 /** @cfgm{/CPUM/IsaExts/AESNI, isaextcfg, depends}
4379 * Whether to expose the AES instructions to the guest. For the time being the
4380 * default is to only do this for VMs with nested paging and AMD-V or
4381 * unrestricted guest mode.
4382 */
4383 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "AESNI", &pConfig->enmAesNi, fNestedPagingAndFullGuestExec);
4384 AssertLogRelRCReturn(rc, rc);
4385
4386 /** @cfgm{/CPUM/IsaExts/PCLMUL, isaextcfg, depends}
4387 * Whether to expose the PCLMULQDQ instructions to the guest. For the time
4388 * being the default is to only do this for VMs with nested paging and AMD-V or
4389 * unrestricted guest mode.
4390 */
4391 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "PCLMUL", &pConfig->enmPClMul, fNestedPagingAndFullGuestExec);
4392 AssertLogRelRCReturn(rc, rc);
4393
4394 /** @cfgm{/CPUM/IsaExts/POPCNT, isaextcfg, depends}
4395 * Whether to expose the POPCNT instructions to the guest. For the time
4396 * being the default is to only do this for VMs with nested paging and AMD-V or
4397 * unrestricted guest mode.
4398 */
4399 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "POPCNT", &pConfig->enmPopCnt, fNestedPagingAndFullGuestExec);
4400 AssertLogRelRCReturn(rc, rc);
4401
4402 /** @cfgm{/CPUM/IsaExts/MOVBE, isaextcfg, depends}
4403 * Whether to expose the MOVBE instructions to the guest. For the time
4404 * being the default is to only do this for VMs with nested paging and AMD-V or
4405 * unrestricted guest mode.
4406 */
4407 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "MOVBE", &pConfig->enmMovBe, fNestedPagingAndFullGuestExec);
4408 AssertLogRelRCReturn(rc, rc);
4409
4410 /** @cfgm{/CPUM/IsaExts/RDRAND, isaextcfg, depends}
4411 * Whether to expose the RDRAND instructions to the guest. For the time being
4412 * the default is to only do this for VMs with nested paging and AMD-V or
4413 * unrestricted guest mode.
4414 */
4415 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "RDRAND", &pConfig->enmRdRand, fNestedPagingAndFullGuestExec);
4416 AssertLogRelRCReturn(rc, rc);
4417
4418 /** @cfgm{/CPUM/IsaExts/RDSEED, isaextcfg, depends}
4419 * Whether to expose the RDSEED instructions to the guest. For the time being
4420 * the default is to only do this for VMs with nested paging and AMD-V or
4421 * unrestricted guest mode.
4422 */
4423 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "RDSEED", &pConfig->enmRdSeed, fNestedPagingAndFullGuestExec);
4424 AssertLogRelRCReturn(rc, rc);
4425
4426 /** @cfgm{/CPUM/IsaExts/CLFLUSHOPT, isaextcfg, depends}
4427 * Whether to expose the CLFLUSHOPT instructions to the guest. For the time
4428 * being the default is to only do this for VMs with nested paging and AMD-V or
4429 * unrestricted guest mode.
4430 */
4431 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "CLFLUSHOPT", &pConfig->enmCLFlushOpt, fNestedPagingAndFullGuestExec);
4432 AssertLogRelRCReturn(rc, rc);
4433
4434 /** @cfgm{/CPUM/IsaExts/FSGSBASE, isaextcfg, true}
4435 * Whether to expose the read/write FSGSBASE instructions to the guest.
4436 */
4437 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "FSGSBASE", &pConfig->enmFsGsBase, true);
4438 AssertLogRelRCReturn(rc, rc);
4439
4440 /** @cfgm{/CPUM/IsaExts/PCID, isaextcfg, true}
4441 * Whether to expose the PCID feature to the guest.
4442 */
4443 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "PCID", &pConfig->enmPcid, pConfig->enmFsGsBase);
4444 AssertLogRelRCReturn(rc, rc);
4445
4446 /** @cfgm{/CPUM/IsaExts/INVPCID, isaextcfg, true}
4447 * Whether to expose the INVPCID instruction to the guest.
4448 */
4449 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "INVPCID", &pConfig->enmInvpcid, pConfig->enmFsGsBase);
4450 AssertLogRelRCReturn(rc, rc);
4451
4452 /** @cfgm{/CPUM/IsaExts/FlushCmdMsr, isaextcfg, true}
4453 * Whether to expose the IA32_FLUSH_CMD MSR to the guest.
4454 */
4455 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "FlushCmdMsr", &pConfig->enmFlushCmdMsr, CPUMISAEXTCFG_ENABLED_SUPPORTED);
4456 AssertLogRelRCReturn(rc, rc);
4457
4458 /** @cfgm{/CPUM/IsaExts/MdsClear, isaextcfg, true}
4459 * Whether to advertise the VERW and MDS related IA32_FLUSH_CMD MSR bits to
4460 * the guest. Requires FlushCmdMsr to be present too.
4461 */
4462 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "MdsClear", &pConfig->enmMdsClear, CPUMISAEXTCFG_ENABLED_SUPPORTED);
4463 AssertLogRelRCReturn(rc, rc);
4464
4465 /** @cfgm{/CPUM/IsaExts/ArchCapMSr, isaextcfg, true}
4466 * Whether to expose the MSR_IA32_ARCH_CAPABILITIES MSR to the guest.
4467 */
4468 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "ArchCapMsr", &pConfig->enmArchCapMsr, CPUMISAEXTCFG_ENABLED_SUPPORTED);
4469 AssertLogRelRCReturn(rc, rc);
4470
4471
4472 /* AMD: */
4473
4474 /** @cfgm{/CPUM/IsaExts/ABM, isaextcfg, depends}
4475 * Whether to expose the AMD ABM instructions to the guest. For the time
4476 * being the default is to only do this for VMs with nested paging and AMD-V or
4477 * unrestricted guest mode.
4478 */
4479 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "ABM", &pConfig->enmAbm, fNestedPagingAndFullGuestExec);
4480 AssertLogRelRCReturn(rc, rc);
4481
4482 /** @cfgm{/CPUM/IsaExts/SSE4A, isaextcfg, depends}
4483 * Whether to expose the AMD SSE4A instructions to the guest. For the time
4484 * being the default is to only do this for VMs with nested paging and AMD-V or
4485 * unrestricted guest mode.
4486 */
4487 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "SSE4A", &pConfig->enmSse4A, fNestedPagingAndFullGuestExec);
4488 AssertLogRelRCReturn(rc, rc);
4489
4490 /** @cfgm{/CPUM/IsaExts/MISALNSSE, isaextcfg, depends}
4491 * Whether to expose the AMD MisAlSse feature (MXCSR flag 17) to the guest. For
4492 * the time being the default is to only do this for VMs with nested paging and
4493 * AMD-V or unrestricted guest mode.
4494 */
4495 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "MISALNSSE", &pConfig->enmMisAlnSse, fNestedPagingAndFullGuestExec);
4496 AssertLogRelRCReturn(rc, rc);
4497
4498 /** @cfgm{/CPUM/IsaExts/3DNOWPRF, isaextcfg, depends}
4499 * Whether to expose the AMD 3D Now! prefetch instructions to the guest.
4500 * For the time being the default is to only do this for VMs with nested paging
4501 * and AMD-V or unrestricted guest mode.
4502 */
4503 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "3DNOWPRF", &pConfig->enm3dNowPrf, fNestedPagingAndFullGuestExec);
4504 AssertLogRelRCReturn(rc, rc);
4505
4506 /** @cfgm{/CPUM/IsaExts/AXMMX, isaextcfg, depends}
4507 * Whether to expose the AMD's MMX Extensions to the guest. For the time being
4508 * the default is to only do this for VMs with nested paging and AMD-V or
4509 * unrestricted guest mode.
4510 */
4511 rc = cpumR3CpuIdReadIsaExtCfg(pVM, pIsaExts, "AXMMX", &pConfig->enmAmdExtMmx, fNestedPagingAndFullGuestExec);
4512 AssertLogRelRCReturn(rc, rc);
4513
4514 return VINF_SUCCESS;
4515}
4516
4517
4518/**
4519 * Initializes the emulated CPU's CPUID & MSR information.
4520 *
4521 * @returns VBox status code.
4522 * @param pVM The cross context VM structure.
4523 * @param pHostMsrs Pointer to the host MSRs.
4524 */
4525int cpumR3InitCpuIdAndMsrs(PVM pVM, PCCPUMMSRS pHostMsrs)
4526{
4527 Assert(pHostMsrs);
4528
4529 PCPUM pCpum = &pVM->cpum.s;
4530 PCFGMNODE pCpumCfg = CFGMR3GetChild(CFGMR3GetRoot(pVM), "CPUM");
4531
4532 /*
4533 * Set the fCpuIdApicFeatureVisible flags so the APIC can assume visibility
4534 * on construction and manage everything from here on.
4535 */
4536 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
4537 {
4538 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
4539 pVCpu->cpum.s.fCpuIdApicFeatureVisible = true;
4540 }
4541
4542 /*
4543 * Read the configuration.
4544 */
4545 CPUMCPUIDCONFIG Config;
4546 RT_ZERO(Config);
4547
4548 bool const fNestedPagingAndFullGuestExec = VM_IS_NEM_ENABLED(pVM) || HMAreNestedPagingAndFullGuestExecEnabled(pVM);
4549 int rc = cpumR3CpuIdReadConfig(pVM, &Config, pCpumCfg, fNestedPagingAndFullGuestExec);
4550 AssertRCReturn(rc, rc);
4551
4552 /*
4553 * Get the guest CPU data from the database and/or the host.
4554 *
4555 * The CPUID and MSRs are currently living on the regular heap to avoid
4556 * fragmenting the hyper heap (and because there isn't/wasn't any realloc
4557 * API for the hyper heap). This means special cleanup considerations.
4558 */
4559 /** @todo The hyper heap will be removed ASAP, so the final destination is
4560 * now a fixed sized arrays in the VM structure. Maybe we can simplify
4561 * this allocation fun a little now? Or maybe it's too convenient for
4562 * the CPU reporter code... No time to figure that out now. */
4563 rc = cpumR3DbGetCpuInfo(Config.szCpuName, &pCpum->GuestInfo);
4564 if (RT_FAILURE(rc))
4565 return rc == VERR_CPUM_DB_CPU_NOT_FOUND
4566 ? VMSetError(pVM, rc, RT_SRC_POS,
4567 "Info on guest CPU '%s' could not be found. Please, select a different CPU.", Config.szCpuName)
4568 : rc;
4569
4570 if (pCpum->GuestInfo.fMxCsrMask & ~pVM->cpum.s.fHostMxCsrMask)
4571 {
4572 LogRel(("Stripping unsupported MXCSR bits from guest mask: %#x -> %#x (host: %#x)\n", pCpum->GuestInfo.fMxCsrMask,
4573 pCpum->GuestInfo.fMxCsrMask & pVM->cpum.s.fHostMxCsrMask, pVM->cpum.s.fHostMxCsrMask));
4574 pCpum->GuestInfo.fMxCsrMask &= pVM->cpum.s.fHostMxCsrMask;
4575 }
4576 LogRel(("CPUM: MXCSR_MASK=%#x (host: %#x)\n", pCpum->GuestInfo.fMxCsrMask, pVM->cpum.s.fHostMxCsrMask));
4577
4578 /** @cfgm{/CPUM/MSRs/[Name]/[First|Last|Type|Value|...],}
4579 * Overrides the guest MSRs.
4580 */
4581 rc = cpumR3LoadMsrOverrides(pVM, CFGMR3GetChild(pCpumCfg, "MSRs"));
4582
4583 /** @cfgm{/CPUM/HostCPUID/[000000xx|800000xx|c000000x]/[eax|ebx|ecx|edx],32-bit}
4584 * Overrides the CPUID leaf values (from the host CPU usually) used for
4585 * calculating the guest CPUID leaves. This can be used to preserve the CPUID
4586 * values when moving a VM to a different machine. Another use is restricting
4587 * (or extending) the feature set exposed to the guest. */
4588 if (RT_SUCCESS(rc))
4589 rc = cpumR3LoadCpuIdOverrides(pVM, CFGMR3GetChild(pCpumCfg, "HostCPUID"), "HostCPUID");
4590
4591 if (RT_SUCCESS(rc) && CFGMR3GetChild(pCpumCfg, "CPUID")) /* 2nd override, now discontinued. */
4592 rc = VMSetError(pVM, VERR_CFGM_CONFIG_UNKNOWN_NODE, RT_SRC_POS,
4593 "Found unsupported configuration node '/CPUM/CPUID/'. "
4594 "Please use IMachine::setCPUIDLeaf() instead.");
4595
4596 CPUMMSRS GuestMsrs;
4597 RT_ZERO(GuestMsrs);
4598
4599 /*
4600 * Pre-explode the CPUID info.
4601 */
4602 if (RT_SUCCESS(rc))
4603 rc = cpumR3CpuIdExplodeFeatures(pCpum->GuestInfo.paCpuIdLeavesR3, pCpum->GuestInfo.cCpuIdLeaves, &GuestMsrs,
4604 &pCpum->GuestFeatures);
4605
4606 /*
4607 * Sanitize the cpuid information passed on to the guest.
4608 */
4609 if (RT_SUCCESS(rc))
4610 {
4611 rc = cpumR3CpuIdSanitize(pVM, pCpum, &Config);
4612 if (RT_SUCCESS(rc))
4613 {
4614 cpumR3CpuIdLimitLeaves(pCpum, &Config);
4615 cpumR3CpuIdLimitIntelFamModStep(pCpum, &Config);
4616 }
4617 }
4618
4619 /*
4620 * Setup MSRs introduced in microcode updates or that are otherwise not in
4621 * the CPU profile, but are advertised in the CPUID info we just sanitized.
4622 */
4623 if (RT_SUCCESS(rc))
4624 rc = cpumR3MsrReconcileWithCpuId(pVM);
4625 /*
4626 * MSR fudging.
4627 */
4628 if (RT_SUCCESS(rc))
4629 {
4630 /** @cfgm{/CPUM/FudgeMSRs, boolean, true}
4631 * Fudges some common MSRs if not present in the selected CPU database entry.
4632 * This is for trying to keep VMs running when moved between different hosts
4633 * and different CPU vendors. */
4634 bool fEnable;
4635 rc = CFGMR3QueryBoolDef(pCpumCfg, "FudgeMSRs", &fEnable, true); AssertRC(rc);
4636 if (RT_SUCCESS(rc) && fEnable)
4637 {
4638 rc = cpumR3MsrApplyFudge(pVM);
4639 AssertLogRelRC(rc);
4640 }
4641 }
4642 if (RT_SUCCESS(rc))
4643 {
4644 /*
4645 * Move the MSR and CPUID arrays over to the static VM structure allocations
4646 * and explode guest CPU features again.
4647 */
4648 void *pvFree = pCpum->GuestInfo.paCpuIdLeavesR3;
4649 rc = cpumR3CpuIdInstallAndExplodeLeaves(pVM, pCpum, pCpum->GuestInfo.paCpuIdLeavesR3,
4650 pCpum->GuestInfo.cCpuIdLeaves, &GuestMsrs);
4651 RTMemFree(pvFree);
4652
4653 AssertFatalMsg(pCpum->GuestInfo.cMsrRanges <= RT_ELEMENTS(pCpum->GuestInfo.aMsrRanges),
4654 ("%u\n", pCpum->GuestInfo.cMsrRanges));
4655 memcpy(pCpum->GuestInfo.aMsrRanges, pCpum->GuestInfo.paMsrRangesR3,
4656 sizeof(pCpum->GuestInfo.paMsrRangesR3[0]) * pCpum->GuestInfo.cMsrRanges);
4657 RTMemFree(pCpum->GuestInfo.paMsrRangesR3);
4658 pCpum->GuestInfo.paMsrRangesR3 = pCpum->GuestInfo.aMsrRanges;
4659
4660 AssertLogRelRCReturn(rc, rc);
4661
4662 /*
4663 * Finally, initialize guest VMX MSRs.
4664 *
4665 * This needs to be done -after- exploding guest features and sanitizing CPUID leaves
4666 * as constructing VMX capabilities MSRs rely on CPU feature bits like long mode,
4667 * unrestricted-guest execution, CR4 feature bits and possibly more in the future.
4668 */
4669 if (pVM->cpum.s.GuestFeatures.fVmx)
4670 {
4671 Assert(Config.fNestedHWVirt);
4672 cpumR3InitVmxGuestFeaturesAndMsrs(pVM, &pHostMsrs->hwvirt.vmx, &GuestMsrs.hwvirt.vmx);
4673
4674 /* Copy MSRs to all VCPUs */
4675 PCVMXMSRS pVmxMsrs = &GuestMsrs.hwvirt.vmx;
4676 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
4677 {
4678 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
4679 memcpy(&pVCpu->cpum.s.Guest.hwvirt.vmx.Msrs, pVmxMsrs, sizeof(*pVmxMsrs));
4680 }
4681 }
4682
4683 /*
4684 * Some more configuration that we're applying at the end of everything
4685 * via the CPUMR3SetGuestCpuIdFeature API.
4686 */
4687
4688 /* Check if PAE was explicitely enabled by the user. */
4689 bool fEnable;
4690 rc = CFGMR3QueryBoolDef(CFGMR3GetRoot(pVM), "EnablePAE", &fEnable, false);
4691 AssertRCReturn(rc, rc);
4692 if (fEnable)
4693 CPUMR3SetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_PAE);
4694
4695 /* We don't normally enable NX for raw-mode, so give the user a chance to force it on. */
4696 rc = CFGMR3QueryBoolDef(pCpumCfg, "EnableNX", &fEnable, false);
4697 AssertRCReturn(rc, rc);
4698 if (fEnable)
4699 CPUMR3SetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_NX);
4700
4701 /* Check if speculation control is enabled. */
4702 rc = CFGMR3QueryBoolDef(pCpumCfg, "SpecCtrl", &fEnable, false);
4703 AssertRCReturn(rc, rc);
4704 if (fEnable)
4705 CPUMR3SetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_SPEC_CTRL);
4706 else
4707 {
4708 /*
4709 * Set the "SSBD-not-needed" flag to work around a bug in some Linux kernels when the VIRT_SPEC_CTL
4710 * feature is not exposed on AMD CPUs and there is only 1 vCPU configured.
4711 * This was observed with kernel "4.15.0-29-generic #31~16.04.1-Ubuntu" but more versions are likely affected.
4712 *
4713 * The kernel doesn't initialize a lock and causes a NULL pointer exception later on when configuring SSBD:
4714 * EIP: _raw_spin_lock+0x14/0x30
4715 * EFLAGS: 00010046 CPU: 0
4716 * EAX: 00000000 EBX: 00000001 ECX: 00000004 EDX: 00000000
4717 * ESI: 00000000 EDI: 00000000 EBP: ee023f1c ESP: ee023f18
4718 * DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
4719 * CR0: 80050033 CR2: 00000004 CR3: 3671c180 CR4: 000006f0
4720 * Call Trace:
4721 * speculative_store_bypass_update+0x8e/0x180
4722 * ssb_prctl_set+0xc0/0xe0
4723 * arch_seccomp_spec_mitigate+0x1d/0x20
4724 * do_seccomp+0x3cb/0x610
4725 * SyS_seccomp+0x16/0x20
4726 * do_fast_syscall_32+0x7f/0x1d0
4727 * entry_SYSENTER_32+0x4e/0x7c
4728 *
4729 * The lock would've been initialized in process.c:speculative_store_bypass_ht_init() called from two places in smpboot.c.
4730 * First when a secondary CPU is started and second in native_smp_prepare_cpus() which is not called in a single vCPU environment.
4731 *
4732 * As spectre control features are completely disabled anyway when we arrived here there is no harm done in informing the
4733 * guest to not even try.
4734 */
4735 if ( pVM->cpum.s.GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_AMD
4736 || pVM->cpum.s.GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_HYGON)
4737 {
4738 PCPUMCPUIDLEAF pLeaf = cpumR3CpuIdGetExactLeaf(&pVM->cpum.s, UINT32_C(0x80000008), 0);
4739 if (pLeaf)
4740 {
4741 pLeaf->uEbx |= X86_CPUID_AMD_EFEID_EBX_NO_SSBD_REQUIRED;
4742 LogRel(("CPUM: Set SSBD not required flag for AMD to work around some buggy Linux kernels!\n"));
4743 }
4744 }
4745 }
4746
4747 return VINF_SUCCESS;
4748 }
4749
4750 /*
4751 * Failed before switching to hyper heap.
4752 */
4753 RTMemFree(pCpum->GuestInfo.paCpuIdLeavesR3);
4754 pCpum->GuestInfo.paCpuIdLeavesR3 = NULL;
4755 RTMemFree(pCpum->GuestInfo.paMsrRangesR3);
4756 pCpum->GuestInfo.paMsrRangesR3 = NULL;
4757 return rc;
4758}
4759
4760
4761/**
4762 * Sets a CPUID feature bit during VM initialization.
4763 *
4764 * Since the CPUID feature bits are generally related to CPU features, other
4765 * CPUM configuration like MSRs can also be modified by calls to this API.
4766 *
4767 * @param pVM The cross context VM structure.
4768 * @param enmFeature The feature to set.
4769 */
4770VMMR3_INT_DECL(void) CPUMR3SetGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature)
4771{
4772 PCPUMCPUIDLEAF pLeaf;
4773 PCPUMMSRRANGE pMsrRange;
4774
4775 switch (enmFeature)
4776 {
4777 /*
4778 * Set the APIC bit in both feature masks.
4779 */
4780 case CPUMCPUIDFEATURE_APIC:
4781 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x00000001));
4782 if (pLeaf && (pLeaf->fFlags & CPUMCPUIDLEAF_F_CONTAINS_APIC))
4783 pVM->cpum.s.aGuestCpuIdPatmStd[1].uEdx = pLeaf->uEdx |= X86_CPUID_FEATURE_EDX_APIC;
4784
4785 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
4786 if (pLeaf && (pLeaf->fFlags & CPUMCPUIDLEAF_F_CONTAINS_APIC))
4787 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx |= X86_CPUID_AMD_FEATURE_EDX_APIC;
4788
4789 pVM->cpum.s.GuestFeatures.fApic = 1;
4790
4791 /* Make sure we've got the APICBASE MSR present. */
4792 pMsrRange = cpumLookupMsrRange(pVM, MSR_IA32_APICBASE);
4793 if (!pMsrRange)
4794 {
4795 static CPUMMSRRANGE const s_ApicBase =
4796 {
4797 /*.uFirst =*/ MSR_IA32_APICBASE, /*.uLast =*/ MSR_IA32_APICBASE,
4798 /*.enmRdFn =*/ kCpumMsrRdFn_Ia32ApicBase, /*.enmWrFn =*/ kCpumMsrWrFn_Ia32ApicBase,
4799 /*.offCpumCpu =*/ UINT16_MAX, /*.fReserved =*/ 0, /*.uValue =*/ 0, /*.fWrIgnMask =*/ 0, /*.fWrGpMask =*/ 0,
4800 /*.szName = */ "IA32_APIC_BASE"
4801 };
4802 int rc = CPUMR3MsrRangesInsert(pVM, &s_ApicBase);
4803 AssertLogRelRC(rc);
4804 }
4805
4806 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled xAPIC\n"));
4807 break;
4808
4809 /*
4810 * Set the x2APIC bit in the standard feature mask.
4811 * Note! ASSUMES CPUMCPUIDFEATURE_APIC is called first.
4812 */
4813 case CPUMCPUIDFEATURE_X2APIC:
4814 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x00000001));
4815 if (pLeaf)
4816 pVM->cpum.s.aGuestCpuIdPatmStd[1].uEcx = pLeaf->uEcx |= X86_CPUID_FEATURE_ECX_X2APIC;
4817 pVM->cpum.s.GuestFeatures.fX2Apic = 1;
4818
4819 /* Make sure the MSR doesn't GP or ignore the EXTD bit. */
4820 pMsrRange = cpumLookupMsrRange(pVM, MSR_IA32_APICBASE);
4821 if (pMsrRange)
4822 {
4823 pMsrRange->fWrGpMask &= ~MSR_IA32_APICBASE_EXTD;
4824 pMsrRange->fWrIgnMask &= ~MSR_IA32_APICBASE_EXTD;
4825 }
4826
4827 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled x2APIC\n"));
4828 break;
4829
4830 /*
4831 * Set the sysenter/sysexit bit in the standard feature mask.
4832 * Assumes the caller knows what it's doing! (host must support these)
4833 */
4834 case CPUMCPUIDFEATURE_SEP:
4835 if (!pVM->cpum.s.HostFeatures.fSysEnter)
4836 {
4837 AssertMsgFailed(("ERROR: Can't turn on SEP when the host doesn't support it!!\n"));
4838 return;
4839 }
4840
4841 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x00000001));
4842 if (pLeaf)
4843 pVM->cpum.s.aGuestCpuIdPatmStd[1].uEdx = pLeaf->uEdx |= X86_CPUID_FEATURE_EDX_SEP;
4844 pVM->cpum.s.GuestFeatures.fSysEnter = 1;
4845 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled SYSENTER/EXIT\n"));
4846 break;
4847
4848 /*
4849 * Set the syscall/sysret bit in the extended feature mask.
4850 * Assumes the caller knows what it's doing! (host must support these)
4851 */
4852 case CPUMCPUIDFEATURE_SYSCALL:
4853 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
4854 if ( !pLeaf
4855 || !pVM->cpum.s.HostFeatures.fSysCall)
4856 {
4857 LogRel(("CPUM: WARNING! Can't turn on SYSCALL/SYSRET when the host doesn't support it!\n"));
4858 return;
4859 }
4860
4861 /* Valid for both Intel and AMD CPUs, although only in 64 bits mode for Intel. */
4862 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx |= X86_CPUID_EXT_FEATURE_EDX_SYSCALL;
4863 pVM->cpum.s.GuestFeatures.fSysCall = 1;
4864 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled SYSCALL/RET\n"));
4865 break;
4866
4867 /*
4868 * Set the PAE bit in both feature masks.
4869 * Assumes the caller knows what it's doing! (host must support these)
4870 */
4871 case CPUMCPUIDFEATURE_PAE:
4872 if (!pVM->cpum.s.HostFeatures.fPae)
4873 {
4874 LogRel(("CPUM: WARNING! Can't turn on PAE when the host doesn't support it!\n"));
4875 return;
4876 }
4877
4878 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x00000001));
4879 if (pLeaf)
4880 pVM->cpum.s.aGuestCpuIdPatmStd[1].uEdx = pLeaf->uEdx |= X86_CPUID_FEATURE_EDX_PAE;
4881
4882 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
4883 if ( pLeaf
4884 && ( pVM->cpum.s.GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_AMD
4885 || pVM->cpum.s.GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_HYGON))
4886 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx |= X86_CPUID_AMD_FEATURE_EDX_PAE;
4887
4888 pVM->cpum.s.GuestFeatures.fPae = 1;
4889 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled PAE\n"));
4890 break;
4891
4892 /*
4893 * Set the LONG MODE bit in the extended feature mask.
4894 * Assumes the caller knows what it's doing! (host must support these)
4895 */
4896 case CPUMCPUIDFEATURE_LONG_MODE:
4897 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
4898 if ( !pLeaf
4899 || !pVM->cpum.s.HostFeatures.fLongMode)
4900 {
4901 LogRel(("CPUM: WARNING! Can't turn on LONG MODE when the host doesn't support it!\n"));
4902 return;
4903 }
4904
4905 /* Valid for both Intel and AMD. */
4906 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx |= X86_CPUID_EXT_FEATURE_EDX_LONG_MODE;
4907 pVM->cpum.s.GuestFeatures.fLongMode = 1;
4908 pVM->cpum.s.GuestFeatures.cVmxMaxPhysAddrWidth = pVM->cpum.s.GuestFeatures.cMaxPhysAddrWidth;
4909 if (pVM->cpum.s.GuestFeatures.fVmx)
4910 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
4911 {
4912 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
4913 pVCpu->cpum.s.Guest.hwvirt.vmx.Msrs.u64Basic &= ~VMX_BASIC_PHYSADDR_WIDTH_32BIT;
4914 }
4915 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled LONG MODE\n"));
4916 break;
4917
4918 /*
4919 * Set the NX/XD bit in the extended feature mask.
4920 * Assumes the caller knows what it's doing! (host must support these)
4921 */
4922 case CPUMCPUIDFEATURE_NX:
4923 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
4924 if ( !pLeaf
4925 || !pVM->cpum.s.HostFeatures.fNoExecute)
4926 {
4927 LogRel(("CPUM: WARNING! Can't turn on NX/XD when the host doesn't support it!\n"));
4928 return;
4929 }
4930
4931 /* Valid for both Intel and AMD. */
4932 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx |= X86_CPUID_EXT_FEATURE_EDX_NX;
4933 pVM->cpum.s.GuestFeatures.fNoExecute = 1;
4934 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled NX\n"));
4935 break;
4936
4937
4938 /*
4939 * Set the LAHF/SAHF support in 64-bit mode.
4940 * Assumes the caller knows what it's doing! (host must support this)
4941 */
4942 case CPUMCPUIDFEATURE_LAHF:
4943 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
4944 if ( !pLeaf
4945 || !pVM->cpum.s.HostFeatures.fLahfSahf)
4946 {
4947 LogRel(("CPUM: WARNING! Can't turn on LAHF/SAHF when the host doesn't support it!\n"));
4948 return;
4949 }
4950
4951 /* Valid for both Intel and AMD. */
4952 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEcx = pLeaf->uEcx |= X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF;
4953 pVM->cpum.s.GuestFeatures.fLahfSahf = 1;
4954 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled LAHF/SAHF\n"));
4955 break;
4956
4957 /*
4958 * Set the RDTSCP support bit.
4959 * Assumes the caller knows what it's doing! (host must support this)
4960 */
4961 case CPUMCPUIDFEATURE_RDTSCP:
4962 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
4963 if ( !pLeaf
4964 || !pVM->cpum.s.HostFeatures.fRdTscP
4965 || pVM->cpum.s.u8PortableCpuIdLevel > 0)
4966 {
4967 if (!pVM->cpum.s.u8PortableCpuIdLevel)
4968 LogRel(("CPUM: WARNING! Can't turn on RDTSCP when the host doesn't support it!\n"));
4969 return;
4970 }
4971
4972 /* Valid for both Intel and AMD. */
4973 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx |= X86_CPUID_EXT_FEATURE_EDX_RDTSCP;
4974 pVM->cpum.s.HostFeatures.fRdTscP = 1;
4975 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled RDTSCP.\n"));
4976 break;
4977
4978 /*
4979 * Set the Hypervisor Present bit in the standard feature mask.
4980 */
4981 case CPUMCPUIDFEATURE_HVP:
4982 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x00000001));
4983 if (pLeaf)
4984 pVM->cpum.s.aGuestCpuIdPatmStd[1].uEcx = pLeaf->uEcx |= X86_CPUID_FEATURE_ECX_HVP;
4985 pVM->cpum.s.GuestFeatures.fHypervisorPresent = 1;
4986 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled Hypervisor Present bit\n"));
4987 break;
4988
4989 /*
4990 * Set up the speculation control CPUID bits and MSRs. This is quite complicated
4991 * on Intel CPUs, and different on AMDs.
4992 */
4993 case CPUMCPUIDFEATURE_SPEC_CTRL:
4994 if (pVM->cpum.s.GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_INTEL)
4995 {
4996 pLeaf = cpumR3CpuIdGetExactLeaf(&pVM->cpum.s, UINT32_C(0x00000007), 0);
4997 if ( !pLeaf
4998 || !(pVM->cpum.s.HostFeatures.fIbpb || pVM->cpum.s.HostFeatures.fIbrs))
4999 {
5000 LogRel(("CPUM: WARNING! Can't turn on Speculation Control when the host doesn't support it!\n"));
5001 return;
5002 }
5003
5004 /* The feature can be enabled. Let's see what we can actually do. */
5005 pVM->cpum.s.GuestFeatures.fSpeculationControl = 1;
5006
5007 /* We will only expose STIBP if IBRS is present to keep things simpler (simple is not an option). */
5008 if (pVM->cpum.s.HostFeatures.fIbrs)
5009 {
5010 pLeaf->uEdx |= X86_CPUID_STEXT_FEATURE_EDX_IBRS_IBPB;
5011 pVM->cpum.s.GuestFeatures.fIbrs = 1;
5012 if (pVM->cpum.s.HostFeatures.fStibp)
5013 {
5014 pLeaf->uEdx |= X86_CPUID_STEXT_FEATURE_EDX_STIBP;
5015 pVM->cpum.s.GuestFeatures.fStibp = 1;
5016 }
5017
5018 /* Make sure we have the speculation control MSR... */
5019 pMsrRange = cpumLookupMsrRange(pVM, MSR_IA32_SPEC_CTRL);
5020 if (!pMsrRange)
5021 {
5022 static CPUMMSRRANGE const s_SpecCtrl =
5023 {
5024 /*.uFirst =*/ MSR_IA32_SPEC_CTRL, /*.uLast =*/ MSR_IA32_SPEC_CTRL,
5025 /*.enmRdFn =*/ kCpumMsrRdFn_Ia32SpecCtrl, /*.enmWrFn =*/ kCpumMsrWrFn_Ia32SpecCtrl,
5026 /*.offCpumCpu =*/ UINT16_MAX, /*.fReserved =*/ 0, /*.uValue =*/ 0, /*.fWrIgnMask =*/ 0, /*.fWrGpMask =*/ 0,
5027 /*.szName = */ "IA32_SPEC_CTRL"
5028 };
5029 int rc = CPUMR3MsrRangesInsert(pVM, &s_SpecCtrl);
5030 AssertLogRelRC(rc);
5031 }
5032
5033 /* ... and the predictor command MSR. */
5034 pMsrRange = cpumLookupMsrRange(pVM, MSR_IA32_PRED_CMD);
5035 if (!pMsrRange)
5036 {
5037 /** @todo incorrect fWrGpMask. */
5038 static CPUMMSRRANGE const s_SpecCtrl =
5039 {
5040 /*.uFirst =*/ MSR_IA32_PRED_CMD, /*.uLast =*/ MSR_IA32_PRED_CMD,
5041 /*.enmRdFn =*/ kCpumMsrRdFn_WriteOnly, /*.enmWrFn =*/ kCpumMsrWrFn_Ia32PredCmd,
5042 /*.offCpumCpu =*/ UINT16_MAX, /*.fReserved =*/ 0, /*.uValue =*/ 0, /*.fWrIgnMask =*/ 0, /*.fWrGpMask =*/ 0,
5043 /*.szName = */ "IA32_PRED_CMD"
5044 };
5045 int rc = CPUMR3MsrRangesInsert(pVM, &s_SpecCtrl);
5046 AssertLogRelRC(rc);
5047 }
5048
5049 }
5050
5051 if (pVM->cpum.s.HostFeatures.fArchCap)
5052 {
5053 /* Install the architectural capabilities MSR. */
5054 pMsrRange = cpumLookupMsrRange(pVM, MSR_IA32_ARCH_CAPABILITIES);
5055 if (!pMsrRange)
5056 {
5057 static CPUMMSRRANGE const s_ArchCaps =
5058 {
5059 /*.uFirst =*/ MSR_IA32_ARCH_CAPABILITIES, /*.uLast =*/ MSR_IA32_ARCH_CAPABILITIES,
5060 /*.enmRdFn =*/ kCpumMsrRdFn_Ia32ArchCapabilities, /*.enmWrFn =*/ kCpumMsrWrFn_ReadOnly,
5061 /*.offCpumCpu =*/ UINT16_MAX, /*.fReserved =*/ 0, /*.uValue =*/ 0, /*.fWrIgnMask =*/ 0, /*.fWrGpMask =*/ UINT64_MAX,
5062 /*.szName = */ "IA32_ARCH_CAPABILITIES"
5063 };
5064 int rc = CPUMR3MsrRangesInsert(pVM, &s_ArchCaps);
5065 AssertLogRelRC(rc);
5066 }
5067
5068 /* Advertise IBRS_ALL if present at this point... */
5069 if (pVM->cpum.s.HostFeatures.fArchCap & MSR_IA32_ARCH_CAP_F_IBRS_ALL)
5070 VMCC_FOR_EACH_VMCPU_STMT(pVM, pVCpu->cpum.s.GuestMsrs.msr.ArchCaps |= MSR_IA32_ARCH_CAP_F_IBRS_ALL);
5071 }
5072
5073 LogRel(("CPUM: SetGuestCpuIdFeature: Enabled Speculation Control.\n"));
5074 }
5075 else if ( pVM->cpum.s.GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_AMD
5076 || pVM->cpum.s.GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_HYGON)
5077 {
5078 /* The precise details of AMD's implementation are not yet clear. */
5079 }
5080 break;
5081
5082 default:
5083 AssertMsgFailed(("enmFeature=%d\n", enmFeature));
5084 break;
5085 }
5086
5087 /** @todo can probably kill this as this API is now init time only... */
5088 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
5089 {
5090 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
5091 pVCpu->cpum.s.fChanged |= CPUM_CHANGED_CPUID;
5092 }
5093}
5094
5095
5096/**
5097 * Queries a CPUID feature bit.
5098 *
5099 * @returns boolean for feature presence
5100 * @param pVM The cross context VM structure.
5101 * @param enmFeature The feature to query.
5102 * @deprecated Use the cpum.ro.GuestFeatures directly instead.
5103 */
5104VMMR3_INT_DECL(bool) CPUMR3GetGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature)
5105{
5106 switch (enmFeature)
5107 {
5108 case CPUMCPUIDFEATURE_APIC: return pVM->cpum.s.GuestFeatures.fApic;
5109 case CPUMCPUIDFEATURE_X2APIC: return pVM->cpum.s.GuestFeatures.fX2Apic;
5110 case CPUMCPUIDFEATURE_SYSCALL: return pVM->cpum.s.GuestFeatures.fSysCall;
5111 case CPUMCPUIDFEATURE_SEP: return pVM->cpum.s.GuestFeatures.fSysEnter;
5112 case CPUMCPUIDFEATURE_PAE: return pVM->cpum.s.GuestFeatures.fPae;
5113 case CPUMCPUIDFEATURE_NX: return pVM->cpum.s.GuestFeatures.fNoExecute;
5114 case CPUMCPUIDFEATURE_LAHF: return pVM->cpum.s.GuestFeatures.fLahfSahf;
5115 case CPUMCPUIDFEATURE_LONG_MODE: return pVM->cpum.s.GuestFeatures.fLongMode;
5116 case CPUMCPUIDFEATURE_RDTSCP: return pVM->cpum.s.GuestFeatures.fRdTscP;
5117 case CPUMCPUIDFEATURE_HVP: return pVM->cpum.s.GuestFeatures.fHypervisorPresent;
5118 case CPUMCPUIDFEATURE_SPEC_CTRL: return pVM->cpum.s.GuestFeatures.fSpeculationControl;
5119 case CPUMCPUIDFEATURE_INVALID:
5120 case CPUMCPUIDFEATURE_32BIT_HACK:
5121 break;
5122 }
5123 AssertFailed();
5124 return false;
5125}
5126
5127
5128/**
5129 * Clears a CPUID feature bit.
5130 *
5131 * @param pVM The cross context VM structure.
5132 * @param enmFeature The feature to clear.
5133 *
5134 * @deprecated Probably better to default the feature to disabled and only allow
5135 * setting (enabling) it during construction.
5136 */
5137VMMR3_INT_DECL(void) CPUMR3ClearGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature)
5138{
5139 PCPUMCPUIDLEAF pLeaf;
5140 switch (enmFeature)
5141 {
5142 case CPUMCPUIDFEATURE_APIC:
5143 Assert(!pVM->cpum.s.GuestFeatures.fApic); /* We only expect this call during init. No MSR adjusting needed. */
5144 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x00000001));
5145 if (pLeaf)
5146 pVM->cpum.s.aGuestCpuIdPatmStd[1].uEdx = pLeaf->uEdx &= ~X86_CPUID_FEATURE_EDX_APIC;
5147
5148 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
5149 if (pLeaf && (pLeaf->fFlags & CPUMCPUIDLEAF_F_CONTAINS_APIC))
5150 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx &= ~X86_CPUID_AMD_FEATURE_EDX_APIC;
5151
5152 pVM->cpum.s.GuestFeatures.fApic = 0;
5153 Log(("CPUM: ClearGuestCpuIdFeature: Disabled xAPIC\n"));
5154 break;
5155
5156 case CPUMCPUIDFEATURE_X2APIC:
5157 Assert(!pVM->cpum.s.GuestFeatures.fX2Apic); /* We only expect this call during init. No MSR adjusting needed. */
5158 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x00000001));
5159 if (pLeaf)
5160 pVM->cpum.s.aGuestCpuIdPatmStd[1].uEcx = pLeaf->uEcx &= ~X86_CPUID_FEATURE_ECX_X2APIC;
5161 pVM->cpum.s.GuestFeatures.fX2Apic = 0;
5162 Log(("CPUM: ClearGuestCpuIdFeature: Disabled x2APIC\n"));
5163 break;
5164
5165 case CPUMCPUIDFEATURE_PAE:
5166 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x00000001));
5167 if (pLeaf)
5168 pVM->cpum.s.aGuestCpuIdPatmStd[1].uEdx = pLeaf->uEdx &= ~X86_CPUID_FEATURE_EDX_PAE;
5169
5170 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
5171 if ( pLeaf
5172 && ( pVM->cpum.s.GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_AMD
5173 || pVM->cpum.s.GuestFeatures.enmCpuVendor == CPUMCPUVENDOR_HYGON))
5174 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx &= ~X86_CPUID_AMD_FEATURE_EDX_PAE;
5175
5176 pVM->cpum.s.GuestFeatures.fPae = 0;
5177 Log(("CPUM: ClearGuestCpuIdFeature: Disabled PAE!\n"));
5178 break;
5179
5180 case CPUMCPUIDFEATURE_LONG_MODE:
5181 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
5182 if (pLeaf)
5183 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx &= ~X86_CPUID_EXT_FEATURE_EDX_LONG_MODE;
5184 pVM->cpum.s.GuestFeatures.fLongMode = 0;
5185 pVM->cpum.s.GuestFeatures.cVmxMaxPhysAddrWidth = 32;
5186 if (pVM->cpum.s.GuestFeatures.fVmx)
5187 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
5188 {
5189 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
5190 pVCpu->cpum.s.Guest.hwvirt.vmx.Msrs.u64Basic |= VMX_BASIC_PHYSADDR_WIDTH_32BIT;
5191 }
5192 break;
5193
5194 case CPUMCPUIDFEATURE_LAHF:
5195 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
5196 if (pLeaf)
5197 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEcx = pLeaf->uEcx &= ~X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF;
5198 pVM->cpum.s.GuestFeatures.fLahfSahf = 0;
5199 break;
5200
5201 case CPUMCPUIDFEATURE_RDTSCP:
5202 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x80000001));
5203 if (pLeaf)
5204 pVM->cpum.s.aGuestCpuIdPatmExt[1].uEdx = pLeaf->uEdx &= ~X86_CPUID_EXT_FEATURE_EDX_RDTSCP;
5205 pVM->cpum.s.GuestFeatures.fRdTscP = 0;
5206 Log(("CPUM: ClearGuestCpuIdFeature: Disabled RDTSCP!\n"));
5207 break;
5208
5209 case CPUMCPUIDFEATURE_HVP:
5210 pLeaf = cpumCpuIdGetLeaf(pVM, UINT32_C(0x00000001));
5211 if (pLeaf)
5212 pVM->cpum.s.aGuestCpuIdPatmStd[1].uEcx = pLeaf->uEcx &= ~X86_CPUID_FEATURE_ECX_HVP;
5213 pVM->cpum.s.GuestFeatures.fHypervisorPresent = 0;
5214 break;
5215
5216 case CPUMCPUIDFEATURE_SPEC_CTRL:
5217 pLeaf = cpumR3CpuIdGetExactLeaf(&pVM->cpum.s, UINT32_C(0x00000007), 0);
5218 if (pLeaf)
5219 pLeaf->uEdx &= ~(X86_CPUID_STEXT_FEATURE_EDX_IBRS_IBPB | X86_CPUID_STEXT_FEATURE_EDX_STIBP);
5220 VMCC_FOR_EACH_VMCPU_STMT(pVM, pVCpu->cpum.s.GuestMsrs.msr.ArchCaps &= ~MSR_IA32_ARCH_CAP_F_IBRS_ALL);
5221 Log(("CPUM: ClearGuestCpuIdFeature: Disabled speculation control!\n"));
5222 break;
5223
5224 default:
5225 AssertMsgFailed(("enmFeature=%d\n", enmFeature));
5226 break;
5227 }
5228
5229 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
5230 {
5231 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
5232 pVCpu->cpum.s.fChanged |= CPUM_CHANGED_CPUID;
5233 }
5234}
5235
5236
5237
5238/*
5239 *
5240 *
5241 * Saved state related code.
5242 * Saved state related code.
5243 * Saved state related code.
5244 *
5245 *
5246 */
5247
5248/**
5249 * Called both in pass 0 and the final pass.
5250 *
5251 * @param pVM The cross context VM structure.
5252 * @param pSSM The saved state handle.
5253 */
5254void cpumR3SaveCpuId(PVM pVM, PSSMHANDLE pSSM)
5255{
5256 /*
5257 * Save all the CPU ID leaves.
5258 */
5259 SSMR3PutU32(pSSM, sizeof(pVM->cpum.s.GuestInfo.paCpuIdLeavesR3[0]));
5260 SSMR3PutU32(pSSM, pVM->cpum.s.GuestInfo.cCpuIdLeaves);
5261 SSMR3PutMem(pSSM, pVM->cpum.s.GuestInfo.paCpuIdLeavesR3,
5262 sizeof(pVM->cpum.s.GuestInfo.paCpuIdLeavesR3[0]) * pVM->cpum.s.GuestInfo.cCpuIdLeaves);
5263
5264 SSMR3PutMem(pSSM, &pVM->cpum.s.GuestInfo.DefCpuId, sizeof(pVM->cpum.s.GuestInfo.DefCpuId));
5265
5266 /*
5267 * Save a good portion of the raw CPU IDs as well as they may come in
5268 * handy when validating features for raw mode.
5269 */
5270 CPUMCPUID aRawStd[16];
5271 for (unsigned i = 0; i < RT_ELEMENTS(aRawStd); i++)
5272 ASMCpuIdExSlow(i, 0, 0, 0, &aRawStd[i].uEax, &aRawStd[i].uEbx, &aRawStd[i].uEcx, &aRawStd[i].uEdx);
5273 SSMR3PutU32(pSSM, RT_ELEMENTS(aRawStd));
5274 SSMR3PutMem(pSSM, &aRawStd[0], sizeof(aRawStd));
5275
5276 CPUMCPUID aRawExt[32];
5277 for (unsigned i = 0; i < RT_ELEMENTS(aRawExt); i++)
5278 ASMCpuIdExSlow(i | UINT32_C(0x80000000), 0, 0, 0, &aRawExt[i].uEax, &aRawExt[i].uEbx, &aRawExt[i].uEcx, &aRawExt[i].uEdx);
5279 SSMR3PutU32(pSSM, RT_ELEMENTS(aRawExt));
5280 SSMR3PutMem(pSSM, &aRawExt[0], sizeof(aRawExt));
5281}
5282
5283
5284static int cpumR3LoadOneOldGuestCpuIdArray(PSSMHANDLE pSSM, uint32_t uBase, PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves)
5285{
5286 uint32_t cCpuIds;
5287 int rc = SSMR3GetU32(pSSM, &cCpuIds);
5288 if (RT_SUCCESS(rc))
5289 {
5290 if (cCpuIds < 64)
5291 {
5292 for (uint32_t i = 0; i < cCpuIds; i++)
5293 {
5294 CPUMCPUID CpuId;
5295 rc = SSMR3GetMem(pSSM, &CpuId, sizeof(CpuId));
5296 if (RT_FAILURE(rc))
5297 break;
5298
5299 CPUMCPUIDLEAF NewLeaf;
5300 NewLeaf.uLeaf = uBase + i;
5301 NewLeaf.uSubLeaf = 0;
5302 NewLeaf.fSubLeafMask = 0;
5303 NewLeaf.uEax = CpuId.uEax;
5304 NewLeaf.uEbx = CpuId.uEbx;
5305 NewLeaf.uEcx = CpuId.uEcx;
5306 NewLeaf.uEdx = CpuId.uEdx;
5307 NewLeaf.fFlags = 0;
5308 rc = cpumR3CpuIdInsert(NULL /* pVM */, ppaLeaves, pcLeaves, &NewLeaf);
5309 }
5310 }
5311 else
5312 rc = VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
5313 }
5314 if (RT_FAILURE(rc))
5315 {
5316 RTMemFree(*ppaLeaves);
5317 *ppaLeaves = NULL;
5318 *pcLeaves = 0;
5319 }
5320 return rc;
5321}
5322
5323
5324static int cpumR3LoadGuestCpuIdArray(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves)
5325{
5326 *ppaLeaves = NULL;
5327 *pcLeaves = 0;
5328
5329 int rc;
5330 if (uVersion > CPUM_SAVED_STATE_VERSION_PUT_STRUCT)
5331 {
5332 /*
5333 * The new format. Starts by declaring the leave size and count.
5334 */
5335 uint32_t cbLeaf;
5336 SSMR3GetU32(pSSM, &cbLeaf);
5337 uint32_t cLeaves;
5338 rc = SSMR3GetU32(pSSM, &cLeaves);
5339 if (RT_SUCCESS(rc))
5340 {
5341 if (cbLeaf == sizeof(**ppaLeaves))
5342 {
5343 if (cLeaves <= CPUM_CPUID_MAX_LEAVES)
5344 {
5345 /*
5346 * Load the leaves one by one.
5347 *
5348 * The uPrev stuff is a kludge for working around a week worth of bad saved
5349 * states during the CPUID revamp in March 2015. We saved too many leaves
5350 * due to a bug in cpumR3CpuIdInstallAndExplodeLeaves, thus ending up with
5351 * garbage entires at the end of the array when restoring. We also had
5352 * a subleaf insertion bug that triggered with the leaf 4 stuff below,
5353 * this kludge doesn't deal correctly with that, but who cares...
5354 */
5355 uint32_t uPrev = 0;
5356 for (uint32_t i = 0; i < cLeaves && RT_SUCCESS(rc); i++)
5357 {
5358 CPUMCPUIDLEAF Leaf;
5359 rc = SSMR3GetMem(pSSM, &Leaf, sizeof(Leaf));
5360 if (RT_SUCCESS(rc))
5361 {
5362 if ( uVersion != CPUM_SAVED_STATE_VERSION_BAD_CPUID_COUNT
5363 || Leaf.uLeaf >= uPrev)
5364 {
5365 rc = cpumR3CpuIdInsert(NULL /* pVM */, ppaLeaves, pcLeaves, &Leaf);
5366 uPrev = Leaf.uLeaf;
5367 }
5368 else
5369 uPrev = UINT32_MAX;
5370 }
5371 }
5372 }
5373 else
5374 rc = SSMR3SetLoadError(pSSM, VERR_TOO_MANY_CPUID_LEAVES, RT_SRC_POS,
5375 "Too many CPUID leaves: %#x, max %#x", cLeaves, CPUM_CPUID_MAX_LEAVES);
5376 }
5377 else
5378 rc = SSMR3SetLoadError(pSSM, VERR_SSM_DATA_UNIT_FORMAT_CHANGED, RT_SRC_POS,
5379 "CPUMCPUIDLEAF size differs: saved=%#x, our=%#x", cbLeaf, sizeof(**ppaLeaves));
5380 }
5381 }
5382 else
5383 {
5384 /*
5385 * The old format with its three inflexible arrays.
5386 */
5387 rc = cpumR3LoadOneOldGuestCpuIdArray(pSSM, UINT32_C(0x00000000), ppaLeaves, pcLeaves);
5388 if (RT_SUCCESS(rc))
5389 rc = cpumR3LoadOneOldGuestCpuIdArray(pSSM, UINT32_C(0x80000000), ppaLeaves, pcLeaves);
5390 if (RT_SUCCESS(rc))
5391 rc = cpumR3LoadOneOldGuestCpuIdArray(pSSM, UINT32_C(0xc0000000), ppaLeaves, pcLeaves);
5392 if (RT_SUCCESS(rc))
5393 {
5394 /*
5395 * Fake up leaf 4 on intel like we used to do in CPUMGetGuestCpuId earlier.
5396 */
5397 PCPUMCPUIDLEAF pLeaf = cpumR3CpuIdGetLeaf(*ppaLeaves, *pcLeaves, 0, 0);
5398 if ( pLeaf
5399 && ASMIsIntelCpuEx(pLeaf->uEbx, pLeaf->uEcx, pLeaf->uEdx))
5400 {
5401 CPUMCPUIDLEAF Leaf;
5402 Leaf.uLeaf = 4;
5403 Leaf.fSubLeafMask = UINT32_MAX;
5404 Leaf.uSubLeaf = 0;
5405 Leaf.uEdx = UINT32_C(0); /* 3 flags, 0 is fine. */
5406 Leaf.uEcx = UINT32_C(63); /* sets - 1 */
5407 Leaf.uEbx = (UINT32_C(7) << 22) /* associativity -1 */
5408 | (UINT32_C(0) << 12) /* phys line partitions - 1 */
5409 | UINT32_C(63); /* system coherency line size - 1 */
5410 Leaf.uEax = (RT_MIN(pVM->cCpus - 1, UINT32_C(0x3f)) << 26) /* cores per package - 1 */
5411 | (UINT32_C(0) << 14) /* threads per cache - 1 */
5412 | (UINT32_C(1) << 5) /* cache level */
5413 | UINT32_C(1); /* cache type (data) */
5414 Leaf.fFlags = 0;
5415 rc = cpumR3CpuIdInsert(NULL /* pVM */, ppaLeaves, pcLeaves, &Leaf);
5416 if (RT_SUCCESS(rc))
5417 {
5418 Leaf.uSubLeaf = 1; /* Should've been cache type 2 (code), but buggy code made it data. */
5419 rc = cpumR3CpuIdInsert(NULL /* pVM */, ppaLeaves, pcLeaves, &Leaf);
5420 }
5421 if (RT_SUCCESS(rc))
5422 {
5423 Leaf.uSubLeaf = 2; /* Should've been cache type 3 (unified), but buggy code made it data. */
5424 Leaf.uEcx = 4095; /* sets - 1 */
5425 Leaf.uEbx &= UINT32_C(0x003fffff); /* associativity - 1 */
5426 Leaf.uEbx |= UINT32_C(23) << 22;
5427 Leaf.uEax &= UINT32_C(0xfc003fff); /* threads per cache - 1 */
5428 Leaf.uEax |= RT_MIN(pVM->cCpus - 1, UINT32_C(0xfff)) << 14;
5429 Leaf.uEax &= UINT32_C(0xffffff1f); /* level */
5430 Leaf.uEax |= UINT32_C(2) << 5;
5431 rc = cpumR3CpuIdInsert(NULL /* pVM */, ppaLeaves, pcLeaves, &Leaf);
5432 }
5433 }
5434 }
5435 }
5436 return rc;
5437}
5438
5439
5440/**
5441 * Loads the CPU ID leaves saved by pass 0, inner worker.
5442 *
5443 * @returns VBox status code.
5444 * @param pVM The cross context VM structure.
5445 * @param pSSM The saved state handle.
5446 * @param uVersion The format version.
5447 * @param paLeaves Guest CPUID leaves loaded from the state.
5448 * @param cLeaves The number of leaves in @a paLeaves.
5449 * @param pMsrs The guest MSRs.
5450 */
5451int cpumR3LoadCpuIdInner(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, PCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, PCCPUMMSRS pMsrs)
5452{
5453 AssertMsgReturn(uVersion >= CPUM_SAVED_STATE_VERSION_VER3_2, ("%u\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
5454
5455 /*
5456 * Continue loading the state into stack buffers.
5457 */
5458 CPUMCPUID GuestDefCpuId;
5459 int rc = SSMR3GetMem(pSSM, &GuestDefCpuId, sizeof(GuestDefCpuId));
5460 AssertRCReturn(rc, rc);
5461
5462 CPUMCPUID aRawStd[16];
5463 uint32_t cRawStd;
5464 rc = SSMR3GetU32(pSSM, &cRawStd); AssertRCReturn(rc, rc);
5465 if (cRawStd > RT_ELEMENTS(aRawStd))
5466 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
5467 rc = SSMR3GetMem(pSSM, &aRawStd[0], cRawStd * sizeof(aRawStd[0]));
5468 AssertRCReturn(rc, rc);
5469 for (uint32_t i = cRawStd; i < RT_ELEMENTS(aRawStd); i++)
5470 ASMCpuIdExSlow(i, 0, 0, 0, &aRawStd[i].uEax, &aRawStd[i].uEbx, &aRawStd[i].uEcx, &aRawStd[i].uEdx);
5471
5472 CPUMCPUID aRawExt[32];
5473 uint32_t cRawExt;
5474 rc = SSMR3GetU32(pSSM, &cRawExt); AssertRCReturn(rc, rc);
5475 if (cRawExt > RT_ELEMENTS(aRawExt))
5476 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
5477 rc = SSMR3GetMem(pSSM, &aRawExt[0], cRawExt * sizeof(aRawExt[0]));
5478 AssertRCReturn(rc, rc);
5479 for (uint32_t i = cRawExt; i < RT_ELEMENTS(aRawExt); i++)
5480 ASMCpuIdExSlow(i | UINT32_C(0x80000000), 0, 0, 0, &aRawExt[i].uEax, &aRawExt[i].uEbx, &aRawExt[i].uEcx, &aRawExt[i].uEdx);
5481
5482 /*
5483 * Get the raw CPU IDs for the current host.
5484 */
5485 CPUMCPUID aHostRawStd[16];
5486 for (unsigned i = 0; i < RT_ELEMENTS(aHostRawStd); i++)
5487 ASMCpuIdExSlow(i, 0, 0, 0, &aHostRawStd[i].uEax, &aHostRawStd[i].uEbx, &aHostRawStd[i].uEcx, &aHostRawStd[i].uEdx);
5488
5489 CPUMCPUID aHostRawExt[32];
5490 for (unsigned i = 0; i < RT_ELEMENTS(aHostRawExt); i++)
5491 ASMCpuIdExSlow(i | UINT32_C(0x80000000), 0, 0, 0,
5492 &aHostRawExt[i].uEax, &aHostRawExt[i].uEbx, &aHostRawExt[i].uEcx, &aHostRawExt[i].uEdx);
5493
5494 /*
5495 * Get the host and guest overrides so we don't reject the state because
5496 * some feature was enabled thru these interfaces.
5497 * Note! We currently only need the feature leaves, so skip rest.
5498 */
5499 PCFGMNODE pOverrideCfg = CFGMR3GetChild(CFGMR3GetRoot(pVM), "CPUM/HostCPUID");
5500 CPUMCPUID aHostOverrideStd[2];
5501 memcpy(&aHostOverrideStd[0], &aHostRawStd[0], sizeof(aHostOverrideStd));
5502 cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x00000000), &aHostOverrideStd[0], RT_ELEMENTS(aHostOverrideStd), pOverrideCfg);
5503
5504 CPUMCPUID aHostOverrideExt[2];
5505 memcpy(&aHostOverrideExt[0], &aHostRawExt[0], sizeof(aHostOverrideExt));
5506 cpumR3CpuIdInitLoadOverrideSet(UINT32_C(0x80000000), &aHostOverrideExt[0], RT_ELEMENTS(aHostOverrideExt), pOverrideCfg);
5507
5508 /*
5509 * This can be skipped.
5510 */
5511 bool fStrictCpuIdChecks;
5512 CFGMR3QueryBoolDef(CFGMR3GetChild(CFGMR3GetRoot(pVM), "CPUM"), "StrictCpuIdChecks", &fStrictCpuIdChecks, true);
5513
5514 /*
5515 * Define a bunch of macros for simplifying the santizing/checking code below.
5516 */
5517 /* Generic expression + failure message. */
5518#define CPUID_CHECK_RET(expr, fmt) \
5519 do { \
5520 if (!(expr)) \
5521 { \
5522 char *pszMsg = RTStrAPrintf2 fmt; /* lack of variadic macros sucks */ \
5523 if (fStrictCpuIdChecks) \
5524 { \
5525 int rcCpuid = SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, "%s", pszMsg); \
5526 RTStrFree(pszMsg); \
5527 return rcCpuid; \
5528 } \
5529 LogRel(("CPUM: %s\n", pszMsg)); \
5530 RTStrFree(pszMsg); \
5531 } \
5532 } while (0)
5533#define CPUID_CHECK_WRN(expr, fmt) \
5534 do { \
5535 if (!(expr)) \
5536 LogRel(fmt); \
5537 } while (0)
5538
5539 /* For comparing two values and bitch if they differs. */
5540#define CPUID_CHECK2_RET(what, host, saved) \
5541 do { \
5542 if ((host) != (saved)) \
5543 { \
5544 if (fStrictCpuIdChecks) \
5545 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
5546 N_(#what " mismatch: host=%#x saved=%#x"), (host), (saved)); \
5547 LogRel(("CPUM: " #what " differs: host=%#x saved=%#x\n", (host), (saved))); \
5548 } \
5549 } while (0)
5550#define CPUID_CHECK2_WRN(what, host, saved) \
5551 do { \
5552 if ((host) != (saved)) \
5553 LogRel(("CPUM: " #what " differs: host=%#x saved=%#x\n", (host), (saved))); \
5554 } while (0)
5555
5556 /* For checking raw cpu features (raw mode). */
5557#define CPUID_RAW_FEATURE_RET(set, reg, bit) \
5558 do { \
5559 if ((aHostRaw##set [1].reg & bit) != (aRaw##set [1].reg & bit)) \
5560 { \
5561 if (fStrictCpuIdChecks) \
5562 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
5563 N_(#bit " mismatch: host=%d saved=%d"), \
5564 !!(aHostRaw##set [1].reg & (bit)), !!(aRaw##set [1].reg & (bit)) ); \
5565 LogRel(("CPUM: " #bit" differs: host=%d saved=%d\n", \
5566 !!(aHostRaw##set [1].reg & (bit)), !!(aRaw##set [1].reg & (bit)) )); \
5567 } \
5568 } while (0)
5569#define CPUID_RAW_FEATURE_WRN(set, reg, bit) \
5570 do { \
5571 if ((aHostRaw##set [1].reg & bit) != (aRaw##set [1].reg & bit)) \
5572 LogRel(("CPUM: " #bit" differs: host=%d saved=%d\n", \
5573 !!(aHostRaw##set [1].reg & (bit)), !!(aRaw##set [1].reg & (bit)) )); \
5574 } while (0)
5575#define CPUID_RAW_FEATURE_IGN(set, reg, bit) do { } while (0)
5576
5577 /* For checking guest features. */
5578#define CPUID_GST_FEATURE_RET(set, reg, bit) \
5579 do { \
5580 if ( (aGuestCpuId##set [1].reg & bit) \
5581 && !(aHostRaw##set [1].reg & bit) \
5582 && !(aHostOverride##set [1].reg & bit) \
5583 ) \
5584 { \
5585 if (fStrictCpuIdChecks) \
5586 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
5587 N_(#bit " is not supported by the host but has already exposed to the guest")); \
5588 LogRel(("CPUM: " #bit " is not supported by the host but has already exposed to the guest\n")); \
5589 } \
5590 } while (0)
5591#define CPUID_GST_FEATURE_WRN(set, reg, bit) \
5592 do { \
5593 if ( (aGuestCpuId##set [1].reg & bit) \
5594 && !(aHostRaw##set [1].reg & bit) \
5595 && !(aHostOverride##set [1].reg & bit) \
5596 ) \
5597 LogRel(("CPUM: " #bit " is not supported by the host but has already exposed to the guest\n")); \
5598 } while (0)
5599#define CPUID_GST_FEATURE_EMU(set, reg, bit) \
5600 do { \
5601 if ( (aGuestCpuId##set [1].reg & bit) \
5602 && !(aHostRaw##set [1].reg & bit) \
5603 && !(aHostOverride##set [1].reg & bit) \
5604 ) \
5605 LogRel(("CPUM: Warning - " #bit " is not supported by the host but already exposed to the guest. This may impact performance.\n")); \
5606 } while (0)
5607#define CPUID_GST_FEATURE_IGN(set, reg, bit) do { } while (0)
5608
5609 /* For checking guest features if AMD guest CPU. */
5610#define CPUID_GST_AMD_FEATURE_RET(set, reg, bit) \
5611 do { \
5612 if ( (aGuestCpuId##set [1].reg & bit) \
5613 && fGuestAmd \
5614 && (!fGuestAmd || !(aHostRaw##set [1].reg & bit)) \
5615 && !(aHostOverride##set [1].reg & bit) \
5616 ) \
5617 { \
5618 if (fStrictCpuIdChecks) \
5619 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
5620 N_(#bit " is not supported by the host but has already exposed to the guest")); \
5621 LogRel(("CPUM: " #bit " is not supported by the host but has already exposed to the guest\n")); \
5622 } \
5623 } while (0)
5624#define CPUID_GST_AMD_FEATURE_WRN(set, reg, bit) \
5625 do { \
5626 if ( (aGuestCpuId##set [1].reg & bit) \
5627 && fGuestAmd \
5628 && (!fGuestAmd || !(aHostRaw##set [1].reg & bit)) \
5629 && !(aHostOverride##set [1].reg & bit) \
5630 ) \
5631 LogRel(("CPUM: " #bit " is not supported by the host but has already exposed to the guest\n")); \
5632 } while (0)
5633#define CPUID_GST_AMD_FEATURE_EMU(set, reg, bit) \
5634 do { \
5635 if ( (aGuestCpuId##set [1].reg & bit) \
5636 && fGuestAmd \
5637 && (!fGuestAmd || !(aHostRaw##set [1].reg & bit)) \
5638 && !(aHostOverride##set [1].reg & bit) \
5639 ) \
5640 LogRel(("CPUM: Warning - " #bit " is not supported by the host but already exposed to the guest. This may impact performance.\n")); \
5641 } while (0)
5642#define CPUID_GST_AMD_FEATURE_IGN(set, reg, bit) do { } while (0)
5643
5644 /* For checking AMD features which have a corresponding bit in the standard
5645 range. (Intel defines very few bits in the extended feature sets.) */
5646#define CPUID_GST_FEATURE2_RET(reg, ExtBit, StdBit) \
5647 do { \
5648 if ( (aGuestCpuIdExt [1].reg & (ExtBit)) \
5649 && !(fHostAmd \
5650 ? aHostRawExt[1].reg & (ExtBit) \
5651 : aHostRawStd[1].reg & (StdBit)) \
5652 && !(aHostOverrideExt[1].reg & (ExtBit)) \
5653 ) \
5654 { \
5655 if (fStrictCpuIdChecks) \
5656 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS, \
5657 N_(#ExtBit " is not supported by the host but has already exposed to the guest")); \
5658 LogRel(("CPUM: " #ExtBit " is not supported by the host but has already exposed to the guest\n")); \
5659 } \
5660 } while (0)
5661#define CPUID_GST_FEATURE2_WRN(reg, ExtBit, StdBit) \
5662 do { \
5663 if ( (aGuestCpuId[1].reg & (ExtBit)) \
5664 && !(fHostAmd \
5665 ? aHostRawExt[1].reg & (ExtBit) \
5666 : aHostRawStd[1].reg & (StdBit)) \
5667 && !(aHostOverrideExt[1].reg & (ExtBit)) \
5668 ) \
5669 LogRel(("CPUM: " #ExtBit " is not supported by the host but has already exposed to the guest\n")); \
5670 } while (0)
5671#define CPUID_GST_FEATURE2_EMU(reg, ExtBit, StdBit) \
5672 do { \
5673 if ( (aGuestCpuIdExt [1].reg & (ExtBit)) \
5674 && !(fHostAmd \
5675 ? aHostRawExt[1].reg & (ExtBit) \
5676 : aHostRawStd[1].reg & (StdBit)) \
5677 && !(aHostOverrideExt[1].reg & (ExtBit)) \
5678 ) \
5679 LogRel(("CPUM: Warning - " #ExtBit " is not supported by the host but already exposed to the guest. This may impact performance.\n")); \
5680 } while (0)
5681#define CPUID_GST_FEATURE2_IGN(reg, ExtBit, StdBit) do { } while (0)
5682
5683
5684 /*
5685 * Verify that we can support the features already exposed to the guest on
5686 * this host.
5687 *
5688 * Most of the features we're emulating requires intercepting instruction
5689 * and doing it the slow way, so there is no need to warn when they aren't
5690 * present in the host CPU. Thus we use IGN instead of EMU on these.
5691 *
5692 * Trailing comments:
5693 * "EMU" - Possible to emulate, could be lots of work and very slow.
5694 * "EMU?" - Can this be emulated?
5695 */
5696 CPUMCPUID aGuestCpuIdStd[2];
5697 RT_ZERO(aGuestCpuIdStd);
5698 cpumR3CpuIdGetLeafLegacy(paLeaves, cLeaves, 1, 0, &aGuestCpuIdStd[1]);
5699
5700 /* CPUID(1).ecx */
5701 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_SSE3); // -> EMU
5702 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_PCLMUL); // -> EMU?
5703 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_DTES64); // -> EMU?
5704 CPUID_GST_FEATURE_IGN(Std, uEcx, X86_CPUID_FEATURE_ECX_MONITOR);
5705 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_CPLDS); // -> EMU?
5706 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_VMX); // -> EMU
5707 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_SMX); // -> EMU
5708 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_EST); // -> EMU
5709 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_TM2); // -> EMU?
5710 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_SSSE3); // -> EMU
5711 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_CNTXID); // -> EMU
5712 CPUID_GST_FEATURE_IGN(Std, uEcx, X86_CPUID_FEATURE_ECX_SDBG);
5713 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_FMA); // -> EMU? what's this?
5714 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_CX16); // -> EMU?
5715 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_TPRUPDATE);//-> EMU
5716 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_PDCM); // -> EMU
5717 CPUID_GST_FEATURE_RET(Std, uEcx, RT_BIT_32(16) /*reserved*/);
5718 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_PCID);
5719 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_DCA); // -> EMU?
5720 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_SSE4_1); // -> EMU
5721 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_SSE4_2); // -> EMU
5722 CPUID_GST_FEATURE_IGN(Std, uEcx, X86_CPUID_FEATURE_ECX_X2APIC);
5723 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_MOVBE); // -> EMU
5724 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_POPCNT); // -> EMU
5725 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_TSCDEADL);
5726 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_AES); // -> EMU
5727 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_XSAVE); // -> EMU
5728 CPUID_GST_FEATURE_IGN(Std, uEcx, X86_CPUID_FEATURE_ECX_OSXSAVE);
5729 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_AVX); // -> EMU?
5730 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_F16C);
5731 CPUID_GST_FEATURE_RET(Std, uEcx, X86_CPUID_FEATURE_ECX_RDRAND);
5732 CPUID_GST_FEATURE_IGN(Std, uEcx, X86_CPUID_FEATURE_ECX_HVP); // Normally not set by host
5733
5734 /* CPUID(1).edx */
5735 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_FPU);
5736 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_VME);
5737 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_DE); // -> EMU?
5738 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_PSE);
5739 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_TSC); // -> EMU
5740 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_MSR); // -> EMU
5741 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_PAE);
5742 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_MCE);
5743 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_CX8); // -> EMU?
5744 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_APIC);
5745 CPUID_GST_FEATURE_RET(Std, uEdx, RT_BIT_32(10) /*reserved*/);
5746 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_SEP);
5747 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_MTRR);
5748 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_PGE);
5749 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_MCA);
5750 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_CMOV); // -> EMU
5751 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_PAT);
5752 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_PSE36);
5753 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_PSN);
5754 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_CLFSH); // -> EMU
5755 CPUID_GST_FEATURE_RET(Std, uEdx, RT_BIT_32(20) /*reserved*/);
5756 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_DS); // -> EMU?
5757 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_ACPI); // -> EMU?
5758 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_MMX); // -> EMU
5759 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_FXSR); // -> EMU
5760 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_SSE); // -> EMU
5761 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_SSE2); // -> EMU
5762 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_SS); // -> EMU?
5763 CPUID_GST_FEATURE_IGN(Std, uEdx, X86_CPUID_FEATURE_EDX_HTT); // -> EMU?
5764 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_TM); // -> EMU?
5765 CPUID_GST_FEATURE_RET(Std, uEdx, RT_BIT_32(30) /*JMPE/IA64*/); // -> EMU
5766 CPUID_GST_FEATURE_RET(Std, uEdx, X86_CPUID_FEATURE_EDX_PBE); // -> EMU?
5767
5768 /* CPUID(0x80000000). */
5769 CPUMCPUID aGuestCpuIdExt[2];
5770 RT_ZERO(aGuestCpuIdExt);
5771 if (cpumR3CpuIdGetLeafLegacy(paLeaves, cLeaves, UINT32_C(0x80000001), 0, &aGuestCpuIdExt[1]))
5772 {
5773 /** @todo deal with no 0x80000001 on the host. */
5774 bool const fHostAmd = ASMIsAmdCpuEx(aHostRawStd[0].uEbx, aHostRawStd[0].uEcx, aHostRawStd[0].uEdx)
5775 || ASMIsHygonCpuEx(aHostRawStd[0].uEbx, aHostRawStd[0].uEcx, aHostRawStd[0].uEdx);
5776 bool const fGuestAmd = ASMIsAmdCpuEx(aGuestCpuIdExt[0].uEbx, aGuestCpuIdExt[0].uEcx, aGuestCpuIdExt[0].uEdx)
5777 || ASMIsHygonCpuEx(aGuestCpuIdExt[0].uEbx, aGuestCpuIdExt[0].uEcx, aGuestCpuIdExt[0].uEdx);
5778
5779 /* CPUID(0x80000001).ecx */
5780 CPUID_GST_FEATURE_WRN(Ext, uEcx, X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF); // -> EMU
5781 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_CMPL); // -> EMU
5782 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_SVM); // -> EMU
5783 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_EXT_APIC);// ???
5784 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_CR8L); // -> EMU
5785 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_ABM); // -> EMU
5786 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_SSE4A); // -> EMU
5787 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_MISALNSSE);//-> EMU
5788 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF);// -> EMU
5789 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_OSVW); // -> EMU?
5790 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_IBS); // -> EMU
5791 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_XOP); // -> EMU
5792 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_SKINIT); // -> EMU
5793 CPUID_GST_AMD_FEATURE_RET(Ext, uEcx, X86_CPUID_AMD_FEATURE_ECX_WDT); // -> EMU
5794 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(14));
5795 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(15));
5796 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(16));
5797 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(17));
5798 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(18));
5799 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(19));
5800 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(20));
5801 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(21));
5802 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(22));
5803 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(23));
5804 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(24));
5805 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(25));
5806 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(26));
5807 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(27));
5808 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(28));
5809 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(29));
5810 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(30));
5811 CPUID_GST_AMD_FEATURE_WRN(Ext, uEcx, RT_BIT_32(31));
5812
5813 /* CPUID(0x80000001).edx */
5814 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_FPU, X86_CPUID_FEATURE_EDX_FPU); // -> EMU
5815 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_VME, X86_CPUID_FEATURE_EDX_VME); // -> EMU
5816 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_DE, X86_CPUID_FEATURE_EDX_DE); // -> EMU
5817 CPUID_GST_FEATURE2_IGN( uEdx, X86_CPUID_AMD_FEATURE_EDX_PSE, X86_CPUID_FEATURE_EDX_PSE);
5818 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_TSC, X86_CPUID_FEATURE_EDX_TSC); // -> EMU
5819 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_MSR, X86_CPUID_FEATURE_EDX_MSR); // -> EMU
5820 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_PAE, X86_CPUID_FEATURE_EDX_PAE);
5821 CPUID_GST_FEATURE2_IGN( uEdx, X86_CPUID_AMD_FEATURE_EDX_MCE, X86_CPUID_FEATURE_EDX_MCE);
5822 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_CX8, X86_CPUID_FEATURE_EDX_CX8); // -> EMU?
5823 CPUID_GST_FEATURE2_IGN( uEdx, X86_CPUID_AMD_FEATURE_EDX_APIC, X86_CPUID_FEATURE_EDX_APIC);
5824 CPUID_GST_AMD_FEATURE_WRN(Ext, uEdx, RT_BIT_32(10) /*reserved*/);
5825 CPUID_GST_FEATURE_IGN( Ext, uEdx, X86_CPUID_EXT_FEATURE_EDX_SYSCALL); // On Intel: long mode only.
5826 CPUID_GST_FEATURE2_IGN( uEdx, X86_CPUID_AMD_FEATURE_EDX_MTRR, X86_CPUID_FEATURE_EDX_MTRR);
5827 CPUID_GST_FEATURE2_IGN( uEdx, X86_CPUID_AMD_FEATURE_EDX_PGE, X86_CPUID_FEATURE_EDX_PGE);
5828 CPUID_GST_FEATURE2_IGN( uEdx, X86_CPUID_AMD_FEATURE_EDX_MCA, X86_CPUID_FEATURE_EDX_MCA);
5829 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_CMOV, X86_CPUID_FEATURE_EDX_CMOV); // -> EMU
5830 CPUID_GST_FEATURE2_IGN( uEdx, X86_CPUID_AMD_FEATURE_EDX_PAT, X86_CPUID_FEATURE_EDX_PAT);
5831 CPUID_GST_FEATURE2_IGN( uEdx, X86_CPUID_AMD_FEATURE_EDX_PSE36, X86_CPUID_FEATURE_EDX_PSE36);
5832 CPUID_GST_AMD_FEATURE_WRN(Ext, uEdx, RT_BIT_32(18) /*reserved*/);
5833 CPUID_GST_AMD_FEATURE_WRN(Ext, uEdx, RT_BIT_32(19) /*reserved*/);
5834 CPUID_GST_FEATURE_RET( Ext, uEdx, X86_CPUID_EXT_FEATURE_EDX_NX);
5835 CPUID_GST_FEATURE_WRN( Ext, uEdx, RT_BIT_32(21) /*reserved*/);
5836 CPUID_GST_FEATURE_RET( Ext, uEdx, X86_CPUID_AMD_FEATURE_EDX_AXMMX);
5837 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_MMX, X86_CPUID_FEATURE_EDX_MMX); // -> EMU
5838 CPUID_GST_FEATURE2_RET( uEdx, X86_CPUID_AMD_FEATURE_EDX_FXSR, X86_CPUID_FEATURE_EDX_FXSR); // -> EMU
5839 CPUID_GST_AMD_FEATURE_RET(Ext, uEdx, X86_CPUID_AMD_FEATURE_EDX_FFXSR);
5840 CPUID_GST_AMD_FEATURE_RET(Ext, uEdx, X86_CPUID_EXT_FEATURE_EDX_PAGE1GB);
5841 CPUID_GST_AMD_FEATURE_RET(Ext, uEdx, X86_CPUID_EXT_FEATURE_EDX_RDTSCP);
5842 CPUID_GST_FEATURE_IGN( Ext, uEdx, RT_BIT_32(28) /*reserved*/);
5843 CPUID_GST_FEATURE_RET( Ext, uEdx, X86_CPUID_EXT_FEATURE_EDX_LONG_MODE);
5844 CPUID_GST_AMD_FEATURE_RET(Ext, uEdx, X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX);
5845 CPUID_GST_AMD_FEATURE_RET(Ext, uEdx, X86_CPUID_AMD_FEATURE_EDX_3DNOW);
5846 }
5847
5848 /** @todo check leaf 7 */
5849
5850 /* CPUID(d) - XCR0 stuff - takes ECX as input.
5851 * ECX=0: EAX - Valid bits in XCR0[31:0].
5852 * EBX - Maximum state size as per current XCR0 value.
5853 * ECX - Maximum state size for all supported features.
5854 * EDX - Valid bits in XCR0[63:32].
5855 * ECX=1: EAX - Various X-features.
5856 * EBX - Maximum state size as per current XCR0|IA32_XSS value.
5857 * ECX - Valid bits in IA32_XSS[31:0].
5858 * EDX - Valid bits in IA32_XSS[63:32].
5859 * ECX=N, where N in 2..63 and indicates a bit in XCR0 and/or IA32_XSS,
5860 * if the bit invalid all four registers are set to zero.
5861 * EAX - The state size for this feature.
5862 * EBX - The state byte offset of this feature.
5863 * ECX - Bit 0 indicates whether this sub-leaf maps to a valid IA32_XSS bit (=1) or a valid XCR0 bit (=0).
5864 * EDX - Reserved, but is set to zero if invalid sub-leaf index.
5865 */
5866 uint64_t fGuestXcr0Mask = 0;
5867 PCPUMCPUIDLEAF pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x0000000d), 0);
5868 if ( pCurLeaf
5869 && (aGuestCpuIdStd[1].uEcx & X86_CPUID_FEATURE_ECX_XSAVE)
5870 && ( pCurLeaf->uEax
5871 || pCurLeaf->uEbx
5872 || pCurLeaf->uEcx
5873 || pCurLeaf->uEdx) )
5874 {
5875 fGuestXcr0Mask = RT_MAKE_U64(pCurLeaf->uEax, pCurLeaf->uEdx);
5876 if (fGuestXcr0Mask & ~pVM->cpum.s.fXStateHostMask)
5877 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS,
5878 N_("CPUID(0xd/0).EDX:EAX mismatch: %#llx saved, %#llx supported by the current host (XCR0 bits)"),
5879 fGuestXcr0Mask, pVM->cpum.s.fXStateHostMask);
5880 if ((fGuestXcr0Mask & (XSAVE_C_X87 | XSAVE_C_SSE)) != (XSAVE_C_X87 | XSAVE_C_SSE))
5881 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS,
5882 N_("CPUID(0xd/0).EDX:EAX missing mandatory X87 or SSE bits: %#RX64"), fGuestXcr0Mask);
5883
5884 /* We don't support any additional features yet. */
5885 pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x0000000d), 1);
5886 if (pCurLeaf && pCurLeaf->uEax)
5887 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS,
5888 N_("CPUID(0xd/1).EAX=%#x, expected zero"), pCurLeaf->uEax);
5889 if (pCurLeaf && (pCurLeaf->uEcx || pCurLeaf->uEdx))
5890 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS,
5891 N_("CPUID(0xd/1).EDX:ECX=%#llx, expected zero"),
5892 RT_MAKE_U64(pCurLeaf->uEdx, pCurLeaf->uEcx));
5893
5894
5895 for (uint32_t uSubLeaf = 2; uSubLeaf < 64; uSubLeaf++)
5896 {
5897 pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x0000000d), uSubLeaf);
5898 if (pCurLeaf)
5899 {
5900 /* If advertised, the state component offset and size must match the one used by host. */
5901 if (pCurLeaf->uEax || pCurLeaf->uEbx || pCurLeaf->uEcx || pCurLeaf->uEdx)
5902 {
5903 CPUMCPUID RawHost;
5904 ASMCpuIdExSlow(UINT32_C(0x0000000d), 0, uSubLeaf, 0,
5905 &RawHost.uEax, &RawHost.uEbx, &RawHost.uEcx, &RawHost.uEdx);
5906 if ( RawHost.uEbx != pCurLeaf->uEbx
5907 || RawHost.uEax != pCurLeaf->uEax)
5908 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS,
5909 N_("CPUID(0xd/%#x).EBX/EAX=%#x/%#x, current host uses %#x/%#x (offset/size)"),
5910 uSubLeaf, pCurLeaf->uEbx, pCurLeaf->uEax, RawHost.uEbx, RawHost.uEax);
5911 }
5912 }
5913 }
5914 }
5915 /* Clear leaf 0xd just in case we're loading an old state... */
5916 else if (pCurLeaf)
5917 {
5918 for (uint32_t uSubLeaf = 0; uSubLeaf < 64; uSubLeaf++)
5919 {
5920 pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x0000000d), uSubLeaf);
5921 if (pCurLeaf)
5922 {
5923 AssertLogRelMsg( uVersion <= CPUM_SAVED_STATE_VERSION_PUT_STRUCT
5924 || ( pCurLeaf->uEax == 0
5925 && pCurLeaf->uEbx == 0
5926 && pCurLeaf->uEcx == 0
5927 && pCurLeaf->uEdx == 0),
5928 ("uVersion=%#x; %#x %#x %#x %#x\n",
5929 uVersion, pCurLeaf->uEax, pCurLeaf->uEbx, pCurLeaf->uEcx, pCurLeaf->uEdx));
5930 pCurLeaf->uEax = pCurLeaf->uEbx = pCurLeaf->uEcx = pCurLeaf->uEdx = 0;
5931 }
5932 }
5933 }
5934
5935 /* Update the fXStateGuestMask value for the VM. */
5936 if (pVM->cpum.s.fXStateGuestMask != fGuestXcr0Mask)
5937 {
5938 LogRel(("CPUM: fXStateGuestMask=%#llx -> %#llx\n", pVM->cpum.s.fXStateGuestMask, fGuestXcr0Mask));
5939 pVM->cpum.s.fXStateGuestMask = fGuestXcr0Mask;
5940 if (!fGuestXcr0Mask && (aGuestCpuIdStd[1].uEcx & X86_CPUID_FEATURE_ECX_XSAVE))
5941 return SSMR3SetLoadError(pSSM, VERR_SSM_LOAD_CPUID_MISMATCH, RT_SRC_POS,
5942 N_("Internal Processing Error: XSAVE feature bit enabled, but leaf 0xd is empty."));
5943 }
5944
5945#undef CPUID_CHECK_RET
5946#undef CPUID_CHECK_WRN
5947#undef CPUID_CHECK2_RET
5948#undef CPUID_CHECK2_WRN
5949#undef CPUID_RAW_FEATURE_RET
5950#undef CPUID_RAW_FEATURE_WRN
5951#undef CPUID_RAW_FEATURE_IGN
5952#undef CPUID_GST_FEATURE_RET
5953#undef CPUID_GST_FEATURE_WRN
5954#undef CPUID_GST_FEATURE_EMU
5955#undef CPUID_GST_FEATURE_IGN
5956#undef CPUID_GST_FEATURE2_RET
5957#undef CPUID_GST_FEATURE2_WRN
5958#undef CPUID_GST_FEATURE2_EMU
5959#undef CPUID_GST_FEATURE2_IGN
5960#undef CPUID_GST_AMD_FEATURE_RET
5961#undef CPUID_GST_AMD_FEATURE_WRN
5962#undef CPUID_GST_AMD_FEATURE_EMU
5963#undef CPUID_GST_AMD_FEATURE_IGN
5964
5965 /*
5966 * We're good, commit the CPU ID leaves.
5967 */
5968 pVM->cpum.s.GuestInfo.DefCpuId = GuestDefCpuId;
5969 rc = cpumR3CpuIdInstallAndExplodeLeaves(pVM, &pVM->cpum.s, paLeaves, cLeaves, pMsrs);
5970 AssertLogRelRCReturn(rc, rc);
5971
5972 return VINF_SUCCESS;
5973}
5974
5975
5976/**
5977 * Loads the CPU ID leaves saved by pass 0.
5978 *
5979 * @returns VBox status code.
5980 * @param pVM The cross context VM structure.
5981 * @param pSSM The saved state handle.
5982 * @param uVersion The format version.
5983 * @param pMsrs The guest MSRs.
5984 */
5985int cpumR3LoadCpuId(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, PCCPUMMSRS pMsrs)
5986{
5987 AssertMsgReturn(uVersion >= CPUM_SAVED_STATE_VERSION_VER3_2, ("%u\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
5988
5989 /*
5990 * Load the CPUID leaves array first and call worker to do the rest, just so
5991 * we can free the memory when we need to without ending up in column 1000.
5992 */
5993 PCPUMCPUIDLEAF paLeaves;
5994 uint32_t cLeaves;
5995 int rc = cpumR3LoadGuestCpuIdArray(pVM, pSSM, uVersion, &paLeaves, &cLeaves);
5996 AssertRC(rc);
5997 if (RT_SUCCESS(rc))
5998 {
5999 rc = cpumR3LoadCpuIdInner(pVM, pSSM, uVersion, paLeaves, cLeaves, pMsrs);
6000 RTMemFree(paLeaves);
6001 }
6002 return rc;
6003}
6004
6005
6006
6007/**
6008 * Loads the CPU ID leaves saved by pass 0 in an pre 3.2 saved state.
6009 *
6010 * @returns VBox status code.
6011 * @param pVM The cross context VM structure.
6012 * @param pSSM The saved state handle.
6013 * @param uVersion The format version.
6014 */
6015int cpumR3LoadCpuIdPre32(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion)
6016{
6017 AssertMsgReturn(uVersion < CPUM_SAVED_STATE_VERSION_VER3_2, ("%u\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
6018
6019 /*
6020 * Restore the CPUID leaves.
6021 *
6022 * Note that we support restoring less than the current amount of standard
6023 * leaves because we've been allowed more is newer version of VBox.
6024 */
6025 uint32_t cElements;
6026 int rc = SSMR3GetU32(pSSM, &cElements); AssertRCReturn(rc, rc);
6027 if (cElements > RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdPatmStd))
6028 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
6029 SSMR3GetMem(pSSM, &pVM->cpum.s.aGuestCpuIdPatmStd[0], cElements*sizeof(pVM->cpum.s.aGuestCpuIdPatmStd[0]));
6030
6031 rc = SSMR3GetU32(pSSM, &cElements); AssertRCReturn(rc, rc);
6032 if (cElements != RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdPatmExt))
6033 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
6034 SSMR3GetMem(pSSM, &pVM->cpum.s.aGuestCpuIdPatmExt[0], sizeof(pVM->cpum.s.aGuestCpuIdPatmExt));
6035
6036 rc = SSMR3GetU32(pSSM, &cElements); AssertRCReturn(rc, rc);
6037 if (cElements != RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdPatmCentaur))
6038 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
6039 SSMR3GetMem(pSSM, &pVM->cpum.s.aGuestCpuIdPatmCentaur[0], sizeof(pVM->cpum.s.aGuestCpuIdPatmCentaur));
6040
6041 SSMR3GetMem(pSSM, &pVM->cpum.s.GuestInfo.DefCpuId, sizeof(pVM->cpum.s.GuestInfo.DefCpuId));
6042
6043 /*
6044 * Check that the basic cpuid id information is unchanged.
6045 */
6046 /** @todo we should check the 64 bits capabilities too! */
6047 uint32_t au32CpuId[8] = {0,0,0,0, 0,0,0,0};
6048 ASMCpuIdExSlow(0, 0, 0, 0, &au32CpuId[0], &au32CpuId[1], &au32CpuId[2], &au32CpuId[3]);
6049 ASMCpuIdExSlow(1, 0, 0, 0, &au32CpuId[4], &au32CpuId[5], &au32CpuId[6], &au32CpuId[7]);
6050 uint32_t au32CpuIdSaved[8];
6051 rc = SSMR3GetMem(pSSM, &au32CpuIdSaved[0], sizeof(au32CpuIdSaved));
6052 if (RT_SUCCESS(rc))
6053 {
6054 /* Ignore CPU stepping. */
6055 au32CpuId[4] &= 0xfffffff0;
6056 au32CpuIdSaved[4] &= 0xfffffff0;
6057
6058 /* Ignore APIC ID (AMD specs). */
6059 au32CpuId[5] &= ~0xff000000;
6060 au32CpuIdSaved[5] &= ~0xff000000;
6061
6062 /* Ignore the number of Logical CPUs (AMD specs). */
6063 au32CpuId[5] &= ~0x00ff0000;
6064 au32CpuIdSaved[5] &= ~0x00ff0000;
6065
6066 /* Ignore some advanced capability bits, that we don't expose to the guest. */
6067 au32CpuId[6] &= ~( X86_CPUID_FEATURE_ECX_DTES64
6068 | X86_CPUID_FEATURE_ECX_VMX
6069 | X86_CPUID_FEATURE_ECX_SMX
6070 | X86_CPUID_FEATURE_ECX_EST
6071 | X86_CPUID_FEATURE_ECX_TM2
6072 | X86_CPUID_FEATURE_ECX_CNTXID
6073 | X86_CPUID_FEATURE_ECX_TPRUPDATE
6074 | X86_CPUID_FEATURE_ECX_PDCM
6075 | X86_CPUID_FEATURE_ECX_DCA
6076 | X86_CPUID_FEATURE_ECX_X2APIC
6077 );
6078 au32CpuIdSaved[6] &= ~( X86_CPUID_FEATURE_ECX_DTES64
6079 | X86_CPUID_FEATURE_ECX_VMX
6080 | X86_CPUID_FEATURE_ECX_SMX
6081 | X86_CPUID_FEATURE_ECX_EST
6082 | X86_CPUID_FEATURE_ECX_TM2
6083 | X86_CPUID_FEATURE_ECX_CNTXID
6084 | X86_CPUID_FEATURE_ECX_TPRUPDATE
6085 | X86_CPUID_FEATURE_ECX_PDCM
6086 | X86_CPUID_FEATURE_ECX_DCA
6087 | X86_CPUID_FEATURE_ECX_X2APIC
6088 );
6089
6090 /* Make sure we don't forget to update the masks when enabling
6091 * features in the future.
6092 */
6093 AssertRelease(!(pVM->cpum.s.aGuestCpuIdPatmStd[1].uEcx &
6094 ( X86_CPUID_FEATURE_ECX_DTES64
6095 | X86_CPUID_FEATURE_ECX_VMX
6096 | X86_CPUID_FEATURE_ECX_SMX
6097 | X86_CPUID_FEATURE_ECX_EST
6098 | X86_CPUID_FEATURE_ECX_TM2
6099 | X86_CPUID_FEATURE_ECX_CNTXID
6100 | X86_CPUID_FEATURE_ECX_TPRUPDATE
6101 | X86_CPUID_FEATURE_ECX_PDCM
6102 | X86_CPUID_FEATURE_ECX_DCA
6103 | X86_CPUID_FEATURE_ECX_X2APIC
6104 )));
6105 /* do the compare */
6106 if (memcmp(au32CpuIdSaved, au32CpuId, sizeof(au32CpuIdSaved)))
6107 {
6108 if (SSMR3HandleGetAfter(pSSM) == SSMAFTER_DEBUG_IT)
6109 LogRel(("cpumR3LoadExec: CpuId mismatch! (ignored due to SSMAFTER_DEBUG_IT)\n"
6110 "Saved=%.*Rhxs\n"
6111 "Real =%.*Rhxs\n",
6112 sizeof(au32CpuIdSaved), au32CpuIdSaved,
6113 sizeof(au32CpuId), au32CpuId));
6114 else
6115 {
6116 LogRel(("cpumR3LoadExec: CpuId mismatch!\n"
6117 "Saved=%.*Rhxs\n"
6118 "Real =%.*Rhxs\n",
6119 sizeof(au32CpuIdSaved), au32CpuIdSaved,
6120 sizeof(au32CpuId), au32CpuId));
6121 rc = VERR_SSM_LOAD_CPUID_MISMATCH;
6122 }
6123 }
6124 }
6125
6126 return rc;
6127}
6128
6129
6130
6131/*
6132 *
6133 *
6134 * CPUID Info Handler.
6135 * CPUID Info Handler.
6136 * CPUID Info Handler.
6137 *
6138 *
6139 */
6140
6141
6142
6143/**
6144 * Get L1 cache / TLS associativity.
6145 */
6146static const char *getCacheAss(unsigned u, char *pszBuf)
6147{
6148 if (u == 0)
6149 return "res0 ";
6150 if (u == 1)
6151 return "direct";
6152 if (u == 255)
6153 return "fully";
6154 if (u >= 256)
6155 return "???";
6156
6157 RTStrPrintf(pszBuf, 16, "%d way", u);
6158 return pszBuf;
6159}
6160
6161
6162/**
6163 * Get L2 cache associativity.
6164 */
6165const char *getL2CacheAss(unsigned u)
6166{
6167 switch (u)
6168 {
6169 case 0: return "off ";
6170 case 1: return "direct";
6171 case 2: return "2 way ";
6172 case 3: return "res3 ";
6173 case 4: return "4 way ";
6174 case 5: return "res5 ";
6175 case 6: return "8 way ";
6176 case 7: return "res7 ";
6177 case 8: return "16 way";
6178 case 9: return "res9 ";
6179 case 10: return "res10 ";
6180 case 11: return "res11 ";
6181 case 12: return "res12 ";
6182 case 13: return "res13 ";
6183 case 14: return "res14 ";
6184 case 15: return "fully ";
6185 default: return "????";
6186 }
6187}
6188
6189
6190/** CPUID(1).EDX field descriptions. */
6191static DBGFREGSUBFIELD const g_aLeaf1EdxSubFields[] =
6192{
6193 DBGFREGSUBFIELD_RO("FPU\0" "x87 FPU on Chip", 0, 1, 0),
6194 DBGFREGSUBFIELD_RO("VME\0" "Virtual 8086 Mode Enhancements", 1, 1, 0),
6195 DBGFREGSUBFIELD_RO("DE\0" "Debugging extensions", 2, 1, 0),
6196 DBGFREGSUBFIELD_RO("PSE\0" "Page Size Extension", 3, 1, 0),
6197 DBGFREGSUBFIELD_RO("TSC\0" "Time Stamp Counter", 4, 1, 0),
6198 DBGFREGSUBFIELD_RO("MSR\0" "Model Specific Registers", 5, 1, 0),
6199 DBGFREGSUBFIELD_RO("PAE\0" "Physical Address Extension", 6, 1, 0),
6200 DBGFREGSUBFIELD_RO("MCE\0" "Machine Check Exception", 7, 1, 0),
6201 DBGFREGSUBFIELD_RO("CX8\0" "CMPXCHG8B instruction", 8, 1, 0),
6202 DBGFREGSUBFIELD_RO("APIC\0" "APIC On-Chip", 9, 1, 0),
6203 DBGFREGSUBFIELD_RO("SEP\0" "SYSENTER and SYSEXIT Present", 11, 1, 0),
6204 DBGFREGSUBFIELD_RO("MTRR\0" "Memory Type Range Registers", 12, 1, 0),
6205 DBGFREGSUBFIELD_RO("PGE\0" "PTE Global Bit", 13, 1, 0),
6206 DBGFREGSUBFIELD_RO("MCA\0" "Machine Check Architecture", 14, 1, 0),
6207 DBGFREGSUBFIELD_RO("CMOV\0" "Conditional Move instructions", 15, 1, 0),
6208 DBGFREGSUBFIELD_RO("PAT\0" "Page Attribute Table", 16, 1, 0),
6209 DBGFREGSUBFIELD_RO("PSE-36\0" "36-bit Page Size Extension", 17, 1, 0),
6210 DBGFREGSUBFIELD_RO("PSN\0" "Processor Serial Number", 18, 1, 0),
6211 DBGFREGSUBFIELD_RO("CLFSH\0" "CLFLUSH instruction", 19, 1, 0),
6212 DBGFREGSUBFIELD_RO("DS\0" "Debug Store", 21, 1, 0),
6213 DBGFREGSUBFIELD_RO("ACPI\0" "Thermal Mon. & Soft. Clock Ctrl.", 22, 1, 0),
6214 DBGFREGSUBFIELD_RO("MMX\0" "Intel MMX Technology", 23, 1, 0),
6215 DBGFREGSUBFIELD_RO("FXSR\0" "FXSAVE and FXRSTOR instructions", 24, 1, 0),
6216 DBGFREGSUBFIELD_RO("SSE\0" "SSE support", 25, 1, 0),
6217 DBGFREGSUBFIELD_RO("SSE2\0" "SSE2 support", 26, 1, 0),
6218 DBGFREGSUBFIELD_RO("SS\0" "Self Snoop", 27, 1, 0),
6219 DBGFREGSUBFIELD_RO("HTT\0" "Hyper-Threading Technology", 28, 1, 0),
6220 DBGFREGSUBFIELD_RO("TM\0" "Therm. Monitor", 29, 1, 0),
6221 DBGFREGSUBFIELD_RO("PBE\0" "Pending Break Enabled", 31, 1, 0),
6222 DBGFREGSUBFIELD_TERMINATOR()
6223};
6224
6225/** CPUID(1).ECX field descriptions. */
6226static DBGFREGSUBFIELD const g_aLeaf1EcxSubFields[] =
6227{
6228 DBGFREGSUBFIELD_RO("SSE3\0" "SSE3 support", 0, 1, 0),
6229 DBGFREGSUBFIELD_RO("PCLMUL\0" "PCLMULQDQ support (for AES-GCM)", 1, 1, 0),
6230 DBGFREGSUBFIELD_RO("DTES64\0" "DS Area 64-bit Layout", 2, 1, 0),
6231 DBGFREGSUBFIELD_RO("MONITOR\0" "MONITOR/MWAIT instructions", 3, 1, 0),
6232 DBGFREGSUBFIELD_RO("CPL-DS\0" "CPL Qualified Debug Store", 4, 1, 0),
6233 DBGFREGSUBFIELD_RO("VMX\0" "Virtual Machine Extensions", 5, 1, 0),
6234 DBGFREGSUBFIELD_RO("SMX\0" "Safer Mode Extensions", 6, 1, 0),
6235 DBGFREGSUBFIELD_RO("EST\0" "Enhanced SpeedStep Technology", 7, 1, 0),
6236 DBGFREGSUBFIELD_RO("TM2\0" "Terminal Monitor 2", 8, 1, 0),
6237 DBGFREGSUBFIELD_RO("SSSE3\0" "Supplemental Streaming SIMD Extensions 3", 9, 1, 0),
6238 DBGFREGSUBFIELD_RO("CNTX-ID\0" "L1 Context ID", 10, 1, 0),
6239 DBGFREGSUBFIELD_RO("SDBG\0" "Silicon Debug interface", 11, 1, 0),
6240 DBGFREGSUBFIELD_RO("FMA\0" "Fused Multiply Add extensions", 12, 1, 0),
6241 DBGFREGSUBFIELD_RO("CX16\0" "CMPXCHG16B instruction", 13, 1, 0),
6242 DBGFREGSUBFIELD_RO("TPRUPDATE\0" "xTPR Update Control", 14, 1, 0),
6243 DBGFREGSUBFIELD_RO("PDCM\0" "Perf/Debug Capability MSR", 15, 1, 0),
6244 DBGFREGSUBFIELD_RO("PCID\0" "Process Context Identifiers", 17, 1, 0),
6245 DBGFREGSUBFIELD_RO("DCA\0" "Direct Cache Access", 18, 1, 0),
6246 DBGFREGSUBFIELD_RO("SSE4_1\0" "SSE4_1 support", 19, 1, 0),
6247 DBGFREGSUBFIELD_RO("SSE4_2\0" "SSE4_2 support", 20, 1, 0),
6248 DBGFREGSUBFIELD_RO("X2APIC\0" "x2APIC support", 21, 1, 0),
6249 DBGFREGSUBFIELD_RO("MOVBE\0" "MOVBE instruction", 22, 1, 0),
6250 DBGFREGSUBFIELD_RO("POPCNT\0" "POPCNT instruction", 23, 1, 0),
6251 DBGFREGSUBFIELD_RO("TSCDEADL\0" "Time Stamp Counter Deadline", 24, 1, 0),
6252 DBGFREGSUBFIELD_RO("AES\0" "AES instructions", 25, 1, 0),
6253 DBGFREGSUBFIELD_RO("XSAVE\0" "XSAVE instruction", 26, 1, 0),
6254 DBGFREGSUBFIELD_RO("OSXSAVE\0" "OSXSAVE instruction", 27, 1, 0),
6255 DBGFREGSUBFIELD_RO("AVX\0" "AVX support", 28, 1, 0),
6256 DBGFREGSUBFIELD_RO("F16C\0" "16-bit floating point conversion instructions", 29, 1, 0),
6257 DBGFREGSUBFIELD_RO("RDRAND\0" "RDRAND instruction", 30, 1, 0),
6258 DBGFREGSUBFIELD_RO("HVP\0" "Hypervisor Present (we're a guest)", 31, 1, 0),
6259 DBGFREGSUBFIELD_TERMINATOR()
6260};
6261
6262/** CPUID(7,0).EBX field descriptions. */
6263static DBGFREGSUBFIELD const g_aLeaf7Sub0EbxSubFields[] =
6264{
6265 DBGFREGSUBFIELD_RO("FSGSBASE\0" "RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE instr.", 0, 1, 0),
6266 DBGFREGSUBFIELD_RO("TSCADJUST\0" "Supports MSR_IA32_TSC_ADJUST", 1, 1, 0),
6267 DBGFREGSUBFIELD_RO("SGX\0" "Supports Software Guard Extensions", 2, 1, 0),
6268 DBGFREGSUBFIELD_RO("BMI1\0" "Advanced Bit Manipulation extension 1", 3, 1, 0),
6269 DBGFREGSUBFIELD_RO("HLE\0" "Hardware Lock Elision", 4, 1, 0),
6270 DBGFREGSUBFIELD_RO("AVX2\0" "Advanced Vector Extensions 2", 5, 1, 0),
6271 DBGFREGSUBFIELD_RO("FDP_EXCPTN_ONLY\0" "FPU DP only updated on exceptions", 6, 1, 0),
6272 DBGFREGSUBFIELD_RO("SMEP\0" "Supervisor Mode Execution Prevention", 7, 1, 0),
6273 DBGFREGSUBFIELD_RO("BMI2\0" "Advanced Bit Manipulation extension 2", 8, 1, 0),
6274 DBGFREGSUBFIELD_RO("ERMS\0" "Enhanced REP MOVSB/STOSB instructions", 9, 1, 0),
6275 DBGFREGSUBFIELD_RO("INVPCID\0" "INVPCID instruction", 10, 1, 0),
6276 DBGFREGSUBFIELD_RO("RTM\0" "Restricted Transactional Memory", 11, 1, 0),
6277 DBGFREGSUBFIELD_RO("PQM\0" "Platform Quality of Service Monitoring", 12, 1, 0),
6278 DBGFREGSUBFIELD_RO("DEPFPU_CS_DS\0" "Deprecates FPU CS, FPU DS values if set", 13, 1, 0),
6279 DBGFREGSUBFIELD_RO("MPE\0" "Intel Memory Protection Extensions", 14, 1, 0),
6280 DBGFREGSUBFIELD_RO("PQE\0" "Platform Quality of Service Enforcement", 15, 1, 0),
6281 DBGFREGSUBFIELD_RO("AVX512F\0" "AVX512 Foundation instructions", 16, 1, 0),
6282 DBGFREGSUBFIELD_RO("RDSEED\0" "RDSEED instruction", 18, 1, 0),
6283 DBGFREGSUBFIELD_RO("ADX\0" "ADCX/ADOX instructions", 19, 1, 0),
6284 DBGFREGSUBFIELD_RO("SMAP\0" "Supervisor Mode Access Prevention", 20, 1, 0),
6285 DBGFREGSUBFIELD_RO("CLFLUSHOPT\0" "CLFLUSHOPT (Cache Line Flush) instruction", 23, 1, 0),
6286 DBGFREGSUBFIELD_RO("INTEL_PT\0" "Intel Processor Trace", 25, 1, 0),
6287 DBGFREGSUBFIELD_RO("AVX512PF\0" "AVX512 Prefetch instructions", 26, 1, 0),
6288 DBGFREGSUBFIELD_RO("AVX512ER\0" "AVX512 Exponential & Reciprocal instructions", 27, 1, 0),
6289 DBGFREGSUBFIELD_RO("AVX512CD\0" "AVX512 Conflict Detection instructions", 28, 1, 0),
6290 DBGFREGSUBFIELD_RO("SHA\0" "Secure Hash Algorithm extensions", 29, 1, 0),
6291 DBGFREGSUBFIELD_TERMINATOR()
6292};
6293
6294/** CPUID(7,0).ECX field descriptions. */
6295static DBGFREGSUBFIELD const g_aLeaf7Sub0EcxSubFields[] =
6296{
6297 DBGFREGSUBFIELD_RO("PREFETCHWT1\0" "PREFETCHWT1 instruction", 0, 1, 0),
6298 DBGFREGSUBFIELD_RO("UMIP\0" "User mode insturction prevention", 2, 1, 0),
6299 DBGFREGSUBFIELD_RO("PKU\0" "Protection Key for Usermode pages", 3, 1, 0),
6300 DBGFREGSUBFIELD_RO("OSPKE\0" "CR4.PKU mirror", 4, 1, 0),
6301 DBGFREGSUBFIELD_RO("MAWAU\0" "Value used by BNDLDX & BNDSTX", 17, 5, 0),
6302 DBGFREGSUBFIELD_RO("RDPID\0" "Read processor ID support", 22, 1, 0),
6303 DBGFREGSUBFIELD_RO("SGX_LC\0" "Supports SGX Launch Configuration", 30, 1, 0),
6304 DBGFREGSUBFIELD_TERMINATOR()
6305};
6306
6307/** CPUID(7,0).EDX field descriptions. */
6308static DBGFREGSUBFIELD const g_aLeaf7Sub0EdxSubFields[] =
6309{
6310 DBGFREGSUBFIELD_RO("MD_CLEAR\0" "Supports MDS related buffer clearing", 10, 1, 0),
6311 DBGFREGSUBFIELD_RO("IBRS_IBPB\0" "IA32_SPEC_CTRL.IBRS and IA32_PRED_CMD.IBPB", 26, 1, 0),
6312 DBGFREGSUBFIELD_RO("STIBP\0" "Supports IA32_SPEC_CTRL.STIBP", 27, 1, 0),
6313 DBGFREGSUBFIELD_RO("FLUSH_CMD\0" "Supports IA32_FLUSH_CMD", 28, 1, 0),
6314 DBGFREGSUBFIELD_RO("ARCHCAP\0" "Supports IA32_ARCH_CAP", 29, 1, 0),
6315 DBGFREGSUBFIELD_RO("CORECAP\0" "Supports IA32_CORE_CAP", 30, 1, 0),
6316 DBGFREGSUBFIELD_RO("SSBD\0" "Supports IA32_SPEC_CTRL.SSBD", 31, 1, 0),
6317 DBGFREGSUBFIELD_TERMINATOR()
6318};
6319
6320
6321/** CPUID(13,0).EAX+EDX, XCR0, ++ bit descriptions. */
6322static DBGFREGSUBFIELD const g_aXSaveStateBits[] =
6323{
6324 DBGFREGSUBFIELD_RO("x87\0" "Legacy FPU state", 0, 1, 0),
6325 DBGFREGSUBFIELD_RO("SSE\0" "128-bit SSE state", 1, 1, 0),
6326 DBGFREGSUBFIELD_RO("YMM_Hi128\0" "Upper 128 bits of YMM0-15 (AVX)", 2, 1, 0),
6327 DBGFREGSUBFIELD_RO("BNDREGS\0" "MPX bound register state", 3, 1, 0),
6328 DBGFREGSUBFIELD_RO("BNDCSR\0" "MPX bound config and status state", 4, 1, 0),
6329 DBGFREGSUBFIELD_RO("Opmask\0" "opmask state", 5, 1, 0),
6330 DBGFREGSUBFIELD_RO("ZMM_Hi256\0" "Upper 256 bits of ZMM0-15 (AVX-512)", 6, 1, 0),
6331 DBGFREGSUBFIELD_RO("Hi16_ZMM\0" "512-bits ZMM16-31 state (AVX-512)", 7, 1, 0),
6332 DBGFREGSUBFIELD_RO("LWP\0" "Lightweight Profiling (AMD)", 62, 1, 0),
6333 DBGFREGSUBFIELD_TERMINATOR()
6334};
6335
6336/** CPUID(13,1).EAX field descriptions. */
6337static DBGFREGSUBFIELD const g_aLeaf13Sub1EaxSubFields[] =
6338{
6339 DBGFREGSUBFIELD_RO("XSAVEOPT\0" "XSAVEOPT is available", 0, 1, 0),
6340 DBGFREGSUBFIELD_RO("XSAVEC\0" "XSAVEC and compacted XRSTOR supported", 1, 1, 0),
6341 DBGFREGSUBFIELD_RO("XGETBC1\0" "XGETBV with ECX=1 supported", 2, 1, 0),
6342 DBGFREGSUBFIELD_RO("XSAVES\0" "XSAVES/XRSTORS and IA32_XSS supported", 3, 1, 0),
6343 DBGFREGSUBFIELD_TERMINATOR()
6344};
6345
6346
6347/** CPUID(0x80000001,0).EDX field descriptions. */
6348static DBGFREGSUBFIELD const g_aExtLeaf1EdxSubFields[] =
6349{
6350 DBGFREGSUBFIELD_RO("FPU\0" "x87 FPU on Chip", 0, 1, 0),
6351 DBGFREGSUBFIELD_RO("VME\0" "Virtual 8086 Mode Enhancements", 1, 1, 0),
6352 DBGFREGSUBFIELD_RO("DE\0" "Debugging extensions", 2, 1, 0),
6353 DBGFREGSUBFIELD_RO("PSE\0" "Page Size Extension", 3, 1, 0),
6354 DBGFREGSUBFIELD_RO("TSC\0" "Time Stamp Counter", 4, 1, 0),
6355 DBGFREGSUBFIELD_RO("MSR\0" "K86 Model Specific Registers", 5, 1, 0),
6356 DBGFREGSUBFIELD_RO("PAE\0" "Physical Address Extension", 6, 1, 0),
6357 DBGFREGSUBFIELD_RO("MCE\0" "Machine Check Exception", 7, 1, 0),
6358 DBGFREGSUBFIELD_RO("CX8\0" "CMPXCHG8B instruction", 8, 1, 0),
6359 DBGFREGSUBFIELD_RO("APIC\0" "APIC On-Chip", 9, 1, 0),
6360 DBGFREGSUBFIELD_RO("SEP\0" "SYSCALL/SYSRET", 11, 1, 0),
6361 DBGFREGSUBFIELD_RO("MTRR\0" "Memory Type Range Registers", 12, 1, 0),
6362 DBGFREGSUBFIELD_RO("PGE\0" "PTE Global Bit", 13, 1, 0),
6363 DBGFREGSUBFIELD_RO("MCA\0" "Machine Check Architecture", 14, 1, 0),
6364 DBGFREGSUBFIELD_RO("CMOV\0" "Conditional Move instructions", 15, 1, 0),
6365 DBGFREGSUBFIELD_RO("PAT\0" "Page Attribute Table", 16, 1, 0),
6366 DBGFREGSUBFIELD_RO("PSE-36\0" "36-bit Page Size Extension", 17, 1, 0),
6367 DBGFREGSUBFIELD_RO("NX\0" "No-Execute/Execute-Disable", 20, 1, 0),
6368 DBGFREGSUBFIELD_RO("AXMMX\0" "AMD Extensions to MMX instructions", 22, 1, 0),
6369 DBGFREGSUBFIELD_RO("MMX\0" "Intel MMX Technology", 23, 1, 0),
6370 DBGFREGSUBFIELD_RO("FXSR\0" "FXSAVE and FXRSTOR Instructions", 24, 1, 0),
6371 DBGFREGSUBFIELD_RO("FFXSR\0" "AMD fast FXSAVE and FXRSTOR instructions", 25, 1, 0),
6372 DBGFREGSUBFIELD_RO("Page1GB\0" "1 GB large page", 26, 1, 0),
6373 DBGFREGSUBFIELD_RO("RDTSCP\0" "RDTSCP instruction", 27, 1, 0),
6374 DBGFREGSUBFIELD_RO("LM\0" "AMD64 Long Mode", 29, 1, 0),
6375 DBGFREGSUBFIELD_RO("3DNOWEXT\0" "AMD Extensions to 3DNow", 30, 1, 0),
6376 DBGFREGSUBFIELD_RO("3DNOW\0" "AMD 3DNow", 31, 1, 0),
6377 DBGFREGSUBFIELD_TERMINATOR()
6378};
6379
6380/** CPUID(0x80000001,0).ECX field descriptions. */
6381static DBGFREGSUBFIELD const g_aExtLeaf1EcxSubFields[] =
6382{
6383 DBGFREGSUBFIELD_RO("LahfSahf\0" "LAHF/SAHF support in 64-bit mode", 0, 1, 0),
6384 DBGFREGSUBFIELD_RO("CmpLegacy\0" "Core multi-processing legacy mode", 1, 1, 0),
6385 DBGFREGSUBFIELD_RO("SVM\0" "AMD Secure Virtual Machine extensions", 2, 1, 0),
6386 DBGFREGSUBFIELD_RO("EXTAPIC\0" "AMD Extended APIC registers", 3, 1, 0),
6387 DBGFREGSUBFIELD_RO("CR8L\0" "AMD LOCK MOV CR0 means MOV CR8", 4, 1, 0),
6388 DBGFREGSUBFIELD_RO("ABM\0" "AMD Advanced Bit Manipulation", 5, 1, 0),
6389 DBGFREGSUBFIELD_RO("SSE4A\0" "SSE4A instructions", 6, 1, 0),
6390 DBGFREGSUBFIELD_RO("MISALIGNSSE\0" "AMD Misaligned SSE mode", 7, 1, 0),
6391 DBGFREGSUBFIELD_RO("3DNOWPRF\0" "AMD PREFETCH and PREFETCHW instructions", 8, 1, 0),
6392 DBGFREGSUBFIELD_RO("OSVW\0" "AMD OS Visible Workaround", 9, 1, 0),
6393 DBGFREGSUBFIELD_RO("IBS\0" "Instruct Based Sampling", 10, 1, 0),
6394 DBGFREGSUBFIELD_RO("XOP\0" "Extended Operation support", 11, 1, 0),
6395 DBGFREGSUBFIELD_RO("SKINIT\0" "SKINIT, STGI, and DEV support", 12, 1, 0),
6396 DBGFREGSUBFIELD_RO("WDT\0" "AMD Watchdog Timer support", 13, 1, 0),
6397 DBGFREGSUBFIELD_RO("LWP\0" "Lightweight Profiling support", 15, 1, 0),
6398 DBGFREGSUBFIELD_RO("FMA4\0" "Four operand FMA instruction support", 16, 1, 0),
6399 DBGFREGSUBFIELD_RO("NodeId\0" "NodeId in MSR C001_100C", 19, 1, 0),
6400 DBGFREGSUBFIELD_RO("TBM\0" "Trailing Bit Manipulation instructions", 21, 1, 0),
6401 DBGFREGSUBFIELD_RO("TOPOEXT\0" "Topology Extensions", 22, 1, 0),
6402 DBGFREGSUBFIELD_RO("PRFEXTCORE\0" "Performance Counter Extensions support", 23, 1, 0),
6403 DBGFREGSUBFIELD_RO("PRFEXTNB\0" "NB Performance Counter Extensions support", 24, 1, 0),
6404 DBGFREGSUBFIELD_RO("DATABPEXT\0" "Data-access Breakpoint Extension", 26, 1, 0),
6405 DBGFREGSUBFIELD_RO("PERFTSC\0" "Performance Time Stamp Counter", 27, 1, 0),
6406 DBGFREGSUBFIELD_RO("PCX_L2I\0" "L2I/L3 Performance Counter Extensions", 28, 1, 0),
6407 DBGFREGSUBFIELD_RO("MWAITX\0" "MWAITX and MONITORX instructions", 29, 1, 0),
6408 DBGFREGSUBFIELD_TERMINATOR()
6409};
6410
6411/** CPUID(0x8000000a,0).EDX field descriptions. */
6412static DBGFREGSUBFIELD const g_aExtLeafAEdxSubFields[] =
6413{
6414 DBGFREGSUBFIELD_RO("NP\0" "Nested Paging", 0, 1, 0),
6415 DBGFREGSUBFIELD_RO("LbrVirt\0" "Last Branch Record Virtualization", 1, 1, 0),
6416 DBGFREGSUBFIELD_RO("SVML\0" "SVM Lock", 2, 1, 0),
6417 DBGFREGSUBFIELD_RO("NRIPS\0" "NextRIP Save", 3, 1, 0),
6418 DBGFREGSUBFIELD_RO("TscRateMsr\0" "MSR based TSC rate control", 4, 1, 0),
6419 DBGFREGSUBFIELD_RO("VmcbClean\0" "VMCB clean bits", 5, 1, 0),
6420 DBGFREGSUBFIELD_RO("FlushByASID\0" "Flush by ASID", 6, 1, 0),
6421 DBGFREGSUBFIELD_RO("DecodeAssists\0" "Decode Assists", 7, 1, 0),
6422 DBGFREGSUBFIELD_RO("PauseFilter\0" "Pause intercept filter", 10, 1, 0),
6423 DBGFREGSUBFIELD_RO("PauseFilterThreshold\0" "Pause filter threshold", 12, 1, 0),
6424 DBGFREGSUBFIELD_RO("AVIC\0" "Advanced Virtual Interrupt Controller", 13, 1, 0),
6425 DBGFREGSUBFIELD_RO("VMSAVEVirt\0" "VMSAVE and VMLOAD Virtualization", 15, 1, 0),
6426 DBGFREGSUBFIELD_RO("VGIF\0" "Virtual Global-Interrupt Flag", 16, 1, 0),
6427 DBGFREGSUBFIELD_RO("GMET\0" "Guest Mode Execute Trap Extension", 17, 1, 0),
6428 DBGFREGSUBFIELD_TERMINATOR()
6429};
6430
6431
6432/** CPUID(0x80000007,0).EDX field descriptions. */
6433static DBGFREGSUBFIELD const g_aExtLeaf7EdxSubFields[] =
6434{
6435 DBGFREGSUBFIELD_RO("TS\0" "Temperature Sensor", 0, 1, 0),
6436 DBGFREGSUBFIELD_RO("FID\0" "Frequency ID control", 1, 1, 0),
6437 DBGFREGSUBFIELD_RO("VID\0" "Voltage ID control", 2, 1, 0),
6438 DBGFREGSUBFIELD_RO("VID\0" "Voltage ID control", 2, 1, 0),
6439 DBGFREGSUBFIELD_RO("TTP\0" "Thermal Trip", 3, 1, 0),
6440 DBGFREGSUBFIELD_RO("TM\0" "Hardware Thermal Control (HTC)", 4, 1, 0),
6441 DBGFREGSUBFIELD_RO("100MHzSteps\0" "100 MHz Multiplier control", 6, 1, 0),
6442 DBGFREGSUBFIELD_RO("HwPstate\0" "Hardware P-state control", 7, 1, 0),
6443 DBGFREGSUBFIELD_RO("TscInvariant\0" "Invariant Time Stamp Counter", 8, 1, 0),
6444 DBGFREGSUBFIELD_RO("CBP\0" "Core Performance Boost", 9, 1, 0),
6445 DBGFREGSUBFIELD_RO("EffFreqRO\0" "Read-only Effective Frequency Interface", 10, 1, 0),
6446 DBGFREGSUBFIELD_RO("ProcFdbkIf\0" "Processor Feedback Interface", 11, 1, 0),
6447 DBGFREGSUBFIELD_RO("ProcPwrRep\0" "Core power reporting interface support", 12, 1, 0),
6448 DBGFREGSUBFIELD_TERMINATOR()
6449};
6450
6451/** CPUID(0x80000008,0).EBX field descriptions. */
6452static DBGFREGSUBFIELD const g_aExtLeaf8EbxSubFields[] =
6453{
6454 DBGFREGSUBFIELD_RO("CLZERO\0" "Clear zero instruction (cacheline)", 0, 1, 0),
6455 DBGFREGSUBFIELD_RO("IRPerf\0" "Instructions retired count support", 1, 1, 0),
6456 DBGFREGSUBFIELD_RO("XSaveErPtr\0" "Save/restore error pointers (FXSAVE/RSTOR*)", 2, 1, 0),
6457 DBGFREGSUBFIELD_RO("RDPRU\0" "RDPRU instruction", 4, 1, 0),
6458 DBGFREGSUBFIELD_RO("MCOMMIT\0" "MCOMMIT instruction", 8, 1, 0),
6459 DBGFREGSUBFIELD_RO("IBPB\0" "Supports the IBPB command in IA32_PRED_CMD", 12, 1, 0),
6460 DBGFREGSUBFIELD_TERMINATOR()
6461};
6462
6463
6464static void cpumR3CpuIdInfoMnemonicListU32(PCDBGFINFOHLP pHlp, uint32_t uVal, PCDBGFREGSUBFIELD pDesc,
6465 const char *pszLeadIn, uint32_t cchWidth)
6466{
6467 if (pszLeadIn)
6468 pHlp->pfnPrintf(pHlp, "%*s", cchWidth, pszLeadIn);
6469
6470 for (uint32_t iBit = 0; iBit < 32; iBit++)
6471 if (RT_BIT_32(iBit) & uVal)
6472 {
6473 while ( pDesc->pszName != NULL
6474 && iBit >= (uint32_t)pDesc->iFirstBit + pDesc->cBits)
6475 pDesc++;
6476 if ( pDesc->pszName != NULL
6477 && iBit - (uint32_t)pDesc->iFirstBit < (uint32_t)pDesc->cBits)
6478 {
6479 if (pDesc->cBits == 1)
6480 pHlp->pfnPrintf(pHlp, " %s", pDesc->pszName);
6481 else
6482 {
6483 uint32_t uFieldValue = uVal >> pDesc->iFirstBit;
6484 if (pDesc->cBits < 32)
6485 uFieldValue &= RT_BIT_32(pDesc->cBits) - UINT32_C(1);
6486 pHlp->pfnPrintf(pHlp, pDesc->cBits < 4 ? " %s=%u" : " %s=%#x", pDesc->pszName, uFieldValue);
6487 iBit = pDesc->iFirstBit + pDesc->cBits - 1;
6488 }
6489 }
6490 else
6491 pHlp->pfnPrintf(pHlp, " %u", iBit);
6492 }
6493 if (pszLeadIn)
6494 pHlp->pfnPrintf(pHlp, "\n");
6495}
6496
6497
6498static void cpumR3CpuIdInfoMnemonicListU64(PCDBGFINFOHLP pHlp, uint64_t uVal, PCDBGFREGSUBFIELD pDesc,
6499 const char *pszLeadIn, uint32_t cchWidth)
6500{
6501 if (pszLeadIn)
6502 pHlp->pfnPrintf(pHlp, "%*s", cchWidth, pszLeadIn);
6503
6504 for (uint32_t iBit = 0; iBit < 64; iBit++)
6505 if (RT_BIT_64(iBit) & uVal)
6506 {
6507 while ( pDesc->pszName != NULL
6508 && iBit >= (uint32_t)pDesc->iFirstBit + pDesc->cBits)
6509 pDesc++;
6510 if ( pDesc->pszName != NULL
6511 && iBit - (uint32_t)pDesc->iFirstBit < (uint32_t)pDesc->cBits)
6512 {
6513 if (pDesc->cBits == 1)
6514 pHlp->pfnPrintf(pHlp, " %s", pDesc->pszName);
6515 else
6516 {
6517 uint64_t uFieldValue = uVal >> pDesc->iFirstBit;
6518 if (pDesc->cBits < 64)
6519 uFieldValue &= RT_BIT_64(pDesc->cBits) - UINT64_C(1);
6520 pHlp->pfnPrintf(pHlp, pDesc->cBits < 4 ? " %s=%llu" : " %s=%#llx", pDesc->pszName, uFieldValue);
6521 iBit = pDesc->iFirstBit + pDesc->cBits - 1;
6522 }
6523 }
6524 else
6525 pHlp->pfnPrintf(pHlp, " %u", iBit);
6526 }
6527 if (pszLeadIn)
6528 pHlp->pfnPrintf(pHlp, "\n");
6529}
6530
6531
6532static void cpumR3CpuIdInfoValueWithMnemonicListU64(PCDBGFINFOHLP pHlp, uint64_t uVal, PCDBGFREGSUBFIELD pDesc,
6533 const char *pszLeadIn, uint32_t cchWidth)
6534{
6535 if (!uVal)
6536 pHlp->pfnPrintf(pHlp, "%*s %#010x`%08x\n", cchWidth, pszLeadIn, RT_HI_U32(uVal), RT_LO_U32(uVal));
6537 else
6538 {
6539 pHlp->pfnPrintf(pHlp, "%*s %#010x`%08x (", cchWidth, pszLeadIn, RT_HI_U32(uVal), RT_LO_U32(uVal));
6540 cpumR3CpuIdInfoMnemonicListU64(pHlp, uVal, pDesc, NULL, 0);
6541 pHlp->pfnPrintf(pHlp, " )\n");
6542 }
6543}
6544
6545
6546static void cpumR3CpuIdInfoVerboseCompareListU32(PCDBGFINFOHLP pHlp, uint32_t uVal1, uint32_t uVal2, PCDBGFREGSUBFIELD pDesc,
6547 uint32_t cchWidth)
6548{
6549 uint32_t uCombined = uVal1 | uVal2;
6550 for (uint32_t iBit = 0; iBit < 32; iBit++)
6551 if ( (RT_BIT_32(iBit) & uCombined)
6552 || (iBit == pDesc->iFirstBit && pDesc->pszName) )
6553 {
6554 while ( pDesc->pszName != NULL
6555 && iBit >= (uint32_t)pDesc->iFirstBit + pDesc->cBits)
6556 pDesc++;
6557
6558 if ( pDesc->pszName != NULL
6559 && iBit - (uint32_t)pDesc->iFirstBit < (uint32_t)pDesc->cBits)
6560 {
6561 size_t cchMnemonic = strlen(pDesc->pszName);
6562 const char *pszDesc = pDesc->pszName + cchMnemonic + 1;
6563 size_t cchDesc = strlen(pszDesc);
6564 uint32_t uFieldValue1 = uVal1 >> pDesc->iFirstBit;
6565 uint32_t uFieldValue2 = uVal2 >> pDesc->iFirstBit;
6566 if (pDesc->cBits < 32)
6567 {
6568 uFieldValue1 &= RT_BIT_32(pDesc->cBits) - UINT32_C(1);
6569 uFieldValue2 &= RT_BIT_32(pDesc->cBits) - UINT32_C(1);
6570 }
6571
6572 pHlp->pfnPrintf(pHlp, pDesc->cBits < 4 ? " %s - %s%*s= %u (%u)\n" : " %s - %s%*s= %#x (%#x)\n",
6573 pDesc->pszName, pszDesc,
6574 cchMnemonic + 3 + cchDesc < cchWidth ? cchWidth - (cchMnemonic + 3 + cchDesc) : 1, "",
6575 uFieldValue1, uFieldValue2);
6576
6577 iBit = pDesc->iFirstBit + pDesc->cBits - 1U;
6578 pDesc++;
6579 }
6580 else
6581 pHlp->pfnPrintf(pHlp, " %2u - Reserved%*s= %u (%u)\n", iBit, 13 < cchWidth ? cchWidth - 13 : 1, "",
6582 RT_BOOL(uVal1 & RT_BIT_32(iBit)), RT_BOOL(uVal2 & RT_BIT_32(iBit)));
6583 }
6584}
6585
6586
6587/**
6588 * Produces a detailed summary of standard leaf 0x00000001.
6589 *
6590 * @param pHlp The info helper functions.
6591 * @param pCurLeaf The 0x00000001 leaf.
6592 * @param fVerbose Whether to be very verbose or not.
6593 * @param fIntel Set if intel CPU.
6594 */
6595static void cpumR3CpuIdInfoStdLeaf1Details(PCDBGFINFOHLP pHlp, PCCPUMCPUIDLEAF pCurLeaf, bool fVerbose, bool fIntel)
6596{
6597 Assert(pCurLeaf); Assert(pCurLeaf->uLeaf == 1);
6598 static const char * const s_apszTypes[4] = { "primary", "overdrive", "MP", "reserved" };
6599 uint32_t uEAX = pCurLeaf->uEax;
6600 uint32_t uEBX = pCurLeaf->uEbx;
6601
6602 pHlp->pfnPrintf(pHlp,
6603 "%36s %2d \tExtended: %d \tEffective: %d\n"
6604 "%36s %2d \tExtended: %d \tEffective: %d\n"
6605 "%36s %d\n"
6606 "%36s %d (%s)\n"
6607 "%36s %#04x\n"
6608 "%36s %d\n"
6609 "%36s %d\n"
6610 "%36s %#04x\n"
6611 ,
6612 "Family:", (uEAX >> 8) & 0xf, (uEAX >> 20) & 0x7f, ASMGetCpuFamily(uEAX),
6613 "Model:", (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX, fIntel),
6614 "Stepping:", ASMGetCpuStepping(uEAX),
6615 "Type:", (uEAX >> 12) & 3, s_apszTypes[(uEAX >> 12) & 3],
6616 "APIC ID:", (uEBX >> 24) & 0xff,
6617 "Logical CPUs:",(uEBX >> 16) & 0xff,
6618 "CLFLUSH Size:",(uEBX >> 8) & 0xff,
6619 "Brand ID:", (uEBX >> 0) & 0xff);
6620 if (fVerbose)
6621 {
6622 CPUMCPUID Host;
6623 ASMCpuIdExSlow(1, 0, 0, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
6624 pHlp->pfnPrintf(pHlp, "Features\n");
6625 pHlp->pfnPrintf(pHlp, " Mnemonic - Description = guest (host)\n");
6626 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, pCurLeaf->uEdx, Host.uEdx, g_aLeaf1EdxSubFields, 56);
6627 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, pCurLeaf->uEcx, Host.uEcx, g_aLeaf1EcxSubFields, 56);
6628 }
6629 else
6630 {
6631 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEdx, g_aLeaf1EdxSubFields, "Features EDX:", 36);
6632 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEcx, g_aLeaf1EcxSubFields, "Features ECX:", 36);
6633 }
6634}
6635
6636
6637/**
6638 * Produces a detailed summary of standard leaf 0x00000007.
6639 *
6640 * @param pHlp The info helper functions.
6641 * @param paLeaves The CPUID leaves array.
6642 * @param cLeaves The number of leaves in the array.
6643 * @param pCurLeaf The first 0x00000007 leaf.
6644 * @param fVerbose Whether to be very verbose or not.
6645 */
6646static void cpumR3CpuIdInfoStdLeaf7Details(PCDBGFINFOHLP pHlp, PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves,
6647 PCCPUMCPUIDLEAF pCurLeaf, bool fVerbose)
6648{
6649 Assert(pCurLeaf); Assert(pCurLeaf->uLeaf == 7);
6650 pHlp->pfnPrintf(pHlp, "Structured Extended Feature Flags Enumeration (leaf 7):\n");
6651 for (;;)
6652 {
6653 CPUMCPUID Host;
6654 ASMCpuIdExSlow(pCurLeaf->uLeaf, 0, pCurLeaf->uSubLeaf, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
6655
6656 switch (pCurLeaf->uSubLeaf)
6657 {
6658 case 0:
6659 if (fVerbose)
6660 {
6661 pHlp->pfnPrintf(pHlp, " Mnemonic - Description = guest (host)\n");
6662 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, pCurLeaf->uEbx, Host.uEbx, g_aLeaf7Sub0EbxSubFields, 56);
6663 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, pCurLeaf->uEcx, Host.uEcx, g_aLeaf7Sub0EcxSubFields, 56);
6664 if (pCurLeaf->uEdx || Host.uEdx)
6665 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, pCurLeaf->uEdx, Host.uEdx, g_aLeaf7Sub0EdxSubFields, 56);
6666 }
6667 else
6668 {
6669 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEbx, g_aLeaf7Sub0EbxSubFields, "Ext Features EBX:", 36);
6670 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEcx, g_aLeaf7Sub0EcxSubFields, "Ext Features ECX:", 36);
6671 if (pCurLeaf->uEdx)
6672 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEdx, g_aLeaf7Sub0EdxSubFields, "Ext Features EDX:", 36);
6673 }
6674 break;
6675
6676 default:
6677 if (pCurLeaf->uEdx || pCurLeaf->uEcx || pCurLeaf->uEbx)
6678 pHlp->pfnPrintf(pHlp, "Unknown extended feature sub-leaf #%u: EAX=%#x EBX=%#x ECX=%#x EDX=%#x\n",
6679 pCurLeaf->uSubLeaf, pCurLeaf->uEax, pCurLeaf->uEbx, pCurLeaf->uEcx, pCurLeaf->uEdx);
6680 break;
6681
6682 }
6683
6684 /* advance. */
6685 pCurLeaf++;
6686 if ( (uintptr_t)(pCurLeaf - paLeaves) >= cLeaves
6687 || pCurLeaf->uLeaf != 0x7)
6688 break;
6689 }
6690}
6691
6692
6693/**
6694 * Produces a detailed summary of standard leaf 0x0000000d.
6695 *
6696 * @param pHlp The info helper functions.
6697 * @param paLeaves The CPUID leaves array.
6698 * @param cLeaves The number of leaves in the array.
6699 * @param pCurLeaf The first 0x00000007 leaf.
6700 * @param fVerbose Whether to be very verbose or not.
6701 */
6702static void cpumR3CpuIdInfoStdLeaf13Details(PCDBGFINFOHLP pHlp, PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves,
6703 PCCPUMCPUIDLEAF pCurLeaf, bool fVerbose)
6704{
6705 RT_NOREF_PV(fVerbose);
6706 Assert(pCurLeaf); Assert(pCurLeaf->uLeaf == 13);
6707 pHlp->pfnPrintf(pHlp, "Processor Extended State Enumeration (leaf 0xd):\n");
6708 for (uint32_t uSubLeaf = 0; uSubLeaf < 64; uSubLeaf++)
6709 {
6710 CPUMCPUID Host;
6711 ASMCpuIdExSlow(UINT32_C(0x0000000d), 0, uSubLeaf, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
6712
6713 switch (uSubLeaf)
6714 {
6715 case 0:
6716 if (pCurLeaf && pCurLeaf->uSubLeaf == uSubLeaf)
6717 pHlp->pfnPrintf(pHlp, "%42s %#x/%#x\n", "XSAVE area cur/max size by XCR0, guest:",
6718 pCurLeaf->uEbx, pCurLeaf->uEcx);
6719 pHlp->pfnPrintf(pHlp, "%42s %#x/%#x\n", "XSAVE area cur/max size by XCR0, host:", Host.uEbx, Host.uEcx);
6720
6721 if (pCurLeaf && pCurLeaf->uSubLeaf == uSubLeaf)
6722 cpumR3CpuIdInfoValueWithMnemonicListU64(pHlp, RT_MAKE_U64(pCurLeaf->uEax, pCurLeaf->uEdx), g_aXSaveStateBits,
6723 "Valid XCR0 bits, guest:", 42);
6724 cpumR3CpuIdInfoValueWithMnemonicListU64(pHlp, RT_MAKE_U64(Host.uEax, Host.uEdx), g_aXSaveStateBits,
6725 "Valid XCR0 bits, host:", 42);
6726 break;
6727
6728 case 1:
6729 if (pCurLeaf && pCurLeaf->uSubLeaf == uSubLeaf)
6730 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEax, g_aLeaf13Sub1EaxSubFields, "XSAVE features, guest:", 42);
6731 cpumR3CpuIdInfoMnemonicListU32(pHlp, Host.uEax, g_aLeaf13Sub1EaxSubFields, "XSAVE features, host:", 42);
6732
6733 if (pCurLeaf && pCurLeaf->uSubLeaf == uSubLeaf)
6734 pHlp->pfnPrintf(pHlp, "%42s %#x\n", "XSAVE area cur size XCR0|XSS, guest:", pCurLeaf->uEbx);
6735 pHlp->pfnPrintf(pHlp, "%42s %#x\n", "XSAVE area cur size XCR0|XSS, host:", Host.uEbx);
6736
6737 if (pCurLeaf && pCurLeaf->uSubLeaf == uSubLeaf)
6738 cpumR3CpuIdInfoValueWithMnemonicListU64(pHlp, RT_MAKE_U64(pCurLeaf->uEcx, pCurLeaf->uEdx), g_aXSaveStateBits,
6739 " Valid IA32_XSS bits, guest:", 42);
6740 cpumR3CpuIdInfoValueWithMnemonicListU64(pHlp, RT_MAKE_U64(Host.uEdx, Host.uEcx), g_aXSaveStateBits,
6741 " Valid IA32_XSS bits, host:", 42);
6742 break;
6743
6744 default:
6745 if ( pCurLeaf
6746 && pCurLeaf->uSubLeaf == uSubLeaf
6747 && (pCurLeaf->uEax || pCurLeaf->uEbx || pCurLeaf->uEcx || pCurLeaf->uEdx) )
6748 {
6749 pHlp->pfnPrintf(pHlp, " State #%u, guest: off=%#06x, cb=%#06x %s", uSubLeaf, pCurLeaf->uEbx,
6750 pCurLeaf->uEax, pCurLeaf->uEcx & RT_BIT_32(0) ? "XCR0-bit" : "IA32_XSS-bit");
6751 if (pCurLeaf->uEcx & ~RT_BIT_32(0))
6752 pHlp->pfnPrintf(pHlp, " ECX[reserved]=%#x\n", pCurLeaf->uEcx & ~RT_BIT_32(0));
6753 if (pCurLeaf->uEdx)
6754 pHlp->pfnPrintf(pHlp, " EDX[reserved]=%#x\n", pCurLeaf->uEdx);
6755 pHlp->pfnPrintf(pHlp, " --");
6756 cpumR3CpuIdInfoMnemonicListU64(pHlp, RT_BIT_64(uSubLeaf), g_aXSaveStateBits, NULL, 0);
6757 pHlp->pfnPrintf(pHlp, "\n");
6758 }
6759 if (Host.uEax || Host.uEbx || Host.uEcx || Host.uEdx)
6760 {
6761 pHlp->pfnPrintf(pHlp, " State #%u, host: off=%#06x, cb=%#06x %s", uSubLeaf, Host.uEbx,
6762 Host.uEax, Host.uEcx & RT_BIT_32(0) ? "XCR0-bit" : "IA32_XSS-bit");
6763 if (Host.uEcx & ~RT_BIT_32(0))
6764 pHlp->pfnPrintf(pHlp, " ECX[reserved]=%#x\n", Host.uEcx & ~RT_BIT_32(0));
6765 if (Host.uEdx)
6766 pHlp->pfnPrintf(pHlp, " EDX[reserved]=%#x\n", Host.uEdx);
6767 pHlp->pfnPrintf(pHlp, " --");
6768 cpumR3CpuIdInfoMnemonicListU64(pHlp, RT_BIT_64(uSubLeaf), g_aXSaveStateBits, NULL, 0);
6769 pHlp->pfnPrintf(pHlp, "\n");
6770 }
6771 break;
6772
6773 }
6774
6775 /* advance. */
6776 if (pCurLeaf)
6777 {
6778 while ( (uintptr_t)(pCurLeaf - paLeaves) < cLeaves
6779 && pCurLeaf->uSubLeaf <= uSubLeaf
6780 && pCurLeaf->uLeaf == UINT32_C(0x0000000d))
6781 pCurLeaf++;
6782 if ( (uintptr_t)(pCurLeaf - paLeaves) >= cLeaves
6783 || pCurLeaf->uLeaf != UINT32_C(0x0000000d))
6784 pCurLeaf = NULL;
6785 }
6786 }
6787}
6788
6789
6790static PCCPUMCPUIDLEAF cpumR3CpuIdInfoRawRange(PCDBGFINFOHLP pHlp, PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves,
6791 PCCPUMCPUIDLEAF pCurLeaf, uint32_t uUpToLeaf, const char *pszTitle)
6792{
6793 if ( (uintptr_t)(pCurLeaf - paLeaves) < cLeaves
6794 && pCurLeaf->uLeaf <= uUpToLeaf)
6795 {
6796 pHlp->pfnPrintf(pHlp,
6797 " %s\n"
6798 " Leaf/sub-leaf eax ebx ecx edx\n", pszTitle);
6799 while ( (uintptr_t)(pCurLeaf - paLeaves) < cLeaves
6800 && pCurLeaf->uLeaf <= uUpToLeaf)
6801 {
6802 CPUMCPUID Host;
6803 ASMCpuIdExSlow(pCurLeaf->uLeaf, 0, pCurLeaf->uSubLeaf, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
6804 pHlp->pfnPrintf(pHlp,
6805 "Gst: %08x/%04x %08x %08x %08x %08x\n"
6806 "Hst: %08x %08x %08x %08x\n",
6807 pCurLeaf->uLeaf, pCurLeaf->uSubLeaf, pCurLeaf->uEax, pCurLeaf->uEbx, pCurLeaf->uEcx, pCurLeaf->uEdx,
6808 Host.uEax, Host.uEbx, Host.uEcx, Host.uEdx);
6809 pCurLeaf++;
6810 }
6811 }
6812
6813 return pCurLeaf;
6814}
6815
6816
6817/**
6818 * Display the guest CpuId leaves.
6819 *
6820 * @param pVM The cross context VM structure.
6821 * @param pHlp The info helper functions.
6822 * @param pszArgs "terse", "default" or "verbose".
6823 */
6824DECLCALLBACK(void) cpumR3CpuIdInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
6825{
6826 /*
6827 * Parse the argument.
6828 */
6829 unsigned iVerbosity = 1;
6830 if (pszArgs)
6831 {
6832 pszArgs = RTStrStripL(pszArgs);
6833 if (!strcmp(pszArgs, "terse"))
6834 iVerbosity--;
6835 else if (!strcmp(pszArgs, "verbose"))
6836 iVerbosity++;
6837 }
6838
6839 uint32_t uLeaf;
6840 CPUMCPUID Host;
6841 uint32_t cLeaves = pVM->cpum.s.GuestInfo.cCpuIdLeaves;
6842 PCPUMCPUIDLEAF paLeaves = pVM->cpum.s.GuestInfo.paCpuIdLeavesR3;
6843 PCCPUMCPUIDLEAF pCurLeaf;
6844 PCCPUMCPUIDLEAF pNextLeaf;
6845 bool const fIntel = ASMIsIntelCpuEx(pVM->cpum.s.aGuestCpuIdPatmStd[0].uEbx,
6846 pVM->cpum.s.aGuestCpuIdPatmStd[0].uEcx,
6847 pVM->cpum.s.aGuestCpuIdPatmStd[0].uEdx);
6848
6849 /*
6850 * Standard leaves. Custom raw dump here due to ECX sub-leaves host handling.
6851 */
6852 uint32_t cHstMax = ASMCpuId_EAX(0);
6853 uint32_t cGstMax = paLeaves[0].uLeaf == 0 ? paLeaves[0].uEax : 0;
6854 uint32_t cMax = RT_MAX(cGstMax, cHstMax);
6855 pHlp->pfnPrintf(pHlp,
6856 " Raw Standard CPUID Leaves\n"
6857 " Leaf/sub-leaf eax ebx ecx edx\n");
6858 for (uLeaf = 0, pCurLeaf = paLeaves; uLeaf <= cMax; uLeaf++)
6859 {
6860 uint32_t cMaxSubLeaves = 1;
6861 if (uLeaf == 4 || uLeaf == 7 || uLeaf == 0xb)
6862 cMaxSubLeaves = 16;
6863 else if (uLeaf == 0xd)
6864 cMaxSubLeaves = 128;
6865
6866 for (uint32_t uSubLeaf = 0; uSubLeaf < cMaxSubLeaves; uSubLeaf++)
6867 {
6868 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
6869 if ( (uintptr_t)(pCurLeaf - paLeaves) < cLeaves
6870 && pCurLeaf->uLeaf == uLeaf
6871 && pCurLeaf->uSubLeaf == uSubLeaf)
6872 {
6873 pHlp->pfnPrintf(pHlp,
6874 "Gst: %08x/%04x %08x %08x %08x %08x\n"
6875 "Hst: %08x %08x %08x %08x\n",
6876 uLeaf, uSubLeaf, pCurLeaf->uEax, pCurLeaf->uEbx, pCurLeaf->uEcx, pCurLeaf->uEdx,
6877 Host.uEax, Host.uEbx, Host.uEcx, Host.uEdx);
6878 pCurLeaf++;
6879 }
6880 else if ( uLeaf != 0xd
6881 || uSubLeaf <= 1
6882 || Host.uEbx != 0 )
6883 pHlp->pfnPrintf(pHlp,
6884 "Hst: %08x/%04x %08x %08x %08x %08x\n",
6885 uLeaf, uSubLeaf, Host.uEax, Host.uEbx, Host.uEcx, Host.uEdx);
6886
6887 /* Done? */
6888 if ( ( (uintptr_t)(pCurLeaf - paLeaves) >= cLeaves
6889 || pCurLeaf->uLeaf != uLeaf)
6890 && ( (uLeaf == 0x4 && ((Host.uEax & 0x000f) == 0 || (Host.uEax & 0x000f) >= 8))
6891 || (uLeaf == 0x7 && Host.uEax == 0)
6892 || (uLeaf == 0xb && ((Host.uEcx & 0xff00) == 0 || (Host.uEcx & 0xff00) >= 8))
6893 || (uLeaf == 0xb && (Host.uEcx & 0xff) != uSubLeaf)
6894 || (uLeaf == 0xd && uSubLeaf >= 128)
6895 )
6896 )
6897 break;
6898 }
6899 }
6900 pNextLeaf = pCurLeaf;
6901
6902 /*
6903 * If verbose, decode it.
6904 */
6905 if (iVerbosity && paLeaves[0].uLeaf == 0)
6906 pHlp->pfnPrintf(pHlp,
6907 "%36s %.04s%.04s%.04s\n"
6908 "%36s 0x00000000-%#010x\n"
6909 ,
6910 "Name:", &paLeaves[0].uEbx, &paLeaves[0].uEdx, &paLeaves[0].uEcx,
6911 "Supports:", paLeaves[0].uEax);
6912
6913 if (iVerbosity && (pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x00000001), 0)) != NULL)
6914 cpumR3CpuIdInfoStdLeaf1Details(pHlp, pCurLeaf, iVerbosity > 1, fIntel);
6915
6916 if (iVerbosity && (pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x00000007), 0)) != NULL)
6917 cpumR3CpuIdInfoStdLeaf7Details(pHlp, paLeaves, cLeaves, pCurLeaf, iVerbosity > 1);
6918
6919 if (iVerbosity && (pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x0000000d), 0)) != NULL)
6920 cpumR3CpuIdInfoStdLeaf13Details(pHlp, paLeaves, cLeaves, pCurLeaf, iVerbosity > 1);
6921
6922 pCurLeaf = pNextLeaf;
6923
6924 /*
6925 * Hypervisor leaves.
6926 *
6927 * Unlike most of the other leaves reported, the guest hypervisor leaves
6928 * aren't a subset of the host CPUID bits.
6929 */
6930 pCurLeaf = cpumR3CpuIdInfoRawRange(pHlp, paLeaves, cLeaves, pCurLeaf, UINT32_C(0x3fffffff), "Unknown CPUID Leaves");
6931
6932 ASMCpuIdExSlow(UINT32_C(0x40000000), 0, 0, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
6933 cHstMax = Host.uEax >= UINT32_C(0x40000001) && Host.uEax <= UINT32_C(0x40000fff) ? Host.uEax : 0;
6934 cGstMax = (uintptr_t)(pCurLeaf - paLeaves) < cLeaves && pCurLeaf->uLeaf == UINT32_C(0x40000000)
6935 ? RT_MIN(pCurLeaf->uEax, UINT32_C(0x40000fff)) : 0;
6936 cMax = RT_MAX(cHstMax, cGstMax);
6937 if (cMax >= UINT32_C(0x40000000))
6938 {
6939 pNextLeaf = cpumR3CpuIdInfoRawRange(pHlp, paLeaves, cLeaves, pCurLeaf, cMax, "Raw Hypervisor CPUID Leaves");
6940
6941 /** @todo dump these in more detail. */
6942
6943 pCurLeaf = pNextLeaf;
6944 }
6945
6946
6947 /*
6948 * Extended. Custom raw dump here due to ECX sub-leaves host handling.
6949 * Implemented after AMD specs.
6950 */
6951 pCurLeaf = cpumR3CpuIdInfoRawRange(pHlp, paLeaves, cLeaves, pCurLeaf, UINT32_C(0x7fffffff), "Unknown CPUID Leaves");
6952
6953 ASMCpuIdExSlow(UINT32_C(0x80000000), 0, 0, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
6954 cHstMax = ASMIsValidExtRange(Host.uEax) ? RT_MIN(Host.uEax, UINT32_C(0x80000fff)) : 0;
6955 cGstMax = (uintptr_t)(pCurLeaf - paLeaves) < cLeaves && pCurLeaf->uLeaf == UINT32_C(0x80000000)
6956 ? RT_MIN(pCurLeaf->uEax, UINT32_C(0x80000fff)) : 0;
6957 cMax = RT_MAX(cHstMax, cGstMax);
6958 if (cMax >= UINT32_C(0x80000000))
6959 {
6960
6961 pHlp->pfnPrintf(pHlp,
6962 " Raw Extended CPUID Leaves\n"
6963 " Leaf/sub-leaf eax ebx ecx edx\n");
6964 PCCPUMCPUIDLEAF pExtLeaf = pCurLeaf;
6965 for (uLeaf = UINT32_C(0x80000000); uLeaf <= cMax; uLeaf++)
6966 {
6967 uint32_t cMaxSubLeaves = 1;
6968 if (uLeaf == UINT32_C(0x8000001d))
6969 cMaxSubLeaves = 16;
6970
6971 for (uint32_t uSubLeaf = 0; uSubLeaf < cMaxSubLeaves; uSubLeaf++)
6972 {
6973 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
6974 if ( (uintptr_t)(pCurLeaf - paLeaves) < cLeaves
6975 && pCurLeaf->uLeaf == uLeaf
6976 && pCurLeaf->uSubLeaf == uSubLeaf)
6977 {
6978 pHlp->pfnPrintf(pHlp,
6979 "Gst: %08x/%04x %08x %08x %08x %08x\n"
6980 "Hst: %08x %08x %08x %08x\n",
6981 uLeaf, uSubLeaf, pCurLeaf->uEax, pCurLeaf->uEbx, pCurLeaf->uEcx, pCurLeaf->uEdx,
6982 Host.uEax, Host.uEbx, Host.uEcx, Host.uEdx);
6983 pCurLeaf++;
6984 }
6985 else if ( uLeaf != 0xd
6986 || uSubLeaf <= 1
6987 || Host.uEbx != 0 )
6988 pHlp->pfnPrintf(pHlp,
6989 "Hst: %08x/%04x %08x %08x %08x %08x\n",
6990 uLeaf, uSubLeaf, Host.uEax, Host.uEbx, Host.uEcx, Host.uEdx);
6991
6992 /* Done? */
6993 if ( ( (uintptr_t)(pCurLeaf - paLeaves) >= cLeaves
6994 || pCurLeaf->uLeaf != uLeaf)
6995 && (uLeaf == UINT32_C(0x8000001d) && ((Host.uEax & 0x000f) == 0 || (Host.uEax & 0x000f) >= 8)) )
6996 break;
6997 }
6998 }
6999 pNextLeaf = pCurLeaf;
7000
7001 /*
7002 * Understandable output
7003 */
7004 if (iVerbosity)
7005 pHlp->pfnPrintf(pHlp,
7006 "Ext Name: %.4s%.4s%.4s\n"
7007 "Ext Supports: 0x80000000-%#010x\n",
7008 &pExtLeaf->uEbx, &pExtLeaf->uEdx, &pExtLeaf->uEcx, pExtLeaf->uEax);
7009
7010 pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x80000001), 0);
7011 if (iVerbosity && pCurLeaf)
7012 {
7013 uint32_t uEAX = pCurLeaf->uEax;
7014 pHlp->pfnPrintf(pHlp,
7015 "Family: %d \tExtended: %d \tEffective: %d\n"
7016 "Model: %d \tExtended: %d \tEffective: %d\n"
7017 "Stepping: %d\n"
7018 "Brand ID: %#05x\n",
7019 (uEAX >> 8) & 0xf, (uEAX >> 20) & 0x7f, ASMGetCpuFamily(uEAX),
7020 (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX, fIntel),
7021 ASMGetCpuStepping(uEAX),
7022 pCurLeaf->uEbx & 0xfff);
7023
7024 if (iVerbosity == 1)
7025 {
7026 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEdx, g_aExtLeaf1EdxSubFields, "Ext Features EDX:", 34);
7027 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEcx, g_aExtLeaf1EdxSubFields, "Ext Features ECX:", 34);
7028 }
7029 else
7030 {
7031 ASMCpuIdExSlow(0x80000001, 0, 0, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
7032 pHlp->pfnPrintf(pHlp, "Ext Features\n");
7033 pHlp->pfnPrintf(pHlp, " Mnemonic - Description = guest (host)\n");
7034 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, pCurLeaf->uEdx, Host.uEdx, g_aExtLeaf1EdxSubFields, 56);
7035 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, pCurLeaf->uEcx, Host.uEcx, g_aExtLeaf1EcxSubFields, 56);
7036 if (Host.uEcx & X86_CPUID_AMD_FEATURE_ECX_SVM)
7037 {
7038 pHlp->pfnPrintf(pHlp, "SVM Feature Identification (leaf A):\n");
7039 ASMCpuIdExSlow(0x8000000a, 0, 0, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
7040 pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x8000000a), 0);
7041 uint32_t const uGstEdx = pCurLeaf ? pCurLeaf->uEdx : 0;
7042 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, uGstEdx, Host.uEdx, g_aExtLeafAEdxSubFields, 56);
7043 }
7044 }
7045 }
7046
7047 if (iVerbosity && (pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x80000002), 0)) != NULL)
7048 {
7049 char szString[4*4*3+1] = {0};
7050 uint32_t *pu32 = (uint32_t *)szString;
7051 *pu32++ = pCurLeaf->uEax;
7052 *pu32++ = pCurLeaf->uEbx;
7053 *pu32++ = pCurLeaf->uEcx;
7054 *pu32++ = pCurLeaf->uEdx;
7055 pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x80000003), 0);
7056 if (pCurLeaf)
7057 {
7058 *pu32++ = pCurLeaf->uEax;
7059 *pu32++ = pCurLeaf->uEbx;
7060 *pu32++ = pCurLeaf->uEcx;
7061 *pu32++ = pCurLeaf->uEdx;
7062 }
7063 pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x80000004), 0);
7064 if (pCurLeaf)
7065 {
7066 *pu32++ = pCurLeaf->uEax;
7067 *pu32++ = pCurLeaf->uEbx;
7068 *pu32++ = pCurLeaf->uEcx;
7069 *pu32++ = pCurLeaf->uEdx;
7070 }
7071 pHlp->pfnPrintf(pHlp, "Full Name: \"%s\"\n", szString);
7072 }
7073
7074 if (iVerbosity && (pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x80000005), 0)) != NULL)
7075 {
7076 uint32_t uEAX = pCurLeaf->uEax;
7077 uint32_t uEBX = pCurLeaf->uEbx;
7078 uint32_t uECX = pCurLeaf->uEcx;
7079 uint32_t uEDX = pCurLeaf->uEdx;
7080 char sz1[32];
7081 char sz2[32];
7082
7083 pHlp->pfnPrintf(pHlp,
7084 "TLB 2/4M Instr/Uni: %s %3d entries\n"
7085 "TLB 2/4M Data: %s %3d entries\n",
7086 getCacheAss((uEAX >> 8) & 0xff, sz1), (uEAX >> 0) & 0xff,
7087 getCacheAss((uEAX >> 24) & 0xff, sz2), (uEAX >> 16) & 0xff);
7088 pHlp->pfnPrintf(pHlp,
7089 "TLB 4K Instr/Uni: %s %3d entries\n"
7090 "TLB 4K Data: %s %3d entries\n",
7091 getCacheAss((uEBX >> 8) & 0xff, sz1), (uEBX >> 0) & 0xff,
7092 getCacheAss((uEBX >> 24) & 0xff, sz2), (uEBX >> 16) & 0xff);
7093 pHlp->pfnPrintf(pHlp, "L1 Instr Cache Line Size: %d bytes\n"
7094 "L1 Instr Cache Lines Per Tag: %d\n"
7095 "L1 Instr Cache Associativity: %s\n"
7096 "L1 Instr Cache Size: %d KB\n",
7097 (uEDX >> 0) & 0xff,
7098 (uEDX >> 8) & 0xff,
7099 getCacheAss((uEDX >> 16) & 0xff, sz1),
7100 (uEDX >> 24) & 0xff);
7101 pHlp->pfnPrintf(pHlp,
7102 "L1 Data Cache Line Size: %d bytes\n"
7103 "L1 Data Cache Lines Per Tag: %d\n"
7104 "L1 Data Cache Associativity: %s\n"
7105 "L1 Data Cache Size: %d KB\n",
7106 (uECX >> 0) & 0xff,
7107 (uECX >> 8) & 0xff,
7108 getCacheAss((uECX >> 16) & 0xff, sz1),
7109 (uECX >> 24) & 0xff);
7110 }
7111
7112 if (iVerbosity && (pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x80000006), 0)) != NULL)
7113 {
7114 uint32_t uEAX = pCurLeaf->uEax;
7115 uint32_t uEBX = pCurLeaf->uEbx;
7116 uint32_t uEDX = pCurLeaf->uEdx;
7117
7118 pHlp->pfnPrintf(pHlp,
7119 "L2 TLB 2/4M Instr/Uni: %s %4d entries\n"
7120 "L2 TLB 2/4M Data: %s %4d entries\n",
7121 getL2CacheAss((uEAX >> 12) & 0xf), (uEAX >> 0) & 0xfff,
7122 getL2CacheAss((uEAX >> 28) & 0xf), (uEAX >> 16) & 0xfff);
7123 pHlp->pfnPrintf(pHlp,
7124 "L2 TLB 4K Instr/Uni: %s %4d entries\n"
7125 "L2 TLB 4K Data: %s %4d entries\n",
7126 getL2CacheAss((uEBX >> 12) & 0xf), (uEBX >> 0) & 0xfff,
7127 getL2CacheAss((uEBX >> 28) & 0xf), (uEBX >> 16) & 0xfff);
7128 pHlp->pfnPrintf(pHlp,
7129 "L2 Cache Line Size: %d bytes\n"
7130 "L2 Cache Lines Per Tag: %d\n"
7131 "L2 Cache Associativity: %s\n"
7132 "L2 Cache Size: %d KB\n",
7133 (uEDX >> 0) & 0xff,
7134 (uEDX >> 8) & 0xf,
7135 getL2CacheAss((uEDX >> 12) & 0xf),
7136 (uEDX >> 16) & 0xffff);
7137 }
7138
7139 if (iVerbosity && (pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x80000007), 0)) != NULL)
7140 {
7141 ASMCpuIdExSlow(UINT32_C(0x80000007), 0, 0, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
7142 if (pCurLeaf->uEdx || (Host.uEdx && iVerbosity))
7143 {
7144 if (iVerbosity < 1)
7145 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEdx, g_aExtLeaf7EdxSubFields, "APM Features EDX:", 34);
7146 else
7147 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, pCurLeaf->uEdx, Host.uEdx, g_aExtLeaf7EdxSubFields, 56);
7148 }
7149 }
7150
7151 pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0x80000008), 0);
7152 if (pCurLeaf != NULL)
7153 {
7154 ASMCpuIdExSlow(UINT32_C(0x80000008), 0, 0, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
7155 if (pCurLeaf->uEbx || (Host.uEbx && iVerbosity))
7156 {
7157 if (iVerbosity < 1)
7158 cpumR3CpuIdInfoMnemonicListU32(pHlp, pCurLeaf->uEbx, g_aExtLeaf8EbxSubFields, "Ext Features ext IDs EBX:", 34);
7159 else
7160 cpumR3CpuIdInfoVerboseCompareListU32(pHlp, pCurLeaf->uEbx, Host.uEbx, g_aExtLeaf8EbxSubFields, 56);
7161 }
7162
7163 if (iVerbosity)
7164 {
7165 uint32_t uEAX = pCurLeaf->uEax;
7166 uint32_t uECX = pCurLeaf->uEcx;
7167
7168 /** @todo 0x80000008:EAX[23:16] is only defined for AMD. We'll get 0 on Intel. On
7169 * AMD if we get 0, the guest physical address width should be taken from
7170 * 0x80000008:EAX[7:0] instead. Guest Physical address width is relevant
7171 * for guests using nested paging. */
7172 pHlp->pfnPrintf(pHlp,
7173 "Physical Address Width: %d bits\n"
7174 "Virtual Address Width: %d bits\n"
7175 "Guest Physical Address Width: %d bits\n",
7176 (uEAX >> 0) & 0xff,
7177 (uEAX >> 8) & 0xff,
7178 (uEAX >> 16) & 0xff);
7179
7180 /** @todo 0x80000008:ECX is reserved on Intel (we'll get incorrect physical core
7181 * count here). */
7182 pHlp->pfnPrintf(pHlp,
7183 "Physical Core Count: %d\n",
7184 ((uECX >> 0) & 0xff) + 1);
7185 }
7186 }
7187
7188 pCurLeaf = pNextLeaf;
7189 }
7190
7191
7192
7193 /*
7194 * Centaur.
7195 */
7196 pCurLeaf = cpumR3CpuIdInfoRawRange(pHlp, paLeaves, cLeaves, pCurLeaf, UINT32_C(0xbfffffff), "Unknown CPUID Leaves");
7197
7198 ASMCpuIdExSlow(UINT32_C(0xc0000000), 0, 0, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
7199 cHstMax = Host.uEax >= UINT32_C(0xc0000001) && Host.uEax <= UINT32_C(0xc0000fff)
7200 ? RT_MIN(Host.uEax, UINT32_C(0xc0000fff)) : 0;
7201 cGstMax = (uintptr_t)(pCurLeaf - paLeaves) < cLeaves && pCurLeaf->uLeaf == UINT32_C(0xc0000000)
7202 ? RT_MIN(pCurLeaf->uEax, UINT32_C(0xc0000fff)) : 0;
7203 cMax = RT_MAX(cHstMax, cGstMax);
7204 if (cMax >= UINT32_C(0xc0000000))
7205 {
7206 pNextLeaf = cpumR3CpuIdInfoRawRange(pHlp, paLeaves, cLeaves, pCurLeaf, cMax, "Raw Centaur CPUID Leaves");
7207
7208 /*
7209 * Understandable output
7210 */
7211 if (iVerbosity && (pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0xc0000000), 0)) != NULL)
7212 pHlp->pfnPrintf(pHlp,
7213 "Centaur Supports: 0xc0000000-%#010x\n",
7214 pCurLeaf->uEax);
7215
7216 if (iVerbosity && (pCurLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, UINT32_C(0xc0000001), 0)) != NULL)
7217 {
7218 ASMCpuIdExSlow(0xc0000001, 0, 0, 0, &Host.uEax, &Host.uEbx, &Host.uEcx, &Host.uEdx);
7219 uint32_t uEdxGst = pCurLeaf->uEdx;
7220 uint32_t uEdxHst = Host.uEdx;
7221
7222 if (iVerbosity == 1)
7223 {
7224 pHlp->pfnPrintf(pHlp, "Centaur Features EDX: ");
7225 if (uEdxGst & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " AIS");
7226 if (uEdxGst & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " AIS-E");
7227 if (uEdxGst & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " RNG");
7228 if (uEdxGst & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " RNG-E");
7229 if (uEdxGst & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " LH");
7230 if (uEdxGst & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " FEMMS");
7231 if (uEdxGst & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " ACE");
7232 if (uEdxGst & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " ACE-E");
7233 /* possibly indicating MM/HE and MM/HE-E on older chips... */
7234 if (uEdxGst & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " ACE2");
7235 if (uEdxGst & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " ACE2-E");
7236 if (uEdxGst & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " PHE");
7237 if (uEdxGst & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " PHE-E");
7238 if (uEdxGst & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " PMM");
7239 if (uEdxGst & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " PMM-E");
7240 for (unsigned iBit = 14; iBit < 32; iBit++)
7241 if (uEdxGst & RT_BIT(iBit))
7242 pHlp->pfnPrintf(pHlp, " %d", iBit);
7243 pHlp->pfnPrintf(pHlp, "\n");
7244 }
7245 else
7246 {
7247 pHlp->pfnPrintf(pHlp, "Mnemonic - Description = guest (host)\n");
7248 pHlp->pfnPrintf(pHlp, "AIS - Alternate Instruction Set = %d (%d)\n", !!(uEdxGst & RT_BIT( 0)), !!(uEdxHst & RT_BIT( 0)));
7249 pHlp->pfnPrintf(pHlp, "AIS-E - AIS enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 1)), !!(uEdxHst & RT_BIT( 1)));
7250 pHlp->pfnPrintf(pHlp, "RNG - Random Number Generator = %d (%d)\n", !!(uEdxGst & RT_BIT( 2)), !!(uEdxHst & RT_BIT( 2)));
7251 pHlp->pfnPrintf(pHlp, "RNG-E - RNG enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 3)), !!(uEdxHst & RT_BIT( 3)));
7252 pHlp->pfnPrintf(pHlp, "LH - LongHaul MSR 0000_110Ah = %d (%d)\n", !!(uEdxGst & RT_BIT( 4)), !!(uEdxHst & RT_BIT( 4)));
7253 pHlp->pfnPrintf(pHlp, "FEMMS - FEMMS = %d (%d)\n", !!(uEdxGst & RT_BIT( 5)), !!(uEdxHst & RT_BIT( 5)));
7254 pHlp->pfnPrintf(pHlp, "ACE - Advanced Cryptography Engine = %d (%d)\n", !!(uEdxGst & RT_BIT( 6)), !!(uEdxHst & RT_BIT( 6)));
7255 pHlp->pfnPrintf(pHlp, "ACE-E - ACE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 7)), !!(uEdxHst & RT_BIT( 7)));
7256 /* possibly indicating MM/HE and MM/HE-E on older chips... */
7257 pHlp->pfnPrintf(pHlp, "ACE2 - Advanced Cryptography Engine 2 = %d (%d)\n", !!(uEdxGst & RT_BIT( 8)), !!(uEdxHst & RT_BIT( 8)));
7258 pHlp->pfnPrintf(pHlp, "ACE2-E - ACE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 9)), !!(uEdxHst & RT_BIT( 9)));
7259 pHlp->pfnPrintf(pHlp, "PHE - Padlock Hash Engine = %d (%d)\n", !!(uEdxGst & RT_BIT(10)), !!(uEdxHst & RT_BIT(10)));
7260 pHlp->pfnPrintf(pHlp, "PHE-E - PHE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(11)), !!(uEdxHst & RT_BIT(11)));
7261 pHlp->pfnPrintf(pHlp, "PMM - Montgomery Multiplier = %d (%d)\n", !!(uEdxGst & RT_BIT(12)), !!(uEdxHst & RT_BIT(12)));
7262 pHlp->pfnPrintf(pHlp, "PMM-E - PMM enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(13)), !!(uEdxHst & RT_BIT(13)));
7263 pHlp->pfnPrintf(pHlp, "14 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(14)), !!(uEdxHst & RT_BIT(14)));
7264 pHlp->pfnPrintf(pHlp, "15 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(15)), !!(uEdxHst & RT_BIT(15)));
7265 pHlp->pfnPrintf(pHlp, "Parallax = %d (%d)\n", !!(uEdxGst & RT_BIT(16)), !!(uEdxHst & RT_BIT(16)));
7266 pHlp->pfnPrintf(pHlp, "Parallax enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(17)), !!(uEdxHst & RT_BIT(17)));
7267 pHlp->pfnPrintf(pHlp, "Overstress = %d (%d)\n", !!(uEdxGst & RT_BIT(18)), !!(uEdxHst & RT_BIT(18)));
7268 pHlp->pfnPrintf(pHlp, "Overstress enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(19)), !!(uEdxHst & RT_BIT(19)));
7269 pHlp->pfnPrintf(pHlp, "TM3 - Temperature Monitoring 3 = %d (%d)\n", !!(uEdxGst & RT_BIT(20)), !!(uEdxHst & RT_BIT(20)));
7270 pHlp->pfnPrintf(pHlp, "TM3-E - TM3 enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(21)), !!(uEdxHst & RT_BIT(21)));
7271 pHlp->pfnPrintf(pHlp, "RNG2 - Random Number Generator 2 = %d (%d)\n", !!(uEdxGst & RT_BIT(22)), !!(uEdxHst & RT_BIT(22)));
7272 pHlp->pfnPrintf(pHlp, "RNG2-E - RNG2 enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(23)), !!(uEdxHst & RT_BIT(23)));
7273 pHlp->pfnPrintf(pHlp, "24 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(24)), !!(uEdxHst & RT_BIT(24)));
7274 pHlp->pfnPrintf(pHlp, "PHE2 - Padlock Hash Engine 2 = %d (%d)\n", !!(uEdxGst & RT_BIT(25)), !!(uEdxHst & RT_BIT(25)));
7275 pHlp->pfnPrintf(pHlp, "PHE2-E - PHE2 enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(26)), !!(uEdxHst & RT_BIT(26)));
7276 for (unsigned iBit = 27; iBit < 32; iBit++)
7277 if ((uEdxGst | uEdxHst) & RT_BIT(iBit))
7278 pHlp->pfnPrintf(pHlp, "Bit %d = %d (%d)\n", iBit, !!(uEdxGst & RT_BIT(iBit)), !!(uEdxHst & RT_BIT(iBit)));
7279 pHlp->pfnPrintf(pHlp, "\n");
7280 }
7281 }
7282
7283 pCurLeaf = pNextLeaf;
7284 }
7285
7286 /*
7287 * The remainder.
7288 */
7289 pCurLeaf = cpumR3CpuIdInfoRawRange(pHlp, paLeaves, cLeaves, pCurLeaf, UINT32_C(0xffffffff), "Unknown CPUID Leaves");
7290}
7291
7292#endif /* !IN_VBOX_CPU_REPORT */
7293
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