VirtualBox

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

Last change on this file since 8377 was 8225, checked in by vboxsync, 17 years ago

Added some assembly support routines (inactive; todo)

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