VirtualBox

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

Last change on this file since 66885 was 66885, checked in by vboxsync, 8 years ago

DBGFReg: Added support for YMM registers, expanding the DBGFREVAL type to 512 in preparation for ZMM regs of AVX-512.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 61.4 KB
Line 
1/* $Id: CPUMDbg.cpp 66885 2017-05-12 19:59:22Z vboxsync $ */
2/** @file
3 * CPUM - CPU Monitor / Manager, Debugger & Debugging APIs.
4 */
5
6/*
7 * Copyright (C) 2010-2016 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.pXStateR3 + 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.pXStateR3 + 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 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
211 return VERR_NOT_IMPLEMENTED;
212}
213
214
215/**
216 * @interface_method_impl{DBGFREGDESC,pfnGet}
217 */
218static DECLCALLBACK(int) cpumR3RegGet_idtr(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
219{
220 PVMCPU pVCpu = (PVMCPU)pvUser;
221 VBOXIDTR const *pIdtr = (VBOXIDTR const *)((uint8_t const *)&pVCpu->cpum + pDesc->offRegister);
222
223 VMCPU_ASSERT_EMT(pVCpu);
224 Assert(pDesc->enmType == DBGFREGVALTYPE_DTR);
225
226 pValue->dtr.u32Limit = pIdtr->cbIdt;
227 pValue->dtr.u64Base = pIdtr->pIdt;
228 return VINF_SUCCESS;
229}
230
231
232/**
233 * @interface_method_impl{DBGFREGDESC,pfnGet}
234 */
235static DECLCALLBACK(int) cpumR3RegSet_idtr(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
236{
237 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
238 return VERR_NOT_IMPLEMENTED;
239}
240
241
242/**
243 * Determins the tag register value for a CPU register when the FPU state
244 * format is FXSAVE.
245 *
246 * @returns The tag register value.
247 * @param pFpu Pointer to the guest FPU.
248 * @param iReg The register number (0..7).
249 */
250DECLINLINE(uint16_t) cpumR3RegCalcFpuTagFromFxSave(PCX86FXSTATE pFpu, unsigned iReg)
251{
252 /*
253 * See table 11-1 in the AMD docs.
254 */
255 if (!(pFpu->FTW & RT_BIT_32(iReg)))
256 return 3; /* b11 - empty */
257
258 uint16_t const uExp = pFpu->aRegs[iReg].au16[4];
259 if (uExp == 0)
260 {
261 if (pFpu->aRegs[iReg].au64[0] == 0) /* J & M == 0 */
262 return 1; /* b01 - zero */
263 return 2; /* b10 - special */
264 }
265
266 if (uExp == UINT16_C(0xffff))
267 return 2; /* b10 - special */
268
269 if (!(pFpu->aRegs[iReg].au64[0] >> 63)) /* J == 0 */
270 return 2; /* b10 - special */
271
272 return 0; /* b00 - valid (normal) */
273}
274
275
276/**
277 * @interface_method_impl{DBGFREGDESC,pfnGet}
278 */
279static DECLCALLBACK(int) cpumR3RegGet_ftw(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
280{
281 PVMCPU pVCpu = (PVMCPU)pvUser;
282 PCX86FXSTATE pFpu = (PCX86FXSTATE)((uint8_t const *)&pVCpu->cpum + pDesc->offRegister);
283
284 VMCPU_ASSERT_EMT(pVCpu);
285 Assert(pDesc->enmType == DBGFREGVALTYPE_U16);
286
287 pValue->u16 = cpumR3RegCalcFpuTagFromFxSave(pFpu, 0)
288 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 1) << 2)
289 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 2) << 4)
290 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 3) << 6)
291 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 4) << 8)
292 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 5) << 10)
293 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 6) << 12)
294 | (cpumR3RegCalcFpuTagFromFxSave(pFpu, 7) << 14);
295 return VINF_SUCCESS;
296}
297
298
299/**
300 * @interface_method_impl{DBGFREGDESC,pfnGet}
301 */
302static DECLCALLBACK(int) cpumR3RegSet_ftw(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
303{
304 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
305 return VERR_DBGF_READ_ONLY_REGISTER;
306}
307
308
309/**
310 * @interface_method_impl{DBGFREGDESC,pfnGet}
311 */
312static DECLCALLBACK(int) cpumR3RegGet_Dummy(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
313{
314 RT_NOREF_PV(pvUser);
315 switch (pDesc->enmType)
316 {
317 case DBGFREGVALTYPE_U8: pValue->u8 = 0; return VINF_SUCCESS;
318 case DBGFREGVALTYPE_U16: pValue->u16 = 0; return VINF_SUCCESS;
319 case DBGFREGVALTYPE_U32: pValue->u32 = 0; return VINF_SUCCESS;
320 case DBGFREGVALTYPE_U64: pValue->u64 = 0; return VINF_SUCCESS;
321 case DBGFREGVALTYPE_U128:
322 RT_ZERO(pValue->u128);
323 return VINF_SUCCESS;
324 case DBGFREGVALTYPE_DTR:
325 pValue->dtr.u32Limit = 0;
326 pValue->dtr.u64Base = 0;
327 return VINF_SUCCESS;
328 case DBGFREGVALTYPE_R80:
329 RT_ZERO(pValue->r80Ex);
330 return VINF_SUCCESS;
331 default:
332 AssertMsgFailedReturn(("%d %s\n", pDesc->enmType, pDesc->pszName), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
333 }
334}
335
336
337/**
338 * @interface_method_impl{DBGFREGDESC,pfnSet}
339 */
340static DECLCALLBACK(int) cpumR3RegSet_Dummy(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
341{
342 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
343 return VERR_DBGF_READ_ONLY_REGISTER;
344}
345
346
347/**
348 * @interface_method_impl{DBGFREGDESC,pfnGet}
349 */
350static DECLCALLBACK(int) cpumR3RegGet_ymm(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
351{
352 PVMCPU pVCpu = (PVMCPU)pvUser;
353 uint32_t iReg = pDesc->offRegister;
354
355 Assert(pDesc->enmType == DBGFREGVALTYPE_U256);
356 VMCPU_ASSERT_EMT(pVCpu);
357
358 if (iReg < 16)
359 {
360 pValue->u256.DQWords.dqw0 = pVCpu->cpum.s.Guest.pXStateR3->x87.aXMM[iReg].uXmm;
361 pValue->u256.DQWords.dqw1 = pVCpu->cpum.s.Guest.pXStateR3->u.YmmHi.aYmmHi[iReg].uXmm;
362 return VINF_SUCCESS;
363 }
364 return VERR_NOT_IMPLEMENTED;
365}
366
367
368/**
369 * @interface_method_impl{DBGFREGDESC,pfnSet}
370 */
371static DECLCALLBACK(int) cpumR3RegSet_ymm(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
372{
373 PVMCPU pVCpu = (PVMCPU)pvUser;
374 uint32_t iReg = pDesc->offRegister;
375
376 Assert(pDesc->enmType == DBGFREGVALTYPE_U256);
377 VMCPU_ASSERT_EMT(pVCpu);
378
379 if (iReg < 16)
380 {
381 RTUINT128U Val;
382 RTUInt128AssignAnd(&pVCpu->cpum.s.Guest.pXStateR3->x87.aXMM[iReg].uXmm,
383 RTUInt128AssignBitwiseNot(RTUInt128Assign(&Val, &pfMask->u256.DQWords.dqw0)));
384 RTUInt128AssignOr(&pVCpu->cpum.s.Guest.pXStateR3->u.YmmHi.aYmmHi[iReg].uXmm,
385 RTUInt128AssignAnd(RTUInt128Assign(&Val, &pValue->u128), &pfMask->u128));
386
387 }
388 return VERR_NOT_IMPLEMENTED;
389}
390
391
392/*
393 *
394 * Guest register access functions.
395 *
396 */
397
398/**
399 * @interface_method_impl{DBGFREGDESC,pfnGet}
400 */
401static DECLCALLBACK(int) cpumR3RegGstGet_crX(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
402{
403 PVMCPU pVCpu = (PVMCPU)pvUser;
404 VMCPU_ASSERT_EMT(pVCpu);
405
406 uint64_t u64Value;
407 int rc = CPUMGetGuestCRx(pVCpu, pDesc->offRegister, &u64Value);
408 AssertRCReturn(rc, rc);
409 switch (pDesc->enmType)
410 {
411 case DBGFREGVALTYPE_U64: pValue->u64 = u64Value; break;
412 case DBGFREGVALTYPE_U32: pValue->u32 = (uint32_t)u64Value; break;
413 default:
414 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
415 }
416 return VINF_SUCCESS;
417}
418
419
420/**
421 * @interface_method_impl{DBGFREGDESC,pfnGet}
422 */
423static DECLCALLBACK(int) cpumR3RegGstSet_crX(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
424{
425 int rc;
426 PVMCPU pVCpu = (PVMCPU)pvUser;
427
428 VMCPU_ASSERT_EMT(pVCpu);
429
430 /*
431 * Calculate the new value.
432 */
433 uint64_t u64Value;
434 uint64_t fMask;
435 uint64_t fMaskMax;
436 switch (pDesc->enmType)
437 {
438 case DBGFREGVALTYPE_U64:
439 u64Value = pValue->u64;
440 fMask = pfMask->u64;
441 fMaskMax = UINT64_MAX;
442 break;
443 case DBGFREGVALTYPE_U32:
444 u64Value = pValue->u32;
445 fMask = pfMask->u32;
446 fMaskMax = UINT32_MAX;
447 break;
448 default:
449 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
450 }
451 if (fMask != fMaskMax)
452 {
453 uint64_t u64FullValue;
454 rc = CPUMGetGuestCRx(pVCpu, pDesc->offRegister, &u64FullValue);
455 if (RT_FAILURE(rc))
456 return rc;
457 u64Value = (u64FullValue & ~fMask)
458 | (u64Value & fMask);
459 }
460
461 /*
462 * Perform the assignment.
463 */
464 switch (pDesc->offRegister)
465 {
466 case 0: rc = CPUMSetGuestCR0(pVCpu, u64Value); break;
467 case 2: rc = CPUMSetGuestCR2(pVCpu, u64Value); break;
468 case 3: rc = CPUMSetGuestCR3(pVCpu, u64Value); break;
469 case 4: rc = CPUMSetGuestCR4(pVCpu, u64Value); break;
470 case 8: rc = APICSetTpr(pVCpu, (uint8_t)(u64Value << 4)); break;
471 default:
472 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
473 }
474 return rc;
475}
476
477
478/**
479 * @interface_method_impl{DBGFREGDESC,pfnGet}
480 */
481static DECLCALLBACK(int) cpumR3RegGstGet_drX(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
482{
483 PVMCPU pVCpu = (PVMCPU)pvUser;
484 VMCPU_ASSERT_EMT(pVCpu);
485
486 uint64_t u64Value;
487 int rc = CPUMGetGuestDRx(pVCpu, pDesc->offRegister, &u64Value);
488 AssertRCReturn(rc, rc);
489 switch (pDesc->enmType)
490 {
491 case DBGFREGVALTYPE_U64: pValue->u64 = u64Value; break;
492 case DBGFREGVALTYPE_U32: pValue->u32 = (uint32_t)u64Value; break;
493 default:
494 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
495 }
496 return VINF_SUCCESS;
497}
498
499
500/**
501 * @interface_method_impl{DBGFREGDESC,pfnGet}
502 */
503static DECLCALLBACK(int) cpumR3RegGstSet_drX(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
504{
505 int rc;
506 PVMCPU pVCpu = (PVMCPU)pvUser;
507
508 VMCPU_ASSERT_EMT(pVCpu);
509
510 /*
511 * Calculate the new value.
512 */
513 uint64_t u64Value;
514 uint64_t fMask;
515 uint64_t fMaskMax;
516 switch (pDesc->enmType)
517 {
518 case DBGFREGVALTYPE_U64:
519 u64Value = pValue->u64;
520 fMask = pfMask->u64;
521 fMaskMax = UINT64_MAX;
522 break;
523 case DBGFREGVALTYPE_U32:
524 u64Value = pValue->u32;
525 fMask = pfMask->u32;
526 fMaskMax = UINT32_MAX;
527 break;
528 default:
529 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
530 }
531 if (fMask != fMaskMax)
532 {
533 uint64_t u64FullValue;
534 rc = CPUMGetGuestDRx(pVCpu, pDesc->offRegister, &u64FullValue);
535 if (RT_FAILURE(rc))
536 return rc;
537 u64Value = (u64FullValue & ~fMask)
538 | (u64Value & fMask);
539 }
540
541 /*
542 * Perform the assignment.
543 */
544 return CPUMSetGuestDRx(pVCpu, pDesc->offRegister, u64Value);
545}
546
547
548/**
549 * @interface_method_impl{DBGFREGDESC,pfnGet}
550 */
551static DECLCALLBACK(int) cpumR3RegGstGet_msr(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
552{
553 PVMCPU pVCpu = (PVMCPU)pvUser;
554 VMCPU_ASSERT_EMT(pVCpu);
555
556 uint64_t u64Value;
557 VBOXSTRICTRC rcStrict = CPUMQueryGuestMsr(pVCpu, pDesc->offRegister, &u64Value);
558 if (rcStrict == VINF_SUCCESS)
559 {
560 switch (pDesc->enmType)
561 {
562 case DBGFREGVALTYPE_U64: pValue->u64 = u64Value; break;
563 case DBGFREGVALTYPE_U32: pValue->u32 = (uint32_t)u64Value; break;
564 case DBGFREGVALTYPE_U16: pValue->u16 = (uint16_t)u64Value; break;
565 default:
566 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
567 }
568 return VBOXSTRICTRC_VAL(rcStrict);
569 }
570
571 /** @todo what to do about errors? */
572 Assert(RT_FAILURE_NP(rcStrict));
573 return VBOXSTRICTRC_VAL(rcStrict);
574}
575
576
577/**
578 * @interface_method_impl{DBGFREGDESC,pfnGet}
579 */
580static DECLCALLBACK(int) cpumR3RegGstSet_msr(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
581{
582 PVMCPU pVCpu = (PVMCPU)pvUser;
583
584 VMCPU_ASSERT_EMT(pVCpu);
585
586 /*
587 * Calculate the new value.
588 */
589 uint64_t u64Value;
590 uint64_t fMask;
591 uint64_t fMaskMax;
592 switch (pDesc->enmType)
593 {
594 case DBGFREGVALTYPE_U64:
595 u64Value = pValue->u64;
596 fMask = pfMask->u64;
597 fMaskMax = UINT64_MAX;
598 break;
599 case DBGFREGVALTYPE_U32:
600 u64Value = pValue->u32;
601 fMask = pfMask->u32;
602 fMaskMax = UINT32_MAX;
603 break;
604 case DBGFREGVALTYPE_U16:
605 u64Value = pValue->u16;
606 fMask = pfMask->u16;
607 fMaskMax = UINT16_MAX;
608 break;
609 default:
610 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
611 }
612 if (fMask != fMaskMax)
613 {
614 uint64_t u64FullValue;
615 VBOXSTRICTRC rcStrict = CPUMQueryGuestMsr(pVCpu, pDesc->offRegister, &u64FullValue);
616 if (rcStrict != VINF_SUCCESS)
617 {
618 AssertRC(RT_FAILURE_NP(rcStrict));
619 return VBOXSTRICTRC_VAL(rcStrict);
620 }
621 u64Value = (u64FullValue & ~fMask)
622 | (u64Value & fMask);
623 }
624
625 /*
626 * Perform the assignment.
627 */
628 VBOXSTRICTRC rcStrict = CPUMSetGuestMsr(pVCpu, pDesc->offRegister, u64Value);
629 if (rcStrict == VINF_SUCCESS)
630 return VINF_SUCCESS;
631 AssertRC(RT_FAILURE_NP(rcStrict));
632 return VBOXSTRICTRC_VAL(rcStrict);
633}
634
635
636/**
637 * @interface_method_impl{DBGFREGDESC,pfnGet}
638 */
639static DECLCALLBACK(int) cpumR3RegGstGet_stN(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
640{
641 PVMCPU pVCpu = (PVMCPU)pvUser;
642 VMCPU_ASSERT_EMT(pVCpu);
643 Assert(pDesc->enmType == DBGFREGVALTYPE_R80);
644
645 PX86FXSTATE pFpuCtx = &pVCpu->cpum.s.Guest.CTX_SUFF(pXState)->x87;
646 unsigned iReg = (pFpuCtx->FSW >> 11) & 7;
647 iReg += pDesc->offRegister;
648 iReg &= 7;
649 pValue->r80Ex = pFpuCtx->aRegs[iReg].r80Ex;
650
651 return VINF_SUCCESS;
652}
653
654
655/**
656 * @interface_method_impl{DBGFREGDESC,pfnGet}
657 */
658static DECLCALLBACK(int) cpumR3RegGstSet_stN(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
659{
660 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
661 return VERR_NOT_IMPLEMENTED;
662}
663
664
665
666/*
667 *
668 * Hypervisor register access functions.
669 *
670 */
671
672/**
673 * @interface_method_impl{DBGFREGDESC,pfnGet}
674 */
675static DECLCALLBACK(int) cpumR3RegHyperGet_crX(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
676{
677 PVMCPU pVCpu = (PVMCPU)pvUser;
678 VMCPU_ASSERT_EMT(pVCpu);
679
680 uint64_t u64Value;
681 switch (pDesc->offRegister)
682 {
683 case 0: u64Value = UINT64_MAX; break;
684 case 2: u64Value = UINT64_MAX; break;
685 case 3: u64Value = CPUMGetHyperCR3(pVCpu); break;
686 case 4: u64Value = UINT64_MAX; break;
687 case 8: u64Value = UINT64_MAX; break;
688 default:
689 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
690 }
691 switch (pDesc->enmType)
692 {
693 case DBGFREGVALTYPE_U64: pValue->u64 = u64Value; break;
694 case DBGFREGVALTYPE_U32: pValue->u32 = (uint32_t)u64Value; break;
695 default:
696 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
697 }
698 return VINF_SUCCESS;
699}
700
701
702/**
703 * @interface_method_impl{DBGFREGDESC,pfnGet}
704 */
705static DECLCALLBACK(int) cpumR3RegHyperSet_crX(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
706{
707 /* Not settable, prevents killing your host. */
708 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
709 return VERR_ACCESS_DENIED;
710}
711
712
713/**
714 * @interface_method_impl{DBGFREGDESC,pfnGet}
715 */
716static DECLCALLBACK(int) cpumR3RegHyperGet_drX(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
717{
718 PVMCPU pVCpu = (PVMCPU)pvUser;
719 VMCPU_ASSERT_EMT(pVCpu);
720
721 uint64_t u64Value;
722 switch (pDesc->offRegister)
723 {
724 case 0: u64Value = CPUMGetHyperDR0(pVCpu); break;
725 case 1: u64Value = CPUMGetHyperDR1(pVCpu); break;
726 case 2: u64Value = CPUMGetHyperDR2(pVCpu); break;
727 case 3: u64Value = CPUMGetHyperDR3(pVCpu); break;
728 case 6: u64Value = CPUMGetHyperDR6(pVCpu); break;
729 case 7: u64Value = CPUMGetHyperDR7(pVCpu); break;
730 default:
731 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
732 }
733 switch (pDesc->enmType)
734 {
735 case DBGFREGVALTYPE_U64: pValue->u64 = u64Value; break;
736 case DBGFREGVALTYPE_U32: pValue->u32 = (uint32_t)u64Value; break;
737 default:
738 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
739 }
740 return VINF_SUCCESS;
741}
742
743
744/**
745 * @interface_method_impl{DBGFREGDESC,pfnGet}
746 */
747static DECLCALLBACK(int) cpumR3RegHyperSet_drX(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
748{
749 /* Not settable, prevents killing your host. */
750 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
751 return VERR_ACCESS_DENIED;
752}
753
754
755/**
756 * @interface_method_impl{DBGFREGDESC,pfnGet}
757 */
758static DECLCALLBACK(int) cpumR3RegHyperGet_msr(void *pvUser, PCDBGFREGDESC pDesc, PDBGFREGVAL pValue)
759{
760 NOREF(pvUser);
761
762 /* Not availble at present, return all FFs to keep things quiet */
763 uint64_t u64Value = UINT64_MAX;
764 switch (pDesc->enmType)
765 {
766 case DBGFREGVALTYPE_U64: pValue->u64 = u64Value; break;
767 case DBGFREGVALTYPE_U32: pValue->u32 = (uint32_t)u64Value; break;
768 case DBGFREGVALTYPE_U16: pValue->u16 = (uint16_t)u64Value; break;
769 default:
770 AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
771 }
772 return VINF_SUCCESS;
773}
774
775
776/**
777 * @interface_method_impl{DBGFREGDESC,pfnGet}
778 */
779static DECLCALLBACK(int) cpumR3RegHyperSet_msr(void *pvUser, PCDBGFREGDESC pDesc, PCDBGFREGVAL pValue, PCDBGFREGVAL pfMask)
780{
781 /* Not settable, return failure. */
782 NOREF(pvUser); NOREF(pDesc); NOREF(pValue); NOREF(pfMask);
783 return VERR_ACCESS_DENIED;
784}
785
786
787/*
788 * Set up aliases.
789 */
790#define CPUMREGALIAS_STD(Name, psz32, psz16, psz8) \
791 static DBGFREGALIAS const g_aCpumRegAliases_##Name[] = \
792 { \
793 { psz32, DBGFREGVALTYPE_U32 }, \
794 { psz16, DBGFREGVALTYPE_U16 }, \
795 { psz8, DBGFREGVALTYPE_U8 }, \
796 { NULL, DBGFREGVALTYPE_INVALID } \
797 }
798CPUMREGALIAS_STD(rax, "eax", "ax", "al");
799CPUMREGALIAS_STD(rcx, "ecx", "cx", "cl");
800CPUMREGALIAS_STD(rdx, "edx", "dx", "dl");
801CPUMREGALIAS_STD(rbx, "ebx", "bx", "bl");
802CPUMREGALIAS_STD(rsp, "esp", "sp", NULL);
803CPUMREGALIAS_STD(rbp, "ebp", "bp", NULL);
804CPUMREGALIAS_STD(rsi, "esi", "si", "sil");
805CPUMREGALIAS_STD(rdi, "edi", "di", "dil");
806CPUMREGALIAS_STD(r8, "r8d", "r8w", "r8b");
807CPUMREGALIAS_STD(r9, "r9d", "r9w", "r9b");
808CPUMREGALIAS_STD(r10, "r10d", "r10w", "r10b");
809CPUMREGALIAS_STD(r11, "r11d", "r11w", "r11b");
810CPUMREGALIAS_STD(r12, "r12d", "r12w", "r12b");
811CPUMREGALIAS_STD(r13, "r13d", "r13w", "r13b");
812CPUMREGALIAS_STD(r14, "r14d", "r14w", "r14b");
813CPUMREGALIAS_STD(r15, "r15d", "r15w", "r15b");
814CPUMREGALIAS_STD(rip, "eip", "ip", NULL);
815CPUMREGALIAS_STD(rflags, "eflags", "flags", NULL);
816#undef CPUMREGALIAS_STD
817
818static DBGFREGALIAS const g_aCpumRegAliases_fpuip[] =
819{
820 { "fpuip16", DBGFREGVALTYPE_U16 },
821 { NULL, DBGFREGVALTYPE_INVALID }
822};
823
824static DBGFREGALIAS const g_aCpumRegAliases_fpudp[] =
825{
826 { "fpudp16", DBGFREGVALTYPE_U16 },
827 { NULL, DBGFREGVALTYPE_INVALID }
828};
829
830static DBGFREGALIAS const g_aCpumRegAliases_cr0[] =
831{
832 { "msw", DBGFREGVALTYPE_U16 },
833 { NULL, DBGFREGVALTYPE_INVALID }
834};
835
836/*
837 * Sub fields.
838 */
839/** Sub-fields for the (hidden) segment attribute register. */
840static DBGFREGSUBFIELD const g_aCpumRegFields_seg[] =
841{
842 DBGFREGSUBFIELD_RW("type", 0, 4, 0),
843 DBGFREGSUBFIELD_RW("s", 4, 1, 0),
844 DBGFREGSUBFIELD_RW("dpl", 5, 2, 0),
845 DBGFREGSUBFIELD_RW("p", 7, 1, 0),
846 DBGFREGSUBFIELD_RW("avl", 12, 1, 0),
847 DBGFREGSUBFIELD_RW("l", 13, 1, 0),
848 DBGFREGSUBFIELD_RW("d", 14, 1, 0),
849 DBGFREGSUBFIELD_RW("g", 15, 1, 0),
850 DBGFREGSUBFIELD_TERMINATOR()
851};
852
853/** Sub-fields for the flags register. */
854static DBGFREGSUBFIELD const g_aCpumRegFields_rflags[] =
855{
856 DBGFREGSUBFIELD_RW("cf", 0, 1, 0),
857 DBGFREGSUBFIELD_RW("pf", 2, 1, 0),
858 DBGFREGSUBFIELD_RW("af", 4, 1, 0),
859 DBGFREGSUBFIELD_RW("zf", 6, 1, 0),
860 DBGFREGSUBFIELD_RW("sf", 7, 1, 0),
861 DBGFREGSUBFIELD_RW("tf", 8, 1, 0),
862 DBGFREGSUBFIELD_RW("if", 9, 1, 0),
863 DBGFREGSUBFIELD_RW("df", 10, 1, 0),
864 DBGFREGSUBFIELD_RW("of", 11, 1, 0),
865 DBGFREGSUBFIELD_RW("iopl", 12, 2, 0),
866 DBGFREGSUBFIELD_RW("nt", 14, 1, 0),
867 DBGFREGSUBFIELD_RW("rf", 16, 1, 0),
868 DBGFREGSUBFIELD_RW("vm", 17, 1, 0),
869 DBGFREGSUBFIELD_RW("ac", 18, 1, 0),
870 DBGFREGSUBFIELD_RW("vif", 19, 1, 0),
871 DBGFREGSUBFIELD_RW("vip", 20, 1, 0),
872 DBGFREGSUBFIELD_RW("id", 21, 1, 0),
873 DBGFREGSUBFIELD_TERMINATOR()
874};
875
876/** Sub-fields for the FPU control word register. */
877static DBGFREGSUBFIELD const g_aCpumRegFields_fcw[] =
878{
879 DBGFREGSUBFIELD_RW("im", 1, 1, 0),
880 DBGFREGSUBFIELD_RW("dm", 2, 1, 0),
881 DBGFREGSUBFIELD_RW("zm", 3, 1, 0),
882 DBGFREGSUBFIELD_RW("om", 4, 1, 0),
883 DBGFREGSUBFIELD_RW("um", 5, 1, 0),
884 DBGFREGSUBFIELD_RW("pm", 6, 1, 0),
885 DBGFREGSUBFIELD_RW("pc", 8, 2, 0),
886 DBGFREGSUBFIELD_RW("rc", 10, 2, 0),
887 DBGFREGSUBFIELD_RW("x", 12, 1, 0),
888 DBGFREGSUBFIELD_TERMINATOR()
889};
890
891/** Sub-fields for the FPU status word register. */
892static DBGFREGSUBFIELD const g_aCpumRegFields_fsw[] =
893{
894 DBGFREGSUBFIELD_RW("ie", 0, 1, 0),
895 DBGFREGSUBFIELD_RW("de", 1, 1, 0),
896 DBGFREGSUBFIELD_RW("ze", 2, 1, 0),
897 DBGFREGSUBFIELD_RW("oe", 3, 1, 0),
898 DBGFREGSUBFIELD_RW("ue", 4, 1, 0),
899 DBGFREGSUBFIELD_RW("pe", 5, 1, 0),
900 DBGFREGSUBFIELD_RW("se", 6, 1, 0),
901 DBGFREGSUBFIELD_RW("es", 7, 1, 0),
902 DBGFREGSUBFIELD_RW("c0", 8, 1, 0),
903 DBGFREGSUBFIELD_RW("c1", 9, 1, 0),
904 DBGFREGSUBFIELD_RW("c2", 10, 1, 0),
905 DBGFREGSUBFIELD_RW("top", 11, 3, 0),
906 DBGFREGSUBFIELD_RW("c3", 14, 1, 0),
907 DBGFREGSUBFIELD_RW("b", 15, 1, 0),
908 DBGFREGSUBFIELD_TERMINATOR()
909};
910
911/** Sub-fields for the FPU tag word register. */
912static DBGFREGSUBFIELD const g_aCpumRegFields_ftw[] =
913{
914 DBGFREGSUBFIELD_RW("tag0", 0, 2, 0),
915 DBGFREGSUBFIELD_RW("tag1", 2, 2, 0),
916 DBGFREGSUBFIELD_RW("tag2", 4, 2, 0),
917 DBGFREGSUBFIELD_RW("tag3", 6, 2, 0),
918 DBGFREGSUBFIELD_RW("tag4", 8, 2, 0),
919 DBGFREGSUBFIELD_RW("tag5", 10, 2, 0),
920 DBGFREGSUBFIELD_RW("tag6", 12, 2, 0),
921 DBGFREGSUBFIELD_RW("tag7", 14, 2, 0),
922 DBGFREGSUBFIELD_TERMINATOR()
923};
924
925/** Sub-fields for the Multimedia Extensions Control and Status Register. */
926static DBGFREGSUBFIELD const g_aCpumRegFields_mxcsr[] =
927{
928 DBGFREGSUBFIELD_RW("ie", 0, 1, 0),
929 DBGFREGSUBFIELD_RW("de", 1, 1, 0),
930 DBGFREGSUBFIELD_RW("ze", 2, 1, 0),
931 DBGFREGSUBFIELD_RW("oe", 3, 1, 0),
932 DBGFREGSUBFIELD_RW("ue", 4, 1, 0),
933 DBGFREGSUBFIELD_RW("pe", 5, 1, 0),
934 DBGFREGSUBFIELD_RW("daz", 6, 1, 0),
935 DBGFREGSUBFIELD_RW("im", 7, 1, 0),
936 DBGFREGSUBFIELD_RW("dm", 8, 1, 0),
937 DBGFREGSUBFIELD_RW("zm", 9, 1, 0),
938 DBGFREGSUBFIELD_RW("om", 10, 1, 0),
939 DBGFREGSUBFIELD_RW("um", 11, 1, 0),
940 DBGFREGSUBFIELD_RW("pm", 12, 1, 0),
941 DBGFREGSUBFIELD_RW("rc", 13, 2, 0),
942 DBGFREGSUBFIELD_RW("fz", 14, 1, 0),
943 DBGFREGSUBFIELD_TERMINATOR()
944};
945
946/** Sub-fields for the FPU tag word register. */
947static DBGFREGSUBFIELD const g_aCpumRegFields_stN[] =
948{
949 DBGFREGSUBFIELD_RW("man", 0, 64, 0),
950 DBGFREGSUBFIELD_RW("exp", 64, 15, 0),
951 DBGFREGSUBFIELD_RW("sig", 79, 1, 0),
952 DBGFREGSUBFIELD_TERMINATOR()
953};
954
955/** Sub-fields for the MMX registers. */
956static DBGFREGSUBFIELD const g_aCpumRegFields_mmN[] =
957{
958 DBGFREGSUBFIELD_RW("dw0", 0, 32, 0),
959 DBGFREGSUBFIELD_RW("dw1", 32, 32, 0),
960 DBGFREGSUBFIELD_RW("w0", 0, 16, 0),
961 DBGFREGSUBFIELD_RW("w1", 16, 16, 0),
962 DBGFREGSUBFIELD_RW("w2", 32, 16, 0),
963 DBGFREGSUBFIELD_RW("w3", 48, 16, 0),
964 DBGFREGSUBFIELD_RW("b0", 0, 8, 0),
965 DBGFREGSUBFIELD_RW("b1", 8, 8, 0),
966 DBGFREGSUBFIELD_RW("b2", 16, 8, 0),
967 DBGFREGSUBFIELD_RW("b3", 24, 8, 0),
968 DBGFREGSUBFIELD_RW("b4", 32, 8, 0),
969 DBGFREGSUBFIELD_RW("b5", 40, 8, 0),
970 DBGFREGSUBFIELD_RW("b6", 48, 8, 0),
971 DBGFREGSUBFIELD_RW("b7", 56, 8, 0),
972 DBGFREGSUBFIELD_TERMINATOR()
973};
974
975/** Sub-fields for the XMM registers. */
976static DBGFREGSUBFIELD const g_aCpumRegFields_xmmN[] =
977{
978 DBGFREGSUBFIELD_RW("r0", 0, 32, 0),
979 DBGFREGSUBFIELD_RW("r0.man", 0+ 0, 23, 0),
980 DBGFREGSUBFIELD_RW("r0.exp", 0+23, 8, 0),
981 DBGFREGSUBFIELD_RW("r0.sig", 0+31, 1, 0),
982 DBGFREGSUBFIELD_RW("r1", 32, 32, 0),
983 DBGFREGSUBFIELD_RW("r1.man", 32+ 0, 23, 0),
984 DBGFREGSUBFIELD_RW("r1.exp", 32+23, 8, 0),
985 DBGFREGSUBFIELD_RW("r1.sig", 32+31, 1, 0),
986 DBGFREGSUBFIELD_RW("r2", 64, 32, 0),
987 DBGFREGSUBFIELD_RW("r2.man", 64+ 0, 23, 0),
988 DBGFREGSUBFIELD_RW("r2.exp", 64+23, 8, 0),
989 DBGFREGSUBFIELD_RW("r2.sig", 64+31, 1, 0),
990 DBGFREGSUBFIELD_RW("r3", 96, 32, 0),
991 DBGFREGSUBFIELD_RW("r3.man", 96+ 0, 23, 0),
992 DBGFREGSUBFIELD_RW("r3.exp", 96+23, 8, 0),
993 DBGFREGSUBFIELD_RW("r3.sig", 96+31, 1, 0),
994 DBGFREGSUBFIELD_TERMINATOR()
995};
996
997#if 0 /* needs special accessor, too lazy for that now. */
998/** Sub-fields for the YMM registers. */
999static DBGFREGSUBFIELD const g_aCpumRegFields_ymmN[] =
1000{
1001 DBGFREGSUBFIELD_RW("r0", 0, 32, 0),
1002 DBGFREGSUBFIELD_RW("r0.man", 0+ 0, 23, 0),
1003 DBGFREGSUBFIELD_RW("r0.exp", 0+23, 8, 0),
1004 DBGFREGSUBFIELD_RW("r0.sig", 0+31, 1, 0),
1005 DBGFREGSUBFIELD_RW("r1", 32, 32, 0),
1006 DBGFREGSUBFIELD_RW("r1.man", 32+ 0, 23, 0),
1007 DBGFREGSUBFIELD_RW("r1.exp", 32+23, 8, 0),
1008 DBGFREGSUBFIELD_RW("r1.sig", 32+31, 1, 0),
1009 DBGFREGSUBFIELD_RW("r2", 64, 32, 0),
1010 DBGFREGSUBFIELD_RW("r2.man", 64+ 0, 23, 0),
1011 DBGFREGSUBFIELD_RW("r2.exp", 64+23, 8, 0),
1012 DBGFREGSUBFIELD_RW("r2.sig", 64+31, 1, 0),
1013 DBGFREGSUBFIELD_RW("r3", 96, 32, 0),
1014 DBGFREGSUBFIELD_RW("r3.man", 96+ 0, 23, 0),
1015 DBGFREGSUBFIELD_RW("r3.exp", 96+23, 8, 0),
1016 DBGFREGSUBFIELD_RW("r3.sig", 96+31, 1, 0),
1017 DBGFREGSUBFIELD_RW("r4", 128, 32, 0),
1018 DBGFREGSUBFIELD_RW("r4.man", 128+ 0, 23, 0),
1019 DBGFREGSUBFIELD_RW("r4.exp", 128+23, 8, 0),
1020 DBGFREGSUBFIELD_RW("r4.sig", 128+31, 1, 0),
1021 DBGFREGSUBFIELD_RW("r5", 160, 32, 0),
1022 DBGFREGSUBFIELD_RW("r5.man", 160+ 0, 23, 0),
1023 DBGFREGSUBFIELD_RW("r5.exp", 160+23, 8, 0),
1024 DBGFREGSUBFIELD_RW("r5.sig", 160+31, 1, 0),
1025 DBGFREGSUBFIELD_RW("r6", 192, 32, 0),
1026 DBGFREGSUBFIELD_RW("r6.man", 192+ 0, 23, 0),
1027 DBGFREGSUBFIELD_RW("r6.exp", 192+23, 8, 0),
1028 DBGFREGSUBFIELD_RW("r6.sig", 192+31, 1, 0),
1029 DBGFREGSUBFIELD_RW("r7", 224, 32, 0),
1030 DBGFREGSUBFIELD_RW("r7.man", 224+ 0, 23, 0),
1031 DBGFREGSUBFIELD_RW("r7.exp", 224+23, 8, 0),
1032 DBGFREGSUBFIELD_RW("r7.sig", 224+31, 1, 0),
1033 DBGFREGSUBFIELD_TERMINATOR()
1034};
1035#endif
1036
1037/** Sub-fields for the CR0 register. */
1038static DBGFREGSUBFIELD const g_aCpumRegFields_cr0[] =
1039{
1040 DBGFREGSUBFIELD_RW("pe", 0, 1, 0),
1041 DBGFREGSUBFIELD_RW("mp", 1, 1, 0),
1042 DBGFREGSUBFIELD_RW("em", 2, 1, 0),
1043 DBGFREGSUBFIELD_RW("ts", 3, 1, 0),
1044 DBGFREGSUBFIELD_RO("et", 4, 1, 0),
1045 DBGFREGSUBFIELD_RW("ne", 5, 1, 0),
1046 DBGFREGSUBFIELD_RW("wp", 16, 1, 0),
1047 DBGFREGSUBFIELD_RW("am", 18, 1, 0),
1048 DBGFREGSUBFIELD_RW("nw", 29, 1, 0),
1049 DBGFREGSUBFIELD_RW("cd", 30, 1, 0),
1050 DBGFREGSUBFIELD_RW("pg", 31, 1, 0),
1051 DBGFREGSUBFIELD_TERMINATOR()
1052};
1053
1054/** Sub-fields for the CR3 register. */
1055static DBGFREGSUBFIELD const g_aCpumRegFields_cr3[] =
1056{
1057 DBGFREGSUBFIELD_RW("pwt", 3, 1, 0),
1058 DBGFREGSUBFIELD_RW("pcd", 4, 1, 0),
1059 DBGFREGSUBFIELD_TERMINATOR()
1060};
1061
1062/** Sub-fields for the CR4 register. */
1063static DBGFREGSUBFIELD const g_aCpumRegFields_cr4[] =
1064{
1065 DBGFREGSUBFIELD_RW("vme", 0, 1, 0),
1066 DBGFREGSUBFIELD_RW("pvi", 1, 1, 0),
1067 DBGFREGSUBFIELD_RW("tsd", 2, 1, 0),
1068 DBGFREGSUBFIELD_RW("de", 3, 1, 0),
1069 DBGFREGSUBFIELD_RW("pse", 4, 1, 0),
1070 DBGFREGSUBFIELD_RW("pae", 5, 1, 0),
1071 DBGFREGSUBFIELD_RW("mce", 6, 1, 0),
1072 DBGFREGSUBFIELD_RW("pge", 7, 1, 0),
1073 DBGFREGSUBFIELD_RW("pce", 8, 1, 0),
1074 DBGFREGSUBFIELD_RW("osfxsr", 9, 1, 0),
1075 DBGFREGSUBFIELD_RW("osxmmeexcpt", 10, 1, 0),
1076 DBGFREGSUBFIELD_RW("vmxe", 13, 1, 0),
1077 DBGFREGSUBFIELD_RW("smxe", 14, 1, 0),
1078 DBGFREGSUBFIELD_RW("pcide", 17, 1, 0),
1079 DBGFREGSUBFIELD_RW("osxsave", 18, 1, 0),
1080 DBGFREGSUBFIELD_RW("smep", 20, 1, 0),
1081 DBGFREGSUBFIELD_RW("smap", 21, 1, 0),
1082 DBGFREGSUBFIELD_TERMINATOR()
1083};
1084
1085/** Sub-fields for the DR6 register. */
1086static DBGFREGSUBFIELD const g_aCpumRegFields_dr6[] =
1087{
1088 DBGFREGSUBFIELD_RW("b0", 0, 1, 0),
1089 DBGFREGSUBFIELD_RW("b1", 1, 1, 0),
1090 DBGFREGSUBFIELD_RW("b2", 2, 1, 0),
1091 DBGFREGSUBFIELD_RW("b3", 3, 1, 0),
1092 DBGFREGSUBFIELD_RW("bd", 13, 1, 0),
1093 DBGFREGSUBFIELD_RW("bs", 14, 1, 0),
1094 DBGFREGSUBFIELD_RW("bt", 15, 1, 0),
1095 DBGFREGSUBFIELD_TERMINATOR()
1096};
1097
1098/** Sub-fields for the DR7 register. */
1099static DBGFREGSUBFIELD const g_aCpumRegFields_dr7[] =
1100{
1101 DBGFREGSUBFIELD_RW("l0", 0, 1, 0),
1102 DBGFREGSUBFIELD_RW("g0", 1, 1, 0),
1103 DBGFREGSUBFIELD_RW("l1", 2, 1, 0),
1104 DBGFREGSUBFIELD_RW("g1", 3, 1, 0),
1105 DBGFREGSUBFIELD_RW("l2", 4, 1, 0),
1106 DBGFREGSUBFIELD_RW("g2", 5, 1, 0),
1107 DBGFREGSUBFIELD_RW("l3", 6, 1, 0),
1108 DBGFREGSUBFIELD_RW("g3", 7, 1, 0),
1109 DBGFREGSUBFIELD_RW("le", 8, 1, 0),
1110 DBGFREGSUBFIELD_RW("ge", 9, 1, 0),
1111 DBGFREGSUBFIELD_RW("gd", 13, 1, 0),
1112 DBGFREGSUBFIELD_RW("rw0", 16, 2, 0),
1113 DBGFREGSUBFIELD_RW("len0", 18, 2, 0),
1114 DBGFREGSUBFIELD_RW("rw1", 20, 2, 0),
1115 DBGFREGSUBFIELD_RW("len1", 22, 2, 0),
1116 DBGFREGSUBFIELD_RW("rw2", 24, 2, 0),
1117 DBGFREGSUBFIELD_RW("len2", 26, 2, 0),
1118 DBGFREGSUBFIELD_RW("rw3", 28, 2, 0),
1119 DBGFREGSUBFIELD_RW("len3", 30, 2, 0),
1120 DBGFREGSUBFIELD_TERMINATOR()
1121};
1122
1123/** Sub-fields for the CR_PAT MSR. */
1124static DBGFREGSUBFIELD const g_aCpumRegFields_apic_base[] =
1125{
1126 DBGFREGSUBFIELD_RW("bsp", 8, 1, 0),
1127 DBGFREGSUBFIELD_RW("ge", 9, 1, 0),
1128 DBGFREGSUBFIELD_RW("base", 12, 20, 12),
1129 DBGFREGSUBFIELD_TERMINATOR()
1130};
1131
1132/** Sub-fields for the CR_PAT MSR. */
1133static DBGFREGSUBFIELD const g_aCpumRegFields_cr_pat[] =
1134{
1135 /** @todo */
1136 DBGFREGSUBFIELD_TERMINATOR()
1137};
1138
1139/** Sub-fields for the PERF_STATUS MSR. */
1140static DBGFREGSUBFIELD const g_aCpumRegFields_perf_status[] =
1141{
1142 /** @todo */
1143 DBGFREGSUBFIELD_TERMINATOR()
1144};
1145
1146/** Sub-fields for the EFER MSR. */
1147static DBGFREGSUBFIELD const g_aCpumRegFields_efer[] =
1148{
1149 /** @todo */
1150 DBGFREGSUBFIELD_TERMINATOR()
1151};
1152
1153/** Sub-fields for the STAR MSR. */
1154static DBGFREGSUBFIELD const g_aCpumRegFields_star[] =
1155{
1156 /** @todo */
1157 DBGFREGSUBFIELD_TERMINATOR()
1158};
1159
1160/** Sub-fields for the CSTAR MSR. */
1161static DBGFREGSUBFIELD const g_aCpumRegFields_cstar[] =
1162{
1163 /** @todo */
1164 DBGFREGSUBFIELD_TERMINATOR()
1165};
1166
1167/** Sub-fields for the LSTAR MSR. */
1168static DBGFREGSUBFIELD const g_aCpumRegFields_lstar[] =
1169{
1170 /** @todo */
1171 DBGFREGSUBFIELD_TERMINATOR()
1172};
1173
1174#if 0 /** @todo */
1175/** Sub-fields for the SF_MASK MSR. */
1176static DBGFREGSUBFIELD const g_aCpumRegFields_sf_mask[] =
1177{
1178 /** @todo */
1179 DBGFREGSUBFIELD_TERMINATOR()
1180};
1181#endif
1182
1183
1184/** @name Macros for producing register descriptor table entries.
1185 * @{ */
1186#define CPU_REG_EX_AS(a_szName, a_RegSuff, a_TypeSuff, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1187 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, a_offRegister, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1188
1189#define CPU_REG_REG(UName, LName) \
1190 CPU_REG_RW_AS(#LName, UName, U64, LName, cpumR3RegGet_Generic, cpumR3RegSet_Generic, g_aCpumRegAliases_##LName, NULL)
1191
1192#define CPU_REG_SEG(UName, LName) \
1193 CPU_REG_RW_AS(#LName, UName, U16, LName.Sel, cpumR3RegGet_Generic, cpumR3RegSet_seg, NULL, NULL ), \
1194 CPU_REG_RW_AS(#LName "_attr", UName##_ATTR, U32, LName.Attr.u, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, g_aCpumRegFields_seg), \
1195 CPU_REG_RW_AS(#LName "_base", UName##_BASE, U64, LName.u64Base, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ), \
1196 CPU_REG_RW_AS(#LName "_lim", UName##_LIMIT, U32, LName.u32Limit, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL )
1197
1198#define CPU_REG_MM(n) \
1199 CPU_REG_XS_RW_AS("mm" #n, MM##n, U64, x87.aRegs[n].mmx, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_mmN)
1200
1201#define CPU_REG_XMM(n) \
1202 CPU_REG_XS_RW_AS("xmm" #n, XMM##n, U128, x87.aXMM[n].xmm, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_xmmN)
1203
1204#define CPU_REG_YMM(n) \
1205 { "ymm" #n, DBGFREG_YMM##n, DBGFREGVALTYPE_U256, 0 /*fFlags*/, n, cpumR3RegGet_ymm, cpumR3RegSet_ymm, NULL /*paAliases*/, NULL /*paSubFields*/ }
1206
1207/** @} */
1208
1209
1210/**
1211 * The guest register descriptors.
1212 */
1213static DBGFREGDESC const g_aCpumRegGstDescs[] =
1214{
1215#define CPU_REG_RW_AS(a_szName, a_RegSuff, a_TypeSuff, a_CpumCtxMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1216 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, RT_OFFSETOF(CPUMCPU, Guest.a_CpumCtxMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1217#define CPU_REG_RO_AS(a_szName, a_RegSuff, a_TypeSuff, a_CpumCtxMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1218 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, RT_OFFSETOF(CPUMCPU, Guest.a_CpumCtxMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1219#define CPU_REG_XS_RW_AS(a_szName, a_RegSuff, a_TypeSuff, a_XStateMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1220 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, RT_OFFSETOF(X86XSAVEAREA, a_XStateMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1221#define CPU_REG_XS_RO_AS(a_szName, a_RegSuff, a_TypeSuff, a_XStateMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1222 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, RT_OFFSETOF(X86XSAVEAREA, a_XStateMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1223#define CPU_REG_MSR(a_szName, UName, a_TypeSuff, a_paSubFields) \
1224 CPU_REG_EX_AS(a_szName, MSR_##UName, a_TypeSuff, MSR_##UName, cpumR3RegGstGet_msr, cpumR3RegGstSet_msr, NULL, a_paSubFields)
1225#define CPU_REG_ST(n) \
1226 CPU_REG_EX_AS("st" #n, ST##n, R80, n, cpumR3RegGstGet_stN, cpumR3RegGstSet_stN, NULL, g_aCpumRegFields_stN)
1227
1228 CPU_REG_REG(RAX, rax),
1229 CPU_REG_REG(RCX, rcx),
1230 CPU_REG_REG(RDX, rdx),
1231 CPU_REG_REG(RBX, rbx),
1232 CPU_REG_REG(RSP, rsp),
1233 CPU_REG_REG(RBP, rbp),
1234 CPU_REG_REG(RSI, rsi),
1235 CPU_REG_REG(RDI, rdi),
1236 CPU_REG_REG(R8, r8),
1237 CPU_REG_REG(R9, r9),
1238 CPU_REG_REG(R10, r10),
1239 CPU_REG_REG(R11, r11),
1240 CPU_REG_REG(R12, r12),
1241 CPU_REG_REG(R13, r13),
1242 CPU_REG_REG(R14, r14),
1243 CPU_REG_REG(R15, r15),
1244 CPU_REG_SEG(CS, cs),
1245 CPU_REG_SEG(DS, ds),
1246 CPU_REG_SEG(ES, es),
1247 CPU_REG_SEG(FS, fs),
1248 CPU_REG_SEG(GS, gs),
1249 CPU_REG_SEG(SS, ss),
1250 CPU_REG_REG(RIP, rip),
1251 CPU_REG_RW_AS("rflags", RFLAGS, U64, rflags, cpumR3RegGet_Generic, cpumR3RegSet_Generic, g_aCpumRegAliases_rflags, g_aCpumRegFields_rflags ),
1252 CPU_REG_XS_RW_AS("fcw", FCW, U16, x87.FCW, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_fcw ),
1253 CPU_REG_XS_RW_AS("fsw", FSW, U16, x87.FSW, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_fsw ),
1254 CPU_REG_XS_RO_AS("ftw", FTW, U16, x87, cpumR3RegGet_ftw, cpumR3RegSet_ftw, NULL, g_aCpumRegFields_ftw ),
1255 CPU_REG_XS_RW_AS("fop", FOP, U16, x87.FOP, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, NULL ),
1256 CPU_REG_XS_RW_AS("fpuip", FPUIP, U32, x87.FPUIP, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, g_aCpumRegAliases_fpuip, NULL ),
1257 CPU_REG_XS_RW_AS("fpucs", FPUCS, U16, x87.CS, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, NULL ),
1258 CPU_REG_XS_RW_AS("fpudp", FPUDP, U32, x87.FPUDP, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, g_aCpumRegAliases_fpudp, NULL ),
1259 CPU_REG_XS_RW_AS("fpuds", FPUDS, U16, x87.DS, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, NULL ),
1260 CPU_REG_XS_RW_AS("mxcsr", MXCSR, U32, x87.MXCSR, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_mxcsr ),
1261 CPU_REG_XS_RW_AS("mxcsr_mask", MXCSR_MASK, U32, x87.MXCSR_MASK, cpumR3RegGet_XStateGeneric, cpumR3RegSet_XStateGeneric, NULL, g_aCpumRegFields_mxcsr ),
1262 CPU_REG_ST(0),
1263 CPU_REG_ST(1),
1264 CPU_REG_ST(2),
1265 CPU_REG_ST(3),
1266 CPU_REG_ST(4),
1267 CPU_REG_ST(5),
1268 CPU_REG_ST(6),
1269 CPU_REG_ST(7),
1270 CPU_REG_MM(0),
1271 CPU_REG_MM(1),
1272 CPU_REG_MM(2),
1273 CPU_REG_MM(3),
1274 CPU_REG_MM(4),
1275 CPU_REG_MM(5),
1276 CPU_REG_MM(6),
1277 CPU_REG_MM(7),
1278 CPU_REG_XMM(0),
1279 CPU_REG_XMM(1),
1280 CPU_REG_XMM(2),
1281 CPU_REG_XMM(3),
1282 CPU_REG_XMM(4),
1283 CPU_REG_XMM(5),
1284 CPU_REG_XMM(6),
1285 CPU_REG_XMM(7),
1286 CPU_REG_XMM(8),
1287 CPU_REG_XMM(9),
1288 CPU_REG_XMM(10),
1289 CPU_REG_XMM(11),
1290 CPU_REG_XMM(12),
1291 CPU_REG_XMM(13),
1292 CPU_REG_XMM(14),
1293 CPU_REG_XMM(15),
1294 CPU_REG_YMM(0),
1295 CPU_REG_YMM(1),
1296 CPU_REG_YMM(2),
1297 CPU_REG_YMM(3),
1298 CPU_REG_YMM(4),
1299 CPU_REG_YMM(5),
1300 CPU_REG_YMM(6),
1301 CPU_REG_YMM(7),
1302 CPU_REG_YMM(8),
1303 CPU_REG_YMM(9),
1304 CPU_REG_YMM(10),
1305 CPU_REG_YMM(11),
1306 CPU_REG_YMM(12),
1307 CPU_REG_YMM(13),
1308 CPU_REG_YMM(14),
1309 CPU_REG_YMM(15),
1310 CPU_REG_RW_AS("gdtr_base", GDTR_BASE, U64, gdtr.pGdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1311 CPU_REG_RW_AS("gdtr_lim", GDTR_LIMIT, U16, gdtr.cbGdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1312 CPU_REG_RW_AS("idtr_base", IDTR_BASE, U64, idtr.pIdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1313 CPU_REG_RW_AS("idtr_lim", IDTR_LIMIT, U16, idtr.cbIdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1314 CPU_REG_SEG(LDTR, ldtr),
1315 CPU_REG_SEG(TR, tr),
1316 CPU_REG_EX_AS("cr0", CR0, U32, 0, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, g_aCpumRegAliases_cr0, g_aCpumRegFields_cr0 ),
1317 CPU_REG_EX_AS("cr2", CR2, U64, 2, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, NULL, NULL ),
1318 CPU_REG_EX_AS("cr3", CR3, U64, 3, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, NULL, g_aCpumRegFields_cr3 ),
1319 CPU_REG_EX_AS("cr4", CR4, U32, 4, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, NULL, g_aCpumRegFields_cr4 ),
1320 CPU_REG_EX_AS("cr8", CR8, U32, 8, cpumR3RegGstGet_crX, cpumR3RegGstSet_crX, NULL, NULL ),
1321 CPU_REG_EX_AS("dr0", DR0, U64, 0, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, NULL ),
1322 CPU_REG_EX_AS("dr1", DR1, U64, 1, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, NULL ),
1323 CPU_REG_EX_AS("dr2", DR2, U64, 2, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, NULL ),
1324 CPU_REG_EX_AS("dr3", DR3, U64, 3, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, NULL ),
1325 CPU_REG_EX_AS("dr6", DR6, U32, 6, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, g_aCpumRegFields_dr6 ),
1326 CPU_REG_EX_AS("dr7", DR7, U32, 7, cpumR3RegGstGet_drX, cpumR3RegGstSet_drX, NULL, g_aCpumRegFields_dr7 ),
1327 CPU_REG_MSR("apic_base", IA32_APICBASE, U32, g_aCpumRegFields_apic_base ),
1328 CPU_REG_MSR("pat", IA32_CR_PAT, U64, g_aCpumRegFields_cr_pat ),
1329 CPU_REG_MSR("perf_status", IA32_PERF_STATUS, U64, g_aCpumRegFields_perf_status),
1330 CPU_REG_MSR("sysenter_cs", IA32_SYSENTER_CS, U16, NULL ),
1331 CPU_REG_MSR("sysenter_eip", IA32_SYSENTER_EIP, U32, NULL ),
1332 CPU_REG_MSR("sysenter_esp", IA32_SYSENTER_ESP, U32, NULL ),
1333 CPU_REG_MSR("tsc", IA32_TSC, U32, NULL ),
1334 CPU_REG_MSR("efer", K6_EFER, U32, g_aCpumRegFields_efer ),
1335 CPU_REG_MSR("star", K6_STAR, U64, g_aCpumRegFields_star ),
1336 CPU_REG_MSR("cstar", K8_CSTAR, U64, g_aCpumRegFields_cstar ),
1337 CPU_REG_MSR("msr_fs_base", K8_FS_BASE, U64, NULL ),
1338 CPU_REG_MSR("msr_gs_base", K8_GS_BASE, U64, NULL ),
1339 CPU_REG_MSR("krnl_gs_base", K8_KERNEL_GS_BASE, U64, NULL ),
1340 CPU_REG_MSR("lstar", K8_LSTAR, U64, g_aCpumRegFields_lstar ),
1341 CPU_REG_MSR("sf_mask", K8_SF_MASK, U64, NULL ),
1342 CPU_REG_MSR("tsc_aux", K8_TSC_AUX, U64, NULL ),
1343 CPU_REG_EX_AS("ah", AH, U8, RT_OFFSETOF(CPUMCPU, Guest.rax) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1344 CPU_REG_EX_AS("ch", CH, U8, RT_OFFSETOF(CPUMCPU, Guest.rcx) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1345 CPU_REG_EX_AS("dh", DH, U8, RT_OFFSETOF(CPUMCPU, Guest.rdx) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1346 CPU_REG_EX_AS("bh", BH, U8, RT_OFFSETOF(CPUMCPU, Guest.rbx) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1347 CPU_REG_RW_AS("gdtr", GDTR, DTR, gdtr, cpumR3RegGet_gdtr, cpumR3RegSet_gdtr, NULL, NULL ),
1348 CPU_REG_RW_AS("idtr", IDTR, DTR, idtr, cpumR3RegGet_idtr, cpumR3RegSet_idtr, NULL, NULL ),
1349 DBGFREGDESC_TERMINATOR()
1350
1351#undef CPU_REG_RW_AS
1352#undef CPU_REG_RO_AS
1353#undef CPU_REG_MSR
1354#undef CPU_REG_ST
1355};
1356
1357
1358/**
1359 * The hypervisor (raw-mode) register descriptors.
1360 */
1361static DBGFREGDESC const g_aCpumRegHyperDescs[] =
1362{
1363#define CPU_REG_RW_AS(a_szName, a_RegSuff, a_TypeSuff, a_CpumCtxMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1364 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, 0 /*fFlags*/, RT_OFFSETOF(CPUMCPU, Hyper.a_CpumCtxMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1365#define CPU_REG_RO_AS(a_szName, a_RegSuff, a_TypeSuff, a_CpumCtxMemb, a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields) \
1366 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, RT_OFFSETOF(CPUMCPU, Hyper.a_CpumCtxMemb), a_pfnGet, a_pfnSet, a_paAliases, a_paSubFields }
1367#define CPU_REG_DUMMY(a_szName, a_RegSuff, a_TypeSuff) \
1368 { a_szName, DBGFREG_##a_RegSuff, DBGFREGVALTYPE_##a_TypeSuff, DBGFREG_FLAGS_READ_ONLY, 0, cpumR3RegGet_Dummy, cpumR3RegSet_Dummy, NULL, NULL}
1369#define CPU_REG_MSR(a_szName, UName, a_TypeSuff, a_paSubFields) \
1370 CPU_REG_EX_AS(a_szName, MSR_##UName, a_TypeSuff, MSR_##UName, cpumR3RegHyperGet_msr, cpumR3RegHyperSet_msr, NULL, a_paSubFields)
1371
1372 CPU_REG_REG(RAX, rax),
1373 CPU_REG_REG(RCX, rcx),
1374 CPU_REG_REG(RDX, rdx),
1375 CPU_REG_REG(RBX, rbx),
1376 CPU_REG_REG(RSP, rsp),
1377 CPU_REG_REG(RBP, rbp),
1378 CPU_REG_REG(RSI, rsi),
1379 CPU_REG_REG(RDI, rdi),
1380 CPU_REG_REG(R8, r8),
1381 CPU_REG_REG(R9, r9),
1382 CPU_REG_REG(R10, r10),
1383 CPU_REG_REG(R11, r11),
1384 CPU_REG_REG(R12, r12),
1385 CPU_REG_REG(R13, r13),
1386 CPU_REG_REG(R14, r14),
1387 CPU_REG_REG(R15, r15),
1388 CPU_REG_SEG(CS, cs),
1389 CPU_REG_SEG(DS, ds),
1390 CPU_REG_SEG(ES, es),
1391 CPU_REG_SEG(FS, fs),
1392 CPU_REG_SEG(GS, gs),
1393 CPU_REG_SEG(SS, ss),
1394 CPU_REG_REG(RIP, rip),
1395 CPU_REG_RW_AS("rflags", RFLAGS, U64, rflags, cpumR3RegGet_Generic, cpumR3RegSet_Generic, g_aCpumRegAliases_rflags, g_aCpumRegFields_rflags ),
1396 CPU_REG_DUMMY("fcw", FCW, U16),
1397 CPU_REG_DUMMY("fsw", FSW, U16),
1398 CPU_REG_DUMMY("ftw", FTW, U16),
1399 CPU_REG_DUMMY("fop", FOP, U16),
1400 CPU_REG_DUMMY("fpuip", FPUIP, U32),
1401 CPU_REG_DUMMY("fpucs", FPUCS, U16),
1402 CPU_REG_DUMMY("fpudp", FPUDP, U32),
1403 CPU_REG_DUMMY("fpuds", FPUDS, U16),
1404 CPU_REG_DUMMY("mxcsr", MXCSR, U32),
1405 CPU_REG_DUMMY("mxcsr_mask", MXCSR_MASK, U32),
1406 CPU_REG_DUMMY("st0", ST0, R80),
1407 CPU_REG_DUMMY("st1", ST1, R80),
1408 CPU_REG_DUMMY("st2", ST2, R80),
1409 CPU_REG_DUMMY("st3", ST3, R80),
1410 CPU_REG_DUMMY("st4", ST4, R80),
1411 CPU_REG_DUMMY("st5", ST5, R80),
1412 CPU_REG_DUMMY("st6", ST6, R80),
1413 CPU_REG_DUMMY("st7", ST7, R80),
1414 CPU_REG_DUMMY("mm0", MM0, U64),
1415 CPU_REG_DUMMY("mm1", MM1, U64),
1416 CPU_REG_DUMMY("mm2", MM2, U64),
1417 CPU_REG_DUMMY("mm3", MM3, U64),
1418 CPU_REG_DUMMY("mm4", MM4, U64),
1419 CPU_REG_DUMMY("mm5", MM5, U64),
1420 CPU_REG_DUMMY("mm6", MM6, U64),
1421 CPU_REG_DUMMY("mm7", MM7, U64),
1422 CPU_REG_DUMMY("xmm0", XMM0, U128),
1423 CPU_REG_DUMMY("xmm1", XMM1, U128),
1424 CPU_REG_DUMMY("xmm2", XMM2, U128),
1425 CPU_REG_DUMMY("xmm3", XMM3, U128),
1426 CPU_REG_DUMMY("xmm4", XMM4, U128),
1427 CPU_REG_DUMMY("xmm5", XMM5, U128),
1428 CPU_REG_DUMMY("xmm6", XMM6, U128),
1429 CPU_REG_DUMMY("xmm7", XMM7, U128),
1430 CPU_REG_DUMMY("xmm8", XMM8, U128),
1431 CPU_REG_DUMMY("xmm9", XMM9, U128),
1432 CPU_REG_DUMMY("xmm10", XMM10, U128),
1433 CPU_REG_DUMMY("xmm11", XMM11, U128),
1434 CPU_REG_DUMMY("xmm12", XMM12, U128),
1435 CPU_REG_DUMMY("xmm13", XMM13, U128),
1436 CPU_REG_DUMMY("xmm14", XMM14, U128),
1437 CPU_REG_DUMMY("xmm15", XMM15, U128),
1438 CPU_REG_DUMMY("ymm0", YMM0, U256),
1439 CPU_REG_DUMMY("ymm1", YMM1, U256),
1440 CPU_REG_DUMMY("ymm2", YMM2, U256),
1441 CPU_REG_DUMMY("ymm3", YMM3, U256),
1442 CPU_REG_DUMMY("ymm4", YMM4, U256),
1443 CPU_REG_DUMMY("ymm5", YMM5, U256),
1444 CPU_REG_DUMMY("ymm6", YMM6, U256),
1445 CPU_REG_DUMMY("ymm7", YMM7, U256),
1446 CPU_REG_DUMMY("ymm8", YMM8, U256),
1447 CPU_REG_DUMMY("ymm9", YMM9, U256),
1448 CPU_REG_DUMMY("ymm10", YMM10, U256),
1449 CPU_REG_DUMMY("ymm11", YMM11, U256),
1450 CPU_REG_DUMMY("ymm12", YMM12, U256),
1451 CPU_REG_DUMMY("ymm13", YMM13, U256),
1452 CPU_REG_DUMMY("ymm14", YMM14, U256),
1453 CPU_REG_DUMMY("ymm15", YMM15, U256),
1454 CPU_REG_RW_AS("gdtr_base", GDTR_BASE, U64, gdtr.pGdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1455 CPU_REG_RW_AS("gdtr_lim", GDTR_LIMIT, U16, gdtr.cbGdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1456 CPU_REG_RW_AS("idtr_base", IDTR_BASE, U64, idtr.pIdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1457 CPU_REG_RW_AS("idtr_lim", IDTR_LIMIT, U16, idtr.cbIdt, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1458 CPU_REG_SEG(LDTR, ldtr),
1459 CPU_REG_SEG(TR, tr),
1460 CPU_REG_EX_AS("cr0", CR0, U32, 0, cpumR3RegHyperGet_crX, cpumR3RegHyperSet_crX, g_aCpumRegAliases_cr0, g_aCpumRegFields_cr0 ),
1461 CPU_REG_EX_AS("cr2", CR2, U64, 2, cpumR3RegHyperGet_crX, cpumR3RegHyperSet_crX, NULL, NULL ),
1462 CPU_REG_EX_AS("cr3", CR3, U64, 3, cpumR3RegHyperGet_crX, cpumR3RegHyperSet_crX, NULL, g_aCpumRegFields_cr3 ),
1463 CPU_REG_EX_AS("cr4", CR4, U32, 4, cpumR3RegHyperGet_crX, cpumR3RegHyperSet_crX, NULL, g_aCpumRegFields_cr4 ),
1464 CPU_REG_EX_AS("cr8", CR8, U32, 8, cpumR3RegHyperGet_crX, cpumR3RegHyperSet_crX, NULL, NULL ),
1465 CPU_REG_EX_AS("dr0", DR0, U64, 0, cpumR3RegHyperGet_drX, cpumR3RegHyperSet_drX, NULL, NULL ),
1466 CPU_REG_EX_AS("dr1", DR1, U64, 1, cpumR3RegHyperGet_drX, cpumR3RegHyperSet_drX, NULL, NULL ),
1467 CPU_REG_EX_AS("dr2", DR2, U64, 2, cpumR3RegHyperGet_drX, cpumR3RegHyperSet_drX, NULL, NULL ),
1468 CPU_REG_EX_AS("dr3", DR3, U64, 3, cpumR3RegHyperGet_drX, cpumR3RegHyperSet_drX, NULL, NULL ),
1469 CPU_REG_EX_AS("dr6", DR6, U32, 6, cpumR3RegHyperGet_drX, cpumR3RegHyperSet_drX, NULL, g_aCpumRegFields_dr6 ),
1470 CPU_REG_EX_AS("dr7", DR7, U32, 7, cpumR3RegHyperGet_drX, cpumR3RegHyperSet_drX, NULL, g_aCpumRegFields_dr7 ),
1471 CPU_REG_MSR("apic_base", IA32_APICBASE, U32, g_aCpumRegFields_apic_base ),
1472 CPU_REG_MSR("pat", IA32_CR_PAT, U64, g_aCpumRegFields_cr_pat ),
1473 CPU_REG_MSR("perf_status", IA32_PERF_STATUS, U64, g_aCpumRegFields_perf_status),
1474 CPU_REG_MSR("sysenter_cs", IA32_SYSENTER_CS, U16, NULL ),
1475 CPU_REG_MSR("sysenter_eip", IA32_SYSENTER_EIP, U32, NULL ),
1476 CPU_REG_MSR("sysenter_esp", IA32_SYSENTER_ESP, U32, NULL ),
1477 CPU_REG_MSR("tsc", IA32_TSC, U32, NULL ),
1478 CPU_REG_MSR("efer", K6_EFER, U32, g_aCpumRegFields_efer ),
1479 CPU_REG_MSR("star", K6_STAR, U64, g_aCpumRegFields_star ),
1480 CPU_REG_MSR("cstar", K8_CSTAR, U64, g_aCpumRegFields_cstar ),
1481 CPU_REG_MSR("msr_fs_base", K8_FS_BASE, U64, NULL ),
1482 CPU_REG_MSR("msr_gs_base", K8_GS_BASE, U64, NULL ),
1483 CPU_REG_MSR("krnl_gs_base", K8_KERNEL_GS_BASE, U64, NULL ),
1484 CPU_REG_MSR("lstar", K8_LSTAR, U64, g_aCpumRegFields_lstar ),
1485 CPU_REG_MSR("sf_mask", K8_SF_MASK, U64, NULL ),
1486 CPU_REG_MSR("tsc_aux", K8_TSC_AUX, U64, NULL ),
1487 CPU_REG_EX_AS("ah", AH, U8, RT_OFFSETOF(CPUMCPU, Hyper.rax) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1488 CPU_REG_EX_AS("ch", CH, U8, RT_OFFSETOF(CPUMCPU, Hyper.rcx) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1489 CPU_REG_EX_AS("dh", DH, U8, RT_OFFSETOF(CPUMCPU, Hyper.rdx) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1490 CPU_REG_EX_AS("bh", BH, U8, RT_OFFSETOF(CPUMCPU, Hyper.rbx) + 1, cpumR3RegGet_Generic, cpumR3RegSet_Generic, NULL, NULL ),
1491 CPU_REG_RW_AS("gdtr", GDTR, DTR, gdtr, cpumR3RegGet_gdtr, cpumR3RegSet_gdtr, NULL, NULL ),
1492 CPU_REG_RW_AS("idtr", IDTR, DTR, idtr, cpumR3RegGet_idtr, cpumR3RegSet_idtr, NULL, NULL ),
1493 DBGFREGDESC_TERMINATOR()
1494#undef CPU_REG_RW_AS
1495#undef CPU_REG_RO_AS
1496#undef CPU_REG_MSR
1497#undef CPU_REG_ST
1498};
1499
1500
1501/**
1502 * Initializes the debugger related sides of the CPUM component.
1503 *
1504 * Called by CPUMR3Init.
1505 *
1506 * @returns VBox status code.
1507 * @param pVM The cross context VM structure.
1508 */
1509int cpumR3DbgInit(PVM pVM)
1510{
1511 for (VMCPUID iCpu = 0; iCpu < pVM->cCpus; iCpu++)
1512 {
1513 int rc = DBGFR3RegRegisterCpu(pVM, &pVM->aCpus[iCpu], g_aCpumRegGstDescs, true /*fGuestRegs*/);
1514 AssertLogRelRCReturn(rc, rc);
1515 rc = DBGFR3RegRegisterCpu(pVM, &pVM->aCpus[iCpu], g_aCpumRegHyperDescs, false /*fGuestRegs*/);
1516 AssertLogRelRCReturn(rc, rc);
1517 }
1518
1519 return VINF_SUCCESS;
1520}
1521
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