VirtualBox

source: vbox/trunk/include/VBox/vmm/em.h@ 106061

Last change on this file since 106061 was 106061, checked in by vboxsync, 3 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
Line 
1/** @file
2 * EM - Execution Monitor.
3 */
4
5/*
6 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef VBOX_INCLUDED_vmm_em_h
37#define VBOX_INCLUDED_vmm_em_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <VBox/types.h>
43#include <VBox/vmm/trpm.h>
44#include <VBox/vmm/vmapi.h>
45
46
47RT_C_DECLS_BEGIN
48
49/** @defgroup grp_em The Execution Monitor / Manager API
50 * @ingroup grp_vmm
51 * @{
52 */
53
54/**
55 * The Execution Manager State.
56 *
57 * @remarks This is used in the saved state!
58 */
59typedef enum EMSTATE
60{
61 /** Invalid zero value. */
62 EMSTATE_INVALID = 0,
63 /** Not yet started. */
64 EMSTATE_NONE,
65 /** Raw-mode execution.
66 * @note obsolete, here only for saved state reasons. */
67 EMSTATE_RAW_OBSOLETE,
68 /** Hardware accelerated raw-mode execution. */
69 EMSTATE_HM,
70 /** Executing in IEM. */
71 EMSTATE_IEM,
72 /** Recompiled mode execution. */
73 EMSTATE_RECOMPILER,
74 /** Execution is halted. (waiting for interrupt)
75 * @note Relevant for saved state. */
76 EMSTATE_HALTED,
77 /** Application processor execution is halted (waiting for startup IPI (SIPI)).
78 * @note Relevant for saved state. */
79 EMSTATE_WAIT_SIPI,
80 /** Execution is suspended. */
81 EMSTATE_SUSPENDED,
82 /** The VM is terminating. */
83 EMSTATE_TERMINATING,
84 /** Guest debug event from raw-mode is being processed. */
85 EMSTATE_DEBUG_GUEST_RAW,
86 /** Guest debug event from hardware accelerated mode is being processed. */
87 EMSTATE_DEBUG_GUEST_HM,
88 /** Guest debug event from interpreted execution mode is being processed. */
89 EMSTATE_DEBUG_GUEST_IEM,
90 /** Guest debug event from recompiled-mode is being processed. */
91 EMSTATE_DEBUG_GUEST_RECOMPILER,
92 /** Hypervisor debug event being processed. */
93 EMSTATE_DEBUG_HYPER,
94 /** The VM has encountered a fatal error. (And everyone is panicing....) */
95 EMSTATE_GURU_MEDITATION,
96 /** Executing in IEM, falling back on REM if we cannot switch back to HM or
97 * RAW after a short while.
98 * @note obsolete, here only for saved state reasons. */
99 EMSTATE_IEM_THEN_REM_OBSOLETE,
100 /** Executing in native (API) execution monitor. */
101 EMSTATE_NEM,
102 /** Guest debug event from NEM mode is being processed. */
103 EMSTATE_DEBUG_GUEST_NEM,
104 /** End of valid values. */
105 EMSTATE_END,
106 /** Just a hack to ensure that we get a 32-bit integer. */
107 EMSTATE_MAKE_32BIT_HACK = 0x7fffffff
108} EMSTATE;
109AssertCompile(EMSTATE_HALTED == 6);
110AssertCompile(EMSTATE_WAIT_SIPI == 7);
111
112VMM_INT_DECL(EMSTATE) EMGetState(PVMCPU pVCpu);
113VMM_INT_DECL(void) EMSetState(PVMCPU pVCpu, EMSTATE enmNewState);
114VMMDECL(void) EMSetHypercallInstructionsEnabled(PVMCPU pVCpu, bool fEnabled);
115VMMDECL(bool) EMAreHypercallInstructionsEnabled(PVMCPU pVCpu);
116VMM_INT_DECL(bool) EMShouldContinueAfterHalt(PVMCPU pVCpu, PCPUMCTX pCtx);
117VMM_INT_DECL(bool) EMMonitorWaitShouldContinue(PVMCPU pVCpu, PCPUMCTX pCtx);
118VMM_INT_DECL(int) EMMonitorWaitPrepare(PVMCPU pVCpu, uint64_t rax, uint64_t rcx, uint64_t rdx, RTGCPHYS GCPhys);
119VMM_INT_DECL(void) EMMonitorWaitClear(PVMCPU pVCpu);
120VMM_INT_DECL(bool) EMMonitorIsArmed(PVMCPU pVCpu);
121VMM_INT_DECL(unsigned) EMMonitorWaitIsActive(PVMCPU pVCpu);
122VMM_INT_DECL(int) EMMonitorWaitPerform(PVMCPU pVCpu, uint64_t rax, uint64_t rcx);
123VMM_INT_DECL(int) EMUnhaltAndWakeUp(PVMCC pVM, PVMCPUCC pVCpuDst);
124VMMRZ_INT_DECL(VBOXSTRICTRC) EMRZSetPendingIoPortWrite(PVMCPU pVCpu, RTIOPORT uPort, uint8_t cbInstr, uint8_t cbValue, uint32_t uValue);
125VMMRZ_INT_DECL(VBOXSTRICTRC) EMRZSetPendingIoPortRead(PVMCPU pVCpu, RTIOPORT uPort, uint8_t cbInstr, uint8_t cbValue);
126
127/**
128 * Common defined exit types that EM knows what to do about.
129 *
130 * These should be used instead of the VT-x, SVM or NEM specific ones for exits
131 * worth optimizing.
132 */
133typedef enum EMEXITTYPE
134{
135 EMEXITTYPE_INVALID = 0,
136 EMEXITTYPE_IO_PORT_READ,
137 EMEXITTYPE_IO_PORT_WRITE,
138 EMEXITTYPE_IO_PORT_STR_READ,
139 EMEXITTYPE_IO_PORT_STR_WRITE,
140 EMEXITTYPE_MMIO,
141 EMEXITTYPE_MMIO_READ,
142 EMEXITTYPE_MMIO_WRITE,
143 EMEXITTYPE_MSR_READ,
144 EMEXITTYPE_MSR_WRITE,
145 EMEXITTYPE_CPUID,
146 EMEXITTYPE_RDTSC,
147 EMEXITTYPE_MOV_CRX,
148 EMEXITTYPE_MOV_DRX,
149 EMEXITTYPE_VMREAD,
150 EMEXITTYPE_VMWRITE,
151
152 /** @name Raw-mode only (for now), keep at end.
153 * @{ */
154 EMEXITTYPE_INVLPG,
155 EMEXITTYPE_LLDT,
156 EMEXITTYPE_RDPMC,
157 EMEXITTYPE_CLTS,
158 EMEXITTYPE_STI,
159 EMEXITTYPE_INT,
160 EMEXITTYPE_SYSCALL,
161 EMEXITTYPE_SYSENTER,
162 EMEXITTYPE_HLT
163 /** @} */
164} EMEXITTYPE;
165AssertCompileSize(EMEXITTYPE, 4);
166
167/** @name EMEXIT_F_XXX - EM exit flags.
168 *
169 * The flags the exit type are combined to a 32-bit number using the
170 * EMEXIT_MAKE_FT() macro.
171 *
172 * @{ */
173#define EMEXIT_F_TYPE_MASK UINT32_C(0x00000fff) /**< The exit type mask. */
174#define EMEXIT_F_KIND_EM UINT32_C(0x00000000) /**< EMEXITTYPE */
175#define EMEXIT_F_KIND_VMX UINT32_C(0x00001000) /**< VT-x exit codes. */
176#define EMEXIT_F_KIND_SVM UINT32_C(0x00002000) /**< SVM exit codes. */
177#define EMEXIT_F_KIND_NEM UINT32_C(0x00003000) /**< NEMEXITTYPE */
178#define EMEXIT_F_KIND_IEM UINT32_C(0x00004000) /**< IEM specific stuff. */
179#define EMEXIT_F_KIND_XCPT UINT32_C(0x00005000) /**< Exception numbers (IEM,raw-mode). */
180#define EMEXIT_F_KIND_MASK UINT32_C(0x00007000)
181#define EMEXIT_F_CS_EIP UINT32_C(0x00010000) /**< The PC is EIP in the low dword and CS in the high. */
182#define EMEXIT_F_UNFLATTENED_PC UINT32_C(0x00020000) /**< The PC hasn't had CS.BASE added to it. */
183/** HM is calling (from ring-0). Preemption is currently disabled or we're using preemption hooks. */
184#define EMEXIT_F_HM UINT32_C(0x00040000)
185#define EMEXIT_F_XCPT_ERRCD UINT32_C(0x00000800) /**< Additional record w/ the error code stored as PC. */
186#define EMEXIT_F_XCPT_CR2 UINT32_C(0x00000400) /**< Additional record w/ the CR3 value stored as PC. */
187/** Combines flags and exit type into EMHistoryAddExit() input. */
188#define EMEXIT_MAKE_FT(a_fFlags, a_uType) ((a_fFlags) | (uint32_t)(a_uType))
189/** @} */
190
191typedef enum EMEXITACTION
192{
193 /** The record is free. */
194 EMEXITACTION_FREE_RECORD = 0,
195 /** Take normal action on the exit. */
196 EMEXITACTION_NORMAL,
197 /** Take normal action on the exit, already probed and found nothing. */
198 EMEXITACTION_NORMAL_PROBED,
199 /** Do a probe execution. */
200 EMEXITACTION_EXEC_PROBE,
201 /** Execute using EMEXITREC::cMaxInstructionsWithoutExit. */
202 EMEXITACTION_EXEC_WITH_MAX
203} EMEXITACTION;
204AssertCompileSize(EMEXITACTION, 4);
205
206/**
207 * Accumulative exit record.
208 *
209 * This could perhaps be squeezed down a bit, but there isn't too much point.
210 * We'll probably need more data as time goes by.
211 */
212typedef struct EMEXITREC
213{
214 /** The flat PC of the exit. */
215 uint64_t uFlatPC;
216 /** Flags and type, see EMEXIT_MAKE_FT. */
217 uint32_t uFlagsAndType;
218 /** The action to take (EMEXITACTION). */
219 uint8_t enmAction;
220 uint8_t bUnused;
221 /** Maximum number of instructions to execute without hitting an exit. */
222 uint16_t cMaxInstructionsWithoutExit;
223 /** The exit number (EMCPU::iNextExit) at which it was last updated. */
224 uint64_t uLastExitNo;
225 /** Number of hits. */
226 uint64_t cHits;
227} EMEXITREC;
228AssertCompileSize(EMEXITREC, 32);
229/** Pointer to an accumulative exit record. */
230typedef EMEXITREC *PEMEXITREC;
231/** Pointer to a const accumulative exit record. */
232typedef EMEXITREC const *PCEMEXITREC;
233
234VMM_INT_DECL(PCEMEXITREC) EMHistoryAddExit(PVMCPUCC pVCpu, uint32_t uFlagsAndType, uint64_t uFlatPC, uint64_t uTimestamp);
235#ifdef IN_RC
236VMMRC_INT_DECL(void) EMRCHistoryAddExitCsEip(PVMCPU pVCpu, uint32_t uFlagsAndType, uint16_t uCs, uint32_t uEip,
237 uint64_t uTimestamp);
238#endif
239VMM_INT_DECL(void) EMHistoryUpdatePC(PVMCPUCC pVCpu, uint64_t uFlatPC, bool fFlattened);
240VMM_INT_DECL(PCEMEXITREC) EMHistoryUpdateFlagsAndType(PVMCPUCC pVCpu, uint32_t uFlagsAndType);
241VMM_INT_DECL(PCEMEXITREC) EMHistoryUpdateFlagsAndTypeAndPC(PVMCPUCC pVCpu, uint32_t uFlagsAndType, uint64_t uFlatPC);
242VMM_INT_DECL(VBOXSTRICTRC) EMHistoryExec(PVMCPUCC pVCpu, PCEMEXITREC pExitRec, uint32_t fWillExit);
243
244
245/** @name Deprecated interpretation related APIs (use IEM).
246 * @{ */
247VMM_INT_DECL(int) EMInterpretDisasCurrent(PVMCPUCC pVCpu, PDISSTATE pDis, unsigned *pcbInstr);
248VMM_INT_DECL(int) EMInterpretDisasOneEx(PVMCPUCC pVCpu, RTGCUINTPTR GCPtrInstr,
249 PDISSTATE pDis, unsigned *pcbInstr);
250VMM_INT_DECL(VBOXSTRICTRC) EMInterpretInstruction(PVMCPUCC pVCpu);
251VMM_INT_DECL(VBOXSTRICTRC) EMInterpretInstructionDisasState(PVMCPUCC pVCpu, PDISSTATE pDis, uint64_t rip);
252/** @} */
253
254
255/** @name EM_ONE_INS_FLAGS_XXX - flags for EMR3HmSingleInstruction (et al).
256 * @{ */
257/** Return when CS:RIP changes or some other important event happens.
258 * This means running whole REP and LOOP $ sequences for instance. */
259#define EM_ONE_INS_FLAGS_RIP_CHANGE RT_BIT_32(0)
260/** Mask of valid flags. */
261#define EM_ONE_INS_FLAGS_MASK UINT32_C(0x00000001)
262/** @} */
263
264
265#ifdef IN_RING0
266/** @defgroup grp_em_r0 The EM Host Context Ring-0 API
267 * @{ */
268VMMR0_INT_DECL(int) EMR0InitVM(PGVM pGVM);
269/** @} */
270#endif
271
272
273#ifdef IN_RING3
274/** @defgroup grp_em_r3 The EM Host Context Ring-3 API
275 * @{
276 */
277
278/**
279 * For use with EMR3SetExecutionPolicy() and EMR3QueryExecutionPolicy().
280 *
281 * It's possible to extend this interface to change several
282 * execution modes at once should the need arise.
283 */
284typedef enum EMEXECPOLICY
285{
286 /** The customary invalid zero entry. */
287 EMEXECPOLICY_INVALID = 0,
288 /** Whether to only use IEM for execution. */
289 EMEXECPOLICY_IEM_ALL,
290 /** Whether IEM is recompiled when used for mass execution. */
291 EMEXECPOLICY_IEM_RECOMPILED,
292 /** End of valid value (not included). */
293 EMEXECPOLICY_END,
294 /** The customary 32-bit type blowup. */
295 EMEXECPOLICY_32BIT_HACK = 0x7fffffff
296} EMEXECPOLICY;
297VMMR3DECL(int) EMR3SetExecutionPolicy(PUVM pUVM, EMEXECPOLICY enmPolicy, bool fEnforce);
298VMMR3DECL(int) EMR3QueryExecutionPolicy(PUVM pUVM, EMEXECPOLICY enmPolicy, bool *pfEnforced);
299VMMR3DECL(int) EMR3QueryMainExecutionEngine(PUVM pUVM, uint8_t *pbMainExecutionEngine);
300
301VMMR3_INT_DECL(int) EMR3Init(PVM pVM);
302VMMR3_INT_DECL(int) EMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
303VMMR3_INT_DECL(void) EMR3Relocate(PVM pVM);
304VMMR3_INT_DECL(void) EMR3ResetCpu(PVMCPU pVCpu);
305VMMR3_INT_DECL(void) EMR3Reset(PVM pVM);
306VMMR3_INT_DECL(int) EMR3Term(PVM pVM);
307VMMR3DECL(DECL_NO_RETURN(void)) EMR3FatalError(PVMCPU pVCpu, int rc);
308VMMR3_INT_DECL(int) EMR3ExecuteVM(PVM pVM, PVMCPU pVCpu);
309VMMR3_INT_DECL(int) EMR3CheckRawForcedActions(PVM pVM, PVMCPU pVCpu);
310VMMR3_INT_DECL(VBOXSTRICTRC) EMR3HmSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
311
312/** @} */
313#endif /* IN_RING3 */
314
315/** @} */
316
317RT_C_DECLS_END
318
319#endif /* !VBOX_INCLUDED_vmm_em_h */
320
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