VirtualBox

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

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

spaces.

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