VirtualBox

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

Last change on this file since 80017 was 80017, 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.3 KB
Line 
1/* $Id: EMInternal.h 80017 2019-07-26 17:28:37Z 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 abPadding[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 union
229 {
230 /** Padding used in the other rings.
231 * This must be larger than jmp_buf on any supported platform. */
232 char achPaddingFatalLongJump[256];
233#ifdef IN_RING3
234 /** Long buffer jump for fatal VM errors.
235 * It will jump to before the outer EM loop is entered. */
236 jmp_buf FatalLongJump;
237#endif
238 } u;
239
240 /** For saving stack space, the disassembler state is allocated here instead of
241 * on the stack. */
242 DISCPUSTATE DisState;
243
244 /** @name Execution profiling.
245 * @{ */
246 STAMPROFILE StatForcedActions;
247 STAMPROFILE StatHalted;
248 STAMPROFILEADV StatCapped;
249 STAMPROFILEADV StatHMEntry;
250 STAMPROFILE StatHMExec;
251 STAMPROFILE StatIEMEmu;
252 STAMPROFILE StatIEMThenREM;
253 STAMPROFILEADV StatNEMEntry;
254 STAMPROFILE StatNEMExec;
255 STAMPROFILE StatREMEmu;
256 STAMPROFILE StatREMExec;
257 STAMPROFILE StatREMSync;
258 STAMPROFILEADV StatREMTotal;
259 STAMPROFILE StatRAWExec;
260 STAMPROFILEADV StatRAWEntry;
261 STAMPROFILEADV StatRAWTail;
262 STAMPROFILEADV StatRAWTotal;
263 STAMPROFILEADV StatTotal;
264 /** @} */
265
266 /** R3: Profiling of emR3RawExecuteIOInstruction. */
267 STAMPROFILE StatIOEmu;
268 /** R3: Profiling of emR3RawPrivileged. */
269 STAMPROFILE StatPrivEmu;
270 /** R3: Number of times emR3HmExecute is called. */
271 STAMCOUNTER StatHMExecuteCalled;
272 /** R3: Number of times emR3NEMExecute is called. */
273 STAMCOUNTER StatNEMExecuteCalled;
274
275 /** More statistics (R3). */
276 R3PTRTYPE(PEMSTATS) pStatsR3;
277 /** More statistics (R0). */
278 R0PTRTYPE(PEMSTATS) pStatsR0;
279
280 /** Tree for keeping track of cli occurrences (debug only). */
281 R3PTRTYPE(PAVLGCPTRNODECORE) pCliStatTree;
282 STAMCOUNTER StatTotalClis;
283 /** Put the history at a 32-byte boundrary. */
284 uint64_t au64Padding[3];
285
286 /** Exit history table (6KB). */
287 EMEXITENTRY aExitHistory[256];
288 /** Where to store the next exit history entry.
289 * Since aExitHistory is 256 items longs, we'll just increment this and
290 * mask it when using it. That help the readers detect whether we've
291 * wrapped around or not. */
292 uint64_t iNextExit;
293
294 /** Index into aExitRecords set by EMHistoryExec when returning to ring-3.
295 * This is UINT16_MAX if not armed. */
296 uint16_t volatile idxContinueExitRec;
297 /** Whether exit optimizations are enabled or not (in general). */
298 bool fExitOptimizationEnabled : 1;
299 /** Whether exit optimizations are enabled for ring-0 (in general). */
300 bool fExitOptimizationEnabledR0 : 1;
301 /** Whether exit optimizations are enabled for ring-0 when preemption is disabled. */
302 bool fExitOptimizationEnabledR0PreemptDisabled : 1;
303 /** Explicit padding. */
304 bool fPadding2;
305 /** Max number of instructions to execute. */
306 uint16_t cHistoryExecMaxInstructions;
307 /** Min number of instructions to execute while probing. */
308 uint16_t cHistoryProbeMinInstructions;
309 /** Max number of instructions to execute without an exit before giving up probe. */
310 uint16_t cHistoryProbeMaxInstructionsWithoutExit;
311 uint16_t uPadding3;
312 /** Number of exit records in use. */
313 uint32_t cExitRecordUsed;
314 /** Profiling the EMHistoryExec when executing (not probing). */
315 STAMPROFILE StatHistoryExec;
316 /** Number of saved exits. */
317 STAMCOUNTER StatHistoryExecSavedExits;
318 /** Number of instructions executed by EMHistoryExec. */
319 STAMCOUNTER StatHistoryExecInstructions;
320 uint64_t uPadding4;
321 /** Number of instructions executed by EMHistoryExec when probing. */
322 STAMCOUNTER StatHistoryProbeInstructions;
323 /** Number of times probing resulted in EMEXITACTION_NORMAL_PROBED. */
324 STAMCOUNTER StatHistoryProbedNormal;
325 /** Number of times probing resulted in EMEXITACTION_EXEC_WITH_MAX. */
326 STAMCOUNTER StatHistoryProbedExecWithMax;
327 /** Number of times probing resulted in ring-3 continuation. */
328 STAMCOUNTER StatHistoryProbedToRing3;
329 /** Profiling the EMHistoryExec when probing.*/
330 STAMPROFILE StatHistoryProbe;
331 /** Hit statistics for each lookup step. */
332 STAMCOUNTER aStatHistoryRecHits[16];
333 /** Type change statistics for each lookup step. */
334 STAMCOUNTER aStatHistoryRecTypeChanged[16];
335 /** Replacement statistics for each lookup step. */
336 STAMCOUNTER aStatHistoryRecReplaced[16];
337 /** New record statistics for each lookup step. */
338 STAMCOUNTER aStatHistoryRecNew[16];
339
340 /** Exit records (32KB). (Aligned on 32 byte boundrary.) */
341 EMEXITREC aExitRecords[1024];
342} EMCPU;
343/** Pointer to EM VM instance data. */
344typedef EMCPU *PEMCPU;
345
346/** @} */
347
348int emR3InitDbg(PVM pVM);
349
350int emR3HmExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
351VBOXSTRICTRC emR3NemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
352int emR3RawExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
353
354EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu);
355int emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
356VBOXSTRICTRC emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rc);
357
358int emR3RawResumeHyper(PVM pVM, PVMCPU pVCpu);
359int emR3RawStep(PVM pVM, PVMCPU pVCpu);
360
361VBOXSTRICTRC emR3NemSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
362
363int emR3SingleStepExecRem(PVM pVM, PVMCPU pVCpu, uint32_t cIterations);
364
365bool emR3IsExecutionAllowed(PVM pVM, PVMCPU pVCpu);
366
367VBOXSTRICTRC emR3ExecutePendingIoPortWrite(PVM pVM, PVMCPU pVCpu);
368VBOXSTRICTRC emR3ExecutePendingIoPortRead(PVM pVM, PVMCPU pVCpu);
369
370RT_C_DECLS_END
371
372#endif /* !VMM_INCLUDED_SRC_include_EMInternal_h */
373
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