VirtualBox

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

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

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.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 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 RDTSC
202 *
203 * @returns VBox status code.
204 * @param pVM The VM handle.
205 * @param pRegFrame The register frame.
206 *
207 */
208EMDECL(int) EMInterpretRdtsc(PVM pVM, PCPUMCTXCORE pRegFrame);
209
210/**
211 * Interpret INVLPG
212 *
213 * @returns VBox status code.
214 * @param pVM The VM handle.
215 * @param pRegFrame The register frame.
216 * @param pAddrGC Operand address
217 *
218 */
219EMDECL(int) EMInterpretInvlpg(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPTR pAddrGC);
220
221/**
222 * Interpret IRET (currently only to V86 code)
223 *
224 * @returns VBox status code.
225 * @param pVM The VM handle.
226 * @param pRegFrame The register frame.
227 *
228 */
229EMDECL(int) EMInterpretIret(PVM pVM, PCPUMCTXCORE pRegFrame);
230
231/**
232 * Interpret DRx write
233 *
234 * @returns VBox status code.
235 * @param pVM The VM handle.
236 * @param pRegFrame The register frame.
237 * @param DestRegDRx DRx register index (USE_REG_DR*)
238 * @param SrcRegGen General purpose register index (USE_REG_E**))
239 *
240 */
241EMDECL(int) EMInterpretDRxWrite(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegDrx, uint32_t SrcRegGen);
242
243/**
244 * Interpret DRx read
245 *
246 * @returns VBox status code.
247 * @param pVM The VM handle.
248 * @param pRegFrame The register frame.
249 * @param DestRegGen General purpose register index (USE_REG_E**))
250 * @param SrcRegDRx DRx register index (USE_REG_DR*)
251 *
252 */
253EMDECL(int) EMInterpretDRxRead(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegDrx);
254
255/**
256 * Interpret CRx write
257 *
258 * @returns VBox status code.
259 * @param pVM The VM handle.
260 * @param pRegFrame The register frame.
261 * @param DestRegCRx DRx register index (USE_REG_CR*)
262 * @param SrcRegGen General purpose register index (USE_REG_E**))
263 *
264 */
265EMDECL(int) EMInterpretCRxWrite(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegCrx, uint32_t SrcRegGen);
266
267/**
268 * Interpret CRx read
269 *
270 * @returns VBox status code.
271 * @param pVM The VM handle.
272 * @param pRegFrame The register frame.
273 * @param DestRegGen General purpose register index (USE_REG_E**))
274 * @param SrcRegCRx CRx register index (USE_REG_CR*)
275 *
276 */
277EMDECL(int) EMInterpretCRxRead(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t DestRegGen, uint32_t SrcRegCrx);
278
279/**
280 * Interpret LMSW
281 *
282 * @returns VBox status code.
283 * @param pVM The VM handle.
284 * @param u16Data LMSW source data.
285 */
286EMDECL(int) EMInterpretLMSW(PVM pVM, uint16_t u16Data);
287
288/**
289 * Interpret CLTS
290 *
291 * @returns VBox status code.
292 * @param pVM The VM handle.
293 *
294 */
295EMDECL(int) EMInterpretCLTS(PVM pVM);
296
297/**
298 * Interpret a port I/O instruction.
299 *
300 * @returns VBox status code suitable for scheduling.
301 * @param pVM The VM handle.
302 * @param pCtxCore The context core. This will be updated on successful return.
303 * @param pCpu The instruction to interpret.
304 * @param cbOp The size of the instruction.
305 * @remark This may raise exceptions.
306 */
307EMDECL(int) EMInterpretPortIO(PVM pVM, PCPUMCTXCORE pCtxCore, PDISCPUSTATE pCpu, uint32_t cbOp);
308
309EMDECL(uint32_t) EMEmulateCmp(uint32_t u32Param1, uint32_t u32Param2, size_t cb);
310EMDECL(uint32_t) EMEmulateAnd(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
311EMDECL(uint32_t) EMEmulateInc(uint32_t *pu32Param1, size_t cb);
312EMDECL(uint32_t) EMEmulateDec(uint32_t *pu32Param1, size_t cb);
313EMDECL(uint32_t) EMEmulateOr(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
314EMDECL(uint32_t) EMEmulateXor(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
315EMDECL(uint32_t) EMEmulateAdd(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
316EMDECL(uint32_t) EMEmulateSub(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
317EMDECL(uint32_t) EMEmulateAdcWithCarrySet(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
318EMDECL(uint32_t) EMEmulateBtr(uint32_t *pu32Param1, uint32_t u32Param2);
319EMDECL(uint32_t) EMEmulateBts(uint32_t *pu32Param1, uint32_t u32Param2);
320EMDECL(uint32_t) EMEmulateBtc(uint32_t *pu32Param1, uint32_t u32Param2);
321
322#ifdef IN_RING3
323/** @defgroup grp_em_r3 The EM Host Context Ring-3 API
324 * @ingroup grp_em
325 * @{
326 */
327
328/**
329 * Initializes the EM.
330 *
331 * @returns VBox status code.
332 * @param pVM The VM to operate on.
333 */
334EMR3DECL(int) EMR3Init(PVM pVM);
335
336/**
337 * Applies relocations to data and code managed by this
338 * component. This function will be called at init and
339 * whenever the VMM need to relocate it self inside the GC.
340 *
341 * @param pVM The VM.
342 */
343EMR3DECL(void) EMR3Relocate(PVM pVM);
344
345/**
346 * Reset notification.
347 *
348 * @param pVM
349 */
350EMR3DECL(void) EMR3Reset(PVM pVM);
351
352/**
353 * Terminates the EM.
354 *
355 * Termination means cleaning up and freeing all resources,
356 * the VM it self is at this point powered off or suspended.
357 *
358 * @returns VBox status code.
359 * @param pVM The VM to operate on.
360 */
361EMR3DECL(int) EMR3Term(PVM pVM);
362
363
364/**
365 * Command argument for EMR3RawSetMode().
366 *
367 * It's possible to extend this interface to change several
368 * execution modes at once should the need arise.
369 */
370typedef enum EMRAWMODE
371{
372 /** No raw execution. */
373 EMRAW_NONE = 0,
374 /** Enable Only ring-3 raw execution. */
375 EMRAW_RING3_ENABLE,
376 /** Only ring-3 raw execution. */
377 EMRAW_RING3_DISABLE,
378 /** Enable raw ring-0 execution. */
379 EMRAW_RING0_ENABLE,
380 /** Disable raw ring-0 execution. */
381 EMRAW_RING0_DISABLE,
382 EMRAW_END
383} EMRAWMODE;
384
385/**
386 * Enables or disables a set of raw-mode execution modes.
387 *
388 * @returns VINF_SUCCESS on success.
389 * @returns VINF_RESCHEDULE if a rescheduling might be required.
390 * @returns VERR_INVALID_PARAMETER on an invalid enmMode value.
391 *
392 * @param pVM The VM to operate on.
393 * @param enmMode The execution mode change.
394 * @thread The emulation thread.
395 */
396EMR3DECL(int) EMR3RawSetMode(PVM pVM, EMRAWMODE enmMode);
397
398/**
399 * Raise a fatal error.
400 *
401 * Safely terminate the VM with full state report and stuff. This function
402 * will naturally never return.
403 *
404 * @param pVM VM handle.
405 * @param rc VBox status code.
406 */
407EMR3DECL(void) EMR3FatalError(PVM pVM, int rc);
408
409/**
410 * Execute VM
411 *
412 * This function is the main loop of the VM. The emulation thread
413 * calls this function when the VM has been successfully constructed
414 * and we're ready for executing the VM.
415 *
416 * Returning from this function means that the VM is turned off or
417 * suspended (state already saved) and deconstruction in next in line.
418 *
419 * @returns VBox status code.
420 * @param pVM The VM to operate on.
421 */
422EMR3DECL(int) EMR3ExecuteVM(PVM pVM);
423
424/**
425 * Check for pending raw actions
426 *
427 * @returns VBox status code.
428 * @param pVM The VM to operate on.
429 */
430EMR3DECL(int) EMR3CheckRawForcedActions(PVM pVM);
431
432/**
433 * Interpret instructions.
434 * This works directly on the Guest CPUM context.
435 * The interpretation will try execute at least one instruction. It will
436 * stop when a we're better off in a raw or recompiler mode.
437 *
438 * @returns Todo - status describing what to do next?
439 * @param pVM The VM to operate on.
440 */
441EMR3DECL(int) EMR3Interpret(PVM pVM);
442
443/** @} */
444#endif
445
446
447#ifdef IN_GC
448/** @defgroup grp_em_gc The EM Guest Context API
449 * @ingroup grp_em
450 * @{
451 */
452
453/**
454 * Decide what to do with a trap.
455 *
456 * @returns Next VMM state.
457 * @returns Might not return at all?
458 * @param pVM The VM to operate on.
459 * @param uTrap The trap number.
460 * @param pRegFrame Register frame to operate on.
461 */
462EMGCDECL(int) EMGCTrap(PVM pVM, unsigned uTrap, PCPUMCTXCORE pRegFrame);
463
464EMGCDECL(uint32_t) EMGCEmulateLockCmpXchg(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize);
465EMGCDECL(uint32_t) EMGCEmulateCmpXchg(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize);
466
467/** @} */
468#endif
469
470/** @} */
471
472__END_DECLS
473
474#endif
475
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