1 | /** @file
|
---|
2 | * CPUM - CPU Monitor(/ Manager).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2024 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 |
|
---|
46 | RT_C_DECLS_BEGIN
|
---|
47 |
|
---|
48 | /** @defgroup grp_cpum_armv8 The CPU Monitor / Manager API
|
---|
49 | * @ingroup grp_vmm
|
---|
50 | * @{
|
---|
51 | */
|
---|
52 |
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * System register read functions.
|
---|
56 | */
|
---|
57 | typedef 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 | /** Read the value from the given offset from the beginning of CPUMGSTCTX. */
|
---|
70 | kCpumSysRegRdFn_ReadCpumOff,
|
---|
71 |
|
---|
72 | /** Read from a GIC PE ICC system register. */
|
---|
73 | kCpumSysRegRdFn_GicIcc,
|
---|
74 | /** Read from the OSLSR_EL1 syste register. */
|
---|
75 | kCpumSysRegRdFn_OslsrEl1,
|
---|
76 | /** Read from a PMU system register. */
|
---|
77 | kCpumSysRegRdFn_Pmu,
|
---|
78 |
|
---|
79 | /** End of valid system register read function indexes. */
|
---|
80 | kCpumSysRegRdFn_End
|
---|
81 | } CPUMSYSREGRDFN;
|
---|
82 |
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * System register write functions.
|
---|
86 | */
|
---|
87 | typedef enum CPUMSYSREGWRFN
|
---|
88 | {
|
---|
89 | /** Invalid zero value. */
|
---|
90 | kCpumSysRegWrFn_Invalid = 0,
|
---|
91 | /** Writes are ignored. */
|
---|
92 | kCpumSysRegWrFn_IgnoreWrite,
|
---|
93 | /** Writes cause an exception. */
|
---|
94 | kCpumSysRegWrFn_ReadOnly,
|
---|
95 | /** Alias to the system register range starting at the system register given by
|
---|
96 | * CPUMSYSREGRANGE::uValue. Must be used in pair with
|
---|
97 | * kCpumSysRegRdFn_Alias. */
|
---|
98 | kCpumSysRegWrFn_Alias,
|
---|
99 | /** Write the value to the given offset from the beginning of CPUMGSTCTX. */
|
---|
100 | kCpumSysRegWrFn_WriteCpumOff,
|
---|
101 |
|
---|
102 | /** Write to a GIC PE ICC system register. */
|
---|
103 | kCpumSysRegWrFn_GicIcc,
|
---|
104 | /** Write to the OSLAR_EL1 syste register. */
|
---|
105 | kCpumSysRegWrFn_OslarEl1,
|
---|
106 | /** Write to a PMU system register. */
|
---|
107 | kCpumSysRegWrFn_Pmu,
|
---|
108 |
|
---|
109 | /** End of valid system register write function indexes. */
|
---|
110 | kCpumSysRegWrFn_End
|
---|
111 | } CPUMSYSREGWRFN;
|
---|
112 |
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * System register range.
|
---|
116 | *
|
---|
117 | * @note This is very similar to how x86/amd64 MSRs are handled.
|
---|
118 | */
|
---|
119 | typedef struct CPUMSYSREGRANGE
|
---|
120 | {
|
---|
121 | /** The first system register. [0] */
|
---|
122 | uint16_t uFirst;
|
---|
123 | /** The last system register. [2] */
|
---|
124 | uint16_t uLast;
|
---|
125 | /** The read function (CPUMMSRRDFN). [4] */
|
---|
126 | uint16_t enmRdFn;
|
---|
127 | /** The write function (CPUMMSRWRFN). [6] */
|
---|
128 | uint16_t enmWrFn;
|
---|
129 | /** The offset of the 64-bit system register value relative to the start of CPUMCPU.
|
---|
130 | * UINT16_MAX if not used by the read and write functions. [8] */
|
---|
131 | uint32_t offCpumCpu : 24;
|
---|
132 | /** Reserved for future hacks. [11] */
|
---|
133 | uint32_t fReserved : 8;
|
---|
134 | /** Padding/Reserved. [12] */
|
---|
135 | uint32_t u32Padding;
|
---|
136 | /** The init/read value. [16]
|
---|
137 | * When enmRdFn is kCpumMsrRdFn_INIT_VALUE, this is the value returned on RDMSR.
|
---|
138 | * offCpumCpu must be UINT16_MAX in that case, otherwise it must be a valid
|
---|
139 | * offset into CPUM. */
|
---|
140 | uint64_t uValue;
|
---|
141 | /** The bits to ignore when writing. [24] */
|
---|
142 | uint64_t fWrIgnMask;
|
---|
143 | /** The bits that will cause an exception when writing. [32]
|
---|
144 | * This is always checked prior to calling the write function. Using
|
---|
145 | * UINT64_MAX effectively marks the MSR as read-only. */
|
---|
146 | uint64_t fWrExcpMask;
|
---|
147 | /** The register name, if applicable. [32] */
|
---|
148 | char szName[56];
|
---|
149 |
|
---|
150 | /** The number of reads. */
|
---|
151 | STAMCOUNTER cReads;
|
---|
152 | /** The number of writes. */
|
---|
153 | STAMCOUNTER cWrites;
|
---|
154 | /** The number of times ignored bits were written. */
|
---|
155 | STAMCOUNTER cIgnoredBits;
|
---|
156 | /** The number of exceptions generated. */
|
---|
157 | STAMCOUNTER cExcp;
|
---|
158 | } CPUMSYSREGRANGE;
|
---|
159 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
160 | AssertCompileSize(CPUMSYSREGRANGE, 128);
|
---|
161 | #endif
|
---|
162 | /** Pointer to an system register range. */
|
---|
163 | typedef CPUMSYSREGRANGE *PCPUMSYSREGRANGE;
|
---|
164 | /** Pointer to a const system register range. */
|
---|
165 | typedef CPUMSYSREGRANGE const *PCCPUMSYSREGRANGE;
|
---|
166 |
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * CPU database entry.
|
---|
170 | */
|
---|
171 | typedef struct CPUMDBENTRY
|
---|
172 | {
|
---|
173 | /** The CPU name. */
|
---|
174 | const char *pszName;
|
---|
175 | /** The full CPU name. */
|
---|
176 | const char *pszFullName;
|
---|
177 | /** The CPU vendor (CPUMCPUVENDOR). */
|
---|
178 | uint8_t enmVendor;
|
---|
179 | /** The CPU family. */
|
---|
180 | uint8_t uFamily;
|
---|
181 | /** The CPU model. */
|
---|
182 | uint8_t uModel;
|
---|
183 | /** The CPU stepping. */
|
---|
184 | uint8_t uStepping;
|
---|
185 | /** The microarchitecture. */
|
---|
186 | CPUMMICROARCH enmMicroarch;
|
---|
187 | /** Scalable bus frequency used for reporting other frequencies. */
|
---|
188 | uint64_t uScalableBusFreq;
|
---|
189 | /** Flags - CPUMDB_F_XXX. */
|
---|
190 | uint32_t fFlags;
|
---|
191 | /** The maximum physical address with of the CPU. This should correspond to
|
---|
192 | * the value in CPUID leaf 0x80000008 when present. */
|
---|
193 | uint8_t cMaxPhysAddrWidth;
|
---|
194 | } CPUMDBENTRY;
|
---|
195 | /** Pointer to a const CPU database entry. */
|
---|
196 | typedef CPUMDBENTRY const *PCCPUMDBENTRY;
|
---|
197 |
|
---|
198 |
|
---|
199 |
|
---|
200 | /** @name Changed flags.
|
---|
201 | * These flags are used to keep track of which important register that
|
---|
202 | * have been changed since last they were reset. The only one allowed
|
---|
203 | * to clear them is REM!
|
---|
204 | *
|
---|
205 | * @todo This is obsolete, but remains as it will be refactored for coordinating
|
---|
206 | * IEM and NEM/HM later. Probably.
|
---|
207 | * @{
|
---|
208 | */
|
---|
209 | #define CPUM_CHANGED_GLOBAL_TLB_FLUSH RT_BIT(0)
|
---|
210 | #define CPUM_CHANGED_ALL ( CPUM_CHANGED_GLOBAL_TLB_FLUSH )
|
---|
211 | /** @} */
|
---|
212 |
|
---|
213 |
|
---|
214 | #if !defined(IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS) || defined(DOXYGEN_RUNNING)
|
---|
215 | /** @name Inlined Guest Getters and predicates Functions.
|
---|
216 | * @{ */
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * Tests if the guest is running in 64 bits mode or not.
|
---|
220 | *
|
---|
221 | * @returns true if in 64 bits mode, otherwise false.
|
---|
222 | * @param pCtx Current CPU context.
|
---|
223 | */
|
---|
224 | DECLINLINE(bool) CPUMIsGuestIn64BitCodeEx(PCCPUMCTX pCtx)
|
---|
225 | {
|
---|
226 | return !RT_BOOL(pCtx->fPState & ARMV8_SPSR_EL2_AARCH64_M4);
|
---|
227 | }
|
---|
228 |
|
---|
229 | /** @} */
|
---|
230 | #endif /* !IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS || DOXYGEN_RUNNING */
|
---|
231 |
|
---|
232 |
|
---|
233 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
234 |
|
---|
235 | #ifdef IN_RING3
|
---|
236 | /** @defgroup grp_cpum_armv8_r3 The CPUM ARMv8 ring-3 API
|
---|
237 | * @{
|
---|
238 | */
|
---|
239 |
|
---|
240 | VMMR3DECL(int) CPUMR3SysRegRangesInsert(PVM pVM, PCCPUMSYSREGRANGE pNewRange);
|
---|
241 | VMMR3DECL(int) CPUMR3PopulateFeaturesByIdRegisters(PVM pVM, PCCPUMARMV8IDREGS pIdRegs);
|
---|
242 |
|
---|
243 | VMMR3_INT_DECL(int) CPUMR3QueryGuestIdRegs(PVM pVM, PCCPUMARMV8IDREGS *ppIdRegs);
|
---|
244 |
|
---|
245 | /** @} */
|
---|
246 | #endif /* IN_RING3 */
|
---|
247 |
|
---|
248 |
|
---|
249 | /** @name Guest Register Getters.
|
---|
250 | * @{ */
|
---|
251 | VMMDECL(bool) CPUMGetGuestIrqMasked(PVMCPUCC pVCpu);
|
---|
252 | VMMDECL(bool) CPUMGetGuestFiqMasked(PVMCPUCC pVCpu);
|
---|
253 | VMM_INT_DECL(uint8_t) CPUMGetGuestEL(PVMCPUCC pVCpu);
|
---|
254 | VMM_INT_DECL(bool) CPUMGetGuestMmuEnabled(PVMCPUCC pVCpu);
|
---|
255 | VMMDECL(VBOXSTRICTRC) CPUMQueryGuestSysReg(PVMCPUCC pVCpu, uint32_t idSysReg, uint64_t *puValue);
|
---|
256 | VMM_INT_DECL(RTGCPHYS) CPUMGetEffectiveTtbr(PVMCPUCC pVCpu, RTGCPTR GCPtr);
|
---|
257 | VMM_INT_DECL(uint64_t) CPUMGetTcrEl1(PVMCPUCC pVCpu);
|
---|
258 | VMM_INT_DECL(RTGCPTR) CPUMGetGCPtrPacStripped(PVMCPUCC pVCpu, RTGCPTR GCPtr);
|
---|
259 | /** @} */
|
---|
260 |
|
---|
261 |
|
---|
262 | /** @name Guest Register Setters.
|
---|
263 | * @{ */
|
---|
264 | VMMDECL(VBOXSTRICTRC) CPUMSetGuestSysReg(PVMCPUCC pVCpu, uint32_t idSysReg, uint64_t uValue);
|
---|
265 | /** @} */
|
---|
266 |
|
---|
267 | #endif
|
---|
268 |
|
---|
269 | /** @} */
|
---|
270 | RT_C_DECLS_END
|
---|
271 |
|
---|
272 |
|
---|
273 | #endif /* !VBOX_INCLUDED_vmm_cpum_armv8_h */
|
---|
274 |
|
---|