1 | /** @file
|
---|
2 | * EM - Execution Monitor.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2010 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_vmm_em_h
|
---|
27 | #define ___VBox_vmm_em_h
|
---|
28 |
|
---|
29 | #include <VBox/types.h>
|
---|
30 | #include <VBox/vmm/trpm.h>
|
---|
31 |
|
---|
32 |
|
---|
33 | RT_C_DECLS_BEGIN
|
---|
34 |
|
---|
35 | /** @defgroup grp_em The Execution Monitor / Manager API
|
---|
36 | * @{
|
---|
37 | */
|
---|
38 |
|
---|
39 | /** Enable to allow V86 code to run in raw mode. */
|
---|
40 | #define VBOX_RAW_V86
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * The Execution Manager State.
|
---|
44 | *
|
---|
45 | * @remarks This is used in the saved state!
|
---|
46 | */
|
---|
47 | typedef enum EMSTATE
|
---|
48 | {
|
---|
49 | /** Not yet started. */
|
---|
50 | EMSTATE_NONE = 1,
|
---|
51 | /** Raw-mode execution. */
|
---|
52 | EMSTATE_RAW,
|
---|
53 | /** Hardware accelerated raw-mode execution. */
|
---|
54 | EMSTATE_HWACC,
|
---|
55 | /** Value reserved for future use (used to be PARAV). */
|
---|
56 | EMSTATE_RESERVED,
|
---|
57 | /** Recompiled mode execution. */
|
---|
58 | EMSTATE_REM,
|
---|
59 | /** Execution is halted. (waiting for interrupt) */
|
---|
60 | EMSTATE_HALTED,
|
---|
61 | /** Application processor execution is halted. (waiting for startup IPI (SIPI)) */
|
---|
62 | EMSTATE_WAIT_SIPI,
|
---|
63 | /** Execution is suspended. */
|
---|
64 | EMSTATE_SUSPENDED,
|
---|
65 | /** The VM is terminating. */
|
---|
66 | EMSTATE_TERMINATING,
|
---|
67 | /** Guest debug event from raw-mode is being processed. */
|
---|
68 | EMSTATE_DEBUG_GUEST_RAW,
|
---|
69 | /** Guest debug event from hardware accelerated mode is being processed. */
|
---|
70 | EMSTATE_DEBUG_GUEST_HWACC,
|
---|
71 | /** Guest debug event from recompiled-mode is being processed. */
|
---|
72 | EMSTATE_DEBUG_GUEST_REM,
|
---|
73 | /** Hypervisor debug event being processed. */
|
---|
74 | EMSTATE_DEBUG_HYPER,
|
---|
75 | /** The VM has encountered a fatal error. (And everyone is panicing....) */
|
---|
76 | EMSTATE_GURU_MEDITATION,
|
---|
77 | /** Just a hack to ensure that we get a 32-bit integer. */
|
---|
78 | EMSTATE_MAKE_32BIT_HACK = 0x7fffffff
|
---|
79 | } EMSTATE;
|
---|
80 |
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * EMInterpretInstructionCPU execution modes.
|
---|
84 | */
|
---|
85 | typedef enum
|
---|
86 | {
|
---|
87 | /** Only supervisor code (CPL=0). */
|
---|
88 | EMCODETYPE_SUPERVISOR,
|
---|
89 | /** User-level code only. */
|
---|
90 | EMCODETYPE_USER,
|
---|
91 | /** Supervisor and user-level code (use with great care!). */
|
---|
92 | EMCODETYPE_ALL,
|
---|
93 | /** Just a hack to ensure that we get a 32-bit integer. */
|
---|
94 | EMCODETYPE_32BIT_HACK = 0x7fffffff
|
---|
95 | } EMCODETYPE;
|
---|
96 |
|
---|
97 | VMMDECL(EMSTATE) EMGetState(PVMCPU pVCpu);
|
---|
98 | VMMDECL(void) EMSetState(PVMCPU pVCpu, EMSTATE enmNewState);
|
---|
99 |
|
---|
100 | /** @name Callback handlers for instruction emulation functions.
|
---|
101 | * These are placed here because IOM wants to use them as well.
|
---|
102 | * @{
|
---|
103 | */
|
---|
104 | typedef DECLCALLBACK(uint32_t) FNEMULATEPARAM2UINT32(void *pvParam1, uint64_t val2);
|
---|
105 | typedef FNEMULATEPARAM2UINT32 *PFNEMULATEPARAM2UINT32;
|
---|
106 | typedef DECLCALLBACK(uint32_t) FNEMULATEPARAM2(void *pvParam1, size_t val2);
|
---|
107 | typedef FNEMULATEPARAM2 *PFNEMULATEPARAM2;
|
---|
108 | typedef DECLCALLBACK(uint32_t) FNEMULATEPARAM3(void *pvParam1, uint64_t val2, size_t val3);
|
---|
109 | typedef FNEMULATEPARAM3 *PFNEMULATEPARAM3;
|
---|
110 | typedef DECLCALLBACK(int) FNEMULATELOCKPARAM2(void *pvParam1, uint64_t val2, RTGCUINTREG32 *pf);
|
---|
111 | typedef FNEMULATELOCKPARAM2 *PFNEMULATELOCKPARAM2;
|
---|
112 | typedef DECLCALLBACK(int) FNEMULATELOCKPARAM3(void *pvParam1, uint64_t val2, size_t cb, RTGCUINTREG32 *pf);
|
---|
113 | typedef FNEMULATELOCKPARAM3 *PFNEMULATELOCKPARAM3;
|
---|
114 | /** @} */
|
---|
115 |
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Checks if raw ring-3 execute mode is enabled.
|
---|
119 | *
|
---|
120 | * @returns true if enabled.
|
---|
121 | * @returns false if disabled.
|
---|
122 | * @param pVM The VM to operate on.
|
---|
123 | */
|
---|
124 | #define EMIsRawRing3Enabled(pVM) (!(pVM)->fRecompileUser)
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Checks if raw ring-0 execute mode is enabled.
|
---|
128 | *
|
---|
129 | * @returns true if enabled.
|
---|
130 | * @returns false if disabled.
|
---|
131 | * @param pVM The VM to operate on.
|
---|
132 | */
|
---|
133 | #define EMIsRawRing0Enabled(pVM) (!(pVM)->fRecompileSupervisor)
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Checks if execution with hardware assisted virtualization is enabled.
|
---|
137 | *
|
---|
138 | * @returns true if enabled.
|
---|
139 | * @returns false if disabled.
|
---|
140 | * @param pVM The VM to operate on.
|
---|
141 | */
|
---|
142 | #define EMIsHwVirtExecutionEnabled(pVM) (!(pVM)->fRecompileSupervisor && !(pVM)->fRecompileUser)
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Checks if execution of supervisor code should be done in the
|
---|
146 | * recompiler or not.
|
---|
147 | *
|
---|
148 | * @returns true if enabled.
|
---|
149 | * @returns false if disabled.
|
---|
150 | * @param pVM The VM to operate on.
|
---|
151 | */
|
---|
152 | #define EMIsSupervisorCodeRecompiled(pVM) ((pVM)->fRecompileSupervisor)
|
---|
153 |
|
---|
154 | VMMDECL(void) EMSetInhibitInterruptsPC(PVMCPU pVCpu, RTGCUINTPTR PC);
|
---|
155 | VMMDECL(RTGCUINTPTR) EMGetInhibitInterruptsPC(PVMCPU pVCpu);
|
---|
156 | VMMDECL(int) EMInterpretDisasOne(PVM pVM, PVMCPU pVCpu, PCCPUMCTXCORE pCtxCore, PDISCPUSTATE pCpu, unsigned *pcbInstr);
|
---|
157 | VMMDECL(int) EMInterpretDisasOneEx(PVM pVM, PVMCPU pVCpu, RTGCUINTPTR GCPtrInstr, PCCPUMCTXCORE pCtxCore,
|
---|
158 | PDISCPUSTATE pDISState, unsigned *pcbInstr);
|
---|
159 | VMMDECL(VBOXSTRICTRC) EMInterpretInstruction(PVMCPU pVCpu, PCPUMCTXCORE pCoreCtx, RTGCPTR pvFault);
|
---|
160 | VMMDECL(VBOXSTRICTRC) EMInterpretInstructionEx(PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbWritten);
|
---|
161 | VMMDECL(VBOXSTRICTRC) EMInterpretInstructionDisasState(PVMCPU pVCpu, PDISCPUSTATE pDis, PCPUMCTXCORE pCoreCtx, RTGCPTR pvFault, EMCODETYPE enmCodeType);
|
---|
162 |
|
---|
163 | #ifdef IN_RC
|
---|
164 | VMMDECL(int) EMInterpretIretV86ForPatm(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | #ifndef VBOX_WITH_IEM
|
---|
168 | VMMDECL(int) EMInterpretCpuId(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
|
---|
169 | VMMDECL(int) EMInterpretRdtsc(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
|
---|
170 | VMMDECL(int) EMInterpretRdpmc(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
|
---|
171 | VMMDECL(int) EMInterpretRdtscp(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
|
---|
172 | VMMDECL(VBOXSTRICTRC) EMInterpretInvlpg(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pAddrGC);
|
---|
173 | VMMDECL(VBOXSTRICTRC) EMInterpretMWait(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
|
---|
174 | VMMDECL(int) EMInterpretMonitor(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
|
---|
175 | VMMDECL(int) EMInterpretDRxWrite(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint32_t DestRegDrx, uint32_t SrcRegGen);
|
---|
176 | VMMDECL(int) EMInterpretDRxRead(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegDrx);
|
---|
177 | VMMDECL(int) EMInterpretCRxWrite(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint32_t DestRegCrx, uint32_t SrcRegGen);
|
---|
178 | VMMDECL(int) EMInterpretCRxRead(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegCrx);
|
---|
179 | VMMDECL(int) EMInterpretLMSW(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint16_t u16Data);
|
---|
180 | VMMDECL(int) EMInterpretCLTS(PVM pVM, PVMCPU pVCpu);
|
---|
181 | VMMDECL(int) EMInterpretRdmsr(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
|
---|
182 | VMMDECL(int) EMInterpretWrmsr(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
|
---|
183 | #endif /* !VBOX_WITH_IEM */
|
---|
184 | VMM_INT_DECL(bool) EMShouldContinueAfterHalt(PVMCPU pVCpu, PCPUMCTX pCtx);
|
---|
185 | VMM_INT_DECL(int) EMMonitorWaitPrepare(PVMCPU pVCpu, uint64_t rax, uint64_t rcx, uint64_t rdx);
|
---|
186 | VMM_INT_DECL(int) EMMonitorWaitPerform(PVMCPU pVCpu, uint64_t rax, uint64_t rcx);
|
---|
187 |
|
---|
188 | /** @name Assembly routines
|
---|
189 | * @{ */
|
---|
190 | VMMDECL(uint32_t) EMEmulateCmp(uint32_t u32Param1, uint64_t u64Param2, size_t cb);
|
---|
191 | VMMDECL(uint32_t) EMEmulateAnd(void *pvParam1, uint64_t u64Param2, size_t cb);
|
---|
192 | VMMDECL(uint32_t) EMEmulateInc(void *pvParam1, size_t cb);
|
---|
193 | VMMDECL(uint32_t) EMEmulateDec(void *pvParam1, size_t cb);
|
---|
194 | VMMDECL(uint32_t) EMEmulateOr(void *pvParam1, uint64_t u64Param2, size_t cb);
|
---|
195 | VMMDECL(int) EMEmulateLockOr(void *pvParam1, uint64_t u64Param2, size_t cbSize, RTGCUINTREG32 *pf);
|
---|
196 | VMMDECL(uint32_t) EMEmulateXor(void *pvParam1, uint64_t u64Param2, size_t cb);
|
---|
197 | VMMDECL(int) EMEmulateLockXor(void *pvParam1, uint64_t u64Param2, size_t cbSize, RTGCUINTREG32 *pf);
|
---|
198 | VMMDECL(uint32_t) EMEmulateAdd(void *pvParam1, uint64_t u64Param2, size_t cb);
|
---|
199 | VMMDECL(int) EMEmulateLockAnd(void *pvParam1, uint64_t u64Param2, size_t cbSize, RTGCUINTREG32 *pf);
|
---|
200 | VMMDECL(uint32_t) EMEmulateSub(void *pvParam1, uint64_t u64Param2, size_t cb);
|
---|
201 | VMMDECL(uint32_t) EMEmulateAdcWithCarrySet(void *pvParam1, uint64_t u64Param2, size_t cb);
|
---|
202 | VMMDECL(uint32_t) EMEmulateBtr(void *pvParam1, uint64_t u64Param2);
|
---|
203 | VMMDECL(int) EMEmulateLockBtr(void *pvParam1, uint64_t u64Param2, RTGCUINTREG32 *pf);
|
---|
204 | VMMDECL(uint32_t) EMEmulateBts(void *pvParam1, uint64_t u64Param2);
|
---|
205 | VMMDECL(uint32_t) EMEmulateBtc(void *pvParam1, uint64_t u64Param2);
|
---|
206 | VMMDECL(uint32_t) EMEmulateCmpXchg(void *pvParam1, uint64_t *pu32Param2, uint64_t u32Param3, size_t cbSize);
|
---|
207 | VMMDECL(uint32_t) EMEmulateLockCmpXchg(void *pvParam1, uint64_t *pu64Param2, uint64_t u64Param3, size_t cbSize);
|
---|
208 | VMMDECL(uint32_t) EMEmulateCmpXchg8b(void *pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
|
---|
209 | VMMDECL(uint32_t) EMEmulateLockCmpXchg8b(void *pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
|
---|
210 | VMMDECL(uint32_t) EMEmulateXAdd(void *pvParam1, void *pvParam2, size_t cbOp);
|
---|
211 | VMMDECL(uint32_t) EMEmulateLockXAdd(void *pvParam1, void *pvParam2, size_t cbOp);
|
---|
212 | /** @} */
|
---|
213 |
|
---|
214 | /** @name REM locking routines
|
---|
215 | * @{ */
|
---|
216 | VMMDECL(void) EMRemUnlock(PVM pVM);
|
---|
217 | VMMDECL(void) EMRemLock(PVM pVM);
|
---|
218 | VMMDECL(bool) EMRemIsLockOwner(PVM pVM);
|
---|
219 | VMMDECL(int) EMRemTryLock(PVM pVM);
|
---|
220 | /** @} */
|
---|
221 |
|
---|
222 | #ifdef IN_RING3
|
---|
223 | /** @defgroup grp_em_r3 The EM Host Context Ring-3 API
|
---|
224 | * @ingroup grp_em
|
---|
225 | * @{
|
---|
226 | */
|
---|
227 | VMMR3DECL(int) EMR3Init(PVM pVM);
|
---|
228 | VMMR3DECL(void) EMR3Relocate(PVM pVM);
|
---|
229 | VMMR3DECL(void) EMR3ResetCpu(PVMCPU pVCpu);
|
---|
230 | VMMR3DECL(void) EMR3Reset(PVM pVM);
|
---|
231 | VMMR3DECL(int) EMR3Term(PVM pVM);
|
---|
232 | VMMR3DECL(DECLNORETURN(void)) EMR3FatalError(PVMCPU pVCpu, int rc);
|
---|
233 | VMMR3DECL(int) EMR3ExecuteVM(PVM pVM, PVMCPU pVCpu);
|
---|
234 | VMMR3DECL(int) EMR3CheckRawForcedActions(PVM pVM, PVMCPU pVCpu);
|
---|
235 | VMMR3DECL(int) EMR3Interpret(PVM pVM);
|
---|
236 |
|
---|
237 | /**
|
---|
238 | * Command argument for EMR3RawSetMode().
|
---|
239 | *
|
---|
240 | * It's possible to extend this interface to change several
|
---|
241 | * execution modes at once should the need arise.
|
---|
242 | */
|
---|
243 | typedef enum EMEXECPOLICY
|
---|
244 | {
|
---|
245 | /** The customary invalid zero entry. */
|
---|
246 | EMEXECPOLICY_INVALID = 0,
|
---|
247 | /** Whether to recompile ring-0 code or execute it in raw/hm. */
|
---|
248 | EMEXECPOLICY_RECOMPILE_RING0,
|
---|
249 | /** Whether to recompile ring-3 code or execute it in raw/hm. */
|
---|
250 | EMEXECPOLICY_RECOMPILE_RING3,
|
---|
251 | /** End of valid value (not included). */
|
---|
252 | EMEXECPOLICY_END,
|
---|
253 | /** The customary 32-bit type blowup. */
|
---|
254 | EMEXECPOLICY_32BIT_HACK = 0x7fffffff
|
---|
255 | } EMEXECPOLICY;
|
---|
256 |
|
---|
257 | VMMR3DECL(int) EMR3SetExecutionPolicy(PVM pVM, EMEXECPOLICY enmPolicy, bool fEnforce);
|
---|
258 | /** @} */
|
---|
259 | #endif /* IN_RING3 */
|
---|
260 |
|
---|
261 |
|
---|
262 | #ifdef IN_RC
|
---|
263 | /** @defgroup grp_em_gc The EM Guest Context API
|
---|
264 | * @ingroup grp_em
|
---|
265 | * @{
|
---|
266 | */
|
---|
267 | VMMRCDECL(int) EMGCTrap(PVM pVM, unsigned uTrap, PCPUMCTXCORE pRegFrame);
|
---|
268 | /** @} */
|
---|
269 | #endif /* IN_RC */
|
---|
270 |
|
---|
271 | /** @} */
|
---|
272 |
|
---|
273 | RT_C_DECLS_END
|
---|
274 |
|
---|
275 | #endif
|
---|
276 |
|
---|