VirtualBox

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

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

Eliminated HCPTRTYPE and replaced with R3R0PTRTYPE where necessary.

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