VirtualBox

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

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