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 |
|
---|
46 | /**
|
---|
47 | * The state of a virtual CPU.
|
---|
48 | *
|
---|
49 | * The VM running states are a sub-states of the VMSTATE_RUNNING state. While
|
---|
50 | * VMCPUSTATE_NOT_RUNNING is a place holder for the other VM states.
|
---|
51 | */
|
---|
52 | typedef enum VMCPUSTATE
|
---|
53 | {
|
---|
54 | /** The customary invalid zero. */
|
---|
55 | VMCPUSTATE_INVALID = 0,
|
---|
56 |
|
---|
57 | /** Running guest code (VM running). */
|
---|
58 | VMCPUSTATE_RUN_EXEC,
|
---|
59 | /** Running guest code in the recompiler (VM running). */
|
---|
60 | VMCPUSTATE_RUN_EXEC_REM,
|
---|
61 | /** Halted (VM running). */
|
---|
62 | VMCPUSTATE_RUN_HALTED,
|
---|
63 | /** All the other bits we do while running a VM (VM running). */
|
---|
64 | VMCPUSTATE_RUN_MISC,
|
---|
65 | /** VM not running, we're servicing requests or whatever. */
|
---|
66 | VMCPUSTATE_NOT_RUNNING,
|
---|
67 | /** The end of valid virtual CPU states. */
|
---|
68 | VMCPUSTATE_END,
|
---|
69 |
|
---|
70 | /** Ensure 32-bit type. */
|
---|
71 | VMCPUSTATE_32BIT_HACK = 0x7fffffff
|
---|
72 | } VMCPUSTATE;
|
---|
73 |
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Per virtual CPU data.
|
---|
77 | */
|
---|
78 | typedef struct VMCPU
|
---|
79 | {
|
---|
80 | /** Per CPU forced action.
|
---|
81 | * See the VMCPU_FF_* \#defines. Updated atomically. */
|
---|
82 | uint32_t volatile fForcedActions;
|
---|
83 | /** The CPU state. */
|
---|
84 | VMCPUSTATE volatile enmState;
|
---|
85 |
|
---|
86 | /** Ring-3 Host Context VM Pointer. */
|
---|
87 | PVMR3 pVMR3;
|
---|
88 | /** Ring-0 Host Context VM Pointer. */
|
---|
89 | PVMR0 pVMR0;
|
---|
90 | /** Raw-mode Context VM Pointer. */
|
---|
91 | PVMRC pVMRC;
|
---|
92 | /** The CPU ID.
|
---|
93 | * This is the index into the VM::aCpus array. */
|
---|
94 | VMCPUID idCpu;
|
---|
95 | /** The ring-3 thread handle of the emulation thread for this CPU.
|
---|
96 | * @todo Use the VM_IS_EMT() macro to check if executing in EMT? */
|
---|
97 | RTTHREAD hThreadR3;
|
---|
98 | /** The native ring-3 handle. */
|
---|
99 | RTNATIVETHREAD hNativeThreadR3;
|
---|
100 | /** The native ring-0 handle. */
|
---|
101 | RTNATIVETHREAD hNativeThreadR0;
|
---|
102 |
|
---|
103 | /** Align the next bit on a 64-byte boundrary. */
|
---|
104 | uint32_t au32Alignment[HC_ARCH_BITS == 32 ? 7 : 2];
|
---|
105 |
|
---|
106 | /** CPUM part. */
|
---|
107 | union
|
---|
108 | {
|
---|
109 | #if 0 /*def ___CPUMInternal_h */
|
---|
110 | struct VMCPUCPUM s;
|
---|
111 | #endif
|
---|
112 | char padding[64];
|
---|
113 | } cpum;
|
---|
114 | } VMCPU;
|
---|
115 |
|
---|
116 |
|
---|
117 | /** The name of the Guest Context VMM Core module. */
|
---|
118 | #define VMMGC_MAIN_MODULE_NAME "VMMGC.gc"
|
---|
119 | /** The name of the Ring 0 Context VMM Core module. */
|
---|
120 | #define VMMR0_MAIN_MODULE_NAME "VMMR0.r0"
|
---|
121 |
|
---|
122 | /** VM Forced Action Flags.
|
---|
123 | *
|
---|
124 | * Use the VM_FF_SET() and VM_FF_CLEAR() macros to change the force
|
---|
125 | * action mask of a VM.
|
---|
126 | *
|
---|
127 | * @{
|
---|
128 | */
|
---|
129 | /** This action forces the VM to service check and pending interrups on the APIC. */
|
---|
130 | #define VM_FF_INTERRUPT_APIC RT_BIT_32(0)
|
---|
131 | /** This action forces the VM to service check and pending interrups on the PIC. */
|
---|
132 | #define VM_FF_INTERRUPT_PIC RT_BIT_32(1)
|
---|
133 | /** This action forces the VM to schedule and run pending timer (TM). */
|
---|
134 | #define VM_FF_TIMER RT_BIT_32(2)
|
---|
135 | /** PDM Queues are pending. */
|
---|
136 | #define VM_FF_PDM_QUEUES RT_BIT_32(3)
|
---|
137 | /** PDM DMA transfers are pending. */
|
---|
138 | #define VM_FF_PDM_DMA RT_BIT_32(4)
|
---|
139 | /** PDM critical section unlocking is pending, process promptly upon return to R3. */
|
---|
140 | #define VM_FF_PDM_CRITSECT RT_BIT_32(5)
|
---|
141 |
|
---|
142 | /** This action forces the VM to call DBGF so DBGF can service debugger
|
---|
143 | * requests in the emulation thread.
|
---|
144 | * This action flag stays asserted till DBGF clears it.*/
|
---|
145 | #define VM_FF_DBGF RT_BIT_32(8)
|
---|
146 | /** This action forces the VM to service pending requests from other
|
---|
147 | * thread or requests which must be executed in another context. */
|
---|
148 | #define VM_FF_REQUEST RT_BIT_32(9)
|
---|
149 | /** Terminate the VM immediately. */
|
---|
150 | #define VM_FF_TERMINATE RT_BIT_32(10)
|
---|
151 | /** Reset the VM. (postponed) */
|
---|
152 | #define VM_FF_RESET RT_BIT_32(11)
|
---|
153 |
|
---|
154 | /** This action forces the VM to resync the page tables before going
|
---|
155 | * back to execute guest code. (GLOBAL FLUSH) */
|
---|
156 | #define VM_FF_PGM_SYNC_CR3 RT_BIT_32(16)
|
---|
157 | /** Same as VM_FF_PGM_SYNC_CR3 except that global pages can be skipped.
|
---|
158 | * (NON-GLOBAL FLUSH) */
|
---|
159 | #define VM_FF_PGM_SYNC_CR3_NON_GLOBAL RT_BIT_32(17)
|
---|
160 | /** PGM needs to allocate handy pages. */
|
---|
161 | #define VM_FF_PGM_NEED_HANDY_PAGES RT_BIT_32(18)
|
---|
162 | /** Check the interupt and trap gates */
|
---|
163 | #define VM_FF_TRPM_SYNC_IDT RT_BIT_32(19)
|
---|
164 | /** Check Guest's TSS ring 0 stack */
|
---|
165 | #define VM_FF_SELM_SYNC_TSS RT_BIT_32(20)
|
---|
166 | /** Check Guest's GDT table */
|
---|
167 | #define VM_FF_SELM_SYNC_GDT RT_BIT_32(21)
|
---|
168 | /** Check Guest's LDT table */
|
---|
169 | #define VM_FF_SELM_SYNC_LDT RT_BIT_32(22)
|
---|
170 | /** Inhibit interrupts pending. See EMGetInhibitInterruptsPC(). */
|
---|
171 | #define VM_FF_INHIBIT_INTERRUPTS RT_BIT_32(23)
|
---|
172 |
|
---|
173 | /** CSAM needs to scan the page that's being executed */
|
---|
174 | #define VM_FF_CSAM_SCAN_PAGE RT_BIT_32(24)
|
---|
175 | /** CSAM needs to do some homework. */
|
---|
176 | #define VM_FF_CSAM_PENDING_ACTION RT_BIT_32(25)
|
---|
177 |
|
---|
178 | /** Force return to Ring-3. */
|
---|
179 | #define VM_FF_TO_R3 RT_BIT_32(28)
|
---|
180 |
|
---|
181 | /** REM needs to be informed about handler changes. */
|
---|
182 | #define VM_FF_REM_HANDLER_NOTIFY RT_BIT_32(29)
|
---|
183 |
|
---|
184 | /** Suspend the VM - debug only. */
|
---|
185 | #define VM_FF_DEBUG_SUSPEND RT_BIT_32(31)
|
---|
186 |
|
---|
187 | /** Externally forced actions. Used to quit the idle/wait loop. */
|
---|
188 | #define VM_FF_EXTERNAL_SUSPENDED_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_REQUEST)
|
---|
189 | /** Externally forced actions. Used to quit the idle/wait loop. */
|
---|
190 | #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)
|
---|
191 | /** High priority pre-execution actions. */
|
---|
192 | #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 \
|
---|
193 | | 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)
|
---|
194 | /** High priority pre raw-mode execution mask. */
|
---|
195 | #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 \
|
---|
196 | | VM_FF_INHIBIT_INTERRUPTS)
|
---|
197 | /** High priority post-execution actions. */
|
---|
198 | #define VM_FF_HIGH_PRIORITY_POST_MASK (VM_FF_PDM_CRITSECT | VM_FF_CSAM_PENDING_ACTION)
|
---|
199 | /** Normal priority post-execution actions. */
|
---|
200 | #define VM_FF_NORMAL_PRIORITY_POST_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_RESET | VM_FF_CSAM_SCAN_PAGE)
|
---|
201 | /** Normal priority actions. */
|
---|
202 | #define VM_FF_NORMAL_PRIORITY_MASK (VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_REM_HANDLER_NOTIFY)
|
---|
203 | /** Flags to check before resuming guest execution. */
|
---|
204 | #define VM_FF_RESUME_GUEST_MASK (VM_FF_TO_R3)
|
---|
205 | /** All the forced flags. */
|
---|
206 | #define VM_FF_ALL_MASK (~0U)
|
---|
207 | /** All the forced flags. */
|
---|
208 | #define VM_FF_ALL_BUT_RAW_MASK (~(VM_FF_HIGH_PRIORITY_PRE_RAW_MASK | VM_FF_CSAM_PENDING_ACTION | VM_FF_PDM_CRITSECT))
|
---|
209 |
|
---|
210 | /** @} */
|
---|
211 |
|
---|
212 | /** @def VM_FF_SET
|
---|
213 | * Sets a force action flag.
|
---|
214 | *
|
---|
215 | * @param pVM VM Handle.
|
---|
216 | * @param fFlag The flag to set.
|
---|
217 | */
|
---|
218 | #if 1
|
---|
219 | # define VM_FF_SET(pVM, fFlag) ASMAtomicOrU32(&(pVM)->fForcedActions, (fFlag))
|
---|
220 | #else
|
---|
221 | # define VM_FF_SET(pVM, fFlag) \
|
---|
222 | do { ASMAtomicOrU32(&(pVM)->fForcedActions, (fFlag)); \
|
---|
223 | RTLogPrintf("VM_FF_SET : %08x %s - %s(%d) %s\n", (pVM)->fForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
|
---|
224 | } while (0)
|
---|
225 | #endif
|
---|
226 |
|
---|
227 | /** @def VMCPU_FF_SET
|
---|
228 | * Sets a force action flag for given VCPU.
|
---|
229 | *
|
---|
230 | * @param pVM VM Handle.
|
---|
231 | * @param idCpu Virtual CPU ID.
|
---|
232 | * @param fFlag The flag to set.
|
---|
233 | */
|
---|
234 | #ifdef VBOX_WITH_SMP_GUESTS
|
---|
235 | # define VMCPU_FF_SET(pVM, idCpu, fFlag) ASMAtomicOrU32(&(pVM)->aCpus[idCpu].fForcedActions, (fFlag))
|
---|
236 | #else
|
---|
237 | # define VMCPU_FF_SET(pVM, idCpu, fFlag) VM_FF_SET(pVM, fFlag)
|
---|
238 | #endif
|
---|
239 |
|
---|
240 | /** @def VM_FF_CLEAR
|
---|
241 | * Clears a force action flag.
|
---|
242 | *
|
---|
243 | * @param pVM VM Handle.
|
---|
244 | * @param fFlag The flag to clear.
|
---|
245 | */
|
---|
246 | #if 1
|
---|
247 | # define VM_FF_CLEAR(pVM, fFlag) ASMAtomicAndU32(&(pVM)->fForcedActions, ~(fFlag))
|
---|
248 | #else
|
---|
249 | # define VM_FF_CLEAR(pVM, fFlag) \
|
---|
250 | do { ASMAtomicAndU32(&(pVM)->fForcedActions, ~(fFlag)); \
|
---|
251 | RTLogPrintf("VM_FF_CLEAR: %08x %s - %s(%d) %s\n", (pVM)->fForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
|
---|
252 | } while (0)
|
---|
253 | #endif
|
---|
254 |
|
---|
255 | /** @def VMCPU_FF_CLEAR
|
---|
256 | * Clears a force action flag for given VCPU.
|
---|
257 | *
|
---|
258 | * @param pVM VM Handle.
|
---|
259 | * @param idCpu Virtual CPU ID.
|
---|
260 | * @param fFlag The flag to clear.
|
---|
261 | */
|
---|
262 | #ifdef VBOX_WITH_SMP_GUESTS
|
---|
263 | # define VMCPU_FF_CLEAR(pVM, idCpu, fFlag) ASMAtomicAndU32(&(pVM)->aCpus[idCpu].fForcedActions, ~(fFlag))
|
---|
264 | #else
|
---|
265 | # define VMCPU_FF_CLEAR(pVM, idCpu, fFlag) VM_FF_CLEAR(pVM, fFlag)
|
---|
266 | #endif
|
---|
267 |
|
---|
268 | /** @def VM_FF_ISSET
|
---|
269 | * Checks if a force action flag is set.
|
---|
270 | *
|
---|
271 | * @param pVM VM Handle.
|
---|
272 | * @param fFlag The flag to check.
|
---|
273 | */
|
---|
274 | #define VM_FF_ISSET(pVM, fFlag) (((pVM)->fForcedActions & (fFlag)) == (fFlag))
|
---|
275 |
|
---|
276 | /** @def VMCPU_FF_ISSET
|
---|
277 | * Checks if a force action flag is set for given VCPU.
|
---|
278 | *
|
---|
279 | * @param pVM VM Handle.
|
---|
280 | * @param idCpu Virtual CPU ID.
|
---|
281 | * @param fFlag The flag to check.
|
---|
282 | */
|
---|
283 | #ifdef VBOX_WITH_SMP_GUESTS
|
---|
284 | # define VMCPU_FF_ISSET(pVM, idCpu, fFlag) (((pVM)->aCpus[idCpu].fForcedActions & (fFlag)) == (fFlag))
|
---|
285 | #else
|
---|
286 | # define VMCPU_FF_ISSET(pVM, idCpu, fFlag) VM_FF_ISSET(pVM, fFlag)
|
---|
287 | #endif
|
---|
288 |
|
---|
289 | /** @def VM_FF_ISPENDING
|
---|
290 | * Checks if one or more force action in the specified set is pending.
|
---|
291 | *
|
---|
292 | * @param pVM VM Handle.
|
---|
293 | * @param fFlags The flags to check for.
|
---|
294 | */
|
---|
295 | #define VM_FF_ISPENDING(pVM, fFlags) ((pVM)->fForcedActions & (fFlags))
|
---|
296 |
|
---|
297 | /** @def VMCPU_FF_ISPENDING
|
---|
298 | * Checks if one or more force action in the specified set is pending for given VCPU.
|
---|
299 | *
|
---|
300 | * @param pVM VM Handle.
|
---|
301 | * @param idCpu Virtual CPU ID.
|
---|
302 | * @param fFlags The flags to check for.
|
---|
303 | */
|
---|
304 | #ifdef VBOX_WITH_SMP_GUESTS
|
---|
305 | # define VMCPU_FF_ISPENDING(pVM, idCpu, fFlags) ((pVM)->aCpus[idCpu].fForcedActions & (fFlags))
|
---|
306 | #else
|
---|
307 | # define VMCPU_FF_ISPENDING(pVM, idCpu, fFlags) VM_FF_ISPENDING(pVM, fFlags)
|
---|
308 | #endif
|
---|
309 |
|
---|
310 | /** @def VM_IS_EMT
|
---|
311 | * Checks if the current thread is the emulation thread (EMT).
|
---|
312 | *
|
---|
313 | * @remark The ring-0 variation will need attention if we expand the ring-0
|
---|
314 | * code to let threads other than EMT mess around with the VM.
|
---|
315 | */
|
---|
316 | #ifdef IN_GC
|
---|
317 | # define VM_IS_EMT(pVM) true
|
---|
318 | #elif defined(IN_RING0)
|
---|
319 | # define VM_IS_EMT(pVM) true
|
---|
320 | #else
|
---|
321 | /** @todo need to rework this macro for the case of multiple emulation threads for SMP */
|
---|
322 | # define VM_IS_EMT(pVM) ((pVM)->NativeThreadEMT == RTThreadNativeSelf())
|
---|
323 | #endif
|
---|
324 |
|
---|
325 | /** @def VM_ASSERT_EMT
|
---|
326 | * Asserts that the current thread IS the emulation thread (EMT).
|
---|
327 | */
|
---|
328 | #ifdef IN_GC
|
---|
329 | # define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
|
---|
330 | #elif defined(IN_RING0)
|
---|
331 | # define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
|
---|
332 | #else
|
---|
333 | # define VM_ASSERT_EMT(pVM) \
|
---|
334 | AssertMsg(VM_IS_EMT(pVM), \
|
---|
335 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), pVM->NativeThreadEMT))
|
---|
336 | #endif
|
---|
337 |
|
---|
338 | /** @def VM_ASSERT_EMT_RETURN
|
---|
339 | * Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
|
---|
340 | */
|
---|
341 | #ifdef IN_GC
|
---|
342 | # define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
|
---|
343 | #elif defined(IN_RING0)
|
---|
344 | # define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
|
---|
345 | #else
|
---|
346 | # define VM_ASSERT_EMT_RETURN(pVM, rc) \
|
---|
347 | AssertMsgReturn(VM_IS_EMT(pVM), \
|
---|
348 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), pVM->NativeThreadEMT), \
|
---|
349 | (rc))
|
---|
350 | #endif
|
---|
351 |
|
---|
352 | /**
|
---|
353 | * Asserts that the current thread is NOT the emulation thread.
|
---|
354 | */
|
---|
355 | #define VM_ASSERT_OTHER_THREAD(pVM) \
|
---|
356 | AssertMsg(!VM_IS_EMT(pVM), ("Not other thread!!\n"))
|
---|
357 |
|
---|
358 |
|
---|
359 | /** @def VM_ASSERT_STATE_RETURN
|
---|
360 | * Asserts a certain VM state.
|
---|
361 | */
|
---|
362 | #define VM_ASSERT_STATE(pVM, _enmState) \
|
---|
363 | AssertMsg((pVM)->enmVMState == (_enmState), \
|
---|
364 | ("state %s, expected %s\n", VMGetStateName(pVM->enmVMState), VMGetStateName(_enmState)))
|
---|
365 |
|
---|
366 | /** @def VM_ASSERT_STATE_RETURN
|
---|
367 | * Asserts a certain VM state and returns if it doesn't match.
|
---|
368 | */
|
---|
369 | #define VM_ASSERT_STATE_RETURN(pVM, _enmState, rc) \
|
---|
370 | AssertMsgReturn((pVM)->enmVMState == (_enmState), \
|
---|
371 | ("state %s, expected %s\n", VMGetStateName(pVM->enmVMState), VMGetStateName(_enmState)), \
|
---|
372 | (rc))
|
---|
373 |
|
---|
374 |
|
---|
375 |
|
---|
376 |
|
---|
377 | /** This is the VM structure.
|
---|
378 | *
|
---|
379 | * It contains (nearly?) all the VM data which have to be available in all
|
---|
380 | * contexts. Even if it contains all the data the idea is to use APIs not
|
---|
381 | * to modify all the members all around the place. Therefore we make use of
|
---|
382 | * unions to hide everything which isn't local to the current source module.
|
---|
383 | * This means we'll have to pay a little bit of attention when adding new
|
---|
384 | * members to structures in the unions and make sure to keep the padding sizes
|
---|
385 | * up to date.
|
---|
386 | *
|
---|
387 | * Run tstVMStructSize after update!
|
---|
388 | */
|
---|
389 | typedef struct VM
|
---|
390 | {
|
---|
391 | /** The state of the VM.
|
---|
392 | * This field is read only to everyone except the VM and EM. */
|
---|
393 | VMSTATE enmVMState;
|
---|
394 | /** Forced action flags.
|
---|
395 | * See the VM_FF_* \#defines. Updated atomically.
|
---|
396 | */
|
---|
397 | volatile uint32_t fForcedActions;
|
---|
398 | /** Pointer to the array of page descriptors for the VM structure allocation. */
|
---|
399 | R3PTRTYPE(PSUPPAGE) paVMPagesR3;
|
---|
400 | /** Session handle. For use when calling SUPR0 APIs. */
|
---|
401 | PSUPDRVSESSION pSession;
|
---|
402 | /** Pointer to the ring-3 VM structure. */
|
---|
403 | PUVM pUVM;
|
---|
404 | /** Ring-3 Host Context VM Pointer. */
|
---|
405 | R3PTRTYPE(struct VM *) pVMR3;
|
---|
406 | /** Ring-0 Host Context VM Pointer. */
|
---|
407 | R0PTRTYPE(struct VM *) pVMR0;
|
---|
408 | /** Raw-mode Context VM Pointer.
|
---|
409 | * @deprecated Use VM::pVMRC. */
|
---|
410 | RCPTRTYPE(struct VM *) pVMGC;
|
---|
411 | /** Raw-mode Context VM Pointer. */
|
---|
412 | RCPTRTYPE(struct VM *) pVMRC;
|
---|
413 |
|
---|
414 | /** The GVM VM handle. Only the GVM should modify this field. */
|
---|
415 | uint32_t hSelf;
|
---|
416 | /** Number of virtual CPUs. */
|
---|
417 | uint32_t cCPUs;
|
---|
418 | /** Reserved; alignment. */
|
---|
419 | uint32_t u32Reserved[7];
|
---|
420 |
|
---|
421 | /** @name Public VMM Switcher APIs
|
---|
422 | * @{ */
|
---|
423 | /**
|
---|
424 | * Assembly switch entry point for returning to host context.
|
---|
425 | * This function will clean up the stack frame.
|
---|
426 | *
|
---|
427 | * @param eax The return code, register.
|
---|
428 | * @param Ctx The guest core context.
|
---|
429 | * @remark Assume interrupts disabled.
|
---|
430 | */
|
---|
431 | RTGCPTR32 pfnVMMGCGuestToHostAsmGuestCtx/*(int32_t eax, CPUMCTXCORE Ctx)*/;
|
---|
432 |
|
---|
433 | /**
|
---|
434 | * Assembly switch entry point for returning to host context.
|
---|
435 | *
|
---|
436 | * This is an alternative entry point which we'll be using when the we have the
|
---|
437 | * hypervisor context and need to save that before going to the host.
|
---|
438 | *
|
---|
439 | * This is typically useful when abandoning the hypervisor because of a trap
|
---|
440 | * and want the trap state to be saved.
|
---|
441 | *
|
---|
442 | * @param eax The return code, register.
|
---|
443 | * @param ecx Pointer to the hypervisor core context, register.
|
---|
444 | * @remark Assume interrupts disabled.
|
---|
445 | */
|
---|
446 | RTGCPTR32 pfnVMMGCGuestToHostAsmHyperCtx/*(int32_t eax, PCPUMCTXCORE ecx)*/;
|
---|
447 |
|
---|
448 | /**
|
---|
449 | * Assembly switch entry point for returning to host context.
|
---|
450 | *
|
---|
451 | * This is an alternative to the two *Ctx APIs and implies that the context has already
|
---|
452 | * been saved, or that it's just a brief return to HC and that the caller intends to resume
|
---|
453 | * whatever it is doing upon 'return' from this call.
|
---|
454 | *
|
---|
455 | * @param eax The return code, register.
|
---|
456 | * @remark Assume interrupts disabled.
|
---|
457 | */
|
---|
458 | RTGCPTR32 pfnVMMGCGuestToHostAsm/*(int32_t eax)*/;
|
---|
459 | /** @} */
|
---|
460 |
|
---|
461 |
|
---|
462 | /** @name Various VM data owned by VM.
|
---|
463 | * @{ */
|
---|
464 | /** The thread handle of the emulation thread.
|
---|
465 | * Use the VM_IS_EMT() macro to check if executing in EMT. */
|
---|
466 | RTTHREAD ThreadEMT;
|
---|
467 | /** The native handle of ThreadEMT. Getting the native handle
|
---|
468 | * is generally faster than getting the IPRT one (except on OS/2 :-). */
|
---|
469 | RTNATIVETHREAD NativeThreadEMT;
|
---|
470 | /** @} */
|
---|
471 |
|
---|
472 |
|
---|
473 | /** @name Various items that are frequently accessed.
|
---|
474 | * @{ */
|
---|
475 | /** Raw ring-3 indicator. */
|
---|
476 | bool fRawR3Enabled;
|
---|
477 | /** Raw ring-0 indicator. */
|
---|
478 | bool fRawR0Enabled;
|
---|
479 | /** PATM enabled flag.
|
---|
480 | * This is placed here for performance reasons. */
|
---|
481 | bool fPATMEnabled;
|
---|
482 | /** CSAM enabled flag.
|
---|
483 | * This is placed here for performance reasons. */
|
---|
484 | bool fCSAMEnabled;
|
---|
485 |
|
---|
486 | /** Hardware VM support is available and enabled.
|
---|
487 | * This is placed here for performance reasons. */
|
---|
488 | bool fHWACCMEnabled;
|
---|
489 | /** @} */
|
---|
490 |
|
---|
491 |
|
---|
492 | /* padding to make gnuc put the StatQemuToGC where msc does. */
|
---|
493 | #if HC_ARCH_BITS == 32
|
---|
494 | uint32_t padding0;
|
---|
495 | #endif
|
---|
496 |
|
---|
497 | /** Profiling the total time from Qemu to GC. */
|
---|
498 | STAMPROFILEADV StatTotalQemuToGC;
|
---|
499 | /** Profiling the total time from GC to Qemu. */
|
---|
500 | STAMPROFILEADV StatTotalGCToQemu;
|
---|
501 | /** Profiling the total time spent in GC. */
|
---|
502 | STAMPROFILEADV StatTotalInGC;
|
---|
503 | /** Profiling the total time spent not in Qemu. */
|
---|
504 | STAMPROFILEADV StatTotalInQemu;
|
---|
505 | /** Profiling the VMMSwitcher code for going to GC. */
|
---|
506 | STAMPROFILEADV StatSwitcherToGC;
|
---|
507 | /** Profiling the VMMSwitcher code for going to HC. */
|
---|
508 | STAMPROFILEADV StatSwitcherToHC;
|
---|
509 | STAMPROFILEADV StatSwitcherSaveRegs;
|
---|
510 | STAMPROFILEADV StatSwitcherSysEnter;
|
---|
511 | STAMPROFILEADV StatSwitcherDebug;
|
---|
512 | STAMPROFILEADV StatSwitcherCR0;
|
---|
513 | STAMPROFILEADV StatSwitcherCR4;
|
---|
514 | STAMPROFILEADV StatSwitcherJmpCR3;
|
---|
515 | STAMPROFILEADV StatSwitcherRstrRegs;
|
---|
516 | STAMPROFILEADV StatSwitcherLgdt;
|
---|
517 | STAMPROFILEADV StatSwitcherLidt;
|
---|
518 | STAMPROFILEADV StatSwitcherLldt;
|
---|
519 | STAMPROFILEADV StatSwitcherTSS;
|
---|
520 |
|
---|
521 | /** @todo Realign everything on 64 byte boundraries to better match the
|
---|
522 | * cache-line size. */
|
---|
523 | /* padding - the unions must be aligned on 32 bytes boundraries. */
|
---|
524 | uint32_t padding[HC_ARCH_BITS == 32 ? 4+8 : 6];
|
---|
525 |
|
---|
526 | /** CPUM part. */
|
---|
527 | union
|
---|
528 | {
|
---|
529 | #ifdef ___CPUMInternal_h
|
---|
530 | struct CPUM s;
|
---|
531 | #endif
|
---|
532 | char padding[4416]; /* multiple of 32 */
|
---|
533 | } cpum;
|
---|
534 |
|
---|
535 | /** VMM part. */
|
---|
536 | union
|
---|
537 | {
|
---|
538 | #ifdef ___VMMInternal_h
|
---|
539 | struct VMM s;
|
---|
540 | #endif
|
---|
541 | char padding[1536]; /* multiple of 32 */
|
---|
542 | } vmm;
|
---|
543 |
|
---|
544 | /** PGM part. */
|
---|
545 | union
|
---|
546 | {
|
---|
547 | #ifdef ___PGMInternal_h
|
---|
548 | struct PGM s;
|
---|
549 | #endif
|
---|
550 | char padding[50*1024]; /* multiple of 32 */
|
---|
551 | } pgm;
|
---|
552 |
|
---|
553 | /** HWACCM part. */
|
---|
554 | union
|
---|
555 | {
|
---|
556 | #ifdef ___HWACCMInternal_h
|
---|
557 | struct HWACCM s;
|
---|
558 | #endif
|
---|
559 | char padding[1536]; /* multiple of 32 */
|
---|
560 | } hwaccm;
|
---|
561 |
|
---|
562 | /** TRPM part. */
|
---|
563 | union
|
---|
564 | {
|
---|
565 | #ifdef ___TRPMInternal_h
|
---|
566 | struct TRPM s;
|
---|
567 | #endif
|
---|
568 | char padding[5344]; /* multiple of 32 */
|
---|
569 | } trpm;
|
---|
570 |
|
---|
571 | /** SELM part. */
|
---|
572 | union
|
---|
573 | {
|
---|
574 | #ifdef ___SELMInternal_h
|
---|
575 | struct SELM s;
|
---|
576 | #endif
|
---|
577 | char padding[544]; /* multiple of 32 */
|
---|
578 | } selm;
|
---|
579 |
|
---|
580 | /** MM part. */
|
---|
581 | union
|
---|
582 | {
|
---|
583 | #ifdef ___MMInternal_h
|
---|
584 | struct MM s;
|
---|
585 | #endif
|
---|
586 | char padding[192]; /* multiple of 32 */
|
---|
587 | } mm;
|
---|
588 |
|
---|
589 | /** CFGM part. */
|
---|
590 | union
|
---|
591 | {
|
---|
592 | #ifdef ___CFGMInternal_h
|
---|
593 | struct CFGM s;
|
---|
594 | #endif
|
---|
595 | char padding[32]; /* multiple of 32 */
|
---|
596 | } cfgm;
|
---|
597 |
|
---|
598 | /** PDM part. */
|
---|
599 | union
|
---|
600 | {
|
---|
601 | #ifdef ___PDMInternal_h
|
---|
602 | struct PDM s;
|
---|
603 | #endif
|
---|
604 | char padding[1824]; /* multiple of 32 */
|
---|
605 | } pdm;
|
---|
606 |
|
---|
607 | /** IOM part. */
|
---|
608 | union
|
---|
609 | {
|
---|
610 | #ifdef ___IOMInternal_h
|
---|
611 | struct IOM s;
|
---|
612 | #endif
|
---|
613 | char padding[4544]; /* multiple of 32 */
|
---|
614 | } iom;
|
---|
615 |
|
---|
616 | /** PATM part. */
|
---|
617 | union
|
---|
618 | {
|
---|
619 | #ifdef ___PATMInternal_h
|
---|
620 | struct PATM s;
|
---|
621 | #endif
|
---|
622 | char padding[768]; /* multiple of 32 */
|
---|
623 | } patm;
|
---|
624 |
|
---|
625 | /** CSAM part. */
|
---|
626 | union
|
---|
627 | {
|
---|
628 | #ifdef ___CSAMInternal_h
|
---|
629 | struct CSAM s;
|
---|
630 | #endif
|
---|
631 | char padding[3328]; /* multiple of 32 */
|
---|
632 | } csam;
|
---|
633 |
|
---|
634 | /** EM part. */
|
---|
635 | union
|
---|
636 | {
|
---|
637 | #ifdef ___EMInternal_h
|
---|
638 | struct EM s;
|
---|
639 | #endif
|
---|
640 | char padding[1344]; /* multiple of 32 */
|
---|
641 | } em;
|
---|
642 |
|
---|
643 | /** TM part. */
|
---|
644 | union
|
---|
645 | {
|
---|
646 | #ifdef ___TMInternal_h
|
---|
647 | struct TM s;
|
---|
648 | #endif
|
---|
649 | char padding[1344]; /* multiple of 32 */
|
---|
650 | } tm;
|
---|
651 |
|
---|
652 | /** DBGF part. */
|
---|
653 | union
|
---|
654 | {
|
---|
655 | #ifdef ___DBGFInternal_h
|
---|
656 | struct DBGF s;
|
---|
657 | #endif
|
---|
658 | char padding[2368]; /* multiple of 32 */
|
---|
659 | } dbgf;
|
---|
660 |
|
---|
661 | /** SSM part. */
|
---|
662 | union
|
---|
663 | {
|
---|
664 | #ifdef ___SSMInternal_h
|
---|
665 | struct SSM s;
|
---|
666 | #endif
|
---|
667 | char padding[32]; /* multiple of 32 */
|
---|
668 | } ssm;
|
---|
669 |
|
---|
670 | /** VM part. */
|
---|
671 | union
|
---|
672 | {
|
---|
673 | #ifdef ___VMInternal_h
|
---|
674 | struct VMINT s;
|
---|
675 | #endif
|
---|
676 | char padding[768]; /* multiple of 32 */
|
---|
677 | } vm;
|
---|
678 |
|
---|
679 | /** REM part. */
|
---|
680 | union
|
---|
681 | {
|
---|
682 | #ifdef ___REMInternal_h
|
---|
683 | struct REM s;
|
---|
684 | #endif
|
---|
685 |
|
---|
686 | #ifdef VBOX_WITH_NEW_RECOMPILER
|
---|
687 | /* Must be multiple of 32 and coherent with REM_ENV_SIZE from REMInternal.h */
|
---|
688 | #if GC_ARCH_BITS == 32
|
---|
689 | #define VM_REM_SIZE (HC_ARCH_BITS == 32 ? 0xff00 : 0xff00)
|
---|
690 | #else
|
---|
691 | #define VM_REM_SIZE (HC_ARCH_BITS == 32 ? 0xff00 : 0xff00)
|
---|
692 | #endif
|
---|
693 | #else
|
---|
694 | #if GC_ARCH_BITS == 32
|
---|
695 | #define VM_REM_SIZE (HC_ARCH_BITS == 32 ? 0x6f00 : 0xbf00)
|
---|
696 | #else
|
---|
697 | #define VM_REM_SIZE (HC_ARCH_BITS == 32 ? 0x9f00 : 0xdf00)
|
---|
698 | #endif
|
---|
699 | #endif // VBOX_WITH_NEW_RECOMILER
|
---|
700 | char padding[ VM_REM_SIZE]; /* multiple of 32 */
|
---|
701 | } rem;
|
---|
702 |
|
---|
703 | /** Padding for aligning the cpu array on a 64 byte boundrary. */
|
---|
704 | uint32_t u32Reserved2[8];
|
---|
705 |
|
---|
706 | /**
|
---|
707 | * Per virtual CPU state.
|
---|
708 | */
|
---|
709 | VMCPU aCpus[1];
|
---|
710 | } VM;
|
---|
711 |
|
---|
712 | /** Pointer to a VM. */
|
---|
713 | #ifndef ___VBox_types_h
|
---|
714 | typedef struct VM *PVM;
|
---|
715 | #endif
|
---|
716 |
|
---|
717 |
|
---|
718 | #ifdef IN_GC
|
---|
719 | __BEGIN_DECLS
|
---|
720 |
|
---|
721 | /** The VM structure.
|
---|
722 | * This is imported from the VMMGCBuiltin module, i.e. it's a one
|
---|
723 | * of those magic globals which we should avoid using.
|
---|
724 | */
|
---|
725 | extern DECLIMPORT(VM) g_VM;
|
---|
726 |
|
---|
727 | __END_DECLS
|
---|
728 | #endif
|
---|
729 |
|
---|
730 | /** @} */
|
---|
731 |
|
---|
732 | #endif
|
---|
733 |
|
---|