VirtualBox

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

Last change on this file since 2199 was 2159, checked in by vboxsync, 18 years ago

Added EMSTATE_DEBUG_GUEST_HWACC

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