VirtualBox

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

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

More room for TM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.1 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 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 /** Ring-3 Host Context VM Pointer. */
238 R3PTRTYPE(struct VM *) pVMR3;
239 /** Ring-0 Host Context VM Pointer. */
240 R0PTRTYPE(struct VM *) pVMR0;
241 /** Guest Context VM Pointer. */
242 GCPTRTYPE(struct VM *) pVMGC;
243
244 /** The GVM VM handle. Only the GVM should modify this field. */
245 uint32_t hSelf;
246 /** Reserved / padding. */
247 uint32_t u32Reserved;
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 ? 4 : 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[3648]; /* multiple of 32 */
360#else
361 char padding[HC_ARCH_BITS == 32 ? 3488 : 3616]; /* 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[1312]; /* 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[256]; /* 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[768]; /* 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