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