VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/CPUMAllRegs-armv8.cpp@ 99220

Last change on this file since 99220 was 99051, checked in by vboxsync, 15 months ago

VMM: More ARMv8 x86/amd64 separation work, VBoxVMMArm compiles and links now, bugref:10385

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.2 KB
Line 
1/* $Id: CPUMAllRegs-armv8.cpp 99051 2023-03-19 16:40:06Z vboxsync $ */
2/** @file
3 * CPUM - CPU Monitor(/Manager) - Getters and Setters, ARMv8 variant.
4 */
5
6/*
7 * Copyright (C) 2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_CPUM
33#include <VBox/vmm/cpum.h>
34#include <VBox/vmm/dbgf.h>
35#include <VBox/vmm/apic.h>
36#include <VBox/vmm/pgm.h>
37#include <VBox/vmm/mm.h>
38#include <VBox/vmm/em.h>
39#include <VBox/vmm/nem.h>
40#include <VBox/vmm/hm.h>
41#include "CPUMInternal-armv8.h"
42#include <VBox/vmm/vmcc.h>
43#include <VBox/err.h>
44#include <VBox/dis.h>
45#include <VBox/log.h>
46#include <VBox/vmm/hm.h>
47#include <VBox/vmm/tm.h>
48#include <iprt/assert.h>
49#include <iprt/asm.h>
50#ifdef IN_RING3
51# include <iprt/thread.h>
52#endif
53
54
55/*********************************************************************************************************************************
56* Defined Constants And Macros *
57*********************************************************************************************************************************/
58/**
59 * Converts a CPUMCPU::Guest pointer into a VMCPU pointer.
60 *
61 * @returns Pointer to the Virtual CPU.
62 * @param a_pGuestCtx Pointer to the guest context.
63 */
64#define CPUM_GUEST_CTX_TO_VMCPU(a_pGuestCtx) RT_FROM_MEMBER(a_pGuestCtx, VMCPU, cpum.s.Guest)
65
66/** @def CPUM_INT_ASSERT_NOT_EXTRN
67 * Macro for asserting that @a a_fNotExtrn are present.
68 *
69 * @param a_pVCpu The cross context virtual CPU structure of the calling EMT.
70 * @param a_fNotExtrn Mask of CPUMCTX_EXTRN_XXX bits to check.
71 */
72#define CPUM_INT_ASSERT_NOT_EXTRN(a_pVCpu, a_fNotExtrn) \
73 AssertMsg(!((a_pVCpu)->cpum.s.Guest.fExtrn & (a_fNotExtrn)), \
74 ("%#RX64; a_fNotExtrn=%#RX64\n", (a_pVCpu)->cpum.s.Guest.fExtrn, (a_fNotExtrn)))
75
76
77/**
78 * Queries the pointer to the internal CPUMCTX structure.
79 *
80 * @returns The CPUMCTX pointer.
81 * @param pVCpu The cross context virtual CPU structure.
82 */
83VMMDECL(PCPUMCTX) CPUMQueryGuestCtxPtr(PVMCPU pVCpu)
84{
85 return &pVCpu->cpum.s.Guest;
86}
87
88
89VMMDECL(uint64_t) CPUMGetGuestFlatPC(PVMCPU pVCpu)
90{
91 CPUM_INT_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_PC);
92 return pVCpu->cpum.s.Guest.Pc.u64;
93}
94
95
96VMMDECL(uint64_t) CPUMGetGuestFlatSP(PVMCPU pVCpu)
97{
98 CPUM_INT_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_SP);
99 AssertReleaseFailed(); /** @todo Exception level. */
100 return pVCpu->cpum.s.Guest.aSpReg[0].u64;
101}
102
103
104/**
105 * Gets the host CPU vendor.
106 *
107 * @returns CPU vendor.
108 * @param pVM The cross context VM structure.
109 */
110VMMDECL(CPUMCPUVENDOR) CPUMGetHostCpuVendor(PVM pVM)
111{
112 RT_NOREF(pVM);
113 //AssertReleaseFailed();
114 return CPUMCPUVENDOR_UNKNOWN;
115}
116
117
118/**
119 * Gets the host CPU microarchitecture.
120 *
121 * @returns CPU microarchitecture.
122 * @param pVM The cross context VM structure.
123 */
124VMMDECL(CPUMMICROARCH) CPUMGetHostMicroarch(PCVM pVM)
125{
126 RT_NOREF(pVM);
127 AssertReleaseFailed();
128 return kCpumMicroarch_Unknown;
129}
130
131
132/**
133 * Gets the guest CPU vendor.
134 *
135 * @returns CPU vendor.
136 * @param pVM The cross context VM structure.
137 */
138VMMDECL(CPUMCPUVENDOR) CPUMGetGuestCpuVendor(PVM pVM)
139{
140 RT_NOREF(pVM);
141 //AssertReleaseFailed();
142 return CPUMCPUVENDOR_UNKNOWN;
143}
144
145
146/**
147 * Gets the guest CPU microarchitecture.
148 *
149 * @returns CPU microarchitecture.
150 * @param pVM The cross context VM structure.
151 */
152VMMDECL(CPUMMICROARCH) CPUMGetGuestMicroarch(PCVM pVM)
153{
154 RT_NOREF(pVM);
155 AssertReleaseFailed();
156 return kCpumMicroarch_Unknown;
157}
158
159
160/**
161 * Gets the maximum number of physical and linear address bits supported by the
162 * guest.
163 *
164 * @param pVM The cross context VM structure.
165 * @param pcPhysAddrWidth Where to store the physical address width.
166 * @param pcLinearAddrWidth Where to store the linear address width.
167 */
168VMMDECL(void) CPUMGetGuestAddrWidths(PCVM pVM, uint8_t *pcPhysAddrWidth, uint8_t *pcLinearAddrWidth)
169{
170 AssertPtr(pVM);
171 AssertReturnVoid(pcPhysAddrWidth);
172 AssertReturnVoid(pcLinearAddrWidth);
173 AssertReleaseFailed();
174}
175
176
177/**
178 * Tests if the guest has the paging enabled (PG).
179 *
180 * @returns true if in real mode, otherwise false.
181 * @param pVCpu The cross context virtual CPU structure.
182 */
183VMMDECL(bool) CPUMIsGuestPagingEnabled(PCVMCPU pVCpu)
184{
185 RT_NOREF(pVCpu);
186 AssertReleaseFailed();
187 return false;
188}
189
190
191/**
192 * Tests if the guest is running in 64 bits mode or not.
193 *
194 * @returns true if in 64 bits protected mode, otherwise false.
195 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
196 */
197VMMDECL(bool) CPUMIsGuestIn64BitCode(PVMCPU pVCpu)
198{
199 RT_NOREF(pVCpu);
200 AssertReleaseFailed();
201 return false;
202}
203
204
205/**
206 * Helper for CPUMIsGuestIn64BitCodeEx that handles lazy resolving of hidden CS
207 * registers.
208 *
209 * @returns true if in 64 bits protected mode, otherwise false.
210 * @param pCtx Pointer to the current guest CPU context.
211 */
212VMM_INT_DECL(bool) CPUMIsGuestIn64BitCodeSlow(PCPUMCTX pCtx)
213{
214 return CPUMIsGuestIn64BitCode(CPUM_GUEST_CTX_TO_VMCPU(pCtx));
215}
216
217
218/**
219 * Sets the specified changed flags (CPUM_CHANGED_*).
220 *
221 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
222 * @param fChangedAdd The changed flags to add.
223 */
224VMMDECL(void) CPUMSetChangedFlags(PVMCPU pVCpu, uint32_t fChangedAdd)
225{
226 pVCpu->cpum.s.fChanged |= fChangedAdd;
227}
228
229
230/**
231 * Checks if the guest debug state is active.
232 *
233 * @returns boolean
234 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
235 */
236VMMDECL(bool) CPUMIsGuestDebugStateActive(PVMCPU pVCpu)
237{
238 return RT_BOOL(pVCpu->cpum.s.fUseFlags & CPUM_USED_DEBUG_REGS_GUEST);
239}
240
241
242/**
243 * Checks if the hyper debug state is active.
244 *
245 * @returns boolean
246 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
247 */
248VMMDECL(bool) CPUMIsHyperDebugStateActive(PVMCPU pVCpu)
249{
250 return RT_BOOL(pVCpu->cpum.s.fUseFlags & CPUM_USED_DEBUG_REGS_HYPER);
251}
252
253
254/**
255 * Mark the guest's debug state as inactive.
256 *
257 * @returns boolean
258 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
259 * @todo This API doesn't make sense any more.
260 */
261VMMDECL(void) CPUMDeactivateGuestDebugState(PVMCPU pVCpu)
262{
263 Assert(!(pVCpu->cpum.s.fUseFlags & (CPUM_USED_DEBUG_REGS_GUEST | CPUM_USED_DEBUG_REGS_HYPER)));
264 NOREF(pVCpu);
265}
266
267
268/**
269 * Get the current exception level of the guest.
270 *
271 * @returns EL
272 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
273 */
274VMMDECL(uint32_t) CPUMGetGuestEL(PVMCPU pVCpu)
275{
276 RT_NOREF(pVCpu);
277 AssertReleaseFailed();
278 return 0;
279}
280
281
282/**
283 * Gets the current guest CPU mode.
284 *
285 * If paging mode is what you need, check out PGMGetGuestMode().
286 *
287 * @returns The CPU mode.
288 * @param pVCpu The cross context virtual CPU structure.
289 */
290VMMDECL(CPUMMODE) CPUMGetGuestMode(PVMCPU pVCpu)
291{
292 CPUM_INT_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_PC | CPUMCTX_EXTRN_PSTATE);
293 AssertReleaseFailed();
294 return CPUMMODE_REAL;
295}
296
297
298/**
299 * Figure whether the CPU is currently executing 16, 32 or 64 bit code.
300 *
301 * @returns 16, 32 or 64.
302 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
303 */
304VMMDECL(uint32_t) CPUMGetGuestCodeBits(PVMCPU pVCpu)
305{
306 CPUM_INT_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_PC | CPUMCTX_EXTRN_PSTATE);
307 AssertReleaseFailed();
308 return 16;
309}
310
311
312VMMDECL(DISCPUMODE) CPUMGetGuestDisMode(PVMCPU pVCpu)
313{
314 CPUM_INT_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_PC | CPUMCTX_EXTRN_PSTATE);
315 AssertReleaseFailed();
316 return DISCPUMODE_16BIT;
317}
318
319
320/**
321 * Used to dynamically imports state residing in NEM or HM.
322 *
323 * This is a worker for the CPUM_IMPORT_EXTRN_RET() macro and various IEM ones.
324 *
325 * @returns VBox status code.
326 * @param pVCpu The cross context virtual CPU structure of the calling thread.
327 * @param fExtrnImport The fields to import.
328 * @thread EMT(pVCpu)
329 */
330VMM_INT_DECL(int) CPUMImportGuestStateOnDemand(PVMCPUCC pVCpu, uint64_t fExtrnImport)
331{
332 VMCPU_ASSERT_EMT(pVCpu);
333 if (pVCpu->cpum.s.Guest.fExtrn & fExtrnImport)
334 {
335 switch (pVCpu->cpum.s.Guest.fExtrn & CPUMCTX_EXTRN_KEEPER_MASK)
336 {
337 case CPUMCTX_EXTRN_KEEPER_NEM:
338 {
339 int rc = NEMImportStateOnDemand(pVCpu, fExtrnImport);
340 Assert(rc == VINF_SUCCESS || RT_FAILURE_NP(rc));
341 return rc;
342 }
343
344 default:
345 AssertLogRelMsgFailedReturn(("%#RX64 vs %#RX64\n", pVCpu->cpum.s.Guest.fExtrn, fExtrnImport), VERR_CPUM_IPE_2);
346 }
347 }
348 return VINF_SUCCESS;
349}
350
351
352/**
353 * Translates a microarchitecture enum value to the corresponding string
354 * constant.
355 *
356 * @returns Read-only string constant (omits "kCpumMicroarch_" prefix). Returns
357 * NULL if the value is invalid.
358 *
359 * @param enmMicroarch The enum value to convert.
360 *
361 * @todo Doesn't really belong here but for now there is no other Armv8 CPUM source file.
362 */
363VMMDECL(const char *) CPUMMicroarchName(CPUMMICROARCH enmMicroarch)
364{
365 switch (enmMicroarch)
366 {
367#define CASE_RET_STR(enmValue) case enmValue: return #enmValue + (sizeof("kCpumMicroarch_") - 1)
368 CASE_RET_STR(kCpumMicroarch_Apple_M1);
369#undef CASE_RET_STR
370 }
371
372 return NULL;
373}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use