VirtualBox

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

Last change on this file since 96860 was 96407, checked in by vboxsync, 22 months ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
Line 
1/* $Id: EMInternal.h 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * EM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2022 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 a triple fault triggers a guru. */
133 bool fGuruOnTripleFault;
134 /** Alignment padding. */
135 bool afPadding[2];
136
137 /** Id of the VCPU that last executed code in the recompiler. */
138 VMCPUID idLastRemCpu;
139} EM;
140/** Pointer to EM VM instance data. */
141typedef EM *PEM;
142
143
144/**
145 * EM VMCPU Instance data.
146 */
147typedef struct EMCPU
148{
149 /** Execution Manager State. */
150 EMSTATE volatile enmState;
151
152 /** The state prior to the suspending of the VM. */
153 EMSTATE enmPrevState;
154
155 /** Set if hypercall instruction VMMCALL (AMD) & VMCALL (Intel) are enabled.
156 * GIM sets this and the execution managers queries it. Not saved, as GIM
157 * takes care of that bit too. */
158 bool fHypercallEnabled;
159
160 /** Explicit padding. */
161 uint8_t abPadding0[3];
162
163 /** The number of instructions we've executed in IEM since switching to the
164 * EMSTATE_IEM_THEN_REM state. */
165 uint32_t cIemThenRemInstructions;
166
167 /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
168 RTGCUINTPTR GCPtrInhibitInterrupts;
169
170 /** Start of the current time slice in ms. */
171 uint64_t u64TimeSliceStart;
172 /** Start of the current time slice in thread execution time (ms). */
173 uint64_t u64TimeSliceStartExec;
174 /** Current time slice value. */
175 uint64_t u64TimeSliceExec;
176
177 /** Pending ring-3 I/O port access (VINF_EM_PENDING_R3_IOPORT_READ / VINF_EM_PENDING_R3_IOPORT_WRITE). */
178 struct
179 {
180 RTIOPORT uPort; /**< The I/O port number.*/
181 uint8_t cbValue; /**< The value size in bytes. Zero when not pending. */
182 uint8_t cbInstr; /**< The instruction length. */
183 uint32_t uValue; /**< The value to write. */
184 } PendingIoPortAccess;
185
186 /** MWait halt state. */
187 struct
188 {
189 uint32_t fWait; /**< Type of mwait; see EMMWAIT_FLAG_*. */
190 uint32_t u32Padding;
191 RTGCPTR uMWaitRAX; /**< MWAIT hints. */
192 RTGCPTR uMWaitRCX; /**< MWAIT extensions. */
193 RTGCPTR uMonitorRAX; /**< Monitored address. */
194 RTGCPTR uMonitorRCX; /**< Monitor extension. */
195 RTGCPTR uMonitorRDX; /**< Monitor hint. */
196 } MWait;
197
198 /** Make sure the jmp_buf is at a 32-byte boundrary. */
199 uint64_t au64Padding1[3];
200 union
201 {
202 /** Padding used in the other rings.
203 * This must be larger than jmp_buf on any supported platform. */
204 char achPaddingFatalLongJump[256];
205#ifdef IN_RING3
206 /** Long buffer jump for fatal VM errors.
207 * It will jump to before the outer EM loop is entered. */
208 jmp_buf FatalLongJump;
209#endif
210 } u;
211
212 /** For saving stack space, the disassembler state is allocated here instead of
213 * on the stack. */
214 DISCPUSTATE DisState;
215
216 /** @name Execution profiling.
217 * @{ */
218 STAMPROFILE StatForcedActions;
219 STAMPROFILE StatHalted;
220 STAMPROFILEADV StatCapped;
221 STAMPROFILEADV StatHMEntry;
222 STAMPROFILE StatHMExec;
223 STAMPROFILE StatIEMEmu;
224 STAMPROFILE StatIEMThenREM;
225 STAMPROFILEADV StatNEMEntry;
226 STAMPROFILE StatNEMExec;
227 STAMPROFILE StatREMEmu;
228 STAMPROFILE StatREMExec;
229 STAMPROFILE StatREMSync;
230 STAMPROFILEADV StatREMTotal;
231 STAMPROFILE StatRAWExec;
232 STAMPROFILEADV StatRAWEntry;
233 STAMPROFILEADV StatRAWTail;
234 STAMPROFILEADV StatRAWTotal;
235 STAMPROFILEADV StatTotal;
236 /** @} */
237
238 /** R3: Profiling of emR3RawExecuteIOInstruction. */
239 STAMPROFILE StatIOEmu;
240 STAMCOUNTER StatIoRestarted;
241 STAMCOUNTER StatIoIem;
242 /** R3: Profiling of emR3RawPrivileged. */
243 STAMPROFILE StatPrivEmu;
244 /** R3: Number of times emR3HmExecute is called. */
245 STAMCOUNTER StatHMExecuteCalled;
246 /** R3: Number of times emR3NEMExecute is called. */
247 STAMCOUNTER StatNEMExecuteCalled;
248
249 /** Align the next member at a 32-byte boundrary. */
250 uint64_t au64Padding2[1+2];
251
252 /** Exit history table (6KB). */
253 EMEXITENTRY aExitHistory[256];
254 /** Where to store the next exit history entry.
255 * Since aExitHistory is 256 items longs, we'll just increment this and
256 * mask it when using it. That help the readers detect whether we've
257 * wrapped around or not. */
258 uint64_t iNextExit;
259
260 /** Index into aExitRecords set by EMHistoryExec when returning to ring-3.
261 * This is UINT16_MAX if not armed. */
262 uint16_t volatile idxContinueExitRec;
263 /** Whether exit optimizations are enabled or not (in general). */
264 bool fExitOptimizationEnabled : 1;
265 /** Whether exit optimizations are enabled for ring-0 (in general). */
266 bool fExitOptimizationEnabledR0 : 1;
267 /** Whether exit optimizations are enabled for ring-0 when preemption is disabled. */
268 bool fExitOptimizationEnabledR0PreemptDisabled : 1;
269 /** Explicit padding. */
270 bool fPadding2;
271 /** Max number of instructions to execute. */
272 uint16_t cHistoryExecMaxInstructions;
273 /** Min number of instructions to execute while probing. */
274 uint16_t cHistoryProbeMinInstructions;
275 /** Max number of instructions to execute without an exit before giving up probe. */
276 uint16_t cHistoryProbeMaxInstructionsWithoutExit;
277 uint16_t uPadding3;
278 /** Number of exit records in use. */
279 uint32_t cExitRecordUsed;
280 /** Profiling the EMHistoryExec when executing (not probing). */
281 STAMPROFILE StatHistoryExec;
282 /** Number of saved exits. */
283 STAMCOUNTER StatHistoryExecSavedExits;
284 /** Number of instructions executed by EMHistoryExec. */
285 STAMCOUNTER StatHistoryExecInstructions;
286 uint64_t uPadding4;
287 /** Number of instructions executed by EMHistoryExec when probing. */
288 STAMCOUNTER StatHistoryProbeInstructions;
289 /** Number of times probing resulted in EMEXITACTION_NORMAL_PROBED. */
290 STAMCOUNTER StatHistoryProbedNormal;
291 /** Number of times probing resulted in EMEXITACTION_EXEC_WITH_MAX. */
292 STAMCOUNTER StatHistoryProbedExecWithMax;
293 /** Number of times probing resulted in ring-3 continuation. */
294 STAMCOUNTER StatHistoryProbedToRing3;
295 /** Profiling the EMHistoryExec when probing.*/
296 STAMPROFILE StatHistoryProbe;
297 /** Hit statistics for each lookup step. */
298 STAMCOUNTER aStatHistoryRecHits[16];
299 /** Type change statistics for each lookup step. */
300 STAMCOUNTER aStatHistoryRecTypeChanged[16];
301 /** Replacement statistics for each lookup step. */
302 STAMCOUNTER aStatHistoryRecReplaced[16];
303 /** New record statistics for each lookup step. */
304 STAMCOUNTER aStatHistoryRecNew[16];
305
306 /** Exit records (32KB). (Aligned on 32 byte boundrary.) */
307 EMEXITREC aExitRecords[1024];
308} EMCPU;
309/** Pointer to EM VM instance data. */
310typedef EMCPU *PEMCPU;
311
312/** @} */
313
314int emR3InitDbg(PVM pVM);
315
316int emR3HmExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
317VBOXSTRICTRC emR3NemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
318int emR3RawExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
319
320EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu);
321int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
322VBOXSTRICTRC emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rc);
323
324int emR3RawResumeHyper(PVM pVM, PVMCPU pVCpu);
325int emR3RawStep(PVM pVM, PVMCPU pVCpu);
326
327VBOXSTRICTRC emR3NemSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
328
329int emR3SingleStepExecRem(PVM pVM, PVMCPU pVCpu, uint32_t cIterations);
330
331bool emR3IsExecutionAllowed(PVM pVM, PVMCPU pVCpu);
332
333VBOXSTRICTRC emR3ExecutePendingIoPortWrite(PVM pVM, PVMCPU pVCpu);
334VBOXSTRICTRC emR3ExecutePendingIoPortRead(PVM pVM, PVMCPU pVCpu);
335VBOXSTRICTRC emR3ExecuteSplitLockInstruction(PVM pVM, PVMCPU pVCpu);
336
337RT_C_DECLS_END
338
339#endif /* !VMM_INCLUDED_SRC_include_EMInternal_h */
340
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use