VirtualBox

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

Last change on this file since 55896 was 55862, checked in by vboxsync, 10 years ago

CPUMR3CpuId.cpp: Corrected XSAVE related CPUID handling loading old state.

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