VirtualBox

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

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

VMM,++: Refactoring code to use VMMC & VMMCPUCC. bugref:9217

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