VirtualBox

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

Last change on this file since 99582 was 99208, checked in by vboxsync, 21 months ago

Disassembler,VMM,Runtime: Get rid of deprecated DISCPUSTATE types (preparation for architecture specific separation in order to support ARMv8), bugref:10394

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.1 KB
Line 
1/** @file
2 * EM - Execution Monitor.
3 */
4
5/*
6 * Copyright (C) 2006-2023 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/** Enable to allow V86 code to run in raw mode. */
55#define VBOX_RAW_V86
56
57/**
58 * The Execution Manager State.
59 *
60 * @remarks This is used in the saved state!
61 */
62typedef enum EMSTATE
63{
64 /** Not yet started. */
65 EMSTATE_NONE = 1,
66 /** Raw-mode execution. */
67 EMSTATE_RAW,
68 /** Hardware accelerated raw-mode execution. */
69 EMSTATE_HM,
70 /** Executing in IEM. */
71 EMSTATE_IEM,
72 /** Recompiled mode execution. */
73 EMSTATE_REM,
74 /** Execution is halted. (waiting for interrupt) */
75 EMSTATE_HALTED,
76 /** Application processor execution is halted. (waiting for startup IPI (SIPI)) */
77 EMSTATE_WAIT_SIPI,
78 /** Execution is suspended. */
79 EMSTATE_SUSPENDED,
80 /** The VM is terminating. */
81 EMSTATE_TERMINATING,
82 /** Guest debug event from raw-mode is being processed. */
83 EMSTATE_DEBUG_GUEST_RAW,
84 /** Guest debug event from hardware accelerated mode is being processed. */
85 EMSTATE_DEBUG_GUEST_HM,
86 /** Guest debug event from interpreted execution mode is being processed. */
87 EMSTATE_DEBUG_GUEST_IEM,
88 /** Guest debug event from recompiled-mode is being processed. */
89 EMSTATE_DEBUG_GUEST_REM,
90 /** Hypervisor debug event being processed. */
91 EMSTATE_DEBUG_HYPER,
92 /** The VM has encountered a fatal error. (And everyone is panicing....) */
93 EMSTATE_GURU_MEDITATION,
94 /** Executing in IEM, falling back on REM if we cannot switch back to HM or
95 * RAW after a short while. */
96 EMSTATE_IEM_THEN_REM,
97 /** Executing in native (API) execution monitor. */
98 EMSTATE_NEM,
99 /** Guest debug event from NEM mode is being processed. */
100 EMSTATE_DEBUG_GUEST_NEM,
101 /** Just a hack to ensure that we get a 32-bit integer. */
102 EMSTATE_MAKE_32BIT_HACK = 0x7fffffff
103} EMSTATE;
104
105
106/**
107 * EMInterpretInstructionCPU execution modes.
108 */
109typedef enum
110{
111 /** Only supervisor code (CPL=0). */
112 EMCODETYPE_SUPERVISOR,
113 /** User-level code only. */
114 EMCODETYPE_USER,
115 /** Supervisor and user-level code (use with great care!). */
116 EMCODETYPE_ALL,
117 /** Just a hack to ensure that we get a 32-bit integer. */
118 EMCODETYPE_32BIT_HACK = 0x7fffffff
119} EMCODETYPE;
120
121VMM_INT_DECL(EMSTATE) EMGetState(PVMCPU pVCpu);
122VMM_INT_DECL(void) EMSetState(PVMCPU pVCpu, EMSTATE enmNewState);
123
124/** @name Callback handlers for instruction emulation functions.
125 * These are placed here because IOM wants to use them as well.
126 * @{
127 */
128typedef DECLCALLBACKTYPE(uint32_t, FNEMULATEPARAM2UINT32,(void *pvParam1, uint64_t val2));
129typedef FNEMULATEPARAM2UINT32 *PFNEMULATEPARAM2UINT32;
130typedef DECLCALLBACKTYPE(uint32_t, FNEMULATEPARAM2,(void *pvParam1, size_t val2));
131typedef FNEMULATEPARAM2 *PFNEMULATEPARAM2;
132typedef DECLCALLBACKTYPE(uint32_t, FNEMULATEPARAM3,(void *pvParam1, uint64_t val2, size_t val3));
133typedef FNEMULATEPARAM3 *PFNEMULATEPARAM3;
134typedef DECLCALLBACKTYPE(int, FNEMULATELOCKPARAM2,(void *pvParam1, uint64_t val2, RTGCUINTREG32 *pf));
135typedef FNEMULATELOCKPARAM2 *PFNEMULATELOCKPARAM2;
136typedef DECLCALLBACKTYPE(int, FNEMULATELOCKPARAM3,(void *pvParam1, uint64_t val2, size_t cb, RTGCUINTREG32 *pf));
137typedef FNEMULATELOCKPARAM3 *PFNEMULATELOCKPARAM3;
138/** @} */
139
140VMMDECL(void) EMSetHypercallInstructionsEnabled(PVMCPU pVCpu, bool fEnabled);
141VMMDECL(bool) EMAreHypercallInstructionsEnabled(PVMCPU pVCpu);
142VMM_INT_DECL(bool) EMShouldContinueAfterHalt(PVMCPU pVCpu, PCPUMCTX pCtx);
143VMM_INT_DECL(bool) EMMonitorWaitShouldContinue(PVMCPU pVCpu, PCPUMCTX pCtx);
144VMM_INT_DECL(int) EMMonitorWaitPrepare(PVMCPU pVCpu, uint64_t rax, uint64_t rcx, uint64_t rdx, RTGCPHYS GCPhys);
145VMM_INT_DECL(void) EMMonitorWaitClear(PVMCPU pVCpu);
146VMM_INT_DECL(bool) EMMonitorIsArmed(PVMCPU pVCpu);
147VMM_INT_DECL(unsigned) EMMonitorWaitIsActive(PVMCPU pVCpu);
148VMM_INT_DECL(int) EMMonitorWaitPerform(PVMCPU pVCpu, uint64_t rax, uint64_t rcx);
149VMM_INT_DECL(int) EMUnhaltAndWakeUp(PVMCC pVM, PVMCPUCC pVCpuDst);
150VMMRZ_INT_DECL(VBOXSTRICTRC) EMRZSetPendingIoPortWrite(PVMCPU pVCpu, RTIOPORT uPort, uint8_t cbInstr, uint8_t cbValue, uint32_t uValue);
151VMMRZ_INT_DECL(VBOXSTRICTRC) EMRZSetPendingIoPortRead(PVMCPU pVCpu, RTIOPORT uPort, uint8_t cbInstr, uint8_t cbValue);
152
153/**
154 * Common defined exit types that EM knows what to do about.
155 *
156 * These should be used instead of the VT-x, SVM or NEM specific ones for exits
157 * worth optimizing.
158 */
159typedef enum EMEXITTYPE
160{
161 EMEXITTYPE_INVALID = 0,
162 EMEXITTYPE_IO_PORT_READ,
163 EMEXITTYPE_IO_PORT_WRITE,
164 EMEXITTYPE_IO_PORT_STR_READ,
165 EMEXITTYPE_IO_PORT_STR_WRITE,
166 EMEXITTYPE_MMIO,
167 EMEXITTYPE_MMIO_READ,
168 EMEXITTYPE_MMIO_WRITE,
169 EMEXITTYPE_MSR_READ,
170 EMEXITTYPE_MSR_WRITE,
171 EMEXITTYPE_CPUID,
172 EMEXITTYPE_RDTSC,
173 EMEXITTYPE_MOV_CRX,
174 EMEXITTYPE_MOV_DRX,
175 EMEXITTYPE_VMREAD,
176 EMEXITTYPE_VMWRITE,
177
178 /** @name Raw-mode only (for now), keep at end.
179 * @{ */
180 EMEXITTYPE_INVLPG,
181 EMEXITTYPE_LLDT,
182 EMEXITTYPE_RDPMC,
183 EMEXITTYPE_CLTS,
184 EMEXITTYPE_STI,
185 EMEXITTYPE_INT,
186 EMEXITTYPE_SYSCALL,
187 EMEXITTYPE_SYSENTER,
188 EMEXITTYPE_HLT
189 /** @} */
190} EMEXITTYPE;
191AssertCompileSize(EMEXITTYPE, 4);
192
193/** @name EMEXIT_F_XXX - EM exit flags.
194 *
195 * The flags the exit type are combined to a 32-bit number using the
196 * EMEXIT_MAKE_FT() macro.
197 *
198 * @{ */
199#define EMEXIT_F_TYPE_MASK UINT32_C(0x00000fff) /**< The exit type mask. */
200#define EMEXIT_F_KIND_EM UINT32_C(0x00000000) /**< EMEXITTYPE */
201#define EMEXIT_F_KIND_VMX UINT32_C(0x00001000) /**< VT-x exit codes. */
202#define EMEXIT_F_KIND_SVM UINT32_C(0x00002000) /**< SVM exit codes. */
203#define EMEXIT_F_KIND_NEM UINT32_C(0x00003000) /**< NEMEXITTYPE */
204#define EMEXIT_F_KIND_XCPT UINT32_C(0x00004000) /**< Exception numbers (raw-mode). */
205#define EMEXIT_F_KIND_MASK UINT32_C(0x00007000)
206#define EMEXIT_F_CS_EIP UINT32_C(0x00010000) /**< The PC is EIP in the low dword and CS in the high. */
207#define EMEXIT_F_UNFLATTENED_PC UINT32_C(0x00020000) /**< The PC hasn't had CS.BASE added to it. */
208/** HM is calling (from ring-0). Preemption is currently disabled or we're using preemption hooks. */
209#define EMEXIT_F_HM UINT32_C(0x00040000)
210/** Combines flags and exit type into EMHistoryAddExit() input. */
211#define EMEXIT_MAKE_FT(a_fFlags, a_uType) ((a_fFlags) | (uint32_t)(a_uType))
212/** @} */
213
214typedef enum EMEXITACTION
215{
216 /** The record is free. */
217 EMEXITACTION_FREE_RECORD = 0,
218 /** Take normal action on the exit. */
219 EMEXITACTION_NORMAL,
220 /** Take normal action on the exit, already probed and found nothing. */
221 EMEXITACTION_NORMAL_PROBED,
222 /** Do a probe execution. */
223 EMEXITACTION_EXEC_PROBE,
224 /** Execute using EMEXITREC::cMaxInstructionsWithoutExit. */
225 EMEXITACTION_EXEC_WITH_MAX
226} EMEXITACTION;
227AssertCompileSize(EMEXITACTION, 4);
228
229/**
230 * Accumulative exit record.
231 *
232 * This could perhaps be squeezed down a bit, but there isn't too much point.
233 * We'll probably need more data as time goes by.
234 */
235typedef struct EMEXITREC
236{
237 /** The flat PC of the exit. */
238 uint64_t uFlatPC;
239 /** Flags and type, see EMEXIT_MAKE_FT. */
240 uint32_t uFlagsAndType;
241 /** The action to take (EMEXITACTION). */
242 uint8_t enmAction;
243 uint8_t bUnused;
244 /** Maximum number of instructions to execute without hitting an exit. */
245 uint16_t cMaxInstructionsWithoutExit;
246 /** The exit number (EMCPU::iNextExit) at which it was last updated. */
247 uint64_t uLastExitNo;
248 /** Number of hits. */
249 uint64_t cHits;
250} EMEXITREC;
251AssertCompileSize(EMEXITREC, 32);
252/** Pointer to an accumulative exit record. */
253typedef EMEXITREC *PEMEXITREC;
254/** Pointer to a const accumulative exit record. */
255typedef EMEXITREC const *PCEMEXITREC;
256
257VMM_INT_DECL(PCEMEXITREC) EMHistoryAddExit(PVMCPUCC pVCpu, uint32_t uFlagsAndType, uint64_t uFlatPC, uint64_t uTimestamp);
258#ifdef IN_RC
259VMMRC_INT_DECL(void) EMRCHistoryAddExitCsEip(PVMCPU pVCpu, uint32_t uFlagsAndType, uint16_t uCs, uint32_t uEip,
260 uint64_t uTimestamp);
261#endif
262VMM_INT_DECL(void) EMHistoryUpdatePC(PVMCPUCC pVCpu, uint64_t uFlatPC, bool fFlattened);
263VMM_INT_DECL(PCEMEXITREC) EMHistoryUpdateFlagsAndType(PVMCPUCC pVCpu, uint32_t uFlagsAndType);
264VMM_INT_DECL(PCEMEXITREC) EMHistoryUpdateFlagsAndTypeAndPC(PVMCPUCC pVCpu, uint32_t uFlagsAndType, uint64_t uFlatPC);
265VMM_INT_DECL(VBOXSTRICTRC) EMHistoryExec(PVMCPUCC pVCpu, PCEMEXITREC pExitRec, uint32_t fWillExit);
266
267
268/** @name Deprecated interpretation related APIs (use IEM).
269 * @{ */
270VMM_INT_DECL(int) EMInterpretDisasCurrent(PVMCPUCC pVCpu, PDISSTATE pDis, unsigned *pcbInstr);
271VMM_INT_DECL(int) EMInterpretDisasOneEx(PVMCPUCC pVCpu, RTGCUINTPTR GCPtrInstr,
272 PDISSTATE pDis, unsigned *pcbInstr);
273VMM_INT_DECL(VBOXSTRICTRC) EMInterpretInstruction(PVMCPUCC pVCpu);
274VMM_INT_DECL(VBOXSTRICTRC) EMInterpretInstructionDisasState(PVMCPUCC pVCpu, PDISSTATE pDis, uint64_t rip);
275/** @} */
276
277
278/** @name EM_ONE_INS_FLAGS_XXX - flags for EMR3HmSingleInstruction (et al).
279 * @{ */
280/** Return when CS:RIP changes or some other important event happens.
281 * This means running whole REP and LOOP $ sequences for instance. */
282#define EM_ONE_INS_FLAGS_RIP_CHANGE RT_BIT_32(0)
283/** Mask of valid flags. */
284#define EM_ONE_INS_FLAGS_MASK UINT32_C(0x00000001)
285/** @} */
286
287
288#ifdef IN_RING0
289/** @defgroup grp_em_r0 The EM Host Context Ring-0 API
290 * @{ */
291VMMR0_INT_DECL(int) EMR0InitVM(PGVM pGVM);
292/** @} */
293#endif
294
295
296#ifdef IN_RING3
297/** @defgroup grp_em_r3 The EM Host Context Ring-3 API
298 * @{
299 */
300
301/**
302 * Command argument for EMR3RawSetMode().
303 *
304 * It's possible to extend this interface to change several
305 * execution modes at once should the need arise.
306 */
307typedef enum EMEXECPOLICY
308{
309 /** The customary invalid zero entry. */
310 EMEXECPOLICY_INVALID = 0,
311 /** Whether to recompile ring-0 code or execute it in raw/hm. */
312 EMEXECPOLICY_RECOMPILE_RING0,
313 /** Whether to recompile ring-3 code or execute it in raw/hm. */
314 EMEXECPOLICY_RECOMPILE_RING3,
315 /** Whether to only use IEM for execution. */
316 EMEXECPOLICY_IEM_ALL,
317 /** End of valid value (not included). */
318 EMEXECPOLICY_END,
319 /** The customary 32-bit type blowup. */
320 EMEXECPOLICY_32BIT_HACK = 0x7fffffff
321} EMEXECPOLICY;
322VMMR3DECL(int) EMR3SetExecutionPolicy(PUVM pUVM, EMEXECPOLICY enmPolicy, bool fEnforce);
323VMMR3DECL(int) EMR3QueryExecutionPolicy(PUVM pUVM, EMEXECPOLICY enmPolicy, bool *pfEnforced);
324VMMR3DECL(int) EMR3QueryMainExecutionEngine(PUVM pUVM, uint8_t *pbMainExecutionEngine);
325
326VMMR3_INT_DECL(int) EMR3Init(PVM pVM);
327VMMR3_INT_DECL(int) EMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
328VMMR3_INT_DECL(void) EMR3Relocate(PVM pVM);
329VMMR3_INT_DECL(void) EMR3ResetCpu(PVMCPU pVCpu);
330VMMR3_INT_DECL(void) EMR3Reset(PVM pVM);
331VMMR3_INT_DECL(int) EMR3Term(PVM pVM);
332VMMR3DECL(DECL_NO_RETURN(void)) EMR3FatalError(PVMCPU pVCpu, int rc);
333VMMR3_INT_DECL(int) EMR3ExecuteVM(PVM pVM, PVMCPU pVCpu);
334VMMR3_INT_DECL(int) EMR3CheckRawForcedActions(PVM pVM, PVMCPU pVCpu);
335VMMR3_INT_DECL(VBOXSTRICTRC) EMR3HmSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
336
337/** @} */
338#endif /* IN_RING3 */
339
340/** @} */
341
342RT_C_DECLS_END
343
344#endif /* !VBOX_INCLUDED_vmm_em_h */
345
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