VirtualBox

source: vbox/trunk/src/VBox/VMM/CPUM.cpp@ 9354

Last change on this file since 9354 was 9354, checked in by vboxsync, 17 years ago

Added CPUMGetCPUVendor.
Added CPUMCPUIDFEATURE_NXE, CPUMCPUIDFEATURE_LONG_MODE, CPUMCPUIDFEATURE_LAHF & CPUMCPUIDFEATURE_SYSCALL cpuid feature bits.

Enable the required cpuid feature bits in 64 bits mode.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 87.2 KB
Line 
1/* $Id: CPUM.cpp 9354 2008-06-03 13:45:14Z vboxsync $ */
2/** @file
3 * CPUM - CPU Monitor(/Manager)
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_CPUM
27#include <VBox/cpum.h>
28#include <VBox/cpumdis.h>
29#include <VBox/pgm.h>
30#include <VBox/mm.h>
31#include <VBox/selm.h>
32#include <VBox/dbgf.h>
33#include <VBox/patm.h>
34#include <VBox/ssm.h>
35#include "CPUMInternal.h"
36#include <VBox/vm.h>
37
38#include <VBox/param.h>
39#include <VBox/dis.h>
40#include <VBox/err.h>
41#include <VBox/log.h>
42#include <iprt/assert.h>
43#include <iprt/asm.h>
44#include <iprt/string.h>
45#include <iprt/system.h>
46
47
48/*******************************************************************************
49* Defined Constants And Macros *
50*******************************************************************************/
51/** The saved state version. */
52#define CPUM_SAVED_STATE_VERSION 6
53
54
55/*******************************************************************************
56* Structures and Typedefs *
57*******************************************************************************/
58
59/**
60 * What kind of cpu info dump to performe.
61 */
62typedef enum CPUMDUMPTYPE
63{
64 CPUMDUMPTYPE_TERSE,
65 CPUMDUMPTYPE_DEFAULT,
66 CPUMDUMPTYPE_VERBOSE
67
68} CPUMDUMPTYPE, *PCPUMDUMPTYPE;
69
70
71/*******************************************************************************
72* Internal Functions *
73*******************************************************************************/
74static int cpumR3CpuIdInit(PVM pVM);
75static DECLCALLBACK(int) cpumR3Save(PVM pVM, PSSMHANDLE pSSM);
76static DECLCALLBACK(int) cpumR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
77static DECLCALLBACK(void) cpumR3InfoAll(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
78static DECLCALLBACK(void) cpumR3InfoGuest(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
79static DECLCALLBACK(void) cpumR3InfoHyper(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
80static DECLCALLBACK(void) cpumR3InfoHost(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
81static DECLCALLBACK(void) cpumR3CpuIdInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
82
83
84/**
85 * Initializes the CPUM.
86 *
87 * @returns VBox status code.
88 * @param pVM The VM to operate on.
89 */
90CPUMR3DECL(int) CPUMR3Init(PVM pVM)
91{
92 LogFlow(("CPUMR3Init\n"));
93
94 /*
95 * Assert alignment and sizes.
96 */
97 AssertRelease(!(RT_OFFSETOF(VM, cpum.s) & 31));
98 AssertRelease(sizeof(pVM->cpum.s) <= sizeof(pVM->cpum.padding));
99
100 /*
101 * Setup any fixed pointers and offsets.
102 */
103 pVM->cpum.s.offVM = RT_OFFSETOF(VM, cpum);
104 pVM->cpum.s.pCPUMHC = &pVM->cpum.s;
105 pVM->cpum.s.pHyperCoreR3 = CPUMCTX2CORE(&pVM->cpum.s.Hyper);
106 pVM->cpum.s.pHyperCoreR0 = VM_R0_ADDR(pVM, CPUMCTX2CORE(&pVM->cpum.s.Hyper));
107
108 /* Hidden selector registers are invalid by default. */
109 pVM->cpum.s.fValidHiddenSelRegs = false;
110
111 /*
112 * Check that the CPU supports the minimum features we require.
113 */
114 /** @todo check the contract! */
115 if (!ASMHasCpuId())
116 {
117 Log(("The CPU doesn't support CPUID!\n"));
118 return VERR_UNSUPPORTED_CPU;
119 }
120 ASMCpuId_ECX_EDX(1, &pVM->cpum.s.CPUFeatures.ecx, &pVM->cpum.s.CPUFeatures.edx);
121
122 /* Setup the CR4 AND and OR masks used in the switcher */
123 /* Depends on the presence of FXSAVE(SSE) support on the host CPU */
124 if (!pVM->cpum.s.CPUFeatures.edx.u1FXSR)
125 {
126 Log(("The CPU doesn't support FXSAVE/FXRSTOR!\n"));
127 /* No FXSAVE implies no SSE */
128 pVM->cpum.s.CR4.AndMask = X86_CR4_PVI | X86_CR4_VME;
129 pVM->cpum.s.CR4.OrMask = 0;
130 }
131 else
132 {
133 pVM->cpum.s.CR4.AndMask = X86_CR4_OSXMMEEXCPT | X86_CR4_PVI | X86_CR4_VME;
134 pVM->cpum.s.CR4.OrMask = X86_CR4_OSFSXR;
135 }
136
137 if (!pVM->cpum.s.CPUFeatures.edx.u1MMX)
138 {
139 Log(("The CPU doesn't support MMX!\n"));
140 return VERR_UNSUPPORTED_CPU;
141 }
142 if (!pVM->cpum.s.CPUFeatures.edx.u1TSC)
143 {
144 Log(("The CPU doesn't support TSC!\n"));
145 return VERR_UNSUPPORTED_CPU;
146 }
147 /* Bogus on AMD? */
148 if (!pVM->cpum.s.CPUFeatures.edx.u1SEP)
149 {
150 Log(("The CPU doesn't support SYSENTER/SYSEXIT!\n"));
151 }
152
153 /*
154 * Setup hypervisor startup values.
155 */
156
157 /*
158 * Register saved state data item.
159 */
160 int rc = SSMR3RegisterInternal(pVM, "cpum", 1, CPUM_SAVED_STATE_VERSION, sizeof(CPUM),
161 NULL, cpumR3Save, NULL,
162 NULL, cpumR3Load, NULL);
163 if (VBOX_FAILURE(rc))
164 return rc;
165
166 /* Query the CPU manufacturer. */
167 uint32_t uEAX, uEBX, uECX, uEDX;
168 ASMCpuId(0, &uEAX, &uEBX, &uECX, &uEDX);
169 if ( uEAX >= 1
170 && uEBX == X86_CPUID_VENDOR_AMD_EBX
171 && uECX == X86_CPUID_VENDOR_AMD_ECX
172 && uEDX == X86_CPUID_VENDOR_AMD_EDX)
173 {
174 pVM->cpum.s.enmCPUVendor = CPUMCPUVENDOR_AMD;
175 }
176 else if ( uEAX >= 1
177 && uEBX == X86_CPUID_VENDOR_INTEL_EBX
178 && uECX == X86_CPUID_VENDOR_INTEL_ECX
179 && uEDX == X86_CPUID_VENDOR_INTEL_EDX)
180 {
181 pVM->cpum.s.enmCPUVendor = CPUMCPUVENDOR_INTEL;
182 }
183 else /* @todo Via */
184 pVM->cpum.s.enmCPUVendor = CPUMCPUVENDOR_UNKNOWN;
185
186 /*
187 * Register info handlers.
188 */
189 DBGFR3InfoRegisterInternal(pVM, "cpum", "Displays the all the cpu states.", &cpumR3InfoAll);
190 DBGFR3InfoRegisterInternal(pVM, "cpumguest", "Displays the guest cpu state.", &cpumR3InfoGuest);
191 DBGFR3InfoRegisterInternal(pVM, "cpumhyper", "Displays the hypervisor cpu state.", &cpumR3InfoHyper);
192 DBGFR3InfoRegisterInternal(pVM, "cpumhost", "Displays the host cpu state.", &cpumR3InfoHost);
193 DBGFR3InfoRegisterInternal(pVM, "cpuid", "Displays the guest cpuid leaves.", &cpumR3CpuIdInfo);
194
195 /*
196 * Initialize the Guest CPU state.
197 */
198 rc = cpumR3CpuIdInit(pVM);
199 if (VBOX_FAILURE(rc))
200 return rc;
201 CPUMR3Reset(pVM);
202 return VINF_SUCCESS;
203}
204
205
206/**
207 * Initializes the emulated CPU's cpuid information.
208 *
209 * @returns VBox status code.
210 * @param pVM The VM to operate on.
211 */
212static int cpumR3CpuIdInit(PVM pVM)
213{
214 PCPUM pCPUM = &pVM->cpum.s;
215 uint32_t i;
216
217 /*
218 * Get the host CPUIDs.
219 */
220 for (i = 0; i < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdStd); i++)
221 ASMCpuId_Idx_ECX(i, 0,
222 &pCPUM->aGuestCpuIdStd[i].eax, &pCPUM->aGuestCpuIdStd[i].ebx,
223 &pCPUM->aGuestCpuIdStd[i].ecx, &pCPUM->aGuestCpuIdStd[i].edx);
224 for (i = 0; i < RT_ELEMENTS(pCPUM->aGuestCpuIdExt); i++)
225 ASMCpuId(0x80000000 + i,
226 &pCPUM->aGuestCpuIdExt[i].eax, &pCPUM->aGuestCpuIdExt[i].ebx,
227 &pCPUM->aGuestCpuIdExt[i].ecx, &pCPUM->aGuestCpuIdExt[i].edx);
228 for (i = 0; i < RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur); i++)
229 ASMCpuId(0xc0000000 + i,
230 &pCPUM->aGuestCpuIdCentaur[i].eax, &pCPUM->aGuestCpuIdCentaur[i].ebx,
231 &pCPUM->aGuestCpuIdCentaur[i].ecx, &pCPUM->aGuestCpuIdCentaur[i].edx);
232
233
234 /*
235 * Only report features we can support.
236 */
237 pCPUM->aGuestCpuIdStd[1].edx &= X86_CPUID_FEATURE_EDX_FPU
238 | X86_CPUID_FEATURE_EDX_VME
239 | X86_CPUID_FEATURE_EDX_DE
240 | X86_CPUID_FEATURE_EDX_PSE
241 | X86_CPUID_FEATURE_EDX_TSC
242 | X86_CPUID_FEATURE_EDX_MSR
243 //| X86_CPUID_FEATURE_EDX_PAE - not implemented yet.
244 | X86_CPUID_FEATURE_EDX_MCE
245 | X86_CPUID_FEATURE_EDX_CX8
246 //| X86_CPUID_FEATURE_EDX_APIC - set by the APIC device if present.
247 /** @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 #1757) */
248 //| X86_CPUID_FEATURE_EDX_SEP
249 //| X86_CPUID_FEATURE_EDX_MTRR - no MTRRs.
250 | X86_CPUID_FEATURE_EDX_PGE
251 //| X86_CPUID_FEATURE_EDX_MCA - not virtualized.
252 | X86_CPUID_FEATURE_EDX_CMOV
253 //| X86_CPUID_FEATURE_EDX_PAT - not virtualized.
254 //| X86_CPUID_FEATURE_EDX_PSE36 - not virtualized.
255 //| X86_CPUID_FEATURE_EDX_PSN - no serial number.
256 | X86_CPUID_FEATURE_EDX_CLFSH
257 //| X86_CPUID_FEATURE_EDX_DS - no debug store.
258 //| X86_CPUID_FEATURE_EDX_ACPI - not virtualized yet.
259 | X86_CPUID_FEATURE_EDX_MMX
260 | X86_CPUID_FEATURE_EDX_FXSR
261 | X86_CPUID_FEATURE_EDX_SSE
262 | X86_CPUID_FEATURE_EDX_SSE2
263 //| X86_CPUID_FEATURE_EDX_SS - no self snoop.
264 //| X86_CPUID_FEATURE_EDX_HTT - no hyperthreading.
265 //| X86_CPUID_FEATURE_EDX_TM - no thermal monitor.
266 //| X86_CPUID_FEATURE_EDX_PBE - no pneding break enabled.
267 | 0;
268 pCPUM->aGuestCpuIdStd[1].ecx &= 0//X86_CPUID_FEATURE_ECX_SSE3 - not supported by the recompiler yet.
269 | X86_CPUID_FEATURE_ECX_MONITOR
270 //| X86_CPUID_FEATURE_ECX_CPLDS - no CPL qualified debug store.
271 //| X86_CPUID_FEATURE_ECX_VMX - not virtualized.
272 //| X86_CPUID_FEATURE_ECX_EST - no extended speed step.
273 //| X86_CPUID_FEATURE_ECX_TM2 - no thermal monitor 2.
274 //| X86_CPUID_FEATURE_ECX_CNTXID - no L1 context id (MSR++).
275 | 0;
276
277 /* ASSUMES that this is ALWAYS the AMD define feature set if present. */
278 pCPUM->aGuestCpuIdExt[1].edx &= X86_CPUID_AMD_FEATURE_EDX_FPU
279 | X86_CPUID_AMD_FEATURE_EDX_VME
280 | X86_CPUID_AMD_FEATURE_EDX_DE
281 | X86_CPUID_AMD_FEATURE_EDX_PSE
282 | X86_CPUID_AMD_FEATURE_EDX_TSC
283 | X86_CPUID_AMD_FEATURE_EDX_MSR //?? this means AMD MSRs..
284 //| X86_CPUID_AMD_FEATURE_EDX_PAE - not implemented yet.
285 //| X86_CPUID_AMD_FEATURE_EDX_MCE - not virtualized yet.
286 | X86_CPUID_AMD_FEATURE_EDX_CX8
287 //| X86_CPUID_AMD_FEATURE_EDX_APIC - set by the APIC device if present.
288 /** @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 #1757) */
289 //| X86_CPUID_AMD_FEATURE_EDX_SEP
290 //| X86_CPUID_AMD_FEATURE_EDX_MTRR - not virtualized.
291 | X86_CPUID_AMD_FEATURE_EDX_PGE
292 //| X86_CPUID_AMD_FEATURE_EDX_MCA - not virtualized.
293 | X86_CPUID_AMD_FEATURE_EDX_CMOV
294 | X86_CPUID_AMD_FEATURE_EDX_PAT
295 //| X86_CPUID_AMD_FEATURE_EDX_PSE36 - not virtualized.
296 //| X86_CPUID_AMD_FEATURE_EDX_NX - not virtualized, requires PAE.
297 | X86_CPUID_AMD_FEATURE_EDX_MMX
298 | X86_CPUID_AMD_FEATURE_EDX_FXSR
299 | X86_CPUID_AMD_FEATURE_EDX_FFXSR
300 //| X86_CPUID_AMD_FEATURE_EDX_LONG_MODE - not yet.
301 | X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX
302 | X86_CPUID_AMD_FEATURE_EDX_3DNOW
303 | 0;
304 pCPUM->aGuestCpuIdExt[1].ecx &= 0//X86_CPUID_AMD_FEATURE_ECX_SVM - not virtualized.
305 | 0;
306
307 /*
308 * Hide HTT, multicode, SMP, whatever.
309 * (APIC-ID := 0 and #LogCpus := 0)
310 */
311 pCPUM->aGuestCpuIdStd[1].ebx &= 0x0000ffff;
312
313 /*
314 * Determin the default.
315 *
316 * Intel returns values of the highest standard function, while AMD
317 * returns zeros. VIA on the other hand seems to returning nothing or
318 * perhaps some random garbage, we don't try duplicate this behavior.
319 */
320 ASMCpuId(pCPUM->aGuestCpuIdStd[0].eax + 10,
321 &pCPUM->GuestCpuIdDef.eax, &pCPUM->GuestCpuIdDef.ebx,
322 &pCPUM->GuestCpuIdDef.ecx, &pCPUM->GuestCpuIdDef.edx);
323
324 /*
325 * Limit it the number of entries and fill the remaining with the defaults.
326 *
327 * The limits are masking off stuff about power saving and similar, this
328 * is perhaps a bit crudely done as there is probably some relatively harmless
329 * info too in these leaves (like words about having a constant TSC).
330 */
331 if (pCPUM->aGuestCpuIdStd[0].eax > 2)
332 pCPUM->aGuestCpuIdStd[0].eax = 2;
333 for (i = pCPUM->aGuestCpuIdStd[0].eax + 1; i < RT_ELEMENTS(pCPUM->aGuestCpuIdStd); i++)
334 pCPUM->aGuestCpuIdStd[i] = pCPUM->GuestCpuIdDef;
335
336 if (pCPUM->aGuestCpuIdExt[0].eax > UINT32_C(0x80000004))
337 pCPUM->aGuestCpuIdExt[0].eax = UINT32_C(0x80000004);
338 for (i = pCPUM->aGuestCpuIdExt[0].eax >= UINT32_C(0x80000000)
339 ? pCPUM->aGuestCpuIdExt[0].eax - UINT32_C(0x80000000) + 1
340 : 0;
341 i < RT_ELEMENTS(pCPUM->aGuestCpuIdExt); i++)
342 pCPUM->aGuestCpuIdExt[i] = pCPUM->GuestCpuIdDef;
343
344 /*
345 * Workaround for missing cpuid(0) patches: If we miss to patch a cpuid(0).eax then
346 * Linux tries to determine the number of processors from (cpuid(4).eax >> 26) + 1.
347 * We don't support more than 1 processor.
348 */
349 pCPUM->aGuestCpuIdStd[4].eax = 0;
350
351 /*
352 * Centaur stuff (VIA).
353 *
354 * The important part here (we think) is to make sure the 0xc0000000
355 * function returns 0xc0000001. As for the features, we don't currently
356 * let on about any of those... 0xc0000002 seems to be some
357 * temperature/hz/++ stuff, include it as well (static).
358 */
359 if ( pCPUM->aGuestCpuIdCentaur[0].eax >= UINT32_C(0xc0000000)
360 && pCPUM->aGuestCpuIdCentaur[0].eax <= UINT32_C(0xc0000004))
361 {
362 pCPUM->aGuestCpuIdCentaur[0].eax = RT_MIN(pCPUM->aGuestCpuIdCentaur[0].eax, UINT32_C(0xc0000002));
363 pCPUM->aGuestCpuIdCentaur[1].edx = 0; /* all features hidden */
364 for (i = pCPUM->aGuestCpuIdCentaur[0].eax - UINT32_C(0xc0000000);
365 i < RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur);
366 i++)
367 pCPUM->aGuestCpuIdCentaur[i] = pCPUM->GuestCpuIdDef;
368 }
369 else
370 for (i = 0; i < RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur); i++)
371 pCPUM->aGuestCpuIdCentaur[i] = pCPUM->GuestCpuIdDef;
372
373
374 /*
375 * Load CPUID overrides from configuration.
376 */
377 PCPUMCPUID pCpuId = &pCPUM->aGuestCpuIdStd[0];
378 uint32_t cElements = ELEMENTS(pCPUM->aGuestCpuIdStd);
379 for (i=0;; )
380 {
381 while (cElements-- > 0)
382 {
383 PCFGMNODE pNode = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "CPUM/CPUID/%RX32", i);
384 if (pNode)
385 {
386 uint32_t u32;
387 int rc = CFGMR3QueryU32(pNode, "eax", &u32);
388 if (VBOX_SUCCESS(rc))
389 pCpuId->eax = u32;
390 else
391 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
392
393 rc = CFGMR3QueryU32(pNode, "ebx", &u32);
394 if (VBOX_SUCCESS(rc))
395 pCpuId->ebx = u32;
396 else
397 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
398
399 rc = CFGMR3QueryU32(pNode, "ecx", &u32);
400 if (VBOX_SUCCESS(rc))
401 pCpuId->ecx = u32;
402 else
403 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
404
405 rc = CFGMR3QueryU32(pNode, "edx", &u32);
406 if (VBOX_SUCCESS(rc))
407 pCpuId->edx = u32;
408 else
409 AssertReturn(rc == VERR_CFGM_VALUE_NOT_FOUND, rc);
410 }
411 pCpuId++;
412 i++;
413 }
414
415 /* next */
416 if ((i & UINT32_C(0xc0000000)) == 0)
417 {
418 pCpuId = &pCPUM->aGuestCpuIdExt[0];
419 cElements = RT_ELEMENTS(pCPUM->aGuestCpuIdExt);
420 i = UINT32_C(0x80000000);
421 }
422 else if ((i & UINT32_C(0xc0000000)) == UINT32_C(0x80000000))
423 {
424 pCpuId = &pCPUM->aGuestCpuIdCentaur[0];
425 cElements = RT_ELEMENTS(pCPUM->aGuestCpuIdCentaur);
426 i = UINT32_C(0xc0000000);
427 }
428 else
429 break;
430 }
431
432 /* Check if PAE was explicitely enabled by the user. */
433 bool fEnable = false;
434 int rc = CFGMR3QueryBool(CFGMR3GetRoot(pVM), "EnablePAE", &fEnable);
435 if (VBOX_SUCCESS(rc) && fEnable)
436 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_PAE);
437
438 /*
439 * Log the cpuid and we're good.
440 */
441 LogRel(("Logical host processors: %d, processor active mask: %08x\n",
442 RTSystemProcessorGetCount(), RTSystemProcessorGetActiveMask()));
443 LogRel(("************************* CPUID dump ************************\n"));
444 DBGFR3Info(pVM, "cpuid", "verbose", DBGFR3InfoLogRelHlp());
445 LogRel(("\n"));
446 DBGFR3InfoLog(pVM, "cpuid", "verbose"); /* macro */
447 LogRel(("******************** End of CPUID dump **********************\n"));
448 return VINF_SUCCESS;
449}
450
451
452
453
454/**
455 * Applies relocations to data and code managed by this
456 * component. This function will be called at init and
457 * whenever the VMM need to relocate it self inside the GC.
458 *
459 * The CPUM will update the addresses used by the switcher.
460 *
461 * @param pVM The VM.
462 */
463CPUMR3DECL(void) CPUMR3Relocate(PVM pVM)
464{
465 LogFlow(("CPUMR3Relocate\n"));
466 /*
467 * Switcher pointers.
468 */
469 pVM->cpum.s.pCPUMGC = VM_GUEST_ADDR(pVM, &pVM->cpum.s);
470 pVM->cpum.s.pHyperCoreGC = MMHyperCCToGC(pVM, pVM->cpum.s.pHyperCoreR3);
471 Assert(pVM->cpum.s.pHyperCoreGC != NIL_RTGCPTR);
472}
473
474
475/**
476 * Queries the pointer to the internal CPUMCTX structure
477 *
478 * @returns VBox status code.
479 * @param pVM Handle to the virtual machine.
480 * @param ppCtx Receives the CPUMCTX GC pointer when successful.
481 */
482CPUMR3DECL(int) CPUMR3QueryGuestCtxGCPtr(PVM pVM, RCPTRTYPE(PCPUMCTX) *ppCtx)
483{
484 LogFlow(("CPUMR3QueryGuestCtxGCPtr\n"));
485 /*
486 * Store the address. (Later we might check how's calling, thus the RC.)
487 */
488 *ppCtx = VM_GUEST_ADDR(pVM, &pVM->cpum.s.Guest);
489 return VINF_SUCCESS;
490}
491
492
493/**
494 * Terminates the CPUM.
495 *
496 * Termination means cleaning up and freeing all resources,
497 * the VM it self is at this point powered off or suspended.
498 *
499 * @returns VBox status code.
500 * @param pVM The VM to operate on.
501 */
502CPUMR3DECL(int) CPUMR3Term(PVM pVM)
503{
504 /** @todo */
505 return 0;
506}
507
508
509/**
510 * Resets the CPU.
511 *
512 * @returns VINF_SUCCESS.
513 * @param pVM The VM handle.
514 */
515CPUMR3DECL(void) CPUMR3Reset(PVM pVM)
516{
517 PCPUMCTX pCtx = &pVM->cpum.s.Guest;
518
519 /*
520 * Initialize everything to ZERO first.
521 */
522 uint32_t fUseFlags = pVM->cpum.s.fUseFlags & ~CPUM_USED_FPU_SINCE_REM;
523 memset(pCtx, 0, sizeof(*pCtx));
524 pVM->cpum.s.fUseFlags = fUseFlags;
525
526 pCtx->cr0 = X86_CR0_CD | X86_CR0_NW | X86_CR0_ET; //0x60000010
527 pCtx->eip = 0x0000fff0;
528 pCtx->edx = 0x00000600; /* P6 processor */
529 pCtx->eflags.Bits.u1Reserved0 = 1;
530
531 pCtx->cs = 0xf000;
532 pCtx->csHid.u32Base = 0xffff0000;
533 pCtx->csHid.u32Limit = 0x0000ffff;
534 pCtx->csHid.Attr.n.u1DescType = 1; /* code/data segment */
535 pCtx->csHid.Attr.n.u1Present = 1;
536 pCtx->csHid.Attr.n.u4Type = X86_SEL_TYPE_READ | X86_SEL_TYPE_CODE;
537
538 pCtx->dsHid.u32Limit = 0x0000ffff;
539 pCtx->dsHid.Attr.n.u1DescType = 1; /* code/data segment */
540 pCtx->dsHid.Attr.n.u1Present = 1;
541 pCtx->dsHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
542
543 pCtx->esHid.u32Limit = 0x0000ffff;
544 pCtx->esHid.Attr.n.u1DescType = 1; /* code/data segment */
545 pCtx->esHid.Attr.n.u1Present = 1;
546 pCtx->esHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
547
548 pCtx->fsHid.u32Limit = 0x0000ffff;
549 pCtx->fsHid.Attr.n.u1DescType = 1; /* code/data segment */
550 pCtx->fsHid.Attr.n.u1Present = 1;
551 pCtx->fsHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
552
553 pCtx->gsHid.u32Limit = 0x0000ffff;
554 pCtx->gsHid.Attr.n.u1DescType = 1; /* code/data segment */
555 pCtx->gsHid.Attr.n.u1Present = 1;
556 pCtx->gsHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
557
558 pCtx->ssHid.u32Limit = 0x0000ffff;
559 pCtx->ssHid.Attr.n.u1Present = 1;
560 pCtx->ssHid.Attr.n.u1DescType = 1; /* code/data segment */
561 pCtx->ssHid.Attr.n.u4Type = X86_SEL_TYPE_RW;
562
563 pCtx->idtr.cbIdt = 0xffff;
564 pCtx->gdtr.cbGdt = 0xffff;
565
566 pCtx->ldtrHid.u32Limit = 0xffff;
567 pCtx->ldtrHid.Attr.n.u1Present = 1;
568 pCtx->ldtrHid.Attr.n.u4Type = X86_SEL_TYPE_SYS_LDT;
569
570 pCtx->trHid.u32Limit = 0xffff;
571 pCtx->trHid.Attr.n.u1Present = 1;
572 pCtx->trHid.Attr.n.u4Type = X86_SEL_TYPE_SYS_286_TSS_BUSY;
573
574 pCtx->dr6 = 0xFFFF0FF0;
575 pCtx->dr7 = 0x400;
576
577 pCtx->fpu.FTW = 0xff; /* All tags are set, i.e. the regs are empty. */
578 pCtx->fpu.FCW = 0x37f;
579
580 /* Init PAT MSR */
581 pCtx->msrPAT = 0x0007040600070406ULL; /* @todo correct? */
582}
583
584
585
586/**
587 * Execute state save operation.
588 *
589 * @returns VBox status code.
590 * @param pVM VM Handle.
591 * @param pSSM SSM operation handle.
592 */
593static DECLCALLBACK(int) cpumR3Save(PVM pVM, PSSMHANDLE pSSM)
594{
595 /*
596 * Save.
597 */
598 SSMR3PutMem(pSSM, &pVM->cpum.s.Hyper, sizeof(pVM->cpum.s.Hyper));
599 SSMR3PutMem(pSSM, &pVM->cpum.s.Guest, sizeof(pVM->cpum.s.Guest));
600 SSMR3PutU32(pSSM, pVM->cpum.s.fUseFlags);
601 SSMR3PutU32(pSSM, pVM->cpum.s.fChanged);
602
603 SSMR3PutU32(pSSM, ELEMENTS(pVM->cpum.s.aGuestCpuIdStd));
604 SSMR3PutMem(pSSM, &pVM->cpum.s.aGuestCpuIdStd[0], sizeof(pVM->cpum.s.aGuestCpuIdStd));
605
606 SSMR3PutU32(pSSM, ELEMENTS(pVM->cpum.s.aGuestCpuIdExt));
607 SSMR3PutMem(pSSM, &pVM->cpum.s.aGuestCpuIdExt[0], sizeof(pVM->cpum.s.aGuestCpuIdExt));
608
609 SSMR3PutU32(pSSM, ELEMENTS(pVM->cpum.s.aGuestCpuIdCentaur));
610 SSMR3PutMem(pSSM, &pVM->cpum.s.aGuestCpuIdCentaur[0], sizeof(pVM->cpum.s.aGuestCpuIdCentaur));
611
612 SSMR3PutMem(pSSM, &pVM->cpum.s.GuestCpuIdDef, sizeof(pVM->cpum.s.GuestCpuIdDef));
613
614 /* Add the cpuid for checking that the cpu is unchanged. */
615 uint32_t au32CpuId[8] = {0};
616 ASMCpuId(0, &au32CpuId[0], &au32CpuId[1], &au32CpuId[2], &au32CpuId[3]);
617 ASMCpuId(1, &au32CpuId[4], &au32CpuId[5], &au32CpuId[6], &au32CpuId[7]);
618 return SSMR3PutMem(pSSM, &au32CpuId[0], sizeof(au32CpuId));
619}
620
621
622/**
623 * Execute state load operation.
624 *
625 * @returns VBox status code.
626 * @param pVM VM Handle.
627 * @param pSSM SSM operation handle.
628 * @param u32Version Data layout version.
629 */
630static DECLCALLBACK(int) cpumR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version)
631{
632 /*
633 * Validate version.
634 */
635 if (u32Version != CPUM_SAVED_STATE_VERSION)
636 {
637 Log(("cpuR3Load: Invalid version u32Version=%d!\n", u32Version));
638 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
639 }
640
641 /*
642 * Restore.
643 */
644 uint32_t uCR3 = pVM->cpum.s.Hyper.cr3;
645 uint32_t uESP = pVM->cpum.s.Hyper.esp; /* see VMMR3Relocate(). */
646 SSMR3GetMem(pSSM, &pVM->cpum.s.Hyper, sizeof(pVM->cpum.s.Hyper));
647 pVM->cpum.s.Hyper.cr3 = uCR3;
648 pVM->cpum.s.Hyper.esp = uESP;
649 SSMR3GetMem(pSSM, &pVM->cpum.s.Guest, sizeof(pVM->cpum.s.Guest));
650 SSMR3GetU32(pSSM, &pVM->cpum.s.fUseFlags);
651 SSMR3GetU32(pSSM, &pVM->cpum.s.fChanged);
652
653 uint32_t cElements;
654 int rc = SSMR3GetU32(pSSM, &cElements); AssertRCReturn(rc, rc);
655 if (cElements != ELEMENTS(pVM->cpum.s.aGuestCpuIdStd))
656 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
657 SSMR3GetMem(pSSM, &pVM->cpum.s.aGuestCpuIdStd[0], sizeof(pVM->cpum.s.aGuestCpuIdStd));
658
659 rc = SSMR3GetU32(pSSM, &cElements); AssertRCReturn(rc, rc);
660 if (cElements != ELEMENTS(pVM->cpum.s.aGuestCpuIdExt))
661 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
662 SSMR3GetMem(pSSM, &pVM->cpum.s.aGuestCpuIdExt[0], sizeof(pVM->cpum.s.aGuestCpuIdExt));
663
664 rc = SSMR3GetU32(pSSM, &cElements); AssertRCReturn(rc, rc);
665 if (cElements != RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdCentaur))
666 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
667 SSMR3GetMem(pSSM, &pVM->cpum.s.aGuestCpuIdCentaur[0], sizeof(pVM->cpum.s.aGuestCpuIdCentaur));
668
669 SSMR3GetMem(pSSM, &pVM->cpum.s.GuestCpuIdDef, sizeof(pVM->cpum.s.GuestCpuIdDef));
670
671 /*
672 * Check that the basic cpuid id information is unchanged.
673 */
674 uint32_t au32CpuId[8] = {0};
675 ASMCpuId(0, &au32CpuId[0], &au32CpuId[1], &au32CpuId[2], &au32CpuId[3]);
676 ASMCpuId(1, &au32CpuId[4], &au32CpuId[5], &au32CpuId[6], &au32CpuId[7]);
677 uint32_t au32CpuIdSaved[8];
678 rc = SSMR3GetMem(pSSM, &au32CpuIdSaved[0], sizeof(au32CpuIdSaved));
679 if (VBOX_SUCCESS(rc))
680 {
681 /* Ignore APIC ID (AMD specs). */
682 au32CpuId[5] &= ~0xff000000;
683 au32CpuIdSaved[5] &= ~0xff000000;
684 /* Ignore the number of Logical CPUs (AMD specs). */
685 au32CpuId[5] &= ~0x00ff0000;
686 au32CpuIdSaved[5] &= ~0x00ff0000;
687
688 /* do the compare */
689 if (memcmp(au32CpuIdSaved, au32CpuId, sizeof(au32CpuIdSaved)))
690 {
691 if (SSMR3HandleGetAfter(pSSM) == SSMAFTER_DEBUG_IT)
692 LogRel(("cpumR3Load: CpuId mismatch! (ignored due to SSMAFTER_DEBUG_IT)\n"
693 "Saved=%.*Vhxs\n"
694 "Real =%.*Vhxs\n",
695 sizeof(au32CpuIdSaved), au32CpuIdSaved,
696 sizeof(au32CpuId), au32CpuId));
697 else
698 {
699 LogRel(("cpumR3Load: CpuId mismatch!\n"
700 "Saved=%.*Vhxs\n"
701 "Real =%.*Vhxs\n",
702 sizeof(au32CpuIdSaved), au32CpuIdSaved,
703 sizeof(au32CpuId), au32CpuId));
704 rc = VERR_SSM_LOAD_CPUID_MISMATCH;
705 }
706 }
707 }
708
709 return rc;
710}
711
712
713/**
714 * Formats the EFLAGS value into mnemonics.
715 *
716 * @param pszEFlags Where to write the mnemonics. (Assumes sufficient buffer space.)
717 * @param efl The EFLAGS value.
718 */
719static void cpumR3InfoFormatFlags(char *pszEFlags, uint32_t efl)
720{
721 /*
722 * Format the flags.
723 */
724 static struct
725 {
726 const char *pszSet; const char *pszClear; uint32_t fFlag;
727 } s_aFlags[] =
728 {
729 { "vip",NULL, X86_EFL_VIP },
730 { "vif",NULL, X86_EFL_VIF },
731 { "ac", NULL, X86_EFL_AC },
732 { "vm", NULL, X86_EFL_VM },
733 { "rf", NULL, X86_EFL_RF },
734 { "nt", NULL, X86_EFL_NT },
735 { "ov", "nv", X86_EFL_OF },
736 { "dn", "up", X86_EFL_DF },
737 { "ei", "di", X86_EFL_IF },
738 { "tf", NULL, X86_EFL_TF },
739 { "nt", "pl", X86_EFL_SF },
740 { "nz", "zr", X86_EFL_ZF },
741 { "ac", "na", X86_EFL_AF },
742 { "po", "pe", X86_EFL_PF },
743 { "cy", "nc", X86_EFL_CF },
744 };
745 char *psz = pszEFlags;
746 for (unsigned i = 0; i < ELEMENTS(s_aFlags); i++)
747 {
748 const char *pszAdd = s_aFlags[i].fFlag & efl ? s_aFlags[i].pszSet : s_aFlags[i].pszClear;
749 if (pszAdd)
750 {
751 strcpy(psz, pszAdd);
752 psz += strlen(pszAdd);
753 *psz++ = ' ';
754 }
755 }
756 psz[-1] = '\0';
757}
758
759
760/**
761 * Formats a full register dump.
762 *
763 * @param pCtx The context to format.
764 * @param pCtxCore The context core to format.
765 * @param pHlp Output functions.
766 * @param enmType The dump type.
767 * @param pszPrefix Register name prefix.
768 */
769static void cpumR3InfoOne(PCPUMCTX pCtx, PCCPUMCTXCORE pCtxCore, PCDBGFINFOHLP pHlp, CPUMDUMPTYPE enmType, const char *pszPrefix)
770{
771 /*
772 * Format the EFLAGS.
773 */
774 uint32_t efl = pCtxCore->eflags.u32;
775 char szEFlags[80];
776 cpumR3InfoFormatFlags(&szEFlags[0], efl);
777
778 /*
779 * Format the registers.
780 */
781 switch (enmType)
782 {
783 case CPUMDUMPTYPE_TERSE:
784 pHlp->pfnPrintf(pHlp,
785 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
786 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
787 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %seflags=%08x\n",
788 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
789 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
790 pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
791 pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, efl);
792 break;
793
794 case CPUMDUMPTYPE_DEFAULT:
795 pHlp->pfnPrintf(pHlp,
796 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
797 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
798 "%scs=%04x %sss=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %str=%04x %seflags=%08x\n"
799 "%scr0=%08RX64 %scr2=%08RX64 %scr3=%08RX64 %scr4=%08RX64 %sgdtr=%08x:%04x %sldtr=%04x\n"
800 ,
801 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
802 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
803 pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
804 pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, (RTSEL)pCtx->tr, pszPrefix, efl,
805 pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
806 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, (RTSEL)pCtx->ldtr);
807 break;
808
809 case CPUMDUMPTYPE_VERBOSE:
810 pHlp->pfnPrintf(pHlp,
811 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
812 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
813 "%scs={%04x base=%08x limit=%08x flags=%08x} %sdr0=%08RX64 %sdr1=%08RX64\n"
814 "%sds={%04x base=%08x limit=%08x flags=%08x} %sdr2=%08RX64 %sdr3=%08RX64\n"
815 "%ses={%04x base=%08x limit=%08x flags=%08x} %sdr4=%08RX64 %sdr5=%08RX64\n"
816 "%sfs={%04x base=%08x limit=%08x flags=%08x} %sdr6=%08RX64 %sdr7=%08RX64\n"
817 "%sgs={%04x base=%08x limit=%08x flags=%08x} %scr0=%08RX64 %scr2=%08RX64\n"
818 "%sss={%04x base=%08x limit=%08x flags=%08x} %scr3=%08RX64 %scr4=%08RX64\n"
819 "%sgdtr=%08x:%04x %sidtr=%08x:%04x %seflags=%08x\n"
820 "%sldtr={%04x base=%08x limit=%08x flags=%08x}\n"
821 "%str ={%04x base=%08x limit=%08x flags=%08x}\n"
822 "%sSysEnter={cs=%04llx eip=%08llx esp=%08llx}\n"
823 ,
824 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
825 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
826 pszPrefix, (RTSEL)pCtxCore->cs, pCtx->csHid.u32Base, pCtx->csHid.u32Limit, pCtx->csHid.Attr.u, pszPrefix, pCtx->dr0, pszPrefix, pCtx->dr1,
827 pszPrefix, (RTSEL)pCtxCore->ds, pCtx->dsHid.u32Base, pCtx->dsHid.u32Limit, pCtx->dsHid.Attr.u, pszPrefix, pCtx->dr2, pszPrefix, pCtx->dr3,
828 pszPrefix, (RTSEL)pCtxCore->es, pCtx->esHid.u32Base, pCtx->esHid.u32Limit, pCtx->esHid.Attr.u, pszPrefix, pCtx->dr4, pszPrefix, pCtx->dr5,
829 pszPrefix, (RTSEL)pCtxCore->fs, pCtx->fsHid.u32Base, pCtx->fsHid.u32Limit, pCtx->fsHid.Attr.u, pszPrefix, pCtx->dr6, pszPrefix, pCtx->dr7,
830 pszPrefix, (RTSEL)pCtxCore->gs, pCtx->gsHid.u32Base, pCtx->gsHid.u32Limit, pCtx->gsHid.Attr.u, pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2,
831 pszPrefix, (RTSEL)pCtxCore->ss, pCtx->ssHid.u32Base, pCtx->ssHid.u32Limit, pCtx->ssHid.Attr.u, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
832 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, pszPrefix, efl,
833 pszPrefix, (RTSEL)pCtx->ldtr, pCtx->ldtrHid.u32Base, pCtx->ldtrHid.u32Limit, pCtx->ldtrHid.Attr.u,
834 pszPrefix, (RTSEL)pCtx->tr, pCtx->trHid.u32Base, pCtx->trHid.u32Limit, pCtx->trHid.Attr.u,
835 pszPrefix, pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp);
836
837 pHlp->pfnPrintf(pHlp,
838 "FPU:\n"
839 "%sFCW=%04x %sFSW=%04x %sFTW=%02x\n"
840 "%sres1=%02x %sFOP=%04x %sFPUIP=%08x %sCS=%04x %sRsvrd1=%04x\n"
841 "%sFPUDP=%04x %sDS=%04x %sRsvrd2=%04x %sMXCSR=%08x %sMXCSR_MASK=%08x\n"
842 ,
843 pszPrefix, pCtx->fpu.FCW, pszPrefix, pCtx->fpu.FSW, pszPrefix, pCtx->fpu.FTW,
844 pszPrefix, pCtx->fpu.huh1, pszPrefix, pCtx->fpu.FOP, pszPrefix, pCtx->fpu.FPUIP, pszPrefix, pCtx->fpu.CS, pszPrefix, pCtx->fpu.Rsvrd1,
845 pszPrefix, pCtx->fpu.FPUDP, pszPrefix, pCtx->fpu.DS, pszPrefix, pCtx->fpu.Rsrvd2,
846 pszPrefix, pCtx->fpu.MXCSR, pszPrefix, pCtx->fpu.MXCSR_MASK);
847
848
849 break;
850 }
851}
852
853
854/**
855 * Display all cpu states and any other cpum info.
856 *
857 * @param pVM VM Handle.
858 * @param pHlp The info helper functions.
859 * @param pszArgs Arguments, ignored.
860 */
861static DECLCALLBACK(void) cpumR3InfoAll(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
862{
863 cpumR3InfoGuest(pVM, pHlp, pszArgs);
864 cpumR3InfoHyper(pVM, pHlp, pszArgs);
865 cpumR3InfoHost(pVM, pHlp, pszArgs);
866}
867
868
869/**
870 * Parses the info argument.
871 *
872 * The argument starts with 'verbose', 'terse' or 'default' and then
873 * continues with the comment string.
874 *
875 * @param pszArgs The pointer to the argument string.
876 * @param penmType Where to store the dump type request.
877 * @param ppszComment Where to store the pointer to the comment string.
878 */
879static void cpumR3InfoParseArg(const char *pszArgs, CPUMDUMPTYPE *penmType, const char **ppszComment)
880{
881 if (!pszArgs)
882 {
883 *penmType = CPUMDUMPTYPE_DEFAULT;
884 *ppszComment = "";
885 }
886 else
887 {
888 if (!strncmp(pszArgs, "verbose", sizeof("verbose") - 1))
889 {
890 pszArgs += 5;
891 *penmType = CPUMDUMPTYPE_VERBOSE;
892 }
893 else if (!strncmp(pszArgs, "terse", sizeof("terse") - 1))
894 {
895 pszArgs += 5;
896 *penmType = CPUMDUMPTYPE_TERSE;
897 }
898 else if (!strncmp(pszArgs, "default", sizeof("default") - 1))
899 {
900 pszArgs += 7;
901 *penmType = CPUMDUMPTYPE_DEFAULT;
902 }
903 else
904 *penmType = CPUMDUMPTYPE_DEFAULT;
905 *ppszComment = RTStrStripL(pszArgs);
906 }
907}
908
909
910/**
911 * Display the guest cpu state.
912 *
913 * @param pVM VM Handle.
914 * @param pHlp The info helper functions.
915 * @param pszArgs Arguments, ignored.
916 */
917static DECLCALLBACK(void) cpumR3InfoGuest(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
918{
919 CPUMDUMPTYPE enmType;
920 const char *pszComment;
921 cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
922 pHlp->pfnPrintf(pHlp, "Guest CPUM state: %s\n", pszComment);
923 cpumR3InfoOne(&pVM->cpum.s.Guest, CPUMCTX2CORE(&pVM->cpum.s.Guest), pHlp, enmType, "");
924}
925
926
927/**
928 * Display the hypervisor cpu state.
929 *
930 * @param pVM VM Handle.
931 * @param pHlp The info helper functions.
932 * @param pszArgs Arguments, ignored.
933 */
934static DECLCALLBACK(void) cpumR3InfoHyper(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
935{
936 CPUMDUMPTYPE enmType;
937 const char *pszComment;
938 cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
939 pHlp->pfnPrintf(pHlp, "Hypervisor CPUM state: %s\n", pszComment);
940 cpumR3InfoOne(&pVM->cpum.s.Hyper, pVM->cpum.s.pHyperCoreR3, pHlp, enmType, ".");
941 pHlp->pfnPrintf(pHlp, "CR4OrMask=%#x CR4AndMask=%#x\n", pVM->cpum.s.CR4.OrMask, pVM->cpum.s.CR4.AndMask);
942}
943
944
945/**
946 * Display the host cpu state.
947 *
948 * @param pVM VM Handle.
949 * @param pHlp The info helper functions.
950 * @param pszArgs Arguments, ignored.
951 */
952static DECLCALLBACK(void) cpumR3InfoHost(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
953{
954 CPUMDUMPTYPE enmType;
955 const char *pszComment;
956 cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
957 pHlp->pfnPrintf(pHlp, "Host CPUM state: %s\n", pszComment);
958
959 /*
960 * Format the EFLAGS.
961 */
962 PCPUMHOSTCTX pCtx = &pVM->cpum.s.Host;
963#if HC_ARCH_BITS == 32
964 uint32_t efl = pCtx->eflags.u32;
965#else
966 uint64_t efl = pCtx->rflags;
967#endif
968 char szEFlags[80];
969 cpumR3InfoFormatFlags(&szEFlags[0], efl);
970
971 /*
972 * Format the registers.
973 */
974#if HC_ARCH_BITS == 32
975# ifdef VBOX_WITH_HYBIRD_32BIT_KERNEL
976 if (!(pCtx->efer & MSR_K6_EFER_LMA))
977# endif
978 {
979 pHlp->pfnPrintf(pHlp,
980 "eax=xxxxxxxx ebx=%08x ecx=xxxxxxxx edx=xxxxxxxx esi=%08x edi=%08x\n"
981 "eip=xxxxxxxx esp=%08x ebp=%08x iopl=%d %31s\n"
982 "cs=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n"
983 "cr0=%08RX64 cr2=xxxxxxxx cr3=%08RX64 cr4=%08RX64 gdtr=%08x:%04x ldtr=%04x\n"
984 "dr0=%08RX64 dr1=%08RX64x dr2=%08RX64 dr3=%08RX64x dr6=%08RX64 dr7=%08RX64\n"
985 "SysEnter={cs=%04x eip=%08x esp=%08x}\n"
986 ,
987 /*pCtx->eax,*/ pCtx->ebx, /*pCtx->ecx, pCtx->edx,*/ pCtx->esi, pCtx->edi,
988 /*pCtx->eip,*/ pCtx->esp, pCtx->ebp, X86_EFL_GET_IOPL(efl), szEFlags,
989 (RTSEL)pCtx->cs, (RTSEL)pCtx->ds, (RTSEL)pCtx->es, (RTSEL)pCtx->fs, (RTSEL)pCtx->gs, efl,
990 pCtx->cr0, /*pCtx->cr2,*/ pCtx->cr3, pCtx->cr4,
991 pCtx->dr0, pCtx->dr1, pCtx->dr2, pCtx->dr3, pCtx->dr6, pCtx->dr7,
992 (uint32_t)pCtx->gdtr.uAddr, pCtx->gdtr.cb, (RTSEL)pCtx->ldtr,
993 pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp);
994 }
995# ifdef VBOX_WITH_HYBIRD_32BIT_KERNEL
996 else
997# endif
998#endif
999#if HC_ARCH_BITS == 64 || defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
1000 {
1001 pHlp->pfnPrintf(pHlp,
1002 "rax=xxxxxxxxxxxxxxxx rbx=%016RX64 rcx=xxxxxxxxxxxxxxxx\n"
1003 "rdx=xxxxxxxxxxxxxxxx rsi=%016RX64 rdi=%016RX64\n"
1004 "rip=xxxxxxxxxxxxxxxx rsp=%016RX64 rbp=%016RX64\n"
1005 " r8=xxxxxxxxxxxxxxxx r9=xxxxxxxxxxxxxxxx r10=%016RX64\n"
1006 "r11=%016RX64 r12=%016RX64 r13=%016RX64\n"
1007 "r14=%016RX64 r15=%016RX64\n"
1008 "iopl=%d %31s\n"
1009 "cs=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08RX64\n"
1010 "cr0=%016RX64 cr2=xxxxxxxxxxxxxxxx cr3=%016RX64\n"
1011 "cr4=%016RX64 cr8=%016RX64 ldtr=%04x tr=%04x\n"
1012 "dr0=%016RX64 dr1=%016RX64 dr2=%016RX64\n"
1013 "dr3=%016RX64 dr6=%016RX64 dr7=%016RX64\n"
1014 "gdtr=%016RX64:%04x idtr=%016RX64:%04x\n"
1015 "SysEnter={cs=%04x eip=%08x esp=%08x}\n"
1016 "FSbase=%016RX64 GSbase=%016RX64 efer=%08RX64\n"
1017 ,
1018 /*pCtx->rax,*/ pCtx->rbx, /*pCtx->rcx,
1019 pCtx->rdx,*/ pCtx->rsi, pCtx->rdi,
1020 /*pCtx->rip,*/ pCtx->rsp, pCtx->rbp,
1021 /*pCtx->r8, pCtx->r9,*/ pCtx->r10,
1022 pCtx->r11, pCtx->r12, pCtx->r13,
1023 pCtx->r14, pCtx->r15,
1024 X86_EFL_GET_IOPL(efl), szEFlags,
1025 (RTSEL)pCtx->cs, (RTSEL)pCtx->ds, (RTSEL)pCtx->es, (RTSEL)pCtx->fs, (RTSEL)pCtx->gs, efl,
1026 pCtx->cr0, /*pCtx->cr2,*/ pCtx->cr3,
1027 pCtx->cr4, pCtx->cr8, pCtx->ldtr, pCtx->tr,
1028 pCtx->dr0, pCtx->dr1, pCtx->dr2,
1029 pCtx->dr3, pCtx->dr6, pCtx->dr7,
1030 pCtx->gdtr.uAddr, pCtx->gdtr.cb, pCtx->idtr.uAddr, pCtx->idtr.cb,
1031 pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp,
1032 pCtx->FSbase, pCtx->GSbase, pCtx->efer);
1033 }
1034#endif
1035}
1036
1037/**
1038 * Get L1 cache / TLS associativity.
1039 */
1040static const char *getCacheAss(unsigned u, char *pszBuf)
1041{
1042 if (u == 0)
1043 return "res0 ";
1044 if (u == 1)
1045 return "direct";
1046 if (u >= 256)
1047 return "???";
1048
1049 RTStrPrintf(pszBuf, 16, "%d way", u);
1050 return pszBuf;
1051}
1052
1053
1054/**
1055 * Get L2 cache soociativity.
1056 */
1057const char *getL2CacheAss(unsigned u)
1058{
1059 switch (u)
1060 {
1061 case 0: return "off ";
1062 case 1: return "direct";
1063 case 2: return "2 way ";
1064 case 3: return "res3 ";
1065 case 4: return "4 way ";
1066 case 5: return "res5 ";
1067 case 6: return "8 way "; case 7: return "res7 ";
1068 case 8: return "16 way";
1069 case 9: return "res9 ";
1070 case 10: return "res10 ";
1071 case 11: return "res11 ";
1072 case 12: return "res12 ";
1073 case 13: return "res13 ";
1074 case 14: return "res14 ";
1075 case 15: return "fully ";
1076 default:
1077 return "????";
1078 }
1079}
1080
1081
1082/**
1083 * Display the guest CpuId leaves.
1084 *
1085 * @param pVM VM Handle.
1086 * @param pHlp The info helper functions.
1087 * @param pszArgs "terse", "default" or "verbose".
1088 */
1089static DECLCALLBACK(void) cpumR3CpuIdInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
1090{
1091 /*
1092 * Parse the argument.
1093 */
1094 unsigned iVerbosity = 1;
1095 if (pszArgs)
1096 {
1097 pszArgs = RTStrStripL(pszArgs);
1098 if (!strcmp(pszArgs, "terse"))
1099 iVerbosity--;
1100 else if (!strcmp(pszArgs, "verbose"))
1101 iVerbosity++;
1102 }
1103
1104 /*
1105 * Start cracking.
1106 */
1107 CPUMCPUID Host;
1108 CPUMCPUID Guest;
1109 unsigned cStdMax = pVM->cpum.s.aGuestCpuIdStd[0].eax;
1110
1111 pHlp->pfnPrintf(pHlp,
1112 " RAW Standard CPUIDs\n"
1113 " Function eax ebx ecx edx\n");
1114 for (unsigned i = 0; i < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdStd); i++)
1115 {
1116 Guest = pVM->cpum.s.aGuestCpuIdStd[i];
1117 ASMCpuId_Idx_ECX(i, 0, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
1118
1119 pHlp->pfnPrintf(pHlp,
1120 "Gst: %08x %08x %08x %08x %08x%s\n"
1121 "Hst: %08x %08x %08x %08x\n",
1122 i, Guest.eax, Guest.ebx, Guest.ecx, Guest.edx,
1123 i <= cStdMax ? "" : "*",
1124 Host.eax, Host.ebx, Host.ecx, Host.edx);
1125 }
1126
1127 /*
1128 * If verbose, decode it.
1129 */
1130 if (iVerbosity)
1131 {
1132 Guest = pVM->cpum.s.aGuestCpuIdStd[0];
1133 pHlp->pfnPrintf(pHlp,
1134 "Name: %.04s%.04s%.04s\n"
1135 "Supports: 0-%x\n",
1136 &Guest.ebx, &Guest.edx, &Guest.ecx, Guest.eax);
1137 }
1138
1139 /*
1140 * Get Features.
1141 */
1142 bool const fIntel = ASMIsIntelCpuEx(pVM->cpum.s.aGuestCpuIdStd[0].ebx,
1143 pVM->cpum.s.aGuestCpuIdStd[0].ecx,
1144 pVM->cpum.s.aGuestCpuIdStd[0].edx);
1145 if (cStdMax >= 1 && iVerbosity)
1146 {
1147 Guest = pVM->cpum.s.aGuestCpuIdStd[1];
1148 uint32_t uEAX = Guest.eax;
1149
1150 pHlp->pfnPrintf(pHlp,
1151 "Family: %d \tExtended: %d \tEffectiv: %d\n"
1152 "Model: %d \tExtended: %d \tEffectiv: %d\n"
1153 "Stepping: %d\n"
1154 "APIC ID: %#04x\n"
1155 "Logical CPUs: %d\n"
1156 "CLFLUSH Size: %d\n"
1157 "Brand ID: %#04x\n",
1158 (uEAX >> 8) & 0xf, (uEAX >> 20) & 0x7f, ASMGetCpuFamily(uEAX),
1159 (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX, fIntel),
1160 ASMGetCpuStepping(uEAX),
1161 (Guest.ebx >> 24) & 0xff,
1162 (Guest.ebx >> 16) & 0xff,
1163 (Guest.ebx >> 8) & 0xff,
1164 (Guest.ebx >> 0) & 0xff);
1165 if (iVerbosity == 1)
1166 {
1167 uint32_t uEDX = Guest.edx;
1168 pHlp->pfnPrintf(pHlp, "Features EDX: ");
1169 if (uEDX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " FPU");
1170 if (uEDX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " VME");
1171 if (uEDX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " DE");
1172 if (uEDX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " PSE");
1173 if (uEDX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " TSC");
1174 if (uEDX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " MSR");
1175 if (uEDX & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " PAE");
1176 if (uEDX & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " MCE");
1177 if (uEDX & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " CX8");
1178 if (uEDX & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " APIC");
1179 if (uEDX & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " 10");
1180 if (uEDX & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " SEP");
1181 if (uEDX & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " MTRR");
1182 if (uEDX & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " PGE");
1183 if (uEDX & RT_BIT(14)) pHlp->pfnPrintf(pHlp, " MCA");
1184 if (uEDX & RT_BIT(15)) pHlp->pfnPrintf(pHlp, " CMOV");
1185 if (uEDX & RT_BIT(16)) pHlp->pfnPrintf(pHlp, " PAT");
1186 if (uEDX & RT_BIT(17)) pHlp->pfnPrintf(pHlp, " PSE36");
1187 if (uEDX & RT_BIT(18)) pHlp->pfnPrintf(pHlp, " PSN");
1188 if (uEDX & RT_BIT(19)) pHlp->pfnPrintf(pHlp, " CLFSH");
1189 if (uEDX & RT_BIT(20)) pHlp->pfnPrintf(pHlp, " 20");
1190 if (uEDX & RT_BIT(21)) pHlp->pfnPrintf(pHlp, " DS");
1191 if (uEDX & RT_BIT(22)) pHlp->pfnPrintf(pHlp, " ACPI");
1192 if (uEDX & RT_BIT(23)) pHlp->pfnPrintf(pHlp, " MMX");
1193 if (uEDX & RT_BIT(24)) pHlp->pfnPrintf(pHlp, " FXSR");
1194 if (uEDX & RT_BIT(25)) pHlp->pfnPrintf(pHlp, " SSE");
1195 if (uEDX & RT_BIT(26)) pHlp->pfnPrintf(pHlp, " SSE2");
1196 if (uEDX & RT_BIT(27)) pHlp->pfnPrintf(pHlp, " SS");
1197 if (uEDX & RT_BIT(28)) pHlp->pfnPrintf(pHlp, " HTT");
1198 if (uEDX & RT_BIT(29)) pHlp->pfnPrintf(pHlp, " TM");
1199 if (uEDX & RT_BIT(30)) pHlp->pfnPrintf(pHlp, " 30");
1200 if (uEDX & RT_BIT(31)) pHlp->pfnPrintf(pHlp, " PBE");
1201 pHlp->pfnPrintf(pHlp, "\n");
1202
1203 uint32_t uECX = Guest.ecx;
1204 pHlp->pfnPrintf(pHlp, "Features ECX: ");
1205 if (uECX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " SSE3");
1206 if (uECX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " 1");
1207 if (uECX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " 2");
1208 if (uECX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " MONITOR");
1209 if (uECX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " DS-CPL");
1210 if (uECX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " VMX");
1211 if (uECX & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " 6");
1212 if (uECX & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " EST");
1213 if (uECX & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " TM2");
1214 if (uECX & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " 9");
1215 if (uECX & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " CNXT-ID");
1216 if (uECX & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " 11");
1217 if (uECX & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " 12");
1218 if (uECX & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " CX16");
1219 for (unsigned iBit = 14; iBit < 32; iBit++)
1220 if (uECX & RT_BIT(iBit))
1221 pHlp->pfnPrintf(pHlp, " %d", iBit);
1222 pHlp->pfnPrintf(pHlp, "\n");
1223 }
1224 else
1225 {
1226 ASMCpuId(1, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
1227
1228 X86CPUIDFEATEDX EdxHost = *(PX86CPUIDFEATEDX)&Host.edx;
1229 X86CPUIDFEATECX EcxHost = *(PX86CPUIDFEATECX)&Host.ecx;
1230 X86CPUIDFEATEDX EdxGuest = *(PX86CPUIDFEATEDX)&Guest.edx;
1231 X86CPUIDFEATECX EcxGuest = *(PX86CPUIDFEATECX)&Guest.ecx;
1232
1233 pHlp->pfnPrintf(pHlp, "Mnemonic - Description = guest (host)\n");
1234 pHlp->pfnPrintf(pHlp, "FPU - x87 FPU on Chip = %d (%d)\n", EdxGuest.u1FPU, EdxHost.u1FPU);
1235 pHlp->pfnPrintf(pHlp, "VME - Virtual 8086 Mode Enhancements = %d (%d)\n", EdxGuest.u1VME, EdxHost.u1VME);
1236 pHlp->pfnPrintf(pHlp, "DE - Debugging extensions = %d (%d)\n", EdxGuest.u1DE, EdxHost.u1DE);
1237 pHlp->pfnPrintf(pHlp, "PSE - Page Size Extension = %d (%d)\n", EdxGuest.u1PSE, EdxHost.u1PSE);
1238 pHlp->pfnPrintf(pHlp, "TSC - Time Stamp Counter = %d (%d)\n", EdxGuest.u1TSC, EdxHost.u1TSC);
1239 pHlp->pfnPrintf(pHlp, "MSR - Model Specific Registers = %d (%d)\n", EdxGuest.u1MSR, EdxHost.u1MSR);
1240 pHlp->pfnPrintf(pHlp, "PAE - Physical Address Extension = %d (%d)\n", EdxGuest.u1PAE, EdxHost.u1PAE);
1241 pHlp->pfnPrintf(pHlp, "MCE - Machine Check Exception = %d (%d)\n", EdxGuest.u1MCE, EdxHost.u1MCE);
1242 pHlp->pfnPrintf(pHlp, "CX8 - CMPXCHG8B instruction = %d (%d)\n", EdxGuest.u1CX8, EdxHost.u1CX8);
1243 pHlp->pfnPrintf(pHlp, "APIC - APIC On-Chip = %d (%d)\n", EdxGuest.u1APIC, EdxHost.u1APIC);
1244 pHlp->pfnPrintf(pHlp, "Reserved = %d (%d)\n", EdxGuest.u1Reserved1, EdxHost.u1Reserved1);
1245 pHlp->pfnPrintf(pHlp, "SEP - SYSENTER and SYSEXIT = %d (%d)\n", EdxGuest.u1SEP, EdxHost.u1SEP);
1246 pHlp->pfnPrintf(pHlp, "MTRR - Memory Type Range Registers = %d (%d)\n", EdxGuest.u1MTRR, EdxHost.u1MTRR);
1247 pHlp->pfnPrintf(pHlp, "PGE - PTE Global Bit = %d (%d)\n", EdxGuest.u1PGE, EdxHost.u1PGE);
1248 pHlp->pfnPrintf(pHlp, "MCA - Machine Check Architecture = %d (%d)\n", EdxGuest.u1MCA, EdxHost.u1MCA);
1249 pHlp->pfnPrintf(pHlp, "CMOV - Conditional Move Instructions = %d (%d)\n", EdxGuest.u1CMOV, EdxHost.u1CMOV);
1250 pHlp->pfnPrintf(pHlp, "PAT - Page Attribute Table = %d (%d)\n", EdxGuest.u1PAT, EdxHost.u1PAT);
1251 pHlp->pfnPrintf(pHlp, "PSE-36 - 36-bit Page Size Extention = %d (%d)\n", EdxGuest.u1PSE36, EdxHost.u1PSE36);
1252 pHlp->pfnPrintf(pHlp, "PSN - Processor Serial Number = %d (%d)\n", EdxGuest.u1PSN, EdxHost.u1PSN);
1253 pHlp->pfnPrintf(pHlp, "CLFSH - CLFLUSH Instruction. = %d (%d)\n", EdxGuest.u1CLFSH, EdxHost.u1CLFSH);
1254 pHlp->pfnPrintf(pHlp, "Reserved = %d (%d)\n", EdxGuest.u1Reserved2, EdxHost.u1Reserved2);
1255 pHlp->pfnPrintf(pHlp, "DS - Debug Store = %d (%d)\n", EdxGuest.u1DS, EdxHost.u1DS);
1256 pHlp->pfnPrintf(pHlp, "ACPI - Thermal Mon. & Soft. Clock Ctrl.= %d (%d)\n", EdxGuest.u1ACPI, EdxHost.u1ACPI);
1257 pHlp->pfnPrintf(pHlp, "MMX - Intel MMX Technology = %d (%d)\n", EdxGuest.u1MMX, EdxHost.u1MMX);
1258 pHlp->pfnPrintf(pHlp, "FXSR - FXSAVE and FXRSTOR Instructions = %d (%d)\n", EdxGuest.u1FXSR, EdxHost.u1FXSR);
1259 pHlp->pfnPrintf(pHlp, "SSE - SSE Support = %d (%d)\n", EdxGuest.u1SSE, EdxHost.u1SSE);
1260 pHlp->pfnPrintf(pHlp, "SSE2 - SSE2 Support = %d (%d)\n", EdxGuest.u1SSE2, EdxHost.u1SSE2);
1261 pHlp->pfnPrintf(pHlp, "SS - Self Snoop = %d (%d)\n", EdxGuest.u1SS, EdxHost.u1SS);
1262 pHlp->pfnPrintf(pHlp, "HTT - Hyper-Threading Technolog = %d (%d)\n", EdxGuest.u1HTT, EdxHost.u1HTT);
1263 pHlp->pfnPrintf(pHlp, "TM - Thermal Monitor = %d (%d)\n", EdxGuest.u1TM, EdxHost.u1TM);
1264 pHlp->pfnPrintf(pHlp, "30 - Reserved = %d (%d)\n", EdxGuest.u1Reserved3, EdxHost.u1Reserved3);
1265 pHlp->pfnPrintf(pHlp, "PBE - Pending Break Enable = %d (%d)\n", EdxGuest.u1PBE, EdxHost.u1PBE);
1266
1267 pHlp->pfnPrintf(pHlp, "Supports SSE3 or not = %d (%d)\n", EcxGuest.u1SSE3, EcxHost.u1SSE3);
1268 pHlp->pfnPrintf(pHlp, "Reserved = %d (%d)\n", EcxGuest.u2Reserved1, EcxHost.u2Reserved1);
1269 pHlp->pfnPrintf(pHlp, "Supports MONITOR/MWAIT = %d (%d)\n", EcxGuest.u1Monitor, EcxHost.u1Monitor);
1270 pHlp->pfnPrintf(pHlp, "CPL-DS - CPL Qualified Debug Store = %d (%d)\n", EcxGuest.u1CPLDS, EcxHost.u1CPLDS);
1271 pHlp->pfnPrintf(pHlp, "VMX - Virtual Machine Technology = %d (%d)\n", EcxGuest.u1VMX, EcxHost.u1VMX);
1272 pHlp->pfnPrintf(pHlp, "Reserved = %d (%d)\n", EcxGuest.u1Reserved2, EcxHost.u1Reserved2);
1273 pHlp->pfnPrintf(pHlp, "Enhanced SpeedStep Technology = %d (%d)\n", EcxGuest.u1EST, EcxHost.u1EST);
1274 pHlp->pfnPrintf(pHlp, "Terminal Monitor 2 = %d (%d)\n", EcxGuest.u1TM2, EcxHost.u1TM2);
1275 pHlp->pfnPrintf(pHlp, "Supports Supplemental SSE3 or not = %d (%d)\n", EcxGuest.u1SSSE3, EcxHost.u1SSSE3);
1276 pHlp->pfnPrintf(pHlp, "L1 Context ID = %d (%d)\n", EcxGuest.u1CNTXID, EcxHost.u1CNTXID);
1277 pHlp->pfnPrintf(pHlp, "Reserved = %#x (%#x)\n",EcxGuest.u2Reserved4, EcxHost.u2Reserved4);
1278 pHlp->pfnPrintf(pHlp, "CMPXCHG16B = %d (%d)\n", EcxGuest.u1CX16, EcxHost.u1CX16);
1279 pHlp->pfnPrintf(pHlp, "xTPR Update Control = %d (%d)\n", EcxGuest.u1TPRUpdate, EcxHost.u1TPRUpdate);
1280 pHlp->pfnPrintf(pHlp, "Reserved = %#x (%#x)\n",EcxGuest.u17Reserved5, EcxHost.u17Reserved5);
1281 }
1282 }
1283 if (cStdMax >= 2 && iVerbosity)
1284 {
1285 /** @todo */
1286 }
1287
1288 /*
1289 * Extended.
1290 * Implemented after AMD specs.
1291 */
1292 unsigned cExtMax = pVM->cpum.s.aGuestCpuIdExt[0].eax & 0xffff;
1293
1294 pHlp->pfnPrintf(pHlp,
1295 "\n"
1296 " RAW Extended CPUIDs\n"
1297 " Function eax ebx ecx edx\n");
1298 for (unsigned i = 0; i < ELEMENTS(pVM->cpum.s.aGuestCpuIdExt); i++)
1299 {
1300 Guest = pVM->cpum.s.aGuestCpuIdExt[i];
1301 ASMCpuId(0x80000000 | i, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
1302
1303 pHlp->pfnPrintf(pHlp,
1304 "Gst: %08x %08x %08x %08x %08x%s\n"
1305 "Hst: %08x %08x %08x %08x\n",
1306 0x80000000 | i, Guest.eax, Guest.ebx, Guest.ecx, Guest.edx,
1307 i <= cExtMax ? "" : "*",
1308 Host.eax, Host.ebx, Host.ecx, Host.edx);
1309 }
1310
1311 /*
1312 * Understandable output
1313 */
1314 if (iVerbosity && cExtMax >= 0)
1315 {
1316 Guest = pVM->cpum.s.aGuestCpuIdExt[0];
1317 pHlp->pfnPrintf(pHlp,
1318 "Ext Name: %.4s%.4s%.4s\n"
1319 "Ext Supports: 0x80000000-%#010x\n",
1320 &Guest.ebx, &Guest.edx, &Guest.ecx, Guest.eax);
1321 }
1322
1323 if (iVerbosity && cExtMax >= 1)
1324 {
1325 Guest = pVM->cpum.s.aGuestCpuIdExt[1];
1326 uint32_t uEAX = Guest.eax;
1327 pHlp->pfnPrintf(pHlp,
1328 "Family: %d \tExtended: %d \tEffectiv: %d\n"
1329 "Model: %d \tExtended: %d \tEffectiv: %d\n"
1330 "Stepping: %d\n"
1331 "Brand ID: %#05x\n",
1332 (uEAX >> 8) & 0xf, (uEAX >> 20) & 0x7f, ASMGetCpuFamily(uEAX),
1333 (uEAX >> 4) & 0xf, (uEAX >> 16) & 0x0f, ASMGetCpuModel(uEAX, fIntel),
1334 ASMGetCpuStepping(uEAX),
1335 Guest.ebx & 0xfff);
1336
1337 if (iVerbosity == 1)
1338 {
1339 uint32_t uEDX = Guest.edx;
1340 pHlp->pfnPrintf(pHlp, "Features EDX: ");
1341 if (uEDX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " FPU");
1342 if (uEDX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " VME");
1343 if (uEDX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " DE");
1344 if (uEDX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " PSE");
1345 if (uEDX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " TSC");
1346 if (uEDX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " MSR");
1347 if (uEDX & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " PAE");
1348 if (uEDX & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " MCE");
1349 if (uEDX & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " CX8");
1350 if (uEDX & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " APIC");
1351 if (uEDX & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " 10");
1352 if (uEDX & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " SCR");
1353 if (uEDX & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " MTRR");
1354 if (uEDX & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " PGE");
1355 if (uEDX & RT_BIT(14)) pHlp->pfnPrintf(pHlp, " MCA");
1356 if (uEDX & RT_BIT(15)) pHlp->pfnPrintf(pHlp, " CMOV");
1357 if (uEDX & RT_BIT(16)) pHlp->pfnPrintf(pHlp, " PAT");
1358 if (uEDX & RT_BIT(17)) pHlp->pfnPrintf(pHlp, " PSE36");
1359 if (uEDX & RT_BIT(18)) pHlp->pfnPrintf(pHlp, " 18");
1360 if (uEDX & RT_BIT(19)) pHlp->pfnPrintf(pHlp, " 19");
1361 if (uEDX & RT_BIT(20)) pHlp->pfnPrintf(pHlp, " NX");
1362 if (uEDX & RT_BIT(21)) pHlp->pfnPrintf(pHlp, " 21");
1363 if (uEDX & RT_BIT(22)) pHlp->pfnPrintf(pHlp, " ExtMMX");
1364 if (uEDX & RT_BIT(23)) pHlp->pfnPrintf(pHlp, " MMX");
1365 if (uEDX & RT_BIT(24)) pHlp->pfnPrintf(pHlp, " FXSR");
1366 if (uEDX & RT_BIT(25)) pHlp->pfnPrintf(pHlp, " FastFXSR");
1367 if (uEDX & RT_BIT(26)) pHlp->pfnPrintf(pHlp, " Page1GB");
1368 if (uEDX & RT_BIT(27)) pHlp->pfnPrintf(pHlp, " RDTSCP");
1369 if (uEDX & RT_BIT(28)) pHlp->pfnPrintf(pHlp, " 28");
1370 if (uEDX & RT_BIT(29)) pHlp->pfnPrintf(pHlp, " LongMode");
1371 if (uEDX & RT_BIT(30)) pHlp->pfnPrintf(pHlp, " Ext3DNow");
1372 if (uEDX & RT_BIT(31)) pHlp->pfnPrintf(pHlp, " 3DNow");
1373 pHlp->pfnPrintf(pHlp, "\n");
1374
1375 uint32_t uECX = Guest.ecx;
1376 pHlp->pfnPrintf(pHlp, "Features ECX: ");
1377 if (uECX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " LAHF/SAHF");
1378 if (uECX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " CMPL");
1379 if (uECX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " SVM");
1380 if (uECX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " ExtAPIC");
1381 if (uECX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " CR8L");
1382 if (uECX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " ABM");
1383 if (uECX & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " SSE4A");
1384 if (uECX & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " MISALNSSE");
1385 if (uECX & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " 3DNOWPRF");
1386 if (uECX & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " OSVW");
1387 if (uECX & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " IBS");
1388 if (uECX & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " SSE5");
1389 if (uECX & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " SKINIT");
1390 if (uECX & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " WDT");
1391 for (unsigned iBit = 5; iBit < 32; iBit++)
1392 if (uECX & RT_BIT(iBit))
1393 pHlp->pfnPrintf(pHlp, " %d", iBit);
1394 pHlp->pfnPrintf(pHlp, "\n");
1395 }
1396 else
1397 {
1398 ASMCpuId(0x80000001, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
1399
1400 uint32_t uEdxGst = Guest.edx;
1401 uint32_t uEdxHst = Host.edx;
1402 pHlp->pfnPrintf(pHlp, "Mnemonic - Description = guest (host)\n");
1403 pHlp->pfnPrintf(pHlp, "FPU - x87 FPU on Chip = %d (%d)\n", !!(uEdxGst & RT_BIT( 0)), !!(uEdxHst & RT_BIT( 0)));
1404 pHlp->pfnPrintf(pHlp, "VME - Virtual 8086 Mode Enhancements = %d (%d)\n", !!(uEdxGst & RT_BIT( 1)), !!(uEdxHst & RT_BIT( 1)));
1405 pHlp->pfnPrintf(pHlp, "DE - Debugging extensions = %d (%d)\n", !!(uEdxGst & RT_BIT( 2)), !!(uEdxHst & RT_BIT( 2)));
1406 pHlp->pfnPrintf(pHlp, "PSE - Page Size Extension = %d (%d)\n", !!(uEdxGst & RT_BIT( 3)), !!(uEdxHst & RT_BIT( 3)));
1407 pHlp->pfnPrintf(pHlp, "TSC - Time Stamp Counter = %d (%d)\n", !!(uEdxGst & RT_BIT( 4)), !!(uEdxHst & RT_BIT( 4)));
1408 pHlp->pfnPrintf(pHlp, "MSR - K86 Model Specific Registers = %d (%d)\n", !!(uEdxGst & RT_BIT( 5)), !!(uEdxHst & RT_BIT( 5)));
1409 pHlp->pfnPrintf(pHlp, "PAE - Physical Address Extension = %d (%d)\n", !!(uEdxGst & RT_BIT( 6)), !!(uEdxHst & RT_BIT( 6)));
1410 pHlp->pfnPrintf(pHlp, "MCE - Machine Check Exception = %d (%d)\n", !!(uEdxGst & RT_BIT( 7)), !!(uEdxHst & RT_BIT( 7)));
1411 pHlp->pfnPrintf(pHlp, "CX8 - CMPXCHG8B instruction = %d (%d)\n", !!(uEdxGst & RT_BIT( 8)), !!(uEdxHst & RT_BIT( 8)));
1412 pHlp->pfnPrintf(pHlp, "APIC - APIC On-Chip = %d (%d)\n", !!(uEdxGst & RT_BIT( 9)), !!(uEdxHst & RT_BIT( 9)));
1413 pHlp->pfnPrintf(pHlp, "10 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(10)), !!(uEdxHst & RT_BIT(10)));
1414 pHlp->pfnPrintf(pHlp, "SEP - SYSCALL and SYSRET = %d (%d)\n", !!(uEdxGst & RT_BIT(11)), !!(uEdxHst & RT_BIT(11)));
1415 pHlp->pfnPrintf(pHlp, "MTRR - Memory Type Range Registers = %d (%d)\n", !!(uEdxGst & RT_BIT(12)), !!(uEdxHst & RT_BIT(12)));
1416 pHlp->pfnPrintf(pHlp, "PGE - PTE Global Bit = %d (%d)\n", !!(uEdxGst & RT_BIT(13)), !!(uEdxHst & RT_BIT(13)));
1417 pHlp->pfnPrintf(pHlp, "MCA - Machine Check Architecture = %d (%d)\n", !!(uEdxGst & RT_BIT(14)), !!(uEdxHst & RT_BIT(14)));
1418 pHlp->pfnPrintf(pHlp, "CMOV - Conditional Move Instructions = %d (%d)\n", !!(uEdxGst & RT_BIT(15)), !!(uEdxHst & RT_BIT(15)));
1419 pHlp->pfnPrintf(pHlp, "PAT - Page Attribute Table = %d (%d)\n", !!(uEdxGst & RT_BIT(16)), !!(uEdxHst & RT_BIT(16)));
1420 pHlp->pfnPrintf(pHlp, "PSE-36 - 36-bit Page Size Extention = %d (%d)\n", !!(uEdxGst & RT_BIT(17)), !!(uEdxHst & RT_BIT(17)));
1421 pHlp->pfnPrintf(pHlp, "18 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(18)), !!(uEdxHst & RT_BIT(18)));
1422 pHlp->pfnPrintf(pHlp, "19 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(19)), !!(uEdxHst & RT_BIT(19)));
1423 pHlp->pfnPrintf(pHlp, "NX - No-Execute Page Protection = %d (%d)\n", !!(uEdxGst & RT_BIT(20)), !!(uEdxHst & RT_BIT(20)));
1424 pHlp->pfnPrintf(pHlp, "DS - Debug Store = %d (%d)\n", !!(uEdxGst & RT_BIT(21)), !!(uEdxHst & RT_BIT(21)));
1425 pHlp->pfnPrintf(pHlp, "AXMMX - AMD Extensions to MMX Instr. = %d (%d)\n", !!(uEdxGst & RT_BIT(22)), !!(uEdxHst & RT_BIT(22)));
1426 pHlp->pfnPrintf(pHlp, "MMX - Intel MMX Technology = %d (%d)\n", !!(uEdxGst & RT_BIT(23)), !!(uEdxHst & RT_BIT(23)));
1427 pHlp->pfnPrintf(pHlp, "FXSR - FXSAVE and FXRSTOR Instructions = %d (%d)\n", !!(uEdxGst & RT_BIT(24)), !!(uEdxHst & RT_BIT(24)));
1428 pHlp->pfnPrintf(pHlp, "25 - AMD fast FXSAVE and FXRSTOR Instr.= %d (%d)\n", !!(uEdxGst & RT_BIT(25)), !!(uEdxHst & RT_BIT(25)));
1429 pHlp->pfnPrintf(pHlp, "26 - 1 GB large page support = %d (%d)\n", !!(uEdxGst & RT_BIT(26)), !!(uEdxHst & RT_BIT(26)));
1430 pHlp->pfnPrintf(pHlp, "27 - RDTSCP instruction = %d (%d)\n", !!(uEdxGst & RT_BIT(27)), !!(uEdxHst & RT_BIT(27)));
1431 pHlp->pfnPrintf(pHlp, "28 - Reserved = %d (%d)\n", !!(uEdxGst & RT_BIT(28)), !!(uEdxHst & RT_BIT(28)));
1432 pHlp->pfnPrintf(pHlp, "29 - AMD Long Mode = %d (%d)\n", !!(uEdxGst & RT_BIT(29)), !!(uEdxHst & RT_BIT(29)));
1433 pHlp->pfnPrintf(pHlp, "30 - AMD Extensions to 3DNow = %d (%d)\n", !!(uEdxGst & RT_BIT(30)), !!(uEdxHst & RT_BIT(30)));
1434 pHlp->pfnPrintf(pHlp, "31 - AMD 3DNow = %d (%d)\n", !!(uEdxGst & RT_BIT(31)), !!(uEdxHst & RT_BIT(31)));
1435
1436 uint32_t uEcxGst = Guest.ecx;
1437 uint32_t uEcxHst = Host.ecx;
1438 pHlp->pfnPrintf(pHlp, "LahfSahf - LAHF/SAHF in 64-bit mode = %d (%d)\n", !!(uEcxGst & RT_BIT( 0)), !!(uEcxHst & RT_BIT( 0)));
1439 pHlp->pfnPrintf(pHlp, "CmpLegacy - Core MP legacy mode (depr) = %d (%d)\n", !!(uEcxGst & RT_BIT( 1)), !!(uEcxHst & RT_BIT( 1)));
1440 pHlp->pfnPrintf(pHlp, "SVM - AMD VM Extensions = %d (%d)\n", !!(uEcxGst & RT_BIT( 2)), !!(uEcxHst & RT_BIT( 2)));
1441 pHlp->pfnPrintf(pHlp, "APIC registers starting at 0x400 = %d (%d)\n", !!(uEcxGst & RT_BIT( 3)), !!(uEcxHst & RT_BIT( 3)));
1442 pHlp->pfnPrintf(pHlp, "AltMovCR8 - LOCK MOV CR0 means MOV CR8 = %d (%d)\n", !!(uEcxGst & RT_BIT( 4)), !!(uEcxHst & RT_BIT( 4)));
1443 pHlp->pfnPrintf(pHlp, "Advanced bit manipulation = %d (%d)\n", !!(uEcxGst & RT_BIT( 5)), !!(uEcxHst & RT_BIT( 5)));
1444 pHlp->pfnPrintf(pHlp, "SSE4A instruction support = %d (%d)\n", !!(uEcxGst & RT_BIT( 6)), !!(uEcxHst & RT_BIT( 6)));
1445 pHlp->pfnPrintf(pHlp, "Misaligned SSE mode = %d (%d)\n", !!(uEcxGst & RT_BIT( 7)), !!(uEcxHst & RT_BIT( 7)));
1446 pHlp->pfnPrintf(pHlp, "PREFETCH and PREFETCHW instruction = %d (%d)\n", !!(uEcxGst & RT_BIT( 8)), !!(uEcxHst & RT_BIT( 8)));
1447 pHlp->pfnPrintf(pHlp, "OS visible workaround = %d (%d)\n", !!(uEcxGst & RT_BIT( 9)), !!(uEcxHst & RT_BIT( 9)));
1448 pHlp->pfnPrintf(pHlp, "Instruction based sampling = %d (%d)\n", !!(uEcxGst & RT_BIT(10)), !!(uEcxHst & RT_BIT(10)));
1449 pHlp->pfnPrintf(pHlp, "SSE5 support = %d (%d)\n", !!(uEcxGst & RT_BIT(11)), !!(uEcxHst & RT_BIT(11)));
1450 pHlp->pfnPrintf(pHlp, "SKINIT, STGI, and DEV support = %d (%d)\n", !!(uEcxGst & RT_BIT(12)), !!(uEcxHst & RT_BIT(12)));
1451 pHlp->pfnPrintf(pHlp, "Watchdog timer support. = %d (%d)\n", !!(uEcxGst & RT_BIT(13)), !!(uEcxHst & RT_BIT(13)));
1452 pHlp->pfnPrintf(pHlp, "31:14 - Reserved = %#x (%#x)\n", uEcxGst >> 14, uEcxHst >> 14);
1453 }
1454 }
1455
1456 if (iVerbosity && cExtMax >= 2)
1457 {
1458 char szString[4*4*3+1] = {0};
1459 uint32_t *pu32 = (uint32_t *)szString;
1460 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[2].eax;
1461 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[2].ebx;
1462 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[2].ecx;
1463 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[2].edx;
1464 if (cExtMax >= 3)
1465 {
1466 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[3].eax;
1467 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[3].ebx;
1468 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[3].ecx;
1469 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[3].edx;
1470 }
1471 if (cExtMax >= 4)
1472 {
1473 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[4].eax;
1474 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[4].ebx;
1475 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[4].ecx;
1476 *pu32++ = pVM->cpum.s.aGuestCpuIdExt[4].edx;
1477 }
1478 pHlp->pfnPrintf(pHlp, "Full Name: %s\n", szString);
1479 }
1480
1481 if (iVerbosity && cExtMax >= 5)
1482 {
1483 uint32_t uEAX = pVM->cpum.s.aGuestCpuIdExt[5].eax;
1484 uint32_t uEBX = pVM->cpum.s.aGuestCpuIdExt[5].ebx;
1485 uint32_t uECX = pVM->cpum.s.aGuestCpuIdExt[5].ecx;
1486 uint32_t uEDX = pVM->cpum.s.aGuestCpuIdExt[5].edx;
1487 char sz1[32];
1488 char sz2[32];
1489
1490 pHlp->pfnPrintf(pHlp,
1491 "TLB 2/4M Instr/Uni: %s %3d entries\n"
1492 "TLB 2/4M Data: %s %3d entries\n",
1493 getCacheAss((uEAX >> 8) & 0xff, sz1), (uEAX >> 0) & 0xff,
1494 getCacheAss((uEAX >> 24) & 0xff, sz2), (uEAX >> 16) & 0xff);
1495 pHlp->pfnPrintf(pHlp,
1496 "TLB 4K Instr/Uni: %s %3d entries\n"
1497 "TLB 4K Data: %s %3d entries\n",
1498 getCacheAss((uEBX >> 8) & 0xff, sz1), (uEBX >> 0) & 0xff,
1499 getCacheAss((uEBX >> 24) & 0xff, sz2), (uEBX >> 16) & 0xff);
1500 pHlp->pfnPrintf(pHlp, "L1 Instr Cache Line Size: %d bytes\n"
1501 "L1 Instr Cache Lines Per Tag: %d\n"
1502 "L1 Instr Cache Associativity: %s\n"
1503 "L1 Instr Cache Size: %d KB\n",
1504 (uEDX >> 0) & 0xff,
1505 (uEDX >> 8) & 0xff,
1506 getCacheAss((uEDX >> 16) & 0xff, sz1),
1507 (uEDX >> 24) & 0xff);
1508 pHlp->pfnPrintf(pHlp,
1509 "L1 Data Cache Line Size: %d bytes\n"
1510 "L1 Data Cache Lines Per Tag: %d\n"
1511 "L1 Data Cache Associativity: %s\n"
1512 "L1 Data Cache Size: %d KB\n",
1513 (uECX >> 0) & 0xff,
1514 (uECX >> 8) & 0xff,
1515 getCacheAss((uECX >> 16) & 0xff, sz1),
1516 (uECX >> 24) & 0xff);
1517 }
1518
1519 if (iVerbosity && cExtMax >= 6)
1520 {
1521 uint32_t uEAX = pVM->cpum.s.aGuestCpuIdExt[6].eax;
1522 uint32_t uEBX = pVM->cpum.s.aGuestCpuIdExt[6].ebx;
1523 uint32_t uEDX = pVM->cpum.s.aGuestCpuIdExt[6].edx;
1524
1525 pHlp->pfnPrintf(pHlp,
1526 "L2 TLB 2/4M Instr/Uni: %s %4d entries\n"
1527 "L2 TLB 2/4M Data: %s %4d entries\n",
1528 getL2CacheAss((uEAX >> 12) & 0xf), (uEAX >> 0) & 0xfff,
1529 getL2CacheAss((uEAX >> 28) & 0xf), (uEAX >> 16) & 0xfff);
1530 pHlp->pfnPrintf(pHlp,
1531 "L2 TLB 4K Instr/Uni: %s %4d entries\n"
1532 "L2 TLB 4K Data: %s %4d entries\n",
1533 getL2CacheAss((uEBX >> 12) & 0xf), (uEBX >> 0) & 0xfff,
1534 getL2CacheAss((uEBX >> 28) & 0xf), (uEBX >> 16) & 0xfff);
1535 pHlp->pfnPrintf(pHlp,
1536 "L2 Cache Line Size: %d bytes\n"
1537 "L2 Cache Lines Per Tag: %d\n"
1538 "L2 Cache Associativity: %s\n"
1539 "L2 Cache Size: %d KB\n",
1540 (uEDX >> 0) & 0xff,
1541 (uEDX >> 8) & 0xf,
1542 getL2CacheAss((uEDX >> 12) & 0xf),
1543 (uEDX >> 16) & 0xffff);
1544 }
1545
1546 if (iVerbosity && cExtMax >= 7)
1547 {
1548 uint32_t uEDX = pVM->cpum.s.aGuestCpuIdExt[7].edx;
1549
1550 pHlp->pfnPrintf(pHlp, "APM Features: ");
1551 if (uEDX & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " TS");
1552 if (uEDX & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " FID");
1553 if (uEDX & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " VID");
1554 if (uEDX & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " TTP");
1555 if (uEDX & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " TM");
1556 if (uEDX & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " STC");
1557 for (unsigned iBit = 6; iBit < 32; iBit++)
1558 if (uEDX & RT_BIT(iBit))
1559 pHlp->pfnPrintf(pHlp, " %d", iBit);
1560 pHlp->pfnPrintf(pHlp, "\n");
1561 }
1562
1563 if (iVerbosity && cExtMax >= 8)
1564 {
1565 uint32_t uEAX = pVM->cpum.s.aGuestCpuIdExt[8].eax;
1566 uint32_t uECX = pVM->cpum.s.aGuestCpuIdExt[8].ecx;
1567
1568 pHlp->pfnPrintf(pHlp,
1569 "Physical Address Width: %d bits\n"
1570 "Virtual Address Width: %d bits\n",
1571 (uEAX >> 0) & 0xff,
1572 (uEAX >> 8) & 0xff);
1573 pHlp->pfnPrintf(pHlp,
1574 "Physical Core Count: %d\n",
1575 (uECX >> 0) & 0xff);
1576 }
1577
1578
1579 /*
1580 * Centaur.
1581 */
1582 unsigned cCentaurMax = pVM->cpum.s.aGuestCpuIdCentaur[0].eax & 0xffff;
1583
1584 pHlp->pfnPrintf(pHlp,
1585 "\n"
1586 " RAW Centaur CPUIDs\n"
1587 " Function eax ebx ecx edx\n");
1588 for (unsigned i = 0; i < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdCentaur); i++)
1589 {
1590 Guest = pVM->cpum.s.aGuestCpuIdCentaur[i];
1591 ASMCpuId(0xc0000000 | i, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
1592
1593 pHlp->pfnPrintf(pHlp,
1594 "Gst: %08x %08x %08x %08x %08x%s\n"
1595 "Hst: %08x %08x %08x %08x\n",
1596 0xc0000000 | i, Guest.eax, Guest.ebx, Guest.ecx, Guest.edx,
1597 i <= cCentaurMax ? "" : "*",
1598 Host.eax, Host.ebx, Host.ecx, Host.edx);
1599 }
1600
1601 /*
1602 * Understandable output
1603 */
1604 if (iVerbosity && cCentaurMax >= 0)
1605 {
1606 Guest = pVM->cpum.s.aGuestCpuIdCentaur[0];
1607 pHlp->pfnPrintf(pHlp,
1608 "Centaur Supports: 0xc0000000-%#010x\n",
1609 Guest.eax);
1610 }
1611
1612 if (iVerbosity && cCentaurMax >= 1)
1613 {
1614 ASMCpuId(0xc0000001, &Host.eax, &Host.ebx, &Host.ecx, &Host.edx);
1615 uint32_t uEdxGst = pVM->cpum.s.aGuestCpuIdExt[1].edx;
1616 uint32_t uEdxHst = Host.edx;
1617
1618 if (iVerbosity == 1)
1619 {
1620 pHlp->pfnPrintf(pHlp, "Centaur Features EDX: ");
1621 if (uEdxGst & RT_BIT(0)) pHlp->pfnPrintf(pHlp, " AIS");
1622 if (uEdxGst & RT_BIT(1)) pHlp->pfnPrintf(pHlp, " AIS-E");
1623 if (uEdxGst & RT_BIT(2)) pHlp->pfnPrintf(pHlp, " RNG");
1624 if (uEdxGst & RT_BIT(3)) pHlp->pfnPrintf(pHlp, " RNG-E");
1625 if (uEdxGst & RT_BIT(4)) pHlp->pfnPrintf(pHlp, " LH");
1626 if (uEdxGst & RT_BIT(5)) pHlp->pfnPrintf(pHlp, " FEMMS");
1627 if (uEdxGst & RT_BIT(6)) pHlp->pfnPrintf(pHlp, " ACE");
1628 if (uEdxGst & RT_BIT(7)) pHlp->pfnPrintf(pHlp, " ACE-E");
1629 /* possibly indicating MM/HE and MM/HE-E on older chips... */
1630 if (uEdxGst & RT_BIT(8)) pHlp->pfnPrintf(pHlp, " ACE2");
1631 if (uEdxGst & RT_BIT(9)) pHlp->pfnPrintf(pHlp, " ACE2-E");
1632 if (uEdxGst & RT_BIT(10)) pHlp->pfnPrintf(pHlp, " PHE");
1633 if (uEdxGst & RT_BIT(11)) pHlp->pfnPrintf(pHlp, " PHE-E");
1634 if (uEdxGst & RT_BIT(12)) pHlp->pfnPrintf(pHlp, " PMM");
1635 if (uEdxGst & RT_BIT(13)) pHlp->pfnPrintf(pHlp, " PMM-E");
1636 for (unsigned iBit = 14; iBit < 32; iBit++)
1637 if (uEdxGst & RT_BIT(iBit))
1638 pHlp->pfnPrintf(pHlp, " %d", iBit);
1639 pHlp->pfnPrintf(pHlp, "\n");
1640 }
1641 else
1642 {
1643 pHlp->pfnPrintf(pHlp, "Mnemonic - Description = guest (host)\n");
1644 pHlp->pfnPrintf(pHlp, "AIS - Alternate Instruction Set = %d (%d)\n", !!(uEdxGst & RT_BIT( 0)), !!(uEdxHst & RT_BIT( 0)));
1645 pHlp->pfnPrintf(pHlp, "AIS-E - AIS enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 1)), !!(uEdxHst & RT_BIT( 1)));
1646 pHlp->pfnPrintf(pHlp, "RNG - Random Number Generator = %d (%d)\n", !!(uEdxGst & RT_BIT( 2)), !!(uEdxHst & RT_BIT( 2)));
1647 pHlp->pfnPrintf(pHlp, "RNG-E - RNG enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 3)), !!(uEdxHst & RT_BIT( 3)));
1648 pHlp->pfnPrintf(pHlp, "LH - LongHaul MSR 0000_110Ah = %d (%d)\n", !!(uEdxGst & RT_BIT( 4)), !!(uEdxHst & RT_BIT( 4)));
1649 pHlp->pfnPrintf(pHlp, "FEMMS - FEMMS = %d (%d)\n", !!(uEdxGst & RT_BIT( 5)), !!(uEdxHst & RT_BIT( 5)));
1650 pHlp->pfnPrintf(pHlp, "ACE - Advanced Cryptography Engine = %d (%d)\n", !!(uEdxGst & RT_BIT( 6)), !!(uEdxHst & RT_BIT( 6)));
1651 pHlp->pfnPrintf(pHlp, "ACE-E - ACE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 7)), !!(uEdxHst & RT_BIT( 7)));
1652 /* possibly indicating MM/HE and MM/HE-E on older chips... */
1653 pHlp->pfnPrintf(pHlp, "ACE2 - Advanced Cryptography Engine 2 = %d (%d)\n", !!(uEdxGst & RT_BIT( 8)), !!(uEdxHst & RT_BIT( 8)));
1654 pHlp->pfnPrintf(pHlp, "ACE2-E - ACE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT( 9)), !!(uEdxHst & RT_BIT( 9)));
1655 pHlp->pfnPrintf(pHlp, "PHE - Hash Engine = %d (%d)\n", !!(uEdxGst & RT_BIT(10)), !!(uEdxHst & RT_BIT(10)));
1656 pHlp->pfnPrintf(pHlp, "PHE-E - PHE enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(11)), !!(uEdxHst & RT_BIT(11)));
1657 pHlp->pfnPrintf(pHlp, "PMM - Montgomery Multiplier = %d (%d)\n", !!(uEdxGst & RT_BIT(12)), !!(uEdxHst & RT_BIT(12)));
1658 pHlp->pfnPrintf(pHlp, "PMM-E - PMM enabled = %d (%d)\n", !!(uEdxGst & RT_BIT(13)), !!(uEdxHst & RT_BIT(13)));
1659 for (unsigned iBit = 14; iBit < 32; iBit++)
1660 if ((uEdxGst | uEdxHst) & RT_BIT(iBit))
1661 pHlp->pfnPrintf(pHlp, "Bit %d = %d (%d)\n", !!(uEdxGst & RT_BIT(iBit)), !!(uEdxHst & RT_BIT(iBit)));
1662 pHlp->pfnPrintf(pHlp, "\n");
1663 }
1664 }
1665}
1666
1667
1668/**
1669 * Structure used when disassembling and instructions in DBGF.
1670 * This is used so the reader function can get the stuff it needs.
1671 */
1672typedef struct CPUMDISASSTATE
1673{
1674 /** Pointer to the CPU structure. */
1675 PDISCPUSTATE pCpu;
1676 /** The VM handle. */
1677 PVM pVM;
1678 /** Pointer to the first byte in the segemnt. */
1679 RTGCUINTPTR GCPtrSegBase;
1680 /** Pointer to the byte after the end of the segment. (might have wrapped!) */
1681 RTGCUINTPTR GCPtrSegEnd;
1682 /** The size of the segment minus 1. */
1683 RTGCUINTPTR cbSegLimit;
1684 /** Pointer to the current page - HC Ptr. */
1685 void const *pvPageHC;
1686 /** Pointer to the current page - GC Ptr. */
1687 RTGCPTR pvPageGC;
1688 /** The lock information that PGMPhysReleasePageMappingLock needs. */
1689 PGMPAGEMAPLOCK PageMapLock;
1690 /** Whether the PageMapLock is valid or not. */
1691 bool fLocked;
1692} CPUMDISASSTATE, *PCPUMDISASSTATE;
1693
1694
1695/**
1696 * Instruction reader.
1697 *
1698 * @returns VBox status code.
1699 * @param PtrSrc Address to read from.
1700 * In our case this is relative to the selector pointed to by the 2nd user argument of uDisCpu.
1701 * @param pu8Dst Where to store the bytes.
1702 * @param cbRead Number of bytes to read.
1703 * @param uDisCpu Pointer to the disassembler cpu state.
1704 * In this context it's always pointer to the Core of a DBGFDISASSTATE.
1705 */
1706static DECLCALLBACK(int) cpumR3DisasInstrRead(RTUINTPTR PtrSrc, uint8_t *pu8Dst, unsigned cbRead, void *uDisCpu)
1707{
1708 PDISCPUSTATE pCpu = (PDISCPUSTATE)uDisCpu;
1709 PCPUMDISASSTATE pState = (PCPUMDISASSTATE)pCpu->apvUserData[0];
1710 Assert(cbRead > 0);
1711 for (;;)
1712 {
1713 RTGCUINTPTR GCPtr = PtrSrc + pState->GCPtrSegBase;
1714
1715 /* Need to update the page translation? */
1716 if ( !pState->pvPageHC
1717 || (GCPtr >> PAGE_SHIFT) != (pState->pvPageGC >> PAGE_SHIFT))
1718 {
1719 int rc = VINF_SUCCESS;
1720
1721 /* translate the address */
1722 pState->pvPageGC = GCPtr & PAGE_BASE_GC_MASK;
1723 if (MMHyperIsInsideArea(pState->pVM, pState->pvPageGC))
1724 {
1725 pState->pvPageHC = MMHyperGC2HC(pState->pVM, pState->pvPageGC);
1726 if (!pState->pvPageHC)
1727 rc = VERR_INVALID_POINTER;
1728 }
1729 else
1730 {
1731 /* Release mapping lock previously acquired. */
1732 if (pState->fLocked)
1733 PGMPhysReleasePageMappingLock(pState->pVM, &pState->PageMapLock);
1734 rc = PGMPhysGCPtr2CCPtrReadOnly(pState->pVM, pState->pvPageGC, &pState->pvPageHC, &pState->PageMapLock);
1735 pState->fLocked = RT_SUCCESS_NP(rc);
1736 }
1737 if (VBOX_FAILURE(rc))
1738 {
1739 pState->pvPageHC = NULL;
1740 return rc;
1741 }
1742 }
1743
1744 /* check the segemnt limit */
1745 if (PtrSrc > pState->cbSegLimit)
1746 return VERR_OUT_OF_SELECTOR_BOUNDS;
1747
1748 /* calc how much we can read */
1749 uint32_t cb = PAGE_SIZE - (GCPtr & PAGE_OFFSET_MASK);
1750 RTGCUINTPTR cbSeg = pState->GCPtrSegEnd - GCPtr;
1751 if (cb > cbSeg && !cbSeg)
1752 cb = cbSeg;
1753 if (cb > cbRead)
1754 cb = cbRead;
1755
1756 /* read and advance */
1757 memcpy(pu8Dst, (char *)pState->pvPageHC + (GCPtr & PAGE_OFFSET_MASK), cb);
1758 cbRead -= cb;
1759 if (!cbRead)
1760 return VINF_SUCCESS;
1761 pu8Dst += cb;
1762 PtrSrc += cb;
1763 }
1764}
1765
1766
1767/**
1768 * Disassemble an instruction and return the information in the provided structure.
1769 *
1770 * @returns VBox status code.
1771 * @param pVM VM Handle
1772 * @param pCtx CPU context
1773 * @param GCPtrPC Program counter (relative to CS) to disassemble from.
1774 * @param pCpu Disassembly state
1775 * @param pszPrefix String prefix for logging (debug only)
1776 *
1777 */
1778CPUMR3DECL(int) CPUMR3DisasmInstrCPU(PVM pVM, PCPUMCTX pCtx, RTGCPTR GCPtrPC, PDISCPUSTATE pCpu, const char *pszPrefix)
1779{
1780 CPUMDISASSTATE State;
1781 int rc;
1782
1783 State.pCpu = pCpu;
1784 State.pvPageGC = 0;
1785 State.pvPageHC = NULL;
1786 State.pVM = pVM;
1787 State.fLocked = false;
1788
1789 /*
1790 * Get selector information.
1791 */
1792 if ( (pCtx->cr0 & X86_CR0_PE)
1793 && pCtx->eflags.Bits.u1VM == 0)
1794 {
1795 if (CPUMAreHiddenSelRegsValid(pVM))
1796 {
1797 State.GCPtrSegBase = pCtx->csHid.u32Base;
1798 State.GCPtrSegEnd = pCtx->csHid.u32Limit + 1 + (RTGCUINTPTR)pCtx->csHid.u32Base;
1799 State.cbSegLimit = pCtx->csHid.u32Limit;
1800 pCpu->mode = pCtx->csHid.Attr.n.u1DefBig ? CPUMODE_32BIT : CPUMODE_16BIT;
1801 }
1802 else
1803 {
1804 SELMSELINFO SelInfo;
1805
1806 rc = SELMR3GetShadowSelectorInfo(pVM, pCtx->cs, &SelInfo);
1807 if (!VBOX_SUCCESS(rc))
1808 {
1809 AssertMsgFailed(("SELMR3GetShadowSelectorInfo failed for %04X:%VGv rc=%d\n", pCtx->cs, GCPtrPC, rc));
1810 return rc;
1811 }
1812
1813 /*
1814 * Validate the selector.
1815 */
1816 rc = SELMSelInfoValidateCS(&SelInfo, pCtx->ss);
1817 if (!VBOX_SUCCESS(rc))
1818 {
1819 AssertMsgFailed(("SELMSelInfoValidateCS failed for %04X:%VGv rc=%d\n", pCtx->cs, GCPtrPC, rc));
1820 return rc;
1821 }
1822 State.GCPtrSegBase = SelInfo.GCPtrBase;
1823 State.GCPtrSegEnd = SelInfo.cbLimit + 1 + (RTGCUINTPTR)SelInfo.GCPtrBase;
1824 State.cbSegLimit = SelInfo.cbLimit;
1825 pCpu->mode = SelInfo.Raw.Gen.u1DefBig ? CPUMODE_32BIT : CPUMODE_16BIT;
1826 }
1827 }
1828 else
1829 {
1830 /* real or V86 mode */
1831 pCpu->mode = CPUMODE_16BIT;
1832 State.GCPtrSegBase = pCtx->cs * 16;
1833 State.GCPtrSegEnd = 0xFFFFFFFF;
1834 State.cbSegLimit = 0xFFFFFFFF;
1835 }
1836
1837 /*
1838 * Disassemble the instruction.
1839 */
1840 pCpu->pfnReadBytes = cpumR3DisasInstrRead;
1841 pCpu->apvUserData[0] = &State;
1842
1843 uint32_t cbInstr;
1844#ifndef LOG_ENABLED
1845 rc = DISInstr(pCpu, GCPtrPC, 0, &cbInstr, NULL);
1846 if (VBOX_SUCCESS(rc))
1847 {
1848#else
1849 char szOutput[160];
1850 rc = DISInstr(pCpu, GCPtrPC, 0, &cbInstr, &szOutput[0]);
1851 if (VBOX_SUCCESS(rc))
1852 {
1853 /* log it */
1854 if (pszPrefix)
1855 Log(("%s: %s", pszPrefix, szOutput));
1856 else
1857 Log(("%s", szOutput));
1858#endif
1859 rc = VINF_SUCCESS;
1860 }
1861 else
1862 Log(("CPUMR3DisasmInstrCPU: DISInstr failed for %04X:%VGv rc=%Vrc\n", pCtx->cs, GCPtrPC, rc));
1863
1864 /* Release mapping lock acquired in cpumR3DisasInstrRead. */
1865 if (State.fLocked)
1866 PGMPhysReleasePageMappingLock(pVM, &State.PageMapLock);
1867
1868 return rc;
1869}
1870
1871
1872#ifdef DEBUG
1873/**
1874 * Disassemble an instruction and dump it to the log
1875 *
1876 * @returns VBox status code.
1877 * @param pVM VM Handle
1878 * @param pCtx CPU context
1879 * @param pc GC instruction pointer
1880 * @param prefix String prefix for logging
1881 * @deprecated Use DBGFR3DisasInstrCurrentLog().
1882 *
1883 */
1884CPUMR3DECL(void) CPUMR3DisasmInstr(PVM pVM, PCPUMCTX pCtx, RTGCPTR pc, char *prefix)
1885{
1886 DISCPUSTATE cpu;
1887
1888 CPUMR3DisasmInstrCPU(pVM, pCtx, pc, &cpu, prefix);
1889}
1890
1891/**
1892 * Disassemble an instruction and dump it to the log
1893 *
1894 * @returns VBox status code.
1895 * @param pVM VM Handle
1896 * @param pCtx CPU context
1897 * @param pc GC instruction pointer
1898 * @param prefix String prefix for logging
1899 * @param nrInstructions
1900 *
1901 */
1902CPUMR3DECL(void) CPUMR3DisasmBlock(PVM pVM, PCPUMCTX pCtx, RTGCPTR pc, char *prefix, int nrInstructions)
1903{
1904 for(int i=0;i<nrInstructions;i++)
1905 {
1906 DISCPUSTATE cpu;
1907
1908 CPUMR3DisasmInstrCPU(pVM, pCtx, pc, &cpu, prefix);
1909 pc += cpu.opsize;
1910 }
1911}
1912
1913#endif
1914
1915#ifdef DEBUG
1916/**
1917 * Debug helper - Saves guest context on raw mode entry (for fatal dump)
1918 *
1919 * @internal
1920 */
1921CPUMR3DECL(void) CPUMR3SaveEntryCtx(PVM pVM)
1922{
1923 pVM->cpum.s.GuestEntry = pVM->cpum.s.Guest;
1924}
1925#endif
1926
1927
1928/**
1929 * API for controlling a few of the CPU features found in CR4.
1930 *
1931 * Currently only X86_CR4_TSD is accepted as input.
1932 *
1933 * @returns VBox status code.
1934 *
1935 * @param pVM The VM handle.
1936 * @param fOr The CR4 OR mask.
1937 * @param fAnd The CR4 AND mask.
1938 */
1939CPUMR3DECL(int) CPUMR3SetCR4Feature(PVM pVM, RTHCUINTREG fOr, RTHCUINTREG fAnd)
1940{
1941 AssertMsgReturn(!(fOr & ~(X86_CR4_TSD)), ("%#x\n", fOr), VERR_INVALID_PARAMETER);
1942 AssertMsgReturn((fAnd & ~(X86_CR4_TSD)) == ~(X86_CR4_TSD), ("%#x\n", fAnd), VERR_INVALID_PARAMETER);
1943
1944 pVM->cpum.s.CR4.OrMask &= fAnd;
1945 pVM->cpum.s.CR4.OrMask |= fOr;
1946
1947 return VINF_SUCCESS;
1948}
1949
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