VirtualBox

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

Last change on this file since 19266 was 19217, checked in by vboxsync, 16 years ago

UVM splitup for SMP guests. Global and local request packets supported.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.4 KB
Line 
1/** @file
2 * VM - The Virtual Machine, data.
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_vm_h
31#define ___VBox_vm_h
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35#include <VBox/cpum.h>
36#include <VBox/stam.h>
37#include <VBox/vmapi.h>
38#include <VBox/sup.h>
39
40
41/** @defgroup grp_vm The Virtual Machine
42 * @{
43 */
44
45/** Maximum number of virtual CPUs per VM. */
46#define VMCPU_MAX_CPU_COUNT 255
47
48/**
49 * The state of a virtual CPU.
50 *
51 * The VM running states are a sub-states of the VMSTATE_RUNNING state. While
52 * VMCPUSTATE_NOT_RUNNING is a place holder for the other VM states.
53 */
54typedef enum VMCPUSTATE
55{
56 /** The customary invalid zero. */
57 VMCPUSTATE_INVALID = 0,
58
59 /** Running guest code (VM running). */
60 VMCPUSTATE_RUN_EXEC,
61 /** Running guest code in the recompiler (VM running). */
62 VMCPUSTATE_RUN_EXEC_REM,
63 /** Halted (VM running). */
64 VMCPUSTATE_RUN_HALTED,
65 /** All the other bits we do while running a VM (VM running). */
66 VMCPUSTATE_RUN_MISC,
67 /** VM not running, we're servicing requests or whatever. */
68 VMCPUSTATE_NOT_RUNNING,
69 /** The end of valid virtual CPU states. */
70 VMCPUSTATE_END,
71
72 /** Ensure 32-bit type. */
73 VMCPUSTATE_32BIT_HACK = 0x7fffffff
74} VMCPUSTATE;
75
76
77/**
78 * Per virtual CPU data.
79 */
80typedef struct VMCPU
81{
82 /** Per CPU forced action.
83 * See the VMCPU_FF_* \#defines. Updated atomically. */
84 uint32_t volatile fLocalForcedActions;
85 /** The CPU state. */
86 VMCPUSTATE volatile enmState;
87
88 /** Pointer to the ring-3 UVMCPU structure. */
89 PUVMCPU pUVCpu;
90 /** Ring-3 Host Context VM Pointer. */
91 PVMR3 pVMR3;
92 /** Ring-0 Host Context VM Pointer. */
93 PVMR0 pVMR0;
94 /** Raw-mode Context VM Pointer. */
95 PVMRC pVMRC;
96 /** The CPU ID.
97 * This is the index into the VM::aCpu array. */
98 VMCPUID idCpu;
99 /** The native thread handle. */
100 RTNATIVETHREAD hNativeThread;
101
102 /** Align the next bit on a 64-byte boundary.
103 *
104 * @remarks The aligments of the members that are larger than 48 bytes should be
105 * 64-byte for cache line reasons. structs containing small amounts of
106 * data could be lumped together at the end with a < 64 byte padding
107 * following it (to grow into and align the struct size).
108 * */
109 uint32_t au32Alignment[HC_ARCH_BITS == 32 ? 8 : 4];
110
111 /** CPUM part. */
112 union
113 {
114#ifdef ___CPUMInternal_h
115 struct CPUMCPU s;
116#endif
117 char padding[4096]; /* multiple of 64 */
118 } cpum;
119 /** VMM part. */
120 union
121 {
122#ifdef ___VMMInternal_h
123 struct VMMCPU s;
124#endif
125 char padding[64]; /* multiple of 64 */
126 } vmm;
127
128 /** PGM part. */
129 union
130 {
131#ifdef ___PGMInternal_h
132 struct PGMCPU s;
133#endif
134 char padding[32*1024]; /* multiple of 64 */
135 } pgm;
136
137 /** HWACCM part. */
138 union
139 {
140#ifdef ___HWACCMInternal_h
141 struct HWACCMCPU s;
142#endif
143 char padding[5120]; /* multiple of 64 */
144 } hwaccm;
145
146 /** EM part. */
147 union
148 {
149#ifdef ___EMInternal_h
150 struct EMCPU s;
151#endif
152 char padding[2048]; /* multiple of 64 */
153 } em;
154
155 /** TRPM part. */
156 union
157 {
158#ifdef ___TRPMInternal_h
159 struct TRPMCPU s;
160#endif
161 char padding[64]; /* multiple of 64 */
162 } trpm;
163
164 /** TM part. */
165 union
166 {
167#ifdef ___TMInternal_h
168 struct TMCPU s;
169#endif
170 char padding[64]; /* multiple of 64 */
171 } tm;
172} VMCPU;
173
174/** Pointer to a VMCPU. */
175#ifndef ___VBox_types_h
176typedef struct VMCPU *PVMCPU;
177#endif
178
179/** The name of the Guest Context VMM Core module. */
180#define VMMGC_MAIN_MODULE_NAME "VMMGC.gc"
181/** The name of the Ring 0 Context VMM Core module. */
182#define VMMR0_MAIN_MODULE_NAME "VMMR0.r0"
183
184/** VM Forced Action Flags.
185 *
186 * Use the VM_FF_SET() and VM_FF_CLEAR() macros to change the force
187 * action mask of a VM.
188 *
189 * @{
190 */
191/** This action forces the VM to schedule and run pending timer (TM). */
192#define VM_FF_TIMER RT_BIT_32(2)
193/** PDM Queues are pending. */
194#define VM_FF_PDM_QUEUES RT_BIT_32(3)
195/** PDM DMA transfers are pending. */
196#define VM_FF_PDM_DMA RT_BIT_32(4)
197/** PDM critical section unlocking is pending, process promptly upon return to R3. */
198#define VM_FF_PDM_CRITSECT RT_BIT_32(5)
199/** This action forces the VM to call DBGF so DBGF can service debugger
200 * requests in the emulation thread.
201 * This action flag stays asserted till DBGF clears it.*/
202#define VM_FF_DBGF RT_BIT_32(8)
203/** This action forces the VM to service pending requests from other
204 * thread or requests which must be executed in another context. */
205#define VM_FF_REQUEST RT_BIT_32(9)
206/** Terminate the VM immediately. */
207#define VM_FF_TERMINATE RT_BIT_32(10)
208/** Reset the VM. (postponed) */
209#define VM_FF_RESET RT_BIT_32(11)
210/** PGM needs to allocate handy pages. */
211#define VM_FF_PGM_NEED_HANDY_PAGES RT_BIT_32(18)
212/** PGM is out of memory.
213 * Abandon all loops and code paths which can be resumed and get up to the EM
214 * loops. */
215#define VM_FF_PGM_NO_MEMORY RT_BIT_32(19)
216/** REM needs to be informed about handler changes. */
217#define VM_FF_REM_HANDLER_NOTIFY RT_BIT_32(29)
218/** Suspend the VM - debug only. */
219#define VM_FF_DEBUG_SUSPEND RT_BIT_32(31)
220
221
222/** This action forces the VM to service check and pending interrups on the APIC. */
223#define VMCPU_FF_INTERRUPT_APIC RT_BIT_32(0)
224/** This action forces the VM to service check and pending interrups on the PIC. */
225#define VMCPU_FF_INTERRUPT_PIC RT_BIT_32(1)
226/** This action forces the VM to schedule and run pending timer (TM). (bogus for now; needed for PATM backwards compatibility) */
227#define VMCPU_FF_TIMER RT_BIT_32(2)
228/** This action forces the VM to service pending requests from other
229 * thread or requests which must be executed in another context. */
230#define VMCPU_FF_REQUEST RT_BIT_32(9)
231/** This action forces the VM to resync the page tables before going
232 * back to execute guest code. (GLOBAL FLUSH) */
233#define VMCPU_FF_PGM_SYNC_CR3 RT_BIT_32(16)
234/** Same as VM_FF_PGM_SYNC_CR3 except that global pages can be skipped.
235 * (NON-GLOBAL FLUSH) */
236#define VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL RT_BIT_32(17)
237/** Check the interupt and trap gates */
238#define VMCPU_FF_TRPM_SYNC_IDT RT_BIT_32(20)
239/** Check Guest's TSS ring 0 stack */
240#define VMCPU_FF_SELM_SYNC_TSS RT_BIT_32(21)
241/** Check Guest's GDT table */
242#define VMCPU_FF_SELM_SYNC_GDT RT_BIT_32(22)
243/** Check Guest's LDT table */
244#define VMCPU_FF_SELM_SYNC_LDT RT_BIT_32(23)
245/** Inhibit interrupts pending. See EMGetInhibitInterruptsPC(). */
246#define VMCPU_FF_INHIBIT_INTERRUPTS RT_BIT_32(24)
247/** CSAM needs to scan the page that's being executed */
248#define VMCPU_FF_CSAM_SCAN_PAGE RT_BIT_32(26)
249/** CSAM needs to do some homework. */
250#define VMCPU_FF_CSAM_PENDING_ACTION RT_BIT_32(27)
251/** Force return to Ring-3. */
252#define VMCPU_FF_TO_R3 RT_BIT_32(28)
253
254/** Externally VM forced actions. Used to quit the idle/wait loop. */
255#define VM_FF_EXTERNAL_SUSPENDED_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_REQUEST)
256/** Externally VMCPU forced actions. Used to quit the idle/wait loop. */
257#define VMCPU_FF_EXTERNAL_SUSPENDED_MASK (VMCPU_FF_REQUEST)
258
259/** Externally forced VM actions. Used to quit the idle/wait loop. */
260#define VM_FF_EXTERNAL_HALTED_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_TIMER | VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA)
261/** Externally forced VMCPU actions. Used to quit the idle/wait loop. */
262#define VMCPU_FF_EXTERNAL_HALTED_MASK (VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC | VMCPU_FF_REQUEST)
263
264/** High priority VM pre-execution actions. */
265#define VM_FF_HIGH_PRIORITY_PRE_MASK ( VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_TIMER | VM_FF_DEBUG_SUSPEND \
266 | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY)
267/** High priority VMCPU pre-execution actions. */
268#define VMCPU_FF_HIGH_PRIORITY_PRE_MASK ( VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC \
269 | VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT)
270
271/** High priority VM pre raw-mode execution mask. */
272#define VM_FF_HIGH_PRIORITY_PRE_RAW_MASK (VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY)
273/** High priority VMCPU pre raw-mode execution mask. */
274#define VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK ( VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT \
275 | VMCPU_FF_INHIBIT_INTERRUPTS)
276
277/** High priority post-execution actions. */
278#define VM_FF_HIGH_PRIORITY_POST_MASK (VM_FF_PDM_CRITSECT | VM_FF_PGM_NO_MEMORY)
279/** High priority post-execution actions. */
280#define VMCPU_FF_HIGH_PRIORITY_POST_MASK (VMCPU_FF_CSAM_PENDING_ACTION)
281
282/** Normal priority VM post-execution actions. */
283#define VM_FF_NORMAL_PRIORITY_POST_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_RESET | VM_FF_PGM_NO_MEMORY)
284/** Normal priority VMCPU post-execution actions. */
285#define VMCPU_FF_NORMAL_PRIORITY_POST_MASK (VMCPU_FF_CSAM_SCAN_PAGE)
286
287/** Normal priority VM actions. */
288#define VM_FF_NORMAL_PRIORITY_MASK (VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_REM_HANDLER_NOTIFY)
289/** Normal priority VMCPU actions. */
290#define VMCPU_FF_NORMAL_PRIORITY_MASK (VMCPU_FF_REQUEST)
291
292/** Flags to clear before resuming guest execution. */
293#define VMCPU_FF_RESUME_GUEST_MASK (VMCPU_FF_TO_R3)
294
295/** VM Flags that cause the HWACCM loops to go back to ring-3. */
296#define VM_FF_HWACCM_TO_R3_MASK (VM_FF_TIMER | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY)
297/** VMCPU Flags that cause the HWACCM loops to go back to ring-3. */
298#define VMCPU_FF_HWACCM_TO_R3_MASK (VMCPU_FF_TO_R3)
299
300/** All the forced flags. */
301#define VM_FF_ALL_MASK (~0U)
302/** All the forced VM flags. */
303#define VM_FF_ALL_BUT_RAW_MASK (~(VM_FF_HIGH_PRIORITY_PRE_RAW_MASK | VM_FF_PDM_CRITSECT) | VM_FF_PGM_NO_MEMORY)
304/** All the forced VMCPU flags. */
305#define VMCPU_FF_ALL_BUT_RAW_MASK (~(VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK | VMCPU_FF_CSAM_PENDING_ACTION))
306
307/** @} */
308
309/** @def VM_FF_SET
310 * Sets a force action flag.
311 *
312 * @param pVM VM Handle.
313 * @param fFlag The flag to set.
314 */
315#if 1
316# define VM_FF_SET(pVM, fFlag) ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag))
317#else
318# define VM_FF_SET(pVM, fFlag) \
319 do { ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag)); \
320 RTLogPrintf("VM_FF_SET : %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
321 } while (0)
322#endif
323
324/** @def VMCPU_FF_SET
325 * Sets a force action flag for the given VCPU.
326 *
327 * @param pVCpu VMCPU Handle.
328 * @param fFlag The flag to set.
329 */
330#define VMCPU_FF_SET(pVCpu, fFlag) ASMAtomicOrU32(&(pVCpu)->fLocalForcedActions, (fFlag))
331
332/** @def VM_FF_CLEAR
333 * Clears a force action flag.
334 *
335 * @param pVM VM Handle.
336 * @param fFlag The flag to clear.
337 */
338#if 1
339# define VM_FF_CLEAR(pVM, fFlag) ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag))
340#else
341# define VM_FF_CLEAR(pVM, fFlag) \
342 do { ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag)); \
343 RTLogPrintf("VM_FF_CLEAR: %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
344 } while (0)
345#endif
346
347/** @def VMCPU_FF_CLEAR
348 * Clears a force action flag for the given VCPU.
349 *
350 * @param pVCpu VMCPU Handle.
351 * @param fFlag The flag to clear.
352 */
353#define VMCPU_FF_CLEAR(pVCpu, fFlag) ASMAtomicAndU32(&(pVCpu)->fLocalForcedActions, ~(fFlag))
354
355/** @def VM_FF_ISSET
356 * Checks if a force action flag is set.
357 *
358 * @param pVM VM Handle.
359 * @param fFlag The flag to check.
360 */
361#define VM_FF_ISSET(pVM, fFlag) (((pVM)->fGlobalForcedActions & (fFlag)) == (fFlag))
362
363/** @def VMCPU_FF_ISSET
364 * Checks if a force action flag is set for the given VCPU.
365 *
366 * @param pVCpu VMCPU Handle.
367 * @param fFlag The flag to check.
368 */
369#define VMCPU_FF_ISSET(pVCpu, fFlag) (((pVCpu)->fLocalForcedActions & (fFlag)) == (fFlag))
370
371/** @def VM_FF_ISPENDING
372 * Checks if one or more force action in the specified set is pending.
373 *
374 * @param pVM VM Handle.
375 * @param fFlags The flags to check for.
376 */
377#define VM_FF_ISPENDING(pVM, fFlags) ((pVM)->fGlobalForcedActions & (fFlags))
378
379/** @def VMCPU_FF_ISPENDING
380 * Checks if one or more force action in the specified set is pending for the given VCPU.
381 *
382 * @param pVCpu VMCPU Handle.
383 * @param fFlags The flags to check for.
384 */
385#define VMCPU_FF_ISPENDING(pVCpu, fFlags) ((pVCpu)->fLocalForcedActions & (fFlags))
386
387/** @def VM_FF_ISPENDING
388 * Checks if one or more force action in the specified set is pending while one
389 * or more other ones are not.
390 *
391 * @param pVM VM Handle.
392 * @param fFlags The flags to check for.
393 * @param fExcpt The flags that should not be set.
394 */
395#define VM_FF_IS_PENDING_EXCEPT(pVM, fFlags, fExcpt) ( ((pVM)->fGlobalForcedActions & (fFlags)) && !((pVM)->fGlobalForcedActions & (fExcpt)) )
396
397/** @def VMCPU_FF_IS_PENDING_EXCEPT
398 * Checks if one or more force action in the specified set is pending for the given
399 * VCPU while one or more other ones are not.
400 *
401 * @param pVCpu VMCPU Handle.
402 * @param fFlags The flags to check for.
403 * @param fExcpt The flags that should not be set.
404 */
405#define VMCPU_FF_IS_PENDING_EXCEPT(pVCpu, fFlags, fExcpt) ( ((pVCpu)->fLocalForcedActions & (fFlags)) && !((pVCpu)->fLocalForcedActions & (fExcpt)) )
406
407/** @def VM_IS_EMT
408 * Checks if the current thread is the emulation thread (EMT).
409 *
410 * @remark The ring-0 variation will need attention if we expand the ring-0
411 * code to let threads other than EMT mess around with the VM.
412 */
413#ifdef IN_RC
414# define VM_IS_EMT(pVM) true
415#elif defined(IN_RING0)
416# define VM_IS_EMT(pVM) true
417#else
418/** @todo need to rework this macro for the case of multiple emulation threads for SMP */
419# define VM_IS_EMT(pVM) (VMR3GetVMCPUNativeThread(pVM) == RTThreadNativeSelf())
420#endif
421
422/** @def VMCPU_IS_EMT
423 * Checks if the current thread is the emulation thread (EMT) for the specified
424 * virtual CPU.
425 */
426#ifdef IN_RC
427# define VMCPU_IS_EMT(pVCpu) true
428#elif defined(IN_RING0)
429# define VMCPU_IS_EMT(pVCpu) fixme - need to call HWACCM I think... /** @todo SMP */
430#else
431/** @todo need to rework this macro for the case of multiple emulation threads for SMP */
432# define VMCPU_IS_EMT(pVCpu) ((pVCpu)->hNativeThread == RTThreadNativeSelf())
433#endif
434
435/** @def VM_ASSERT_EMT
436 * Asserts that the current thread IS the emulation thread (EMT).
437 */
438#ifdef IN_RC
439# define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
440#elif defined(IN_RING0)
441# define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
442#else
443# define VM_ASSERT_EMT(pVM) \
444 AssertMsg(VM_IS_EMT(pVM), \
445 ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)))
446#endif
447
448/** @def VMCPU_ASSERT_EMT
449 * Asserts that the current thread IS the emulation thread (EMT) of the
450 * specified virtual CPU.
451 */
452#ifdef IN_RC
453# define VMCPU_ASSERT_EMT(pVCpu) Assert(VMCPU_IS_EMT(pVCpu))
454#elif defined(IN_RING0)
455# define VMCPU_ASSERT_EMT(pVCpu) Assert(VMCPU_IS_EMT(pVCpu))
456#else
457# define VMCPU_ASSERT_EMT(pVCpu) \
458 AssertMsg(VMCPU_IS_EMT(pVCpu), \
459 ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
460 RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
461#endif
462
463/** @def VM_ASSERT_EMT_RETURN
464 * Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
465 */
466#ifdef IN_RC
467# define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
468#elif defined(IN_RING0)
469# define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
470#else
471# define VM_ASSERT_EMT_RETURN(pVM, rc) \
472 AssertMsgReturn(VM_IS_EMT(pVM), \
473 ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)), \
474 (rc))
475#endif
476
477/** @def VMCPU_ASSERT_EMT_RETURN
478 * Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
479 */
480#ifdef IN_RC
481# define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
482#elif defined(IN_RING0)
483# define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
484#else
485# define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) \
486 AssertMsg(VMCPU_IS_EMT(pVCpu), \
487 ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
488 RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu), \
489 (rc))
490#endif
491
492
493/**
494 * Asserts that the current thread is NOT the emulation thread.
495 */
496#define VM_ASSERT_OTHER_THREAD(pVM) \
497 AssertMsg(!VM_IS_EMT(pVM), ("Not other thread!!\n"))
498
499
500/** @def VM_ASSERT_STATE_RETURN
501 * Asserts a certain VM state.
502 */
503#define VM_ASSERT_STATE(pVM, _enmState) \
504 AssertMsg((pVM)->enmVMState == (_enmState), \
505 ("state %s, expected %s\n", VMGetStateName(pVM->enmVMState), VMGetStateName(_enmState)))
506
507/** @def VM_ASSERT_STATE_RETURN
508 * Asserts a certain VM state and returns if it doesn't match.
509 */
510#define VM_ASSERT_STATE_RETURN(pVM, _enmState, rc) \
511 AssertMsgReturn((pVM)->enmVMState == (_enmState), \
512 ("state %s, expected %s\n", VMGetStateName(pVM->enmVMState), VMGetStateName(_enmState)), \
513 (rc))
514
515/** @def VM_ASSERT_VALID_EXT_RETURN
516 * Asserts a the VM handle is valid for external access, i.e. not being
517 * destroy or terminated.
518 */
519#define VM_ASSERT_VALID_EXT_RETURN(pVM, rc) \
520 AssertMsgReturn( RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
521 && (unsigned)(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING, \
522 ("pVM=%p state %s\n", (pVM), RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
523 ? VMGetStateName(pVM->enmVMState) : ""), \
524 (rc))
525
526/** @def VMCPU_ASSERT_VALID_EXT_RETURN
527 * Asserts a the VMCPU handle is valid for external access, i.e. not being
528 * destroy or terminated.
529 */
530#define VMCPU_ASSERT_VALID_EXT_RETURN(pVCpu, rc) \
531 AssertMsgReturn( RT_VALID_ALIGNED_PTR(pVCpu, 64) \
532 && RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
533 && (unsigned)(pVCpu)->CTX_SUFF(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING, \
534 ("pVCpu=%p pVM=%p state %s\n", (pVCpu), RT_VALID_ALIGNED_PTR(pVCpu, 64) ? (pVCpu)->CTX_SUFF(pVM) : NULL, \
535 RT_VALID_ALIGNED_PTR(pVCpu, 64) && RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
536 ? VMGetStateName((pVCpu)->pVMR3->enmVMState) : ""), \
537 (rc))
538
539
540/** This is the VM structure.
541 *
542 * It contains (nearly?) all the VM data which have to be available in all
543 * contexts. Even if it contains all the data the idea is to use APIs not
544 * to modify all the members all around the place. Therefore we make use of
545 * unions to hide everything which isn't local to the current source module.
546 * This means we'll have to pay a little bit of attention when adding new
547 * members to structures in the unions and make sure to keep the padding sizes
548 * up to date.
549 *
550 * Run tstVMStructSize after update!
551 */
552typedef struct VM
553{
554 /** The state of the VM.
555 * This field is read only to everyone except the VM and EM. */
556 VMSTATE enmVMState;
557 /** Forced action flags.
558 * See the VM_FF_* \#defines. Updated atomically.
559 */
560 volatile uint32_t fGlobalForcedActions;
561 /** Pointer to the array of page descriptors for the VM structure allocation. */
562 R3PTRTYPE(PSUPPAGE) paVMPagesR3;
563 /** Session handle. For use when calling SUPR0 APIs. */
564 PSUPDRVSESSION pSession;
565 /** Pointer to the ring-3 VM structure. */
566 PUVM pUVM;
567 /** Ring-3 Host Context VM Pointer. */
568 R3PTRTYPE(struct VM *) pVMR3;
569 /** Ring-0 Host Context VM Pointer. */
570 R0PTRTYPE(struct VM *) pVMR0;
571 /** Raw-mode Context VM Pointer. */
572 RCPTRTYPE(struct VM *) pVMRC;
573
574 /** The GVM VM handle. Only the GVM should modify this field. */
575 uint32_t hSelf;
576 /** Number of virtual CPUs. */
577 uint32_t cCPUs;
578
579 /** Size of the VM structure including the VMCPU array. */
580 uint32_t cbSelf;
581
582 /** Offset to the VMCPU array starting from beginning of this structure. */
583 uint32_t offVMCPU;
584
585 /** Reserved; alignment. */
586 uint32_t u32Reserved[6];
587
588 /** @name Public VMM Switcher APIs
589 * @{ */
590 /**
591 * Assembly switch entry point for returning to host context.
592 * This function will clean up the stack frame.
593 *
594 * @param eax The return code, register.
595 * @param Ctx The guest core context.
596 * @remark Assume interrupts disabled.
597 */
598 RTRCPTR pfnVMMGCGuestToHostAsmGuestCtx/*(int32_t eax, CPUMCTXCORE Ctx)*/;
599
600 /**
601 * Assembly switch entry point for returning to host context.
602 *
603 * This is an alternative entry point which we'll be using when the we have the
604 * hypervisor context and need to save that before going to the host.
605 *
606 * This is typically useful when abandoning the hypervisor because of a trap
607 * and want the trap state to be saved.
608 *
609 * @param eax The return code, register.
610 * @param ecx Pointer to the hypervisor core context, register.
611 * @remark Assume interrupts disabled.
612 */
613 RTRCPTR pfnVMMGCGuestToHostAsmHyperCtx/*(int32_t eax, PCPUMCTXCORE ecx)*/;
614
615 /**
616 * Assembly switch entry point for returning to host context.
617 *
618 * This is an alternative to the two *Ctx APIs and implies that the context has already
619 * been saved, or that it's just a brief return to HC and that the caller intends to resume
620 * whatever it is doing upon 'return' from this call.
621 *
622 * @param eax The return code, register.
623 * @remark Assume interrupts disabled.
624 */
625 RTRCPTR pfnVMMGCGuestToHostAsm/*(int32_t eax)*/;
626 /** @} */
627
628
629 /** @name Various VM data owned by VM.
630 * @{ */
631 RTTHREAD uPadding1;
632 /** The native handle of ThreadEMT. Getting the native handle
633 * is generally faster than getting the IPRT one (except on OS/2 :-). */
634 RTNATIVETHREAD uPadding2;
635 /** @} */
636
637
638 /** @name Various items that are frequently accessed.
639 * @{ */
640 /** Raw ring-3 indicator. */
641 bool fRawR3Enabled;
642 /** Raw ring-0 indicator. */
643 bool fRawR0Enabled;
644 /** PATM enabled flag.
645 * This is placed here for performance reasons. */
646 bool fPATMEnabled;
647 /** CSAM enabled flag.
648 * This is placed here for performance reasons. */
649 bool fCSAMEnabled;
650 /** Hardware VM support is available and enabled.
651 * This is placed here for performance reasons. */
652 bool fHWACCMEnabled;
653 /** Hardware VM support is required and non-optional.
654 * This is initialized together with the rest of the VM structure. */
655 bool fHwVirtExtForced;
656 /** PARAV enabled flag. */
657 bool fPARAVEnabled;
658 /** @} */
659
660
661 /* padding to make gnuc put the StatQemuToGC where msc does. */
662#if HC_ARCH_BITS == 32
663 uint32_t padding0;
664#endif
665
666 /** Profiling the total time from Qemu to GC. */
667 STAMPROFILEADV StatTotalQemuToGC;
668 /** Profiling the total time from GC to Qemu. */
669 STAMPROFILEADV StatTotalGCToQemu;
670 /** Profiling the total time spent in GC. */
671 STAMPROFILEADV StatTotalInGC;
672 /** Profiling the total time spent not in Qemu. */
673 STAMPROFILEADV StatTotalInQemu;
674 /** Profiling the VMMSwitcher code for going to GC. */
675 STAMPROFILEADV StatSwitcherToGC;
676 /** Profiling the VMMSwitcher code for going to HC. */
677 STAMPROFILEADV StatSwitcherToHC;
678 STAMPROFILEADV StatSwitcherSaveRegs;
679 STAMPROFILEADV StatSwitcherSysEnter;
680 STAMPROFILEADV StatSwitcherDebug;
681 STAMPROFILEADV StatSwitcherCR0;
682 STAMPROFILEADV StatSwitcherCR4;
683 STAMPROFILEADV StatSwitcherJmpCR3;
684 STAMPROFILEADV StatSwitcherRstrRegs;
685 STAMPROFILEADV StatSwitcherLgdt;
686 STAMPROFILEADV StatSwitcherLidt;
687 STAMPROFILEADV StatSwitcherLldt;
688 STAMPROFILEADV StatSwitcherTSS;
689
690/** @todo Realign everything on 64 byte boundaries to better match the
691 * cache-line size. */
692 /* padding - the unions must be aligned on 32 bytes boundraries. */
693 uint32_t padding[HC_ARCH_BITS == 32 ? 4+8 : 6];
694
695 /** CPUM part. */
696 union
697 {
698#ifdef ___CPUMInternal_h
699 struct CPUM s;
700#endif
701 char padding[2048]; /* multiple of 32 */
702 } cpum;
703
704 /** VMM part. */
705 union
706 {
707#ifdef ___VMMInternal_h
708 struct VMM s;
709#endif
710 char padding[1600]; /* multiple of 32 */
711 } vmm;
712
713 /** PGM part. */
714 union
715 {
716#ifdef ___PGMInternal_h
717 struct PGM s;
718#endif
719 char padding[16*1024]; /* multiple of 32 */
720 } pgm;
721
722 /** HWACCM part. */
723 union
724 {
725#ifdef ___HWACCMInternal_h
726 struct HWACCM s;
727#endif
728 char padding[512]; /* multiple of 32 */
729 } hwaccm;
730
731 /** TRPM part. */
732 union
733 {
734#ifdef ___TRPMInternal_h
735 struct TRPM s;
736#endif
737 char padding[5344]; /* multiple of 32 */
738 } trpm;
739
740 /** SELM part. */
741 union
742 {
743#ifdef ___SELMInternal_h
744 struct SELM s;
745#endif
746 char padding[544]; /* multiple of 32 */
747 } selm;
748
749 /** MM part. */
750 union
751 {
752#ifdef ___MMInternal_h
753 struct MM s;
754#endif
755 char padding[192]; /* multiple of 32 */
756 } mm;
757
758 /** CFGM part. */
759 union
760 {
761#ifdef ___CFGMInternal_h
762 struct CFGM s;
763#endif
764 char padding[32]; /* multiple of 32 */
765 } cfgm;
766
767 /** PDM part. */
768 union
769 {
770#ifdef ___PDMInternal_h
771 struct PDM s;
772#endif
773 char padding[1824]; /* multiple of 32 */
774 } pdm;
775
776 /** IOM part. */
777 union
778 {
779#ifdef ___IOMInternal_h
780 struct IOM s;
781#endif
782 char padding[4544]; /* multiple of 32 */
783 } iom;
784
785 /** PATM part. */
786 union
787 {
788#ifdef ___PATMInternal_h
789 struct PATM s;
790#endif
791 char padding[768]; /* multiple of 32 */
792 } patm;
793
794 /** CSAM part. */
795 union
796 {
797#ifdef ___CSAMInternal_h
798 struct CSAM s;
799#endif
800 char padding[3328]; /* multiple of 32 */
801 } csam;
802
803 /** PARAV part. */
804 union
805 {
806#ifdef ___PARAVInternal_h
807 struct PARAV s;
808#endif
809 char padding[128];
810 } parav;
811
812 /** EM part. */
813 union
814 {
815#ifdef ___EMInternal_h
816 struct EM s;
817#endif
818 char padding[64]; /* multiple of 32 */
819 } em;
820
821 /** TM part. */
822 union
823 {
824#ifdef ___TMInternal_h
825 struct TM s;
826#endif
827 char padding[1536]; /* multiple of 32 */
828 } tm;
829
830 /** DBGF part. */
831 union
832 {
833#ifdef ___DBGFInternal_h
834 struct DBGF s;
835#endif
836 char padding[2368]; /* multiple of 32 */
837 } dbgf;
838
839 /** SSM part. */
840 union
841 {
842#ifdef ___SSMInternal_h
843 struct SSM s;
844#endif
845 char padding[32]; /* multiple of 32 */
846 } ssm;
847
848 /** VM part. */
849 union
850 {
851#ifdef ___VMInternal_h
852 struct VMINT s;
853#endif
854 char padding[768]; /* multiple of 32 */
855 } vm;
856
857 /** REM part. */
858 union
859 {
860#ifdef ___REMInternal_h
861 struct REM s;
862#endif
863
864/** @def VM_REM_SIZE
865 * Must be multiple of 32 and coherent with REM_ENV_SIZE from REMInternal.h. */
866#if GC_ARCH_BITS == 32
867# define VM_REM_SIZE (HC_ARCH_BITS == 32 ? 0x10800 : 0x10800)
868#else
869# define VM_REM_SIZE (HC_ARCH_BITS == 32 ? 0x10900 : 0x10900)
870#endif
871 char padding[VM_REM_SIZE]; /* multiple of 32 */
872 } rem;
873
874 /** Padding for aligning the cpu array on a 64 byte boundrary. */
875 uint32_t u32Reserved2[8];
876
877 /** VMCPU array for the configured number of virtual CPUs.
878 * Must be aligned on a 64-byte boundrary. */
879 VMCPU aCpus[1];
880} VM;
881
882/** Pointer to a VM. */
883#ifndef ___VBox_types_h
884typedef struct VM *PVM;
885#endif
886
887
888#ifdef IN_RC
889__BEGIN_DECLS
890
891/** The VM structure.
892 * This is imported from the VMMGCBuiltin module, i.e. it's a one
893 * of those magic globals which we should avoid using.
894 */
895extern DECLIMPORT(VM) g_VM;
896
897__END_DECLS
898#endif
899
900/** @} */
901
902#endif
903
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