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