VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/DBGFCpu.cpp@ 80191

Last change on this file since 80191 was 80191, checked in by vboxsync, 5 years ago

VMM/r3: Refactored VMCPU enumeration in preparation that aCpus will be replaced with a pointer array. Removed two raw-mode offset members from the CPUM and CPUMCPU sub-structures. bugref:9217 bugref:9517

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/* $Id: DBGFCpu.cpp 80191 2019-08-08 00:36:57Z vboxsync $ */
2/** @file
3 * DBGF - Debugger Facility, CPU State Accessors.
4 */
5
6/*
7 * Copyright (C) 2009-2019 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 VBOX_BUGREF_9217_PART_I
23#define LOG_GROUP LOG_GROUP_DBGF
24#define VMCPU_INCL_CPUM_GST_CTX /* For CPUM_IMPORT_EXTRN_RET(). */
25#include <VBox/vmm/dbgf.h>
26#include <VBox/vmm/cpum.h>
27#include "DBGFInternal.h"
28#include <VBox/vmm/vm.h>
29#include <VBox/vmm/uvm.h>
30#include <iprt/errcore.h>
31#include <VBox/log.h>
32#include <VBox/param.h>
33#include <iprt/assert.h>
34
35
36/**
37 * Wrapper around CPUMGetGuestMode.
38 *
39 * @returns VINF_SUCCESS.
40 * @param pVM The cross context VM structure.
41 * @param idCpu The current CPU ID.
42 * @param penmMode Where to return the mode.
43 */
44static DECLCALLBACK(int) dbgfR3CpuGetMode(PVM pVM, VMCPUID idCpu, CPUMMODE *penmMode)
45{
46 Assert(idCpu == VMMGetCpuId(pVM));
47 PVMCPU pVCpu = VMMGetCpuById(pVM, idCpu);
48 CPUM_IMPORT_EXTRN_RET(pVCpu, CPUMCTX_EXTRN_CR0 | CPUMCTX_EXTRN_EFER);
49 *penmMode = CPUMGetGuestMode(pVCpu);
50 return VINF_SUCCESS;
51}
52
53
54/**
55 * Get the current CPU mode.
56 *
57 * @returns The CPU mode on success, CPUMMODE_INVALID on failure.
58 * @param pUVM The user mode VM handle.
59 * @param idCpu The target CPU ID.
60 */
61VMMR3DECL(CPUMMODE) DBGFR3CpuGetMode(PUVM pUVM, VMCPUID idCpu)
62{
63 UVM_ASSERT_VALID_EXT_RETURN(pUVM, CPUMMODE_INVALID);
64 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, CPUMMODE_INVALID);
65 AssertReturn(idCpu < pUVM->pVM->cCpus, CPUMMODE_INVALID);
66
67 CPUMMODE enmMode;
68 int rc = VMR3ReqPriorityCallWaitU(pUVM, idCpu, (PFNRT)dbgfR3CpuGetMode, 3, pUVM->pVM, idCpu, &enmMode);
69 if (RT_FAILURE(rc))
70 return CPUMMODE_INVALID;
71 return enmMode;
72}
73
74
75/**
76 * Wrapper around CPUMIsGuestIn64BitCode.
77 *
78 * @returns VINF_SUCCESS.
79 * @param pVM The cross context VM structure.
80 * @param idCpu The current CPU ID.
81 * @param pfIn64BitCode Where to return the result.
82 */
83static DECLCALLBACK(int) dbgfR3CpuIn64BitCode(PVM pVM, VMCPUID idCpu, bool *pfIn64BitCode)
84{
85 Assert(idCpu == VMMGetCpuId(pVM));
86 PVMCPU pVCpu = VMMGetCpuById(pVM, idCpu);
87 CPUM_IMPORT_EXTRN_RET(pVCpu, CPUMCTX_EXTRN_CS | CPUMCTX_EXTRN_EFER);
88 *pfIn64BitCode = CPUMIsGuestIn64BitCode(pVCpu);
89 return VINF_SUCCESS;
90}
91
92
93/**
94 * Checks if the given CPU is executing 64-bit code or not.
95 *
96 * @returns true / false accordingly.
97 * @param pUVM The user mode VM handle.
98 * @param idCpu The target CPU ID.
99 */
100VMMR3DECL(bool) DBGFR3CpuIsIn64BitCode(PUVM pUVM, VMCPUID idCpu)
101{
102 UVM_ASSERT_VALID_EXT_RETURN(pUVM, false);
103 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, false);
104 AssertReturn(idCpu < pUVM->pVM->cCpus, false);
105
106 bool fIn64BitCode;
107 int rc = VMR3ReqPriorityCallWaitU(pUVM, idCpu, (PFNRT)dbgfR3CpuIn64BitCode, 3, pUVM->pVM, idCpu, &fIn64BitCode);
108 if (RT_FAILURE(rc))
109 return false;
110 return fIn64BitCode;
111}
112
113
114/**
115 * Wrapper around CPUMIsGuestInV86Code.
116 *
117 * @returns VINF_SUCCESS.
118 * @param pVM The cross context VM structure.
119 * @param idCpu The current CPU ID.
120 * @param pfInV86Code Where to return the result.
121 */
122static DECLCALLBACK(int) dbgfR3CpuInV86Code(PVM pVM, VMCPUID idCpu, bool *pfInV86Code)
123{
124 Assert(idCpu == VMMGetCpuId(pVM));
125 PVMCPU pVCpu = VMMGetCpuById(pVM, idCpu);
126 CPUM_IMPORT_EXTRN_RET(pVCpu, CPUMCTX_EXTRN_RFLAGS);
127 *pfInV86Code = CPUMIsGuestInV86ModeEx(CPUMQueryGuestCtxPtr(pVCpu));
128 return VINF_SUCCESS;
129}
130
131
132/**
133 * Checks if the given CPU is executing V8086 code or not.
134 *
135 * @returns true / false accordingly.
136 * @param pUVM The user mode VM handle.
137 * @param idCpu The target CPU ID.
138 */
139VMMR3DECL(bool) DBGFR3CpuIsInV86Code(PUVM pUVM, VMCPUID idCpu)
140{
141 UVM_ASSERT_VALID_EXT_RETURN(pUVM, false);
142 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, false);
143 AssertReturn(idCpu < pUVM->pVM->cCpus, false);
144
145 bool fInV86Code;
146 int rc = VMR3ReqPriorityCallWaitU(pUVM, idCpu, (PFNRT)dbgfR3CpuInV86Code, 3, pUVM->pVM, idCpu, &fInV86Code);
147 if (RT_FAILURE(rc))
148 return false;
149 return fInV86Code;
150}
151
152
153/**
154 * Get the number of CPUs (or threads if you insist).
155 *
156 * @returns The number of CPUs
157 * @param pUVM The user mode VM handle.
158 */
159VMMR3DECL(VMCPUID) DBGFR3CpuGetCount(PUVM pUVM)
160{
161 UVM_ASSERT_VALID_EXT_RETURN(pUVM, 1);
162 return pUVM->cCpus;
163}
164
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