VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/CPUMDbg.cpp@ 92473

Last change on this file since 92473 was 91281, checked in by vboxsync, 3 years ago

VMM/CPUM,++: Moved the guest's extended state (XState) from the hyper heap and into CPUMCTX. bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 47.9 KB
Line 
1/* $Id: CPUMDbg.cpp 91281 2021-09-16 13:32:18Z vboxsync $ */
2/** @file
3 * CPUM - CPU Monitor / Manager, Debugger & Debugging APIs.
4 */
5
6/*
7 * Copyright (C) 2010-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DBGF
23#include <VBox/vmm/cpum.h>
24#include <VBox/vmm/dbgf.h>
25#include <VBox/vmm/apic.h>
26#include "CPUMInternal.h"
27#include <VBox/vmm/vm.h>
28#include <VBox/param.h>
29#include <VBox/err.h>
30#include <VBox/log.h>
31#include <iprt/thread.h>
32#include <iprt/string.h>
33#include <iprt/uint128.h>
34
35
36/**
37 * @interface_method_impl{DBGFREGDESC,pfnGet}
38 */
39static DECLCALLBACK(int) cpumR3RegGet_Generic(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
40{
41 PVMCPU pVCpu = (PVMCPU)pvUser;
42 void const *pv = (uint8_t const *)&pVCpu->cpum + pDesc->offRegister;
43
44 VMCPU_ASSERT_EMT(pVCpu);
45
46 switch (pDesc->enmType)
47 {
48 case DBGFREGVALTYPE_U8: pValue->u8 = *(uint8_t const *)pv; return VINF_SUCCESS;
49 case DBGFREGVALTYPE_U16: pValue->u16 = *(uint16_t const *)pv; return VINF_SUCCESS;
50 case DBGFREGVALTYPE_U32: pValue->u32 = *(uint32_t const *)pv; return VINF_SUCCESS;
51 case DBGFREGVALTYPE_U64: pValue->u64 = *(uint64_t const *)pv; return VINF_SUCCESS;
52 case DBGFREGVALTYPE_U128: pValue->u128 = *(PCRTUINT128U )pv; return VINF_SUCCESS;
53 case DBGFREGVALTYPE_U256: pValue->u256 = *(PCRTUINT256U )pv; return VINF_SUCCESS;
54 case DBGFREGVALTYPE_U512: pValue->u512 = *(PCRTUINT512U )pv; return VINF_SUCCESS;
55 default:
56 AssertMsgFailedReturn(("%d %s\n", pDesc->enmType, pDesc->pszName), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
57 }
58}
59
60
61/**
62 * @interface_method_impl{DBGFREGDESC,pfnSet}
63 */
64static DECLCALLBACK(int) cpumR3RegSet_Generic(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
65{
66 PVMCPU pVCpu = (PVMCPU)pvUser;
67 void *pv = (uint8_t *)&pVCpu->cpum + pDesc->offRegister;
68
69 VMCPU_ASSERT_EMT(pVCpu);
70
71 switch (pDesc->enmType)
72 {
73 case DBGFREGVALTYPE_U8:
74 *(uint8_t *)pv &= ~pfMask->u8;
75 *(uint8_t *)pv |= pValue->u8 & pfMask->u8;
76 return VINF_SUCCESS;
77
78 case DBGFREGVALTYPE_U16:
79 *(uint16_t *)pv &= ~pfMask->u16;
80 *(uint16_t *)pv |= pValue->u16 & pfMask->u16;
81 return VINF_SUCCESS;
82
83 case DBGFREGVALTYPE_U32:
84 *(uint32_t *)pv &= ~pfMask->u32;
85 *(uint32_t *)pv |= pValue->u32 & pfMask->u32;
86 return VINF_SUCCESS;
87
88 case DBGFREGVALTYPE_U64:
89 *(uint64_t *)pv &= ~pfMask->u64;
90 *(uint64_t *)pv |= pValue->u64 & pfMask->u64;
91 return VINF_SUCCESS;
92
93 case DBGFREGVALTYPE_U128:
94 {
95 RTUINT128U Val;
96 RTUInt128AssignAnd((PRTUINT128U)pv, RTUInt128AssignBitwiseNot(RTUInt128Assign(&Val, &pfMask->u128)));
97 RTUInt128AssignOr((PRTUINT128U)pv, RTUInt128AssignAnd(RTUInt128Assign(&Val, &pValue->u128), &pfMask->u128));
98 return VINF_SUCCESS;
99 }
100
101 default:
102 AssertMsgFailedReturn(("%d %s\n", pDesc->enmType, pDesc->pszName), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
103 }
104}
105
106
107/**
108 * @interface_method_impl{DBGFREGDESC,pfnGet}
109 */
110static DECLCALLBACK(int) cpumR3RegGet_XStateGeneric(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
111{
112 PVMCPU pVCpu = (PVMCPU)pvUser;
113 void const *pv = (uint8_t const *)&pVCpu->cpum.s.Guest.XState + pDesc->offRegister;
114
115 VMCPU_ASSERT_EMT(pVCpu);
116
117 switch (pDesc->enmType)
118 {
119 case DBGFREGVALTYPE_U8: pValue->u8 = *(uint8_t const *)pv; return VINF_SUCCESS;
120 case DBGFREGVALTYPE_U16: pValue->u16 = *(uint16_t const *)pv; return VINF_SUCCESS;
121 case DBGFREGVALTYPE_U32: pValue->u32 = *(uint32_t const *)pv; return VINF_SUCCESS;
122 case DBGFREGVALTYPE_U64: pValue->u64 = *(uint64_t const *)pv; return VINF_SUCCESS;
123 case DBGFREGVALTYPE_U128: pValue->u128 = *(PCRTUINT128U )pv; return VINF_SUCCESS;
124 default:
125 AssertMsgFailedReturn(("%d %s\n", pDesc->enmType, pDesc->pszName), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
126 }
127}
128
129
130/**
131 * @interface_method_impl{DBGFREGDESC,pfnSet}
132 */
133static DECLCALLBACK(int) cpumR3RegSet_XStateGeneric(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
134{
135 PVMCPU pVCpu = (PVMCPU)pvUser;
136 void *pv = (uint8_t *)&pVCpu->cpum.s.Guest.XState + pDesc->offRegister;
137
138 VMCPU_ASSERT_EMT(pVCpu);
139
140 switch (pDesc->enmType)
141 {
142 case DBGFREGVALTYPE_U8:
143 *(uint8_t *)pv &= ~pfMask->u8;
144 *(uint8_t *)pv |= pValue->u8 & pfMask->u8;
145 return VINF_SUCCESS;
146
147 case DBGFREGVALTYPE_U16:
148 *(uint16_t *)pv &= ~pfMask->u16;
149 *(uint16_t *)pv |= pValue->u16 & pfMask->u16;
150 return VINF_SUCCESS;
151
152 case DBGFREGVALTYPE_U32:
153 *(uint32_t *)pv &= ~pfMask->u32;
154 *(uint32_t *)pv |= pValue->u32 & pfMask->u32;
155 return VINF_SUCCESS;
156
157 case DBGFREGVALTYPE_U64:
158 *(uint64_t *)pv &= ~pfMask->u64;
159 *(uint64_t *)pv |= pValue->u64 & pfMask->u64;
160 return VINF_SUCCESS;
161
162 case DBGFREGVALTYPE_U128:
163 {
164 RTUINT128U Val;
165 RTUInt128AssignAnd((PRTUINT128U)pv, RTUInt128AssignBitwiseNot(RTUInt128Assign(&Val, &pfMask->u128)));
166 RTUInt128AssignOr((PRTUINT128U)pv, RTUInt128AssignAnd(RTUInt128Assign(&Val, &pValue->u128), &pfMask->u128));
167 return VINF_SUCCESS;
168 }
169
170 default:
171 AssertMsgFailedReturn(("%d %s\n", pDesc->enmType, pDesc->pszName), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
172 }
173}
174
175
176
177/**
178 * @interface_method_impl{DBGFREGDESC,pfnGet}
179 */
180static DECLCALLBACK(int) cpumR3RegSet_seg(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
181{
182 /** @todo perform a selector load, updating hidden selectors and stuff. */
183 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
184 return VERR_NOT_IMPLEMENTED;
185}
186
187
188/**
189 * @interface_method_impl{DBGFREGDESC,pfnGet}
190 */
191static DECLCALLBACK(int) cpumR3RegGet_gdtr(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
192{
193 PVMCPU pVCpu = (PVMCPU)pvUser;
194 VBOXGDTR const *pGdtr = (VBOXGDTR const *)((uint8_t const *)&pVCpu->cpum + pDesc->offRegister);
195
196 VMCPU_ASSERT_EMT(pVCpu);
197 Assert(pDesc->enmType == DBGFREGVALTYPE_DTR);
198
199 pValue->dtr.u32Limit = pGdtr->cbGdt;
200 pValue->dtr.u64Base = pGdtr->pGdt;
201 return VINF_SUCCESS;
202}
203
204
205/**
206 * @interface_method_impl{DBGFREGDESC,pfnGet}
207 */
208static DECLCALLBACK(int) cpumR3RegSet_gdtr(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
209{
210 RT_NOREF(pfMask);
211
212 PVMCPU pVCpu = (PVMCPU)pvUser;
213 VBOXGDTR *pGdtr = (VBOXGDTR *)((uint8_t *)&pVCpu->cpum + pDesc->offRegister);
214
215 VMCPU_ASSERT_EMT(pVCpu);
216 Assert(pDesc->enmType == DBGFREGVALTYPE_DTR);
217
218 pGdtr->cbGdt = pValue->dtr.u32Limit;
219 pGdtr->pGdt = pValue->dtr.u64Base;
220 return VINF_SUCCESS;
221}
222
223
224/**
225 * @interface_method_impl{DBGFREGDESC,pfnGet}
226 */
227static DECLCALLBACK(int) cpumR3RegGet_idtr(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
228{
229 PVMCPU pVCpu = (PVMCPU)pvUser;
230 VBOXIDTR const *pIdtr = (VBOXIDTR const *)((uint8_t const *)&pVCpu->cpum + pDesc->offRegister);
231
232 VMCPU_ASSERT_EMT(pVCpu);
233 Assert(pDesc->enmType == DBGFREGVALTYPE_DTR);
234
235 pValue->dtr.u32Limit = pIdtr->cbIdt;
236 pValue->dtr.u64Base = pIdtr->pIdt;
237 return VINF_SUCCESS;
238}
239
240
241/**
242 * @interface_method_impl{DBGFREGDESC,pfnGet}
243 */
244static DECLCALLBACK(int) cpumR3RegSet_idtr(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
245{
246 RT_NOREF(pfMask);
247
248 PVMCPU pVCpu = (PVMCPU)pvUser;
249 VBOXIDTR *pIdtr = (VBOXIDTR *)((uint8_t *)&pVCpu->cpum + pDesc->offRegister);
250
251 VMCPU_ASSERT_EMT(pVCpu);
252 Assert(pDesc->enmType == DBGFREGVALTYPE_DTR);
253
254 pIdtr->cbIdt = pValue->dtr.u32Limit;
255 pIdtr->pIdt = pValue->dtr.u64Base;
256 return VINF_SUCCESS;
257}
258
259
260/**
261 * Determins the tag register value for a CPU register when the FPU state
262 * format is FXSAVE.
263 *
264 * @returns The tag register value.
265 * @param pFpu Pointer to the guest FPU.
266 * @param iReg The register number (0..7).
267 */
268DECLINLINE(uint16_t) cpumR3RegCalcFpuTagFromFxSave(PCX86FXSTATE pFpu, unsigned iReg)
269{
270 /*
271 * See table 11-1 in the AMD docs.
272 */
273 if (!(pFpu->FTW & RT_BIT_32(iReg)))
274 return 3; /* b11 - empty */
275
276 uint16_t const uExp = pFpu->aRegs[iReg].au16[4];
277 if (uExp == 0)
278 {
279 if (pFpu->aRegs[iReg].au64[0] == 0) /* J & M == 0 */
280 return 1; /* b01 - zero */
281 return 2; /* b10 - special */
282 }
283
284 if (uExp == UINT16_C(0xffff))
285 return 2; /* b10 - special */
286
287 if (!(pFpu->aRegs[iReg].au64[0] >> 63)) /* J == 0 */
288 return 2; /* b10 - special */
289
290 return 0; /* b00 - valid (normal) */
291}
292
293
294/**
295 * @interface_method_impl{DBGFREGDESC,pfnGet}
296 */
297static DECLCALLBACK(int) cpumR3RegGet_ftw(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
298{
299 PVMCPU pVCpu = (PVMCPU)pvUser;
300 PCX86FXSTATE pFpu = (PCX86FXSTATE)((uint8_t const *)&pVCpu->cpum + pDesc->offRegister);
301
302 VMCPU_ASSERT_EMT(pVCpu);
303 Assert(pDesc->enmType == DBGFREGVALTYPE_U16);
304
305 pValue->u16 = cpumR3RegCalcFpuTagFromFxSave(pFpu, 0)
306 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 1) << 2)
307 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 2) << 4)
308 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 3) << 6)
309 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 4) << 8)
310 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 5) << 10)
311 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 6) << 12)
312 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 7) << 14);
313 return VINF_SUCCESS;
314}
315
316
317/**
318 * @interface_method_impl{DBGFREGDESC,pfnGet}
319 */
320static DECLCALLBACK(int) cpumR3RegSet_ftw(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
321{
322 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
323 return VERR_DBGF_READ_ONLY_REGISTER;
324}
325
326#if 0 /* unused */
327
328/**
329 * @interface_method_impl{DBGFREGDESC,pfnGet}
330 */
331static DECLCALLBACK(int) cpumR3RegGet_Dummy(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
332{
333 RT_NOREF_PV(pvUser);
334 switch (pDesc->enmType)
335 {
336 case DBGFREGVALTYPE_U8: pValue->u8 = 0; return VINF_SUCCESS;
337 case DBGFREGVALTYPE_U16: pValue->u16 = 0; return VINF_SUCCESS;
338 case DBGFREGVALTYPE_U32: pValue->u32 = 0; return VINF_SUCCESS;
339 case DBGFREGVALTYPE_U64: pValue->u64 = 0; return VINF_SUCCESS;
340 case DBGFREGVALTYPE_U128:
341 RT_ZERO(pValue->u128);
342 return VINF_SUCCESS;
343 case DBGFREGVALTYPE_DTR:
344 pValue->dtr.u32Limit = 0;
345 pValue->dtr.u64Base = 0;
346 return VINF_SUCCESS;
347 case DBGFREGVALTYPE_R80:
348 RT_ZERO(pValue->r80Ex);
349 return VINF_SUCCESS;
350 default:
351 AssertMsgFailedReturn(("%d %s\n", pDesc->enmType, pDesc->pszName), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
352 }
353}
354
355
356/**
357 * @interface_method_impl{DBGFREGDESC,pfnSet}
358 */
359static DECLCALLBACK(int) cpumR3RegSet_Dummy(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
360{
361 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
362 return VERR_DBGF_READ_ONLY_REGISTER;
363}
364
365#endif /* unused */
366
367/**
368 * @interface_method_impl{DBGFREGDESC,pfnGet}
369 */
370static DECLCALLBACK(int) cpumR3RegGet_ymm(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
371{
372 PVMCPU pVCpu = (PVMCPU)pvUser;
373 uint32_t iReg = pDesc->offRegister;
374
375 Assert(pDesc->enmType == DBGFREGVALTYPE_U256);
376 VMCPU_ASSERT_EMT(pVCpu);
377
378 if (iReg < 16)
379 {
380 pValue->u256.DQWords.dqw0 = pVCpu->cpum.s.Guest.XState.x87.aXMM[iReg].uXmm;
381 pValue->u256.DQWords.dqw1 = pVCpu->cpum.s.Guest.XState.u.YmmHi.aYmmHi[iReg].uXmm;
382 return VINF_SUCCESS;
383 }
384 return VERR_NOT_IMPLEMENTED;
385}
386
387
388/**
389 * @interface_method_impl{DBGFREGDESC,pfnSet}
390 */
391static DECLCALLBACK(int) cpumR3RegSet_ymm(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
392{
393 PVMCPU pVCpu = (PVMCPU)pvUser;
394 uint32_t iReg = pDesc->offRegister;
395
396 Assert(pDesc->enmType == DBGFREGVALTYPE_U256);
397 VMCPU_ASSERT_EMT(pVCpu);
398
399 if (iReg < 16)
400 {
401 RTUINT128U Val;
402 RTUInt128AssignAnd(&pVCpu->cpum.s.Guest.XState.x87.aXMM[iReg].uXmm,
403 RTUInt128AssignBitwiseNot(RTUInt128Assign(&Val, &pfMask->u256.DQWords.dqw0)));
404 RTUInt128AssignOr(&pVCpu->cpum.s.Guest.XState.u.YmmHi.aYmmHi[iReg].uXmm,
405 RTUInt128AssignAnd(RTUInt128Assign(&Val, &pValue->u128), &pfMask->u128));
406
407 }
408 return VERR_NOT_IMPLEMENTED;
409}
410
411
412/*
413 *
414 * Guest register access functions.
415 *
416 */
417
418/**
419 * @interface_method_impl{DBGFREGDESC,pfnGet}
420 */
421static DECLCALLBACK(int) cpumR3RegGstGet_crX(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
422{
423 PVMCPU pVCpu = (PVMCPU)pvUser;
424 VMCPU_ASSERT_EMT(pVCpu);
425
426 uint64_t u64Value;
427 int rc = CPUMGetGuestCRx(pVCpu, pDesc->offRegister, &u64Value);
428 if (rc == VERR_PDM_NO_APIC_INSTANCE) /* CR8 might not be available, see @bugref{8868}.*/
429 u64Value = 0;
430 else
431 AssertRCReturn(rc, rc);
432 switch (pDesc->enmType)
433 {
434 case DBGFREGVALTYPE_U64: pValue->u64 = u64Value; break;
435 case DBGFREGVALTYPE_U32: pValue->u32 = (uint32_t)u64Value; break;
436 default:
437 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
438 }
439 return VINF_SUCCESS;
440}
441
442
443/**
444 * @interface_method_impl{DBGFREGDESC,pfnGet}
445 */
446static DECLCALLBACK(int) cpumR3RegGstSet_crX(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
447{
448 int rc;
449 PVMCPU pVCpu = (PVMCPU)pvUser;
450
451 VMCPU_ASSERT_EMT(pVCpu);
452
453 /*
454 * Calculate the new value.
455 */
456 uint64_t u64Value;
457 uint64_t fMask;
458 uint64_t fMaskMax;
459 switch (pDesc->enmType)
460 {
461 case DBGFREGVALTYPE_U64:
462 u64Value = pValue->u64;
463 fMask = pfMask->u64;
464 fMaskMax = UINT64_MAX;
465 break;
466 case DBGFREGVALTYPE_U32:
467 u64Value = pValue->u32;
468 fMask = pfMask->u32;
469 fMaskMax = UINT32_MAX;
470 break;
471 default:
472 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
473 }
474 if (fMask != fMaskMax)
475 {
476 uint64_t u64FullValue;
477 rc = CPUMGetGuestCRx(pVCpu, pDesc->offRegister, &u64FullValue);
478 if (RT_FAILURE(rc))
479 return rc;
480 u64Value = (u64FullValue & ~fMask)
481 | (u64Value & fMask);
482 }
483
484 /*
485 * Perform the assignment.
486 */
487 switch (pDesc->offRegister)
488 {
489 case 0: rc = CPUMSetGuestCR0(pVCpu, u64Value); break;
490 case 2: rc = CPUMSetGuestCR2(pVCpu, u64Value); break;
491 case 3: rc = CPUMSetGuestCR3(pVCpu, u64Value); break;
492 case 4: rc = CPUMSetGuestCR4(pVCpu, u64Value); break;
493 case 8: rc = APICSetTpr(pVCpu, (uint8_t)(u64Value << 4)); break;
494 default:
495 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
496 }
497 return rc;
498}
499
500
501/**
502 * @interface_method_impl{DBGFREGDESC,pfnGet}
503 */
504static DECLCALLBACK(int) cpumR3RegGstGet_drX(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
505{
506 PVMCPU pVCpu = (PVMCPU)pvUser;
507 VMCPU_ASSERT_EMT(pVCpu);
508
509 uint64_t u64Value;
510 int rc = CPUMGetGuestDRx(pVCpu, pDesc->offRegister, &u64Value);
511 AssertRCReturn(rc, rc);
512 switch (pDesc->enmType)
513 {
514 case DBGFREGVALTYPE_U64: pValue->u64 = u64Value; break;
515 case DBGFREGVALTYPE_U32: pValue->u32 = (uint32_t)u64Value; break;
516 default:
517 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
518 }
519 return VINF_SUCCESS;
520}
521
522
523/**
524 * @interface_method_impl{DBGFREGDESC,pfnGet}
525 */
526static DECLCALLBACK(int) cpumR3RegGstSet_drX(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
527{
528 int rc;
529 PVMCPU pVCpu = (PVMCPU)pvUser;
530
531 VMCPU_ASSERT_EMT(pVCpu);
532
533 /*
534 * Calculate the new value.
535 */
536 uint64_t u64Value;
537 uint64_t fMask;
538 uint64_t fMaskMax;
539 switch (pDesc->enmType)
540 {
541 case DBGFREGVALTYPE_U64:
542 u64Value = pValue->u64;
543 fMask = pfMask->u64;
544 fMaskMax = UINT64_MAX;
545 break;
546 case DBGFREGVALTYPE_U32:
547 u64Value = pValue->u32;
548 fMask = pfMask->u32;
549 fMaskMax = UINT32_MAX;
550 break;
551 default:
552 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
553 }
554 if (fMask != fMaskMax)
555 {
556 uint64_t u64FullValue;
557 rc = CPUMGetGuestDRx(pVCpu, pDesc->offRegister, &u64FullValue);
558 if (RT_FAILURE(rc))
559 return rc;
560 u64Value = (u64FullValue & ~fMask)
561 | (u64Value & fMask);
562 }
563
564 /*
565 * Perform the assignment.
566 */
567 return CPUMSetGuestDRx(pVCpu, pDesc->offRegister, u64Value);
568}
569
570
571/**
572 * @interface_method_impl{DBGFREGDESC,pfnGet}
573 */
574static DECLCALLBACK(int) cpumR3RegGstGet_msr(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
575{
576 PVMCPU pVCpu = (PVMCPU)pvUser;
577 VMCPU_ASSERT_EMT(pVCpu);
578
579 uint64_t u64Value;
580 VBOXSTRICTRC rcStrict = CPUMQueryGuestMsr(pVCpu, pDesc->offRegister, &u64Value);
581 if (rcStrict == VINF_SUCCESS)
582 {
583 switch (pDesc->enmType)
584 {
585 case DBGFREGVALTYPE_U64: pValue->u64 = u64Value; break;
586 case DBGFREGVALTYPE_U32: pValue->u32 = (uint32_t)u64Value; break;
587 case DBGFREGVALTYPE_U16: pValue->u16 = (uint16_t)u64Value; break;
588 default:
589 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
590 }
591 return VBOXSTRICTRC_VAL(rcStrict);
592 }
593
594 /** @todo what to do about errors? */
595 Assert(RT_FAILURE_NP(rcStrict));
596 return VBOXSTRICTRC_VAL(rcStrict);
597}
598
599
600/**
601 * @interface_method_impl{DBGFREGDESC,pfnGet}
602 */
603static DECLCALLBACK(int) cpumR3RegGstSet_msr(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
604{
605 PVMCPU pVCpu = (PVMCPU)pvUser;
606
607 VMCPU_ASSERT_EMT(pVCpu);
608
609 /*
610 * Calculate the new value.
611 */
612 uint64_t u64Value;
613 uint64_t fMask;
614 uint64_t fMaskMax;
615 switch (pDesc->enmType)
616 {
617 case DBGFREGVALTYPE_U64:
618 u64Value = pValue->u64;
619 fMask = pfMask->u64;
620 fMaskMax = UINT64_MAX;
621 break;
622 case DBGFREGVALTYPE_U32:
623 u64Value = pValue->u32;
624 fMask = pfMask->u32;
625 fMaskMax = UINT32_MAX;
626 break;
627 case DBGFREGVALTYPE_U16:
628 u64Value = pValue->u16;
629 fMask = pfMask->u16;
630 fMaskMax = UINT16_MAX;
631 break;
632 default:
633 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
634 }
635 if (fMask != fMaskMax)
636 {
637 uint64_t u64FullValue;
638 VBOXSTRICTRC rcStrict = CPUMQueryGuestMsr(pVCpu, pDesc->offRegister, &u64FullValue);
639 if (rcStrict != VINF_SUCCESS)
640 {
641 AssertRC(RT_FAILURE_NP(rcStrict));
642 return VBOXSTRICTRC_VAL(rcStrict);
643 }
644 u64Value = (u64FullValue & ~fMask)
645 | (u64Value & fMask);
646 }
647
648 /*
649 * Perform the assignment.
650 */
651 VBOXSTRICTRC rcStrict = CPUMSetGuestMsr(pVCpu, pDesc->offRegister, u64Value);
652 if (rcStrict == VINF_SUCCESS)
653 return VINF_SUCCESS;
654 AssertRC(RT_FAILURE_NP(rcStrict));
655 return VBOXSTRICTRC_VAL(rcStrict);
656}
657
658
659/**
660 * @interface_method_impl{DBGFREGDESC,pfnGet}
661 */
662static DECLCALLBACK(int) cpumR3RegGstGet_stN(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
663{
664 PVMCPU pVCpu = (PVMCPU)pvUser;
665 VMCPU_ASSERT_EMT(pVCpu);
666 Assert(pDesc->enmType == DBGFREGVALTYPE_R80);
667
668 PX86FXSTATE pFpuCtx = &pVCpu->cpum.s.Guest.XState.x87;
669 unsigned iReg = (pFpuCtx->FSW >> 11) & 7;
670 iReg += pDesc->offRegister;
671 iReg &= 7;
672 pValue->r80Ex = pFpuCtx->aRegs[iReg].r80Ex;
673
674 return VINF_SUCCESS;
675}
676
677
678/**
679 * @interface_method_impl{DBGFREGDESC,pfnGet}
680 */
681static DECLCALLBACK(int) cpumR3RegGstSet_stN(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
682{
683 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
684 return VERR_NOT_IMPLEMENTED;
685}
686
687
688
689/*
690 * Set up aliases.
691 */
692#define CPUMREGALIAS_STD(Name, psz32, psz16, psz8) \
693 static DBGFREGALIAS const g_aCpumRegAliases_##Name[] = \
694 { \
695 { psz32, DBGFREGVALTYPE_U32 }, \
696 { psz16, DBGFREGVALTYPE_U16 }, \
697 { psz8, DBGFREGVALTYPE_U8 }, \
698 { NULL, DBGFREGVALTYPE_INVALID } \
699 }
700CPUMREGALIAS_STD(rax, "eax", "ax", "al");
701CPUMREGALIAS_STD(rcx, "ecx", "cx", "cl");
702CPUMREGALIAS_STD(rdx, "edx", "dx", "dl");
703CPUMREGALIAS_STD(rbx, "ebx", "bx", "bl");
704CPUMREGALIAS_STD(rsp, "esp", "sp", NULL);
705CPUMREGALIAS_STD(rbp, "ebp", "bp", NULL);
706CPUMREGALIAS_STD(rsi, "esi", "si", "sil");
707CPUMREGALIAS_STD(rdi, "edi", "di", "dil");
708CPUMREGALIAS_STD(r8, "r8d", "r8w", "r8b");
709CPUMREGALIAS_STD(r9, "r9d", "r9w", "r9b");
710CPUMREGALIAS_STD(r10, "r10d", "r10w", "r10b");
711CPUMREGALIAS_STD(r11, "r11d", "r11w", "r11b");
712CPUMREGALIAS_STD(r12, "r12d", "r12w", "r12b");
713CPUMREGALIAS_STD(r13, "r13d", "r13w", "r13b");
714CPUMREGALIAS_STD(r14, "r14d", "r14w", "r14b");
715CPUMREGALIAS_STD(r15, "r15d", "r15w", "r15b");
716CPUMREGALIAS_STD(rip, "eip", "ip", NULL);
717CPUMREGALIAS_STD(rflags, "eflags", "flags", NULL);
718#undef CPUMREGALIAS_STD
719
720static DBGFREGALIAS const g_aCpumRegAliases_fpuip[] =
721{
722 { "fpuip16", DBGFREGVALTYPE_U16 },
723 { NULL, DBGFREGVALTYPE_INVALID }
724};
725
726static DBGFREGALIAS const g_aCpumRegAliases_fpudp[] =
727{
728 { "fpudp16", DBGFREGVALTYPE_U16 },
729 { NULL, DBGFREGVALTYPE_INVALID }
730};
731
732static DBGFREGALIAS const g_aCpumRegAliases_cr0[] =
733{
734 { "msw", DBGFREGVALTYPE_U16 },
735 { NULL, DBGFREGVALTYPE_INVALID }
736};
737
738/*
739 * Sub fields.
740 */
741/** Sub-fields for the (hidden) segment attribute register. */
742static DBGFREGSUBFIELD const g_aCpumRegFields_seg[] =
743{
744 DBGFREGSUBFIELD_RW("type", 0, 4, 0),
745 DBGFREGSUBFIELD_RW("s", 4, 1, 0),
746 DBGFREGSUBFIELD_RW("dpl", 5, 2, 0),
747 DBGFREGSUBFIELD_RW("p", 7, 1, 0),
748 DBGFREGSUBFIELD_RW("avl", 12, 1, 0),
749 DBGFREGSUBFIELD_RW("l", 13, 1, 0),
750 DBGFREGSUBFIELD_RW("d", 14, 1, 0),
751 DBGFREGSUBFIELD_RW("g", 15, 1, 0),
752 DBGFREGSUBFIELD_TERMINATOR()
753};
754
755/** Sub-fields for the flags register. */
756static DBGFREGSUBFIELD const g_aCpumRegFields_rflags[] =
757{
758 DBGFREGSUBFIELD_RW("cf", 0, 1, 0),
759 DBGFREGSUBFIELD_RW("pf", 2, 1, 0),
760 DBGFREGSUBFIELD_RW("af", 4, 1, 0),
761 DBGFREGSUBFIELD_RW("zf", 6, 1, 0),
762 DBGFREGSUBFIELD_RW("sf", 7, 1, 0),
763 DBGFREGSUBFIELD_RW("tf", 8, 1, 0),
764 DBGFREGSUBFIELD_RW("if", 9, 1, 0),
765 DBGFREGSUBFIELD_RW("df", 10, 1, 0),
766 DBGFREGSUBFIELD_RW("of", 11, 1, 0),
767 DBGFREGSUBFIELD_RW("iopl", 12, 2, 0),
768 DBGFREGSUBFIELD_RW("nt", 14, 1, 0),
769 DBGFREGSUBFIELD_RW("rf", 16, 1, 0),
770 DBGFREGSUBFIELD_RW("vm", 17, 1, 0),
771 DBGFREGSUBFIELD_RW("ac", 18, 1, 0),
772 DBGFREGSUBFIELD_RW("vif", 19, 1, 0),
773 DBGFREGSUBFIELD_RW("vip", 20, 1, 0),
774 DBGFREGSUBFIELD_RW("id", 21, 1, 0),
775 DBGFREGSUBFIELD_TERMINATOR()
776};
777
778/** Sub-fields for the FPU control word register. */
779static DBGFREGSUBFIELD const g_aCpumRegFields_fcw[] =
780{
781 DBGFREGSUBFIELD_RW("im", 1, 1, 0),
782 DBGFREGSUBFIELD_RW("dm", 2, 1, 0),
783 DBGFREGSUBFIELD_RW("zm", 3, 1, 0),
784 DBGFREGSUBFIELD_RW("om", 4, 1, 0),
785 DBGFREGSUBFIELD_RW("um", 5, 1, 0),
786 DBGFREGSUBFIELD_RW("pm", 6, 1, 0),
787 DBGFREGSUBFIELD_RW("pc", 8, 2, 0),
788 DBGFREGSUBFIELD_RW("rc", 10, 2, 0),
789 DBGFREGSUBFIELD_RW("x", 12, 1, 0),
790 DBGFREGSUBFIELD_TERMINATOR()
791};
792
793/** Sub-fields for the FPU status word register. */
794static DBGFREGSUBFIELD const g_aCpumRegFields_fsw[] =
795{
796 DBGFREGSUBFIELD_RW("ie", 0, 1, 0),
797 DBGFREGSUBFIELD_RW("de", 1, 1, 0),
798 DBGFREGSUBFIELD_RW("ze", 2, 1, 0),
799 DBGFREGSUBFIELD_RW("oe", 3, 1, 0),
800 DBGFREGSUBFIELD_RW("ue", 4, 1, 0),
801 DBGFREGSUBFIELD_RW("pe", 5, 1, 0),
802 DBGFREGSUBFIELD_RW("se", 6, 1, 0),
803 DBGFREGSUBFIELD_RW("es", 7, 1, 0),
804 DBGFREGSUBFIELD_RW("c0", 8, 1, 0),
805 DBGFREGSUBFIELD_RW("c1", 9, 1, 0),
806 DBGFREGSUBFIELD_RW("c2", 10, 1, 0),
807 DBGFREGSUBFIELD_RW("top", 11, 3, 0),
808 DBGFREGSUBFIELD_RW("c3", 14, 1, 0),
809 DBGFREGSUBFIELD_RW("b", 15, 1, 0),
810 DBGFREGSUBFIELD_TERMINATOR()
811};
812
813/** Sub-fields for the FPU tag word register. */
814static DBGFREGSUBFIELD const g_aCpumRegFields_ftw[] =
815{
816 DBGFREGSUBFIELD_RW("tag0", 0, 2, 0),
817 DBGFREGSUBFIELD_RW("tag1", 2, 2, 0),
818 DBGFREGSUBFIELD_RW("tag2", 4, 2, 0),
819 DBGFREGSUBFIELD_RW("tag3", 6, 2, 0),
820 DBGFREGSUBFIELD_RW("tag4", 8, 2, 0),
821 DBGFREGSUBFIELD_RW("tag5", 10, 2, 0),
822 DBGFREGSUBFIELD_RW("tag6", 12, 2, 0),
823 DBGFREGSUBFIELD_RW("tag7", 14, 2, 0),
824 DBGFREGSUBFIELD_TERMINATOR()
825};
826
827/** Sub-fields for the Multimedia Extensions Control and Status Register. */
828static DBGFREGSUBFIELD const g_aCpumRegFields_mxcsr[] =
829{
830 DBGFREGSUBFIELD_RW("ie", 0, 1, 0),
831 DBGFREGSUBFIELD_RW("de", 1, 1, 0),
832 DBGFREGSUBFIELD_RW("ze", 2, 1, 0),
833 DBGFREGSUBFIELD_RW("oe", 3, 1, 0),
834 DBGFREGSUBFIELD_RW("ue", 4, 1, 0),
835 DBGFREGSUBFIELD_RW("pe", 5, 1, 0),
836 DBGFREGSUBFIELD_RW("daz", 6, 1, 0),
837 DBGFREGSUBFIELD_RW("im", 7, 1, 0),
838 DBGFREGSUBFIELD_RW("dm", 8, 1, 0),
839 DBGFREGSUBFIELD_RW("zm", 9, 1, 0),
840 DBGFREGSUBFIELD_RW("om", 10, 1, 0),
841 DBGFREGSUBFIELD_RW("um", 11, 1, 0),
842 DBGFREGSUBFIELD_RW("pm", 12, 1, 0),
843 DBGFREGSUBFIELD_RW("rc", 13, 2, 0),
844 DBGFREGSUBFIELD_RW("fz", 14, 1, 0),
845 DBGFREGSUBFIELD_TERMINATOR()
846};
847
848/** Sub-fields for the FPU tag word register. */
849static DBGFREGSUBFIELD const g_aCpumRegFields_stN[] =
850{
851 DBGFREGSUBFIELD_RW("man", 0, 64, 0),
852 DBGFREGSUBFIELD_RW("exp", 64, 15, 0),
853 DBGFREGSUBFIELD_RW("sig", 79, 1, 0),
854 DBGFREGSUBFIELD_TERMINATOR()
855};
856
857/** Sub-fields for the MMX registers. */
858static DBGFREGSUBFIELD const g_aCpumRegFields_mmN[] =
859{
860 DBGFREGSUBFIELD_RW("dw0", 0, 32, 0),
861 DBGFREGSUBFIELD_RW("dw1", 32, 32, 0),
862 DBGFREGSUBFIELD_RW("w0", 0, 16, 0),
863 DBGFREGSUBFIELD_RW("w1", 16, 16, 0),
864 DBGFREGSUBFIELD_RW("w2", 32, 16, 0),
865 DBGFREGSUBFIELD_RW("w3", 48, 16, 0),
866 DBGFREGSUBFIELD_RW("b0", 0, 8, 0),
867 DBGFREGSUBFIELD_RW("b1", 8, 8, 0),
868 DBGFREGSUBFIELD_RW("b2", 16, 8, 0),
869 DBGFREGSUBFIELD_RW("b3", 24, 8, 0),
870 DBGFREGSUBFIELD_RW("b4", 32, 8, 0),
871 DBGFREGSUBFIELD_RW("b5", 40, 8, 0),
872 DBGFREGSUBFIELD_RW("b6", 48, 8, 0),
873 DBGFREGSUBFIELD_RW("b7", 56, 8, 0),
874 DBGFREGSUBFIELD_TERMINATOR()
875};
876
877/** Sub-fields for the XMM registers. */
878static DBGFREGSUBFIELD const g_aCpumRegFields_xmmN[] =
879{
880 DBGFREGSUBFIELD_RW("r0", 0, 32, 0),
881 DBGFREGSUBFIELD_RW("r0.man", 0+ 0, 23, 0),
882 DBGFREGSUBFIELD_RW("r0.exp", 0+23, 8, 0),
883 DBGFREGSUBFIELD_RW("r0.sig", 0+31, 1, 0),
884 DBGFREGSUBFIELD_RW("r1", 32, 32, 0),
885 DBGFREGSUBFIELD_RW("r1.man", 32+ 0, 23, 0),
886 DBGFREGSUBFIELD_RW("r1.exp", 32+23, 8, 0),
887 DBGFREGSUBFIELD_RW("r1.sig", 32+31, 1, 0),
888 DBGFREGSUBFIELD_RW("r2", 64, 32, 0),
889 DBGFREGSUBFIELD_RW("r2.man", 64+ 0, 23, 0),
890 DBGFREGSUBFIELD_RW("r2.exp", 64+23, 8, 0),
891 DBGFREGSUBFIELD_RW("r2.sig", 64+31, 1, 0),
892 DBGFREGSUBFIELD_RW("r3", 96, 32, 0),
893 DBGFREGSUBFIELD_RW("r3.man", 96+ 0, 23, 0),
894 DBGFREGSUBFIELD_RW("r3.exp", 96+23, 8, 0),
895 DBGFREGSUBFIELD_RW("r3.sig", 96+31, 1, 0),
896 DBGFREGSUBFIELD_TERMINATOR()
897};
898
899#if 0 /* needs special accessor, too lazy for that now. */
900/** Sub-fields for the YMM registers. */
901static DBGFREGSUBFIELD const g_aCpumRegFields_ymmN[] =
902{
903 DBGFREGSUBFIELD_RW("r0", 0, 32, 0),
904 DBGFREGSUBFIELD_RW("r0.man", 0+ 0, 23, 0),
905 DBGFREGSUBFIELD_RW("r0.exp", 0+23, 8, 0),
906 DBGFREGSUBFIELD_RW("r0.sig", 0+31, 1, 0),
907 DBGFREGSUBFIELD_RW("r1", 32, 32, 0),
908 DBGFREGSUBFIELD_RW("r1.man", 32+ 0, 23, 0),
909 DBGFREGSUBFIELD_RW("r1.exp", 32+23, 8, 0),
910 DBGFREGSUBFIELD_RW("r1.sig", 32+31, 1, 0),
911 DBGFREGSUBFIELD_RW("r2", 64, 32, 0),
912 DBGFREGSUBFIELD_RW("r2.man", 64+ 0, 23, 0),
913 DBGFREGSUBFIELD_RW("r2.exp", 64+23, 8, 0),
914 DBGFREGSUBFIELD_RW("r2.sig", 64+31, 1, 0),
915 DBGFREGSUBFIELD_RW("r3", 96, 32, 0),
916 DBGFREGSUBFIELD_RW("r3.man", 96+ 0, 23, 0),
917 DBGFREGSUBFIELD_RW("r3.exp", 96+23, 8, 0),
918 DBGFREGSUBFIELD_RW("r3.sig", 96+31, 1, 0),
919 DBGFREGSUBFIELD_RW("r4", 128, 32, 0),
920 DBGFREGSUBFIELD_RW("r4.man", 128+ 0, 23, 0),
921 DBGFREGSUBFIELD_RW("r4.exp", 128+23, 8, 0),
922 DBGFREGSUBFIELD_RW("r4.sig", 128+31, 1, 0),
923 DBGFREGSUBFIELD_RW("r5", 160, 32, 0),
924 DBGFREGSUBFIELD_RW("r5.man", 160+ 0, 23, 0),
925 DBGFREGSUBFIELD_RW("r5.exp", 160+23, 8, 0),
926 DBGFREGSUBFIELD_RW("r5.sig", 160+31, 1, 0),
927 DBGFREGSUBFIELD_RW("r6", 192, 32, 0),
928 DBGFREGSUBFIELD_RW("r6.man", 192+ 0, 23, 0),
929 DBGFREGSUBFIELD_RW("r6.exp", 192+23, 8, 0),
930 DBGFREGSUBFIELD_RW("r6.sig", 192+31, 1, 0),
931 DBGFREGSUBFIELD_RW("r7", 224, 32, 0),
932 DBGFREGSUBFIELD_RW("r7.man", 224+ 0, 23, 0),
933 DBGFREGSUBFIELD_RW("r7.exp", 224+23, 8, 0),
934 DBGFREGSUBFIELD_RW("r7.sig", 224+31, 1, 0),
935 DBGFREGSUBFIELD_TERMINATOR()
936};
937#endif
938
939/** Sub-fields for the CR0 register. */
940static DBGFREGSUBFIELD const g_aCpumRegFields_cr0[] =
941{
942 DBGFREGSUBFIELD_RW("pe", 0, 1, 0),
943 DBGFREGSUBFIELD_RW("mp", 1, 1, 0),
944 DBGFREGSUBFIELD_RW("em", 2, 1, 0),
945 DBGFREGSUBFIELD_RW("ts", 3, 1, 0),
946 DBGFREGSUBFIELD_RO("et", 4, 1, 0),
947 DBGFREGSUBFIELD_RW("ne", 5, 1, 0),
948 DBGFREGSUBFIELD_RW("wp", 16, 1, 0),
949 DBGFREGSUBFIELD_RW("am", 18, 1, 0),
950 DBGFREGSUBFIELD_RW("nw", 29, 1, 0),
951 DBGFREGSUBFIELD_RW("cd", 30, 1, 0),
952 DBGFREGSUBFIELD_RW("pg", 31, 1, 0),
953 DBGFREGSUBFIELD_TERMINATOR()
954};
955
956/** Sub-fields for the CR3 register. */
957static DBGFREGSUBFIELD const g_aCpumRegFields_cr3[] =
958{
959 DBGFREGSUBFIELD_RW("pwt", 3, 1, 0),
960 DBGFREGSUBFIELD_RW("pcd", 4, 1, 0),
961 DBGFREGSUBFIELD_TERMINATOR()
962};
963
964/** Sub-fields for the CR4 register. */
965static DBGFREGSUBFIELD const g_aCpumRegFields_cr4[] =
966{
967 DBGFREGSUBFIELD_RW("vme", 0, 1, 0),
968 DBGFREGSUBFIELD_RW("pvi", 1, 1, 0),
969 DBGFREGSUBFIELD_RW("tsd", 2, 1, 0),
970 DBGFREGSUBFIELD_RW("de", 3, 1, 0),
971 DBGFREGSUBFIELD_RW("pse", 4, 1, 0),
972 DBGFREGSUBFIELD_RW("pae", 5, 1, 0),
973 DBGFREGSUBFIELD_RW("mce", 6, 1, 0),
974 DBGFREGSUBFIELD_RW("pge", 7, 1, 0),
975 DBGFREGSUBFIELD_RW("pce", 8, 1, 0),
976 DBGFREGSUBFIELD_RW("osfxsr", 9, 1, 0),
977 DBGFREGSUBFIELD_RW("osxmmeexcpt", 10, 1, 0),
978 DBGFREGSUBFIELD_RW("vmxe", 13, 1, 0),
979 DBGFREGSUBFIELD_RW("smxe", 14, 1, 0),
980 DBGFREGSUBFIELD_RW("pcide", 17, 1, 0),
981 DBGFREGSUBFIELD_RW("osxsave", 18, 1, 0),
982 DBGFREGSUBFIELD_RW("smep", 20, 1, 0),
983 DBGFREGSUBFIELD_RW("smap", 21, 1, 0),
984 DBGFREGSUBFIELD_TERMINATOR()
985};
986
987/** Sub-fields for the DR6 register. */
988static DBGFREGSUBFIELD const g_aCpumRegFields_dr6[] =
989{
990 DBGFREGSUBFIELD_RW("b0", 0, 1, 0),
991 DBGFREGSUBFIELD_RW("b1", 1, 1, 0),
992 DBGFREGSUBFIELD_RW("b2", 2, 1, 0),
993 DBGFREGSUBFIELD_RW("b3", 3, 1, 0),
994 DBGFREGSUBFIELD_RW("bd", 13, 1, 0),
995 DBGFREGSUBFIELD_RW("bs", 14, 1, 0),
996 DBGFREGSUBFIELD_RW("bt", 15, 1, 0),
997 DBGFREGSUBFIELD_TERMINATOR()
998};
999
1000/** Sub-fields for the DR7 register. */
1001static DBGFREGSUBFIELD const g_aCpumRegFields_dr7[] =
1002{
1003 DBGFREGSUBFIELD_RW("l0", 0, 1, 0),
1004 DBGFREGSUBFIELD_RW("g0", 1, 1, 0),
1005 DBGFREGSUBFIELD_RW("l1", 2, 1, 0),
1006 DBGFREGSUBFIELD_RW("g1", 3, 1, 0),
1007 DBGFREGSUBFIELD_RW("l2", 4, 1, 0),
1008 DBGFREGSUBFIELD_RW("g2", 5, 1, 0),
1009 DBGFREGSUBFIELD_RW("l3", 6, 1, 0),
1010 DBGFREGSUBFIELD_RW("g3", 7, 1, 0),
1011 DBGFREGSUBFIELD_RW("le", 8, 1, 0),
1012 DBGFREGSUBFIELD_RW("ge", 9, 1, 0),
1013 DBGFREGSUBFIELD_RW("gd", 13, 1, 0),
1014 DBGFREGSUBFIELD_RW("rw0", 16, 2, 0),
1015 DBGFREGSUBFIELD_RW("len0", 18, 2, 0),
1016 DBGFREGSUBFIELD_RW("rw1", 20, 2, 0),
1017 DBGFREGSUBFIELD_RW("len1", 22, 2, 0),
1018 DBGFREGSUBFIELD_RW("rw2", 24, 2, 0),
1019 DBGFREGSUBFIELD_RW("len2", 26, 2, 0),
1020 DBGFREGSUBFIELD_RW("rw3", 28, 2, 0),
1021 DBGFREGSUBFIELD_RW("len3", 30, 2, 0),
1022 DBGFREGSUBFIELD_TERMINATOR()
1023};
1024
1025/** Sub-fields for the CR_PAT MSR. */
1026static DBGFREGSUBFIELD const g_aCpumRegFields_apic_base[] =
1027{
1028 DBGFREGSUBFIELD_RW("bsp", 8, 1, 0),
1029 DBGFREGSUBFIELD_RW("ge", 9, 1, 0),
1030 DBGFREGSUBFIELD_RW("base", 12, 20, 12),
1031 DBGFREGSUBFIELD_TERMINATOR()
1032};
1033
1034/** Sub-fields for the CR_PAT MSR. */
1035static DBGFREGSUBFIELD const g_aCpumRegFields_cr_pat[] =
1036{
1037 /** @todo */
1038 DBGFREGSUBFIELD_TERMINATOR()
1039};
1040
1041/** Sub-fields for the PERF_STATUS MSR. */
1042static DBGFREGSUBFIELD const g_aCpumRegFields_perf_status[] =
1043{
1044 /** @todo */
1045 DBGFREGSUBFIELD_TERMINATOR()
1046};
1047
1048/** Sub-fields for the EFER MSR. */
1049static DBGFREGSUBFIELD const g_aCpumRegFields_efer[] =
1050{
1051 /** @todo */
1052 DBGFREGSUBFIELD_TERMINATOR()
1053};
1054
1055/** Sub-fields for the STAR MSR. */
1056static DBGFREGSUBFIELD const g_aCpumRegFields_star[] =
1057{
1058 /** @todo */
1059 DBGFREGSUBFIELD_TERMINATOR()
1060};
1061
1062/** Sub-fields for the CSTAR MSR. */
1063static DBGFREGSUBFIELD const g_aCpumRegFields_cstar[] =
1064{
1065 /** @todo */
1066 DBGFREGSUBFIELD_TERMINATOR()
1067};
1068
1069/** Sub-fields for the LSTAR MSR. */
1070static DBGFREGSUBFIELD const g_aCpumRegFields_lstar[] =
1071{
1072 /** @todo */
1073 DBGFREGSUBFIELD_TERMINATOR()
1074};
1075
1076#if 0 /** @todo */
1077/** Sub-fields for the SF_MASK MSR. */
1078static DBGFREGSUBFIELD const g_aCpumRegFields_sf_mask[] =
1079{
1080 /** @todo */
1081 DBGFREGSUBFIELD_TERMINATOR()
1082};
1083#endif
1084
1085
1086/** @name Macros for producing register descriptor table entries.
1087 * @{ */
1088#define CPU_REG_EX_AS(a_szName, a_RegSuff, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1089 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1090
1091#define CPU_REG_REG(UName, LName) \
1092 CPU_REG_RW_AS(#LName, UName, U64, LName, cpumR3RegGet_Generic, cpumR3RegSet_Generic, g_aCpumRegAliases_##LName, NULL)
1093
1094#define CPU_REG_SEG(UName, LName) \
1095 CPU_REG_RW_AS(#LName, UName, U16, LName.Sel, cpumR3RegGet_Generic, cpumR3RegSet_seg, NULL, NULL ), \
1096 CPU_REG_RW_AS(#LName "_attr", UName##_ATTR, U32, LName.Attr.u, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, g_aCpumRegFields_seg), \
1097 CPU_REG_RW_AS(#LName "_base", UName##_BASE, U64, LName.u64Base, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ), \
1098 CPU_REG_RW_AS(#LName "_lim", UName##_LIMIT, U32, LName.u32Limit, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL )
1099
1100#define CPU_REG_MM(n) \
1101 CPU_REG_XS_RW_AS("mm" #n, MM##n, U64, x87.aRegs[n].mmx, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_mmN)
1102
1103#define CPU_REG_XMM(n) \
1104 CPU_REG_XS_RW_AS("xmm" #n, XMM##n, U128, x87.aXMM[n].xmm, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_xmmN)
1105
1106#define CPU_REG_YMM(n) \
1107 { "ymm" #n, DBGFREG_YMM##n, DBGFREGVALTYPE_U256, 0 /*fFlags*/, n, cpumR3RegGet_ymm, cpumR3RegSet_ymm, NULL /*paAliases*/, NULL /*paSubFields*/ }
1108
1109/** @} */
1110
1111
1112/**
1113 * The guest register descriptors.
1114 */
1115static DBGFREGDESC const g_aCpumRegGstDescs[] =
1116{
1117#define CPU_REG_RW_AS(a_szName, a_RegSuff, a_TypeSuff, a_CpumCtxMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1118 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, (uint32_t)RT_UOFFSETOF(CPUMCPU, Guest.a_CpumCtxMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1119#define CPU_REG_RO_AS(a_szName, a_RegSuff, a_TypeSuff, a_CpumCtxMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1120 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, (uint32_t)RT_UOFFSETOF(CPUMCPU, Guest.a_CpumCtxMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1121#define CPU_REG_XS_RW_AS(a_szName, a_RegSuff, a_TypeSuff, a_XStateMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1122 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, (uint32_t)RT_UOFFSETOF(X86XSAVEAREA, a_XStateMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1123#define CPU_REG_XS_RO_AS(a_szName, a_RegSuff, a_TypeSuff, a_XStateMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1124 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, (uint32_t)RT_UOFFSETOF(X86XSAVEAREA, a_XStateMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1125#define CPU_REG_MSR(a_szName, UName, a_TypeSuff, a_paSubFields) \
1126 CPU_REG_EX_AS(a_szName, MSR_##UName, a_TypeSuff, MSR_##UName, cpumR3RegGstGet_msr, cpumR3RegGstSet_msr, NULL, a_paSubFields)
1127#define CPU_REG_ST(n) \
1128 CPU_REG_EX_AS("st" #n, ST##n, R80, n, cpumR3RegGstGet_stN, cpumR3RegGstSet_stN, NULL, g_aCpumRegFields_stN)
1129
1130 CPU_REG_REG(RAX, rax),
1131 CPU_REG_REG(RCX, rcx),
1132 CPU_REG_REG(RDX, rdx),
1133 CPU_REG_REG(RBX, rbx),
1134 CPU_REG_REG(RSP, rsp),
1135 CPU_REG_REG(RBP, rbp),
1136 CPU_REG_REG(RSI, rsi),
1137 CPU_REG_REG(RDI, rdi),
1138 CPU_REG_REG(R8, r8),
1139 CPU_REG_REG(R9, r9),
1140 CPU_REG_REG(R10, r10),
1141 CPU_REG_REG(R11, r11),
1142 CPU_REG_REG(R12, r12),
1143 CPU_REG_REG(R13, r13),
1144 CPU_REG_REG(R14, r14),
1145 CPU_REG_REG(R15, r15),
1146 CPU_REG_SEG(CS, cs),
1147 CPU_REG_SEG(DS, ds),
1148 CPU_REG_SEG(ES, es),
1149 CPU_REG_SEG(FS, fs),
1150 CPU_REG_SEG(GS, gs),
1151 CPU_REG_SEG(SS, ss),
1152 CPU_REG_REG(RIP, rip),
1153 CPU_REG_RW_AS("rflags", RFLAGS, U64, rflags, cpumR3RegGet_Generic, cpumR3RegSet_Generic, g_aCpumRegAliases_rflags, g_aCpumRegFields_rflags ),
1154 CPU_REG_XS_RW_AS("fcw", FCW, U16, x87.FCW, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_fcw ),
1155 CPU_REG_XS_RW_AS("fsw", FSW, U16, x87.FSW, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_fsw ),
1156 CPU_REG_XS_RO_AS("ftw", FTW, U16, x87, cpumR3RegGet_ftw, cpumR3RegSet_ftw, NULL, g_aCpumRegFields_ftw ),
1157 CPU_REG_XS_RW_AS("fop", FOP, U16, x87.FOP, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, NULL ),
1158 CPU_REG_XS_RW_AS("fpuip", FPUIP, U32, x87.FPUIP, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, g_aCpumRegAliases_fpuip, NULL ),
1159 CPU_REG_XS_RW_AS("fpucs", FPUCS, U16, x87.CS, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, NULL ),
1160 CPU_REG_XS_RW_AS("fpudp", FPUDP, U32, x87.FPUDP, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, g_aCpumRegAliases_fpudp, NULL ),
1161 CPU_REG_XS_RW_AS("fpuds", FPUDS, U16, x87.DS, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, NULL ),
1162 CPU_REG_XS_RW_AS("mxcsr", MXCSR, U32, x87.MXCSR, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_mxcsr ),
1163 CPU_REG_XS_RW_AS("mxcsr_mask", MXCSR_MASK, U32, x87.MXCSR_MASK, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_mxcsr ),
1164 CPU_REG_ST(0),
1165 CPU_REG_ST(1),
1166 CPU_REG_ST(2),
1167 CPU_REG_ST(3),
1168 CPU_REG_ST(4),
1169 CPU_REG_ST(5),
1170 CPU_REG_ST(6),
1171 CPU_REG_ST(7),
1172 CPU_REG_MM(0),
1173 CPU_REG_MM(1),
1174 CPU_REG_MM(2),
1175 CPU_REG_MM(3),
1176 CPU_REG_MM(4),
1177 CPU_REG_MM(5),
1178 CPU_REG_MM(6),
1179 CPU_REG_MM(7),
1180 CPU_REG_XMM(0),
1181 CPU_REG_XMM(1),
1182 CPU_REG_XMM(2),
1183 CPU_REG_XMM(3),
1184 CPU_REG_XMM(4),
1185 CPU_REG_XMM(5),
1186 CPU_REG_XMM(6),
1187 CPU_REG_XMM(7),
1188 CPU_REG_XMM(8),
1189 CPU_REG_XMM(9),
1190 CPU_REG_XMM(10),
1191 CPU_REG_XMM(11),
1192 CPU_REG_XMM(12),
1193 CPU_REG_XMM(13),
1194 CPU_REG_XMM(14),
1195 CPU_REG_XMM(15),
1196 CPU_REG_YMM(0),
1197 CPU_REG_YMM(1),
1198 CPU_REG_YMM(2),
1199 CPU_REG_YMM(3),
1200 CPU_REG_YMM(4),
1201 CPU_REG_YMM(5),
1202 CPU_REG_YMM(6),
1203 CPU_REG_YMM(7),
1204 CPU_REG_YMM(8),
1205 CPU_REG_YMM(9),
1206 CPU_REG_YMM(10),
1207 CPU_REG_YMM(11),
1208 CPU_REG_YMM(12),
1209 CPU_REG_YMM(13),
1210 CPU_REG_YMM(14),
1211 CPU_REG_YMM(15),
1212 CPU_REG_RW_AS("gdtr_base", GDTR_BASE, U64, gdtr.pGdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1213 CPU_REG_RW_AS("gdtr_lim", GDTR_LIMIT, U16, gdtr.cbGdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1214 CPU_REG_RW_AS("idtr_base", IDTR_BASE, U64, idtr.pIdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1215 CPU_REG_RW_AS("idtr_lim", IDTR_LIMIT, U16, idtr.cbIdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1216 CPU_REG_SEG(LDTR, ldtr),
1217 CPU_REG_SEG(TR, tr),
1218 CPU_REG_EX_AS("cr0", CR0, U32, 0, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, g_aCpumRegAliases_cr0, g_aCpumRegFields_cr0 ),
1219 CPU_REG_EX_AS("cr2", CR2, U64, 2, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, NULL, NULL ),
1220 CPU_REG_EX_AS("cr3", CR3, U64, 3, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, NULL, g_aCpumRegFields_cr3 ),
1221 CPU_REG_EX_AS("cr4", CR4, U32, 4, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, NULL, g_aCpumRegFields_cr4 ),
1222 CPU_REG_EX_AS("cr8", CR8, U32, 8, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, NULL, NULL ),
1223 CPU_REG_EX_AS("dr0", DR0, U64, 0, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, NULL ),
1224 CPU_REG_EX_AS("dr1", DR1, U64, 1, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, NULL ),
1225 CPU_REG_EX_AS("dr2", DR2, U64, 2, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, NULL ),
1226 CPU_REG_EX_AS("dr3", DR3, U64, 3, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, NULL ),
1227 CPU_REG_EX_AS("dr6", DR6, U32, 6, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, g_aCpumRegFields_dr6 ),
1228 CPU_REG_EX_AS("dr7", DR7, U32, 7, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, g_aCpumRegFields_dr7 ),
1229 CPU_REG_MSR("apic_base", IA32_APICBASE, U32, g_aCpumRegFields_apic_base ),
1230 CPU_REG_MSR("pat", IA32_CR_PAT, U64, g_aCpumRegFields_cr_pat ),
1231 CPU_REG_MSR("perf_status", IA32_PERF_STATUS, U64, g_aCpumRegFields_perf_status),
1232 CPU_REG_MSR("sysenter_cs", IA32_SYSENTER_CS, U16, NULL ),
1233 CPU_REG_MSR("sysenter_eip", IA32_SYSENTER_EIP, U64, NULL ),
1234 CPU_REG_MSR("sysenter_esp", IA32_SYSENTER_ESP, U64, NULL ),
1235 CPU_REG_MSR("tsc", IA32_TSC, U32, NULL ),
1236 CPU_REG_MSR("efer", K6_EFER, U32, g_aCpumRegFields_efer ),
1237 CPU_REG_MSR("star", K6_STAR, U64, g_aCpumRegFields_star ),
1238 CPU_REG_MSR("cstar", K8_CSTAR, U64, g_aCpumRegFields_cstar ),
1239 CPU_REG_MSR("msr_fs_base", K8_FS_BASE, U64, NULL ),
1240 CPU_REG_MSR("msr_gs_base", K8_GS_BASE, U64, NULL ),
1241 CPU_REG_MSR("krnl_gs_base", K8_KERNEL_GS_BASE, U64, NULL ),
1242 CPU_REG_MSR("lstar", K8_LSTAR, U64, g_aCpumRegFields_lstar ),
1243 CPU_REG_MSR("sf_mask", K8_SF_MASK, U64, NULL ),
1244 CPU_REG_MSR("tsc_aux", K8_TSC_AUX, U64, NULL ),
1245 CPU_REG_EX_AS("ah", AH, U8, RT_OFFSETOF(CPUMCPU, Guest.rax) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1246 CPU_REG_EX_AS("ch", CH, U8, RT_OFFSETOF(CPUMCPU, Guest.rcx) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1247 CPU_REG_EX_AS("dh", DH, U8, RT_OFFSETOF(CPUMCPU, Guest.rdx) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1248 CPU_REG_EX_AS("bh", BH, U8, RT_OFFSETOF(CPUMCPU, Guest.rbx) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1249 CPU_REG_RW_AS("gdtr", GDTR, DTR, gdtr, cpumR3RegGet_gdtr, cpumR3RegSet_gdtr, NULL, NULL ),
1250 CPU_REG_RW_AS("idtr", IDTR, DTR, idtr, cpumR3RegGet_idtr, cpumR3RegSet_idtr, NULL, NULL ),
1251 DBGFREGDESC_TERMINATOR()
1252
1253#undef CPU_REG_RW_AS
1254#undef CPU_REG_RO_AS
1255#undef CPU_REG_MSR
1256#undef CPU_REG_ST
1257};
1258
1259
1260/**
1261 * Initializes the debugger related sides of the CPUM component.
1262 *
1263 * Called by CPUMR3Init.
1264 *
1265 * @returns VBox status code.
1266 * @param pVM The cross context VM structure.
1267 */
1268int cpumR3DbgInit(PVM pVM)
1269{
1270 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
1271 {
1272 int rc = DBGFR3RegRegisterCpu(pVM, pVM->apCpusR3[idCpu], g_aCpumRegGstDescs, true /*fGuestRegs*/);
1273 AssertLogRelRCReturn(rc, rc);
1274 }
1275
1276 return VINF_SUCCESS;
1277}
1278
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