VirtualBox

source: vbox/trunk/include/VBox/em.h@ 18050

Last change on this file since 18050 was 14411, checked in by vboxsync, 16 years ago

RDTSCP support added. Enabled only for AMD-V guests.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/** @file
2 * EM - Execution Monitor.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_em_h
31#define ___VBox_em_h
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35#include <VBox/trpm.h>
36#include <VBox/dis.h>
37
38__BEGIN_DECLS
39
40/** @defgroup grp_em The Execution Monitor / Manager API
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 */
50typedef enum EMSTATE
51{
52 /** Not yet started. */
53 EMSTATE_NONE = 1,
54 /** Raw-mode execution. */
55 EMSTATE_RAW,
56 /** Hardware accelerated raw-mode execution. */
57 EMSTATE_HWACC,
58 /** PARAV function. */
59 EMSTATE_PARAV,
60 /** Recompiled mode execution. */
61 EMSTATE_REM,
62 /** Execution is halted. (waiting for interrupt) */
63 EMSTATE_HALTED,
64 /** Execution is suspended. */
65 EMSTATE_SUSPENDED,
66 /** The VM is terminating. */
67 EMSTATE_TERMINATING,
68 /** Guest debug event from raw-mode is being processed. */
69 EMSTATE_DEBUG_GUEST_RAW,
70 /** Guest debug event from hardware accelerated mode is being processed. */
71 EMSTATE_DEBUG_GUEST_HWACC,
72 /** Guest debug event from recompiled-mode is being processed. */
73 EMSTATE_DEBUG_GUEST_REM,
74 /** Hypervisor debug event being processed. */
75 EMSTATE_DEBUG_HYPER,
76 /** The VM has encountered a fatal error. (And everyone is panicing....) */
77 EMSTATE_GURU_MEDITATION,
78 /** Just a hack to ensure that we get a 32-bit integer. */
79 EMSTATE_MAKE_32BIT_HACK = 0x7fffffff
80} EMSTATE;
81
82VMMDECL(EMSTATE) EMGetState(PVM pVM);
83
84/** @name Callback handlers for instruction emulation functions.
85 * These are placed here because IOM wants to use them as well.
86 * @{
87 */
88typedef DECLCALLBACK(uint32_t) FNEMULATEPARAM2UINT32(void *pvParam1, uint64_t val2);
89typedef FNEMULATEPARAM2UINT32 *PFNEMULATEPARAM2UINT32;
90typedef DECLCALLBACK(uint32_t) FNEMULATEPARAM2(void *pvParam1, size_t val2);
91typedef FNEMULATEPARAM2 *PFNEMULATEPARAM2;
92typedef DECLCALLBACK(uint32_t) FNEMULATEPARAM3(void *pvParam1, uint64_t val2, size_t val3);
93typedef FNEMULATEPARAM3 *PFNEMULATEPARAM3;
94typedef DECLCALLBACK(int) FNEMULATELOCKPARAM2(void *pvParam1, uint64_t val2, RTGCUINTREG32 *pf);
95typedef FNEMULATELOCKPARAM2 *PFNEMULATELOCKPARAM2;
96typedef DECLCALLBACK(int) FNEMULATELOCKPARAM3(void *pvParam1, uint64_t val2, size_t cb, RTGCUINTREG32 *pf);
97typedef FNEMULATELOCKPARAM3 *PFNEMULATELOCKPARAM3;
98/** @} */
99
100
101/**
102 * Checks if raw ring-3 execute mode is enabled.
103 *
104 * @returns true if enabled.
105 * @returns false if disabled.
106 * @param pVM The VM to operate on.
107 */
108#define EMIsRawRing3Enabled(pVM) ((pVM)->fRawR3Enabled)
109
110/**
111 * Checks if raw ring-0 execute mode is enabled.
112 *
113 * @returns true if enabled.
114 * @returns false if disabled.
115 * @param pVM The VM to operate on.
116 */
117#define EMIsRawRing0Enabled(pVM) ((pVM)->fRawR0Enabled)
118
119VMMDECL(void) EMSetInhibitInterruptsPC(PVM pVM, RTGCUINTPTR PC);
120VMMDECL(RTGCUINTPTR) EMGetInhibitInterruptsPC(PVM pVM);
121VMMDECL(int) EMInterpretDisasOne(PVM pVM, PCCPUMCTXCORE pCtxCore, PDISCPUSTATE pCpu, unsigned *pcbInstr);
122VMMDECL(int) EMInterpretDisasOneEx(PVM pVM, RTGCUINTPTR GCPtrInstr, PCCPUMCTXCORE pCtxCore,
123 PDISCPUSTATE pCpu, unsigned *pcbInstr);
124VMMDECL(int) EMInterpretInstruction(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbSize);
125VMMDECL(int) EMInterpretInstructionCPU(PVM pVM, PDISCPUSTATE pCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbSize);
126VMMDECL(int) EMInterpretCpuId(PVM pVM, PCPUMCTXCORE pRegFrame);
127VMMDECL(int) EMInterpretRdtsc(PVM pVM, PCPUMCTXCORE pRegFrame);
128VMMDECL(int) EMInterpretRdtscp(PVM pVM, PCPUMCTX pCtx);
129VMMDECL(int) EMInterpretInvlpg(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPTR pAddrGC);
130VMMDECL(int) EMInterpretIret(PVM pVM, PCPUMCTXCORE pRegFrame);
131VMMDECL(int) EMInterpretDRxWrite(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegDrx, uint32_t SrcRegGen);
132VMMDECL(int) EMInterpretDRxRead(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegDrx);
133VMMDECL(int) EMInterpretCRxWrite(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegCrx, uint32_t SrcRegGen);
134VMMDECL(int) EMInterpretCRxRead(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegCrx);
135VMMDECL(int) EMInterpretLMSW(PVM pVM, PCPUMCTXCORE pRegFrame, uint16_t u16Data);
136VMMDECL(int) EMInterpretCLTS(PVM pVM);
137VMMDECL(int) EMInterpretPortIO(PVM pVM, PCPUMCTXCORE pCtxCore, PDISCPUSTATE pCpu, uint32_t cbOp);
138VMMDECL(int) EMInterpretRdmsr(PVM pVM, PCPUMCTXCORE pRegFrame);
139VMMDECL(int) EMInterpretWrmsr(PVM pVM, PCPUMCTXCORE pRegFrame);
140
141/** @name Assembly routines
142 * @{ */
143VMMDECL(uint32_t) EMEmulateCmp(uint32_t u32Param1, uint64_t u64Param2, size_t cb);
144VMMDECL(uint32_t) EMEmulateAnd(void *pvParam1, uint64_t u64Param2, size_t cb);
145VMMDECL(uint32_t) EMEmulateInc(void *pvParam1, size_t cb);
146VMMDECL(uint32_t) EMEmulateDec(void *pvParam1, size_t cb);
147VMMDECL(uint32_t) EMEmulateOr(void *pvParam1, uint64_t u64Param2, size_t cb);
148VMMDECL(int) EMEmulateLockOr(void *pvParam1, uint64_t u64Param2, size_t cbSize, RTGCUINTREG32 *pf);
149VMMDECL(uint32_t) EMEmulateXor(void *pvParam1, uint64_t u64Param2, size_t cb);
150VMMDECL(uint32_t) EMEmulateAdd(void *pvParam1, uint64_t u64Param2, size_t cb);
151VMMDECL(uint32_t) EMEmulateSub(void *pvParam1, uint64_t u64Param2, size_t cb);
152VMMDECL(uint32_t) EMEmulateAdcWithCarrySet(void *pvParam1, uint64_t u64Param2, size_t cb);
153VMMDECL(uint32_t) EMEmulateBtr(void *pvParam1, uint64_t u64Param2);
154VMMDECL(int) EMEmulateLockBtr(void *pvParam1, uint64_t u64Param2, RTGCUINTREG32 *pf);
155VMMDECL(uint32_t) EMEmulateBts(void *pvParam1, uint64_t u64Param2);
156VMMDECL(uint32_t) EMEmulateBtc(void *pvParam1, uint64_t u64Param2);
157VMMDECL(uint32_t) EMEmulateCmpXchg(void *pvParam1, uint64_t *pu32Param2, uint64_t u32Param3, size_t cbSize);
158VMMDECL(uint32_t) EMEmulateLockCmpXchg(void *pvParam1, uint64_t *pu64Param2, uint64_t u64Param3, size_t cbSize);
159VMMDECL(uint32_t) EMEmulateCmpXchg8b(void *pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
160VMMDECL(uint32_t) EMEmulateLockCmpXchg8b(void *pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
161/** @} */
162
163#ifdef IN_RING3
164/** @defgroup grp_em_r3 The EM Host Context Ring-3 API
165 * @ingroup grp_em
166 * @{
167 */
168VMMR3DECL(int) EMR3Init(PVM pVM);
169VMMR3DECL(int) EMR3InitCPU(PVM pVM);
170VMMR3DECL(void) EMR3Relocate(PVM pVM);
171VMMR3DECL(void) EMR3Reset(PVM pVM);
172VMMR3DECL(int) EMR3Term(PVM pVM);
173VMMR3DECL(int) EMR3TermCPU(PVM pVM);
174VMMR3DECL(DECLNORETURN(void)) EMR3FatalError(PVM pVM, int rc);
175VMMR3DECL(int) EMR3ExecuteVM(PVM pVM, RTCPUID idCpu);
176VMMR3DECL(int) EMR3CheckRawForcedActions(PVM pVM);
177VMMR3DECL(int) EMR3Interpret(PVM pVM);
178
179/**
180 * Command argument for EMR3RawSetMode().
181 *
182 * It's possible to extend this interface to change several
183 * execution modes at once should the need arise.
184 */
185typedef enum EMRAWMODE
186{
187 /** No raw execution. */
188 EMRAW_NONE = 0,
189 /** Enable Only ring-3 raw execution. */
190 EMRAW_RING3_ENABLE,
191 /** Only ring-3 raw execution. */
192 EMRAW_RING3_DISABLE,
193 /** Enable raw ring-0 execution. */
194 EMRAW_RING0_ENABLE,
195 /** Disable raw ring-0 execution. */
196 EMRAW_RING0_DISABLE,
197 EMRAW_END
198} EMRAWMODE;
199
200VMMR3DECL(int) EMR3RawSetMode(PVM pVM, EMRAWMODE enmMode);
201/** @} */
202#endif /* IN_RING3 */
203
204
205#ifdef IN_RC
206/** @defgroup grp_em_gc The EM Guest Context API
207 * @ingroup grp_em
208 * @{
209 */
210VMMRCDECL(int) EMGCTrap(PVM pVM, unsigned uTrap, PCPUMCTXCORE pRegFrame);
211VMMRCDECL(uint32_t) EMGCEmulateLockCmpXchg(RTRCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
212VMMRCDECL(uint32_t) EMGCEmulateCmpXchg(RTRCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
213VMMRCDECL(uint32_t) EMGCEmulateLockCmpXchg8b(RTRCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX, uint32_t *pEflags);
214VMMRCDECL(uint32_t) EMGCEmulateCmpXchg8b(RTRCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX, uint32_t *pEflags);
215VMMRCDECL(uint32_t) EMGCEmulateLockXAdd(RTRCPTR pu32Param1, uint32_t *pu32Param2, size_t cbSize, uint32_t *pEflags);
216VMMRCDECL(uint32_t) EMGCEmulateXAdd(RTRCPTR pu32Param1, uint32_t *pu32Param2, size_t cbSize, uint32_t *pEflags);
217/** @} */
218#endif /* IN_RC */
219
220/** @} */
221
222__END_DECLS
223
224#endif
225
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