VirtualBox

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

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

The Giant CDDL Dual-License Header Change.

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