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.215389.xyz.
|
---|
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 | /** @name Changed flags.
|
---|
169 | * These flags are used to keep track of which important register that
|
---|
170 | * have been changed since last they were reset. The only one allowed
|
---|
171 | * to clear them is REM!
|
---|
172 | *
|
---|
173 | * @todo This is obsolete, but remains as it will be refactored for coordinating
|
---|
174 | * IEM and NEM/HM later. Probably.
|
---|
175 | * @{
|
---|
176 | */
|
---|
177 | #define CPUM_CHANGED_GLOBAL_TLB_FLUSH RT_BIT(0)
|
---|
178 | #define CPUM_CHANGED_ALL ( CPUM_CHANGED_GLOBAL_TLB_FLUSH )
|
---|
179 | /** @} */
|
---|
180 |
|
---|
181 |
|
---|
182 | #if !defined(IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS) || defined(DOXYGEN_RUNNING)
|
---|
183 | /** @name Inlined Guest Getters and predicates Functions.
|
---|
184 | * @{ */
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Tests if the guest is running in 64 bits mode or not.
|
---|
188 | *
|
---|
189 | * @returns true if in 64 bits mode, otherwise false.
|
---|
190 | * @param pCtx Current CPU context.
|
---|
191 | */
|
---|
192 | DECLINLINE(bool) CPUMIsGuestIn64BitCodeEx(PCCPUMCTX pCtx)
|
---|
193 | {
|
---|
194 | return !RT_BOOL(pCtx->fPState & ARMV8_SPSR_EL2_AARCH64_M4);
|
---|
195 | }
|
---|
196 |
|
---|
197 | /** @} */
|
---|
198 | #endif /* !IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS || DOXYGEN_RUNNING */
|
---|
199 |
|
---|
200 |
|
---|
201 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
202 |
|
---|
203 | #ifdef IN_RING3
|
---|
204 | /** @defgroup grp_cpum_armv8_r3 The CPUM ARMv8 ring-3 API
|
---|
205 | * @{
|
---|
206 | */
|
---|
207 |
|
---|
208 | VMMR3DECL(int) CPUMR3SysRegRangesInsert(PVM pVM, PCCPUMSYSREGRANGE pNewRange);
|
---|
209 | VMMR3DECL(int) CPUMR3PopulateFeaturesByIdRegisters(PVM pVM, PCCPUMARMV8IDREGS pIdRegs);
|
---|
210 |
|
---|
211 | VMMR3_INT_DECL(int) CPUMR3QueryGuestIdRegs(PVM pVM, PCCPUMARMV8IDREGS *ppIdRegs);
|
---|
212 |
|
---|
213 | /** @} */
|
---|
214 | #endif /* IN_RING3 */
|
---|
215 |
|
---|
216 |
|
---|
217 | /** @name Guest Register Getters.
|
---|
218 | * @{ */
|
---|
219 | VMMDECL(bool) CPUMGetGuestIrqMasked(PVMCPUCC pVCpu);
|
---|
220 | VMMDECL(bool) CPUMGetGuestFiqMasked(PVMCPUCC pVCpu);
|
---|
221 | VMM_INT_DECL(uint8_t) CPUMGetGuestEL(PVMCPUCC pVCpu);
|
---|
222 | VMM_INT_DECL(bool) CPUMGetGuestMmuEnabled(PVMCPUCC pVCpu);
|
---|
223 | VMMDECL(VBOXSTRICTRC) CPUMQueryGuestSysReg(PVMCPUCC pVCpu, uint32_t idSysReg, uint64_t *puValue);
|
---|
224 | VMM_INT_DECL(RTGCPHYS) CPUMGetEffectiveTtbr(PVMCPUCC pVCpu, RTGCPTR GCPtr);
|
---|
225 | VMM_INT_DECL(uint64_t) CPUMGetTcrEl1(PVMCPUCC pVCpu);
|
---|
226 | VMM_INT_DECL(RTGCPTR) CPUMGetGCPtrPacStripped(PVMCPUCC pVCpu, RTGCPTR GCPtr);
|
---|
227 | /** @} */
|
---|
228 |
|
---|
229 |
|
---|
230 | /** @name Guest Register Setters.
|
---|
231 | * @{ */
|
---|
232 | VMMDECL(VBOXSTRICTRC) CPUMSetGuestSysReg(PVMCPUCC pVCpu, uint32_t idSysReg, uint64_t uValue);
|
---|
233 | /** @} */
|
---|
234 |
|
---|
235 | #endif
|
---|
236 |
|
---|
237 | /** @} */
|
---|
238 | RT_C_DECLS_END
|
---|
239 |
|
---|
240 |
|
---|
241 | #endif /* !VBOX_INCLUDED_vmm_cpum_armv8_h */
|
---|
242 |
|
---|