VirtualBox

source: vbox/trunk/src/VBox/VMM/include/EMInternal.h@ 100594

Last change on this file since 100594 was 99923, checked in by vboxsync, 19 months ago

VMM/EM: scm fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1/* $Id: EMInternal.h 99923 2023-05-22 21:06:26Z vboxsync $ */
2/** @file
3 * EM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-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#ifndef VMM_INCLUDED_SRC_include_EMInternal_h
29#define VMM_INCLUDED_SRC_include_EMInternal_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <VBox/cdefs.h>
35#include <VBox/types.h>
36#include <VBox/vmm/em.h>
37#include <VBox/vmm/stam.h>
38#include <VBox/dis.h>
39#include <VBox/vmm/pdmcritsect.h>
40#include <iprt/avl.h>
41#include <iprt/setjmp-without-sigmask.h>
42
43RT_C_DECLS_BEGIN
44
45
46/** @defgroup grp_em_int Internal
47 * @ingroup grp_em
48 * @internal
49 * @{
50 */
51
52/** The saved state version. */
53#define EM_SAVED_STATE_VERSION 5
54#define EM_SAVED_STATE_VERSION_PRE_IEM 4
55#define EM_SAVED_STATE_VERSION_PRE_MWAIT 3
56#define EM_SAVED_STATE_VERSION_PRE_SMP 2
57
58
59/** @name MWait state flags.
60 * @{
61 */
62/** MWait activated. */
63#define EMMWAIT_FLAG_ACTIVE RT_BIT(0)
64/** MWait will continue when an interrupt is pending even when IF=0. */
65#define EMMWAIT_FLAG_BREAKIRQIF0 RT_BIT(1)
66/** Monitor instruction was executed previously. */
67#define EMMWAIT_FLAG_MONITOR_ACTIVE RT_BIT(2)
68/** @} */
69
70/** EM time slice in ms; used for capping execution time. */
71#define EM_TIME_SLICE 100
72
73/**
74 * Cli node structure
75 */
76typedef struct CLISTAT
77{
78 /** The key is the cli address. */
79 AVLGCPTRNODECORE Core;
80#if HC_ARCH_BITS == 32 && !defined(RT_OS_WINDOWS)
81 /** Padding. */
82 uint32_t u32Padding;
83#endif
84 /** Occurrences. */
85 STAMCOUNTER Counter;
86} CLISTAT, *PCLISTAT;
87#ifdef IN_RING3
88AssertCompileMemberAlignment(CLISTAT, Counter, 8);
89#endif
90
91
92/**
93 * Exit history entry.
94 *
95 * @remarks We could perhaps trim this down a little bit by assuming uFlatPC
96 * only needs 48 bits (currently true but will change) and stuffing
97 * the flags+type in the available 16 bits made available. The
98 * timestamp could likewise be shortened to accomodate the index, or
99 * we might skip the index entirely. However, since we will have to
100 * deal with 56-bit wide PC address before long, there's not point.
101 *
102 * On the upside, there are unused bits in both uFlagsAndType and the
103 * idxSlot fields if needed for anything.
104 */
105typedef struct EMEXITENTRY
106{
107 /** The flat PC (CS:EIP/RIP) address of the exit.
108 * UINT64_MAX if not available. */
109 uint64_t uFlatPC;
110 /** The EMEXIT_MAKE_FLAGS_AND_TYPE */
111 uint32_t uFlagsAndType;
112 /** The index into the exit slot hash table.
113 * UINT32_MAX if too many collisions and not entered into it. */
114 uint32_t idxSlot;
115 /** The TSC timestamp of the exit.
116 * This is 0 if not timestamped. */
117 uint64_t uTimestamp;
118} EMEXITENTRY;
119/** Pointer to an exit history entry. */
120typedef EMEXITENTRY *PEMEXITENTRY;
121/** Pointer to a const exit history entry. */
122typedef EMEXITENTRY const *PCEMEXITENTRY;
123
124
125/**
126 * EM VM Instance data.
127 */
128typedef struct EM
129{
130 /** Whether IEM executes everything. */
131 bool fIemExecutesAll;
132 /** Whether IEM execution (pure) is recompiled (true) or interpreted (false). */
133 bool fIemRecompiled;
134 /** Whether a triple fault triggers a guru. */
135 bool fGuruOnTripleFault;
136 /** Alignment padding. */
137 bool afPadding[5];
138} EM;
139/** Pointer to EM VM instance data. */
140typedef EM *PEM;
141
142
143/**
144 * EM VMCPU Instance data.
145 */
146typedef struct EMCPU
147{
148 /** Execution Manager State. */
149 EMSTATE volatile enmState;
150
151 /** The state prior to the suspending of the VM. */
152 EMSTATE enmPrevState;
153
154 /** Set if hypercall instruction VMMCALL (AMD) & VMCALL (Intel) are enabled.
155 * GIM sets this and the execution managers queries it. Not saved, as GIM
156 * takes care of that bit too. */
157 bool fHypercallEnabled;
158
159 /** Explicit padding. */
160 uint8_t abPadding0[7];
161
162 /** Start of the current time slice in ms (RTTimeMilliTS). */
163 uint64_t msTimeSliceStart;
164 /** The sum of the RTThreadGetExecutionTimeMilli() values at the start of the
165 * current slice. */
166 uint64_t cMsTimeSliceStartExec;
167 /** Number of milliseconds into the current time slice last we checked.
168 * This is in terms of the RTThreadGetExecutionTimeMilli() total, like for
169 * cMsTimeSliceStartExec. */
170 uint64_t cMsTimeSliceExec;
171
172 /** Pending ring-3 I/O port access (VINF_EM_PENDING_R3_IOPORT_READ / VINF_EM_PENDING_R3_IOPORT_WRITE). */
173 struct
174 {
175 RTIOPORT uPort; /**< The I/O port number.*/
176 uint8_t cbValue; /**< The value size in bytes. Zero when not pending. */
177 uint8_t cbInstr; /**< The instruction length. */
178 uint32_t uValue; /**< The value to write. */
179 } PendingIoPortAccess;
180
181 /** MWait halt state. */
182 struct
183 {
184 uint32_t fWait; /**< Type of mwait; see EMMWAIT_FLAG_*. */
185 uint32_t u32Padding;
186 RTGCPTR uMWaitRAX; /**< MWAIT hints. */
187 RTGCPTR uMWaitRCX; /**< MWAIT extensions. */
188 RTGCPTR uMonitorRAX; /**< Monitored address. */
189 RTGCPTR uMonitorRCX; /**< Monitor extension. */
190 RTGCPTR uMonitorRDX; /**< Monitor hint. */
191 } MWait;
192
193#if 0
194 /** Make sure the jmp_buf is at a 32-byte boundrary. */
195 uint64_t au64Padding1[4];
196#endif
197 union
198 {
199 /** Padding used in the other rings.
200 * This must be larger than jmp_buf on any supported platform. */
201 char achPaddingFatalLongJump[256];
202#ifdef IN_RING3
203 /** Long buffer jump for fatal VM errors.
204 * It will jump to before the outer EM loop is entered. */
205 jmp_buf FatalLongJump;
206#endif
207 } u;
208
209 /** For saving stack space, the disassembler state is allocated here instead of
210 * on the stack. */
211 DISSTATE Dis;
212
213 /** @name Execution profiling.
214 * @{ */
215 STAMPROFILE StatForcedActions;
216 STAMPROFILE StatHalted;
217 STAMPROFILEADV StatCapped;
218 STAMPROFILEADV StatHMEntry;
219 STAMPROFILE StatHMExec;
220 STAMPROFILE StatIEMEmu;
221 STAMPROFILE StatIEMThenREM;
222 STAMPROFILEADV StatNEMEntry;
223 STAMPROFILE StatNEMExec;
224 STAMPROFILE StatREMExec;
225 STAMPROFILE StatREMTotal;
226 STAMPROFILEADV StatTotal;
227 /** @} */
228
229 /** R3: Profiling of emR3RawExecuteIOInstruction. */
230 STAMPROFILE StatIOEmu;
231 STAMCOUNTER StatIoRestarted;
232 STAMCOUNTER StatIoIem;
233 /** R3: Profiling of emR3RawPrivileged. */
234 STAMPROFILE StatPrivEmu;
235 /** R3: Number of times emR3HmExecute is called. */
236 STAMCOUNTER StatHMExecuteCalled;
237 /** R3: Number of times emR3NEMExecute is called. */
238 STAMCOUNTER StatNEMExecuteCalled;
239
240 /** Align the next member at a 32-byte boundrary. */
241 uint64_t au64Padding2[1+2];
242
243 /** Exit history table (6KB). */
244 EMEXITENTRY aExitHistory[256];
245 /** Where to store the next exit history entry.
246 * Since aExitHistory is 256 items longs, we'll just increment this and
247 * mask it when using it. That help the readers detect whether we've
248 * wrapped around or not. */
249 uint64_t iNextExit;
250
251 /** Index into aExitRecords set by EMHistoryExec when returning to ring-3.
252 * This is UINT16_MAX if not armed. */
253 uint16_t volatile idxContinueExitRec;
254 /** Whether exit optimizations are enabled or not (in general). */
255 bool fExitOptimizationEnabled : 1;
256 /** Whether exit optimizations are enabled for ring-0 (in general). */
257 bool fExitOptimizationEnabledR0 : 1;
258 /** Whether exit optimizations are enabled for ring-0 when preemption is disabled. */
259 bool fExitOptimizationEnabledR0PreemptDisabled : 1;
260 /** Explicit padding. */
261 bool fPadding2;
262 /** Max number of instructions to execute. */
263 uint16_t cHistoryExecMaxInstructions;
264 /** Min number of instructions to execute while probing. */
265 uint16_t cHistoryProbeMinInstructions;
266 /** Max number of instructions to execute without an exit before giving up probe. */
267 uint16_t cHistoryProbeMaxInstructionsWithoutExit;
268 uint16_t uPadding3;
269 /** Number of exit records in use. */
270 uint32_t cExitRecordUsed;
271 /** Profiling the EMHistoryExec when executing (not probing). */
272 STAMPROFILE StatHistoryExec;
273 /** Number of saved exits. */
274 STAMCOUNTER StatHistoryExecSavedExits;
275 /** Number of instructions executed by EMHistoryExec. */
276 STAMCOUNTER StatHistoryExecInstructions;
277 uint64_t uPadding4;
278 /** Number of instructions executed by EMHistoryExec when probing. */
279 STAMCOUNTER StatHistoryProbeInstructions;
280 /** Number of times probing resulted in EMEXITACTION_NORMAL_PROBED. */
281 STAMCOUNTER StatHistoryProbedNormal;
282 /** Number of times probing resulted in EMEXITACTION_EXEC_WITH_MAX. */
283 STAMCOUNTER StatHistoryProbedExecWithMax;
284 /** Number of times probing resulted in ring-3 continuation. */
285 STAMCOUNTER StatHistoryProbedToRing3;
286 /** Profiling the EMHistoryExec when probing.*/
287 STAMPROFILE StatHistoryProbe;
288 /** Hit statistics for each lookup step. */
289 STAMCOUNTER aStatHistoryRecHits[16];
290 /** Type change statistics for each lookup step. */
291 STAMCOUNTER aStatHistoryRecTypeChanged[16];
292 /** Replacement statistics for each lookup step. */
293 STAMCOUNTER aStatHistoryRecReplaced[16];
294 /** New record statistics for each lookup step. */
295 STAMCOUNTER aStatHistoryRecNew[16];
296
297 /** Exit records (32KB). (Aligned on 32 byte boundrary.) */
298 EMEXITREC aExitRecords[1024];
299} EMCPU;
300/** Pointer to EM VM instance data. */
301typedef EMCPU *PEMCPU;
302
303/** @} */
304
305int emR3InitDbg(PVM pVM);
306
307int emR3HmExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
308VBOXSTRICTRC emR3NemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
309int emR3RawExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
310
311EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu);
312int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
313VBOXSTRICTRC emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rc);
314
315int emR3RawResumeHyper(PVM pVM, PVMCPU pVCpu);
316int emR3RawStep(PVM pVM, PVMCPU pVCpu);
317
318VBOXSTRICTRC emR3NemSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
319
320bool emR3IsExecutionAllowedSlow(PVM pVM, PVMCPU pVCpu);
321
322VBOXSTRICTRC emR3ExecutePendingIoPortWrite(PVM pVM, PVMCPU pVCpu);
323VBOXSTRICTRC emR3ExecutePendingIoPortRead(PVM pVM, PVMCPU pVCpu);
324VBOXSTRICTRC emR3ExecuteSplitLockInstruction(PVM pVM, PVMCPU pVCpu);
325
326RT_C_DECLS_END
327
328#endif /* !VMM_INCLUDED_SRC_include_EMInternal_h */
329
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