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 |
|
---|
44 | RT_C_DECLS_BEGIN
|
---|
45 |
|
---|
46 | /** @defgroup grp_cpum The CPU Monitor / Manager API
|
---|
47 | * @ingroup grp_vmm
|
---|
48 | * @{
|
---|
49 | */
|
---|
50 |
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * System register read functions.
|
---|
54 | */
|
---|
55 | typedef enum CPUMSYSREGRDFN
|
---|
56 | {
|
---|
57 | /** Invalid zero value. */
|
---|
58 | kCpumSysRegRdFn_Invalid = 0,
|
---|
59 | /** Return the CPUMMSRRANGE::uValue. */
|
---|
60 | kCpumSysRegRdFn_FixedValue,
|
---|
61 | /** Alias to the system register range starting at the system register given by
|
---|
62 | * CPUMSYSREGRANGE::uValue. Must be used in pair with
|
---|
63 | * kCpumSysRegWrFn_Alias. */
|
---|
64 | kCpumSysRegRdFn_Alias,
|
---|
65 | /** Write only register, all read attempts cause an exception. */
|
---|
66 | kCpumSysRegRdFn_WriteOnly,
|
---|
67 |
|
---|
68 | /** Read from a GICv3 PE ICC system register. */
|
---|
69 | kCpumSysRegRdFn_GicV3Icc,
|
---|
70 |
|
---|
71 | /** End of valid system register read function indexes. */
|
---|
72 | kCpumSysRegRdFn_End
|
---|
73 | } CPUMSYSREGRDFN;
|
---|
74 |
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * System register write functions.
|
---|
78 | */
|
---|
79 | typedef enum CPUMSYSREGWRFN
|
---|
80 | {
|
---|
81 | /** Invalid zero value. */
|
---|
82 | kCpumSysRegWrFn_Invalid = 0,
|
---|
83 | /** Writes are ignored. */
|
---|
84 | kCpumSysRegWrFn_IgnoreWrite,
|
---|
85 | /** Writes cause an exception. */
|
---|
86 | kCpumSysRegWrFn_ReadOnly,
|
---|
87 | /** Alias to the system register range starting at the system register given by
|
---|
88 | * CPUMSYSREGRANGE::uValue. Must be used in pair with
|
---|
89 | * kCpumSysRegRdFn_Alias. */
|
---|
90 | kCpumSysRegWrFn_Alias,
|
---|
91 |
|
---|
92 | /** Write to a GICv3 PE ICC system register. */
|
---|
93 | kCpumSysRegWrFn_GicV3Icc,
|
---|
94 |
|
---|
95 | /** End of valid system register write function indexes. */
|
---|
96 | kCpumSysRegWrFn_End
|
---|
97 | } CPUMSYSREGWRFN;
|
---|
98 |
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * System register range.
|
---|
102 | *
|
---|
103 | * @note This is very similar to how x86/amd64 MSRs are handled.
|
---|
104 | */
|
---|
105 | typedef struct CPUMSYSREGRANGE
|
---|
106 | {
|
---|
107 | /** The first system register. [0] */
|
---|
108 | uint16_t uFirst;
|
---|
109 | /** The last system register. [2] */
|
---|
110 | uint16_t uLast;
|
---|
111 | /** The read function (CPUMMSRRDFN). [4] */
|
---|
112 | uint16_t enmRdFn;
|
---|
113 | /** The write function (CPUMMSRWRFN). [6] */
|
---|
114 | uint16_t enmWrFn;
|
---|
115 | /** The offset of the 64-bit system register value relative to the start of CPUMCPU.
|
---|
116 | * UINT16_MAX if not used by the read and write functions. [8] */
|
---|
117 | uint32_t offCpumCpu : 24;
|
---|
118 | /** Reserved for future hacks. [11] */
|
---|
119 | uint32_t fReserved : 8;
|
---|
120 | /** Padding/Reserved. [12] */
|
---|
121 | uint32_t u32Padding;
|
---|
122 | /** The init/read value. [16]
|
---|
123 | * When enmRdFn is kCpumMsrRdFn_INIT_VALUE, this is the value returned on RDMSR.
|
---|
124 | * offCpumCpu must be UINT16_MAX in that case, otherwise it must be a valid
|
---|
125 | * offset into CPUM. */
|
---|
126 | uint64_t uValue;
|
---|
127 | /** The bits to ignore when writing. [24] */
|
---|
128 | uint64_t fWrIgnMask;
|
---|
129 | /** The bits that will cause an exception when writing. [32]
|
---|
130 | * This is always checked prior to calling the write function. Using
|
---|
131 | * UINT64_MAX effectively marks the MSR as read-only. */
|
---|
132 | uint64_t fWrExcpMask;
|
---|
133 | /** The register name, if applicable. [32] */
|
---|
134 | char szName[56];
|
---|
135 |
|
---|
136 | /** The number of reads. */
|
---|
137 | STAMCOUNTER cReads;
|
---|
138 | /** The number of writes. */
|
---|
139 | STAMCOUNTER cWrites;
|
---|
140 | /** The number of times ignored bits were written. */
|
---|
141 | STAMCOUNTER cIgnoredBits;
|
---|
142 | /** The number of exceptions generated. */
|
---|
143 | STAMCOUNTER cExcp;
|
---|
144 | } CPUMSYSREGRANGE;
|
---|
145 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
146 | AssertCompileSize(CPUMSYSREGRANGE, 128);
|
---|
147 | #endif
|
---|
148 | /** Pointer to an system register range. */
|
---|
149 | typedef CPUMSYSREGRANGE *PCPUMSYSREGRANGE;
|
---|
150 | /** Pointer to a const system register range. */
|
---|
151 | typedef CPUMSYSREGRANGE const *PCCPUMSYSREGRANGE;
|
---|
152 |
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * CPU features and quirks.
|
---|
156 | * This is mostly exploded CPUID info.
|
---|
157 | */
|
---|
158 | typedef struct CPUMFEATURES
|
---|
159 | {
|
---|
160 | /** The CPU vendor (CPUMCPUVENDOR). */
|
---|
161 | uint8_t enmCpuVendor;
|
---|
162 | /** The CPU family. */
|
---|
163 | uint8_t uFamily;
|
---|
164 | /** The CPU model. */
|
---|
165 | uint8_t uModel;
|
---|
166 | /** The CPU stepping. */
|
---|
167 | uint8_t uStepping;
|
---|
168 | /** The microarchitecture. */
|
---|
169 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
170 | CPUMMICROARCH enmMicroarch;
|
---|
171 | #else
|
---|
172 | uint32_t enmMicroarch;
|
---|
173 | #endif
|
---|
174 | /** The maximum physical address width of the CPU. */
|
---|
175 | uint8_t cMaxPhysAddrWidth;
|
---|
176 | /** The maximum linear address width of the CPU. */
|
---|
177 | uint8_t cMaxLinearAddrWidth;
|
---|
178 |
|
---|
179 | /** Padding to the required size to match CPUMFEATURES for x86/amd64. */
|
---|
180 | uint8_t abPadding[48 - 10];
|
---|
181 | } CPUMFEATURES;
|
---|
182 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
183 | AssertCompileSize(CPUMFEATURES, 48);
|
---|
184 | #endif
|
---|
185 | /** Pointer to a CPU feature structure. */
|
---|
186 | typedef CPUMFEATURES *PCPUMFEATURES;
|
---|
187 | /** Pointer to a const CPU feature structure. */
|
---|
188 | typedef CPUMFEATURES const *PCCPUMFEATURES;
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Chameleon wrapper structure for the host CPU features.
|
---|
192 | *
|
---|
193 | * This is used for the globally readable g_CpumHostFeatures variable, which is
|
---|
194 | * initialized once during VMMR0 load for ring-0 and during CPUMR3Init in
|
---|
195 | * ring-3. To reflect this immutability after load/init, we use this wrapper
|
---|
196 | * structure to switch it between const and non-const depending on the context.
|
---|
197 | * Only two files sees it as non-const (CPUMR0.cpp and CPUM.cpp).
|
---|
198 | */
|
---|
199 | typedef struct CPUHOSTFEATURES
|
---|
200 | {
|
---|
201 | CPUMFEATURES
|
---|
202 | #ifndef CPUM_WITH_NONCONST_HOST_FEATURES
|
---|
203 | const
|
---|
204 | #endif
|
---|
205 | s;
|
---|
206 | } CPUHOSTFEATURES;
|
---|
207 | /** Pointer to a const host CPU feature structure. */
|
---|
208 | typedef CPUHOSTFEATURES const *PCCPUHOSTFEATURES;
|
---|
209 |
|
---|
210 | /** Host CPU features.
|
---|
211 | * @note In ring-3, only valid after CPUMR3Init. In ring-0, valid after
|
---|
212 | * module init. */
|
---|
213 | extern CPUHOSTFEATURES g_CpumHostFeatures;
|
---|
214 |
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * CPU database entry.
|
---|
218 | */
|
---|
219 | typedef struct CPUMDBENTRY
|
---|
220 | {
|
---|
221 | /** The CPU name. */
|
---|
222 | const char *pszName;
|
---|
223 | /** The full CPU name. */
|
---|
224 | const char *pszFullName;
|
---|
225 | /** The CPU vendor (CPUMCPUVENDOR). */
|
---|
226 | uint8_t enmVendor;
|
---|
227 | /** The CPU family. */
|
---|
228 | uint8_t uFamily;
|
---|
229 | /** The CPU model. */
|
---|
230 | uint8_t uModel;
|
---|
231 | /** The CPU stepping. */
|
---|
232 | uint8_t uStepping;
|
---|
233 | /** The microarchitecture. */
|
---|
234 | CPUMMICROARCH enmMicroarch;
|
---|
235 | /** Scalable bus frequency used for reporting other frequencies. */
|
---|
236 | uint64_t uScalableBusFreq;
|
---|
237 | /** Flags - CPUMDB_F_XXX. */
|
---|
238 | uint32_t fFlags;
|
---|
239 | /** The maximum physical address with of the CPU. This should correspond to
|
---|
240 | * the value in CPUID leaf 0x80000008 when present. */
|
---|
241 | uint8_t cMaxPhysAddrWidth;
|
---|
242 | } CPUMDBENTRY;
|
---|
243 | /** Pointer to a const CPU database entry. */
|
---|
244 | typedef CPUMDBENTRY const *PCCPUMDBENTRY;
|
---|
245 |
|
---|
246 |
|
---|
247 | /** @name Changed flags.
|
---|
248 | * These flags are used to keep track of which important register that
|
---|
249 | * have been changed since last they were reset. The only one allowed
|
---|
250 | * to clear them is REM!
|
---|
251 | *
|
---|
252 | * @todo This is obsolete, but remains as it will be refactored for coordinating
|
---|
253 | * IEM and NEM/HM later. Probably.
|
---|
254 | * @{
|
---|
255 | */
|
---|
256 | #define CPUM_CHANGED_GLOBAL_TLB_FLUSH RT_BIT(0)
|
---|
257 | #define CPUM_CHANGED_ALL ( CPUM_CHANGED_GLOBAL_TLB_FLUSH )
|
---|
258 | /** @} */
|
---|
259 |
|
---|
260 |
|
---|
261 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
262 |
|
---|
263 | #ifdef IN_RING3
|
---|
264 | /** @defgroup grp_cpum_armv8_r3 The CPUM ARMv8 ring-3 API
|
---|
265 | * @{
|
---|
266 | */
|
---|
267 |
|
---|
268 | VMMR3DECL(int) CPUMR3SysRegRangesInsert(PVM pVM, PCCPUMSYSREGRANGE pNewRange);
|
---|
269 |
|
---|
270 | /** @} */
|
---|
271 | #endif /* IN_RING3 */
|
---|
272 |
|
---|
273 |
|
---|
274 | /** @name Guest Register Getters.
|
---|
275 | * @{ */
|
---|
276 | VMMDECL(bool) CPUMGetGuestIrqMasked(PVMCPUCC pVCpu);
|
---|
277 | VMMDECL(bool) CPUMGetGuestFiqMasked(PVMCPUCC pVCpu);
|
---|
278 | VMMDECL(VBOXSTRICTRC) CPUMQueryGuestSysReg(PVMCPUCC pVCpu, uint32_t idSysReg, uint64_t *puValue);
|
---|
279 | /** @} */
|
---|
280 |
|
---|
281 |
|
---|
282 | /** @name Guest Register Setters.
|
---|
283 | * @{ */
|
---|
284 | VMMDECL(VBOXSTRICTRC) CPUMSetGuestSysReg(PVMCPUCC pVCpu, uint32_t idSysReg, uint64_t uValue);
|
---|
285 | /** @} */
|
---|
286 |
|
---|
287 | #endif
|
---|
288 |
|
---|
289 | /** @} */
|
---|
290 | RT_C_DECLS_END
|
---|
291 |
|
---|
292 |
|
---|
293 | #endif /* !VBOX_INCLUDED_vmm_cpum_armv8_h */
|
---|
294 |
|
---|