VirtualBox

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

Last change on this file since 9545 was 9545, checked in by vboxsync, 16 years ago

Rearranged the full cpu state dump (long mode).

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