VirtualBox

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

Last change on this file since 53349 was 52106, checked in by vboxsync, 10 years ago

Spaces.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 57.8 KB
Line 
1/* $Id: CPUMR3CpuId.cpp 52106 2014-07-21 04:59:10Z vboxsync $ */
2/** @file
3 * CPUM - CPU ID part.
4 */
5
6/*
7 * Copyright (C) 2013-2014 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 "CPUMInternal.h"
24#include <VBox/vmm/vm.h>
25#include <VBox/vmm/mm.h>
26
27#include <VBox/err.h>
28#include <iprt/asm-amd64-x86.h>
29#include <iprt/ctype.h>
30#include <iprt/mem.h>
31#include <iprt/string.h>
32
33
34/*******************************************************************************
35* Global Variables *
36*******************************************************************************/
37/**
38 * The intel pentium family.
39 */
40static const CPUMMICROARCH g_aenmIntelFamily06[] =
41{
42 /* [ 0(0x00)] = */ kCpumMicroarch_Intel_P6, /* Pentium Pro A-step (says sandpile.org). */
43 /* [ 1(0x01)] = */ kCpumMicroarch_Intel_P6, /* Pentium Pro */
44 /* [ 2(0x02)] = */ kCpumMicroarch_Intel_Unknown,
45 /* [ 3(0x03)] = */ kCpumMicroarch_Intel_P6_II, /* PII Klamath */
46 /* [ 4(0x04)] = */ kCpumMicroarch_Intel_Unknown,
47 /* [ 5(0x05)] = */ kCpumMicroarch_Intel_P6_II, /* PII Deschutes */
48 /* [ 6(0x06)] = */ kCpumMicroarch_Intel_P6_II, /* Celeron Mendocino. */
49 /* [ 7(0x07)] = */ kCpumMicroarch_Intel_P6_III, /* PIII Katmai. */
50 /* [ 8(0x08)] = */ kCpumMicroarch_Intel_P6_III, /* PIII Coppermine (includes Celeron). */
51 /* [ 9(0x09)] = */ kCpumMicroarch_Intel_P6_M_Banias, /* Pentium/Celeron M Banias. */
52 /* [10(0x0a)] = */ kCpumMicroarch_Intel_P6_III, /* PIII Xeon */
53 /* [11(0x0b)] = */ kCpumMicroarch_Intel_P6_III, /* PIII Tualatin (includes Celeron). */
54 /* [12(0x0c)] = */ kCpumMicroarch_Intel_Unknown,
55 /* [13(0x0d)] = */ kCpumMicroarch_Intel_P6_M_Dothan, /* Pentium/Celeron M Dothan. */
56 /* [14(0x0e)] = */ kCpumMicroarch_Intel_Core_Yonah, /* Core Yonah (Enhanced Pentium M). */
57 /* [15(0x0f)] = */ kCpumMicroarch_Intel_Core2_Merom, /* Merom */
58 /* [16(0x10)] = */ kCpumMicroarch_Intel_Unknown,
59 /* [17(0x11)] = */ kCpumMicroarch_Intel_Unknown,
60 /* [18(0x12)] = */ kCpumMicroarch_Intel_Unknown,
61 /* [19(0x13)] = */ kCpumMicroarch_Intel_Unknown,
62 /* [20(0x14)] = */ kCpumMicroarch_Intel_Unknown,
63 /* [21(0x15)] = */ kCpumMicroarch_Intel_P6_M_Dothan, /* Tolapai - System-on-a-chip. */
64 /* [22(0x16)] = */ kCpumMicroarch_Intel_Core2_Merom,
65 /* [23(0x17)] = */ kCpumMicroarch_Intel_Core2_Penryn,
66 /* [24(0x18)] = */ kCpumMicroarch_Intel_Unknown,
67 /* [25(0x19)] = */ kCpumMicroarch_Intel_Unknown,
68 /* [26(0x1a)] = */ kCpumMicroarch_Intel_Core7_Nehalem,
69 /* [27(0x1b)] = */ kCpumMicroarch_Intel_Unknown,
70 /* [28(0x1c)] = */ kCpumMicroarch_Intel_Atom_Bonnell, /* Diamonville, Pineview, */
71 /* [29(0x1d)] = */ kCpumMicroarch_Intel_Core2_Penryn,
72 /* [30(0x1e)] = */ kCpumMicroarch_Intel_Core7_Nehalem, /* Clarksfield, Lynnfield, Jasper Forest. */
73 /* [31(0x1f)] = */ kCpumMicroarch_Intel_Core7_Nehalem, /* Only listed by sandpile.org. 2 cores ABD/HVD, whatever that means. */
74 /* [32(0x20)] = */ kCpumMicroarch_Intel_Unknown,
75 /* [33(0x21)] = */ kCpumMicroarch_Intel_Unknown,
76 /* [34(0x22)] = */ kCpumMicroarch_Intel_Unknown,
77 /* [35(0x23)] = */ kCpumMicroarch_Intel_Unknown,
78 /* [36(0x24)] = */ kCpumMicroarch_Intel_Unknown,
79 /* [37(0x25)] = */ kCpumMicroarch_Intel_Core7_Westmere, /* Arrandale, Clarksdale. */
80 /* [38(0x26)] = */ kCpumMicroarch_Intel_Atom_Lincroft,
81 /* [39(0x27)] = */ kCpumMicroarch_Intel_Atom_Saltwell,
82 /* [40(0x28)] = */ kCpumMicroarch_Intel_Unknown,
83 /* [41(0x29)] = */ kCpumMicroarch_Intel_Unknown,
84 /* [42(0x2a)] = */ kCpumMicroarch_Intel_Core7_SandyBridge,
85 /* [43(0x2b)] = */ kCpumMicroarch_Intel_Unknown,
86 /* [44(0x2c)] = */ kCpumMicroarch_Intel_Core7_Westmere, /* Gulftown, Westmere-EP. */
87 /* [45(0x2d)] = */ kCpumMicroarch_Intel_Core7_SandyBridge, /* SandyBridge-E, SandyBridge-EN, SandyBridge-EP. */
88 /* [46(0x2e)] = */ kCpumMicroarch_Intel_Core7_Nehalem, /* Beckton (Xeon). */
89 /* [47(0x2f)] = */ kCpumMicroarch_Intel_Core7_Westmere, /* Westmere-EX. */
90 /* [48(0x30)] = */ kCpumMicroarch_Intel_Unknown,
91 /* [49(0x31)] = */ kCpumMicroarch_Intel_Unknown,
92 /* [50(0x32)] = */ kCpumMicroarch_Intel_Unknown,
93 /* [51(0x33)] = */ kCpumMicroarch_Intel_Unknown,
94 /* [52(0x34)] = */ kCpumMicroarch_Intel_Unknown,
95 /* [53(0x35)] = */ kCpumMicroarch_Intel_Atom_Saltwell, /* ?? */
96 /* [54(0x36)] = */ kCpumMicroarch_Intel_Atom_Saltwell, /* Cedarview, ++ */
97 /* [55(0x37)] = */ kCpumMicroarch_Intel_Atom_Silvermont,
98 /* [56(0x38)] = */ kCpumMicroarch_Intel_Unknown,
99 /* [57(0x39)] = */ kCpumMicroarch_Intel_Unknown,
100 /* [58(0x3a)] = */ kCpumMicroarch_Intel_Core7_IvyBridge,
101 /* [59(0x3b)] = */ kCpumMicroarch_Intel_Unknown,
102 /* [60(0x3c)] = */ kCpumMicroarch_Intel_Core7_Haswell,
103 /* [61(0x3d)] = */ kCpumMicroarch_Intel_Core7_Broadwell,
104 /* [62(0x3e)] = */ kCpumMicroarch_Intel_Core7_IvyBridge,
105 /* [63(0x3f)] = */ kCpumMicroarch_Intel_Core7_Haswell,
106 /* [64(0x40)] = */ kCpumMicroarch_Intel_Unknown,
107 /* [65(0x41)] = */ kCpumMicroarch_Intel_Unknown,
108 /* [66(0x42)] = */ kCpumMicroarch_Intel_Unknown,
109 /* [67(0x43)] = */ kCpumMicroarch_Intel_Unknown,
110 /* [68(0x44)] = */ kCpumMicroarch_Intel_Unknown,
111 /* [69(0x45)] = */ kCpumMicroarch_Intel_Core7_Haswell,
112 /* [70(0x46)] = */ kCpumMicroarch_Intel_Core7_Haswell,
113 /* [71(0x47)] = */ kCpumMicroarch_Intel_Unknown,
114 /* [72(0x48)] = */ kCpumMicroarch_Intel_Unknown,
115 /* [73(0x49)] = */ kCpumMicroarch_Intel_Unknown,
116 /* [74(0x4a)] = */ kCpumMicroarch_Intel_Atom_Silvermont,
117 /* [75(0x4b)] = */ kCpumMicroarch_Intel_Unknown,
118 /* [76(0x4c)] = */ kCpumMicroarch_Intel_Unknown,
119 /* [77(0x4d)] = */ kCpumMicroarch_Intel_Atom_Silvermont,
120 /* [78(0x4e)] = */ kCpumMicroarch_Intel_Unknown,
121 /* [79(0x4f)] = */ kCpumMicroarch_Intel_Unknown,
122};
123
124
125
126/**
127 * Figures out the (sub-)micro architecture given a bit of CPUID info.
128 *
129 * @returns Micro architecture.
130 * @param enmVendor The CPU vendor .
131 * @param bFamily The CPU family.
132 * @param bModel The CPU model.
133 * @param bStepping The CPU stepping.
134 */
135VMMR3DECL(CPUMMICROARCH) CPUMR3CpuIdDetermineMicroarchEx(CPUMCPUVENDOR enmVendor, uint8_t bFamily,
136 uint8_t bModel, uint8_t bStepping)
137{
138 if (enmVendor == CPUMCPUVENDOR_AMD)
139 {
140 switch (bFamily)
141 {
142 case 0x02: return kCpumMicroarch_AMD_Am286; /* Not really kosher... */
143 case 0x03: return kCpumMicroarch_AMD_Am386;
144 case 0x23: return kCpumMicroarch_AMD_Am386; /* SX*/
145 case 0x04: return bModel < 14 ? kCpumMicroarch_AMD_Am486 : kCpumMicroarch_AMD_Am486Enh;
146 case 0x05: return bModel < 6 ? kCpumMicroarch_AMD_K5 : kCpumMicroarch_AMD_K6; /* Genode LX is 0x0a, lump it with K6. */
147 case 0x06:
148 switch (bModel)
149 {
150 case 0: kCpumMicroarch_AMD_K7_Palomino;
151 case 1: kCpumMicroarch_AMD_K7_Palomino;
152 case 2: kCpumMicroarch_AMD_K7_Palomino;
153 case 3: kCpumMicroarch_AMD_K7_Spitfire;
154 case 4: kCpumMicroarch_AMD_K7_Thunderbird;
155 case 6: kCpumMicroarch_AMD_K7_Palomino;
156 case 7: kCpumMicroarch_AMD_K7_Morgan;
157 case 8: kCpumMicroarch_AMD_K7_Thoroughbred;
158 case 10: kCpumMicroarch_AMD_K7_Barton; /* Thorton too. */
159 }
160 return kCpumMicroarch_AMD_K7_Unknown;
161 case 0x0f:
162 /*
163 * This family is a friggin mess. Trying my best to make some
164 * sense out of it. Too much happened in the 0x0f family to
165 * lump it all together as K8 (130nm->90nm->65nm, AMD-V, ++).
166 *
167 * Emperical CPUID.01h.EAX evidence from revision guides, wikipedia,
168 * cpu-world.com, and other places:
169 * - 130nm:
170 * - ClawHammer: F7A/SH-CG, F5A/-CG, F4A/-CG, F50/-B0, F48/-C0, F58/-C0,
171 * - SledgeHammer: F50/SH-B0, F48/-C0, F58/-C0, F4A/-CG, F5A/-CG, F7A/-CG, F51/-B3
172 * - Newcastle: FC0/DH-CG (errum #180: FE0/DH-CG), FF0/DH-CG
173 * - Dublin: FC0/-CG, FF0/-CG, F82/CH-CG, F4A/-CG, F48/SH-C0,
174 * - Odessa: FC0/DH-CG (errum #180: FE0/DH-CG)
175 * - Paris: FF0/DH-CG, FC0/DH-CG (errum #180: FE0/DH-CG),
176 * - 90nm:
177 * - Winchester: 10FF0/DH-D0, 20FF0/DH-E3.
178 * - Oakville: 10FC0/DH-D0.
179 * - Georgetown: 10FC0/DH-D0.
180 * - Sonora: 10FC0/DH-D0.
181 * - Venus: 20F71/SH-E4
182 * - Troy: 20F51/SH-E4
183 * - Athens: 20F51/SH-E4
184 * - San Diego: 20F71/SH-E4.
185 * - Lancaster: 20F42/SH-E5
186 * - Newark: 20F42/SH-E5.
187 * - Albany: 20FC2/DH-E6.
188 * - Roma: 20FC2/DH-E6.
189 * - Venice: 20FF0/DH-E3, 20FC2/DH-E6, 20FF2/DH-E6.
190 * - Palermo: 10FC0/DH-D0, 20FF0/DH-E3, 20FC0/DH-E3, 20FC2/DH-E6, 20FF2/DH-E6
191 * - 90nm introducing Dual core:
192 * - Denmark: 20F30/JH-E1, 20F32/JH-E6
193 * - Italy: 20F10/JH-E1, 20F12/JH-E6
194 * - Egypt: 20F10/JH-E1, 20F12/JH-E6
195 * - Toledo: 20F32/JH-E6, 30F72/DH-E6 (single code variant).
196 * - Manchester: 20FB1/BH-E4, 30FF2/BH-E4.
197 * - 90nm 2nd gen opteron ++, AMD-V introduced (might be missing in some cheaper models):
198 * - Santa Ana: 40F32/JH-F2, /-F3
199 * - Santa Rosa: 40F12/JH-F2, 40F13/JH-F3
200 * - Windsor: 40F32/JH-F2, 40F33/JH-F3, C0F13/JH-F3, 40FB2/BH-F2, ??20FB1/BH-E4??.
201 * - Manila: 50FF2/DH-F2, 40FF2/DH-F2
202 * - Orleans: 40FF2/DH-F2, 50FF2/DH-F2, 50FF3/DH-F3.
203 * - Keene: 40FC2/DH-F2.
204 * - Richmond: 40FC2/DH-F2
205 * - Taylor: 40F82/BH-F2
206 * - Trinidad: 40F82/BH-F2
207 *
208 * - 65nm:
209 * - Brisbane: 60FB1/BH-G1, 60FB2/BH-G2.
210 * - Tyler: 60F81/BH-G1, 60F82/BH-G2.
211 * - Sparta: 70FF1/DH-G1, 70FF2/DH-G2.
212 * - Lima: 70FF1/DH-G1, 70FF2/DH-G2.
213 * - Sherman: /-G1, 70FC2/DH-G2.
214 * - Huron: 70FF2/DH-G2.
215 */
216 if (bModel < 0x10)
217 return kCpumMicroarch_AMD_K8_130nm;
218 if (bModel >= 0x60 && bModel < 0x80)
219 return kCpumMicroarch_AMD_K8_65nm;
220 if (bModel >= 0x40)
221 return kCpumMicroarch_AMD_K8_90nm_AMDV;
222 switch (bModel)
223 {
224 case 0x21:
225 case 0x23:
226 case 0x2b:
227 case 0x2f:
228 case 0x37:
229 case 0x3f:
230 return kCpumMicroarch_AMD_K8_90nm_DualCore;
231 }
232 return kCpumMicroarch_AMD_K8_90nm;
233 case 0x10:
234 return kCpumMicroarch_AMD_K10;
235 case 0x11:
236 return kCpumMicroarch_AMD_K10_Lion;
237 case 0x12:
238 return kCpumMicroarch_AMD_K10_Llano;
239 case 0x14:
240 return kCpumMicroarch_AMD_Bobcat;
241 case 0x15:
242 switch (bModel)
243 {
244 case 0x00: return kCpumMicroarch_AMD_15h_Bulldozer; /* Any? prerelease? */
245 case 0x01: return kCpumMicroarch_AMD_15h_Bulldozer; /* Opteron 4200, FX-81xx. */
246 case 0x02: return kCpumMicroarch_AMD_15h_Piledriver; /* Opteron 4300, FX-83xx. */
247 case 0x10: return kCpumMicroarch_AMD_15h_Piledriver; /* A10-5800K for e.g. */
248 case 0x11: /* ?? */
249 case 0x12: /* ?? */
250 case 0x13: return kCpumMicroarch_AMD_15h_Piledriver; /* A10-6800K for e.g. */
251 }
252 return kCpumMicroarch_AMD_15h_Unknown;
253 case 0x16:
254 return kCpumMicroarch_AMD_Jaguar;
255
256 }
257 return kCpumMicroarch_AMD_Unknown;
258 }
259
260 if (enmVendor == CPUMCPUVENDOR_INTEL)
261 {
262 switch (bFamily)
263 {
264 case 3:
265 return kCpumMicroarch_Intel_80386;
266 case 4:
267 return kCpumMicroarch_Intel_80486;
268 case 5:
269 return kCpumMicroarch_Intel_P5;
270 case 6:
271 if (bModel < RT_ELEMENTS(g_aenmIntelFamily06))
272 return g_aenmIntelFamily06[bModel];
273 return kCpumMicroarch_Intel_Atom_Unknown;
274 case 15:
275 switch (bModel)
276 {
277 case 0: return kCpumMicroarch_Intel_NB_Willamette;
278 case 1: return kCpumMicroarch_Intel_NB_Willamette;
279 case 2: return kCpumMicroarch_Intel_NB_Northwood;
280 case 3: return kCpumMicroarch_Intel_NB_Prescott;
281 case 4: return kCpumMicroarch_Intel_NB_Prescott2M; /* ?? */
282 case 5: return kCpumMicroarch_Intel_NB_Unknown; /*??*/
283 case 6: return kCpumMicroarch_Intel_NB_CedarMill;
284 case 7: return kCpumMicroarch_Intel_NB_Gallatin;
285 default: return kCpumMicroarch_Intel_NB_Unknown;
286 }
287 break;
288 /* The following are not kosher but kind of follow intuitively from 6, 5 & 4. */
289 case 1:
290 return kCpumMicroarch_Intel_8086;
291 case 2:
292 return kCpumMicroarch_Intel_80286;
293 }
294 return kCpumMicroarch_Intel_Unknown;
295 }
296
297 if (enmVendor == CPUMCPUVENDOR_VIA)
298 {
299 switch (bFamily)
300 {
301 case 5:
302 switch (bModel)
303 {
304 case 1: return kCpumMicroarch_Centaur_C6;
305 case 4: return kCpumMicroarch_Centaur_C6;
306 case 8: return kCpumMicroarch_Centaur_C2;
307 case 9: return kCpumMicroarch_Centaur_C3;
308 }
309 break;
310
311 case 6:
312 switch (bModel)
313 {
314 case 5: return kCpumMicroarch_VIA_C3_M2;
315 case 6: return kCpumMicroarch_VIA_C3_C5A;
316 case 7: return bStepping < 8 ? kCpumMicroarch_VIA_C3_C5B : kCpumMicroarch_VIA_C3_C5C;
317 case 8: return kCpumMicroarch_VIA_C3_C5N;
318 case 9: return bStepping < 8 ? kCpumMicroarch_VIA_C3_C5XL : kCpumMicroarch_VIA_C3_C5P;
319 case 10: return kCpumMicroarch_VIA_C7_C5J;
320 case 15: return kCpumMicroarch_VIA_Isaiah;
321 }
322 break;
323 }
324 return kCpumMicroarch_VIA_Unknown;
325 }
326
327 if (enmVendor == CPUMCPUVENDOR_CYRIX)
328 {
329 switch (bFamily)
330 {
331 case 4:
332 switch (bModel)
333 {
334 case 9: return kCpumMicroarch_Cyrix_5x86;
335 }
336 break;
337
338 case 5:
339 switch (bModel)
340 {
341 case 2: return kCpumMicroarch_Cyrix_M1;
342 case 4: return kCpumMicroarch_Cyrix_MediaGX;
343 case 5: return kCpumMicroarch_Cyrix_MediaGXm;
344 }
345 break;
346
347 case 6:
348 switch (bModel)
349 {
350 case 0: return kCpumMicroarch_Cyrix_M2;
351 }
352 break;
353
354 }
355 return kCpumMicroarch_Cyrix_Unknown;
356 }
357
358 return kCpumMicroarch_Unknown;
359}
360
361
362/**
363 * Translates a microarchitecture enum value to the corresponding string
364 * constant.
365 *
366 * @returns Read-only string constant (omits "kCpumMicroarch_" prefix). Returns
367 * NULL if the value is invalid.
368 *
369 * @param enmMicroarch The enum value to convert.
370 */
371VMMR3DECL(const char *) CPUMR3MicroarchName(CPUMMICROARCH enmMicroarch)
372{
373 switch (enmMicroarch)
374 {
375#define CASE_RET_STR(enmValue) case enmValue: return #enmValue + (sizeof("kCpumMicroarch_") - 1)
376 CASE_RET_STR(kCpumMicroarch_Intel_8086);
377 CASE_RET_STR(kCpumMicroarch_Intel_80186);
378 CASE_RET_STR(kCpumMicroarch_Intel_80286);
379 CASE_RET_STR(kCpumMicroarch_Intel_80386);
380 CASE_RET_STR(kCpumMicroarch_Intel_80486);
381 CASE_RET_STR(kCpumMicroarch_Intel_P5);
382
383 CASE_RET_STR(kCpumMicroarch_Intel_P6);
384 CASE_RET_STR(kCpumMicroarch_Intel_P6_II);
385 CASE_RET_STR(kCpumMicroarch_Intel_P6_III);
386
387 CASE_RET_STR(kCpumMicroarch_Intel_P6_M_Banias);
388 CASE_RET_STR(kCpumMicroarch_Intel_P6_M_Dothan);
389 CASE_RET_STR(kCpumMicroarch_Intel_Core_Yonah);
390
391 CASE_RET_STR(kCpumMicroarch_Intel_Core2_Merom);
392 CASE_RET_STR(kCpumMicroarch_Intel_Core2_Penryn);
393
394 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Nehalem);
395 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Westmere);
396 CASE_RET_STR(kCpumMicroarch_Intel_Core7_SandyBridge);
397 CASE_RET_STR(kCpumMicroarch_Intel_Core7_IvyBridge);
398 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Haswell);
399 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Broadwell);
400 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Skylake);
401 CASE_RET_STR(kCpumMicroarch_Intel_Core7_Cannonlake);
402
403 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Bonnell);
404 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Lincroft);
405 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Saltwell);
406 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Silvermont);
407 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Airmount);
408 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Goldmont);
409 CASE_RET_STR(kCpumMicroarch_Intel_Atom_Unknown);
410
411 CASE_RET_STR(kCpumMicroarch_Intel_NB_Willamette);
412 CASE_RET_STR(kCpumMicroarch_Intel_NB_Northwood);
413 CASE_RET_STR(kCpumMicroarch_Intel_NB_Prescott);
414 CASE_RET_STR(kCpumMicroarch_Intel_NB_Prescott2M);
415 CASE_RET_STR(kCpumMicroarch_Intel_NB_CedarMill);
416 CASE_RET_STR(kCpumMicroarch_Intel_NB_Gallatin);
417 CASE_RET_STR(kCpumMicroarch_Intel_NB_Unknown);
418
419 CASE_RET_STR(kCpumMicroarch_Intel_Unknown);
420
421 CASE_RET_STR(kCpumMicroarch_AMD_Am286);
422 CASE_RET_STR(kCpumMicroarch_AMD_Am386);
423 CASE_RET_STR(kCpumMicroarch_AMD_Am486);
424 CASE_RET_STR(kCpumMicroarch_AMD_Am486Enh);
425 CASE_RET_STR(kCpumMicroarch_AMD_K5);
426 CASE_RET_STR(kCpumMicroarch_AMD_K6);
427
428 CASE_RET_STR(kCpumMicroarch_AMD_K7_Palomino);
429 CASE_RET_STR(kCpumMicroarch_AMD_K7_Spitfire);
430 CASE_RET_STR(kCpumMicroarch_AMD_K7_Thunderbird);
431 CASE_RET_STR(kCpumMicroarch_AMD_K7_Morgan);
432 CASE_RET_STR(kCpumMicroarch_AMD_K7_Thoroughbred);
433 CASE_RET_STR(kCpumMicroarch_AMD_K7_Barton);
434 CASE_RET_STR(kCpumMicroarch_AMD_K7_Unknown);
435
436 CASE_RET_STR(kCpumMicroarch_AMD_K8_130nm);
437 CASE_RET_STR(kCpumMicroarch_AMD_K8_90nm);
438 CASE_RET_STR(kCpumMicroarch_AMD_K8_90nm_DualCore);
439 CASE_RET_STR(kCpumMicroarch_AMD_K8_90nm_AMDV);
440 CASE_RET_STR(kCpumMicroarch_AMD_K8_65nm);
441
442 CASE_RET_STR(kCpumMicroarch_AMD_K10);
443 CASE_RET_STR(kCpumMicroarch_AMD_K10_Lion);
444 CASE_RET_STR(kCpumMicroarch_AMD_K10_Llano);
445 CASE_RET_STR(kCpumMicroarch_AMD_Bobcat);
446 CASE_RET_STR(kCpumMicroarch_AMD_Jaguar);
447
448 CASE_RET_STR(kCpumMicroarch_AMD_15h_Bulldozer);
449 CASE_RET_STR(kCpumMicroarch_AMD_15h_Piledriver);
450 CASE_RET_STR(kCpumMicroarch_AMD_15h_Steamroller);
451 CASE_RET_STR(kCpumMicroarch_AMD_15h_Excavator);
452 CASE_RET_STR(kCpumMicroarch_AMD_15h_Unknown);
453
454 CASE_RET_STR(kCpumMicroarch_AMD_16h_First);
455
456 CASE_RET_STR(kCpumMicroarch_AMD_Unknown);
457
458 CASE_RET_STR(kCpumMicroarch_Centaur_C6);
459 CASE_RET_STR(kCpumMicroarch_Centaur_C2);
460 CASE_RET_STR(kCpumMicroarch_Centaur_C3);
461 CASE_RET_STR(kCpumMicroarch_VIA_C3_M2);
462 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5A);
463 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5B);
464 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5C);
465 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5N);
466 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5XL);
467 CASE_RET_STR(kCpumMicroarch_VIA_C3_C5P);
468 CASE_RET_STR(kCpumMicroarch_VIA_C7_C5J);
469 CASE_RET_STR(kCpumMicroarch_VIA_Isaiah);
470 CASE_RET_STR(kCpumMicroarch_VIA_Unknown);
471
472 CASE_RET_STR(kCpumMicroarch_Cyrix_5x86);
473 CASE_RET_STR(kCpumMicroarch_Cyrix_M1);
474 CASE_RET_STR(kCpumMicroarch_Cyrix_MediaGX);
475 CASE_RET_STR(kCpumMicroarch_Cyrix_MediaGXm);
476 CASE_RET_STR(kCpumMicroarch_Cyrix_M2);
477 CASE_RET_STR(kCpumMicroarch_Cyrix_Unknown);
478
479 CASE_RET_STR(kCpumMicroarch_Unknown);
480
481#undef CASE_RET_STR
482 case kCpumMicroarch_Invalid:
483 case kCpumMicroarch_Intel_End:
484 case kCpumMicroarch_Intel_Core7_End:
485 case kCpumMicroarch_Intel_Atom_End:
486 case kCpumMicroarch_Intel_P6_Core_Atom_End:
487 case kCpumMicroarch_Intel_NB_End:
488 case kCpumMicroarch_AMD_K7_End:
489 case kCpumMicroarch_AMD_K8_End:
490 case kCpumMicroarch_AMD_15h_End:
491 case kCpumMicroarch_AMD_16h_End:
492 case kCpumMicroarch_AMD_End:
493 case kCpumMicroarch_VIA_End:
494 case kCpumMicroarch_Cyrix_End:
495 case kCpumMicroarch_32BitHack:
496 break;
497 /* no default! */
498 }
499
500 return NULL;
501}
502
503
504
505/**
506 * Gets a matching leaf in the CPUID leaf array.
507 *
508 * @returns Pointer to the matching leaf, or NULL if not found.
509 * @param paLeaves The CPUID leaves to search. This is sorted.
510 * @param cLeaves The number of leaves in the array.
511 * @param uLeaf The leaf to locate.
512 * @param uSubLeaf The subleaf to locate. Pass 0 if no subleaves.
513 */
514PCPUMCPUIDLEAF cpumR3CpuIdGetLeaf(PCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf, uint32_t uSubLeaf)
515{
516 /* Lazy bird does linear lookup here since this is only used for the
517 occational CPUID overrides. */
518 for (uint32_t i = 0; i < cLeaves; i++)
519 if ( paLeaves[i].uLeaf == uLeaf
520 && paLeaves[i].uSubLeaf == (uSubLeaf & paLeaves[i].fSubLeafMask))
521 return &paLeaves[i];
522 return NULL;
523}
524
525
526/**
527 * Gets a matching leaf in the CPUID leaf array, converted to a CPUMCPUID.
528 *
529 * @returns true if found, false it not.
530 * @param paLeaves The CPUID leaves to search. This is sorted.
531 * @param cLeaves The number of leaves in the array.
532 * @param uLeaf The leaf to locate.
533 * @param uSubLeaf The subleaf to locate. Pass 0 if no subleaves.
534 * @param pLegacy The legacy output leaf.
535 */
536bool cpumR3CpuIdGetLeafLegacy(PCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf, uint32_t uSubLeaf, PCPUMCPUID pLegacy)
537{
538 PCPUMCPUIDLEAF pLeaf = cpumR3CpuIdGetLeaf(paLeaves, cLeaves, uLeaf, uSubLeaf);
539 if (pLeaf)
540 {
541 pLegacy->eax = pLeaf->uEax;
542 pLegacy->ebx = pLeaf->uEbx;
543 pLegacy->ecx = pLeaf->uEcx;
544 pLegacy->edx = pLeaf->uEdx;
545 return true;
546 }
547 return false;
548}
549
550
551/**
552 * Ensures that the CPUID leaf array can hold one more leaf.
553 *
554 * @returns Pointer to the CPUID leaf array (*ppaLeaves) on success. NULL on
555 * failure.
556 * @param pVM Pointer to the VM, used as the heap selector. Passing
557 * NULL uses the host-context heap, otherwise the VM's
558 * hyper heap is used.
559 * @param ppaLeaves Pointer to the variable holding the array pointer
560 * (input/output).
561 * @param cLeaves The current array size.
562 *
563 * @remarks This function will automatically update the R0 and RC pointers when
564 * using the hyper heap, which means @a ppaLeaves and @a cLeaves must
565 * be the corresponding VM's CPUID arrays (which is asserted).
566 */
567static PCPUMCPUIDLEAF cpumR3CpuIdEnsureSpace(PVM pVM, PCPUMCPUIDLEAF *ppaLeaves, uint32_t cLeaves)
568{
569 uint32_t cAllocated;
570 if (!pVM)
571 cAllocated = RT_ALIGN(cLeaves, 16);
572 else
573 {
574 /*
575 * We're using the hyper heap now, but when the arrays were copied over to it from
576 * the host-context heap, we only copy the exact size and not the ensured size.
577 * See @bugref{7270}.
578 */
579 cAllocated = cLeaves;
580 }
581
582 if (cLeaves + 1 > cAllocated)
583 {
584 void *pvNew;
585#ifndef IN_VBOX_CPU_REPORT
586 if (pVM)
587 {
588 Assert(ppaLeaves == &pVM->cpum.s.GuestInfo.paCpuIdLeavesR3);
589 Assert(cLeaves == pVM->cpum.s.GuestInfo.cCpuIdLeaves);
590
591 size_t cb = cAllocated * sizeof(**ppaLeaves);
592 size_t cbNew = (cAllocated + 16) * sizeof(**ppaLeaves);
593 int rc = MMR3HyperRealloc(pVM, *ppaLeaves, cb, 32, MM_TAG_CPUM_CPUID, cbNew, &pvNew);
594 if (RT_FAILURE(rc))
595 {
596 *ppaLeaves = NULL;
597 pVM->cpum.s.GuestInfo.paCpuIdLeavesR0 = NIL_RTR0PTR;
598 pVM->cpum.s.GuestInfo.paCpuIdLeavesRC = NIL_RTRCPTR;
599 LogRel(("CPUM: cpumR3CpuIdEnsureSpace: MMR3HyperRealloc failed. rc=%Rrc\n", rc));
600 return NULL;
601 }
602 *ppaLeaves = (PCPUMCPUIDLEAF)pvNew;
603 }
604 else
605#endif
606 {
607 pvNew = RTMemRealloc(*ppaLeaves, (cAllocated + 16) * sizeof(**ppaLeaves));
608 if (!pvNew)
609 {
610 RTMemFree(*ppaLeaves);
611 *ppaLeaves = NULL;
612 return NULL;
613 }
614 *ppaLeaves = (PCPUMCPUIDLEAF)pvNew;
615 }
616 }
617
618#ifndef IN_VBOX_CPU_REPORT
619 /* Update the R0 and RC pointers. */
620 if (pVM)
621 {
622 Assert(ppaLeaves == &pVM->cpum.s.GuestInfo.paCpuIdLeavesR3);
623 pVM->cpum.s.GuestInfo.paCpuIdLeavesR0 = MMHyperR3ToR0(pVM, *ppaLeaves);
624 pVM->cpum.s.GuestInfo.paCpuIdLeavesRC = MMHyperR3ToRC(pVM, *ppaLeaves);
625 }
626#endif
627
628 return *ppaLeaves;
629}
630
631
632/**
633 * Append a CPUID leaf or sub-leaf.
634 *
635 * ASSUMES linear insertion order, so we'll won't need to do any searching or
636 * replace anything. Use cpumR3CpuIdInsert() for those cases.
637 *
638 * @returns VINF_SUCCESS or VERR_NO_MEMORY. On error, *ppaLeaves is freed, so
639 * the caller need do no more work.
640 * @param ppaLeaves Pointer to the the pointer to the array of sorted
641 * CPUID leaves and sub-leaves.
642 * @param pcLeaves Where we keep the leaf count for *ppaLeaves.
643 * @param uLeaf The leaf we're adding.
644 * @param uSubLeaf The sub-leaf number.
645 * @param fSubLeafMask The sub-leaf mask.
646 * @param uEax The EAX value.
647 * @param uEbx The EBX value.
648 * @param uEcx The ECX value.
649 * @param uEdx The EDX value.
650 * @param fFlags The flags.
651 */
652static int cpumR3CollectCpuIdInfoAddOne(PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves,
653 uint32_t uLeaf, uint32_t uSubLeaf, uint32_t fSubLeafMask,
654 uint32_t uEax, uint32_t uEbx, uint32_t uEcx, uint32_t uEdx, uint32_t fFlags)
655{
656 if (!cpumR3CpuIdEnsureSpace(NULL /* pVM */, ppaLeaves, *pcLeaves))
657 return VERR_NO_MEMORY;
658
659 PCPUMCPUIDLEAF pNew = &(*ppaLeaves)[*pcLeaves];
660 Assert( *pcLeaves == 0
661 || pNew[-1].uLeaf < uLeaf
662 || (pNew[-1].uLeaf == uLeaf && pNew[-1].uSubLeaf < uSubLeaf) );
663
664 pNew->uLeaf = uLeaf;
665 pNew->uSubLeaf = uSubLeaf;
666 pNew->fSubLeafMask = fSubLeafMask;
667 pNew->uEax = uEax;
668 pNew->uEbx = uEbx;
669 pNew->uEcx = uEcx;
670 pNew->uEdx = uEdx;
671 pNew->fFlags = fFlags;
672
673 *pcLeaves += 1;
674 return VINF_SUCCESS;
675}
676
677
678/**
679 * Inserts a CPU ID leaf, replacing any existing ones.
680 *
681 * When inserting a simple leaf where we already got a series of subleaves with
682 * the same leaf number (eax), the simple leaf will replace the whole series.
683 *
684 * When pVM is NULL, this ASSUMES that the leaves array is still on the normal
685 * host-context heap and has only been allocated/reallocated by the
686 * cpumR3CpuIdEnsureSpace function.
687 *
688 * @returns VBox status code.
689 * @param pVM Pointer to the VM, used as the heap selector.
690 * Passing NULL uses the host-context heap, otherwise
691 * the VM's hyper heap is used.
692 * @param ppaLeaves Pointer to the the pointer to the array of sorted
693 * CPUID leaves and sub-leaves. Must be NULL if using
694 * the hyper heap.
695 * @param pcLeaves Where we keep the leaf count for *ppaLeaves. Must be
696 * NULL if using the hyper heap.
697 * @param pNewLeaf Pointer to the data of the new leaf we're about to
698 * insert.
699 */
700int cpumR3CpuIdInsert(PVM pVM, PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves, PCPUMCPUIDLEAF pNewLeaf)
701{
702 /*
703 * Validate input parameters if we are using the hyper heap and use the VM's CPUID arrays.
704 */
705 if (pVM)
706 {
707 AssertReturn(!ppaLeaves, VERR_INVALID_PARAMETER);
708 AssertReturn(!pcLeaves, VERR_INVALID_PARAMETER);
709
710 ppaLeaves = &pVM->cpum.s.GuestInfo.paCpuIdLeavesR3;
711 pcLeaves = &pVM->cpum.s.GuestInfo.cCpuIdLeaves;
712 }
713
714 PCPUMCPUIDLEAF paLeaves = *ppaLeaves;
715 uint32_t cLeaves = *pcLeaves;
716
717 /*
718 * Validate the new leaf a little.
719 */
720 AssertReturn(!(pNewLeaf->fFlags & ~CPUMCPUIDLEAF_F_SUBLEAVES_ECX_UNCHANGED), VERR_INVALID_FLAGS);
721 AssertReturn(pNewLeaf->fSubLeafMask != 0 || pNewLeaf->uSubLeaf == 0, VERR_INVALID_PARAMETER);
722 AssertReturn(RT_IS_POWER_OF_TWO(pNewLeaf->fSubLeafMask + 1), VERR_INVALID_PARAMETER);
723 AssertReturn((pNewLeaf->fSubLeafMask & pNewLeaf->uSubLeaf) == pNewLeaf->uSubLeaf, VERR_INVALID_PARAMETER);
724
725 /*
726 * Find insertion point. The lazy bird uses the same excuse as in
727 * cpumR3CpuIdGetLeaf().
728 */
729 uint32_t i = 0;
730 while ( i < cLeaves
731 && paLeaves[i].uLeaf < pNewLeaf->uLeaf)
732 i++;
733 if ( i < cLeaves
734 && paLeaves[i].uLeaf == pNewLeaf->uLeaf)
735 {
736 if (paLeaves[i].fSubLeafMask != pNewLeaf->fSubLeafMask)
737 {
738 /*
739 * The subleaf mask differs, replace all existing leaves with the
740 * same leaf number.
741 */
742 uint32_t c = 1;
743 while ( i + c < cLeaves
744 && paLeaves[i + c].uSubLeaf == pNewLeaf->uLeaf)
745 c++;
746 if (c > 1 && i + c < cLeaves)
747 {
748 memmove(&paLeaves[i + c], &paLeaves[i + 1], (cLeaves - i - c) * sizeof(paLeaves[0]));
749 *pcLeaves = cLeaves -= c - 1;
750 }
751
752 paLeaves[i] = *pNewLeaf;
753 return VINF_SUCCESS;
754 }
755
756 /* Find subleaf insertion point. */
757 while ( i < cLeaves
758 && paLeaves[i].uSubLeaf < pNewLeaf->uSubLeaf)
759 i++;
760
761 /*
762 * If we've got an exactly matching leaf, replace it.
763 */
764 if ( paLeaves[i].uLeaf == pNewLeaf->uLeaf
765 && paLeaves[i].uSubLeaf == pNewLeaf->uSubLeaf)
766 {
767 paLeaves[i] = *pNewLeaf;
768 return VINF_SUCCESS;
769 }
770 }
771
772 /*
773 * Adding a new leaf at 'i'.
774 */
775 paLeaves = cpumR3CpuIdEnsureSpace(pVM, ppaLeaves, cLeaves);
776 if (!paLeaves)
777 return VERR_NO_MEMORY;
778
779 if (i < cLeaves)
780 memmove(&paLeaves[i + 1], &paLeaves[i], (cLeaves - i) * sizeof(paLeaves[0]));
781 *pcLeaves += 1;
782 paLeaves[i] = *pNewLeaf;
783 return VINF_SUCCESS;
784}
785
786
787/**
788 * Removes a range of CPUID leaves.
789 *
790 * This will not reallocate the array.
791 *
792 * @param paLeaves The array of sorted CPUID leaves and sub-leaves.
793 * @param pcLeaves Where we keep the leaf count for @a paLeaves.
794 * @param uFirst The first leaf.
795 * @param uLast The last leaf.
796 */
797void cpumR3CpuIdRemoveRange(PCPUMCPUIDLEAF paLeaves, uint32_t *pcLeaves, uint32_t uFirst, uint32_t uLast)
798{
799 uint32_t cLeaves = *pcLeaves;
800
801 Assert(uFirst <= uLast);
802
803 /*
804 * Find the first one.
805 */
806 uint32_t iFirst = 0;
807 while ( iFirst < cLeaves
808 && paLeaves[iFirst].uLeaf < uFirst)
809 iFirst++;
810
811 /*
812 * Find the end (last + 1).
813 */
814 uint32_t iEnd = iFirst;
815 while ( iEnd < cLeaves
816 && paLeaves[iEnd].uLeaf <= uLast)
817 iEnd++;
818
819 /*
820 * Adjust the array if anything needs removing.
821 */
822 if (iFirst < iEnd)
823 {
824 if (iEnd < cLeaves)
825 memmove(&paLeaves[iFirst], &paLeaves[iEnd], (cLeaves - iEnd) * sizeof(paLeaves[0]));
826 *pcLeaves = cLeaves -= (iEnd - iFirst);
827 }
828}
829
830
831
832/**
833 * Checks if ECX make a difference when reading a given CPUID leaf.
834 *
835 * @returns @c true if it does, @c false if it doesn't.
836 * @param uLeaf The leaf we're reading.
837 * @param pcSubLeaves Number of sub-leaves accessible via ECX.
838 * @param pfFinalEcxUnchanged Whether ECX is passed thru when going beyond the
839 * final sub-leaf.
840 */
841static bool cpumR3IsEcxRelevantForCpuIdLeaf(uint32_t uLeaf, uint32_t *pcSubLeaves, bool *pfFinalEcxUnchanged)
842{
843 *pfFinalEcxUnchanged = false;
844
845 uint32_t auCur[4];
846 uint32_t auPrev[4];
847 ASMCpuIdExSlow(uLeaf, 0, 0, 0, &auPrev[0], &auPrev[1], &auPrev[2], &auPrev[3]);
848
849 /* Look for sub-leaves. */
850 uint32_t uSubLeaf = 1;
851 for (;;)
852 {
853 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
854 if (memcmp(auCur, auPrev, sizeof(auCur)))
855 break;
856
857 /* Advance / give up. */
858 uSubLeaf++;
859 if (uSubLeaf >= 64)
860 {
861 *pcSubLeaves = 1;
862 return false;
863 }
864 }
865
866 /* Count sub-leaves. */
867 uint32_t cRepeats = 0;
868 uSubLeaf = 0;
869 for (;;)
870 {
871 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
872
873 /* Figuring out when to stop isn't entirely straight forward as we need
874 to cover undocumented behavior up to a point and implementation shortcuts. */
875
876 /* 1. Look for zero values. */
877 if ( auCur[0] == 0
878 && auCur[1] == 0
879 && (auCur[2] == 0 || auCur[2] == uSubLeaf)
880 && (auCur[3] == 0 || uLeaf == 0xb /* edx is fixed */) )
881 break;
882
883 /* 2. Look for more than 4 repeating value sets. */
884 if ( auCur[0] == auPrev[0]
885 && auCur[1] == auPrev[1]
886 && ( auCur[2] == auPrev[2]
887 || ( auCur[2] == uSubLeaf
888 && auPrev[2] == uSubLeaf - 1) )
889 && auCur[3] == auPrev[3])
890 {
891 cRepeats++;
892 if (cRepeats > 4)
893 break;
894 }
895 else
896 cRepeats = 0;
897
898 /* 3. Leaf 0xb level type 0 check. */
899 if ( uLeaf == 0xb
900 && (auCur[3] & 0xff00) == 0
901 && (auPrev[3] & 0xff00) == 0)
902 break;
903
904 /* 99. Give up. */
905 if (uSubLeaf >= 128)
906 {
907#ifndef IN_VBOX_CPU_REPORT
908 /* Ok, limit it according to the documentation if possible just to
909 avoid annoying users with these detection issues. */
910 uint32_t cDocLimit = UINT32_MAX;
911 if (uLeaf == 0x4)
912 cDocLimit = 4;
913 else if (uLeaf == 0x7)
914 cDocLimit = 1;
915 else if (uLeaf == 0xf)
916 cDocLimit = 2;
917 if (cDocLimit != UINT32_MAX)
918 {
919 *pfFinalEcxUnchanged = auCur[2] == uSubLeaf;
920 *pcSubLeaves = cDocLimit + 3;
921 return true;
922 }
923#endif
924 *pcSubLeaves = UINT32_MAX;
925 return true;
926 }
927
928 /* Advance. */
929 uSubLeaf++;
930 memcpy(auPrev, auCur, sizeof(auCur));
931 }
932
933 /* Standard exit. */
934 *pfFinalEcxUnchanged = auCur[2] == uSubLeaf;
935 *pcSubLeaves = uSubLeaf + 1 - cRepeats;
936 return true;
937}
938
939
940/**
941 * Gets a CPU ID leaf.
942 *
943 * @returns VBox status code.
944 * @param pVM Pointer to the VM.
945 * @param pLeaf Where to store the found leaf.
946 * @param uLeaf The leaf to locate.
947 * @param uSubLeaf The subleaf to locate. Pass 0 if no subleaves.
948 */
949VMMR3DECL(int) CPUMR3CpuIdGetLeaf(PVM pVM, PCPUMCPUIDLEAF pLeaf, uint32_t uLeaf, uint32_t uSubLeaf)
950{
951 PCPUMCPUIDLEAF pcLeaf = cpumR3CpuIdGetLeaf(pVM->cpum.s.GuestInfo.paCpuIdLeavesR3, pVM->cpum.s.GuestInfo.cCpuIdLeaves,
952 uLeaf, uSubLeaf);
953 if (pcLeaf)
954 {
955 memcpy(pLeaf, pcLeaf, sizeof(*pLeaf));
956 return VINF_SUCCESS;
957 }
958
959 return VERR_NOT_FOUND;
960}
961
962
963/**
964 * Inserts a CPU ID leaf, replacing any existing ones.
965 *
966 * @returns VBox status code.
967 * @param pVM Pointer to the VM.
968 * @param pNewLeaf Pointer to the leaf being inserted.
969 */
970VMMR3DECL(int) CPUMR3CpuIdInsert(PVM pVM, PCPUMCPUIDLEAF pNewLeaf)
971{
972 /*
973 * Validate parameters.
974 */
975 AssertReturn(pVM, VERR_INVALID_PARAMETER);
976 AssertReturn(pNewLeaf, VERR_INVALID_PARAMETER);
977
978 /*
979 * Disallow replacing CPU ID leaves that this API currently cannot manage.
980 * These leaves have dependencies on saved-states, see PATMCpuidReplacement().
981 * If you want to modify these leaves, use CPUMSetGuestCpuIdFeature().
982 */
983 if ( pNewLeaf->uLeaf == UINT32_C(0x00000000) /* Standard */
984 || pNewLeaf->uLeaf == UINT32_C(0x80000000) /* Extended */
985 || pNewLeaf->uLeaf == UINT32_C(0xc0000000)) /* Centaur */
986 {
987 return VERR_NOT_SUPPORTED;
988 }
989
990 return cpumR3CpuIdInsert(pVM, NULL /* ppaLeaves */, NULL /* pcLeaves */, pNewLeaf);
991}
992
993/**
994 * Collects CPUID leaves and sub-leaves, returning a sorted array of them.
995 *
996 * @returns VBox status code.
997 * @param ppaLeaves Where to return the array pointer on success.
998 * Use RTMemFree to release.
999 * @param pcLeaves Where to return the size of the array on
1000 * success.
1001 */
1002VMMR3DECL(int) CPUMR3CpuIdCollectLeaves(PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves)
1003{
1004 *ppaLeaves = NULL;
1005 *pcLeaves = 0;
1006
1007 /*
1008 * Try out various candidates. This must be sorted!
1009 */
1010 static struct { uint32_t uMsr; bool fSpecial; } const s_aCandidates[] =
1011 {
1012 { UINT32_C(0x00000000), false },
1013 { UINT32_C(0x10000000), false },
1014 { UINT32_C(0x20000000), false },
1015 { UINT32_C(0x30000000), false },
1016 { UINT32_C(0x40000000), false },
1017 { UINT32_C(0x50000000), false },
1018 { UINT32_C(0x60000000), false },
1019 { UINT32_C(0x70000000), false },
1020 { UINT32_C(0x80000000), false },
1021 { UINT32_C(0x80860000), false },
1022 { UINT32_C(0x8ffffffe), true },
1023 { UINT32_C(0x8fffffff), true },
1024 { UINT32_C(0x90000000), false },
1025 { UINT32_C(0xa0000000), false },
1026 { UINT32_C(0xb0000000), false },
1027 { UINT32_C(0xc0000000), false },
1028 { UINT32_C(0xd0000000), false },
1029 { UINT32_C(0xe0000000), false },
1030 { UINT32_C(0xf0000000), false },
1031 };
1032
1033 for (uint32_t iOuter = 0; iOuter < RT_ELEMENTS(s_aCandidates); iOuter++)
1034 {
1035 uint32_t uLeaf = s_aCandidates[iOuter].uMsr;
1036 uint32_t uEax, uEbx, uEcx, uEdx;
1037 ASMCpuIdExSlow(uLeaf, 0, 0, 0, &uEax, &uEbx, &uEcx, &uEdx);
1038
1039 /*
1040 * Does EAX look like a typical leaf count value?
1041 */
1042 if ( uEax > uLeaf
1043 && uEax - uLeaf < UINT32_C(0xff)) /* Adjust 0xff limit when exceeded by real HW. */
1044 {
1045 /* Yes, dump them. */
1046 uint32_t cLeaves = uEax - uLeaf + 1;
1047 while (cLeaves-- > 0)
1048 {
1049 /* Check three times here to reduce the chance of CPU migration
1050 resulting in false positives with things like the APIC ID. */
1051 uint32_t cSubLeaves;
1052 bool fFinalEcxUnchanged;
1053 if ( cpumR3IsEcxRelevantForCpuIdLeaf(uLeaf, &cSubLeaves, &fFinalEcxUnchanged)
1054 && cpumR3IsEcxRelevantForCpuIdLeaf(uLeaf, &cSubLeaves, &fFinalEcxUnchanged)
1055 && cpumR3IsEcxRelevantForCpuIdLeaf(uLeaf, &cSubLeaves, &fFinalEcxUnchanged))
1056 {
1057 if (cSubLeaves > 16)
1058 {
1059 /* This shouldn't happen. But in case it does, file all
1060 relevant details in the release log. */
1061 LogRel(("CPUM: VERR_CPUM_TOO_MANY_CPUID_SUBLEAVES! uLeaf=%#x cSubLeaves=%#x\n", uLeaf, cSubLeaves));
1062 LogRel(("------------------ dump of problematic subleaves ------------------\n"));
1063 for (uint32_t uSubLeaf = 0; uSubLeaf < 128; uSubLeaf++)
1064 {
1065 uint32_t auTmp[4];
1066 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &auTmp[0], &auTmp[1], &auTmp[2], &auTmp[3]);
1067 LogRel(("CPUM: %#010x, %#010x => %#010x %#010x %#010x %#010x\n",
1068 uLeaf, uSubLeaf, auTmp[0], auTmp[1], auTmp[2], auTmp[3]));
1069 }
1070 LogRel(("----------------- dump of what we've found so far -----------------\n"));
1071 for (uint32_t i = 0 ; i < *pcLeaves; i++)
1072 LogRel(("CPUM: %#010x, %#010x/%#010x => %#010x %#010x %#010x %#010x\n",
1073 (*ppaLeaves)[i].uLeaf, (*ppaLeaves)[i].uSubLeaf, (*ppaLeaves)[i].fSubLeafMask,
1074 (*ppaLeaves)[i].uEax, (*ppaLeaves)[i].uEbx, (*ppaLeaves)[i].uEcx, (*ppaLeaves)[i].uEdx));
1075 LogRel(("\nPlease create a defect on virtualbox.org and attach this log file!\n\n"));
1076 return VERR_CPUM_TOO_MANY_CPUID_SUBLEAVES;
1077 }
1078
1079 for (uint32_t uSubLeaf = 0; uSubLeaf < cSubLeaves; uSubLeaf++)
1080 {
1081 ASMCpuIdExSlow(uLeaf, 0, uSubLeaf, 0, &uEax, &uEbx, &uEcx, &uEdx);
1082 int rc = cpumR3CollectCpuIdInfoAddOne(ppaLeaves, pcLeaves,
1083 uLeaf, uSubLeaf, UINT32_MAX, uEax, uEbx, uEcx, uEdx,
1084 uSubLeaf + 1 == cSubLeaves && fFinalEcxUnchanged
1085 ? CPUMCPUIDLEAF_F_SUBLEAVES_ECX_UNCHANGED : 0);
1086 if (RT_FAILURE(rc))
1087 return rc;
1088 }
1089 }
1090 else
1091 {
1092 ASMCpuIdExSlow(uLeaf, 0, 0, 0, &uEax, &uEbx, &uEcx, &uEdx);
1093 int rc = cpumR3CollectCpuIdInfoAddOne(ppaLeaves, pcLeaves,
1094 uLeaf, 0, 0, uEax, uEbx, uEcx, uEdx, 0);
1095 if (RT_FAILURE(rc))
1096 return rc;
1097 }
1098
1099 /* next */
1100 uLeaf++;
1101 }
1102 }
1103 /*
1104 * Special CPUIDs needs special handling as they don't follow the
1105 * leaf count principle used above.
1106 */
1107 else if (s_aCandidates[iOuter].fSpecial)
1108 {
1109 bool fKeep = false;
1110 if (uLeaf == 0x8ffffffe && uEax == UINT32_C(0x00494544))
1111 fKeep = true;
1112 else if ( uLeaf == 0x8fffffff
1113 && RT_C_IS_PRINT(RT_BYTE1(uEax))
1114 && RT_C_IS_PRINT(RT_BYTE2(uEax))
1115 && RT_C_IS_PRINT(RT_BYTE3(uEax))
1116 && RT_C_IS_PRINT(RT_BYTE4(uEax))
1117 && RT_C_IS_PRINT(RT_BYTE1(uEbx))
1118 && RT_C_IS_PRINT(RT_BYTE2(uEbx))
1119 && RT_C_IS_PRINT(RT_BYTE3(uEbx))
1120 && RT_C_IS_PRINT(RT_BYTE4(uEbx))
1121 && RT_C_IS_PRINT(RT_BYTE1(uEcx))
1122 && RT_C_IS_PRINT(RT_BYTE2(uEcx))
1123 && RT_C_IS_PRINT(RT_BYTE3(uEcx))
1124 && RT_C_IS_PRINT(RT_BYTE4(uEcx))
1125 && RT_C_IS_PRINT(RT_BYTE1(uEdx))
1126 && RT_C_IS_PRINT(RT_BYTE2(uEdx))
1127 && RT_C_IS_PRINT(RT_BYTE3(uEdx))
1128 && RT_C_IS_PRINT(RT_BYTE4(uEdx)) )
1129 fKeep = true;
1130 if (fKeep)
1131 {
1132 int rc = cpumR3CollectCpuIdInfoAddOne(ppaLeaves, pcLeaves,
1133 uLeaf, 0, 0, uEax, uEbx, uEcx, uEdx, 0);
1134 if (RT_FAILURE(rc))
1135 return rc;
1136 }
1137 }
1138 }
1139
1140 return VINF_SUCCESS;
1141}
1142
1143
1144/**
1145 * Determines the method the CPU uses to handle unknown CPUID leaves.
1146 *
1147 * @returns VBox status code.
1148 * @param penmUnknownMethod Where to return the method.
1149 * @param pDefUnknown Where to return default unknown values. This
1150 * will be set, even if the resulting method
1151 * doesn't actually needs it.
1152 */
1153VMMR3DECL(int) CPUMR3CpuIdDetectUnknownLeafMethod(PCPUMUKNOWNCPUID penmUnknownMethod, PCPUMCPUID pDefUnknown)
1154{
1155 uint32_t uLastStd = ASMCpuId_EAX(0);
1156 uint32_t uLastExt = ASMCpuId_EAX(0x80000000);
1157 if (!ASMIsValidExtRange(uLastExt))
1158 uLastExt = 0x80000000;
1159
1160 uint32_t auChecks[] =
1161 {
1162 uLastStd + 1,
1163 uLastStd + 5,
1164 uLastStd + 8,
1165 uLastStd + 32,
1166 uLastStd + 251,
1167 uLastExt + 1,
1168 uLastExt + 8,
1169 uLastExt + 15,
1170 uLastExt + 63,
1171 uLastExt + 255,
1172 0x7fbbffcc,
1173 0x833f7872,
1174 0xefff2353,
1175 0x35779456,
1176 0x1ef6d33e,
1177 };
1178
1179 static const uint32_t s_auValues[] =
1180 {
1181 0xa95d2156,
1182 0x00000001,
1183 0x00000002,
1184 0x00000008,
1185 0x00000000,
1186 0x55773399,
1187 0x93401769,
1188 0x12039587,
1189 };
1190
1191 /*
1192 * Simple method, all zeros.
1193 */
1194 *penmUnknownMethod = CPUMUKNOWNCPUID_DEFAULTS;
1195 pDefUnknown->eax = 0;
1196 pDefUnknown->ebx = 0;
1197 pDefUnknown->ecx = 0;
1198 pDefUnknown->edx = 0;
1199
1200 /*
1201 * Intel has been observed returning the last standard leaf.
1202 */
1203 uint32_t auLast[4];
1204 ASMCpuIdExSlow(uLastStd, 0, 0, 0, &auLast[0], &auLast[1], &auLast[2], &auLast[3]);
1205
1206 uint32_t cChecks = RT_ELEMENTS(auChecks);
1207 while (cChecks > 0)
1208 {
1209 uint32_t auCur[4];
1210 ASMCpuIdExSlow(auChecks[cChecks - 1], 0, 0, 0, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
1211 if (memcmp(auCur, auLast, sizeof(auCur)))
1212 break;
1213 cChecks--;
1214 }
1215 if (cChecks == 0)
1216 {
1217 /* Now, what happens when the input changes? Esp. ECX. */
1218 uint32_t cTotal = 0;
1219 uint32_t cSame = 0;
1220 uint32_t cLastWithEcx = 0;
1221 uint32_t cNeither = 0;
1222 uint32_t cValues = RT_ELEMENTS(s_auValues);
1223 while (cValues > 0)
1224 {
1225 uint32_t uValue = s_auValues[cValues - 1];
1226 uint32_t auLastWithEcx[4];
1227 ASMCpuIdExSlow(uLastStd, uValue, uValue, uValue,
1228 &auLastWithEcx[0], &auLastWithEcx[1], &auLastWithEcx[2], &auLastWithEcx[3]);
1229
1230 cChecks = RT_ELEMENTS(auChecks);
1231 while (cChecks > 0)
1232 {
1233 uint32_t auCur[4];
1234 ASMCpuIdExSlow(auChecks[cChecks - 1], uValue, uValue, uValue, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
1235 if (!memcmp(auCur, auLast, sizeof(auCur)))
1236 {
1237 cSame++;
1238 if (!memcmp(auCur, auLastWithEcx, sizeof(auCur)))
1239 cLastWithEcx++;
1240 }
1241 else if (!memcmp(auCur, auLastWithEcx, sizeof(auCur)))
1242 cLastWithEcx++;
1243 else
1244 cNeither++;
1245 cTotal++;
1246 cChecks--;
1247 }
1248 cValues--;
1249 }
1250
1251 Log(("CPUM: cNeither=%d cSame=%d cLastWithEcx=%d cTotal=%d\n", cNeither, cSame, cLastWithEcx, cTotal));
1252 if (cSame == cTotal)
1253 *penmUnknownMethod = CPUMUKNOWNCPUID_LAST_STD_LEAF;
1254 else if (cLastWithEcx == cTotal)
1255 *penmUnknownMethod = CPUMUKNOWNCPUID_LAST_STD_LEAF_WITH_ECX;
1256 else
1257 *penmUnknownMethod = CPUMUKNOWNCPUID_LAST_STD_LEAF;
1258 pDefUnknown->eax = auLast[0];
1259 pDefUnknown->ebx = auLast[1];
1260 pDefUnknown->ecx = auLast[2];
1261 pDefUnknown->edx = auLast[3];
1262 return VINF_SUCCESS;
1263 }
1264
1265 /*
1266 * Unchanged register values?
1267 */
1268 cChecks = RT_ELEMENTS(auChecks);
1269 while (cChecks > 0)
1270 {
1271 uint32_t const uLeaf = auChecks[cChecks - 1];
1272 uint32_t cValues = RT_ELEMENTS(s_auValues);
1273 while (cValues > 0)
1274 {
1275 uint32_t uValue = s_auValues[cValues - 1];
1276 uint32_t auCur[4];
1277 ASMCpuIdExSlow(uLeaf, uValue, uValue, uValue, &auCur[0], &auCur[1], &auCur[2], &auCur[3]);
1278 if ( auCur[0] != uLeaf
1279 || auCur[1] != uValue
1280 || auCur[2] != uValue
1281 || auCur[3] != uValue)
1282 break;
1283 cValues--;
1284 }
1285 if (cValues != 0)
1286 break;
1287 cChecks--;
1288 }
1289 if (cChecks == 0)
1290 {
1291 *penmUnknownMethod = CPUMUKNOWNCPUID_PASSTHRU;
1292 return VINF_SUCCESS;
1293 }
1294
1295 /*
1296 * Just go with the simple method.
1297 */
1298 return VINF_SUCCESS;
1299}
1300
1301
1302/**
1303 * Translates a unknow CPUID leaf method into the constant name (sans prefix).
1304 *
1305 * @returns Read only name string.
1306 * @param enmUnknownMethod The method to translate.
1307 */
1308VMMR3DECL(const char *) CPUMR3CpuIdUnknownLeafMethodName(CPUMUKNOWNCPUID enmUnknownMethod)
1309{
1310 switch (enmUnknownMethod)
1311 {
1312 case CPUMUKNOWNCPUID_DEFAULTS: return "DEFAULTS";
1313 case CPUMUKNOWNCPUID_LAST_STD_LEAF: return "LAST_STD_LEAF";
1314 case CPUMUKNOWNCPUID_LAST_STD_LEAF_WITH_ECX: return "LAST_STD_LEAF_WITH_ECX";
1315 case CPUMUKNOWNCPUID_PASSTHRU: return "PASSTHRU";
1316
1317 case CPUMUKNOWNCPUID_INVALID:
1318 case CPUMUKNOWNCPUID_END:
1319 case CPUMUKNOWNCPUID_32BIT_HACK:
1320 break;
1321 }
1322 return "Invalid-unknown-CPUID-method";
1323}
1324
1325
1326/**
1327 * Detect the CPU vendor give n the
1328 *
1329 * @returns The vendor.
1330 * @param uEAX EAX from CPUID(0).
1331 * @param uEBX EBX from CPUID(0).
1332 * @param uECX ECX from CPUID(0).
1333 * @param uEDX EDX from CPUID(0).
1334 */
1335VMMR3DECL(CPUMCPUVENDOR) CPUMR3CpuIdDetectVendorEx(uint32_t uEAX, uint32_t uEBX, uint32_t uECX, uint32_t uEDX)
1336{
1337 if (ASMIsValidStdRange(uEAX))
1338 {
1339 if (ASMIsAmdCpuEx(uEBX, uECX, uEDX))
1340 return CPUMCPUVENDOR_AMD;
1341
1342 if (ASMIsIntelCpuEx(uEBX, uECX, uEDX))
1343 return CPUMCPUVENDOR_INTEL;
1344
1345 if (ASMIsViaCentaurCpuEx(uEBX, uECX, uEDX))
1346 return CPUMCPUVENDOR_VIA;
1347
1348 if ( uEBX == UINT32_C(0x69727943) /* CyrixInstead */
1349 && uECX == UINT32_C(0x64616574)
1350 && uEDX == UINT32_C(0x736E4978))
1351 return CPUMCPUVENDOR_CYRIX;
1352
1353 /* "Geode by NSC", example: family 5, model 9. */
1354
1355 /** @todo detect the other buggers... */
1356 }
1357
1358 return CPUMCPUVENDOR_UNKNOWN;
1359}
1360
1361
1362/**
1363 * Translates a CPU vendor enum value into the corresponding string constant.
1364 *
1365 * The named can be prefixed with 'CPUMCPUVENDOR_' to construct a valid enum
1366 * value name. This can be useful when generating code.
1367 *
1368 * @returns Read only name string.
1369 * @param enmVendor The CPU vendor value.
1370 */
1371VMMR3DECL(const char *) CPUMR3CpuVendorName(CPUMCPUVENDOR enmVendor)
1372{
1373 switch (enmVendor)
1374 {
1375 case CPUMCPUVENDOR_INTEL: return "INTEL";
1376 case CPUMCPUVENDOR_AMD: return "AMD";
1377 case CPUMCPUVENDOR_VIA: return "VIA";
1378 case CPUMCPUVENDOR_CYRIX: return "CYRIX";
1379 case CPUMCPUVENDOR_UNKNOWN: return "UNKNOWN";
1380
1381 case CPUMCPUVENDOR_INVALID:
1382 case CPUMCPUVENDOR_32BIT_HACK:
1383 break;
1384 }
1385 return "Invalid-cpu-vendor";
1386}
1387
1388
1389static PCCPUMCPUIDLEAF cpumR3CpuIdFindLeaf(PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf)
1390{
1391 /* Could do binary search, doing linear now because I'm lazy. */
1392 PCCPUMCPUIDLEAF pLeaf = paLeaves;
1393 while (cLeaves-- > 0)
1394 {
1395 if (pLeaf->uLeaf == uLeaf)
1396 return pLeaf;
1397 pLeaf++;
1398 }
1399 return NULL;
1400}
1401
1402
1403int cpumR3CpuIdExplodeFeatures(PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, PCPUMFEATURES pFeatures)
1404{
1405 RT_ZERO(*pFeatures);
1406 if (cLeaves >= 2)
1407 {
1408 AssertLogRelReturn(paLeaves[0].uLeaf == 0, VERR_CPUM_IPE_1);
1409 AssertLogRelReturn(paLeaves[1].uLeaf == 1, VERR_CPUM_IPE_1);
1410
1411 pFeatures->enmCpuVendor = CPUMR3CpuIdDetectVendorEx(paLeaves[0].uEax,
1412 paLeaves[0].uEbx,
1413 paLeaves[0].uEcx,
1414 paLeaves[0].uEdx);
1415 pFeatures->uFamily = ASMGetCpuFamily(paLeaves[1].uEax);
1416 pFeatures->uModel = ASMGetCpuModel(paLeaves[1].uEax, pFeatures->enmCpuVendor == CPUMCPUVENDOR_INTEL);
1417 pFeatures->uStepping = ASMGetCpuStepping(paLeaves[1].uEax);
1418 pFeatures->enmMicroarch = CPUMR3CpuIdDetermineMicroarchEx((CPUMCPUVENDOR)pFeatures->enmCpuVendor,
1419 pFeatures->uFamily,
1420 pFeatures->uModel,
1421 pFeatures->uStepping);
1422
1423 PCCPUMCPUIDLEAF pLeaf = cpumR3CpuIdFindLeaf(paLeaves, cLeaves, 0x80000008);
1424 if (pLeaf)
1425 pFeatures->cMaxPhysAddrWidth = pLeaf->uEax & 0xff;
1426 else if (paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_PSE36)
1427 pFeatures->cMaxPhysAddrWidth = 36;
1428 else
1429 pFeatures->cMaxPhysAddrWidth = 32;
1430
1431 /* Standard features. */
1432 pFeatures->fMsr = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_MSR);
1433 pFeatures->fApic = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_APIC);
1434 pFeatures->fX2Apic = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_X2APIC);
1435 pFeatures->fPse = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_PSE);
1436 pFeatures->fPse36 = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_PSE36);
1437 pFeatures->fPae = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_PAE);
1438 pFeatures->fPat = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_PAT);
1439 pFeatures->fFxSaveRstor = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_FXSR);
1440 pFeatures->fSysEnter = RT_BOOL(paLeaves[1].uEdx & X86_CPUID_FEATURE_EDX_SEP);
1441 pFeatures->fHypervisorPresent = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_HVP);
1442 pFeatures->fMonitorMWait = RT_BOOL(paLeaves[1].uEcx & X86_CPUID_FEATURE_ECX_MONITOR);
1443
1444 /* MWAIT/MONITOR leaf. */
1445 PCCPUMCPUIDLEAF const pMWaitLeaf = cpumR3CpuIdFindLeaf(paLeaves, cLeaves, 5);
1446 if (pMWaitLeaf)
1447 {
1448 pFeatures->fMWaitExtensions = (pMWaitLeaf->uEcx & (X86_CPUID_MWAIT_ECX_EXT | X86_CPUID_MWAIT_ECX_BREAKIRQIF0))
1449 == (X86_CPUID_MWAIT_ECX_EXT | X86_CPUID_MWAIT_ECX_BREAKIRQIF0);
1450 }
1451
1452 /* Extended features. */
1453 PCCPUMCPUIDLEAF const pExtLeaf = cpumR3CpuIdFindLeaf(paLeaves, cLeaves, 0x80000001);
1454 if (pExtLeaf)
1455 {
1456 pFeatures->fLongMode = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_EXT_FEATURE_EDX_LONG_MODE);
1457 pFeatures->fSysCall = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_EXT_FEATURE_EDX_SYSCALL);
1458 pFeatures->fNoExecute = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_EXT_FEATURE_EDX_NX);
1459 pFeatures->fLahfSahf = RT_BOOL(pExtLeaf->uEcx & X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF);
1460 pFeatures->fRdTscP = RT_BOOL(pExtLeaf->uEdx & X86_CPUID_EXT_FEATURE_EDX_RDTSCP);
1461 }
1462
1463 if ( pExtLeaf
1464 && pFeatures->enmCpuVendor == CPUMCPUVENDOR_AMD)
1465 {
1466 /* AMD features. */
1467 pFeatures->fMsr |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_MSR);
1468 pFeatures->fApic |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_APIC);
1469 pFeatures->fPse |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_PSE);
1470 pFeatures->fPse36 |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_PSE36);
1471 pFeatures->fPae |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_PAE);
1472 pFeatures->fPat |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_PAT);
1473 pFeatures->fFxSaveRstor |= RT_BOOL(pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_FXSR);
1474 }
1475
1476 /*
1477 * Quirks.
1478 */
1479 pFeatures->fLeakyFxSR = pExtLeaf
1480 && (pExtLeaf->uEdx & X86_CPUID_AMD_FEATURE_EDX_FFXSR)
1481 && pFeatures->enmCpuVendor == CPUMCPUVENDOR_AMD
1482 && pFeatures->uFamily >= 6 /* K7 and up */;
1483 }
1484 else
1485 AssertLogRelReturn(cLeaves == 0, VERR_CPUM_IPE_1);
1486 return VINF_SUCCESS;
1487}
1488
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