VirtualBox

source: vbox/trunk/include/VBox/vmm/cpum-armv8.h@ 100728

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

VMM/ARM: Some preliminary saved state handling and logging for the vCPU state, bugref:10387 [missing file]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/** @file
2 * CPUM - CPU Monitor(/ Manager).
3 */
4
5/*
6 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef VBOX_INCLUDED_vmm_cpum_armv8_h
37#define VBOX_INCLUDED_vmm_cpum_armv8_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <VBox/types.h>
43#include <iprt/armv8.h>
44
45
46RT_C_DECLS_BEGIN
47
48/** @defgroup grp_cpum The CPU Monitor / Manager API
49 * @ingroup grp_vmm
50 * @{
51 */
52
53
54/**
55 * System register read functions.
56 */
57typedef enum CPUMSYSREGRDFN
58{
59 /** Invalid zero value. */
60 kCpumSysRegRdFn_Invalid = 0,
61 /** Return the CPUMMSRRANGE::uValue. */
62 kCpumSysRegRdFn_FixedValue,
63 /** Alias to the system register range starting at the system register given by
64 * CPUMSYSREGRANGE::uValue. Must be used in pair with
65 * kCpumSysRegWrFn_Alias. */
66 kCpumSysRegRdFn_Alias,
67 /** Write only register, all read attempts cause an exception. */
68 kCpumSysRegRdFn_WriteOnly,
69
70 /** Read from a GICv3 PE ICC system register. */
71 kCpumSysRegRdFn_GicV3Icc,
72 /** Read from the OSLSR_EL1 syste register. */
73 kCpumSysRegRdFn_OslsrEl1,
74
75 /** End of valid system register read function indexes. */
76 kCpumSysRegRdFn_End
77} CPUMSYSREGRDFN;
78
79
80/**
81 * System register write functions.
82 */
83typedef enum CPUMSYSREGWRFN
84{
85 /** Invalid zero value. */
86 kCpumSysRegWrFn_Invalid = 0,
87 /** Writes are ignored. */
88 kCpumSysRegWrFn_IgnoreWrite,
89 /** Writes cause an exception. */
90 kCpumSysRegWrFn_ReadOnly,
91 /** Alias to the system register range starting at the system register given by
92 * CPUMSYSREGRANGE::uValue. Must be used in pair with
93 * kCpumSysRegRdFn_Alias. */
94 kCpumSysRegWrFn_Alias,
95
96 /** Write to a GICv3 PE ICC system register. */
97 kCpumSysRegWrFn_GicV3Icc,
98 /** Write to the OSLAR_EL1 syste register. */
99 kCpumSysRegWrFn_OslarEl1,
100
101 /** End of valid system register write function indexes. */
102 kCpumSysRegWrFn_End
103} CPUMSYSREGWRFN;
104
105
106/**
107 * System register range.
108 *
109 * @note This is very similar to how x86/amd64 MSRs are handled.
110 */
111typedef struct CPUMSYSREGRANGE
112{
113 /** The first system register. [0] */
114 uint16_t uFirst;
115 /** The last system register. [2] */
116 uint16_t uLast;
117 /** The read function (CPUMMSRRDFN). [4] */
118 uint16_t enmRdFn;
119 /** The write function (CPUMMSRWRFN). [6] */
120 uint16_t enmWrFn;
121 /** The offset of the 64-bit system register value relative to the start of CPUMCPU.
122 * UINT16_MAX if not used by the read and write functions. [8] */
123 uint32_t offCpumCpu : 24;
124 /** Reserved for future hacks. [11] */
125 uint32_t fReserved : 8;
126 /** Padding/Reserved. [12] */
127 uint32_t u32Padding;
128 /** The init/read value. [16]
129 * When enmRdFn is kCpumMsrRdFn_INIT_VALUE, this is the value returned on RDMSR.
130 * offCpumCpu must be UINT16_MAX in that case, otherwise it must be a valid
131 * offset into CPUM. */
132 uint64_t uValue;
133 /** The bits to ignore when writing. [24] */
134 uint64_t fWrIgnMask;
135 /** The bits that will cause an exception when writing. [32]
136 * This is always checked prior to calling the write function. Using
137 * UINT64_MAX effectively marks the MSR as read-only. */
138 uint64_t fWrExcpMask;
139 /** The register name, if applicable. [32] */
140 char szName[56];
141
142 /** The number of reads. */
143 STAMCOUNTER cReads;
144 /** The number of writes. */
145 STAMCOUNTER cWrites;
146 /** The number of times ignored bits were written. */
147 STAMCOUNTER cIgnoredBits;
148 /** The number of exceptions generated. */
149 STAMCOUNTER cExcp;
150} CPUMSYSREGRANGE;
151#ifndef VBOX_FOR_DTRACE_LIB
152AssertCompileSize(CPUMSYSREGRANGE, 128);
153#endif
154/** Pointer to an system register range. */
155typedef CPUMSYSREGRANGE *PCPUMSYSREGRANGE;
156/** Pointer to a const system register range. */
157typedef CPUMSYSREGRANGE const *PCCPUMSYSREGRANGE;
158
159
160/**
161 * CPU features and quirks.
162 * This is mostly exploded CPUID info.
163 */
164typedef struct CPUMFEATURES
165{
166 /** The CPU vendor (CPUMCPUVENDOR). */
167 uint8_t enmCpuVendor;
168 /** The CPU family. */
169 uint8_t uFamily;
170 /** The CPU model. */
171 uint8_t uModel;
172 /** The CPU stepping. */
173 uint8_t uStepping;
174 /** The microarchitecture. */
175#ifndef VBOX_FOR_DTRACE_LIB
176 CPUMMICROARCH enmMicroarch;
177#else
178 uint32_t enmMicroarch;
179#endif
180 /** The maximum physical address width of the CPU. */
181 uint8_t cMaxPhysAddrWidth;
182 /** The maximum linear address width of the CPU. */
183 uint8_t cMaxLinearAddrWidth;
184
185 /** Padding to the required size to match CPUMFEATURES for x86/amd64. */
186 uint8_t abPadding[48 - 10];
187} CPUMFEATURES;
188#ifndef VBOX_FOR_DTRACE_LIB
189AssertCompileSize(CPUMFEATURES, 48);
190#endif
191/** Pointer to a CPU feature structure. */
192typedef CPUMFEATURES *PCPUMFEATURES;
193/** Pointer to a const CPU feature structure. */
194typedef CPUMFEATURES const *PCCPUMFEATURES;
195
196/**
197 * Chameleon wrapper structure for the host CPU features.
198 *
199 * This is used for the globally readable g_CpumHostFeatures variable, which is
200 * initialized once during VMMR0 load for ring-0 and during CPUMR3Init in
201 * ring-3. To reflect this immutability after load/init, we use this wrapper
202 * structure to switch it between const and non-const depending on the context.
203 * Only two files sees it as non-const (CPUMR0.cpp and CPUM.cpp).
204 */
205typedef struct CPUHOSTFEATURES
206{
207 CPUMFEATURES
208#ifndef CPUM_WITH_NONCONST_HOST_FEATURES
209 const
210#endif
211 s;
212} CPUHOSTFEATURES;
213/** Pointer to a const host CPU feature structure. */
214typedef CPUHOSTFEATURES const *PCCPUHOSTFEATURES;
215
216/** Host CPU features.
217 * @note In ring-3, only valid after CPUMR3Init. In ring-0, valid after
218 * module init. */
219extern CPUHOSTFEATURES g_CpumHostFeatures;
220
221
222/**
223 * CPU database entry.
224 */
225typedef struct CPUMDBENTRY
226{
227 /** The CPU name. */
228 const char *pszName;
229 /** The full CPU name. */
230 const char *pszFullName;
231 /** The CPU vendor (CPUMCPUVENDOR). */
232 uint8_t enmVendor;
233 /** The CPU family. */
234 uint8_t uFamily;
235 /** The CPU model. */
236 uint8_t uModel;
237 /** The CPU stepping. */
238 uint8_t uStepping;
239 /** The microarchitecture. */
240 CPUMMICROARCH enmMicroarch;
241 /** Scalable bus frequency used for reporting other frequencies. */
242 uint64_t uScalableBusFreq;
243 /** Flags - CPUMDB_F_XXX. */
244 uint32_t fFlags;
245 /** The maximum physical address with of the CPU. This should correspond to
246 * the value in CPUID leaf 0x80000008 when present. */
247 uint8_t cMaxPhysAddrWidth;
248} CPUMDBENTRY;
249/** Pointer to a const CPU database entry. */
250typedef CPUMDBENTRY const *PCCPUMDBENTRY;
251
252
253/** @name Changed flags.
254 * These flags are used to keep track of which important register that
255 * have been changed since last they were reset. The only one allowed
256 * to clear them is REM!
257 *
258 * @todo This is obsolete, but remains as it will be refactored for coordinating
259 * IEM and NEM/HM later. Probably.
260 * @{
261 */
262#define CPUM_CHANGED_GLOBAL_TLB_FLUSH RT_BIT(0)
263#define CPUM_CHANGED_ALL ( CPUM_CHANGED_GLOBAL_TLB_FLUSH )
264/** @} */
265
266
267#if !defined(IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS) || defined(DOXYGEN_RUNNING)
268/** @name Inlined Guest Getters and predicates Functions.
269 * @{ */
270
271/**
272 * Tests if the guest is running in 64 bits mode or not.
273 *
274 * @returns true if in 64 bits mode, otherwise false.
275 * @param pCtx Current CPU context.
276 */
277DECLINLINE(bool) CPUMIsGuestIn64BitCodeEx(PCPUMCTX pCtx)
278{
279 return !RT_BOOL(pCtx->fPState & ARMV8_SPSR_EL2_AARCH64_M4);
280}
281
282/** @} */
283#endif /* !IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS || DOXYGEN_RUNNING */
284
285
286#ifndef VBOX_FOR_DTRACE_LIB
287
288#ifdef IN_RING3
289/** @defgroup grp_cpum_armv8_r3 The CPUM ARMv8 ring-3 API
290 * @{
291 */
292
293VMMR3DECL(int) CPUMR3SysRegRangesInsert(PVM pVM, PCCPUMSYSREGRANGE pNewRange);
294
295/** @} */
296#endif /* IN_RING3 */
297
298
299/** @name Guest Register Getters.
300 * @{ */
301VMMDECL(bool) CPUMGetGuestIrqMasked(PVMCPUCC pVCpu);
302VMMDECL(bool) CPUMGetGuestFiqMasked(PVMCPUCC pVCpu);
303VMMDECL(VBOXSTRICTRC) CPUMQueryGuestSysReg(PVMCPUCC pVCpu, uint32_t idSysReg, uint64_t *puValue);
304/** @} */
305
306
307/** @name Guest Register Setters.
308 * @{ */
309VMMDECL(VBOXSTRICTRC) CPUMSetGuestSysReg(PVMCPUCC pVCpu, uint32_t idSysReg, uint64_t uValue);
310/** @} */
311
312#endif
313
314/** @} */
315RT_C_DECLS_END
316
317
318#endif /* !VBOX_INCLUDED_vmm_cpum_armv8_h */
319
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