~ubuntu-branches/ubuntu/trusty/virtualbox-lts-xenial/trusty-proposed

« back to all changes in this revision

Viewing changes to include/VBox/vmm/em.h

  • Committer: Package Import Robot
  • Author(s): Gianfranco Costamagna
  • Date: 2016-02-23 14:28:26 UTC
  • Revision ID: package-import@ubuntu.com-20160223142826-bdu69el2z6wa2a44
Tags: upstream-4.3.36-dfsg
ImportĀ upstreamĀ versionĀ 4.3.36-dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 * EM - Execution Monitor.
 
3
 */
 
4
 
 
5
/*
 
6
 * Copyright (C) 2006-2013 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_HM,
 
55
    /** Executing in IEM. */
 
56
    EMSTATE_IEM,
 
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_HM,
 
71
    /** Guest debug event from interpreted execution mode is being processed. */
 
72
    EMSTATE_DEBUG_GUEST_IEM,
 
73
    /** Guest debug event from recompiled-mode is being processed. */
 
74
    EMSTATE_DEBUG_GUEST_REM,
 
75
    /** Hypervisor debug event being processed. */
 
76
    EMSTATE_DEBUG_HYPER,
 
77
    /** The VM has encountered a fatal error. (And everyone is panicing....) */
 
78
    EMSTATE_GURU_MEDITATION,
 
79
    /** Executing in IEM, falling back on REM if we cannot switch back to HM or
 
80
     * RAW after a short while. */
 
81
    EMSTATE_IEM_THEN_REM,
 
82
    /** Just a hack to ensure that we get a 32-bit integer. */
 
83
    EMSTATE_MAKE_32BIT_HACK = 0x7fffffff
 
84
} EMSTATE;
 
85
 
 
86
 
 
87
/**
 
88
 * EMInterpretInstructionCPU execution modes.
 
89
 */
 
90
typedef enum
 
91
{
 
92
    /** Only supervisor code (CPL=0). */
 
93
    EMCODETYPE_SUPERVISOR,
 
94
    /** User-level code only. */
 
95
    EMCODETYPE_USER,
 
96
    /** Supervisor and user-level code (use with great care!). */
 
97
    EMCODETYPE_ALL,
 
98
    /** Just a hack to ensure that we get a 32-bit integer. */
 
99
    EMCODETYPE_32BIT_HACK = 0x7fffffff
 
100
} EMCODETYPE;
 
101
 
 
102
VMM_INT_DECL(EMSTATE)           EMGetState(PVMCPU pVCpu);
 
103
VMM_INT_DECL(void)              EMSetState(PVMCPU pVCpu, EMSTATE enmNewState);
 
104
 
 
105
/** @name Callback handlers for instruction emulation functions.
 
106
 * These are placed here because IOM wants to use them as well.
 
107
 * @{
 
108
 */
 
109
typedef DECLCALLBACK(uint32_t)  FNEMULATEPARAM2UINT32(void *pvParam1, uint64_t val2);
 
110
typedef FNEMULATEPARAM2UINT32  *PFNEMULATEPARAM2UINT32;
 
111
typedef DECLCALLBACK(uint32_t)  FNEMULATEPARAM2(void *pvParam1, size_t val2);
 
112
typedef FNEMULATEPARAM2        *PFNEMULATEPARAM2;
 
113
typedef DECLCALLBACK(uint32_t)  FNEMULATEPARAM3(void *pvParam1, uint64_t val2, size_t val3);
 
114
typedef FNEMULATEPARAM3        *PFNEMULATEPARAM3;
 
115
typedef DECLCALLBACK(int)       FNEMULATELOCKPARAM2(void *pvParam1, uint64_t val2, RTGCUINTREG32 *pf);
 
116
typedef FNEMULATELOCKPARAM2    *PFNEMULATELOCKPARAM2;
 
117
typedef DECLCALLBACK(int)       FNEMULATELOCKPARAM3(void *pvParam1, uint64_t val2, size_t cb, RTGCUINTREG32 *pf);
 
118
typedef FNEMULATELOCKPARAM3    *PFNEMULATELOCKPARAM3;
 
119
/** @}  */
 
120
 
 
121
 
 
122
/**
 
123
 * Checks if raw ring-3 execute mode is enabled.
 
124
 *
 
125
 * @returns true if enabled.
 
126
 * @returns false if disabled.
 
127
 * @param   pVM         The VM to operate on.
 
128
 */
 
