VirtualBox

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

Last change on this file since 99900 was 99899, checked in by vboxsync, 19 months ago

VMM/EM,DBGF: Removed the EMSTATE_IEM_THEN_REM stuff as it makes no sense without the old REM. bugref:10369

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* $Id: EMInternal.h 99899 2023-05-22 12:43:21Z 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. */
163 uint64_t u64TimeSliceStart;
164 /** Start of the current time slice in thread execution time (ms). */
165 uint64_t u64TimeSliceStartExec;
166 /** Current time slice value. */
167 uint64_t u64TimeSliceExec;
168
169 /** Pending ring-3 I/O port access (VINF_EM_PENDING_R3_IOPORT_READ / VINF_EM_PENDING_R3_IOPORT_WRITE). */
170 struct
171 {
172 RTIOPORT uPort; /**< The I/O port number.*/
173 uint8_t cbValue; /**< The value size in bytes. Zero when not pending. */
174 uint8_t cbInstr; /**< The instruction length. */
175 uint32_t uValue; /**< The value to write. */
176 } PendingIoPortAccess;
177
178 /** MWait halt state. */
179 struct
180 {
181 uint32_t fWait; /**< Type of mwait; see EMMWAIT_FLAG_*. */
182 uint32_t u32Padding;
183 RTGCPTR uMWaitRAX; /**< MWAIT hints. */
184 RTGCPTR uMWaitRCX; /**< MWAIT extensions. */
185 RTGCPTR uMonitorRAX; /**< Monitored address. */
186 RTGCPTR uMonitorRCX; /**< Monitor extension. */
187 RTGCPTR uMonitorRDX; /**< Monitor hint. */
188 } MWait;
189
190#if 0
191 /** Make sure the jmp_buf is at a 32-byte boundrary. */
192 uint64_t au64Padding1[4];
193#endif
194 union
195 {
196 /** Padding used in the other rings.
197 * This must be larger than jmp_buf on any supported platform. */
198 char achPaddingFatalLongJump[256];
199#ifdef IN_RING3
200 /** Long buffer jump for fatal VM errors.
201 * It will jump to before the outer EM loop is entered. */
202 jmp_buf FatalLongJump;
203#endif
204 } u;
205
206 /** For saving stack space, the disassembler state is allocated here instead of
207 * on the stack. */
208 DISSTATE Dis;
209
210 /** @name Execution profiling.
211 * @{ */
212 STAMPROFILE StatForcedActions;
213 STAMPROFILE StatHalted;
214 STAMPROFILEADV StatCapped;
215 STAMPROFILEADV StatHMEntry;
216 STAMPROFILE StatHMExec;
217 STAMPROFILE StatIEMEmu;
218 STAMPROFILE StatIEMThenREM;
219 STAMPROFILEADV StatNEMEntry;
220 STAMPROFILE StatNEMExec;
221 STAMPROFILE StatREMExec;
222 STAMPROFILE StatREMTotal;
223 STAMPROFILEADV StatTotal;
224 /** @} */
225
226 /** R3: Profiling of emR3RawExecuteIOInstruction. */
227 STAMPROFILE StatIOEmu;
228 STAMCOUNTER StatIoRestarted;
229 STAMCOUNTER StatIoIem;
230 /** R3: Profiling of emR3RawPrivileged. */
231 STAMPROFILE StatPrivEmu;
232 /** R3: Number of times emR3HmExecute is called. */
233 STAMCOUNTER StatHMExecuteCalled;
234 /** R3: Number of times emR3NEMExecute is called. */
235 STAMCOUNTER StatNEMExecuteCalled;
236
237 /** Align the next member at a 32-byte boundrary. */
238 uint64_t au64Padding2[1+2];
239
240 /** Exit history table (6KB). */
241 EMEXITENTRY aExitHistory[256];
242 /** Where to store the next exit history entry.
243 * Since aExitHistory is 256 items longs, we'll just increment this and
244 * mask it when using it. That help the readers detect whether we've
245 * wrapped around or not. */
246 uint64_t iNextExit;
247
248 /** Index into aExitRecords set by EMHistoryExec when returning to ring-3.
249 * This is UINT16_MAX if not armed. */
250 uint16_t volatile idxContinueExitRec;
251 /** Whether exit optimizations are enabled or not (in general). */
252 bool fExitOptimizationEnabled : 1;
253 /** Whether exit optimizations are enabled for ring-0 (in general). */
254 bool fExitOptimizationEnabledR0 : 1;
255 /** Whether exit optimizations are enabled for ring-0 when preemption is disabled. */
256 bool fExitOptimizationEnabledR0PreemptDisabled : 1;
257 /** Explicit padding. */
258 bool fPadding2;
259 /** Max number of instructions to execute. */
260 uint16_t cHistoryExecMaxInstructions;
261 /** Min number of instructions to execute while probing. */
262 uint16_t cHistoryProbeMinInstructions;
263 /** Max number of instructions to execute without an exit before giving up probe. */
264 uint16_t cHistoryProbeMaxInstructionsWithoutExit;
265 uint16_t uPadding3;
266 /** Number of exit records in use. */
267 uint32_t cExitRecordUsed;
268 /** Profiling the EMHistoryExec when executing (not probing). */
269 STAMPROFILE StatHistoryExec;
270 /** Number of saved exits. */
271 STAMCOUNTER StatHistoryExecSavedExits;
272 /** Number of instructions executed by EMHistoryExec. */
273 STAMCOUNTER StatHistoryExecInstructions;
274 uint64_t uPadding4;
275 /** Number of instructions executed by EMHistoryExec when probing. */
276 STAMCOUNTER StatHistoryProbeInstructions;
277 /** Number of times probing resulted in EMEXITACTION_NORMAL_PROBED. */
278 STAMCOUNTER StatHistoryProbedNormal;
279 /** Number of times probing resulted in EMEXITACTION_EXEC_WITH_MAX. */
280 STAMCOUNTER StatHistoryProbedExecWithMax;
281 /** Number of times probing resulted in ring-3 continuation. */
282 STAMCOUNTER StatHistoryProbedToRing3;
283 /** Profiling the EMHistoryExec when probing.*/
284 STAMPROFILE StatHistoryProbe;
285 /** Hit statistics for each lookup step. */
286 STAMCOUNTER aStatHistoryRecHits[16];
287 /** Type change statistics for each lookup step. */
288 STAMCOUNTER aStatHistoryRecTypeChanged[16];
289 /** Replacement statistics for each lookup step. */
290 STAMCOUNTER aStatHistoryRecReplaced[16];
291 /** New record statistics for each lookup step. */
292 STAMCOUNTER aStatHistoryRecNew[16];
293
294 /** Exit records (32KB). (Aligned on 32 byte boundrary.) */
295 EMEXITREC aExitRecords[1024];
296} EMCPU;
297/** Pointer to EM VM instance data. */
298typedef EMCPU *PEMCPU;
299
300/** @} */
301
302int emR3InitDbg(PVM pVM);
303
304int emR3HmExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
305VBOXSTRICTRC emR3NemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
306int emR3RawExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
307
308EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu);
309int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
310VBOXSTRICTRC emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rc);
311
312int emR3RawResumeHyper(PVM pVM, PVMCPU pVCpu);
313int emR3RawStep(PVM pVM, PVMCPU pVCpu);
314
315VBOXSTRICTRC emR3NemSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
316
317bool emR3IsExecutionAllowedSlow(PVM pVM, PVMCPU pVCpu);
318
319VBOXSTRICTRC emR3ExecutePendingIoPortWrite(PVM pVM, PVMCPU pVCpu);
320VBOXSTRICTRC emR3ExecutePendingIoPortRead(PVM pVM, PVMCPU pVCpu);
321VBOXSTRICTRC emR3ExecuteSplitLockInstruction(PVM pVM, PVMCPU pVCpu);
322
323RT_C_DECLS_END
324
325#endif /* !VMM_INCLUDED_SRC_include_EMInternal_h */
326
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