VirtualBox

source: vbox/trunk/include/VBox/vm.h@ 2138

Last change on this file since 2138 was 1832, checked in by vboxsync, 18 years ago

CSAM updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 KB
Line 
1/** @file
2 * VM - The Virtual Machine, data.
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_vm_h__
23#define __VBox_vm_h__
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27#include <VBox/cpum.h>
28#include <VBox/stam.h>
29#include <VBox/vmapi.h>
30#include <VBox/sup.h>
31
32
33/** @defgroup grp_vm The Virtual Machine
34 * @{
35 */
36
37/** The name of the Guest Context VMM Core module. */
38#define VMMGC_MAIN_MODULE_NAME "VMMGC.gc"
39/** The name of the Ring 0 Context VMM Core module. */
40#define VMMR0_MAIN_MODULE_NAME "VMMR0.r0"
41
42/** VM Forced Action Flags.
43 *
44 * Use the VM_FF_SET() and VM_FF_CLEAR() macros to change the force
45 * action mask of a VM.
46 *
47 * @{
48 */
49/** This action forces the VM to service check and pending interrups on the APIC. */
50#define VM_FF_INTERRUPT_APIC BIT(0)
51/** This action forces the VM to service check and pending interrups on the PIC. */
52#define VM_FF_INTERRUPT_PIC BIT(1)
53/** This action forces the VM to schedule and run pending timer (TM). */
54#define VM_FF_TIMER BIT(2)
55/** PDM Queues are pending. */
56#define VM_FF_PDM_QUEUES BIT(3)
57/** PDM DMA transfers are pending. */
58#define VM_FF_PDM_DMA BIT(4)
59/** PDM critical section unlocking is pending, process promptly upon return to R3. */
60#define VM_FF_PDM_CRITSECT BIT(5)
61
62/** This action forces the VM to call DBGF so DBGF can service debugger
63 * requests in the emulation thread.
64 * This action flag stays asserted till DBGF clears it.*/
65#define VM_FF_DBGF BIT(8)
66/** This action forces the VM to service pending requests from other
67 * thread or requests which must be executed in another context. */
68#define VM_FF_REQUEST BIT(9)
69/** Terminate the VM immediately. */
70#define VM_FF_TERMINATE BIT(10)
71/** Reset the VM. (postponed) */
72#define VM_FF_RESET BIT(11)
73
74/** This action forces the VM to resync the page tables before going
75 * back to execute guest code. (GLOBAL FLUSH) */
76#define VM_FF_PGM_SYNC_CR3 BIT(16)
77/** Same as VM_FF_PGM_SYNC_CR3 except that global pages can be skipped.
78 * (NON-GLOBAL FLUSH) */
79#define VM_FF_PGM_SYNC_CR3_NON_GLOBAL BIT(17)
80/** Check the interupt and trap gates */
81#define VM_FF_TRPM_SYNC_IDT BIT(18)
82/** Check Guest's TSS ring 0 stack */
83#define VM_FF_SELM_SYNC_TSS BIT(19)
84/** Check Guest's GDT table */
85#define VM_FF_SELM_SYNC_GDT BIT(20)
86/** Check Guest's LDT table */
87#define VM_FF_SELM_SYNC_LDT BIT(21)
88/** Inhibit interrupts pending. See EMGetInhibitInterruptsPC(). */
89#define VM_FF_INHIBIT_INTERRUPTS BIT(22)
90
91/** CSAM needs to scan the page that's being executed */
92#define VM_FF_CSAM_SCAN_PAGE BIT(24)
93/** CSAM needs to do some homework. */
94#define VM_FF_CSAM_PENDING_ACTION BIT(25)
95
96/** Force return to Ring-3. */
97#define VM_FF_TO_R3 BIT(28)
98
99/** Suspend the VM - debug only. */
100#define VM_FF_DEBUG_SUSPEND BIT(31)
101
102/** Externally forced actions. Used to quit the idle/wait loop. */
103#define VM_FF_EXTERNAL_SUSPENDED_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_REQUEST)
104/** Externally forced actions. Used to quit the idle/wait loop. */
105#define VM_FF_EXTERNAL_HALTED_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_TIMER | VM_FF_INTERRUPT_APIC | VM_FF_INTERRUPT_PIC | VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA)
106/** High priority pre-execution actions. */
107#define VM_FF_HIGH_PRIORITY_PRE_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_INTERRUPT_APIC | VM_FF_INTERRUPT_PIC | VM_FF_TIMER | VM_FF_DEBUG_SUSPEND \
108 | VM_FF_PGM_SYNC_CR3 | VM_FF_PGM_SYNC_CR3_NON_GLOBAL | VM_FF_SELM_SYNC_TSS | VM_FF_TRPM_SYNC_IDT | VM_FF_SELM_SYNC_GDT | VM_FF_SELM_SYNC_LDT)
109/** High priority pre raw-mode execution mask. */
110#define VM_FF_HIGH_PRIORITY_PRE_RAW_MASK (VM_FF_PGM_SYNC_CR3 | VM_FF_PGM_SYNC_CR3_NON_GLOBAL | VM_FF_SELM_SYNC_TSS | VM_FF_TRPM_SYNC_IDT | VM_FF_SELM_SYNC_GDT | VM_FF_SELM_SYNC_LDT | VM_FF_INHIBIT_INTERRUPTS)
111/** High priority post-execution actions. */
112#define VM_FF_HIGH_PRIORITY_POST_MASK (VM_FF_PDM_CRITSECT|VM_FF_CSAM_PENDING_ACTION)
113/** Normal priority post-execution actions. */
114#define VM_FF_NORMAL_PRIORITY_POST_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_RESET | VM_FF_CSAM_SCAN_PAGE)
115/** Normal priority actions. */
116#define VM_FF_NORMAL_PRIORITY_MASK (VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA)
117/** Flags to check before resuming guest execution. */
118#define VM_FF_RESUME_GUEST_MASK (VM_FF_TO_R3)
119/** All the forced flags. */
120#define VM_FF_ALL_MASK (~0U)
121/** All the forced flags. */
122#define VM_FF_ALL_BUT_RAW_MASK (~(VM_FF_HIGH_PRIORITY_PRE_RAW_MASK | VM_FF_CSAM_PENDING_ACTION | VM_FF_PDM_CRITSECT))
123
124/** @} */
125
126/** @def VM_FF_SET
127 * Sets a force action flag.
128 *
129 * @param pVM VM Handle.
130 * @param fFlag The flag to set.
131 */
132#if 1
133# define VM_FF_SET(pVM, fFlag) ASMAtomicOrU32(&(pVM)->fForcedActions, (fFlag))
134#else
135# define VM_FF_SET(pVM, fFlag) \
136 do { ASMAtomicOrU32(&(pVM)->fForcedActions, (fFlag)); \
137 RTLogPrintf("VM_FF_SET : %08x %s - %s(%d) %s\n", (pVM)->fForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
138 } while (0)
139#endif
140
141/** @def VM_FF_CLEAR
142 * Clears a force action flag.
143 *
144 * @param pVM VM Handle.
145 * @param fFlag The flag to clear.
146 */
147#if 1
148# define VM_FF_CLEAR(pVM, fFlag) ASMAtomicAndU32(&(pVM)->fForcedActions, ~(fFlag))
149#else
150# define VM_FF_CLEAR(pVM, fFlag) \
151 do { ASMAtomicAndU32(&(pVM)->fForcedActions, ~(fFlag)); \
152 RTLogPrintf("VM_FF_CLEAR: %08x %s - %s(%d) %s\n", (pVM)->fForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
153 } while (0)
154#endif
155
156/** @def VM_FF_ISSET
157 * Checks if a force action flag is set.
158 *
159 * @param pVM VM Handle.
160 * @param fFlag The flag to check.
161 */
162#define VM_FF_ISSET(pVM, fFlag) (((pVM)->fForcedActions & (fFlag)) == (fFlag))
163
164/** @def VM_FF_ISPENDING
165 * Checks if one or more force action in the specified set is pending.
166 *
167 * @param pVM VM Handle.
168 * @param fFlags The flags to check for.
169 */
170#define VM_FF_ISPENDING(pVM, fFlags) ((pVM)->fForcedActions & (fFlags))
171
172
173/** @def VM_IS_EMT
174 * Checks if the current thread is the emulation thread (EMT).
175 *
176 * @remark The ring-0 variation will need attention if we expand the ring-0
177 * code to let threads other than EMT mess around with the VM.
178 */
179#ifdef IN_GC
180# define VM_IS_EMT(pVM) true
181#elif defined(IN_RING0)
182# define VM_IS_EMT(pVM) true
183#else
184# define VM_IS_EMT(pVM) ((pVM)->NativeThreadEMT == RTThreadNativeSelf())
185#endif
186
187/** @def VM_ASSERT_EMT
188 * Asserts that the current thread IS the emulation thread (EMT).
189 */
190#ifdef IN_GC
191# define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
192#elif defined(IN_RING0)
193# define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
194#else
195# define VM_ASSERT_EMT(pVM) \
196 AssertMsg(VM_IS_EMT(pVM), \
197 ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), pVM->NativeThreadEMT))
198#endif
199
200
201/**
202 * Asserts that the current thread is NOT the emulation thread.
203 */
204#define VM_ASSERT_OTHER_THREAD(pVM) \
205 AssertMsg(!VM_IS_EMT(pVM), ("Not other thread!!\n"))
206
207
208
209/** This is the VM structure.
210 *
211 * It contains (nearly?) all the VM data which have to be available in all
212 * contexts. Even if it contains all the data the idea is to use APIs not
213 * to modify all the members all around the place. Therefore we make use of
214 * unions to hide everything which isn't local to the current source module.
215 * This means we'll have to pay a little bit of attention when adding new
216 * members to structures in the unions and make sure to keep the padding sizes
217 * up to date.
218 *
219 * Run tstVMStructSize after update!
220 */
221typedef struct VM
222{
223 /** The state of the VM.
224 * This field is read only to everyone except the VM and EM. */
225 VMSTATE enmVMState;
226 /** Forced action flags.
227 * See the VM_FF_* \#defines. Updated atomically.
228 */
229 volatile uint32_t fForcedActions;
230 /** Pointer to the array of page descriptors for the VM structure allocation. */
231 R3PTRTYPE(PSUPPAGE) paVMPagesR3;
232 /** Session handle. For use when calling SUPR0 APIs. */
233 HCPTRTYPE(PSUPDRVSESSION) pSession;
234 /** Pointer to the next VM.
235 * We keep a per process list of VM for the event that a process could
236 * contain more than one VM.
237 */
238 HCPTRTYPE(struct VM *) pNext;
239 /** Host Context VM Pointer.
240 * @obsolete don't use in new code! */
241 HCPTRTYPE(struct VM *) pVMHC;
242 /** Ring-3 Host Context VM Pointer. */
243 R3PTRTYPE(struct VM *) pVMR3;
244 /** Ring-0 Host Context VM Pointer. */
245 R0PTRTYPE(struct VM *) pVMR0;
246 /** Guest Context VM Pointer. */
247 GCPTRTYPE(struct VM *) pVMGC;
248
249 /** @name Public VMM Switcher APIs
250 * @{ */
251 /**
252 * Assembly switch entry point for returning to host context.
253 * This function will clean up the stack frame.
254 *
255 * @param eax The return code, register.
256 * @param Ctx The guest core context.
257 * @remark Assume interrupts disabled.
258 */
259 RTGCPTR pfnVMMGCGuestToHostAsmGuestCtx/*(int32_t eax, CPUMCTXCORE Ctx)*/;
260
261 /**
262 * Assembly switch entry point for returning to host context.
263 *
264 * This is an alternative entry point which we'll be using when the we have the
265 * hypervisor context and need to save that before going to the host.
266 *
267 * This is typically useful when abandoning the hypervisor because of a trap
268 * and want the trap state to be saved.
269 *
270 * @param eax The return code, register.
271 * @param ecx Pointer to the hypervisor core context, register.
272 * @remark Assume interrupts disabled.
273 */
274 RTGCPTR pfnVMMGCGuestToHostAsmHyperCtx/*(int32_t eax, PCPUMCTXCORE ecx)*/;
275
276 /**
277 * Assembly switch entry point for returning to host context.
278 *
279 * This is an alternative to the two *Ctx APIs and implies that the context has already
280 * been saved, or that it's just a brief return to HC and that the caller intends to resume
281 * whatever it is doing upon 'return' from this call.
282 *
283 * @param eax The return code, register.
284 * @remark Assume interrupts disabled.
285 */
286 RTGCPTR pfnVMMGCGuestToHostAsm/*(int32_t eax)*/;
287 /** @} */
288
289
290 /** @name Various VM data owned by VM.
291 * @{ */
292 /** The thread handle of the emulation thread.
293 * Use the VM_IS_EMT() macro to check if executing in EMT. */
294 RTTHREAD ThreadEMT;
295 /** The native handle of ThreadEMT. Getting the native handle
296 * is generally faster than getting the IPRT one (except on OS/2 :-). */
297 RTNATIVETHREAD NativeThreadEMT;
298 /** @} */
299
300
301 /** @name Various items that are frequently accessed.
302 * @{ */
303 /** Raw ring-3 indicator. */
304 bool fRawR3Enabled;
305 /** Raw ring-0 indicator. */
306 bool fRawR0Enabled;
307 /** PATM enabled flag.
308 * This is placed here for performance reasons. */
309 bool fPATMEnabled;
310 /** CSAM enabled flag.
311 * This is placed here for performance reasons. */
312 bool fCSAMEnabled;
313
314 /** Hardware VM support is available and enabled.
315 * This is placed here for performance reasons. */
316 bool fHWACCMEnabled;
317 /** @} */
318
319
320 /* padding to make gnuc put the StatQemuToGC where msc does. */
321/*#if HC_ARCH_BITS == 32
322 uint32_t padding0;
323#endif */
324
325 /** Profiling the total time from Qemu to GC. */
326 STAMPROFILEADV StatTotalQemuToGC;
327 /** Profiling the total time from GC to Qemu. */
328 STAMPROFILEADV StatTotalGCToQemu;
329 /** Profiling the total time spent in GC. */
330 STAMPROFILEADV StatTotalInGC;
331 /** Profiling the total time spent not in Qemu. */
332 STAMPROFILEADV StatTotalInQemu;
333 /** Profiling the VMMSwitcher code for going to GC. */
334 STAMPROFILEADV StatSwitcherToGC;
335 /** Profiling the VMMSwitcher code for going to HC. */
336 STAMPROFILEADV StatSwitcherToHC;
337 STAMPROFILEADV StatSwitcherSaveRegs;
338 STAMPROFILEADV StatSwitcherSysEnter;
339 STAMPROFILEADV StatSwitcherDebug;
340 STAMPROFILEADV StatSwitcherCR0;
341 STAMPROFILEADV StatSwitcherCR4;
342 STAMPROFILEADV StatSwitcherJmpCR3;
343 STAMPROFILEADV StatSwitcherRstrRegs;
344 STAMPROFILEADV StatSwitcherLgdt;
345 STAMPROFILEADV StatSwitcherLidt;
346 STAMPROFILEADV StatSwitcherLldt;
347 STAMPROFILEADV StatSwitcherTSS;
348
349 /* padding - the unions must be aligned on 32 bytes boundraries. */
350 uint32_t padding[HC_ARCH_BITS == 32 ? 6 : 6];
351
352 /** CPUM part. */
353 union
354 {
355#ifdef __CPUMInternal_h__
356 struct CPUM s;
357#endif
358#ifdef VBOX_WITH_HYBIRD_32BIT_KERNEL
359 char padding[3584]; /* multiple of 32 */
360#else
361 char padding[HC_ARCH_BITS == 32 ? 3424 : 3552]; /* multiple of 32 */
362#endif
363 } cpum;
364
365 /** VMM part. */
366 union
367 {
368#ifdef __VMMInternal_h__
369 struct VMM s;
370#endif
371 char padding[1024]; /* multiple of 32 */
372 } vmm;
373
374 /** PGM part. */
375 union
376 {
377#ifdef __PGMInternal_h__
378 struct PGM s;
379#endif
380 char padding[50*1024]; /* multiple of 32 */
381 } pgm;
382
383 /** HWACCM part. */
384 union
385 {
386#ifdef __HWACCMInternal_h__
387 struct HWACCM s;
388#endif
389 char padding[1024]; /* multiple of 32 */
390 } hwaccm;
391
392 /** TRPM part. */
393 union
394 {
395#ifdef __TRPMInternal_h__
396 struct TRPM s;
397#endif
398 char padding[5344]; /* multiple of 32 */
399 } trpm;
400
401 /** SELM part. */
402 union
403 {
404#ifdef __SELMInternal_h__
405 struct SELM s;
406#endif
407 char padding[544]; /* multiple of 32 */
408 } selm;
409
410 /** MM part. */
411 union
412 {
413#ifdef __MMInternal_h__
414 struct MM s;
415#endif
416 char padding[128]; /* multiple of 32 */
417 } mm;
418
419 /** CFGM part. */
420 union
421 {
422#ifdef __CFGMInternal_h__
423 struct CFGM s;
424#endif
425 char padding[32]; /* multiple of 32 */
426 } cfgm;
427
428 /** PDM part. */
429 union
430 {
431#ifdef __PDMInternal_h__
432 struct PDM s;
433#endif
434 char padding[1024]; /* multiple of 32 */
435 } pdm;
436
437 /** IOM part. */
438 union
439 {
440#ifdef __IOMInternal_h__
441 struct IOM s;
442#endif
443 char padding[4544]; /* multiple of 32 */
444 } iom;
445
446 /** PATM part. */
447 union
448 {
449#ifdef __PATMInternal_h__
450 struct PATM s;
451#endif
452 char padding[768]; /* multiple of 32 */
453 } patm;
454
455 /** CSAM part. */
456 union
457 {
458#ifdef __CSAMInternal_h__
459 struct CSAM s;
460#endif
461 char padding[3328]; /* multiple of 32 */
462 } csam;
463
464 /** EM part. */
465 union
466 {
467#ifdef __EMInternal_h__
468 struct EM s;
469#endif
470 char padding[1344]; /* multiple of 32 */
471 } em;
472
473 /** TM part. */
474 union
475 {
476#ifdef __TMInternal_h__
477 struct TM s;
478#endif
479 char padding[768]; /* multiple of 32 */
480 } tm;
481
482 /** DBGF part. */
483 union
484 {
485#ifdef __DBGFInternal_h__
486 struct DBGF s;
487#endif
488 char padding[HC_ARCH_BITS == 32 ? 1888 : 1920]; /* multiple of 32 */
489 } dbgf;
490
491 /** STAM part. */
492 union
493 {
494#ifdef __STAMInternal_h__
495 struct STAM s;
496#endif
497 char padding[32]; /* multiple of 32 */
498 } stam;
499
500 /** SSM part. */
501 union
502 {
503#ifdef __SSMInternal_h__
504 struct SSM s;
505#endif
506 char padding[32]; /* multiple of 32 */
507 } ssm;
508
509 /** VM part. */
510 union
511 {
512#ifdef __VMInternal_h__
513 struct VMINT s;
514#endif
515 char padding[672]; /* multiple of 32 */
516 } vm;
517
518 /** REM part. */
519 union
520 {
521#ifdef __REMInternal_h__
522 struct REM s;
523#endif
524 char padding[HC_ARCH_BITS == 32 ? 0x6b00 : 0xbf00]; /* multiple of 32 */
525 } rem;
526} VM;
527
528/** Pointer to a VM. */
529#ifndef __VBox_types_h__
530typedef struct VM *PVM;
531#endif
532
533
534#ifdef IN_GC
535__BEGIN_DECLS
536
537/** The VM structure.
538 * This is imported from the VMMGCBuiltin module, i.e. it's a one
539 * of those magic globals which we should avoid using.
540 */
541extern DECLIMPORT(VM) g_VM;
542
543__END_DECLS
544#endif
545
546/** @} */
547
548#endif
549
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