129
#define EMIsRawRing3Enabled(pVM)            (!(pVM)->fRecompileUser)
 
130
 
 
131
/**
 
132
 * Checks if raw ring-0 execute mode is enabled.
 
133
 *
 
134
 * @returns true if enabled.
 
135
 * @returns false if disabled.
 
136
 * @param   pVM         The VM to operate on.
 
137
 */
 
138
#define EMIsRawRing0Enabled(pVM)            (!(pVM)->fRecompileSupervisor)
 
139
 
 
140
#ifdef VBOX_WITH_RAW_RING1
 
141
/**
 
142
 * Checks if raw ring-1 execute mode is enabled.
 
143
 *
 
144
 * @returns true if enabled.
 
145
 * @returns false if disabled.
 
146
 * @param   pVM         The VM to operate on.
 
147
 */
 
148
# define EMIsRawRing1Enabled(pVM)           ((pVM)->fRawRing1Enabled)
 
149
#else
 
150
# define EMIsRawRing1Enabled(pVM)           false
 
151
#endif
 
152
 
 
153
/**
 
154
 * Checks if execution with hardware assisted virtualization is enabled.
 
155
 *
 
156
 * @returns true if enabled.
 
157
 * @returns false if disabled.
 
158
 * @param   pVM         The VM to operate on.
 
159
 */
 
160
#define EMIsHwVirtExecutionEnabled(pVM)     (!(pVM)->fRecompileSupervisor && !(pVM)->fRecompileUser)
 
161
 
 
162
/**
 
163
 * Checks if execution of supervisor code should be done in the
 
164
 * recompiler or not.
 
165
 *
 
166
 * @returns true if enabled.
 
167
 * @returns false if disabled.
 
168
 * @param   pVM         The VM to operate on.
 
169
 */
 
170
#define EMIsSupervisorCodeRecompiled(pVM) ((pVM)->fRecompileSupervisor)
 
171
 
 
172
VMMDECL(void)                   EMSetInhibitInterruptsPC(PVMCPU pVCpu, RTGCUINTPTR PC);
 
173
VMMDECL(RTGCUINTPTR)            EMGetInhibitInterruptsPC(PVMCPU pVCpu);
 
174
VMM_INT_DECL(int)               EMInterpretDisasCurrent(PVM pVM, PVMCPU pVCpu, PDISCPUSTATE pCpu, unsigned *pcbInstr);
 
175
VMM_INT_DECL(int)               EMInterpretDisasOneEx(PVM pVM, PVMCPU pVCpu, RTGCUINTPTR GCPtrInstr, PCCPUMCTXCORE pCtxCore,
 
176
                                                      PDISCPUSTATE pDISState, unsigned *pcbInstr);
 
177
VMM_INT_DECL(VBOXSTRICTRC)      EMInterpretInstruction(PVMCPU pVCpu, PCPUMCTXCORE pCoreCtx, RTGCPTR pvFault);
 
178
VMM_INT_DECL(VBOXSTRICTRC)      EMInterpretInstructionEx(PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbWritten);
 
179
VMM_INT_DECL(VBOXSTRICTRC)      EMInterpretInstructionDisasState(PVMCPU pVCpu, PDISCPUSTATE pDis, PCPUMCTXCORE pCoreCtx,
 
180
                                                                 RTGCPTR pvFault, EMCODETYPE enmCodeType);
 
181
 
 
182
#ifdef IN_RC
 
