VirtualBox

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

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

The Giant CDDL Dual-License Header Change.

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