1 | /** @file
|
---|
2 | * VM - The Virtual Machine, data.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2017 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 <iprt/param.h>
|
---|
31 | # include <VBox/types.h>
|
---|
32 | # include <VBox/vmm/cpum.h>
|
---|
33 | # include <VBox/vmm/stam.h>
|
---|
34 | # include <VBox/vmm/vmapi.h>
|
---|
35 | # include <VBox/vmm/vmm.h>
|
---|
36 | # include <VBox/sup.h>
|
---|
37 | #else
|
---|
38 | # pragma D depends_on library vbox-types.d
|
---|
39 | # pragma D depends_on library CPUMInternal.d
|
---|
40 | # define ___CPUMInternal_h
|
---|
41 | #endif
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 | /** @defgroup grp_vm The Virtual Machine
|
---|
46 | * @ingroup grp_vmm
|
---|
47 | * @{
|
---|
48 | */
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * The state of a Virtual CPU.
|
---|
52 | *
|
---|
53 | * The basic state indicated here is whether the CPU has been started or not. In
|
---|
54 | * addition, there are sub-states when started for assisting scheduling (GVMM
|
---|
55 | * mostly).
|
---|
56 | *
|
---|
57 | * The transition out of the STOPPED state is done by a vmR3PowerOn.
|
---|
58 | * The transition back to the STOPPED state is done by vmR3PowerOff.
|
---|
59 | *
|
---|
60 | * (Alternatively we could let vmR3PowerOn start CPU 0 only and let the SPIP
|
---|
61 | * handling switch on the other CPUs. Then vmR3Reset would stop all but CPU 0.)
|
---|
62 | */
|
---|
63 | typedef enum VMCPUSTATE
|
---|
64 | {
|
---|
65 | /** The customary invalid zero. */
|
---|
66 | VMCPUSTATE_INVALID = 0,
|
---|
67 |
|
---|
68 | /** Virtual CPU has not yet been started. */
|
---|
69 | VMCPUSTATE_STOPPED,
|
---|
70 |
|
---|
71 | /** CPU started. */
|
---|
72 | VMCPUSTATE_STARTED,
|
---|
73 | /** CPU started in HM context. */
|
---|
74 | VMCPUSTATE_STARTED_HM,
|
---|
75 | /** Executing guest code and can be poked (RC or STI bits of HM). */
|
---|
76 | VMCPUSTATE_STARTED_EXEC,
|
---|
77 | /** Executing guest code in the recompiler. */
|
---|
78 | VMCPUSTATE_STARTED_EXEC_REM,
|
---|
79 | /** Executing guest code using NEM. */
|
---|
80 | VMCPUSTATE_STARTED_EXEC_NEM,
|
---|
81 | VMCPUSTATE_STARTED_EXEC_NEM_WAIT,
|
---|
82 | VMCPUSTATE_STARTED_EXEC_NEM_CANCELED,
|
---|
83 | /** Halted. */
|
---|
84 | VMCPUSTATE_STARTED_HALTED,
|
---|
85 |
|
---|
86 | /** The end of valid virtual CPU states. */
|
---|
87 | VMCPUSTATE_END,
|
---|
88 |
|
---|
89 | /** Ensure 32-bit type. */
|
---|
90 | VMCPUSTATE_32BIT_HACK = 0x7fffffff
|
---|
91 | } VMCPUSTATE;
|
---|
92 |
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * The cross context virtual CPU structure.
|
---|
96 | *
|
---|
97 | * Run 'kmk run-struct-tests' (from src/VBox/VMM if you like) after updating!
|
---|
98 | */
|
---|
99 | typedef struct VMCPU
|
---|
100 | {
|
---|
101 | /** Per CPU forced action.
|
---|
102 | * See the VMCPU_FF_* \#defines. Updated atomically. */
|
---|
103 | uint32_t volatile fLocalForcedActions; /* 0 */
|
---|
104 | /** The CPU state. */
|
---|
105 | VMCPUSTATE volatile enmState; /* 4 */
|
---|
106 |
|
---|
107 | /** Pointer to the ring-3 UVMCPU structure. */
|
---|
108 | PUVMCPU pUVCpu; /* 8 */
|
---|
109 | /** Ring-3 Host Context VM Pointer. */
|
---|
110 | PVMR3 pVMR3; /* 16 / 12 */
|
---|
111 | /** Ring-0 Host Context VM Pointer. */
|
---|
112 | PVMR0 pVMR0; /* 24 / 16 */
|
---|
113 | /** Raw-mode Context VM Pointer. */
|
---|
114 | PVMRC pVMRC; /* 32 / 20 */
|
---|
115 | /** The CPU ID.
|
---|
116 | * This is the index into the VM::aCpu array. */
|
---|
117 | VMCPUID idCpu; /* 36 / 24 */
|
---|
118 | /** The native thread handle. */
|
---|
119 | RTNATIVETHREAD hNativeThread; /* 40 / 28 */
|
---|
120 | /** The native R0 thread handle. (different from the R3 handle!) */
|
---|
121 | RTNATIVETHREAD hNativeThreadR0; /* 48 / 32 */
|
---|
122 | /** Which host CPU ID is this EMT running on.
|
---|
123 | * Only valid when in RC or HMR0 with scheduling disabled. */
|
---|
124 | RTCPUID volatile idHostCpu; /* 56 / 36 */
|
---|
125 | /** The CPU set index corresponding to idHostCpu, UINT32_MAX if not valid.
|
---|
126 | * @remarks Best to make sure iHostCpuSet shares cache line with idHostCpu! */
|
---|
127 | uint32_t volatile iHostCpuSet; /* 60 / 40 */
|
---|
128 |
|
---|
129 | #if HC_ARCH_BITS == 32
|
---|
130 | /** Align the structures below bit on a 64-byte boundary and make sure it starts
|
---|
131 | * at the same offset in both 64-bit and 32-bit builds.
|
---|
132 | *
|
---|
133 | * @remarks The alignments of the members that are larger than 48 bytes should be
|
---|
134 | * 64-byte for cache line reasons. structs containing small amounts of
|
---|
135 | * data could be lumped together at the end with a < 64 byte padding
|
---|
136 | * following it (to grow into and align the struct size).
|
---|
137 | */
|
---|
138 | uint8_t abAlignment1[HC_ARCH_BITS == 64 ? 0 : 20];
|
---|
139 | #endif
|
---|
140 |
|
---|
141 | /** IEM part.
|
---|
142 | * @remarks This comes first as it allows the use of 8-bit immediates for the
|
---|
143 | * first 64 bytes of the structure, reducing code size a wee bit. */
|
---|
144 | #ifdef ___IEMInternal_h /* For PDB hacking. */
|
---|
145 | union VMCPUUNIONIEMFULL
|
---|
146 | #else
|
---|
147 | union VMCPUUNIONIEMSTUB
|
---|
148 | #endif
|
---|
149 | {
|
---|
150 | #ifdef ___IEMInternal_h
|
---|
151 | struct IEMCPU s;
|
---|
152 | #endif
|
---|
153 | uint8_t padding[18496]; /* multiple of 64 */
|
---|
154 | } iem;
|
---|
155 |
|
---|
156 | /** HM part. */
|
---|
157 | union VMCPUUNIONHM
|
---|
158 | {
|
---|
159 | #ifdef ___HMInternal_h
|
---|
160 | struct HMCPU s;
|
---|
161 | #endif
|
---|
162 | uint8_t padding[5888]; /* multiple of 64 */
|
---|
163 | } hm;
|
---|
164 |
|
---|
165 | /** NEM part. */
|
---|
166 | union VMCPUUNIONNEM
|
---|
167 | {
|
---|
168 | #ifdef ___NEMInternal_h
|
---|
169 | struct NEMCPU s;
|
---|
170 | #endif
|
---|
171 | uint8_t padding[512]; /* multiple of 64 */
|
---|
172 | } nem;
|
---|
173 |
|
---|
174 | /** TRPM part. */
|
---|
175 | union VMCPUUNIONTRPM
|
---|
176 | {
|
---|
177 | #ifdef ___TRPMInternal_h
|
---|
178 | struct TRPMCPU s;
|
---|
179 | #endif
|
---|
180 | uint8_t padding[128]; /* multiple of 64 */
|
---|
181 | } trpm;
|
---|
182 |
|
---|
183 | /** TM part. */
|
---|
184 | union VMCPUUNIONTM
|
---|
185 | {
|
---|
186 | #ifdef ___TMInternal_h
|
---|
187 | struct TMCPU s;
|
---|
188 | #endif
|
---|
189 | uint8_t padding[384]; /* multiple of 64 */
|
---|
190 | } tm;
|
---|
191 |
|
---|
192 | /** VMM part. */
|
---|
193 | union VMCPUUNIONVMM
|
---|
194 | {
|
---|
195 | #ifdef ___VMMInternal_h
|
---|
196 | struct VMMCPU s;
|
---|
197 | #endif
|
---|
198 | uint8_t padding[768]; /* multiple of 64 */
|
---|
199 | } vmm;
|
---|
200 |
|
---|
201 | /** PDM part. */
|
---|
202 | union VMCPUUNIONPDM
|
---|
203 | {
|
---|
204 | #ifdef ___PDMInternal_h
|
---|
205 | struct PDMCPU s;
|
---|
206 | #endif
|
---|
207 | uint8_t padding[256]; /* multiple of 64 */
|
---|
208 | } pdm;
|
---|
209 |
|
---|
210 | /** IOM part. */
|
---|
211 | union VMCPUUNIONIOM
|
---|
212 | {
|
---|
213 | #ifdef ___IOMInternal_h
|
---|
214 | struct IOMCPU s;
|
---|
215 | #endif
|
---|
216 | uint8_t padding[512]; /* multiple of 64 */
|
---|
217 | } iom;
|
---|
218 |
|
---|
219 | /** DBGF part.
|
---|
220 | * @todo Combine this with other tiny structures. */
|
---|
221 | union VMCPUUNIONDBGF
|
---|
222 | {
|
---|
223 | #ifdef ___DBGFInternal_h
|
---|
224 | struct DBGFCPU s;
|
---|
225 | #endif
|
---|
226 | uint8_t padding[256]; /* multiple of 64 */
|
---|
227 | } dbgf;
|
---|
228 |
|
---|
229 | /** GIM part. */
|
---|
230 | union VMCPUUNIONGIM
|
---|
231 | {
|
---|
232 | #ifdef ___GIMInternal_h
|
---|
233 | struct GIMCPU s;
|
---|
234 | #endif
|
---|
235 | uint8_t padding[512]; /* multiple of 64 */
|
---|
236 | } gim;
|
---|
237 |
|
---|
238 | /** APIC part. */
|
---|
239 | union VMCPUUNIONAPIC
|
---|
240 | {
|
---|
241 | #ifdef ___APICInternal_h
|
---|
242 | struct APICCPU s;
|
---|
243 | #endif
|
---|
244 | uint8_t padding[1792]; /* multiple of 64 */
|
---|
245 | } apic;
|
---|
246 |
|
---|
247 | /*
|
---|
248 | * Some less frequently used global members that doesn't need to take up
|
---|
249 | * precious space at the head of the structure.
|
---|
250 | */
|
---|
251 |
|
---|
252 | /** Trace groups enable flags. */
|
---|
253 | uint32_t fTraceGroups; /* 64 / 44 */
|
---|
254 | /** State data for use by ad hoc profiling. */
|
---|
255 | uint32_t uAdHoc;
|
---|
256 | /** Profiling samples for use by ad hoc profiling. */
|
---|
257 | STAMPROFILEADV aStatAdHoc[8]; /* size: 40*8 = 320 */
|
---|
258 |
|
---|
259 | /** Align the following members on page boundary. */
|
---|
260 | uint8_t abAlignment2[2872];
|
---|
261 |
|
---|
262 | /** PGM part. */
|
---|
263 | union VMCPUUNIONPGM
|
---|
264 | {
|
---|
265 | #ifdef ___PGMInternal_h
|
---|
266 | struct PGMCPU s;
|
---|
267 | #endif
|
---|
268 | uint8_t padding[4096]; /* multiple of 4096 */
|
---|
269 | } pgm;
|
---|
270 |
|
---|
271 | /** CPUM part. */
|
---|
272 | union VMCPUUNIONCPUM
|
---|
273 | {
|
---|
274 | #ifdef ___CPUMInternal_h
|
---|
275 | struct CPUMCPU s;
|
---|
276 | #endif
|
---|
277 | #ifdef VMCPU_INCL_CPUM_GST_CTX
|
---|
278 | /** The guest CPUM context for direct use by execution engines.
|
---|
279 | * This is not for general consumption, but for HM, REM, IEM, and maybe a few
|
---|
280 | * others. The rest will use the function based CPUM API. */
|
---|
281 | CPUMCTX GstCtx;
|
---|
282 | #endif
|
---|
283 | uint8_t padding[4096]; /* multiple of 4096 */
|
---|
284 | } cpum;
|
---|
285 |
|
---|
286 | /** EM part. */
|
---|
287 | union VMCPUUNIONEM
|
---|
288 | {
|
---|
289 | #ifdef ___EMInternal_h
|
---|
290 | struct EMCPU s;
|
---|
291 | #endif
|
---|
292 | uint8_t padding[40960]; /* multiple of 4096 */
|
---|
293 | } em;
|
---|
294 | } VMCPU;
|
---|
295 |
|
---|
296 |
|
---|
297 | #ifndef VBOX_FOR_DTRACE_LIB
|
---|
298 |
|
---|
299 | /** @name Operations on VMCPU::enmState
|
---|
300 | * @{ */
|
---|
301 | /** Gets the VMCPU state. */
|
---|
302 | #define VMCPU_GET_STATE(pVCpu) ( (pVCpu)->enmState )
|
---|
303 | /** Sets the VMCPU state. */
|
---|
304 | #define VMCPU_SET_STATE(pVCpu, enmNewState) \
|
---|
305 | ASMAtomicWriteU32((uint32_t volatile *)&(pVCpu)->enmState, (enmNewState))
|
---|
306 | /** Cmpares and sets the VMCPU state. */
|
---|
307 | #define VMCPU_CMPXCHG_STATE(pVCpu, enmNewState, enmOldState) \
|
---|
308 | ASMAtomicCmpXchgU32((uint32_t volatile *)&(pVCpu)->enmState, (enmNewState), (enmOldState))
|
---|
309 | /** Checks the VMCPU state. */
|
---|
310 | #ifdef VBOX_STRICT
|
---|
311 | # define VMCPU_ASSERT_STATE(pVCpu, enmExpectedState) \
|
---|
312 | do { \
|
---|
313 | VMCPUSTATE enmState = VMCPU_GET_STATE(pVCpu); \
|
---|
314 | AssertMsg(enmState == (enmExpectedState), \
|
---|
315 | ("enmState=%d enmExpectedState=%d idCpu=%u\n", \
|
---|
316 | enmState, enmExpectedState, (pVCpu)->idCpu)); \
|
---|
317 | } while (0)
|
---|
318 | #else
|
---|
319 | # define VMCPU_ASSERT_STATE(pVCpu, enmExpectedState) do { } while (0)
|
---|
320 | #endif
|
---|
321 | /** Tests if the state means that the CPU is started. */
|
---|
322 | #define VMCPUSTATE_IS_STARTED(enmState) ( (enmState) > VMCPUSTATE_STOPPED )
|
---|
323 | /** Tests if the state means that the CPU is stopped. */
|
---|
324 | #define VMCPUSTATE_IS_STOPPED(enmState) ( (enmState) == VMCPUSTATE_STOPPED )
|
---|
325 | /** @} */
|
---|
326 |
|
---|
327 |
|
---|
328 | /** The name of the raw-mode context VMM Core module. */
|
---|
329 | #define VMMRC_MAIN_MODULE_NAME "VMMRC.rc"
|
---|
330 | /** The name of the ring-0 context VMM Core module. */
|
---|
331 | #define VMMR0_MAIN_MODULE_NAME "VMMR0.r0"
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * Wrapper macro for avoiding too much \#ifdef VBOX_WITH_RAW_MODE.
|
---|
335 | */
|
---|
336 | #ifdef VBOX_WITH_RAW_MODE
|
---|
337 | # define VM_WHEN_RAW_MODE(a_WithExpr, a_WithoutExpr) a_WithExpr
|
---|
338 | #else
|
---|
339 | # define VM_WHEN_RAW_MODE(a_WithExpr, a_WithoutExpr) a_WithoutExpr
|
---|
340 | #endif
|
---|
341 |
|
---|
342 |
|
---|
343 | /** VM Forced Action Flags.
|
---|
344 | *
|
---|
345 | * Use the VM_FF_SET() and VM_FF_CLEAR() macros to change the force
|
---|
346 | * action mask of a VM.
|
---|
347 | *
|
---|
348 | * Available VM bits:
|
---|
349 | * 0, 1, 5, 6, 7, 13, 14, 15, 16, 17, 21, 22, 23, 24, 25, 26, 27, 28, 30
|
---|
350 | *
|
---|
351 | *
|
---|
352 | * Available VMCPU bits:
|
---|
353 | * 14, 15
|
---|
354 | *
|
---|
355 | * @todo If we run low on VMCPU, we may consider merging the SELM bits
|
---|
356 | *
|
---|
357 | * @{
|
---|
358 | */
|
---|
359 | /** The virtual sync clock has been stopped, go to TM until it has been
|
---|
360 | * restarted... */
|
---|
361 | #define VM_FF_TM_VIRTUAL_SYNC RT_BIT_32(2)
|
---|
362 | /** PDM Queues are pending. */
|
---|
363 | #define VM_FF_PDM_QUEUES RT_BIT_32(VM_FF_PDM_QUEUES_BIT)
|
---|
364 | /** The bit number for VM_FF_PDM_QUEUES. */
|
---|
365 | #define VM_FF_PDM_QUEUES_BIT 3
|
---|
366 | /** PDM DMA transfers are pending. */
|
---|
367 | #define VM_FF_PDM_DMA RT_BIT_32(VM_FF_PDM_DMA_BIT)
|
---|
368 | /** The bit number for VM_FF_PDM_DMA. */
|
---|
369 | #define VM_FF_PDM_DMA_BIT 4
|
---|
370 | /** This action forces the VM to call DBGF so DBGF can service debugger
|
---|
371 | * requests in the emulation thread.
|
---|
372 | * This action flag stays asserted till DBGF clears it.*/
|
---|
373 | #define VM_FF_DBGF RT_BIT_32(VM_FF_DBGF_BIT)
|
---|
374 | /** The bit number for VM_FF_DBGF. */
|
---|
375 | #define VM_FF_DBGF_BIT 8
|
---|
376 | /** This action forces the VM to service pending requests from other
|
---|
377 | * thread or requests which must be executed in another context. */
|
---|
378 | #define VM_FF_REQUEST RT_BIT_32(9)
|
---|
379 | /** Check for VM state changes and take appropriate action. */
|
---|
380 | #define VM_FF_CHECK_VM_STATE RT_BIT_32(VM_FF_CHECK_VM_STATE_BIT)
|
---|
381 | /** The bit number for VM_FF_CHECK_VM_STATE. */
|
---|
382 | #define VM_FF_CHECK_VM_STATE_BIT 10
|
---|
383 | /** Reset the VM. (postponed) */
|
---|
384 | #define VM_FF_RESET RT_BIT_32(VM_FF_RESET_BIT)
|
---|
385 | /** The bit number for VM_FF_RESET. */
|
---|
386 | #define VM_FF_RESET_BIT 11
|
---|
387 | /** EMT rendezvous in VMM. */
|
---|
388 | #define VM_FF_EMT_RENDEZVOUS RT_BIT_32(VM_FF_EMT_RENDEZVOUS_BIT)
|
---|
389 | /** The bit number for VM_FF_EMT_RENDEZVOUS. */
|
---|
390 | #define VM_FF_EMT_RENDEZVOUS_BIT 12
|
---|
391 |
|
---|
392 | /** PGM needs to allocate handy pages. */
|
---|
393 | #define VM_FF_PGM_NEED_HANDY_PAGES RT_BIT_32(18)
|
---|
394 | /** PGM is out of memory.
|
---|
395 | * Abandon all loops and code paths which can be resumed and get up to the EM
|
---|
396 | * loops. */
|
---|
397 | #define VM_FF_PGM_NO_MEMORY RT_BIT_32(19)
|
---|
398 | /** PGM is about to perform a lightweight pool flush
|
---|
399 | * Guest SMP: all EMT threads should return to ring 3
|
---|
400 | */
|
---|
401 | #define VM_FF_PGM_POOL_FLUSH_PENDING RT_BIT_32(20)
|
---|
402 | /** REM needs to be informed about handler changes. */
|
---|
403 | #define VM_FF_REM_HANDLER_NOTIFY RT_BIT_32(VM_FF_REM_HANDLER_NOTIFY_BIT)
|
---|
404 | /** The bit number for VM_FF_REM_HANDLER_NOTIFY. */
|
---|
405 | #define VM_FF_REM_HANDLER_NOTIFY_BIT 29
|
---|
406 | /** Suspend the VM - debug only. */
|
---|
407 | #define VM_FF_DEBUG_SUSPEND RT_BIT_32(31)
|
---|
408 |
|
---|
409 |
|
---|
410 | /** This action forces the VM to check any pending interrupts on the APIC. */
|
---|
411 | #define VMCPU_FF_INTERRUPT_APIC RT_BIT_32(0)
|
---|
412 | /** This action forces the VM to check any pending interrups on the PIC. */
|
---|
413 | #define VMCPU_FF_INTERRUPT_PIC RT_BIT_32(1)
|
---|
414 | /** This action forces the VM to schedule and run pending timer (TM).
|
---|
415 | * @remarks Don't move - PATM compatibility. */
|
---|
416 | #define VMCPU_FF_TIMER RT_BIT_32(2)
|
---|
417 | /** This action forces the VM to check any pending NMIs. */
|
---|
418 | #define VMCPU_FF_INTERRUPT_NMI_BIT 3
|
---|
419 | #define VMCPU_FF_INTERRUPT_NMI RT_BIT_32(VMCPU_FF_INTERRUPT_NMI_BIT)
|
---|
420 | /** This action forces the VM to check any pending SMIs. */
|
---|
421 | #define VMCPU_FF_INTERRUPT_SMI_BIT 4
|
---|
422 | #define VMCPU_FF_INTERRUPT_SMI RT_BIT_32(VMCPU_FF_INTERRUPT_SMI_BIT)
|
---|
423 | /** PDM critical section unlocking is pending, process promptly upon return to R3. */
|
---|
424 | #define VMCPU_FF_PDM_CRITSECT RT_BIT_32(5)
|
---|
425 | /** Special EM internal force flag that is used by EMUnhaltAndWakeUp() to force
|
---|
426 | * the virtual CPU out of the next (/current) halted state. It is not processed
|
---|
427 | * nor cleared by emR3ForcedActions (similar to VMCPU_FF_BLOCK_NMIS), instead it
|
---|
428 | * is cleared the next time EM leaves the HALTED state. */
|
---|
429 | #define VMCPU_FF_UNHALT RT_BIT_32(6)
|
---|
430 | /** Pending IEM action (bit number). */
|
---|
431 | #define VMCPU_FF_IEM_BIT 7
|
---|
432 | /** Pending IEM action (mask). */
|
---|
433 | #define VMCPU_FF_IEM RT_BIT_32(VMCPU_FF_IEM_BIT)
|
---|
434 | /** Pending APIC action (bit number). */
|
---|
435 | #define VMCPU_FF_UPDATE_APIC_BIT 8
|
---|
436 | /** This action forces the VM to update APIC's asynchronously arrived
|
---|
437 | * interrupts as pending interrupts. */
|
---|
438 | #define VMCPU_FF_UPDATE_APIC RT_BIT_32(VMCPU_FF_UPDATE_APIC_BIT)
|
---|
439 | /** This action forces the VM to service pending requests from other
|
---|
440 | * thread or requests which must be executed in another context. */
|
---|
441 | #define VMCPU_FF_REQUEST RT_BIT_32(9)
|
---|
442 | /** Pending DBGF event (alternative to passing VINF_EM_DBG_EVENT around). */
|
---|
443 | #define VMCPU_FF_DBGF RT_BIT_32(VMCPU_FF_DBGF_BIT)
|
---|
444 | /** The bit number for VMCPU_FF_DBGF. */
|
---|
445 | #define VMCPU_FF_DBGF_BIT 10
|
---|
446 | /** Pending MTF (Monitor Trap Flag) event - Intel only. */
|
---|
447 | #define VMCPU_FF_MTF RT_BIT_32(VMCPU_FF_MTF_BIT)
|
---|
448 | /** The bit number for VMCPU_FF_MTF. */
|
---|
449 | #define VMCPU_FF_MTF_BIT 11
|
---|
450 | /** This action forces the VM to service any pending updates to CR3 (used only
|
---|
451 | * by HM). */
|
---|
452 | #define VMCPU_FF_HM_UPDATE_CR3 RT_BIT_32(12)
|
---|
453 | /** This action forces the VM to service any pending updates to PAE PDPEs (used
|
---|
454 | * only by HM). */
|
---|
455 | #define VMCPU_FF_HM_UPDATE_PAE_PDPES RT_BIT_32(13)
|
---|
456 | /** This action forces the VM to resync the page tables before going
|
---|
457 | * back to execute guest code. (GLOBAL FLUSH) */
|
---|
458 | #define VMCPU_FF_PGM_SYNC_CR3 RT_BIT_32(16)
|
---|
459 | /** Same as VM_FF_PGM_SYNC_CR3 except that global pages can be skipped.
|
---|
460 | * (NON-GLOBAL FLUSH) */
|
---|
461 | #define VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL RT_BIT_32(17)
|
---|
462 | /** Check for pending TLB shootdown actions (deprecated)
|
---|
463 | * Reserved for furture HM re-use if necessary / safe.
|
---|
464 | * Consumer: HM */
|
---|
465 | #define VMCPU_FF_TLB_SHOOTDOWN_UNUSED RT_BIT_32(18)
|
---|
466 | /** Check for pending TLB flush action.
|
---|
467 | * Consumer: HM
|
---|
468 | * @todo rename to VMCPU_FF_HM_TLB_FLUSH */
|
---|
469 | #define VMCPU_FF_TLB_FLUSH RT_BIT_32(VMCPU_FF_TLB_FLUSH_BIT)
|
---|
470 | /** The bit number for VMCPU_FF_TLB_FLUSH. */
|
---|
471 | #define VMCPU_FF_TLB_FLUSH_BIT 19
|
---|
472 | #ifdef VBOX_WITH_RAW_MODE
|
---|
473 | /** Check the interrupt and trap gates */
|
---|
474 | # define VMCPU_FF_TRPM_SYNC_IDT RT_BIT_32(20)
|
---|
475 | /** Check Guest's TSS ring 0 stack */
|
---|
476 | # define VMCPU_FF_SELM_SYNC_TSS RT_BIT_32(21)
|
---|
477 | /** Check Guest's GDT table */
|
---|
478 | # define VMCPU_FF_SELM_SYNC_GDT RT_BIT_32(22)
|
---|
479 | /** Check Guest's LDT table */
|
---|
480 | # define VMCPU_FF_SELM_SYNC_LDT RT_BIT_32(23)
|
---|
481 | #endif /* VBOX_WITH_RAW_MODE */
|
---|
482 | /** Inhibit interrupts pending. See EMGetInhibitInterruptsPC(). */
|
---|
483 | #define VMCPU_FF_INHIBIT_INTERRUPTS RT_BIT_32(24)
|
---|
484 | /** Block injection of non-maskable interrupts to the guest. */
|
---|
485 | #define VMCPU_FF_BLOCK_NMIS RT_BIT_32(25)
|
---|
486 | #ifdef VBOX_WITH_RAW_MODE
|
---|
487 | /** CSAM needs to scan the page that's being executed */
|
---|
488 | # define VMCPU_FF_CSAM_SCAN_PAGE RT_BIT_32(26)
|
---|
489 | /** CSAM needs to do some homework. */
|
---|
490 | # define VMCPU_FF_CSAM_PENDING_ACTION RT_BIT_32(27)
|
---|
491 | #endif /* VBOX_WITH_RAW_MODE */
|
---|
492 | /** Force return to Ring-3. */
|
---|
493 | #define VMCPU_FF_TO_R3 RT_BIT_32(28)
|
---|
494 | /** Force return to ring-3 to service pending I/O or MMIO write.
|
---|
495 | * This is a backup for mechanism VINF_IOM_R3_IOPORT_COMMIT_WRITE and
|
---|
496 | * VINF_IOM_R3_MMIO_COMMIT_WRITE, allowing VINF_EM_DBG_BREAKPOINT and similar
|
---|
497 | * status codes to be propagated at the same time without loss. */
|
---|
498 | #define VMCPU_FF_IOM RT_BIT_32(29)
|
---|
499 | #ifdef VBOX_WITH_RAW_MODE
|
---|
500 | /** CPUM need to adjust CR0.TS/EM before executing raw-mode code again. */
|
---|
501 | # define VMCPU_FF_CPUM RT_BIT_32(VMCPU_FF_CPUM_BIT)
|
---|
502 | /** The bit number for VMCPU_FF_CPUM. */
|
---|
503 | # define VMCPU_FF_CPUM_BIT 30
|
---|
504 | #endif /* VBOX_WITH_RAW_MODE */
|
---|
505 | /** Hardware virtualized nested-guest interrupt pending. */
|
---|
506 | #define VMCPU_FF_INTERRUPT_NESTED_GUEST RT_BIT_32(31)
|
---|
507 |
|
---|
508 | /** Externally VM forced actions. Used to quit the idle/wait loop. */
|
---|
509 | #define VM_FF_EXTERNAL_SUSPENDED_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_REQUEST | VM_FF_EMT_RENDEZVOUS )
|
---|
510 | /** Externally VMCPU forced actions. Used to quit the idle/wait loop. */
|
---|
511 | #define VMCPU_FF_EXTERNAL_SUSPENDED_MASK ( VMCPU_FF_REQUEST | VMCPU_FF_DBGF )
|
---|
512 |
|
---|
513 | /** Externally forced VM actions. Used to quit the idle/wait loop. */
|
---|
514 | #define VM_FF_EXTERNAL_HALTED_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_REQUEST \
|
---|
515 | | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_EMT_RENDEZVOUS )
|
---|
516 | /** Externally forced VMCPU actions. Used to quit the idle/wait loop. */
|
---|
517 | #define VMCPU_FF_EXTERNAL_HALTED_MASK ( VMCPU_FF_UPDATE_APIC | VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC \
|
---|
518 | | VMCPU_FF_REQUEST | VMCPU_FF_INTERRUPT_NMI | VMCPU_FF_INTERRUPT_SMI \
|
---|
519 | | VMCPU_FF_UNHALT | VMCPU_FF_TIMER | VMCPU_FF_DBGF )
|
---|
520 |
|
---|
521 | /** High priority VM pre-execution actions. */
|
---|
522 | #define VM_FF_HIGH_PRIORITY_PRE_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_TM_VIRTUAL_SYNC \
|
---|
523 | | VM_FF_DEBUG_SUSPEND | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY \
|
---|
524 | | VM_FF_EMT_RENDEZVOUS )
|
---|
525 | /** High priority VMCPU pre-execution actions. */
|
---|
526 | #define VMCPU_FF_HIGH_PRIORITY_PRE_MASK ( VMCPU_FF_TIMER | VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC \
|
---|
527 | | VMCPU_FF_UPDATE_APIC | VMCPU_FF_INHIBIT_INTERRUPTS | VMCPU_FF_DBGF \
|
---|
528 | | VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL \
|
---|
529 | | VM_WHEN_RAW_MODE( VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT \
|
---|
530 | | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT, 0 ) )
|
---|
531 |
|
---|
532 | /** High priority VM pre raw-mode execution mask. */
|
---|
533 | #define VM_FF_HIGH_PRIORITY_PRE_RAW_MASK ( VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY )
|
---|
534 | /** High priority VMCPU pre raw-mode execution mask. */
|
---|
535 | #define VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK ( VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL \
|
---|
536 | | VMCPU_FF_INHIBIT_INTERRUPTS \
|
---|
537 | | VM_WHEN_RAW_MODE( VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT \
|
---|
538 | | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT, 0) )
|
---|
539 |
|
---|
540 | /** High priority post-execution actions. */
|
---|
541 | #define VM_FF_HIGH_PRIORITY_POST_MASK ( VM_FF_PGM_NO_MEMORY )
|
---|
542 | /** High priority post-execution actions. */
|
---|
543 | #define VMCPU_FF_HIGH_PRIORITY_POST_MASK ( VMCPU_FF_PDM_CRITSECT | VM_WHEN_RAW_MODE(VMCPU_FF_CSAM_PENDING_ACTION, 0) \
|
---|
544 | | VMCPU_FF_HM_UPDATE_CR3 | VMCPU_FF_HM_UPDATE_PAE_PDPES \
|
---|
545 | | VMCPU_FF_IEM | VMCPU_FF_IOM )
|
---|
546 |
|
---|
547 | /** Normal priority VM post-execution actions. */
|
---|
548 | #define VM_FF_NORMAL_PRIORITY_POST_MASK ( VM_FF_CHECK_VM_STATE | VM_FF_DBGF | VM_FF_RESET \
|
---|
549 | | VM_FF_PGM_NO_MEMORY | VM_FF_EMT_RENDEZVOUS)
|
---|
550 | /** Normal priority VMCPU post-execution actions. */
|
---|
551 | #define VMCPU_FF_NORMAL_PRIORITY_POST_MASK ( VM_WHEN_RAW_MODE(VMCPU_FF_CSAM_SCAN_PAGE, 0) | VMCPU_FF_DBGF )
|
---|
552 |
|
---|
553 | /** Normal priority VM actions. */
|
---|
554 | #define VM_FF_NORMAL_PRIORITY_MASK ( VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA \
|
---|
555 | | VM_FF_REM_HANDLER_NOTIFY | VM_FF_EMT_RENDEZVOUS)
|
---|
556 | /** Normal priority VMCPU actions. */
|
---|
557 | #define VMCPU_FF_NORMAL_PRIORITY_MASK ( VMCPU_FF_REQUEST )
|
---|
558 |
|
---|
559 | /** Flags to clear before resuming guest execution. */
|
---|
560 | #define VMCPU_FF_RESUME_GUEST_MASK ( VMCPU_FF_TO_R3 )
|
---|
561 |
|
---|
562 |
|
---|
563 | /** VM flags that cause the REP[|NE|E] STRINS loops to yield immediately. */
|
---|
564 | #define VM_FF_HIGH_PRIORITY_POST_REPSTR_MASK ( VM_FF_TM_VIRTUAL_SYNC | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY \
|
---|
565 | | VM_FF_EMT_RENDEZVOUS | VM_FF_PGM_POOL_FLUSH_PENDING | VM_FF_RESET)
|
---|
566 | /** VM flags that cause the REP[|NE|E] STRINS loops to yield. */
|
---|
567 | #define VM_FF_YIELD_REPSTR_MASK ( VM_FF_HIGH_PRIORITY_POST_REPSTR_MASK \
|
---|
568 | | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_DBGF | VM_FF_DEBUG_SUSPEND )
|
---|
569 | /** VMCPU flags that cause the REP[|NE|E] STRINS loops to yield immediately. */
|
---|
570 | #ifdef IN_RING3
|
---|
571 | # define VMCPU_FF_HIGH_PRIORITY_POST_REPSTR_MASK ( VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_DBGF )
|
---|
572 | #else
|
---|
573 | # define VMCPU_FF_HIGH_PRIORITY_POST_REPSTR_MASK ( VMCPU_FF_TO_R3 | VMCPU_FF_IEM | VMCPU_FF_IOM | VMCPU_FF_PGM_SYNC_CR3 \
|
---|
574 | | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_DBGF )
|
---|
575 | #endif
|
---|
576 | /** VMCPU flags that cause the REP[|NE|E] STRINS loops to yield, interrupts
|
---|
577 | * enabled. */
|
---|
578 | #define VMCPU_FF_YIELD_REPSTR_MASK ( VMCPU_FF_HIGH_PRIORITY_POST_REPSTR_MASK \
|
---|
579 | | VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_UPDATE_APIC | VMCPU_FF_INTERRUPT_PIC \
|
---|
580 | | VMCPU_FF_INTERRUPT_NMI | VMCPU_FF_INTERRUPT_SMI | VMCPU_FF_PDM_CRITSECT \
|
---|
581 | | VMCPU_FF_TIMER | VMCPU_FF_REQUEST )
|
---|
582 | /** VMCPU flags that cause the REP[|NE|E] STRINS loops to yield, interrupts
|
---|
583 | * disabled. */
|
---|
584 | #define VMCPU_FF_YIELD_REPSTR_NOINT_MASK ( VMCPU_FF_YIELD_REPSTR_MASK \
|
---|
585 | & ~(VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_UPDATE_APIC | VMCPU_FF_INTERRUPT_PIC) )
|
---|
586 |
|
---|
587 | /** VM Flags that cause the HM loops to go back to ring-3. */
|
---|
588 | #define VM_FF_HM_TO_R3_MASK ( VM_FF_TM_VIRTUAL_SYNC | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY \
|
---|
589 | | VM_FF_PDM_QUEUES | VM_FF_EMT_RENDEZVOUS)
|
---|
590 | /** VMCPU Flags that cause the HM loops to go back to ring-3. */
|
---|
591 | #define VMCPU_FF_HM_TO_R3_MASK ( VMCPU_FF_TO_R3 | VMCPU_FF_TIMER | VMCPU_FF_PDM_CRITSECT \
|
---|
592 | | VMCPU_FF_IEM | VMCPU_FF_IOM)
|
---|
593 |
|
---|
594 | /** High priority ring-0 VM pre HM-mode execution mask. */
|
---|
595 | #define VM_FF_HP_R0_PRE_HM_MASK (VM_FF_HM_TO_R3_MASK | VM_FF_REQUEST | VM_FF_PGM_POOL_FLUSH_PENDING | VM_FF_PDM_DMA)
|
---|
596 | /** High priority ring-0 VMCPU pre HM-mode execution mask. */
|
---|
597 | #define VMCPU_FF_HP_R0_PRE_HM_MASK ( VMCPU_FF_HM_TO_R3_MASK | VMCPU_FF_PGM_SYNC_CR3 \
|
---|
598 | | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_REQUEST)
|
---|
599 | /** High priority ring-0 VM pre HM-mode execution mask, single stepping. */
|
---|
600 | #define VM_FF_HP_R0_PRE_HM_STEP_MASK (VM_FF_HP_R0_PRE_HM_MASK & ~( VM_FF_TM_VIRTUAL_SYNC | VM_FF_PDM_QUEUES \
|
---|
601 | | VM_FF_EMT_RENDEZVOUS | VM_FF_REQUEST \
|
---|
602 | | VM_FF_PDM_DMA) )
|
---|
603 | /** High priority ring-0 VMCPU pre HM-mode execution mask, single stepping. */
|
---|
604 | #define VMCPU_FF_HP_R0_PRE_HM_STEP_MASK (VMCPU_FF_HP_R0_PRE_HM_MASK & ~( VMCPU_FF_TO_R3 | VMCPU_FF_TIMER \
|
---|
605 | | VMCPU_FF_PDM_CRITSECT | VMCPU_FF_REQUEST) )
|
---|
606 |
|
---|
607 | /** All the forced VM flags. */
|
---|
608 | #define VM_FF_ALL_MASK (UINT32_MAX)
|
---|
609 | /** All the forced VMCPU flags. */
|
---|
610 | #define VMCPU_FF_ALL_MASK (UINT32_MAX)
|
---|
611 |
|
---|
612 | /** All the forced VM flags except those related to raw-mode and hardware
|
---|
613 | * assisted execution. */
|
---|
614 | #define VM_FF_ALL_REM_MASK (~(VM_FF_HIGH_PRIORITY_PRE_RAW_MASK) | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY)
|
---|
615 | /** All the forced VMCPU flags except those related to raw-mode and hardware
|
---|
616 | * assisted execution. */
|
---|
617 | #define VMCPU_FF_ALL_REM_MASK (~( VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK | VMCPU_FF_PDM_CRITSECT \
|
---|
618 | | VMCPU_FF_TLB_FLUSH | VM_WHEN_RAW_MODE(VMCPU_FF_CSAM_PENDING_ACTION, 0) ))
|
---|
619 | /** @} */
|
---|
620 |
|
---|
621 | /** @def VM_FF_SET
|
---|
622 | * Sets a force action flag.
|
---|
623 | *
|
---|
624 | * @param pVM The cross context VM structure.
|
---|
625 | * @param fFlag The flag to set.
|
---|
626 | */
|
---|
627 | #if 1
|
---|
628 | # define VM_FF_SET(pVM, fFlag) ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag))
|
---|
629 | #else
|
---|
630 | # define VM_FF_SET(pVM, fFlag) \
|
---|
631 | do { ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag)); \
|
---|
632 | RTLogPrintf("VM_FF_SET : %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
|
---|
633 | } while (0)
|
---|
634 | #endif
|
---|
635 |
|
---|
636 | /** @def VMCPU_FF_SET
|
---|
637 | * Sets a force action flag for the given VCPU.
|
---|
638 | *
|
---|
639 | * @param pVCpu The cross context virtual CPU structure.
|
---|
640 | * @param fFlag The flag to set.
|
---|
641 | */
|
---|
642 | #define VMCPU_FF_SET(pVCpu, fFlag) ASMAtomicOrU32(&(pVCpu)->fLocalForcedActions, (fFlag))
|
---|
643 |
|
---|
644 | /** @def VM_FF_CLEAR
|
---|
645 | * Clears a single force action flag.
|
---|
646 | *
|
---|
647 | * @param pVM The cross context VM structure.
|
---|
648 | * @param fFlag The flag to clear.
|
---|
649 | */
|
---|
650 | #if 1
|
---|
651 | # if !defined(VBOX_STRICT) || !defined(RT_COMPILER_SUPPORTS_LAMBDA)
|
---|
652 | # define VM_FF_CLEAR(pVM, fFlag) ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag))
|
---|
653 | # else
|
---|
654 | # define VM_FF_CLEAR(pVM, fFlag) \
|
---|
655 | ([](PVM a_pVM) -> void \
|
---|
656 | { \
|
---|
657 | AssertCompile(RT_IS_POWER_OF_TWO(fFlag)); \
|
---|
658 | ASMAtomicAndU32(&a_pVM->fGlobalForcedActions, ~(fFlag)); \
|
---|
659 | }(pVM))
|
---|
660 | # endif
|
---|
661 | #else
|
---|
662 | # define VM_FF_CLEAR(pVM, fFlag) \
|
---|
663 | do { ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag)); \
|
---|
664 | RTLogPrintf("VM_FF_CLEAR: %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
|
---|
665 | } while (0)
|
---|
666 | #endif
|
---|
667 |
|
---|
668 | /** @def VMCPU_FF_CLEAR
|
---|
669 | * Clears a single force action flag for the given VCPU.
|
---|
670 | *
|
---|
671 | * @param pVCpu The cross context virtual CPU structure.
|
---|
672 | * @param fFlag The flag to clear.
|
---|
673 | */
|
---|
674 | #if !defined(VBOX_STRICT) || !defined(RT_COMPILER_SUPPORTS_LAMBDA)
|
---|
675 | # define VMCPU_FF_CLEAR(pVCpu, fFlag) ASMAtomicAndU32(&(pVCpu)->fLocalForcedActions, ~(fFlag))
|
---|
676 | #else
|
---|
677 | # define VMCPU_FF_CLEAR(pVCpu, fFlag) \
|
---|
678 | ([](PVMCPU a_pVCpu) -> void \
|
---|
679 | { \
|
---|
680 | AssertCompile(RT_IS_POWER_OF_TWO(fFlag)); \
|
---|
681 | ASMAtomicAndU32(&a_pVCpu->fLocalForcedActions, ~(fFlag)); \
|
---|
682 | }(pVCpu))
|
---|
683 | #endif
|
---|
684 |
|
---|
685 | /** @def VMCPU_FF_CLEAR_MASK
|
---|
686 | * Clears two or more force action flags for the given VCPU.
|
---|
687 | *
|
---|
688 | * @param pVCpu The cross context virtual CPU structure.
|
---|
689 | * @param fFlags The flags to clear.
|
---|
690 | */
|
---|
691 | #define VMCPU_FF_CLEAR_MASK(pVCpu, fFlags) ASMAtomicAndU32(&(pVCpu)->fLocalForcedActions, ~(fFlags))
|
---|
692 |
|
---|
693 | /** @def VM_FF_IS_SET
|
---|
694 | * Checks if a force action flag is set.
|
---|
695 | *
|
---|
696 | * @param pVM The cross context VM structure.
|
---|
697 | * @param fFlag The flag to check.
|
---|
698 | */
|
---|
699 | #define VM_FF_IS_SET(pVM, fFlag) (((pVM)->fGlobalForcedActions & (fFlag)) == (fFlag))
|
---|
700 |
|
---|
701 |
|
---|
702 | /** @def VMCPU_FF_IS_SET
|
---|
703 | * Checks if a force action flag is set for the given VCPU.
|
---|
704 | *
|
---|
705 | * @param pVCpu The cross context virtual CPU structure.
|
---|
706 | * @param fFlag The flag to check.
|
---|
707 | * @sa VMCPU_FF_IS_ANY_SET
|
---|
708 | */
|
---|
709 | #if !defined(VBOX_STRICT) || !defined(RT_COMPILER_SUPPORTS_LAMBDA)
|
---|
710 | # define VMCPU_FF_IS_SET(pVCpu, fFlag) (((pVCpu)->fLocalForcedActions & (fFlag)) == (fFlag))
|
---|
711 | #else
|
---|
712 | # define VMCPU_FF_IS_SET(pVCpu, fFlag) \
|
---|
713 | ([](PVMCPU a_pVCpu) -> bool \
|
---|
714 | { \
|
---|
715 | AssertCompile(RT_IS_POWER_OF_TWO(fFlag)); \
|
---|
716 | return (a_pVCpu->fLocalForcedActions & (fFlag)) == (fFlag); \
|
---|
717 | }(pVCpu))
|
---|
718 | #endif
|
---|
719 |
|
---|
720 | /** @def VM_FF_IS_PENDING
|
---|
721 | * Checks if one or more force action in the specified set is pending.
|
---|
722 | *
|
---|
723 | * @param pVM The cross context VM structure.
|
---|
724 | * @param fFlags The flags to check for.
|
---|
725 | */
|
---|
726 | #define VM_FF_IS_PENDING(pVM, fFlags) RT_BOOL((pVM)->fGlobalForcedActions & (fFlags))
|
---|
727 |
|
---|
728 | /** @def VMCPU_FF_IS_ANY_SET
|
---|
729 | * Checks if two or more force action flags in the specified set is set for the given VCPU.
|
---|
730 | *
|
---|
731 | * @param pVCpu The cross context virtual CPU structure.
|
---|
732 | * @param fFlags The flags to check for.
|
---|
733 | * @sa VMCPU_FF_IS_SET
|
---|
734 | */
|
---|
735 | #define VMCPU_FF_IS_ANY_SET(pVCpu, fFlags) RT_BOOL((pVCpu)->fLocalForcedActions & (fFlags))
|
---|
736 |
|
---|
737 | /** @def VM_FF_TEST_AND_CLEAR
|
---|
738 | * Checks if one (!) force action in the specified set is pending and clears it atomically
|
---|
739 | *
|
---|
740 | * @returns true if the bit was set.
|
---|
741 | * @returns false if the bit was clear.
|
---|
742 | * @param pVM The cross context VM structure.
|
---|
743 | * @param fFlag Flag constant to check and clear (_BIT is appended).
|
---|
744 | */
|
---|
745 | #define VM_FF_TEST_AND_CLEAR(pVM, fFlag) (ASMAtomicBitTestAndClear(&(pVM)->fGlobalForcedActions, fFlag##_BIT))
|
---|
746 |
|
---|
747 | /** @def VMCPU_FF_TEST_AND_CLEAR
|
---|
748 | * Checks if one (!) force action in the specified set is pending and clears it atomically
|
---|
749 | *
|
---|
750 | * @returns true if the bit was set.
|
---|
751 | * @returns false if the bit was clear.
|
---|
752 | * @param pVCpu The cross context virtual CPU structure.
|
---|
753 | * @param fFlag Flag constant to check and clear (_BIT is appended).
|
---|
754 | */
|
---|
755 | #define VMCPU_FF_TEST_AND_CLEAR(pVCpu, fFlag) (ASMAtomicBitTestAndClear(&(pVCpu)->fLocalForcedActions, fFlag##_BIT))
|
---|
756 |
|
---|
757 | /** @def VM_FF_IS_PENDING_EXCEPT
|
---|
758 | * Checks if one or more force action in the specified set is pending while one
|
---|
759 | * or more other ones are not.
|
---|
760 | *
|
---|
761 | * @param pVM The cross context VM structure.
|
---|
762 | * @param fFlags The flags to check for.
|
---|
763 | * @param fExcpt The flags that should not be set.
|
---|
764 | */
|
---|
765 | #define VM_FF_IS_PENDING_EXCEPT(pVM, fFlags, fExcpt) \
|
---|
766 | ( ((pVM)->fGlobalForcedActions & (fFlags)) && !((pVM)->fGlobalForcedActions & (fExcpt)) )
|
---|
767 |
|
---|
768 | /** @def VM_IS_EMT
|
---|
769 | * Checks if the current thread is the emulation thread (EMT).
|
---|
770 | *
|
---|
771 | * @remark The ring-0 variation will need attention if we expand the ring-0
|
---|
772 | * code to let threads other than EMT mess around with the VM.
|
---|
773 | */
|
---|
774 | #ifdef IN_RC
|
---|
775 | # define VM_IS_EMT(pVM) true
|
---|
776 | #else
|
---|
777 | # define VM_IS_EMT(pVM) (VMMGetCpu(pVM) != NULL)
|
---|
778 | #endif
|
---|
779 |
|
---|
780 | /** @def VMCPU_IS_EMT
|
---|
781 | * Checks if the current thread is the emulation thread (EMT) for the specified
|
---|
782 | * virtual CPU.
|
---|
783 | */
|
---|
784 | #ifdef IN_RC
|
---|
785 | # define VMCPU_IS_EMT(pVCpu) true
|
---|
786 | #else
|
---|
787 | # define VMCPU_IS_EMT(pVCpu) ((pVCpu) && ((pVCpu) == VMMGetCpu((pVCpu)->CTX_SUFF(pVM))))
|
---|
788 | #endif
|
---|
789 |
|
---|
790 | /** @def VM_ASSERT_EMT
|
---|
791 | * Asserts that the current thread IS the emulation thread (EMT).
|
---|
792 | */
|
---|
793 | #ifdef IN_RC
|
---|
794 | # define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
|
---|
795 | #elif defined(IN_RING0)
|
---|
796 | # define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
|
---|
797 | #else
|
---|
798 | # define VM_ASSERT_EMT(pVM) \
|
---|
799 | AssertMsg(VM_IS_EMT(pVM), \
|
---|
800 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)))
|
---|
801 | #endif
|
---|
802 |
|
---|
803 | /** @def VMCPU_ASSERT_EMT
|
---|
804 | * Asserts that the current thread IS the emulation thread (EMT) of the
|
---|
805 | * specified virtual CPU.
|
---|
806 | */
|
---|
807 | #ifdef IN_RC
|
---|
808 | # define VMCPU_ASSERT_EMT(pVCpu) Assert(VMCPU_IS_EMT(pVCpu))
|
---|
809 | #elif defined(IN_RING0)
|
---|
810 | # define VMCPU_ASSERT_EMT(pVCpu) AssertMsg(VMCPU_IS_EMT(pVCpu), \
|
---|
811 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%u\n", \
|
---|
812 | RTThreadNativeSelf(), (pVCpu) ? (pVCpu)->hNativeThreadR0 : 0, \
|
---|
813 | (pVCpu) ? (pVCpu)->idCpu : 0))
|
---|
814 | #else
|
---|
815 | # define VMCPU_ASSERT_EMT(pVCpu) AssertMsg(VMCPU_IS_EMT(pVCpu), \
|
---|
816 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
|
---|
817 | RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
|
---|
818 | #endif
|
---|
819 |
|
---|
820 | /** @def VM_ASSERT_EMT_RETURN
|
---|
821 | * Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
|
---|
822 | */
|
---|
823 | #ifdef IN_RC
|
---|
824 | # define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
|
---|
825 | #elif defined(IN_RING0)
|
---|
826 | # define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
|
---|
827 | #else
|
---|
828 | # define VM_ASSERT_EMT_RETURN(pVM, rc) \
|
---|
829 | AssertMsgReturn(VM_IS_EMT(pVM), \
|
---|
830 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)), \
|
---|
831 | (rc))
|
---|
832 | #endif
|
---|
833 |
|
---|
834 | /** @def VMCPU_ASSERT_EMT_RETURN
|
---|
835 | * Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
|
---|
836 | */
|
---|
837 | #ifdef IN_RC
|
---|
838 | # define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
|
---|
839 | #elif defined(IN_RING0)
|
---|
840 | # define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
|
---|
841 | #else
|
---|
842 | # define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) \
|
---|
843 | AssertMsgReturn(VMCPU_IS_EMT(pVCpu), \
|
---|
844 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
|
---|
845 | RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu), \
|
---|
846 | (rc))
|
---|
847 | #endif
|
---|
848 |
|
---|
849 | /** @def VMCPU_ASSERT_EMT_OR_GURU
|
---|
850 | * Asserts that the current thread IS the emulation thread (EMT) of the
|
---|
851 | * specified virtual CPU.
|
---|
852 | */
|
---|
853 | #if defined(IN_RC) || defined(IN_RING0)
|
---|
854 | # define VMCPU_ASSERT_EMT_OR_GURU(pVCpu) Assert( VMCPU_IS_EMT(pVCpu) \
|
---|
855 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION \
|
---|
856 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION_LS )
|
---|
857 | #else
|
---|
858 | # define VMCPU_ASSERT_EMT_OR_GURU(pVCpu) \
|
---|
859 | AssertMsg( VMCPU_IS_EMT(pVCpu) \
|
---|
860 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION \
|
---|
861 | || pVCpu->CTX_SUFF(pVM)->enmVMState == VMSTATE_GURU_MEDITATION_LS, \
|
---|
862 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
|
---|
863 | RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
|
---|
864 | #endif
|
---|
865 |
|
---|
866 | /** @def VMCPU_ASSERT_EMT_OR_NOT_RUNNING
|
---|
867 | * Asserts that the current thread IS the emulation thread (EMT) of the
|
---|
868 | * specified virtual CPU or the VM is not running.
|
---|
869 | */
|
---|
870 | #if defined(IN_RC) || defined(IN_RING0)
|
---|
871 | # define VMCPU_ASSERT_EMT_OR_NOT_RUNNING(pVCpu) \
|
---|
872 | Assert( VMCPU_IS_EMT(pVCpu) \
|
---|
873 | || !VM_IS_RUNNING_FOR_ASSERTIONS_ONLY((pVCpu)->CTX_SUFF(pVM)) )
|
---|
874 | #else
|
---|
875 | # define VMCPU_ASSERT_EMT_OR_NOT_RUNNING(pVCpu) \
|
---|
876 | AssertMsg( VMCPU_IS_EMT(pVCpu) \
|
---|
877 | || !VM_IS_RUNNING_FOR_ASSERTIONS_ONLY((pVCpu)->CTX_SUFF(pVM)), \
|
---|
878 | ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
|
---|
879 | RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
|
---|
880 | #endif
|
---|
881 |
|
---|
882 | /** @def VMSTATE_IS_RUNNING
|
---|
883 | * Checks if the given state indicates a running VM.
|
---|
884 | */
|
---|
885 | #define VMSTATE_IS_RUNNING(a_enmVMState) \
|
---|
886 | ( (enmVMState) == VMSTATE_RUNNING \
|
---|
887 | || (enmVMState) == VMSTATE_RUNNING_LS \
|
---|
888 | || (enmVMState) == VMSTATE_RUNNING_FT )
|
---|
889 |
|
---|
890 | /** @def VM_IS_RUNNING_FOR_ASSERTIONS_ONLY
|
---|
891 | * Checks if the VM is running.
|
---|
892 | * @note This is only for pure debug assertions. No AssertReturn or similar!
|
---|
893 | * @sa VMSTATE_IS_RUNNING
|
---|
894 | */
|
---|
895 | #define VM_IS_RUNNING_FOR_ASSERTIONS_ONLY(pVM) \
|
---|
896 | ( (pVM)->enmVMState == VMSTATE_RUNNING \
|
---|
897 | || (pVM)->enmVMState == VMSTATE_RUNNING_LS \
|
---|
898 | || (pVM)->enmVMState == VMSTATE_RUNNING_FT )
|
---|
899 |
|
---|
900 | /** @def VM_ASSERT_IS_NOT_RUNNING
|
---|
901 | * Asserts that the VM is not running.
|
---|
902 | */
|
---|
903 | #if defined(IN_RC) || defined(IN_RING0)
|
---|
904 | #define VM_ASSERT_IS_NOT_RUNNING(pVM) Assert(!VM_IS_RUNNING_FOR_ASSERTIONS_ONLY(pVM))
|
---|
905 | #else
|
---|
906 | #define VM_ASSERT_IS_NOT_RUNNING(pVM) AssertMsg(!VM_IS_RUNNING_FOR_ASSERTIONS_ONLY(pVM), \
|
---|
907 | ("VM is running. enmVMState=%d\n", (pVM)->enmVMState))
|
---|
908 | #endif
|
---|
909 |
|
---|
910 | /** @def VM_ASSERT_EMT0
|
---|
911 | * Asserts that the current thread IS emulation thread \#0 (EMT0).
|
---|
912 | */
|
---|
913 | #define VM_ASSERT_EMT0(pVM) VMCPU_ASSERT_EMT(&(pVM)->aCpus[0])
|
---|
914 |
|
---|
915 | /** @def VM_ASSERT_EMT0_RETURN
|
---|
916 | * Asserts that the current thread IS emulation thread \#0 (EMT0) and returns if
|
---|
917 | * it isn't.
|
---|
918 | */
|
---|
919 | #define VM_ASSERT_EMT0_RETURN(pVM, rc) VMCPU_ASSERT_EMT_RETURN(&(pVM)->aCpus[0], (rc))
|
---|
920 |
|
---|
921 |
|
---|
922 | /**
|
---|
923 | * Asserts that the current thread is NOT the emulation thread.
|
---|
924 | */
|
---|
925 | #define VM_ASSERT_OTHER_THREAD(pVM) \
|
---|
926 | AssertMsg(!VM_IS_EMT(pVM), ("Not other thread!!\n"))
|
---|
927 |
|
---|
928 |
|
---|
929 | /** @def VM_ASSERT_STATE
|
---|
930 | * Asserts a certain VM state.
|
---|
931 | */
|
---|
932 | #define VM_ASSERT_STATE(pVM, _enmState) \
|
---|
933 | AssertMsg((pVM)->enmVMState == (_enmState), \
|
---|
934 | ("state %s, expected %s\n", VMGetStateName((pVM)->enmVMState), VMGetStateName(_enmState)))
|
---|
935 |
|
---|
936 | /** @def VM_ASSERT_STATE_RETURN
|
---|
937 | * Asserts a certain VM state and returns if it doesn't match.
|
---|
938 | */
|
---|
939 | #define VM_ASSERT_STATE_RETURN(pVM, _enmState, rc) \
|
---|
940 | AssertMsgReturn((pVM)->enmVMState == (_enmState), \
|
---|
941 | ("state %s, expected %s\n", VMGetStateName((pVM)->enmVMState), VMGetStateName(_enmState)), \
|
---|
942 | (rc))
|
---|
943 |
|
---|
944 | /** @def VM_IS_VALID_EXT
|
---|
945 | * Asserts a the VM handle is valid for external access, i.e. not being destroy
|
---|
946 | * or terminated. */
|
---|
947 | #define VM_IS_VALID_EXT(pVM) \
|
---|
948 | ( RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
|
---|
949 | && ( (unsigned)(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING \
|
---|
950 | || ( (unsigned)(pVM)->enmVMState == (unsigned)VMSTATE_DESTROYING \
|
---|
951 | && VM_IS_EMT(pVM))) )
|
---|
952 |
|
---|
953 | /** @def VM_ASSERT_VALID_EXT_RETURN
|
---|
954 | * Asserts a the VM handle is valid for external access, i.e. not being
|
---|
955 | * destroy or terminated.
|
---|
956 | */
|
---|
957 | #define VM_ASSERT_VALID_EXT_RETURN(pVM, rc) \
|
---|
958 | AssertMsgReturn(VM_IS_VALID_EXT(pVM), \
|
---|
959 | ("pVM=%p state %s\n", (pVM), RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
|
---|
960 | ? VMGetStateName(pVM->enmVMState) : ""), \
|
---|
961 | (rc))
|
---|
962 |
|
---|
963 | /** @def VMCPU_ASSERT_VALID_EXT_RETURN
|
---|
964 | * Asserts a the VMCPU handle is valid for external access, i.e. not being
|
---|
965 | * destroy or terminated.
|
---|
966 | */
|
---|
967 | #define VMCPU_ASSERT_VALID_EXT_RETURN(pVCpu, rc) \
|
---|
968 | AssertMsgReturn( RT_VALID_ALIGNED_PTR(pVCpu, 64) \
|
---|
969 | && RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
|
---|
970 | && (unsigned)(pVCpu)->CTX_SUFF(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING, \
|
---|
971 | ("pVCpu=%p pVM=%p state %s\n", (pVCpu), RT_VALID_ALIGNED_PTR(pVCpu, 64) ? (pVCpu)->CTX_SUFF(pVM) : NULL, \
|
---|
972 | RT_VALID_ALIGNED_PTR(pVCpu, 64) && RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
|
---|
973 | ? VMGetStateName((pVCpu)->pVMR3->enmVMState) : ""), \
|
---|
974 | (rc))
|
---|
975 |
|
---|
976 | #endif /* !VBOX_FOR_DTRACE_LIB */
|
---|
977 |
|
---|
978 |
|
---|
979 | /**
|
---|
980 | * Helper that HM and NEM uses for safely modifying VM::bMainExecutionEngine.
|
---|
981 | *
|
---|
982 | * ONLY HM and NEM MAY USE THIS!
|
---|
983 | *
|
---|
984 | * @param a_pVM The cross context VM structure.
|
---|
985 | * @param a_bValue The new value.
|
---|
986 | * @internal
|
---|
987 | */
|
---|
988 | #define VM_SET_MAIN_EXECUTION_ENGINE(a_pVM, a_bValue) \
|
---|
989 | do { \
|
---|
990 | *const_cast<uint8_t *>(&(a_pVM)->bMainExecutionEngine) = (a_bValue); \
|
---|
991 | ASMCompilerBarrier(); /* just to be on the safe side */ \
|
---|
992 | } while (0)
|
---|
993 |
|
---|
994 | /**
|
---|
995 | * Checks whether raw-mode is used.
|
---|
996 | *
|
---|
997 | * @retval true if either is used.
|
---|
998 | * @retval false if software virtualization (raw-mode) is used.
|
---|
999 | *
|
---|
1000 | * @param a_pVM The cross context VM structure.
|
---|
1001 | * @sa VM_IS_HM_OR_NEM_ENABLED, VM_IS_HM_ENABLED, VM_IS_NEM_ENABLED.
|
---|
1002 | * @internal
|
---|
1003 | */
|
---|
1004 | #ifdef VBOX_WITH_RAW_MODE
|
---|
1005 | # define VM_IS_RAW_MODE_ENABLED(a_pVM) ((a_pVM)->bMainExecutionEngine == VM_EXEC_ENGINE_RAW_MODE)
|
---|
1006 | #else
|
---|
1007 | # define VM_IS_RAW_MODE_ENABLED(a_pVM) (false)
|
---|
1008 | #endif
|
---|
1009 |
|
---|
1010 | /**
|
---|
1011 | * Checks whether HM (VT-x/AMD-V) or NEM is being used by this VM.
|
---|
1012 | *
|
---|
1013 | * @retval true if either is used.
|
---|
1014 | * @retval false if software virtualization (raw-mode) is used.
|
---|
1015 | *
|
---|
1016 | * @param a_pVM The cross context VM structure.
|
---|
1017 | * @sa VM_IS_RAW_MODE_ENABLED, VM_IS_HM_ENABLED, VM_IS_NEM_ENABLED.
|
---|
1018 | * @internal
|
---|
1019 | */
|
---|
1020 | #define VM_IS_HM_OR_NEM_ENABLED(a_pVM) ((a_pVM)->bMainExecutionEngine != VM_EXEC_ENGINE_RAW_MODE)
|
---|
1021 |
|
---|
1022 | /**
|
---|
1023 | * Checks whether HM is being used by this VM.
|
---|
1024 | *
|
---|
1025 | * @retval true if HM (VT-x/AMD-v) is used.
|
---|
1026 | * @retval false if not.
|
---|
1027 | *
|
---|
1028 | * @param a_pVM The cross context VM structure.
|
---|
1029 | * @sa VM_IS_NEM_ENABLED, VM_IS_RAW_MODE_ENABLED, VM_IS_HM_OR_NEM_ENABLED.
|
---|
1030 | * @internal
|
---|
1031 | */
|
---|
1032 | #define VM_IS_HM_ENABLED(a_pVM) ((a_pVM)->bMainExecutionEngine == VM_EXEC_ENGINE_HW_VIRT)
|
---|
1033 |
|
---|
1034 | /**
|
---|
1035 | * Checks whether NEM is being used by this VM.
|
---|
1036 | *
|
---|
1037 | * @retval true if a native hypervisor API is used.
|
---|
1038 | * @retval false if not.
|
---|
1039 | *
|
---|
1040 | * @param a_pVM The cross context VM structure.
|
---|
1041 | * @sa VM_IS_HM_ENABLED, VM_IS_RAW_MODE_ENABLED, VM_IS_HM_OR_NEM_ENABLED.
|
---|
1042 | * @internal
|
---|
1043 | */
|
---|
1044 | #define VM_IS_NEM_ENABLED(a_pVM) ((a_pVM)->bMainExecutionEngine == VM_EXEC_ENGINE_NATIVE_API)
|
---|
1045 |
|
---|
1046 |
|
---|
1047 | /**
|
---|
1048 | * The cross context VM structure.
|
---|
1049 | *
|
---|
1050 | * It contains all the VM data which have to be available in all contexts.
|
---|
1051 | * Even if it contains all the data the idea is to use APIs not to modify all
|
---|
1052 | * the members all around the place. Therefore we make use of unions to hide
|
---|
1053 | * everything which isn't local to the current source module. This means we'll
|
---|
1054 | * have to pay a little bit of attention when adding new members to structures
|
---|
1055 | * in the unions and make sure to keep the padding sizes up to date.
|
---|
1056 | *
|
---|
1057 | * Run 'kmk run-struct-tests' (from src/VBox/VMM if you like) after updating!
|
---|
1058 | */
|
---|
1059 | typedef struct VM
|
---|
1060 | {
|
---|
1061 | /** The state of the VM.
|
---|
1062 | * This field is read only to everyone except the VM and EM. */
|
---|
1063 | VMSTATE volatile enmVMState;
|
---|
1064 | /** Forced action flags.
|
---|
1065 | * See the VM_FF_* \#defines. Updated atomically.
|
---|
1066 | */
|
---|
1067 | volatile uint32_t fGlobalForcedActions;
|
---|
1068 | /** Pointer to the array of page descriptors for the VM structure allocation. */
|
---|
1069 | R3PTRTYPE(PSUPPAGE) paVMPagesR3;
|
---|
1070 | /** Session handle. For use when calling SUPR0 APIs. */
|
---|
1071 | PSUPDRVSESSION pSession;
|
---|
1072 | /** Pointer to the ring-3 VM structure. */
|
---|
1073 | PUVM pUVM;
|
---|
1074 | /** Ring-3 Host Context VM Pointer. */
|
---|
1075 | R3PTRTYPE(struct VM *) pVMR3;
|
---|
1076 | /** Ring-0 Host Context VM Pointer. */
|
---|
1077 | R0PTRTYPE(struct VM *) pVMR0;
|
---|
1078 | /** Raw-mode Context VM Pointer. */
|
---|
1079 | RCPTRTYPE(struct VM *) pVMRC;
|
---|
1080 |
|
---|
1081 | /** The GVM VM handle. Only the GVM should modify this field. */
|
---|
1082 | uint32_t hSelf;
|
---|
1083 | /** Number of virtual CPUs. */
|
---|
1084 | uint32_t cCpus;
|
---|
1085 | /** CPU excution cap (1-100) */
|
---|
1086 | uint32_t uCpuExecutionCap;
|
---|
1087 |
|
---|
1088 | /** Size of the VM structure including the VMCPU array. */
|
---|
1089 | uint32_t cbSelf;
|
---|
1090 |
|
---|
1091 | /** Offset to the VMCPU array starting from beginning of this structure. */
|
---|
1092 | uint32_t offVMCPU;
|
---|
1093 |
|
---|
1094 | /**
|
---|
1095 | * VMMSwitcher assembly entry point returning to host context.
|
---|
1096 | *
|
---|
1097 | * Depending on how the host handles the rc status given in @a eax, this may
|
---|
1098 | * return and let the caller resume whatever it was doing prior to the call.
|
---|
1099 | *
|
---|
1100 | *
|
---|
1101 | * @param eax The return code, register.
|
---|
1102 | * @remark Assume interrupts disabled.
|
---|
1103 | * @remark This method pointer lives here because TRPM needs it.
|
---|
1104 | */
|
---|
1105 | RTRCPTR pfnVMMRCToHostAsm/*(int32_t eax)*/;
|
---|
1106 |
|
---|
1107 | /**
|
---|
1108 | * VMMSwitcher assembly entry point returning to host context without saving the
|
---|
1109 | * raw-mode context (hyper) registers.
|
---|
1110 | *
|
---|
1111 | * Unlike pfnVMMRC2HCAsm, this will not return to the caller. Instead it
|
---|
1112 | * expects the caller to save a RC context in CPUM where one might return if the
|
---|
1113 | * return code indicate that this is possible.
|
---|
1114 | *
|
---|
1115 | * This method pointer lives here because TRPM needs it.
|
---|
1116 | *
|
---|
1117 | * @param eax The return code, register.
|
---|
1118 | * @remark Assume interrupts disabled.
|
---|
1119 | * @remark This method pointer lives here because TRPM needs it.
|
---|
1120 | */
|
---|
1121 | RTRCPTR pfnVMMRCToHostAsmNoReturn/*(int32_t eax)*/;
|
---|
1122 |
|
---|
1123 | /** @name Various items that are frequently accessed.
|
---|
1124 | * @{ */
|
---|
1125 | /** The main execution engine, VM_EXEC_ENGINE_XXX.
|
---|
1126 | * This is set early during vmR3InitRing3 by HM or NEM. */
|
---|
1127 | uint8_t const bMainExecutionEngine;
|
---|
1128 |
|
---|
1129 | /** Whether to recompile user mode code or run it raw/hm/nem.
|
---|
1130 | * In non-raw-mode both fRecompileUser and fRecompileSupervisor must be set
|
---|
1131 | * to recompiler stuff. */
|
---|
1132 | bool fRecompileUser;
|
---|
1133 | /** Whether to recompile supervisor mode code or run it raw/hm/nem.
|
---|
1134 | * In non-raw-mode both fRecompileUser and fRecompileSupervisor must be set
|
---|
1135 | * to recompiler stuff. */
|
---|
1136 | bool fRecompileSupervisor;
|
---|
1137 | /** Whether raw mode supports ring-1 code or not.
|
---|
1138 | * This will be cleared when not in raw-mode. */
|
---|
1139 | bool fRawRing1Enabled;
|
---|
1140 | /** PATM enabled flag.
|
---|
1141 | * This is placed here for performance reasons.
|
---|
1142 | * This will be cleared when not in raw-mode. */
|
---|
1143 | bool fPATMEnabled;
|
---|
1144 | /** CSAM enabled flag.
|
---|
1145 | * This is placed here for performance reasons.
|
---|
1146 | * This will be cleared when not in raw-mode. */
|
---|
1147 | bool fCSAMEnabled;
|
---|
1148 |
|
---|
1149 | /** Hardware VM support is available and enabled.
|
---|
1150 | * Determined very early during init.
|
---|
1151 | * This is placed here for performance reasons.
|
---|
1152 | * @todo obsoleted by bMainExecutionEngine, eliminate. */
|
---|
1153 | bool fHMEnabled;
|
---|
1154 | /** Hardware VM support requires a minimal raw-mode context.
|
---|
1155 | * This is never set on 64-bit hosts, only 32-bit hosts requires it. */
|
---|
1156 | bool fHMNeedRawModeCtx;
|
---|
1157 |
|
---|
1158 | /** Set when this VM is the master FT node.
|
---|
1159 | * @todo This doesn't need to be here, FTM should store it in it's own
|
---|
1160 | * structures instead. */
|
---|
1161 | bool fFaultTolerantMaster;
|
---|
1162 | /** Large page enabled flag.
|
---|
1163 | * @todo This doesn't need to be here, PGM should store it in it's own
|
---|
1164 | * structures instead. */
|
---|
1165 | bool fUseLargePages;
|
---|
1166 | /** @} */
|
---|
1167 |
|
---|
1168 | /** Alignment padding. */
|
---|
1169 | uint8_t uPadding1[2];
|
---|
1170 |
|
---|
1171 | /** @name Debugging
|
---|
1172 | * @{ */
|
---|
1173 | /** Raw-mode Context VM Pointer. */
|
---|
1174 | RCPTRTYPE(RTTRACEBUF) hTraceBufRC;
|
---|
1175 | /** Ring-3 Host Context VM Pointer. */
|
---|
1176 | R3PTRTYPE(RTTRACEBUF) hTraceBufR3;
|
---|
1177 | /** Ring-0 Host Context VM Pointer. */
|
---|
1178 | R0PTRTYPE(RTTRACEBUF) hTraceBufR0;
|
---|
1179 | /** @} */
|
---|
1180 |
|
---|
1181 | #if HC_ARCH_BITS == 32
|
---|
1182 | /** Alignment padding. */
|
---|
1183 | uint32_t uPadding2;
|
---|
1184 | #endif
|
---|
1185 |
|
---|
1186 | /** @name Switcher statistics (remove)
|
---|
1187 | * @{ */
|
---|
1188 | /** Profiling the total time from Qemu to GC. */
|
---|
1189 | STAMPROFILEADV StatTotalQemuToGC;
|
---|
1190 | /** Profiling the total time from GC to Qemu. */
|
---|
1191 | STAMPROFILEADV StatTotalGCToQemu;
|
---|
1192 | /** Profiling the total time spent in GC. */
|
---|
1193 | STAMPROFILEADV StatTotalInGC;
|
---|
1194 | /** Profiling the total time spent not in Qemu. */
|
---|
1195 | STAMPROFILEADV StatTotalInQemu;
|
---|
1196 | /** Profiling the VMMSwitcher code for going to GC. */
|
---|
1197 | STAMPROFILEADV StatSwitcherToGC;
|
---|
1198 | /** Profiling the VMMSwitcher code for going to HC. */
|
---|
1199 | STAMPROFILEADV StatSwitcherToHC;
|
---|
1200 | STAMPROFILEADV StatSwitcherSaveRegs;
|
---|
1201 | STAMPROFILEADV StatSwitcherSysEnter;
|
---|
1202 | STAMPROFILEADV StatSwitcherDebug;
|
---|
1203 | STAMPROFILEADV StatSwitcherCR0;
|
---|
1204 | STAMPROFILEADV StatSwitcherCR4;
|
---|
1205 | STAMPROFILEADV StatSwitcherJmpCR3;
|
---|
1206 | STAMPROFILEADV StatSwitcherRstrRegs;
|
---|
1207 | STAMPROFILEADV StatSwitcherLgdt;
|
---|
1208 | STAMPROFILEADV StatSwitcherLidt;
|
---|
1209 | STAMPROFILEADV StatSwitcherLldt;
|
---|
1210 | STAMPROFILEADV StatSwitcherTSS;
|
---|
1211 | /** @} */
|
---|
1212 |
|
---|
1213 | /** Padding - the unions must be aligned on a 64 bytes boundary and the unions
|
---|
1214 | * must start at the same offset on both 64-bit and 32-bit hosts. */
|
---|
1215 | uint8_t abAlignment3[(HC_ARCH_BITS == 32 ? 24 : 0) + 40];
|
---|
1216 |
|
---|
1217 | /** CPUM part. */
|
---|
1218 | union
|
---|
1219 | {
|
---|
1220 | #ifdef ___CPUMInternal_h
|
---|
1221 | struct CPUM s;
|
---|
1222 | #endif
|
---|
1223 | #ifdef ___VBox_vmm_cpum_h
|
---|
1224 | /** Read only info exposed about the host and guest CPUs. */
|
---|
1225 | struct
|
---|
1226 | {
|
---|
1227 | /** Padding for hidden fields. */
|
---|
1228 | uint8_t abHidden0[64];
|
---|
1229 | /** Host CPU feature information. */
|
---|
1230 | CPUMFEATURES HostFeatures;
|
---|
1231 | /** Guest CPU feature information. */
|
---|
1232 | CPUMFEATURES GuestFeatures;
|
---|
1233 | } const ro;
|
---|
1234 | #endif
|
---|
1235 | uint8_t padding[1536]; /* multiple of 64 */
|
---|
1236 | } cpum;
|
---|
1237 |
|
---|
1238 | /** VMM part. */
|
---|
1239 | union
|
---|
1240 | {
|
---|
1241 | #ifdef ___VMMInternal_h
|
---|
1242 | struct VMM s;
|
---|
1243 | #endif
|
---|
1244 | uint8_t padding[1600]; /* multiple of 64 */
|
---|
1245 | } vmm;
|
---|
1246 |
|
---|
1247 | /** PGM part. */
|
---|
1248 | union
|
---|
1249 | {
|
---|
1250 | #ifdef ___PGMInternal_h
|
---|
1251 | struct PGM s;
|
---|
1252 | #endif
|
---|
1253 | uint8_t padding[4096*2+6080]; /* multiple of 64 */
|
---|
1254 | } pgm;
|
---|
1255 |
|
---|
1256 | /** HM part. */
|
---|
1257 | union
|
---|
1258 | {
|
---|
1259 | #ifdef ___HMInternal_h
|
---|
1260 | struct HM s;
|
---|
1261 | #endif
|
---|
1262 | uint8_t padding[5440]; /* multiple of 64 */
|
---|
1263 | } hm;
|
---|
1264 |
|
---|
1265 | /** TRPM part. */
|
---|
1266 | union
|
---|
1267 | {
|
---|
1268 | #ifdef ___TRPMInternal_h
|
---|
1269 | struct TRPM s;
|
---|
1270 | #endif
|
---|
1271 | uint8_t padding[5248]; /* multiple of 64 */
|
---|
1272 | } trpm;
|
---|
1273 |
|
---|
1274 | /** SELM part. */
|
---|
1275 | union
|
---|
1276 | {
|
---|
1277 | #ifdef ___SELMInternal_h
|
---|
1278 | struct SELM s;
|
---|
1279 | #endif
|
---|
1280 | uint8_t padding[768]; /* multiple of 64 */
|
---|
1281 | } selm;
|
---|
1282 |
|
---|
1283 | /** MM part. */
|
---|
1284 | union
|
---|
1285 | {
|
---|
1286 | #ifdef ___MMInternal_h
|
---|
1287 | struct MM s;
|
---|
1288 | #endif
|
---|
1289 | uint8_t padding[192]; /* multiple of 64 */
|
---|
1290 | } mm;
|
---|
1291 |
|
---|
1292 | /** PDM part. */
|
---|
1293 | union
|
---|
1294 | {
|
---|
1295 | #ifdef ___PDMInternal_h
|
---|
1296 | struct PDM s;
|
---|
1297 | #endif
|
---|
1298 | uint8_t padding[1920]; /* multiple of 64 */
|
---|
1299 | } pdm;
|
---|
1300 |
|
---|
1301 | /** IOM part. */
|
---|
1302 | union
|
---|
1303 | {
|
---|
1304 | #ifdef ___IOMInternal_h
|
---|
1305 | struct IOM s;
|
---|
1306 | #endif
|
---|
1307 | uint8_t padding[896]; /* multiple of 64 */
|
---|
1308 | } iom;
|
---|
1309 |
|
---|
1310 | /** EM part. */
|
---|
1311 | union
|
---|
1312 | {
|
---|
1313 | #ifdef ___EMInternal_h
|
---|
1314 | struct EM s;
|
---|
1315 | #endif
|
---|
1316 | uint8_t padding[256]; /* multiple of 64 */
|
---|
1317 | } em;
|
---|
1318 |
|
---|
1319 | /** NEM part. */
|
---|
1320 | union
|
---|
1321 | {
|
---|
1322 | #ifdef ___NEMInternal_h
|
---|
1323 | struct NEM s;
|
---|
1324 | #endif
|
---|
1325 | uint8_t padding[128]; /* multiple of 64 */
|
---|
1326 | } nem;
|
---|
1327 |
|
---|
1328 | /** TM part. */
|
---|
1329 | union
|
---|
1330 | {
|
---|
1331 | #ifdef ___TMInternal_h
|
---|
1332 | struct TM s;
|
---|
1333 | #endif
|
---|
1334 | uint8_t padding[2496]; /* multiple of 64 */
|
---|
1335 | } tm;
|
---|
1336 |
|
---|
1337 | /** DBGF part. */
|
---|
1338 | union
|
---|
1339 | {
|
---|
1340 | #ifdef ___DBGFInternal_h
|
---|
1341 | struct DBGF s;
|
---|
1342 | #endif
|
---|
1343 | #ifdef ___VBox_vmm_dbgf_h
|
---|
1344 | /** Read only info exposed about interrupt breakpoints and selected events. */
|
---|
1345 | struct
|
---|
1346 | {
|
---|
1347 | /** Bitmap of enabled hardware interrupt breakpoints. */
|
---|
1348 | uint32_t bmHardIntBreakpoints[256 / 32];
|
---|
1349 | /** Bitmap of enabled software interrupt breakpoints. */
|
---|
1350 | uint32_t bmSoftIntBreakpoints[256 / 32];
|
---|
1351 | /** Bitmap of selected events.
|
---|
1352 | * This includes non-selectable events too for simplicity, we maintain the
|
---|
1353 | * state for some of these, as it may come in handy. */
|
---|
1354 | uint64_t bmSelectedEvents[(DBGFEVENT_END + 63) / 64];
|
---|
1355 | /** Enabled hardware interrupt breakpoints. */
|
---|
1356 | uint32_t cHardIntBreakpoints;
|
---|
1357 | /** Enabled software interrupt breakpoints. */
|
---|
1358 | uint32_t cSoftIntBreakpoints;
|
---|
1359 | /** The number of selected events. */
|
---|
1360 | uint32_t cSelectedEvents;
|
---|
1361 | /** The number of enabled hardware breakpoints. */
|
---|
1362 | uint8_t cEnabledHwBreakpoints;
|
---|
1363 | /** The number of enabled hardware I/O breakpoints. */
|
---|
1364 | uint8_t cEnabledHwIoBreakpoints;
|
---|
1365 | /** The number of enabled INT3 breakpoints. */
|
---|
1366 | uint8_t cEnabledInt3Breakpoints;
|
---|
1367 | uint8_t abPadding[1]; /**< Unused padding space up for grabs. */
|
---|
1368 | } const ro;
|
---|
1369 | #endif
|
---|
1370 | uint8_t padding[2432]; /* multiple of 64 */
|
---|
1371 | } dbgf;
|
---|
1372 |
|
---|
1373 | /** SSM part. */
|
---|
1374 | union
|
---|
1375 | {
|
---|
1376 | #ifdef ___SSMInternal_h
|
---|
1377 | struct SSM s;
|
---|
1378 | #endif
|
---|
1379 | uint8_t padding[128]; /* multiple of 64 */
|
---|
1380 | } ssm;
|
---|
1381 |
|
---|
1382 | /** FTM part. */
|
---|
1383 | union
|
---|
1384 | {
|
---|
1385 | #ifdef ___FTMInternal_h
|
---|
1386 | struct FTM s;
|
---|
1387 | #endif
|
---|
1388 | uint8_t padding[512]; /* multiple of 64 */
|
---|
1389 | } ftm;
|
---|
1390 |
|
---|
1391 | #ifdef VBOX_WITH_RAW_MODE
|
---|
1392 | /** PATM part. */
|
---|
1393 | union
|
---|
1394 | {
|
---|
1395 | # ifdef ___PATMInternal_h
|
---|
1396 | struct PATM s;
|
---|
1397 | # endif
|
---|
1398 | uint8_t padding[768]; /* multiple of 64 */
|
---|
1399 | } patm;
|
---|
1400 |
|
---|
1401 | /** CSAM part. */
|
---|
1402 | union
|
---|
1403 | {
|
---|
1404 | # ifdef ___CSAMInternal_h
|
---|
1405 | struct CSAM s;
|
---|
1406 | # endif
|
---|
1407 | uint8_t padding[1088]; /* multiple of 64 */
|
---|
1408 | } csam;
|
---|
1409 | #endif
|
---|
1410 |
|
---|
1411 | #ifdef VBOX_WITH_REM
|
---|
1412 | /** REM part. */
|
---|
1413 | union
|
---|
1414 | {
|
---|
1415 | # ifdef ___REMInternal_h
|
---|
1416 | struct REM s;
|
---|
1417 | # endif
|
---|
1418 | uint8_t padding[0x11100]; /* multiple of 64 */
|
---|
1419 | } rem;
|
---|
1420 | #endif
|
---|
1421 |
|
---|
1422 | union
|
---|
1423 | {
|
---|
1424 | #ifdef ___GIMInternal_h
|
---|
1425 | struct GIM s;
|
---|
1426 | #endif
|
---|
1427 | uint8_t padding[448]; /* multiple of 64 */
|
---|
1428 | } gim;
|
---|
1429 |
|
---|
1430 | union
|
---|
1431 | {
|
---|
1432 | #ifdef ___APICInternal_h
|
---|
1433 | struct APIC s;
|
---|
1434 | #endif
|
---|
1435 | uint8_t padding[128]; /* multiple of 8 */
|
---|
1436 | } apic;
|
---|
1437 |
|
---|
1438 | /* ---- begin small stuff ---- */
|
---|
1439 |
|
---|
1440 | /** VM part. */
|
---|
1441 | union
|
---|
1442 | {
|
---|
1443 | #ifdef ___VMInternal_h
|
---|
1444 | struct VMINT s;
|
---|
1445 | #endif
|
---|
1446 | uint8_t padding[32]; /* multiple of 8 */
|
---|
1447 | } vm;
|
---|
1448 |
|
---|
1449 | /** CFGM part. */
|
---|
1450 | union
|
---|
1451 | {
|
---|
1452 | #ifdef ___CFGMInternal_h
|
---|
1453 | struct CFGM s;
|
---|
1454 | #endif
|
---|
1455 | uint8_t padding[8]; /* multiple of 8 */
|
---|
1456 | } cfgm;
|
---|
1457 |
|
---|
1458 | /** Padding for aligning the cpu array on a page boundary. */
|
---|
1459 | #if defined(VBOX_WITH_REM) && defined(VBOX_WITH_RAW_MODE)
|
---|
1460 | uint8_t abAlignment2[3670];
|
---|
1461 | #elif defined(VBOX_WITH_REM) && !defined(VBOX_WITH_RAW_MODE)
|
---|
1462 | uint8_t abAlignment2[1430];
|
---|
1463 | #elif !defined(VBOX_WITH_REM) && defined(VBOX_WITH_RAW_MODE)
|
---|
1464 | uint8_t abAlignment2[3926];
|
---|
1465 | #else
|
---|
1466 | uint8_t abAlignment2[1686];
|
---|
1467 | #endif
|
---|
1468 |
|
---|
1469 | /* ---- end small stuff ---- */
|
---|
1470 |
|
---|
1471 | /** VMCPU array for the configured number of virtual CPUs.
|
---|
1472 | * Must be aligned on a page boundary for TLB hit reasons as well as
|
---|
1473 | * alignment of VMCPU members. */
|
---|
1474 | VMCPU aCpus[1];
|
---|
1475 | } VM;
|
---|
1476 |
|
---|
1477 |
|
---|
1478 | #ifdef IN_RC
|
---|
1479 | RT_C_DECLS_BEGIN
|
---|
1480 |
|
---|
1481 | /** The VM structure.
|
---|
1482 | * This is imported from the VMMRCBuiltin module, i.e. it's a one of those magic
|
---|
1483 | * globals which we should avoid using.
|
---|
1484 | */
|
---|
1485 | extern DECLIMPORT(VM) g_VM;
|
---|
1486 |
|
---|
1487 | RT_C_DECLS_END
|
---|
1488 | #endif
|
---|
1489 |
|
---|
1490 | /** @} */
|
---|
1491 |
|
---|
1492 | #endif
|
---|
1493 |
|
---|