VirtualBox

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

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

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.4 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);
330
331#ifdef IN_RING3
332/** @defgroup grp_em_r3 The EM Host Context Ring-3 API
333 * @ingroup grp_em
334 * @{
335 */
336
337/**
338 * Initializes the EM.
339 *
340 * @returns VBox status code.
341 * @param pVM The VM to operate on.
342 */
343EMR3DECL(int) EMR3Init(PVM pVM);
344
345/**
346 * Applies relocations to data and code managed by this
347 * component. This function will be called at init and
348 * whenever the VMM need to relocate it self inside the GC.
349 *
350 * @param pVM The VM.
351 */
352EMR3DECL(void) EMR3Relocate(PVM pVM);
353
354/**
355 * Reset notification.
356 *
357 * @param pVM
358 */
359EMR3DECL(void) EMR3Reset(PVM pVM);
360
361/**
362 * Terminates the EM.
363 *
364 * Termination means cleaning up and freeing all resources,
365 * the VM it self is at this point powered off or suspended.
366 *
367 * @returns VBox status code.
368 * @param pVM The VM to operate on.
369 */
370EMR3DECL(int) EMR3Term(PVM pVM);
371
372
373/**
374 * Command argument for EMR3RawSetMode().
375 *
376 * It's possible to extend this interface to change several
377 * execution modes at once should the need arise.
378 */
379typedef enum EMRAWMODE
380{
381 /** No raw execution. */
382 EMRAW_NONE = 0,
383 /** Enable Only ring-3 raw execution. */
384 EMRAW_RING3_ENABLE,
385 /** Only ring-3 raw execution. */
386 EMRAW_RING3_DISABLE,
387 /** Enable raw ring-0 execution. */
388 EMRAW_RING0_ENABLE,
389 /** Disable raw ring-0 execution. */
390 EMRAW_RING0_DISABLE,
391 EMRAW_END
392} EMRAWMODE;
393
394/**
395 * Enables or disables a set of raw-mode execution modes.
396 *
397 * @returns VINF_SUCCESS on success.
398 * @returns VINF_RESCHEDULE if a rescheduling might be required.
399 * @returns VERR_INVALID_PARAMETER on an invalid enmMode value.
400 *
401 * @param pVM The VM to operate on.
402 * @param enmMode The execution mode change.
403 * @thread The emulation thread.
404 */
405EMR3DECL(int) EMR3RawSetMode(PVM pVM, EMRAWMODE enmMode);
406
407/**
408 * Raise a fatal error.
409 *
410 * Safely terminate the VM with full state report and stuff. This function
411 * will naturally never return.
412 *
413 * @param pVM VM handle.
414 * @param rc VBox status code.
415 */
416EMR3DECL(DECLNORETURN(void)) EMR3FatalError(PVM pVM, int rc);
417
418/**
419 * Execute VM
420 *
421 * This function is the main loop of the VM. The emulation thread
422 * calls this function when the VM has been successfully constructed
423 * and we're ready for executing the VM.
424 *
425 * Returning from this function means that the VM is turned off or
426 * suspended (state already saved) and deconstruction in next in line.
427 *
428 * @returns VBox status code.
429 * @param pVM The VM to operate on.
430 */
431EMR3DECL(int) EMR3ExecuteVM(PVM pVM);
432
433/**
434 * Check for pending raw actions
435 *
436 * @returns VBox status code.
437 * @param pVM The VM to operate on.
438 */
439EMR3DECL(int) EMR3CheckRawForcedActions(PVM pVM);
440
441/**
442 * Interpret instructions.
443 * This works directly on the Guest CPUM context.
444 * The interpretation will try execute at least one instruction. It will
445 * stop when a we're better off in a raw or recompiler mode.
446 *
447 * @returns Todo - status describing what to do next?
448 * @param pVM The VM to operate on.
449 */
450EMR3DECL(int) EMR3Interpret(PVM pVM);
451
452/** @} */
453#endif
454
455
456#ifdef IN_GC
457/** @defgroup grp_em_gc The EM Guest Context API
458 * @ingroup grp_em
459 * @{
460 */
461
462/**
463 * Decide what to do with a trap.
464 *
465 * @returns Next VMM state.
466 * @returns Might not return at all?
467 * @param pVM The VM to operate on.
468 * @param uTrap The trap number.
469 * @param pRegFrame Register frame to operate on.
470 */
471EMGCDECL(int) EMGCTrap(PVM pVM, unsigned uTrap, PCPUMCTXCORE pRegFrame);
472
473EMGCDECL(uint32_t) EMGCEmulateLockCmpXchg(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
474EMGCDECL(uint32_t) EMGCEmulateCmpXchg(RTGCPTR pu32Param1, uint32_t *pu32Param2, uint32_t u32Param3, size_t cbSize, uint32_t *pEflags);
475EMGCDECL(uint32_t) EMGCEmulateLockCmpXchg8b(RTGCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX, uint32_t *pEflags);
476EMGCDECL(uint32_t) EMGCEmulateCmpXchg8b(RTGCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX, uint32_t *pEflags);
477EMGCDECL(uint32_t) EMGCEmulateLockXAdd(RTGCPTR pu32Param1, uint32_t *pu32Param2, size_t cbSize, uint32_t *pEflags);
478EMGCDECL(uint32_t) EMGCEmulateXAdd(RTGCPTR pu32Param1, uint32_t *pu32Param2, size_t cbSize, uint32_t *pEflags);
479
480/** @} */
481#endif
482
483/** @} */
484
485__END_DECLS
486
487#endif
488
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