1 | /** @file
|
---|
2 | * VM - The Virtual Machine, data.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___VBox_vmm_vm_h
|
---|
27 | #define ___VBox_vmm_vm_h
|
---|
28 |
|
---|
29 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
30 | # include <VBox/types.h>
|
---|
31 | # include <VBox/vmm/cpum.h>
|
---|
32 | # include <VBox/vmm/stam.h>
|
---|
33 | # include <VBox/vmm/vmapi.h>
|
---|
34 | # include <VBox/vmm/vmm.h>
|
---|
35 | # include <VBox/sup.h>
|
---|
36 | #else
|
---|
37 | # pragma D depends_on library vbox-types.d
|
---|
38 | # pragma D depends_on library CPUMInternal.d
|
---|
39 | # define ___CPUMInternal_h
|
---|
40 | #endif
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 | /** @defgroup grp_vm The Virtual Machine
|
---|
45 | * @{
|
---|
46 | */
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * The state of a Virtual CPU.
|
---|
50 | *
|
---|
51 | * The basic state indicated here is whether the CPU has been started or not. In
|
---|
52 | * addition, there are sub-states when started for assisting scheduling (GVMM
|
---|
53 | * mostly).
|
---|
54 | *
|
---|
55 | * The transition out of the STOPPED state is done by a vmR3PowerOn.
|
---|
56 | * The transition back to the STOPPED state is done by vmR3PowerOff.
|
---|
57 | *
|
---|
58 | * (Alternatively we could let vmR3PowerOn start CPU 0 only and let the SPIP
|
---|
59 | * handling switch on the other CPUs. Then vmR3Reset would stop all but CPU 0.)
|
---|
60 | */
|
---|
61 | typedef enum VMCPUSTATE
|
---|
62 | {
|
---|
63 | /** The customary invalid zero. */
|
---|
64 | VMCPUSTATE_INVALID = 0,
|
---|
65 |
|
---|
66 | /** Virtual CPU has not yet been started. */
|
---|
67 | VMCPUSTATE_STOPPED,
|
---|
68 |
|
---|
69 | /** CPU started. */
|
---|
70 | VMCPUSTATE_STARTED,
|
---|
71 | /** Executing guest code and can be poked. */
|
---|
72 | VMCPUSTATE_STARTED_EXEC,
|
---|
73 | /** Executing guest code in the recompiler. */
|
---|
74 | VMCPUSTATE_STARTED_EXEC_REM,
|
---|
75 | /** Halted. */
|
---|
76 | VMCPUSTATE_STARTED_HALTED,
|
---|
77 |
|
---|
78 | /** The end of valid virtual CPU states. */
|
---|
79 | VMCPUSTATE_END,
|
---|
80 |
|
---|
81 | /** Ensure 32-bit type. */
|
---|
82 | VMCPUSTATE_32BIT_HACK = 0x7fffffff
|
---|
83 | } VMCPUSTATE;
|
---|
84 |
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Per virtual CPU data.
|
---|
88 | */
|
---|
89 | typedef struct VMCPU
|
---|
90 | {
|
---|
91 | /** Per CPU forced action.
|
---|
92 | * See the VMCPU_FF_* \#defines. Updated atomically. */
|
---|
93 | uint32_t volatile fLocalForcedActions; /* 0 */
|
---|
94 | /** The CPU state. */
|
---|
95 | VMCPUSTATE volatile enmState; /* 4 */
|
---|
96 |
|
---|
97 | /** Pointer to the ring-3 UVMCPU structure. */
|
---|
98 | PUVMCPU pUVCpu; /* 8 */
|
---|
99 | /** Ring-3 Host Context VM Pointer. */
|
---|
100 | PVMR3 pVMR3; /* 16 / 12 */
|
---|
101 | /** Ring-0 Host Context VM Pointer. */
|
---|
102 | PVMR0 pVMR0; /* 24 / 16 */
|
---|
103 | /** Raw-mode Context VM Pointer. */
|
---|
104 | PVMRC pVMRC; /* 32 / 20 */
|
---|
105 | /** The CPU ID.
|
---|
106 | * This is the index into the VM::aCpu array. */
|
---|
107 | VMCPUID idCpu; /* 36 / 24 */
|
---|
108 | /** The native thread handle. */
|
---|
109 | RTNATIVETHREAD hNativeThread; /* 40 / 28 */
|
---|
110 | /** The native R0 thread handle. (different from the R3 handle!) */
|
---|
111 | RTNATIVETHREAD hNativeThreadR0; /* 48 / 32 */
|
---|
112 | /** Which host CPU ID is this EMT running on.
|
---|
113 | * Only valid when in RC or HMR0 with scheduling disabled. */
|
---|
114 | RTCPUID volatile idHostCpu; /* 56 / 36 */
|
---|
115 |
|
---|
116 | /** Trace groups enable flags. */
|
---|
117 | uint32_t fTraceGroups; /* 60 / 40 */
|
---|
118 | /** Align the structures below bit on a 64-byte boundary and make sure it starts
|
---|
119 | * at the same offset in both 64-bit and 32-bit builds.
|
---|
120 | *
|
---|
121 | * @remarks The alignments of the members that are larger than 48 bytes should be
|
---|
122 | * 64-byte for cache line reasons. structs containing small amounts of
|
---|
123 | * data could be lumped together at the end with a < 64 byte padding
|
---|
124 | * following it (to grow into and align the struct size).
|
---|
125 | * */
|
---|
126 | uint8_t abAlignment1[HC_ARCH_BITS == 64 ? 60 : 16+64];
|
---|
127 | /** State data for use by ad hoc profiling. */
|
---|
128 | uint32_t uAdHoc;
|
---|
129 | /** Profiling samples for use by ad hoc profiling. */
|
---|
130 | STAMPROFILEADV aStatAdHoc[8]; /* size: 40*8 = 320 */
|
---|
131 |
|
---|
132 | /** CPUM part. */
|
---|
133 | union
|
---|
134 | {
|
---|
135 | #ifdef ___CPUMInternal_h
|
---|
136 | struct CPUMCPU s;
|
---|
137 | #endif
|
---|
138 | uint8_t padding[3584]; /* multiple of 64 */
|
---|
139 | } cpum;
|
---|
140 |
|
---|
141 | /** HM part. */
|
---|
142 | union
|
---|
143 | {
|
---|
144 | #ifdef ___HMInternal_h
|
---|
145 | struct HMCPU s;
|
---|
146 | #endif
|
---|
147 | uint8_t padding[5376]; /* multiple of 64 */
|
---|
148 | } hm;
|
---|
149 |
|
---|
150 | /** EM part. */
|
---|
151 | union
|
---|
152 | {
|
---|
153 | #ifdef ___EMInternal_h
|
---|
154 | struct EMCPU s;
|
---|
155 | #endif
|
---|
156 | uint8_t padding[1472]; /* multiple of 64 */
|
---|
157 | } em;
|
---|
158 |
|
---|
159 | /** IEM part. */
|
---|
160 | union
|
---|
161 | {
|
---|
162 | #ifdef ___IEMInternal_h
|
---|
163 | struct IEMCPU s;
|
---|
164 | #endif
|
---|
165 | uint8_t padding[3072]; /* multiple of 64 */
|
---|
166 | } iem;
|
---|
167 |
|
---|
168 | /** TRPM part. */
|
---|
169 | union
|
---|
170 | {
|
---|
171 | #ifdef ___TRPMInternal_h
|
---|
172 | struct TRPMCPU s;
|
---|
173 | #endif
|
---|
174 | uint8_t padding[128]; /* multiple of 64 */
|
---|
175 | } trpm;
|
---|
176 |
|
---|
177 | /** TM part. */
|
---|
178 | union
|
---|
179 | {
|
---|
180 | #ifdef ___TMInternal_h
|
---|
181 | struct TMCPU s;
|
---|
182 | #endif
|
---|
183 | uint8_t padding[384]; /* multiple of 64 */
|
---|
184 | } tm;
|
---|
185 |
|
---|
186 | /** VMM part. */
|
---|
187 | union
|
---|
188 | {
|
---|
189 | #ifdef ___VMMInternal_h
|
---|
190 | struct VMMCPU s;
|
---|
191 | #endif
|
---|
192 | uint8_t padding[640]; /* multiple of 64 */
|
---|
193 | } vmm;
|
---|
194 |
|
---|
195 | /** PDM part. */
|
---|
196 | union
|
---|
197 | {
|
---|
198 | #ifdef ___PDMInternal_h
|
---|
199 | struct PDMCPU s;
|
---|
200 | #endif
|
---|
201 | uint8_t padding[128]; /* multiple of 64 */
|
---|
202 | } pdm;
|
---|
203 |
|
---|
204 | /** IOM part. */
|
---|
205 | union
|
---|
206 | {
|
---|
207 | #ifdef ___IOMInternal_h
|
---|
208 | struct IOMCPU s;
|
---|
209 | #endif
|
---|
210 | uint8_t padding[512]; /* multiple of 64 */
|
---|
211 | } iom;
|
---|
212 |
|
---|
213 | /** DBGF part.
|
---|
214 | * @todo Combine this with other tiny structures. */
|
---|
215 | union
|
---|
216 | {
|
---|
217 | #ifdef ___DBGFInternal_h
|
---|
218 | struct DBGFCPU s;
|
---|
219 | #endif
|
---|
220 | uint8_t padding[64]; /* multiple of 64 */
|
---|
221 | } dbgf;
|
---|
222 |
|
---|
223 | /** Align the following members on page boundary. */
|
---|
224 | uint8_t abAlignment2[1024 - 320 - 128];
|
---|
225 |
|
---|
226 | /** PGM part. */
|
---|
227 | union
|
---|
228 | {
|
---|
229 | #ifdef ___PGMInternal_h
|
---|
230 | struct PGMCPU s;
|
---|
231 | #endif
|
---|
232 | uint8_t padding[4096]; /* multiple of 4096 */
|
---|
233 | } pgm;
|
---|
234 |
|
---|
235 | } VMCPU;
|
---|
236 |
|
---|
237 |
|
---|
238 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
239 |
|
---|
240 | /** @name Operations on VMCPU::enmState
|
---|
241 | * @{ */
|
---|
242 | /** Gets the VMCPU state. */
|
---|
243 | #define VMCPU_GET_STATE(pVCpu) ( (pVCpu)->enmState )
|
---|
244 | /** Sets the VMCPU state. */
|
---|
245 | #define VMCPU_SET_STATE(pVCpu, enmNewState) \
|
---|
246 | ASMAtomicWriteU32((uint32_t volatile *)&(pVCpu)->enmState, (enmNewState))
|
---|
247 | /** Cmpares and sets the VMCPU state. */
|
---|
248 | #define VMCPU_CMPXCHG_STATE(pVCpu, enmNewState, enmOldState) \
|
---|
249 | ASMAtomicCmpXchgU32((uint32_t volatile *)&(pVCpu)->enmState, (enmNewState), (enmOldState))
|
---|
250 | /** Checks the VMCPU state. */
|
---|
251 | #ifdef VBOX_STRICT
|
---|
252 | # define VMCPU_ASSERT_STATE(pVCpu, enmExpectedState) \
|
---|
253 | do { \
|
---|
254 | VMCPUSTATE enmState = VMCPU_GET_STATE(pVCpu); \
|
---|
255 | AssertMsg(enmState == (enmExpectedState), \
|
---|
256 | ("enmState=%d enmExpectedState=%d idCpu=%u\n", \
|
---|
257 | enmState, enmExpectedState, (pVCpu)->idCpu)); \
|
---|
258 | } while (0)
|
---|
259 | #else
|
---|
260 | # define VMCPU_ASSERT_STATE(pVCpu, enmExpectedState) do { } while (0)
|
---|
261 | #endif
|
---|
262 | /** Tests if the state means that the CPU is started. */
|
---|
263 | #define VMCPUSTATE_IS_STARTED(enmState) ( (enmState) > VMCPUSTATE_STOPPED )
|
---|
264 | /** Tests if the state means that the CPU is stopped. */
|
---|
265 | #define VMCPUSTATE_IS_STOPPED(enmState) ( (enmState) == VMCPUSTATE_STOPPED )
|
---|
266 | /** @} */
|
---|
267 |
|
---|
268 |
|
---|
269 | /** The name of the Guest Context VMM Core module. */
|
---|
270 | #define VMMGC_MAIN_MODULE_NAME "VMMGC.gc"
|
---|
271 | /** The name of the Ring 0 Context VMM Core module. */
|
---|
272 | #define VMMR0_MAIN_MODULE_NAME "VMMR0.r0"
|
---|
273 |
|
---|
274 | /** VM Forced Action Flags.
|
---|
275 | *
|
---|
276 | * Use the VM_FF_SET() and VM_FF_CLEAR() macros to change the force
|
---|
277 | * action mask of a VM.
|
---|
278 | *
|
---|
279 | * @{
|
---|
280 | */
|
---|
281 | /** The virtual sync clock has been stopped, go to TM until it has been
|
---|
282 | * restarted... */
|
---|
283 | #define VM_FF_TM_VIRTUAL_SYNC RT_BIT_32(2)
|
---|
284 | /** PDM Queues are pending. */
|
---|
285 | #define VM_FF_PDM_QUEUES RT_BIT_32(VM_FF_PDM_QUEUES_BIT)
|
---|
286 | /** The bit number for VM_FF_PDM_QUEUES. */
|
---|
287 | #define VM_FF_PDM_QUEUES_BIT 3
|
---|
288 | /** PDM DMA transfers are pending. */
|
---|
289 | #define VM_FF_PDM_DMA RT_BIT_32(VM_FF_PDM_DMA_BIT)
|
---|
290 | /** The bit number for VM_FF_PDM_DMA. */
|
---|
291 | #define VM_FF_PDM_DMA_BIT 4
|
---|
292 | /** This action forces the VM to call DBGF so DBGF can service debugger
|
---|
293 | * requests in the emulation thread.
|
---|
294 | * This action flag stays asserted till DBGF clears it.*/
|
---|
295 | #define VM_FF_DBGF RT_BIT_32(VM_FF_DBGF_BIT)
|
---|
296 | /** The bit number for VM_FF_DBGF. */
|
---|
297 | #define VM_FF_DBGF_BIT 8
|
---|
298 | /** This action forces the VM to service pending requests from other
|
---|
299 | * thread or requests which must be executed in another context. */
|
---|
300 | #define VM_FF_REQUEST RT_BIT_32(9)
|
---|
301 | /** Check for VM state changes and take appropriate action. */
|
---|
302 | #define VM_FF_CHECK_VM_STATE RT_BIT_32(VM_FF_CHECK_VM_STATE_BIT)
|
---|
303 | /** The bit number for VM_FF_CHECK_VM_STATE. */
|
---|
304 | #define VM_FF_CHECK_VM_STATE_BIT 10
|
---|
305 | /** Reset the VM. (postponed) */
|
---|
306 | #define VM_FF_RESET RT_BIT_32(VM_FF_RESET_BIT)
|
---|
307 | /** The bit number for VM_FF_RESET. */
|
---|
308 | #define VM_FF_RESET_BIT 11
|
---|
309 | /** EMT rendezvous in VMM. */
|
---|
310 | #define VM_FF_EMT_RENDEZVOUS RT_BIT_32(VM_FF_EMT_RENDEZVOUS_BIT)
|
---|
311 | /** The bit number for VM_FF_EMT_RENDEZVOUS. */
|
---|
312 | #define VM_FF_EMT_RENDEZVOUS_BIT 12
|
---|
313 |
|
---|
314 | /** PGM needs to allocate handy pages. */
|
---|
315 | #define VM_FF_PGM_NEED_HANDY_PAGES RT_BIT_32(18)
|
---|
316 | /** PGM is out of memory.
|
---|
317 | * Abandon all loops and code paths which can be resumed and get up to the EM
|
---|
318 | * loops. */
|
---|
319 | #define VM_FF_PGM_NO_MEMORY RT_BIT_32(19)
|
---|
320 | /** PGM is about to perform a lightweight pool flush
|
---|
321 | * Guest SMP: all EMT threads should return to ring 3
|
---|
322 | */
|
---|
323 | #define VM_FF_PGM_POOL_FLUSH_PENDING RT_BIT_32(20)
|
---|
324 | /** REM needs to be informed about handler changes. */
|
---|
325 | #define VM_FF_REM_HANDLER_NOTIFY RT_BIT_32(VM_FF_REM_HANDLER_NOTIFY_BIT)
|
---|
326 | /** The bit number for VM_FF_REM_HANDLER_NOTIFY. */
|
---|
327 | #define VM_FF_REM_HANDLER_NOTIFY_BIT 29
|
---|
328 | /** Suspend the VM - debug only. */
|
---|
329 | #define VM_FF_DEBUG_SUSPEND RT_BIT_32(31)
|
---|
330 |
|
---|
331 |
|
---|
332 | /** This action forces the VM to check any pending interrups on the APIC. */
|
---|
333 | #define VMCPU_FF_INTERRUPT_APIC RT_BIT_32(0)
|
---|
334 | /** This action forces the VM to check any pending interrups on the PIC. */
|
---|
335 | #define VMCPU_FF_INTERRUPT_PIC RT_BIT_32(1)
|
---|
336 | /** This action forces the VM to schedule and run pending timer (TM).
|
---|
337 | * @remarks Don't move - PATM compatibility. */
|
---|
338 | #define VMCPU_FF_TIMER RT_BIT_32(2)
|
---|
339 | /** This action forces the VM to check any pending NMIs. */
|
---|
340 | #define VMCPU_FF_INTERRUPT_NMI_BIT 3
|
---|
341 | #define VMCPU_FF_INTERRUPT_NMI RT_BIT_32(VMCPU_FF_INTERRUPT_NMI_BIT)
|
---|
342 | /** This action forces the VM to check any pending SMIs. */
|
---|
343 | #define VMCPU_FF_INTERRUPT_SMI_BIT 4
|
---|
344 | #define VMCPU_FF_INTERRUPT_SMI RT_BIT_32(VMCPU_FF_INTERRUPT_SMI_BIT)
|
---|
345 | /** PDM critical section unlocking is pending, process promptly upon return to R3. */
|
---|
346 | #define VMCPU_FF_PDM_CRITSECT RT_BIT_32(5)
|
---|
347 | /** This action forces the VM to service pending requests from other
|
---|
348 | * thread or requests which must be executed in another context. */
|
---|
349 | #define VMCPU_FF_REQUEST RT_BIT_32(9)
|
---|
350 | /** This action forces the VM to resync the page tables before going
|
---|
351 | * back to execute guest code. (GLOBAL FLUSH) */
|
---|
352 | #define VMCPU_FF_PGM_SYNC_CR3 RT_BIT_32(16)
|
---|
353 | /** Same as VM_FF_PGM_SYNC_CR3 except that global pages can be skipped.
|
---|
354 | * (NON-GLOBAL FLUSH) */
|
---|
355 | #define VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL RT_BIT_32(17)
|
---|
356 | /** Check for pending TLB shootdown actions.
|
---|
357 | * Consumer: HM
|
---|
358 | * @todo rename to VMCPU_FF_HM_TLB_SHOOTDOWN */
|
---|
359 | #define VMCPU_FF_TLB_SHOOTDOWN RT_BIT_32(18)
|
---|
360 | /** Check for pending TLB flush action.
|
---|
361 | * Consumer: HM
|
---|
362 | * @todo rename to VMCPU_FF_HM_TLB_FLUSH */
|
---|
363 | #define VMCPU_FF_TLB_FLUSH RT_BIT_32(VMCPU_FF_TLB_FLUSH_BIT)
|
---|
364 | /** The bit number for VMCPU_FF_TLB_FLUSH. */
|
---|
365 | #define VMCPU_FF_TLB_FLUSH_BIT 19
|
---|
366 | /** Check the interrupt and trap gates */
|
---|
367 | #define VMCPU_FF_TRPM_SYNC_IDT RT_BIT_32(20)
|
---|
368 | /** Check Guest's TSS ring 0 stack */
|
---|
369 | #define VMCPU_FF_SELM_SYNC_TSS RT_BIT_32(21)
|
---|
370 | /** Check Guest's GDT table */
|
---|
371 | #define VMCPU_FF_SELM_SYNC_GDT RT_BIT_32(22)
|
---|
372 | /** Check Guest's LDT table */
|
---|
373 | #define VMCPU_FF_SELM_SYNC_LDT RT_BIT_32(23)
|
---|
374 | /** Inhibit interrupts pending. See EMGetInhibitInterruptsPC(). */
|
---|
375 | #define VMCPU_FF_INHIBIT_INTERRUPTS RT_BIT_32(24)
|
---|
376 | /** CSAM needs to scan the page that's being executed */
|
---|
377 | #define VMCPU_FF_CSAM_SCAN_PAGE RT_BIT_32(26)
|
---|
378 | /** CSAM needs to do some homework. */
|
---|
379 | #define VMCPU_FF_CSAM_PENDING_ACTION RT_BIT_32(27)
|
---|
380 | /** Force return to Ring-3. */
|
---|
381 | #define VMCPU_FF_TO_R3 RT_BIT_32(28)
|
---|
382 |
|
---|
383 | /** Externally VM forced actions. Used to quit the idle/wait loop. */
|
---|
384 | #define VM_FF_EXTERNAL_SUSPENDED_MASK (VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_REQUEST | VM_FF_EMT_RENDEZVOUS)
|
---|
385 | /** Externally VMCPU forced actions. Used to quit the idle/wait loop. */
|
---|
386 | #define VMCPU_FF_EXTERNAL_SUSPENDED_MASK (VMCPU_FF_REQUEST)
|
---|
387 |
|
---|
388 | /** Externally forced VM actions. Used to quit the idle/wait loop. */
|
---|
389 | #define VM_FF_EXTERNAL_HALTED_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_REQUEST \
|
---|
390 | | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_EMT_RENDEZVOUS)
|
---|
391 | /** Externally forced VMCPU actions. Used to quit the idle/wait loop. */
|
---|
392 | #define VMCPU_FF_EXTERNAL_HALTED_MASK (VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC | VMCPU_FF_REQUEST | VMCPU_FF_TIMER)
|
---|
393 |
|
---|
394 | /** High priority VM pre-execution actions. */
|
---|
395 | #define VM_FF_HIGH_PRIORITY_PRE_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_TM_VIRTUAL_SYNC \
|
---|
396 | | VM_FF_DEBUG_SUSPEND | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY | VM_FF_EMT_RENDEZVOUS)
|
---|
397 | /** High priority VMCPU pre-execution actions. */
|
---|
398 | #define VMCPU_FF_HIGH_PRIORITY_PRE_MASK ( VMCPU_FF_TIMER | VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC | VMCPU_FF_PGM_SYNC_CR3 \
|
---|
399 | | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT \
|
---|
400 | | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT | VMCPU_FF_INHIBIT_INTERRUPTS)
|
---|
401 |
|
---|
402 | /** High priority VM pre raw-mode execution mask. */
|
---|
403 | #define VM_FF_HIGH_PRIORITY_PRE_RAW_MASK (VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY)
|
---|
404 | /** High priority VMCPU pre raw-mode execution mask. */
|
---|
405 | #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 \
|
---|
406 | | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT | VMCPU_FF_INHIBIT_INTERRUPTS)
|
---|
407 |
|
---|
408 | /** High priority post-execution actions. */
|
---|
409 | #define VM_FF_HIGH_PRIORITY_POST_MASK (VM_FF_PGM_NO_MEMORY)
|
---|
410 | /** High priority post-execution actions. */
|
---|
411 | #define VMCPU_FF_HIGH_PRIORITY_POST_MASK (VMCPU_FF_PDM_CRITSECT|VMCPU_FF_CSAM_PENDING_ACTION)
|
---|
412 |
|
---|
413 | /** Normal priority VM post-execution actions. */
|
---|
414 | #define VM_FF_NORMAL_PRIORITY_POST_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_RESET \
|
---|
415 | | VM_FF_PGM_NO_MEMORY | VM_FF_EMT_RENDEZVOUS)
|
---|
416 | /** Normal priority VMCPU post-execution actions. */
|
---|
417 | #define VMCPU_FF_NORMAL_PRIORITY_POST_MASK (VMCPU_FF_CSAM_SCAN_PAGE)
|
---|
418 |
|
---|
419 | /** Normal priority VM actions. */
|
---|
420 | #define VM_FF_NORMAL_PRIORITY_MASK (VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_REM_HANDLER_NOTIFY | VM_FF_EMT_RENDEZVOUS)
|
---|
421 | /** Normal priority VMCPU actions. */
|
---|
422 | #define VMCPU_FF_NORMAL_PRIORITY_MASK (VMCPU_FF_REQUEST)
|
---|
423 |
|
---|
424 | /** Flags to clear before resuming guest execution. */
|
---|
425 | #define VMCPU_FF_RESUME_GUEST_MASK (VMCPU_FF_TO_R3)
|
---|
426 |
|
---|
427 | /** VM Flags that cause the HM loops to go back to ring-3. */
|
---|
428 | #define VM_FF_HM_TO_R3_MASK (VM_FF_TM_VIRTUAL_SYNC | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY | VM_FF_PDM_QUEUES | VM_FF_EMT_RENDEZVOUS)
|
---|
429 | /** VMCPU Flags that cause the HM loops to go back to ring-3. */
|
---|
430 | #define VMCPU_FF_HM_TO_R3_MASK (VMCPU_FF_TO_R3 | VMCPU_FF_TIMER | VMCPU_FF_PDM_CRITSECT)
|
---|
431 |
|
---|
432 | /** All the forced VM flags. */
|
---|
433 | #define VM_FF_ALL_MASK (~0U)
|
---|
434 | /** All the forced VMCPU flags. */
|
---|
435 | #define VMCPU_FF_ALL_MASK (~0U)
|
---|
436 |
|
---|
437 | /** All the forced VM flags except those related to raw-mode and hardware
|
---|
438 | * assisted execution. */
|
---|
439 | #define VM_FF_ALL_REM_MASK (~(VM_FF_HIGH_PRIORITY_PRE_RAW_MASK) | VM_FF_PGM_NO_MEMORY)
|
---|
440 | /** All the forced VMCPU flags except those related to raw-mode and hardware
|
---|
441 | * assisted execution. */
|
---|
442 | #define VMCPU_FF_ALL_REM_MASK (~(VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK | VMCPU_FF_CSAM_PENDING_ACTION | VMCPU_FF_PDM_CRITSECT | VMCPU_FF_TLB_FLUSH | VMCPU_FF_TLB_SHOOTDOWN))
|
---|
443 |
|
---|
444 | /** @} */
|
---|
445 |
|
---|
446 | /** @def VM_FF_SET
|
---|
447 | * Sets a force action flag.
|
---|
448 | *
|
---|
449 | * @param pVM VM Handle.
|
---|
450 | * @param fFlag The flag to set.
|
---|
451 | */
|
---|
452 | #if 1
|
---|
453 | # define VM_FF_SET(pVM, fFlag) ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag))
|
---|
454 | #else
|
---|
455 | # define VM_FF_SET(pVM, fFlag) \
|
---|
456 | do { ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag)); \
|
---|
457 | RTLogPrintf("VM_FF_SET : %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
|
---|
458 | } while (0)
|
---|
459 | #endif
|
---|
460 |
|
---|
461 | /** @def VMCPU_FF_SET
|
---|
462 | * Sets a force action flag for the given VCPU.
|
---|
463 | *
|
---|
464 | * @param pVCpu VMCPU Handle.
|
---|
465 | * @param fFlag The flag to set.
|
---|
466 | */
|
---|
467 | #define VMCPU_FF_SET(pVCpu, fFlag) ASMAtomicOrU32(&(pVCpu)->fLocalForcedActions, (fFlag))
|
---|
468 |
|
---|
469 | /** @def VM_FF_CLEAR
|
---|
470 | * Clears a force action flag.
|
---|
471 | *
|
---|
472 | * @param pVM VM Handle.
|
---|
473 | * @param fFlag The flag to clear.
|
---|
474 | */
|
---|
475 | #if 1
|
---|
476 | # define VM_FF_CLEAR(pVM, fFlag) ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag))
|
---|
477 | #else
|
---|
478 | # define VM_FF_CLEAR(pVM, fFlag) \
|
---|
479 | do { ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag)); \
|
---|
480 | RTLogPrintf("VM_FF_CLEAR: %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
|
---|
481 | } while (0)
|
---|
482 | #endif
|
---|
483 |
|
---|
484 | /** @def VMCPU_FF_CLEAR
|
---|
485 | * Clears a force action flag for the given VCPU.
|
---|
486 | *
|
---|
487 | * @param pVCpu VMCPU Handle.
|
---|
488 | * @param fFlag The flag to clear.
|
---|
489 | */
|
---|
490 | #define VMCPU_FF_CLEAR(pVCpu, fFlag) ASMAtomicAndU32(&(pVCpu)->fLocalForcedActions, ~(fFlag))
|
---|
491 |
|
---|
492 | /** @def VM_FF_ISSET
|
---|
493 | * Checks if a force action flag is set.
|
---|
494 | *
|
---|
495 | * @param pVM VM Handle.
|
---|
496 | * @param fFlag The flag to check.
|
---|
497 | */
|
---|
498 | #define VM_FF_IS_SET(pVM, fFlag) (((pVM)->fGlobalForcedActions & (fFlag)) == (fFlag))
|
---|
499 | /** @deprecated */
|
---|
500 | #define VM_FF_ISSET(pVM, fFlag) VM_FF_IS_SET(pVM, fFlag)
|
---|
501 |
|
---|
502 | /** @def VMCPU_FF_ISSET
|
---|
503 | * Checks if a force action flag is set for the given VCPU.
|
---|
504 | *
|
---|
505 | * @param pVCpu VMCPU Handle.
|
---|
506 | * @param fFlag The flag to check.
|
---|
507 | */
|
---|
508 | #define VMCPU_FF_IS_SET(pVCpu, fFlag) (((pVCpu)->fLocalForcedActions & (fFlag)) == (fFlag))
|
---|
509 | /** @deprecated */
|
---|
510 | #define VMCPU_FF_ISSET(pVCpu, fFlag) VMCPU_FF_IS_SET(pVCpu, fFlag)
|
---|
511 |
|
---|
512 | /** @def VM_FF_ISPENDING
|
---|
513 | * Checks if one or more force action in the specified set is pending.
|
---|
514 | *
|
---|
515 | * @param pVM VM Handle.
|
---|
516 | * @param fFlags The flags to check for.
|
---|
517 | */
|
---|
518 | #define VM_FF_IS_PENDING(pVM, fFlags) ((pVM)->fGlobalForcedActions & (fFlags))
|
---|
519 | /** @deprecated */
|
---|
520 | #define VM_FF_ISPENDING(pVM, fFlags) VM_FF_IS_PENDING(pVM, fFlags)
|
---|
521 |
|
---|
522 | /** @def VM_FF_TESTANDCLEAR
|
---|
523 | * Checks if one (!) force action in the specified set is pending and clears it atomically
|
---|
524 | *
|
---|
525 | * @returns true if the bit was set.
|
---|
526 | * @returns false if the bit was clear.
|
---|
527 | * @param pVM VM Handle.
|
---|
528 | * @param iBit Bit position to check and clear
|
---|
529 | */
|
---|
530 | #define VM_FF_TEST_AND_CLEAR(pVM, iBit) (ASMAtomicBitTestAndClear(&(pVM)->fGlobalForcedActions, iBit##_BIT))
|
---|
531 | /** @deprecated */
|
---|
532 | #define VM_FF_TESTANDCLEAR(pVM, iBit) (ASMAtomicBitTestAndClear(&(pVM)->fGlobalForcedActions, iBit##_BIT))
|
---|
533 |
|
---|
534 | /** @def VMCPU_FF_TESTANDCLEAR
|
---|
535 | * Checks if one (!) force action in the specified set is pending and clears it atomically
|
---|
536 | *
|
---|
537 | * @returns true if the bit was set.
|
---|
538 | * @returns false if the bit was clear.
|
---|
539 | * @param pVCpu VMCPU Handle.
|
---|
540 | * @param iBit Bit position to check and clear
|
---|
541 | */
|
---|
542 | #define VMCPU_FF_TEST_AND_CLEAR(pVCpu, iBit) (ASMAtomicBitTestAndClear(&(pVCpu)->fLocalForcedActions, iBit##_BIT))
|
---|
543 | /** @deprecated */
|
---|
544 | #define VMCPU_FF_TESTANDCLEAR(pVCpu, iBit) (ASMAtomicBitTestAndClear(&(pVCpu)->fLocalForcedActions, iBit##_BIT))
|
---|
545 |
|
---|
546 | /** @def VMCPU_FF_ISPENDING
|
---|
547 | * Checks if one or more force action in the specified set is pending for the given VCPU.
|
---|
548 | *
|
---|
549 | * @param pVCpu VMCPU Handle.
|
---|
550 | * @param fFlags The flags to check for.
|
---|
551 | */
|
---|
552 | #define VMCPU_FF_IS_PENDING(pVCpu, fFlags) ((pVCpu)->fLocalForcedActions & (fFlags))
|
---|
553 | /** @deprecated */
|
---|
554 | #define VMCPU_FF_ISPENDING(pVCpu, fFlags) VMCPU_FF_IS_PENDING(pVCpu, fFlags)
|
---|
555 |
|
---|
556 | /** @def VM_FF_ISPENDING
|
---|
557 | * Checks if one or more force action in the specified set is pending while one
|
---|
558 | * or more other ones are not.
|
---|
559 | *
|
---|
560 | * @param pVM VM Handle.
|
---|
561 | * @param fFlags The flags to check for.
|
---|
562 | * @param fExcpt The flags that should not be set.
|
---|
563 | */
|
---|
564 | #define VM_FF_IS_PENDING_EXCEPT(pVM, fFlags, fExcpt) ( ((pVM)->fGlobalForcedActions & (fFlags)) && !((pVM)->fGlobalForcedActions & (fExcpt)) )
|
---|
565 |
|
---|
566 | /** @def VMCPU_FF_IS_PENDING_EXCEPT
|
---|
567 | * Checks if one or more force action in the specified set is pending for the given
|
---|
568 | * VCPU while one or more other ones are not.
|
---|
569 | *
|
---|
570 | * @param pVCpu VMCPU Handle.
|
---|
571 | * @param fFlags The flags to check for.
|
---|
572 | * @param fExcpt The flags that should not be set.
|
---|
573 | */
|
---|
574 | #define VMCPU_FF_IS_PENDING_EXCEPT(pVCpu, fFlags, fExcpt) ( ((pVCpu)->fLocalForcedActions & (fFlags)) && !((pVCpu)->fLocalForcedActions & (fExcpt)) )
|
---|
575 |
|
---|
576 | /** @def VM_IS_EMT
|
---|
577 | * Checks if the current thread is the emulation thread (EMT).
|
---|
578 | *
|
---|
579 | * @remark The ring-0 variation will need attention if we expand the ring-0
|
---|
580 | * code to let threads other than EMT mess around with the VM.
|
---|
581 | */
|
---|
582 | #ifdef IN_RC
|
---|
583 | # define VM_IS_EMT(pVM) true
|
---|
584 | #else
|
---|
585 | # define VM_IS_EMT(pVM) (VMMGetCpu(pVM) != NULL)
|
---|
586 | #endif
|
---|
587 |
|
---|
588 | /** @def VMCPU_IS_EMT
|
---|
589 | * Checks if the current thread is the emulation thread (EMT) for the specified
|
---|
590 | * virtual CPU.
|
---|
591 | */
|
---|
592 | #ifdef IN_RC
|
---|
593 | # define VMCPU_IS_EMT(pVCpu) true
|
---|
594 | #else
|
---|
595 | # define VMCPU_IS_EMT(pVCpu) ((pVCpu) && ((pVCpu) == VMMGetCpu((pVCpu)->CTX_SUFF(pVM))))
|
---|
596 | #endif
|
---|
597 |
|
---|
598 | /** @def VM_ASSERT_EMT
|
---|
599 | * Asserts that the current thread IS the emulation thread (EMT).
|
---|
600 | */
|
---|
601 | #ifdef IN_RC
|
---|
602 | # define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
|
---|
603 | #elif defined(IN_RING0)
|
---|
604 | # define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
|
---|
605 | #else
|
---|
606 | # define VM_ASSERT_EMT(pVM) \
|
---|
607 | AssertMsg(VM_IS_EMT(pVM), \
|
---|
608 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)))
|
---|
609 | #endif
|
---|
610 |
|
---|
611 | /** @def VMCPU_ASSERT_EMT
|
---|
612 | * Asserts that the current thread IS the emulation thread (EMT) of the
|
---|
613 | * specified virtual CPU.
|
---|
614 | */
|
---|
615 | #ifdef IN_RC
|
---|
616 | # define VMCPU_ASSERT_EMT(pVCpu) Assert(VMCPU_IS_EMT(pVCpu))
|
---|
617 | #elif defined(IN_RING0)
|
---|
618 | # define VMCPU_ASSERT_EMT(pVCpu) Assert(VMCPU_IS_EMT(pVCpu))
|
---|
619 | #else
|
---|
620 | # define VMCPU_ASSERT_EMT(pVCpu) \
|
---|
621 | AssertMsg(VMCPU_IS_EMT(pVCpu), \
|
---|
622 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
|
---|
623 | RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
|
---|
624 | #endif
|
---|
625 |
|
---|
626 | /** @def VM_ASSERT_EMT_RETURN
|
---|
627 | * Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
|
---|
628 | */
|
---|
629 | #ifdef IN_RC
|
---|
630 | # define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
|
---|
631 | #elif defined(IN_RING0)
|
---|
632 | # define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
|
---|
633 | #else
|
---|
634 | # define VM_ASSERT_EMT_RETURN(pVM, rc) \
|
---|
635 | AssertMsgReturn(VM_IS_EMT(pVM), \
|
---|
636 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)), \
|
---|
637 | (rc))
|
---|
638 | #endif
|
---|
639 |
|
---|
640 | /** @def VMCPU_ASSERT_EMT_RETURN
|
---|
641 | * Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
|
---|
642 | */
|
---|
643 | #ifdef IN_RC
|
---|
644 | # define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
|
---|
645 | #elif defined(IN_RING0)
|
---|
646 | # define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
|
---|
647 | #else
|
---|
648 | # define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) \
|
---|
649 | AssertMsg(VMCPU_IS_EMT(pVCpu), \
|
---|
650 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
|
---|
651 | RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu), \
|
---|
652 | (rc))
|
---|
653 | #endif
|
---|
654 |
|
---|
655 | /** @def VMCPU_ASSERT_EMT_OR_GURU
|
---|
656 | * Asserts that the current thread IS the emulation thread (EMT) of the
|
---|
657 | * specified virtual CPU.
|
---|
658 | */
|
---|
659 | #if defined(IN_RC) || defined(IN_RING0)
|
---|
660 | # define VMCPU_ASSERT_EMT_OR_GURU(pVCpu) Assert( VMCPU_IS_EMT(pVCpu) \
|
---|
661 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION \
|
---|
662 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION_LS )
|
---|
663 | #else
|
---|
664 | # define VMCPU_ASSERT_EMT_OR_GURU(pVCpu) \
|
---|
665 | AssertMsg( VMCPU_IS_EMT(pVCpu) \
|
---|
666 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION \
|
---|
667 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION_LS, \
|
---|
668 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
|
---|
669 | RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
|
---|
670 | #endif
|
---|
671 |
|
---|
672 | /** @def VMCPU_ASSERT_EMT_OR_NOT_RUNNING
|
---|
673 | * Asserts that the current thread IS the emulation thread (EMT) of the
|
---|
674 | * specified virtual CPU when the VM is running.
|
---|
675 | */
|
---|
676 | #if defined(IN_RC) || defined(IN_RING0)
|
---|
677 | # define VMCPU_ASSERT_EMT_OR_NOT_RUNNING(pVCpu) \
|
---|
678 | Assert( VMCPU_IS_EMT(pVCpu) \
|
---|
679 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_RUNNING \
|
---|
680 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_RUNNING_LS \
|
---|
681 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_RUNNING_FT )
|
---|
682 | #else
|
---|
683 | # define VMCPU_ASSERT_EMT_OR_NOT_RUNNING(pVCpu) \
|
---|
684 | AssertMsg( VMCPU_IS_EMT(pVCpu) \
|
---|
685 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_RUNNING \
|
---|
686 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_RUNNING_LS \
|
---|
687 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_RUNNING_FT, \
|
---|
688 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
|
---|
689 | RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
|
---|
690 | #endif
|
---|
691 |
|
---|
692 | /** @def VM_ASSERT_EMT0
|
---|
693 | * Asserts that the current thread IS emulation thread \#0 (EMT0).
|
---|
694 | */
|
---|
695 | #define VM_ASSERT_EMT0(pVM) VMCPU_ASSERT_EMT(&(pVM)->aCpus[0])
|
---|
696 |
|
---|
697 | /** @def VM_ASSERT_EMT0_RETURN
|
---|
698 | * Asserts that the current thread IS emulation thread \#0 (EMT0) and returns if
|
---|
699 | * it isn't.
|
---|
700 | */
|
---|
701 | #define VM_ASSERT_EMT0_RETURN(pVM, rc) VMCPU_ASSERT_EMT_RETURN(&(pVM)->aCpus[0], (rc))
|
---|
702 |
|
---|
703 |
|
---|
704 | /**
|
---|
705 | * Asserts that the current thread is NOT the emulation thread.
|
---|
706 | */
|
---|
707 | #define VM_ASSERT_OTHER_THREAD(pVM) \
|
---|
708 | AssertMsg(!VM_IS_EMT(pVM), ("Not other thread!!\n"))
|
---|
709 |
|
---|
710 |
|
---|
711 | /** @def VM_ASSERT_STATE_RETURN
|
---|
712 | * Asserts a certain VM state.
|
---|
713 | */
|
---|
714 | #define VM_ASSERT_STATE(pVM, _enmState) \
|
---|
715 | AssertMsg((pVM)->enmVMState == (_enmState), \
|
---|
716 | ("state %s, expected %s\n", VMGetStateName((pVM)->enmVMState), VMGetStateName(_enmState)))
|
---|
717 |
|
---|
718 | /** @def VM_ASSERT_STATE_RETURN
|
---|
719 | * Asserts a certain VM state and returns if it doesn't match.
|
---|
720 | */
|
---|
721 | #define VM_ASSERT_STATE_RETURN(pVM, _enmState, rc) \
|
---|
722 | AssertMsgReturn((pVM)->enmVMState == (_enmState), \
|
---|
723 | ("state %s, expected %s\n", VMGetStateName((pVM)->enmVMState), VMGetStateName(_enmState)), \
|
---|
724 | (rc))
|
---|
725 |
|
---|
726 | /** @def VM_ASSERT_VALID_EXT_RETURN
|
---|
727 | * Asserts a the VM handle is valid for external access, i.e. not being
|
---|
728 | * destroy or terminated.
|
---|
729 | */
|
---|
730 | #define VM_ASSERT_VALID_EXT_RETURN(pVM, rc) \
|
---|
731 | AssertMsgReturn( RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
|
---|
732 | && ( (unsigned)(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING \
|
---|
733 | || ( (unsigned)(pVM)->enmVMState == (unsigned)VMSTATE_DESTROYING \
|
---|
734 | && VM_IS_EMT(pVM))), \
|
---|
735 | ("pVM=%p state %s\n", (pVM), RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
|
---|
736 | ? VMGetStateName(pVM->enmVMState) : ""), \
|
---|
737 | (rc))
|
---|
738 |
|
---|
739 | /** @def VMCPU_ASSERT_VALID_EXT_RETURN
|
---|
740 | * Asserts a the VMCPU handle is valid for external access, i.e. not being
|
---|
741 | * destroy or terminated.
|
---|
742 | */
|
---|
743 | #define VMCPU_ASSERT_VALID_EXT_RETURN(pVCpu, rc) \
|
---|
744 | AssertMsgReturn( RT_VALID_ALIGNED_PTR(pVCpu, 64) \
|
---|
745 | && RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
|
---|
746 | && (unsigned)(pVCpu)->CTX_SUFF(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING, \
|
---|
747 | ("pVCpu=%p pVM=%p state %s\n", (pVCpu), RT_VALID_ALIGNED_PTR(pVCpu, 64) ? (pVCpu)->CTX_SUFF(pVM) : NULL, \
|
---|
748 | RT_VALID_ALIGNED_PTR(pVCpu, 64) && RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
|
---|
749 | ? VMGetStateName((pVCpu)->pVMR3->enmVMState) : ""), \
|
---|
750 | (rc))
|
---|
751 |
|
---|
752 | #endif /* !VBOX_FOR_DTRACE_LIB */
|
---|
753 |
|
---|
754 |
|
---|
755 |
|
---|
756 | /** This is the VM structure.
|
---|
757 | *
|
---|
758 | * It contains (nearly?) all the VM data which have to be available in all
|
---|
759 | * contexts. Even if it contains all the data the idea is to use APIs not
|
---|
760 | * to modify all the members all around the place. Therefore we make use of
|
---|
761 | * unions to hide everything which isn't local to the current source module.
|
---|
762 | * This means we'll have to pay a little bit of attention when adding new
|
---|
763 | * members to structures in the unions and make sure to keep the padding sizes
|
---|
764 | * up to date.
|
---|
765 | *
|
---|
766 | * Run tstVMStructSize after update!
|
---|
767 | */
|
---|
768 | typedef struct VM
|
---|
769 | {
|
---|
770 | /** The state of the VM.
|
---|
771 | * This field is read only to everyone except the VM and EM. */
|
---|
772 | VMSTATE volatile enmVMState;
|
---|
773 | /** Forced action flags.
|
---|
774 | * See the VM_FF_* \#defines. Updated atomically.
|
---|
775 | */
|
---|
776 | volatile uint32_t fGlobalForcedActions;
|
---|
777 | /** Pointer to the array of page descriptors for the VM structure allocation. */
|
---|
778 | R3PTRTYPE(PSUPPAGE) paVMPagesR3;
|
---|
779 | /** Session handle. For use when calling SUPR0 APIs. */
|
---|
780 | PSUPDRVSESSION pSession;
|
---|
781 | /** Pointer to the ring-3 VM structure. */
|
---|
782 | PUVM pUVM;
|
---|
783 | /** Ring-3 Host Context VM Pointer. */
|
---|
784 | R3PTRTYPE(struct VM *) pVMR3;
|
---|
785 | /** Ring-0 Host Context VM Pointer. */
|
---|
786 | R0PTRTYPE(struct VM *) pVMR0;
|
---|
787 | /** Raw-mode Context VM Pointer. */
|
---|
788 | RCPTRTYPE(struct VM *) pVMRC;
|
---|
789 |
|
---|
790 | /** The GVM VM handle. Only the GVM should modify this field. */
|
---|
791 | uint32_t hSelf;
|
---|
792 | /** Number of virtual CPUs. */
|
---|
793 | uint32_t cCpus;
|
---|
794 | /** CPU excution cap (1-100) */
|
---|
795 | uint32_t uCpuExecutionCap;
|
---|
796 |
|
---|
797 | /** Size of the VM structure including the VMCPU array. */
|
---|
798 | uint32_t cbSelf;
|
---|
799 |
|
---|
800 | /** Offset to the VMCPU array starting from beginning of this structure. */
|
---|
801 | uint32_t offVMCPU;
|
---|
802 |
|
---|
803 | /**
|
---|
804 | * VMMSwitcher assembly entry point returning to host context.
|
---|
805 | *
|
---|
806 | * Depending on how the host handles the rc status given in @a eax, this may
|
---|
807 | * return and let the caller resume whatever it was doing prior to the call.
|
---|
808 | *
|
---|
809 | *
|
---|
810 | * @param eax The return code, register.
|
---|
811 | * @remark Assume interrupts disabled.
|
---|
812 | * @remark This method pointer lives here because TRPM needs it.
|
---|
813 | */
|
---|
814 | RTRCPTR pfnVMMRCToHostAsm/*(int32_t eax)*/;
|
---|
815 |
|
---|
816 | /**
|
---|
817 | * VMMSwitcher assembly entry point returning to host context without saving the
|
---|
818 | * raw-mode context (hyper) registers.
|
---|
819 | *
|
---|
820 | * Unlike pfnVMMRC2HCAsm, this will not return to the caller. Instead it
|
---|
821 | * expects the caller to save a RC context in CPUM where one might return if the
|
---|
822 | * return code indicate that this is possible.
|
---|
823 | *
|
---|
824 | * This method pointer lives here because TRPM needs it.
|
---|
825 | *
|
---|
826 | * @param eax The return code, register.
|
---|
827 | * @remark Assume interrupts disabled.
|
---|
828 | * @remark This method pointer lives here because TRPM needs it.
|
---|
829 | */
|
---|
830 | RTRCPTR pfnVMMRCToHostAsmNoReturn/*(int32_t eax)*/;
|
---|
831 |
|
---|
832 | /** @name Various items that are frequently accessed.
|
---|
833 | * @{ */
|
---|
834 | /** Whether to recompile user mode code or run it raw/hm. */
|
---|
835 | bool fRecompileUser;
|
---|
836 | /** Whether to recompile supervisor mode code or run it raw/hm. */
|
---|
837 | bool fRecompileSupervisor;
|
---|
838 | /** PATM enabled flag.
|
---|
839 | * This is placed here for performance reasons. */
|
---|
840 | bool fPATMEnabled;
|
---|
841 | /** CSAM enabled flag.
|
---|
842 | * This is placed here for performance reasons. */
|
---|
843 | bool fCSAMEnabled;
|
---|
844 | /** Hardware VM support is available and enabled.
|
---|
845 | * This is placed here for performance reasons. */
|
---|
846 | bool fHMEnabled;
|
---|
847 | /** Hardware VM support is required and non-optional.
|
---|
848 | * This is initialized together with the rest of the VM structure. */
|
---|
849 | bool fHwVirtExtForced;
|
---|
850 | /** Set when this VM is the master FT node. */
|
---|
851 | bool fFaultTolerantMaster;
|
---|
852 | /** Large page enabled flag. */
|
---|
853 | bool fUseLargePages;
|
---|
854 | /** @} */
|
---|
855 |
|
---|
856 | /** Alignment padding.. */
|
---|
857 | uint32_t uPadding1;
|
---|
858 |
|
---|
859 | /** @name Debugging
|
---|
860 | * @{ */
|
---|
861 | /** Raw-mode Context VM Pointer. */
|
---|
862 | RCPTRTYPE(RTTRACEBUF) hTraceBufRC;
|
---|
863 | /** Ring-3 Host Context VM Pointer. */
|
---|
864 | R3PTRTYPE(RTTRACEBUF) hTraceBufR3;
|
---|
865 | /** Ring-0 Host Context VM Pointer. */
|
---|
866 | R0PTRTYPE(RTTRACEBUF) hTraceBufR0;
|
---|
867 | /** @} */
|
---|
868 |
|
---|
869 | #if HC_ARCH_BITS == 32
|
---|
870 | /** Alignment padding.. */
|
---|
871 | uint32_t uPadding2;
|
---|
872 | #endif
|
---|
873 |
|
---|
874 | /** @name Switcher statistics (remove)
|
---|
875 | * @{ */
|
---|
876 | /** Profiling the total time from Qemu to GC. */
|
---|
877 | STAMPROFILEADV StatTotalQemuToGC;
|
---|
878 | /** Profiling the total time from GC to Qemu. */
|
---|
879 | STAMPROFILEADV StatTotalGCToQemu;
|
---|
880 | /** Profiling the total time spent in GC. */
|
---|
881 | STAMPROFILEADV StatTotalInGC;
|
---|
882 | /** Profiling the total time spent not in Qemu. */
|
---|
883 | STAMPROFILEADV StatTotalInQemu;
|
---|
884 | /** Profiling the VMMSwitcher code for going to GC. */
|
---|
885 | STAMPROFILEADV StatSwitcherToGC;
|
---|
886 | /** Profiling the VMMSwitcher code for going to HC. */
|
---|
887 | STAMPROFILEADV StatSwitcherToHC;
|
---|
888 | STAMPROFILEADV StatSwitcherSaveRegs;
|
---|
889 | STAMPROFILEADV StatSwitcherSysEnter;
|
---|
890 | STAMPROFILEADV StatSwitcherDebug;
|
---|
891 | STAMPROFILEADV StatSwitcherCR0;
|
---|
892 | STAMPROFILEADV StatSwitcherCR4;
|
---|
893 | STAMPROFILEADV StatSwitcherJmpCR3;
|
---|
894 | STAMPROFILEADV StatSwitcherRstrRegs;
|
---|
895 | STAMPROFILEADV StatSwitcherLgdt;
|
---|
896 | STAMPROFILEADV StatSwitcherLidt;
|
---|
897 | STAMPROFILEADV StatSwitcherLldt;
|
---|
898 | STAMPROFILEADV StatSwitcherTSS;
|
---|
899 | /** @} */
|
---|
900 |
|
---|
901 | /** Padding - the unions must be aligned on a 64 bytes boundary and the unions
|
---|
902 | * must start at the same offset on both 64-bit and 32-bit hosts. */
|
---|
903 | uint8_t abAlignment3[(HC_ARCH_BITS == 32 ? 24 : 0) + 40];
|
---|
904 |
|
---|
905 | /** CPUM part. */
|
---|
906 | union
|
---|
907 | {
|
---|
908 | #ifdef ___CPUMInternal_h
|
---|
909 | struct CPUM s;
|
---|
910 | #endif
|
---|
911 | uint8_t padding[1536]; /* multiple of 64 */
|
---|
912 | } cpum;
|
---|
913 |
|
---|
914 | /** VMM part. */
|
---|
915 | union
|
---|
916 | {
|
---|
917 | #ifdef ___VMMInternal_h
|
---|
918 | struct VMM s;
|
---|
919 | #endif
|
---|
920 | uint8_t padding[1600]; /* multiple of 64 */
|
---|
921 | } vmm;
|
---|
922 |
|
---|
923 | /** PGM part. */
|
---|
924 | union
|
---|
925 | {
|
---|
926 | #ifdef ___PGMInternal_h
|
---|
927 | struct PGM s;
|
---|
928 | #endif
|
---|
929 | uint8_t padding[4096*2+6080]; /* multiple of 64 */
|
---|
930 | } pgm;
|
---|
931 |
|
---|
932 | /** HM part. */
|
---|
933 | union
|
---|
934 | {
|
---|
935 | #ifdef ___HMInternal_h
|
---|
936 | struct HM s;
|
---|
937 | #endif
|
---|
938 | uint8_t padding[5376]; /* multiple of 64 */
|
---|
939 | } hm;
|
---|
940 |
|
---|
941 | /** TRPM part. */
|
---|
942 | union
|
---|
943 | {
|
---|
944 | #ifdef ___TRPMInternal_h
|
---|
945 | struct TRPM s;
|
---|
946 | #endif
|
---|
947 | uint8_t padding[5248]; /* multiple of 64 */
|
---|
948 | } trpm;
|
---|
949 |
|
---|
950 | /** SELM part. */
|
---|
951 | union
|
---|
952 | {
|
---|
953 | #ifdef ___SELMInternal_h
|
---|
954 | struct SELM s;
|
---|
955 | #endif
|
---|
956 | uint8_t padding[768]; /* multiple of 64 */
|
---|
957 | } selm;
|
---|
958 |
|
---|
959 | /** MM part. */
|
---|
960 | union
|
---|
961 | {
|
---|
962 | #ifdef ___MMInternal_h
|
---|
963 | struct MM s;
|
---|
964 | #endif
|
---|
965 | uint8_t padding[192]; /* multiple of 64 */
|
---|
966 | } mm;
|
---|
967 |
|
---|
968 | /** PDM part. */
|
---|
969 | union
|
---|
970 | {
|
---|
971 | #ifdef ___PDMInternal_h
|
---|
972 | struct PDM s;
|
---|
973 | #endif
|
---|
974 | uint8_t padding[1920]; /* multiple of 64 */
|
---|
975 | } pdm;
|
---|
976 |
|
---|
977 | /** IOM part. */
|
---|
978 | union
|
---|
979 | {
|
---|
980 | #ifdef ___IOMInternal_h
|
---|
981 | struct IOM s;
|
---|
982 | #endif
|
---|
983 | uint8_t padding[832]; /* multiple of 64 */
|
---|
984 | } iom;
|
---|
985 |
|
---|
986 | /** PATM part. */
|
---|
987 | union
|
---|
988 | {
|
---|
989 | #ifdef ___PATMInternal_h
|
---|
990 | struct PATM s;
|
---|
991 | #endif
|
---|
992 | uint8_t padding[768]; /* multiple of 64 */
|
---|
993 | } patm;
|
---|
994 |
|
---|
995 | /** CSAM part. */
|
---|
996 | union
|
---|
997 | {
|
---|
998 | #ifdef ___CSAMInternal_h
|
---|
999 | struct CSAM s;
|
---|
1000 | #endif
|
---|
1001 | uint8_t padding[1088]; /* multiple of 64 */
|
---|
1002 | } csam;
|
---|
1003 |
|
---|
1004 | /** EM part. */
|
---|
1005 | union
|
---|
1006 | {
|
---|
1007 | #ifdef ___EMInternal_h
|
---|
1008 | struct EM s;
|
---|
1009 | #endif
|
---|
1010 | uint8_t padding[256]; /* multiple of 64 */
|
---|
1011 | } em;
|
---|
1012 |
|
---|
1013 | /** TM part. */
|
---|
1014 | union
|
---|
1015 | {
|
---|
1016 | #ifdef ___TMInternal_h
|
---|
1017 | struct TM s;
|
---|
1018 | #endif
|
---|
1019 | uint8_t padding[2432]; /* multiple of 64 */
|
---|
1020 | } tm;
|
---|
1021 |
|
---|
1022 | /** DBGF part. */
|
---|
1023 | union
|
---|
1024 | {
|
---|
1025 | #ifdef ___DBGFInternal_h
|
---|
1026 | struct DBGF s;
|
---|
1027 | #endif
|
---|
1028 | uint8_t padding[2368]; /* multiple of 64 */
|
---|
1029 | } dbgf;
|
---|
1030 |
|
---|
1031 | /** SSM part. */
|
---|
1032 | union
|
---|
1033 | {
|
---|
1034 | #ifdef ___SSMInternal_h
|
---|
1035 | struct SSM s;
|
---|
1036 | #endif
|
---|
1037 | uint8_t padding[128]; /* multiple of 64 */
|
---|
1038 | } ssm;
|
---|
1039 |
|
---|
1040 | /** FTM part. */
|
---|
1041 | union
|
---|
1042 | {
|
---|
1043 | #ifdef ___FTMInternal_h
|
---|
1044 | struct FTM s;
|
---|
1045 | #endif
|
---|
1046 | uint8_t padding[512]; /* multiple of 64 */
|
---|
1047 | } ftm;
|
---|
1048 |
|
---|
1049 | /** REM part. */
|
---|
1050 | union
|
---|
1051 | {
|
---|
1052 | #ifdef ___REMInternal_h
|
---|
1053 | struct REM s;
|
---|
1054 | #endif
|
---|
1055 | uint8_t padding[0x11100]; /* multiple of 64 */
|
---|
1056 | } rem;
|
---|
1057 |
|
---|
1058 | /* ---- begin small stuff ---- */
|
---|
1059 |
|
---|
1060 | /** VM part. */
|
---|
1061 | union
|
---|
1062 | {
|
---|
1063 | #ifdef ___VMInternal_h
|
---|
1064 | struct VMINT s;
|
---|
1065 | #endif
|
---|
1066 | uint8_t padding[24]; /* multiple of 8 */
|
---|
1067 | } vm;
|
---|
1068 |
|
---|
1069 | /** CFGM part. */
|
---|
1070 | union
|
---|
1071 | {
|
---|
1072 | #ifdef ___CFGMInternal_h
|
---|
1073 | struct CFGM s;
|
---|
1074 | #endif
|
---|
1075 | uint8_t padding[8]; /* multiple of 8 */
|
---|
1076 | } cfgm;
|
---|
1077 |
|
---|
1078 |
|
---|
1079 | /** Padding for aligning the cpu array on a page boundary. */
|
---|
1080 | uint8_t abAlignment2[542];
|
---|
1081 |
|
---|
1082 | /* ---- end small stuff ---- */
|
---|
1083 |
|
---|
1084 | /** VMCPU array for the configured number of virtual CPUs.
|
---|
1085 | * Must be aligned on a page boundary for TLB hit reasons as well as
|
---|
1086 | * alignment of VMCPU members. */
|
---|
1087 | VMCPU aCpus[1];
|
---|
1088 | } VM;
|
---|
1089 |
|
---|
1090 |
|
---|
1091 | #ifdef IN_RC
|
---|
1092 | RT_C_DECLS_BEGIN
|
---|
1093 |
|
---|
1094 | /** The VM structure.
|
---|
1095 | * This is imported from the VMMGCBuiltin module, i.e. it's a one
|
---|
1096 | * of those magic globals which we should avoid using.
|
---|
1097 | */
|
---|
1098 | extern DECLIMPORT(VM) g_VM;
|
---|
1099 |
|
---|
1100 | RT_C_DECLS_END
|
---|
1101 | #endif
|
---|
1102 |
|
---|
1103 | /** @} */
|
---|
1104 |
|
---|
1105 | #endif
|
---|
1106 |
|
---|