VirtualBox

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

Last change on this file since 80360 was 80018, checked in by vboxsync, 5 years ago

VMM: Kicking out raw-mode (work in progress) - EM. bugref:9517

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.4 KB
Line 
1/* $Id: EMInternal.h 80018 2019-07-26 18:21:50Z vboxsync $ */
2/** @file
3 * EM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VMM_INCLUDED_SRC_include_EMInternal_h
19#define VMM_INCLUDED_SRC_include_EMInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBox/cdefs.h>
25#include <VBox/types.h>
26#include <VBox/vmm/em.h>
27#include <VBox/vmm/stam.h>
28#include <VBox/dis.h>
29#include <VBox/vmm/pdmcritsect.h>
30#include <iprt/avl.h>
31#include <setjmp.h>
32
33RT_C_DECLS_BEGIN
34
35
36/** @defgroup grp_em_int Internal
37 * @ingroup grp_em
38 * @internal
39 * @{
40 */
41
42/** The saved state version. */
43#define EM_SAVED_STATE_VERSION 5
44#define EM_SAVED_STATE_VERSION_PRE_IEM 4
45#define EM_SAVED_STATE_VERSION_PRE_MWAIT 3
46#define EM_SAVED_STATE_VERSION_PRE_SMP 2
47
48
49/** @name MWait state flags.
50 * @{
51 */
52/** MWait activated. */
53#define EMMWAIT_FLAG_ACTIVE RT_BIT(0)
54/** MWait will continue when an interrupt is pending even when IF=0. */
55#define EMMWAIT_FLAG_BREAKIRQIF0 RT_BIT(1)
56/** Monitor instruction was executed previously. */
57#define EMMWAIT_FLAG_MONITOR_ACTIVE RT_BIT(2)
58/** @} */
59
60/** EM time slice in ms; used for capping execution time. */
61#define EM_TIME_SLICE 100
62
63/**
64 * Cli node structure
65 */
66typedef struct CLISTAT
67{
68 /** The key is the cli address. */
69 AVLGCPTRNODECORE Core;
70#if HC_ARCH_BITS == 32 && !defined(RT_OS_WINDOWS)
71 /** Padding. */
72 uint32_t u32Padding;
73#endif
74 /** Occurrences. */
75 STAMCOUNTER Counter;
76} CLISTAT, *PCLISTAT;
77#ifdef IN_RING3
78AssertCompileMemberAlignment(CLISTAT, Counter, 8);
79#endif
80
81
82/**
83 * Excessive (used to be) EM statistics.
84 */
85typedef struct EMSTATS
86{
87#if 1 /* rawmode only? */
88 /** @name Privileged Instructions Ending Up In HC.
89 * @{ */
90 STAMCOUNTER StatIoRestarted;
91 STAMCOUNTER StatIoIem;
92 STAMCOUNTER StatCli;
93 STAMCOUNTER StatSti;
94 STAMCOUNTER StatInvlpg;
95 STAMCOUNTER StatHlt;
96 STAMCOUNTER StatMovReadCR[DISCREG_CR4 + 1];
97 STAMCOUNTER StatMovWriteCR[DISCREG_CR4 + 1];
98 STAMCOUNTER StatMovDRx;
99 STAMCOUNTER StatIret;
100 STAMCOUNTER StatMovLgdt;
101 STAMCOUNTER StatMovLldt;
102 STAMCOUNTER StatMovLidt;
103 STAMCOUNTER StatMisc;
104 STAMCOUNTER StatSysEnter;
105 STAMCOUNTER StatSysExit;
106 STAMCOUNTER StatSysCall;
107 STAMCOUNTER StatSysRet;
108 /** @} */
109#endif
110} EMSTATS;
111/** Pointer to the excessive EM statistics. */
112typedef EMSTATS *PEMSTATS;
113
114
115/**
116 * Exit history entry.
117 *
118 * @remarks We could perhaps trim this down a little bit by assuming uFlatPC
119 * only needs 48 bits (currently true but will change) and stuffing
120 * the flags+type in the available 16 bits made available. The
121 * timestamp could likewise be shortened to accomodate the index, or
122 * we might skip the index entirely. However, since we will have to
123 * deal with 56-bit wide PC address before long, there's not point.
124 *
125 * On the upside, there are unused bits in both uFlagsAndType and the
126 * idxSlot fields if needed for anything.
127 */
128typedef struct EMEXITENTRY
129{
130 /** The flat PC (CS:EIP/RIP) address of the exit.
131 * UINT64_MAX if not available. */
132 uint64_t uFlatPC;
133 /** The EMEXIT_MAKE_FLAGS_AND_TYPE */
134 uint32_t uFlagsAndType;
135 /** The index into the exit slot hash table.
136 * UINT32_MAX if too many collisions and not entered into it. */
137 uint32_t idxSlot;
138 /** The TSC timestamp of the exit.
139 * This is 0 if not timestamped. */
140 uint64_t uTimestamp;
141} EMEXITENTRY;
142/** Pointer to an exit history entry. */
143typedef EMEXITENTRY *PEMEXITENTRY;
144/** Pointer to a const exit history entry. */
145typedef EMEXITENTRY const *PCEMEXITENTRY;
146
147
148/**
149 * EM VM Instance data.
150 */
151typedef struct EM
152{
153 /** Whether IEM executes everything. */
154 bool fIemExecutesAll;
155 /** Whether a triple fault triggers a guru. */
156 bool fGuruOnTripleFault;
157 /** Alignment padding. */
158 bool afPadding[2];
159
160 /** Id of the VCPU that last executed code in the recompiler. */
161 VMCPUID idLastRemCpu;
162
163#ifdef VBOX_WITH_REM
164 /** REM critical section.
165 * This protects recompiler usage
166 */
167 PDMCRITSECT CritSectREM;
168#endif
169} EM;
170/** Pointer to EM VM instance data. */
171typedef EM *PEM;
172
173
174/**
175 * EM VMCPU Instance data.
176 */
177typedef struct EMCPU
178{
179 /** Execution Manager State. */
180 EMSTATE volatile enmState;
181
182 /** The state prior to the suspending of the VM. */
183 EMSTATE enmPrevState;
184
185 /** Set if hypercall instruction VMMCALL (AMD) & VMCALL (Intel) are enabled.
186 * GIM sets this and the execution managers queries it. Not saved, as GIM
187 * takes care of that bit too. */
188 bool fHypercallEnabled;
189
190 /** Explicit padding. */
191 uint8_t abPadding0[3];
192
193 /** The number of instructions we've executed in IEM since switching to the
194 * EMSTATE_IEM_THEN_REM state. */
195 uint32_t cIemThenRemInstructions;
196
197 /** Inhibit interrupts for this instruction. Valid only when VM_FF_INHIBIT_INTERRUPTS is set. */
198 RTGCUINTPTR GCPtrInhibitInterrupts;
199
200 /** Start of the current time slice in ms. */
201 uint64_t u64TimeSliceStart;
202 /** Start of the current time slice in thread execution time (ms). */
203 uint64_t u64TimeSliceStartExec;
204 /** Current time slice value. */
205 uint64_t u64TimeSliceExec;
206
207 /** Pending ring-3 I/O port access (VINF_EM_PENDING_R3_IOPORT_READ / VINF_EM_PENDING_R3_IOPORT_WRITE). */
208 struct
209 {
210 RTIOPORT uPort; /**< The I/O port number.*/
211 uint8_t cbValue; /**< The value size in bytes. Zero when not pending. */
212 uint8_t cbInstr; /**< The instruction length. */
213 uint32_t uValue; /**< The value to write. */
214 } PendingIoPortAccess;
215
216 /** MWait halt state. */
217 struct
218 {
219 uint32_t fWait; /**< Type of mwait; see EMMWAIT_FLAG_*. */
220 uint32_t u32Padding;
221 RTGCPTR uMWaitRAX; /**< MWAIT hints. */
222 RTGCPTR uMWaitRCX; /**< MWAIT extensions. */
223 RTGCPTR uMonitorRAX; /**< Monitored address. */
224 RTGCPTR uMonitorRCX; /**< Monitor extension. */
225 RTGCPTR uMonitorRDX; /**< Monitor hint. */
226 } MWait;
227
228 /** Make sure the jmp_buf is at a 32-byte boundrary. */
229 uint64_t au64Padding1[3];
230 union
231 {
232 /** Padding used in the other rings.
233 * This must be larger than jmp_buf on any supported platform. */
234 char achPaddingFatalLongJump[256];
235#ifdef IN_RING3
236 /** Long buffer jump for fatal VM errors.
237 * It will jump to before the outer EM loop is entered. */
238 jmp_buf FatalLongJump;
239#endif
240 } u;
241
242 /** For saving stack space, the disassembler state is allocated here instead of
243 * on the stack. */
244 DISCPUSTATE DisState;
245
246 /** @name Execution profiling.
247 * @{ */
248 STAMPROFILE StatForcedActions;
249 STAMPROFILE StatHalted;
250 STAMPROFILEADV StatCapped;
251 STAMPROFILEADV StatHMEntry;
252 STAMPROFILE StatHMExec;
253 STAMPROFILE StatIEMEmu;
254 STAMPROFILE StatIEMThenREM;
255 STAMPROFILEADV StatNEMEntry;
256 STAMPROFILE StatNEMExec;
257 STAMPROFILE StatREMEmu;
258 STAMPROFILE StatREMExec;
259 STAMPROFILE StatREMSync;
260 STAMPROFILEADV StatREMTotal;
261 STAMPROFILE StatRAWExec;
262 STAMPROFILEADV StatRAWEntry;
263 STAMPROFILEADV StatRAWTail;
264 STAMPROFILEADV StatRAWTotal;
265 STAMPROFILEADV StatTotal;
266 /** @} */
267
268 /** R3: Profiling of emR3RawExecuteIOInstruction. */
269 STAMPROFILE StatIOEmu;
270 /** R3: Profiling of emR3RawPrivileged. */
271 STAMPROFILE StatPrivEmu;
272 /** R3: Number of times emR3HmExecute is called. */
273 STAMCOUNTER StatHMExecuteCalled;
274 /** R3: Number of times emR3NEMExecute is called. */
275 STAMCOUNTER StatNEMExecuteCalled;
276
277 /** More statistics (R3). */
278 R3PTRTYPE(PEMSTATS) pStatsR3;
279 /** More statistics (R0). */
280 R0PTRTYPE(PEMSTATS) pStatsR0;
281
282 /** Tree for keeping track of cli occurrences (debug only). */
283 R3PTRTYPE(PAVLGCPTRNODECORE) pCliStatTree;
284 STAMCOUNTER StatTotalClis;
285 /** Align the next member at a 16-byte boundrary. */
286 uint64_t au64Padding2[1];
287
288 /** Exit history table (6KB). */
289 EMEXITENTRY aExitHistory[256];
290 /** Where to store the next exit history entry.
291 * Since aExitHistory is 256 items longs, we'll just increment this and
292 * mask it when using it. That help the readers detect whether we've
293 * wrapped around or not. */
294 uint64_t iNextExit;
295
296 /** Index into aExitRecords set by EMHistoryExec when returning to ring-3.
297 * This is UINT16_MAX if not armed. */
298 uint16_t volatile idxContinueExitRec;
299 /** Whether exit optimizations are enabled or not (in general). */
300 bool fExitOptimizationEnabled : 1;
301 /** Whether exit optimizations are enabled for ring-0 (in general). */
302 bool fExitOptimizationEnabledR0 : 1;
303 /** Whether exit optimizations are enabled for ring-0 when preemption is disabled. */
304 bool fExitOptimizationEnabledR0PreemptDisabled : 1;
305 /** Explicit padding. */
306 bool fPadding2;
307 /** Max number of instructions to execute. */
308 uint16_t cHistoryExecMaxInstructions;
309 /** Min number of instructions to execute while probing. */
310 uint16_t cHistoryProbeMinInstructions;
311 /** Max number of instructions to execute without an exit before giving up probe. */
312 uint16_t cHistoryProbeMaxInstructionsWithoutExit;
313 uint16_t uPadding3;
314 /** Number of exit records in use. */
315 uint32_t cExitRecordUsed;
316 /** Profiling the EMHistoryExec when executing (not probing). */
317 STAMPROFILE StatHistoryExec;
318 /** Number of saved exits. */
319 STAMCOUNTER StatHistoryExecSavedExits;
320 /** Number of instructions executed by EMHistoryExec. */
321 STAMCOUNTER StatHistoryExecInstructions;
322 uint64_t uPadding4;
323 /** Number of instructions executed by EMHistoryExec when probing. */
324 STAMCOUNTER StatHistoryProbeInstructions;
325 /** Number of times probing resulted in EMEXITACTION_NORMAL_PROBED. */
326 STAMCOUNTER StatHistoryProbedNormal;
327 /** Number of times probing resulted in EMEXITACTION_EXEC_WITH_MAX. */
328 STAMCOUNTER StatHistoryProbedExecWithMax;
329 /** Number of times probing resulted in ring-3 continuation. */
330 STAMCOUNTER StatHistoryProbedToRing3;
331 /** Profiling the EMHistoryExec when probing.*/
332 STAMPROFILE StatHistoryProbe;
333 /** Hit statistics for each lookup step. */
334 STAMCOUNTER aStatHistoryRecHits[16];
335 /** Type change statistics for each lookup step. */
336 STAMCOUNTER aStatHistoryRecTypeChanged[16];
337 /** Replacement statistics for each lookup step. */
338 STAMCOUNTER aStatHistoryRecReplaced[16];
339 /** New record statistics for each lookup step. */
340 STAMCOUNTER aStatHistoryRecNew[16];
341
342 /** Exit records (32KB). (Aligned on 32 byte boundrary.) */
343 EMEXITREC aExitRecords[1024];
344} EMCPU;
345/** Pointer to EM VM instance data. */
346typedef EMCPU *PEMCPU;
347
348/** @} */
349
350int emR3InitDbg(PVM pVM);
351
352int emR3HmExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
353VBOXSTRICTRC emR3NemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
354int emR3RawExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
355
356EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu);
357int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
358VBOXSTRICTRC emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rc);
359
360int emR3RawResumeHyper(PVM pVM, PVMCPU pVCpu);
361int emR3RawStep(PVM pVM, PVMCPU pVCpu);
362
363VBOXSTRICTRC emR3NemSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
364
365int emR3SingleStepExecRem(PVM pVM, PVMCPU pVCpu, uint32_t cIterations);
366
367bool emR3IsExecutionAllowed(PVM pVM, PVMCPU pVCpu);
368
369VBOXSTRICTRC emR3ExecutePendingIoPortWrite(PVM pVM, PVMCPU pVCpu);
370VBOXSTRICTRC emR3ExecutePendingIoPortRead(PVM pVM, PVMCPU pVCpu);
371
372RT_C_DECLS_END
373
374#endif /* !VMM_INCLUDED_SRC_include_EMInternal_h */
375
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