VirtualBox

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

Last change on this file since 8113 was 8098, checked in by vboxsync, 17 years ago

Emulate cmpxchg8b in GC.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.2 KB
Line 
1/** @file
2 * EM - Execution Monitor.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
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_em_h
27#define ___VBox_em_h
28
29#include <VBox/cdefs.h>
30#include <VBox/types.h>
31#include <VBox/trpm.h>
32#include <VBox/dis.h>
33
34__BEGIN_DECLS
35
36/** @defgroup grp_em The Execution Monitor API
37 * @{
38 */
39
40/** Enable to allow V86 code to run in raw mode. */
41#define VBOX_RAW_V86
42
43/**
44 * The Execution Manager State.
45 */
46typedef enum EMSTATE
47{
48 /** Not yet started. */
49 EMSTATE_NONE = 1,
50 /** Raw-mode execution. */
51 EMSTATE_RAW,
52 /** Hardware accelerated raw-mode execution. */
53 EMSTATE_HWACC,
54 /** Recompiled mode execution. */
55 EMSTATE_REM,
56 /** Execution is halted. (waiting for interrupt) */
57 EMSTATE_HALTED,
58 /** Execution is suspended. */
59 EMSTATE_SUSPENDED,
60 /** The VM is terminating. */
61 EMSTATE_TERMINATING,
62 /** Guest debug event from raw-mode is being processed. */
63 EMSTATE_DEBUG_GUEST_RAW,
64 /** Guest debug event from hardware accelerated mode is being processed. */
65 EMSTATE_DEBUG_GUEST_HWACC,
66 /** Guest debug event from recompiled-mode is being processed. */
67 EMSTATE_DEBUG_GUEST_REM,
68 /** Hypervisor debug event being processed. */
69 EMSTATE_DEBUG_HYPER,
70 /** The VM has encountered a fatal error. (And everyone is panicing....) */
71 EMSTATE_GURU_MEDITATION,
72 /** Just a hack to ensure that we get a 32-bit integer. */
73 EMSTATE_MAKE_32BIT_HACK = 0x7fffffff
74} EMSTATE;
75
76
77/**
78 * Get the current execution manager status.
79 *
80 * @returns Current status.
81 */
82EMDECL(EMSTATE) EMGetState(PVM pVM);
83
84/**
85 * Checks if raw ring-3 execute mode is enabled.
86 *
87 * @returns true if enabled.
88 * @returns false if disabled.
89 * @param pVM The VM to operate on.
90 */
91#define EMIsRawRing3Enabled(pVM) ((pVM)->fRawR3Enabled)
92
93/**
94 * Checks if raw ring-0 execute mode is enabled.
95 *
96 * @returns true if enabled.
97 * @returns false if disabled.
98 * @param pVM The VM to operate on.
99 */
100#define EMIsRawRing0Enabled(pVM) ((pVM)->fRawR0Enabled)
101
102/**
103 * Sets the PC for which interrupts should be inhibited.
104 *
105 * @param pVM The VM handle.
106 * @param PC The PC.
107 */
108EMDECL(void) EMSetInhibitInterruptsPC(PVM pVM, RTGCUINTPTR PC);
109
110/**
111 * Gets the PC for which interrupts should be inhibited.
112 *
113 * There are a few instructions which inhibits or delays interrupts
114 * for the instruction following them. These instructions are:
115 * - STI
116 * - MOV SS, r/m16
117 * - POP SS
118 *
119 * @returns The PC for which interrupts should be inhibited.
120 * @param pVM VM handle.
121 *
122 */
123EMDECL(RTGCUINTPTR) EMGetInhibitInterruptsPC(PVM pVM);
124
125/**
126 * Disassembles one instruction.
127 *
128 * @param pVM The VM handle.
129 * @param pCtxCore The context core (used for both the mode and instruction).
130 * @param pCpu Where to return the parsed instruction info.
131 * @param pcbInstr Where to return the instruction size. (optional)
132 */
133EMDECL(int) EMInterpretDisasOne(PVM pVM, PCCPUMCTXCORE pCtxCore, PDISCPUSTATE pCpu, unsigned *pcbInstr);
134
135/**
136 * Disassembles one instruction.
137 *
138 * This is used by internally by the interpreter and by trap/access handlers.
139 *
140 * @param pVM The VM handle.
141 * @param GCPtrInstr The flat address of the instruction.
142 * @param pCtxCore The context core (used to determin the cpu mode).
143 * @param pCpu Where to return the parsed instruction info.
144 * @param pcbInstr Where to return the instruction size. (optional)
145 */
146EMDECL(int) EMInterpretDisasOneEx(PVM pVM, RTGCUINTPTR GCPtrInstr, PCCPUMCTXCORE pCtxCore,
147 PDISCPUSTATE pCpu, unsigned *pcbInstr);
148
149/**
150 * Interprets the current instruction.
151 *
152 * @returns VBox status code.
153 * @retval VINF_* Scheduling instructions.
154 * @retval VERR_EM_INTERPRETER Something we can't cope with.
155 * @retval VERR_* Fatal errors.
156 *
157 * @param pVM The VM handle.
158 * @param pRegFrame The register frame.
159 * Updates the EIP if an instruction was executed successfully.
160 * @param pvFault The fault address (CR2).
161 * @param pcbSize Size of the write (if applicable).
162 *
163 * @remark Invalid opcode exceptions have a higher priority than GP (see Intel
164 * Architecture System Developers Manual, Vol 3, 5.5) so we don't need
165 * to worry about e.g. invalid modrm combinations (!)
166 */
167EMDECL(int) EMInterpretInstruction(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbSize);
168
169/**
170 * Interprets the current instruction using the supplied DISCPUSTATE structure.
171 *
172 * EIP is *NOT* updated!
173 *
174 * @returns VBox status code.
175 * @retval VINF_* Scheduling instructions. When these are returned, it
176 * starts to get a bit tricky to know whether code was
177 * executed or not... We'll address this when it becomes a problem.
178 * @retval VERR_EM_INTERPRETER Something we can't cope with.
179 * @retval VERR_* Fatal errors.
180 *
181 * @param pVM The VM handle.
182 * @param pCpu The disassembler cpu state for the instruction to be interpreted.
183 * @param pRegFrame The register frame. EIP is *NOT* changed!
184 * @param pvFault The fault address (CR2).
185 * @param pcbSize Size of the write (if applicable).
186 *
187 * @remark Invalid opcode exceptions have a higher priority than GP (see Intel
188 * Architecture System Developers Manual, Vol 3, 5.5) so we don't need
189 * to worry about e.g. invalid modrm combinations (!)
190 */
191EMDECL(int) EMInterpretInstructionCPU(PVM pVM, PDISCPUSTATE pCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbSize);
192
193/**
194 * Interpret CPUID given the parameters in the CPU context
195 *
196 * @returns VBox status code.
197 * @param pVM The VM handle.
198 * @param pRegFrame The register frame.
199 *
200 */
201EMDECL(int) EMInterpretCpuId(PVM pVM, PCPUMCTXCORE pRegFrame);
202
203/**
204 * Interpret RDTSC
205 *
206 * @returns VBox status code.
207 * @param pVM The VM handle.
208 * @param pRegFrame The register frame.
209 *
210 */
211EMDECL(int) EMInterpretRdtsc(PVM pVM, PCPUMCTXCORE pRegFrame);
212
213/**
214 * Interpret INVLPG
215 *
216 * @returns VBox status code.
217 * @param pVM The VM handle.
218 * @param pRegFrame The register frame.
219 * @param pAddrGC Operand address
220 *
221 */
222EMDECL(int) EMInterpretInvlpg(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPTR pAddrGC);
223
224/**
225 * Interpret IRET (currently only to V86 code)
226 *
227 * @returns VBox status code.
228 * @param pVM The VM handle.
229 * @param pRegFrame The register frame.
230 *
231 */
232EMDECL(int) EMInterpretIret(PVM pVM, PCPUMCTXCORE pRegFrame);
233
234/**
235 * Interpret DRx write
236 *
237 * @returns VBox status code.
238 * @param pVM The VM handle.
239 * @param pRegFrame The register frame.
240 * @param DestRegDRx DRx register index (USE_REG_DR*)
241 * @param SrcRegGen General purpose register index (USE_REG_E**))
242 *
243 */
244EMDECL(int) EMInterpretDRxWrite(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegDrx, uint32_t SrcRegGen);
245
246/**
247 * Interpret DRx read
248 *
249 * @returns VBox status code.
250 * @param pVM The VM handle.
251 * @param pRegFrame The register frame.
252 * @param DestRegGen General purpose register index (USE_REG_E**))
253 * @param SrcRegDRx DRx register index (USE_REG_DR*)
254 *
255 */
256EMDECL(int) EMInterpretDRxRead(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegDrx);
257
258/**
259 * Interpret CRx write
260 *
261 * @returns VBox status code.
262 * @param pVM The VM handle.
263 * @param pRegFrame The register frame.
264 * @param DestRegCRx DRx register index (USE_REG_CR*)
265 * @param SrcRegGen General purpose register index (USE_REG_E**))
266 *
267 */
268EMDECL(int) EMInterpretCRxWrite(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegCrx, uint32_t SrcRegGen);
269
270/**
271 * Interpret CRx read
272 *
273 * @returns VBox status code.
274 * @param pVM The VM handle.
275 * @param pRegFrame The register frame.
276 * @param DestRegGen General purpose register index (USE_REG_E**))
277 * @param SrcRegCRx CRx register index (USE_REG_CR*)
278 *
279 */
280EMDECL(int) EMInterpretCRxRead(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegCrx);
281
282/**
283 * Interpret LMSW
284 *
285 * @returns VBox status code.
286 * @param pVM The VM handle.
287 * @param u16Data LMSW source data.
288 */
289EMDECL(int) EMInterpretLMSW(PVM pVM, uint16_t u16Data);
290
291/**
292 * Interpret CLTS
293 *
294 * @returns VBox status code.
295 * @param pVM The VM handle.
296 *
297 */
298EMDECL(int) EMInterpretCLTS(PVM pVM);
299
300/**
301 * Interpret a port I/O instruction.
302 *
303 * @returns VBox status code suitable for scheduling.
304 * @param pVM The VM handle.
305 * @param pCtxCore The context core. This will be updated on successful return.
306 * @param pCpu The instruction to interpret.
307 * @param cbOp The size of the instruction.
308 * @remark This may raise exceptions.
309 */
310EMDECL(int) EMInterpretPortIO(PVM pVM, PCPUMCTXCORE pCtxCore, PDISCPUSTATE pCpu, uint32_t cbOp);
311
312EMDECL(uint32_t) EMEmulateCmp(uint32_t u32Param1, uint32_t u32Param2, size_t cb);
313EMDECL(uint32_t) EMEmulateAnd(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
314EMDECL(uint32_t) EMEmulateInc(uint32_t *pu32Param1, size_t cb);
315EMDECL(uint32_t) EMEmulateDec(uint32_t *pu32Param1, size_t cb);
316EMDECL(uint32_t) EMEmulateOr(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
317EMDECL(int) EMEmulateLockOr(RTGCPTR GCPtrParam1, RTGCUINTREG Param2, size_t cbSize, uint32_t *pf);
318EMDECL(uint32_t) EMEmulateXor(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
319EMDECL(uint32_t) EMEmulateAdd(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
320EMDECL(uint32_t) EMEmulateSub(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
321EMDECL(uint32_t) EMEmulateAdcWithCarrySet(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
322EMDECL(uint32_t) EMEmulateBtr(uint32_t *pu32Param1, uint32_t u32Param2);
323EMDECL(int) EMEmulateLockBtr(RTGCPTR GCPtrParam1, RTGCUINTREG Param2, uint32_t *pf);
324EMDECL(uint32_t) EMEmulateBts(uint32_t *pu32Param1, uint32_t u32Param2);
325EMDECL(uint32_t) EMEmulateBtc(uint32_t *pu32Param1, uint32_t u32Param2);
326
327#ifdef IN_RING3
328/** @defgroup grp_em_r3 The EM Host Context Ring-3 API
329 * @ingroup grp_em
330 * @{
331 */
332
333/**
334 * Initializes the EM.
335 *
336 * @returns VBox status code.
337 * @param pVM The VM to operate on.
338 */
339EMR3DECL(int) EMR3Init(PVM pVM);
340
341/**
342 * Applies relocations to data and code managed by this
343 * component. This function will be called at init and
344 * whenever the VMM need to relocate it self inside the GC.
345 *
346 * @param pVM The VM.
347 */
348EMR3DECL(void) EMR3Relocate(PVM pVM);
349
350/**
351 * Reset notification.
352 *
353 * @param pVM
354 */
355EMR3DECL(void) EMR3Reset(PVM pVM);
356
357/**
358 * Terminates the EM.
359 *
360 * Termination means cleaning up and freeing all resources,
361 * the VM it self is at this point powered off or suspended.
362 *
363 * @returns VBox status code.
364 * @param pVM The VM to operate on.
365 */
366EMR3DECL(int) EMR3Term(PVM pVM);
367
368
369/**
370 * Command argument for EMR3RawSetMode().
371 *
372 * It's possible to extend this interface to change several
373 * execution modes at once should the need arise.
374 */
375typedef enum EMRAWMODE
376{
377 /** No raw execution. */
378 EMRAW_NONE = 0,
379 /** Enable Only ring-3 raw execution. */
380 EMRAW_RING3_ENABLE,
381 /** Only ring-3 raw execution. */
382 EMRAW_RING3_DISABLE,
383 /** Enable raw ring-0 execution. */
384 EMRAW_RING0_ENABLE,
385 /** Disable raw ring-0 execution. */
386 EMRAW_RING0_DISABLE,
387 EMRAW_END
388} EMRAWMODE;
389
390/**
391 * Enables or disables a set of raw-mode execution modes.
392 *
393 * @returns VINF_SUCCESS on success.
394 * @returns VINF_RESCHEDULE if a rescheduling might be required.
395 * @returns VERR_INVALID_PARAMETER on an invalid enmMode value.
396 *
397 * @param pVM The VM to operate on.
398 * @param enmMode The execution mode change.
399 * @thread The emulation thread.
400 */
401EMR3DECL(int) EMR3RawSetMode(PVM pVM, EMRAWMODE enmMode);
402
403/**
404 * Raise a fatal error.
405 *
406 * Safely terminate the VM with full state report and stuff. This function
407 * will naturally never return.
408 *
409 * @param pVM VM handle.
410 * @param rc VBox status code.
411 */
412EMR3DECL(DECLNORETURN(void)) EMR3FatalError(PVM pVM, int rc);
413
414/**
415 * Execute VM
416 *
417 * This function is the main loop of the VM. The emulation thread
418 * calls this function when the VM has been successfully constructed
419 * and we're ready for executing the VM.
420 *
421 * Returning from this function means that the VM is turned off or
422 * suspended (state already saved) and deconstruction in next in line.
423 *
424 * @returns VBox status code.
425 * @param pVM The VM to operate on.
426 */
427EMR3DECL(int) EMR3ExecuteVM(PVM pVM);
428
429/**
430 * Check for pending raw actions
431 *
432 * @returns VBox status code.
433 * @param pVM The VM to operate on.
434 */
435EMR3DECL(int) EMR3CheckRawForcedActions(PVM pVM);
436
437/**
438 * Interpret instructions.
439 * This works directly on the Guest CPUM context.
440 * The interpretation will try execute at least one instruction. It will
441 * stop when a we're better off in a raw or recompiler mode.
442 *
443 * @returns Todo - status describing what to do next?
444 * @param pVM The VM to operate on.
445 */
446EMR3DECL(int) EMR3Interpret(PVM pVM);
447
448/** @} */
449#endif
450
451
452#ifdef IN_GC
453/** @defgroup grp_em_gc The EM Guest Context API
454 * @ingroup grp_em
455 * @{
456 */
457
458/**
459 * Decide what to do with a trap.
460 *
461 * @returns Next VMM state.
462 * @returns Might not return at all?
463 * @param pVM The VM to operate on.
464 * @param uTrap The trap number.
465 * @param pRegFrame Register frame to operate on.
466 */
467EMGCDECL(int) EMGCTrap(PVM pVM, unsigned uTrap, PCPUMCTXCORE pRegFrame);
468
469EMGCDECL(uint32_t) EMGCEmulateLockCmpXchg(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
470EMGCDECL(uint32_t) EMGCEmulateCmpXchg(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
471EMGCDECL(uint32_t) EMGCEmulateLockCmpXchg8b(RTGCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX, uint32_t *pEflags);
472EMGCDECL(uint32_t) EMGCEmulateCmpXchg8b(RTGCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX, uint32_t *pEflags);
473EMGCDECL(uint32_t) EMGCEmulateLockXAdd(RTGCPTR pu32Param1, uint32_t *pu32Param2, size_t cbSize, uint32_t *pEflags);
474EMGCDECL(uint32_t) EMGCEmulateXAdd(RTGCPTR pu32Param1, uint32_t *pu32Param2, size_t cbSize, uint32_t *pEflags);
475
476/** @} */
477#endif
478
479/** @} */
480
481__END_DECLS
482
483#endif
484
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