VirtualBox

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

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

Interpret msr reads and writes (currently disabled in order not to break anything at this point in time)

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