183
VMM_INT_DECL(int)               EMInterpretIretV86ForPatm(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
 
184
#endif
 
185
 
 
186
VMM_INT_DECL(int)               EMInterpretCpuId(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
 
187
VMM_INT_DECL(int)               EMInterpretRdtsc(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
 
188
VMM_INT_DECL(int)               EMInterpretRdpmc(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
 
189
VMM_INT_DECL(int)               EMInterpretRdtscp(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
 
190
VMM_INT_DECL(VBOXSTRICTRC)      EMInterpretInvlpg(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pAddrGC);
 
191
VMM_INT_DECL(VBOXSTRICTRC)      EMInterpretMWait(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
 
192
VMM_INT_DECL(int)               EMInterpretMonitor(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
 
193
VMM_INT_DECL(int)               EMInterpretDRxWrite(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint32_t DestRegDrx, uint32_t SrcRegGen);
 
194
VMM_INT_DECL(int)               EMInterpretDRxRead(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegDrx);
 
195
VMM_INT_DECL(int)               EMInterpretCRxWrite(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint32_t DestRegCrx, uint32_t SrcRegGen);
 
196
VMM_INT_DECL(int)               EMInterpretCRxRead(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegCrx);
 
197
VMM_INT_DECL(int)               EMInterpretLMSW(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint16_t u16Data);
 
198
VMM_INT_DECL(int)               EMInterpretCLTS(PVM pVM, PVMCPU pVCpu);
 
199
VMM_INT_DECL(int)               EMInterpretRdmsr(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
 
200
VMM_INT_DECL(int)               EMInterpretWrmsr(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
 
201
VMM_INT_DECL(bool)              EMShouldContinueAfterHalt(PVMCPU pVCpu, PCPUMCTX pCtx);
 
202
VMM_INT_DECL(bool)              EMMonitorWaitShouldContinue(PVMCPU pVCpu, PCPUMCTX pCtx);
 
203
VMM_INT_DECL(int)               EMMonitorWaitPrepare(PVMCPU pVCpu, uint64_t rax, uint64_t rcx, uint64_t rdx, RTGCPHYS GCPhys);
 
204
VMM_INT_DECL(int)               EMMonitorWaitPerform(PVMCPU pVCpu, uint64_t rax, uint64_t rcx);
 
205
 
 
206
/** @name Assembly routines
 
207
 * @{ */
 
208
VMMDECL(uint32_t)   EMEmulateCmp(uint32_t u32Param1, uint64_t u64Param2, size_t cb);
 
209
VMMDECL(uint32_t)   EMEmulateAnd(void *pvParam1, uint64_t u64Param2, size_t cb);
 
210
VMMDECL(uint32_t)   EMEmulateInc(void *pvParam1, size_t cb);
 
211
VMMDECL(uint32_t)   EMEmulateDec(void *pvParam1, size_t cb);
 
212
VMMDECL(uint32_t)   EMEmulateOr(void *pvParam1, uint64_t u64Param2, size_t cb);
 
213
VMMDECL(int)        EMEmulateLockOr(void *pvParam1, uint64_t u64Param2, size_t cbSize, RTGCUINTREG32 *pf);
 
214
VMMDECL(uint32_t)   EMEmulateXor(void *pvParam1, uint64_t u64Param2, size_t cb);
 
215
VMMDECL(int)        EMEmulateLockXor(void *pvParam1, uint64_t u64Param2, size_t cbSize, RTGCUINTREG32 *pf);
 
216
VMMDECL(uint32_t)   EMEmulateAdd(void *pvParam1, uint64_t u64Param2, size_t cb);
 
217
VMMDECL(int)        EMEmulateLockAnd(void *pvParam1, uint64_t u64Param2, size_t cbSize, RTGCUINTREG32 *pf);
 
218
VMMDECL(uint32_t)   EMEmulateSub(void *pvParam1, uint64_t u64Param2, size_t cb);
 
219
VMMDECL(uint32_t)   EMEmulateAdcWithCarrySet(void *pvParam1, uint64_t u64Param2, size_t cb);
 
220
VMMDECL(uint32_t)   EMEmulateBtr(void *pvParam1, uint64_t u64Param2);
 
221
VMMDECL(int)        EMEmulateLockBtr(void *pvParam1, uint64_t u64Param2, RTGCUINTREG32 *pf);
 
222
VMMDECL(uint32_t)   EMEmulateBts(void *pvParam1, uint64_t u64Param2);
 
223
VMMDECL(uint32_t)   EMEmulateBtc(void *pvParam1, uint64_t u64Param2);
 
224
VMMDECL(uint32_t)   EMEmulateCmpXchg(void *pvParam1, uint64_t *pu32Param2, uint64_t u32Param3, size_t cbSize);
 
225
VMMDECL(uint32_t)   EMEmulateLockCmpXchg(void *pvParam1, uint64_t *pu64Param2, uint64_t u64Param3, size_t cbSize);
 
226
VMMDECL(uint32_t)   EMEmulateCmpXchg8b(void *pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
 
227
VMMDECL(uint32_t)   EMEmulateLockCmpXchg8b(void *pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
 
228
VMMDECL(uint32_t)   EMEmulateXAdd(void *pvParam1, void *pvParam2, size_t cbOp);
 
229
VMMDECL(uint32_t)   EMEmulateLockXAdd(void *pvParam1, void *pvParam2, size_t cbOp);
 
230
/** @} */
 
231
 
 
232
/** @name REM locking routines
 
233
 * @{ */
 
234
VMMDECL(void)                   EMRemUnlock(PVM pVM);
 
235
VMMDECL(void)                   EMRemLock(PVM pVM);
 
236
VMMDECL(bool)                   EMRemIsLockOwner(PVM pVM);
 
237
VMM_INT_DECL(int)               EMRemTryLock(PVM pVM);
 
238
/** @} */
 
239
 
 
240
 
 
241
/** @name EM_ONE_INS_FLAGS_XXX - flags for EMR3HmSingleInstruction (et al).
 
242
 * @{ */
 
243
/** Return when CS:RIP changes or some other important event happens.
 
244
 * This means running whole REP and LOOP $ sequences for instance. */
 
245
#define EM_ONE_INS_FLAGS_RIP_CHANGE     RT_BIT_32(0)
 
246
/** Mask of valid flags. */
 
247
#define EM_ONE_INS_FLAGS_MASK           UINT32_C(0x00000001)
 
248
/** @} */
 
249
 
 
250
 
 
251
#ifdef IN_RING3
 
252
/** @defgroup grp_em_r3     The EM Host Context Ring-3 API
 
253
 * @ingroup grp_em
 
254
 * @{
 
255
 */
 
256
 
 
257
/**
 
258
 * Command argument for EMR3RawSetMode().
 
259
 *
 
260
 * It's possible to extend this interface to change several
 
261
 * execution modes at once should the need arise.
 
262
 */
 
263
typedef enum EMEXECPOLICY
 
264
{
 
265
    /** The customary invalid zero entry. */
 
266
    EMEXECPOLICY_INVALID = 0,
 
267
    /** Whether to recompile ring-0 code or execute it in raw/hm. */
 
268
    EMEXECPOLICY_RECOMPILE_RING0,
 
269
    /** Whether to recompile ring-3 code or execute it in raw/hm. */
 
270
    EMEXECPOLICY_RECOMPILE_RING3,
 
271
    /** Whether to only use IEM for execution. */
 
272
    EMEXECPOLICY_IEM_ALL,
 
273
    /** End of valid value (not included). */
 
274
    EMEXECPOLICY_END,
 
275
    /** The customary 32-bit type blowup. */
 
276
    EMEXECPOLICY_32BIT_HACK = 0x7fffffff
 
277
} EMEXECPOLICY;
 
278
VMMR3DECL(int)                  EMR3SetExecutionPolicy(PUVM pUVM, EMEXECPOLICY enmPolicy, bool fEnforce);
 
279
VMMR3DECL(int)                  EMR3QueryExecutionPolicy(PUVM pUVM, EMEXECPOLICY enmPolicy, bool *pfEnforced);
 
280
 
 
281
VMMR3_INT_DECL(int)             EMR3Init(PVM pVM);
 
282
VMMR3_INT_DECL(void)            EMR3Relocate(PVM pVM);
 
283
VMMR3_INT_DECL(void)            EMR3ResetCpu(PVMCPU pVCpu);
 
284
VMMR3_INT_DECL(void)            EMR3Reset(PVM pVM);
 
285
VMMR3_INT_DECL(int)             EMR3Term(PVM pVM);
 
286
VMMR3DECL(DECLNORETURN(void))   EMR3FatalError(PVMCPU pVCpu, int rc);
 
287
VMMR3_INT_DECL(int)             EMR3ExecuteVM(PVM pVM, PVMCPU pVCpu);
 
288
VMMR3_INT_DECL(int)             EMR3CheckRawForcedActions(PVM pVM, PVMCPU pVCpu);
 
289
VMMR3_INT_DECL(int)             EMR3NotifyResume(PVM pVM);
 
290
VMMR3_INT_DECL(int)             EMR3NotifySuspend(PVM pVM);
 
291
VMMR3_INT_DECL(VBOXSTRICTRC)    EMR3HmSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
 
292
 
 
293
/** @} */
 
294
#endif /* IN_RING3 */
 
295
 
 
296
/** @} */
 
297
 
 
298
RT_C_DECLS_END
 
299
 
 
300
#endif
 
301