VirtualBox

source: vbox/trunk/src/VBox/VMM/include/NEMInternal.h@ 99196

Last change on this file since 99196 was 99051, checked in by vboxsync, 21 months ago

VMM: More ARMv8 x86/amd64 separation work, VBoxVMMArm compiles and links now, bugref:10385

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.1 KB
Line 
1/* $Id: NEMInternal.h 99051 2023-03-19 16:40:06Z vboxsync $ */
2/** @file
3 * NEM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2018-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef VMM_INCLUDED_SRC_include_NEMInternal_h
29#define VMM_INCLUDED_SRC_include_NEMInternal_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <VBox/cdefs.h>
35#include <VBox/types.h>
36#include <VBox/vmm/nem.h>
37#include <VBox/vmm/cpum.h> /* For CPUMCPUVENDOR. */
38#include <VBox/vmm/stam.h>
39#include <VBox/vmm/vmapi.h>
40#ifdef RT_OS_WINDOWS
41#include <iprt/nt/hyperv.h>
42#include <iprt/critsect.h>
43#elif defined(RT_OS_DARWIN)
44# if defined(VBOX_VMM_TARGET_ARMV8)
45# include <Hypervisor/Hypervisor.h>
46# else
47# include "VMXInternal.h"
48# endif
49#endif
50
51RT_C_DECLS_BEGIN
52
53
54/** @defgroup grp_nem_int Internal
55 * @ingroup grp_nem
56 * @internal
57 * @{
58 */
59
60#if defined(VBOX_WITH_NATIVE_NEM) && !defined(VBOX_WITH_PGM_NEM_MODE)
61# error "VBOX_WITH_NATIVE_NEM requires VBOX_WITH_PGM_NEM_MODE to be defined"
62#endif
63
64
65#ifdef RT_OS_WINDOWS
66/*
67 * Windows: Code configuration.
68 */
69/* nothing at the moment */
70
71/**
72 * Windows VID I/O control information.
73 */
74typedef struct NEMWINIOCTL
75{
76 /** The I/O control function number. */
77 uint32_t uFunction;
78 uint32_t cbInput;
79 uint32_t cbOutput;
80} NEMWINIOCTL;
81
82/** @name Windows: Our two-bit physical page state for PGMPAGE
83 * @{ */
84# define NEM_WIN_PAGE_STATE_NOT_SET 0
85# define NEM_WIN_PAGE_STATE_UNMAPPED 1
86# define NEM_WIN_PAGE_STATE_READABLE 2
87# define NEM_WIN_PAGE_STATE_WRITABLE 3
88/** @} */
89
90/** Windows: Checks if a_GCPhys is subject to the limited A20 gate emulation. */
91# define NEM_WIN_IS_SUBJECT_TO_A20(a_GCPhys) ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K)
92/** Windows: Checks if a_GCPhys is relevant to the limited A20 gate emulation. */
93# define NEM_WIN_IS_RELEVANT_TO_A20(a_GCPhys) \
94 ( ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K) || ((RTGCPHYS)(a_GCPhys) < (RTGCPHYS)_64K) )
95
96/** The CPUMCTX_EXTRN_XXX mask for IEM. */
97# define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_INHIBIT_INT \
98 | CPUMCTX_EXTRN_INHIBIT_NMI )
99/** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
100# define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
101
102/** @name Windows: Interrupt window flags (NEM_WIN_INTW_F_XXX).
103 * @{ */
104# define NEM_WIN_INTW_F_NMI UINT8_C(0x01)
105# define NEM_WIN_INTW_F_REGULAR UINT8_C(0x02)
106# define NEM_WIN_INTW_F_PRIO_MASK UINT8_C(0x3c)
107# define NEM_WIN_INTW_F_PRIO_SHIFT 2
108/** @} */
109
110#endif /* RT_OS_WINDOWS */
111
112
113#ifdef RT_OS_DARWIN
114# if !defined(VBOX_VMM_TARGET_ARMV8)
115/** vCPU ID declaration to avoid dragging in HV headers here. */
116typedef unsigned hv_vcpuid_t;
117/** The HV VM memory space ID (ASID). */
118typedef unsigned hv_vm_space_t;
119# endif
120
121
122/** @name Darwin: Our two-bit physical page state for PGMPAGE
123 * @{ */
124# define NEM_DARWIN_PAGE_STATE_NOT_SET 0
125# define NEM_DARWIN_PAGE_STATE_UNMAPPED 1
126# define NEM_DARWIN_PAGE_STATE_READABLE 2
127# define NEM_DARWIN_PAGE_STATE_WRITABLE 3
128/** @} */
129
130# if defined(VBOX_VMM_TARGET_ARMV8)
131/** The CPUMCTX_EXTRN_XXX mask for IEM. */
132# define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK )
133# else
134/** The CPUMCTX_EXTRN_XXX mask for IEM. */
135# define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_INHIBIT_INT \
136 | CPUMCTX_EXTRN_INHIBIT_NMI )
137#endif
138
139/** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
140# define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
141
142#endif
143
144
145/** Trick to make slickedit see the static functions in the template. */
146#ifndef IN_SLICKEDIT
147# define NEM_TMPL_STATIC static
148#else
149# define NEM_TMPL_STATIC
150#endif
151
152
153/**
154 * Generic NEM exit type enumeration for use with EMHistoryAddExit.
155 *
156 * On windows we've got two different set of exit types and they are both jumping
157 * around the place value wise, so EM can use their values.
158 *
159 * @note We only have exit types for exits not covered by EM here.
160 */
161typedef enum NEMEXITTYPE
162{
163 NEMEXITTYPE_INVALID = 0,
164
165 /* Common: */
166 NEMEXITTYPE_INTTERRUPT_WINDOW,
167 NEMEXITTYPE_HALT,
168
169 /* Windows: */
170 NEMEXITTYPE_UNRECOVERABLE_EXCEPTION,
171 NEMEXITTYPE_INVALID_VP_REGISTER_VALUE,
172 NEMEXITTYPE_XCPT_UD,
173 NEMEXITTYPE_XCPT_DB,
174 NEMEXITTYPE_XCPT_BP,
175 NEMEXITTYPE_CANCELED,
176 NEMEXITTYPE_MEMORY_ACCESS,
177
178 /* Linux: */
179 NEMEXITTYPE_INTERNAL_ERROR_EMULATION,
180 NEMEXITTYPE_INTERNAL_ERROR_FATAL,
181 NEMEXITTYPE_INTERRUPTED,
182 NEMEXITTYPE_FAILED_ENTRY,
183
184 /* End of valid types. */
185 NEMEXITTYPE_END
186} NEMEXITTYPE;
187
188
189/**
190 * NEM VM Instance data.
191 */
192typedef struct NEM
193{
194 /** NEM_MAGIC. */
195 uint32_t u32Magic;
196
197 /** Set if enabled. */
198 bool fEnabled;
199 /** Set if long mode guests are allowed. */
200 bool fAllow64BitGuests;
201 /** Set when the debug facility has breakpoints/events enabled that requires
202 * us to use the debug execution loop. */
203 bool fUseDebugLoop;
204
205#if defined(RT_OS_LINUX)
206 /** The '/dev/kvm' file descriptor. */
207 int32_t fdKvm;
208 /** The KVM_CREATE_VM file descriptor. */
209 int32_t fdVm;
210
211 /** KVM_GET_VCPU_MMAP_SIZE. */
212 uint32_t cbVCpuMmap;
213 /** KVM_CAP_NR_MEMSLOTS. */
214 uint32_t cMaxMemSlots;
215 /** KVM_CAP_X86_ROBUST_SINGLESTEP. */
216 bool fRobustSingleStep;
217
218 /** Hint where there might be a free slot. */
219 uint16_t idPrevSlot;
220 /** Memory slot ID allocation bitmap. */
221 uint64_t bmSlotIds[_32K / 8 / sizeof(uint64_t)];
222
223#elif defined(RT_OS_WINDOWS)
224 /** Set if we've created the EMTs. */
225 bool fCreatedEmts : 1;
226 /** WHvRunVpExitReasonX64Cpuid is supported. */
227 bool fExtendedMsrExit : 1;
228 /** WHvRunVpExitReasonX64MsrAccess is supported. */
229 bool fExtendedCpuIdExit : 1;
230 /** WHvRunVpExitReasonException is supported. */
231 bool fExtendedXcptExit : 1;
232# ifdef NEM_WIN_WITH_A20
233 /** Set if we've started more than one CPU and cannot mess with A20. */
234 bool fA20Fixed : 1;
235 /** Set if A20 is enabled. */
236 bool fA20Enabled : 1;
237# endif
238 /** The reported CPU vendor. */
239 CPUMCPUVENDOR enmCpuVendor;
240 /** Cache line flush size as a power of two. */
241 uint8_t cCacheLineFlushShift;
242 /** The result of WHvCapabilityCodeProcessorFeatures. */
243 union
244 {
245 /** 64-bit view. */
246 uint64_t u64;
247# ifdef _WINHVAPIDEFS_H_
248 /** Interpreed features. */
249 WHV_PROCESSOR_FEATURES u;
250# endif
251 } uCpuFeatures;
252
253 /** The partition handle. */
254# ifdef _WINHVAPIDEFS_H_
255 WHV_PARTITION_HANDLE
256# else
257 RTHCUINTPTR
258# endif
259 hPartition;
260 /** The device handle for the partition, for use with Vid APIs or direct I/O
261 * controls. */
262 RTR3PTR hPartitionDevice;
263
264 /** Number of currently mapped pages. */
265 uint32_t volatile cMappedPages;
266 uint32_t u32Padding;
267 STAMCOUNTER StatMapPage;
268 STAMCOUNTER StatUnmapPage;
269 STAMCOUNTER StatMapPageFailed;
270 STAMCOUNTER StatUnmapPageFailed;
271 STAMPROFILE StatProfMapGpaRange;
272 STAMPROFILE StatProfUnmapGpaRange;
273 STAMPROFILE StatProfMapGpaRangePage;
274 STAMPROFILE StatProfUnmapGpaRangePage;
275
276 /** Statistics updated by NEMR0UpdateStatistics. */
277 struct
278 {
279 uint64_t cPagesAvailable;
280 uint64_t cPagesInUse;
281 } R0Stats;
282
283#elif defined(RT_OS_DARWIN)
284 /** Set if we've created the EMTs. */
285 bool fCreatedEmts : 1;
286 /** Set if hv_vm_create() was called successfully. */
287 bool fCreatedVm : 1;
288# if defined(VBOX_VMM_TARGET_ARMV8)
289 /** @todo */
290# else
291 /** Set if hv_vm_space_create() was called successfully. */
292 bool fCreatedAsid : 1;
293 /** Set if Last Branch Record (LBR) is enabled. */
294 bool fLbr;
295 /** The ASID for this VM (only valid if fCreatedAsid is true). */
296 hv_vm_space_t uVmAsid;
297 /** Number of mach time units per NS, for hv_vcpu_run_until(). */
298 uint64_t cMachTimePerNs;
299 /** Pause-loop exiting (PLE) gap in ticks. */
300 uint32_t cPleGapTicks;
301 /** Pause-loop exiting (PLE) window in ticks. */
302 uint32_t cPleWindowTicks;
303
304 /** The host LBR TOS (top-of-stack) MSR id. */
305 uint32_t idLbrTosMsr;
306 /** The host LBR select MSR id. */
307 uint32_t idLbrSelectMsr;
308 /** The host last event record from IP MSR id. */
309 uint32_t idLerFromIpMsr;
310 /** The host last event record to IP MSR id. */
311 uint32_t idLerToIpMsr;
312
313 /** The first valid host LBR branch-from-IP stack range. */
314 uint32_t idLbrFromIpMsrFirst;
315 /** The last valid host LBR branch-from-IP stack range. */
316 uint32_t idLbrFromIpMsrLast;
317
318 /** The first valid host LBR branch-to-IP stack range. */
319 uint32_t idLbrToIpMsrFirst;
320 /** The last valid host LBR branch-to-IP stack range. */
321 uint32_t idLbrToIpMsrLast;
322
323 /** The first valid host LBR info stack range. */
324 uint32_t idLbrInfoMsrFirst;
325 /** The last valid host LBR info stack range. */
326 uint32_t idLbrInfoMsrLast;
327# endif
328
329 STAMCOUNTER StatMapPage;
330 STAMCOUNTER StatUnmapPage;
331 STAMCOUNTER StatMapPageFailed;
332 STAMCOUNTER StatUnmapPageFailed;
333#endif /* RT_OS_WINDOWS */
334} NEM;
335/** Pointer to NEM VM instance data. */
336typedef NEM *PNEM;
337
338/** NEM::u32Magic value. */
339#define NEM_MAGIC UINT32_C(0x004d454e)
340/** NEM::u32Magic value after termination. */
341#define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
342
343
344/**
345 * NEM VMCPU Instance data.
346 */
347typedef struct NEMCPU
348{
349 /** NEMCPU_MAGIC. */
350 uint32_t u32Magic;
351 /** Whether \#UD needs to be intercepted and presented to GIM. */
352 bool fGIMTrapXcptUD : 1;
353 /** Whether \#GP needs to be intercept for mesa driver workaround. */
354 bool fTrapXcptGpForLovelyMesaDrv: 1;
355 /** Whether we should use the debug loop because of single stepping or special
356 * debug breakpoints / events are armed. */
357 bool fUseDebugLoop : 1;
358 /** Whether we're executing a single instruction. */
359 bool fSingleInstruction : 1;
360 /** Set if we using the debug loop and wish to intercept RDTSC. */
361 bool fDebugWantRdTscExit : 1;
362 /** Whether we are currently executing in the debug loop.
363 * Mainly for assertions. */
364 bool fUsingDebugLoop : 1;
365 /** Set if we need to clear the trap flag because of single stepping. */
366 bool fClearTrapFlag : 1;
367 /** Whether we're using the hyper DR7 or guest DR7. */
368 bool fUsingHyperDR7 : 1;
369 /** Whether \#DE needs to be intercepted for GIM. */
370 bool fGCMTrapXcptDE : 1;
371
372#if defined(RT_OS_LINUX)
373 uint8_t abPadding[3];
374 /** The KVM VCpu file descriptor. */
375 int32_t fdVCpu;
376 /** Pointer to the KVM_RUN data exchange region. */
377 R3PTRTYPE(struct kvm_run *) pRun;
378 /** The MSR_IA32_APICBASE value known to KVM. */
379 uint64_t uKvmApicBase;
380
381 /** @name Statistics
382 * @{ */
383 STAMCOUNTER StatExitTotal;
384 STAMCOUNTER StatExitIo;
385 STAMCOUNTER StatExitMmio;
386 STAMCOUNTER StatExitSetTpr;
387 STAMCOUNTER StatExitTprAccess;
388 STAMCOUNTER StatExitRdMsr;
389 STAMCOUNTER StatExitWrMsr;
390 STAMCOUNTER StatExitIrqWindowOpen;
391 STAMCOUNTER StatExitHalt;
392 STAMCOUNTER StatExitIntr;
393 STAMCOUNTER StatExitHypercall;
394 STAMCOUNTER StatExitDebug;
395 STAMCOUNTER StatExitBusLock;
396 STAMCOUNTER StatExitInternalErrorEmulation;
397 STAMCOUNTER StatExitInternalErrorFatal;
398# if 0
399 STAMCOUNTER StatExitCpuId;
400 STAMCOUNTER StatExitUnrecoverable;
401 STAMCOUNTER StatGetMsgTimeout;
402 STAMCOUNTER StatStopCpuSuccess;
403 STAMCOUNTER StatStopCpuPending;
404 STAMCOUNTER StatStopCpuPendingAlerts;
405 STAMCOUNTER StatStopCpuPendingOdd;
406 STAMCOUNTER StatCancelChangedState;
407 STAMCOUNTER StatCancelAlertedThread;
408# endif
409 STAMCOUNTER StatBreakOnCancel;
410 STAMCOUNTER StatBreakOnFFPre;
411 STAMCOUNTER StatBreakOnFFPost;
412 STAMCOUNTER StatBreakOnStatus;
413 STAMCOUNTER StatFlushExitOnReturn;
414 STAMCOUNTER StatFlushExitOnReturn1Loop;
415 STAMCOUNTER StatFlushExitOnReturn2Loops;
416 STAMCOUNTER StatFlushExitOnReturn3Loops;
417 STAMCOUNTER StatFlushExitOnReturn4PlusLoops;
418 STAMCOUNTER StatImportOnDemand;
419 STAMCOUNTER StatImportOnReturn;
420 STAMCOUNTER StatImportOnReturnSkipped;
421 STAMCOUNTER StatImportPendingInterrupt;
422 STAMCOUNTER StatExportPendingInterrupt;
423 STAMCOUNTER StatQueryCpuTick;
424 /** @} */
425
426
427#elif defined(RT_OS_WINDOWS)
428 /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
429 uint8_t fCurrentInterruptWindows;
430 /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
431 uint8_t fDesiredInterruptWindows;
432 /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
433 bool fLastInterruptShadow : 1;
434 uint32_t uPadding;
435 /** The VID_MSHAGN_F_XXX flags.
436 * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
437 uint32_t fHandleAndGetFlags;
438 /** What VidMessageSlotMap returns and is used for passing exit info. */
439 RTR3PTR pvMsgSlotMapping;
440 /** The windows thread handle. */
441 RTR3PTR hNativeThreadHandle;
442
443 /** @name Statistics
444 * @{ */
445 STAMCOUNTER StatExitPortIo;
446 STAMCOUNTER StatExitMemUnmapped;
447 STAMCOUNTER StatExitMemIntercept;
448 STAMCOUNTER StatExitHalt;
449 STAMCOUNTER StatExitInterruptWindow;
450 STAMCOUNTER StatExitCpuId;
451 STAMCOUNTER StatExitMsr;
452 STAMCOUNTER StatExitException;
453 STAMCOUNTER StatExitExceptionBp;
454 STAMCOUNTER StatExitExceptionDb;
455 STAMCOUNTER StatExitExceptionGp;
456 STAMCOUNTER StatExitExceptionGpMesa;
457 STAMCOUNTER StatExitExceptionUd;
458 STAMCOUNTER StatExitExceptionUdHandled;
459 STAMCOUNTER StatExitUnrecoverable;
460 STAMCOUNTER StatGetMsgTimeout;
461 STAMCOUNTER StatStopCpuSuccess;
462 STAMCOUNTER StatStopCpuPending;
463 STAMCOUNTER StatStopCpuPendingAlerts;
464 STAMCOUNTER StatStopCpuPendingOdd;
465 STAMCOUNTER StatCancelChangedState;
466 STAMCOUNTER StatCancelAlertedThread;
467 STAMCOUNTER StatBreakOnCancel;
468 STAMCOUNTER StatBreakOnFFPre;
469 STAMCOUNTER StatBreakOnFFPost;
470 STAMCOUNTER StatBreakOnStatus;
471 STAMCOUNTER StatImportOnDemand;
472 STAMCOUNTER StatImportOnReturn;
473 STAMCOUNTER StatImportOnReturnSkipped;
474 STAMCOUNTER StatQueryCpuTick;
475 /** @} */
476
477#elif defined(RT_OS_DARWIN)
478# if defined(VBOX_VMM_TARGET_ARMV8)
479 /** The vCPU handle associated with the EMT executing this vCPU. */
480 hv_vcpu_t hVCpu;
481 /** Pointer to the exit information structure. */
482 hv_vcpu_exit_t *pHvExit;
483 /** Flag whether an event is pending. */
484 bool fEventPending;
485# else
486 /** The vCPU handle associated with the EMT executing this vCPU. */
487 hv_vcpuid_t hVCpuId;
488
489 /** @name State shared with the VT-x code.
490 * @{ */
491 /** An additional error code used for some gurus. */
492 uint32_t u32HMError;
493 /** The last exit-to-ring-3 reason. */
494 int32_t rcLastExitToR3;
495 /** CPU-context changed flags (see HM_CHANGED_xxx). */
496 uint64_t fCtxChanged;
497
498 /** The guest VMCS information. */
499 VMXVMCSINFO VmcsInfo;
500
501 /** VT-x data. */
502 struct HMCPUVMX
503 {
504 /** @name Guest information.
505 * @{ */
506 /** Guest VMCS information shared with ring-3. */
507 VMXVMCSINFOSHARED VmcsInfo;
508 /** Nested-guest VMCS information shared with ring-3. */
509 VMXVMCSINFOSHARED VmcsInfoNstGst;
510 /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
511 * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
512 bool fSwitchedToNstGstVmcsCopyForRing3;
513 /** Whether the static guest VMCS controls has been merged with the
514 * nested-guest VMCS controls. */
515 bool fMergedNstGstCtls;
516 /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
517 bool fCopiedNstGstToShadowVmcs;
518 /** Whether flushing the TLB is required due to switching to/from the
519 * nested-guest. */
520 bool fSwitchedNstGstFlushTlb;
521 /** Alignment. */
522 bool afAlignment0[4];
523 /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
524 uint64_t u64GstMsrApicBase;
525 /** @} */
526
527 /** @name Error reporting and diagnostics.
528 * @{ */
529 /** VT-x error-reporting (mainly for ring-3 propagation). */
530 struct
531 {
532 RTCPUID idCurrentCpu;
533 RTCPUID idEnteredCpu;
534 RTHCPHYS HCPhysCurrentVmcs;
535 uint32_t u32VmcsRev;
536 uint32_t u32InstrError;
537 uint32_t u32ExitReason;
538 uint32_t u32GuestIntrState;
539 } LastError;
540 /** @} */
541 } vmx;
542
543 /** Event injection state. */
544 HMEVENT Event;
545
546 /** Current shadow paging mode for updating CR4.
547 * @todo move later (@bugref{9217}). */
548 PGMMODE enmShadowMode;
549 uint32_t u32TemporaryPadding;
550
551 /** The PAE PDPEs used with Nested Paging (only valid when
552 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
553 X86PDPE aPdpes[4];
554 /** Pointer to the VMX statistics. */
555 PVMXSTATISTICS pVmxStats;
556# endif
557
558 /** @name Statistics
559 * @{ */
560 STAMCOUNTER StatExitAll;
561 STAMCOUNTER StatBreakOnCancel;
562 STAMCOUNTER StatBreakOnFFPre;
563 STAMCOUNTER StatBreakOnFFPost;
564 STAMCOUNTER StatBreakOnStatus;
565 STAMCOUNTER StatImportOnDemand;
566 STAMCOUNTER StatImportOnReturn;
567 STAMCOUNTER StatImportOnReturnSkipped;
568 STAMCOUNTER StatQueryCpuTick;
569#ifdef VBOX_WITH_STATISTICS
570 STAMPROFILEADV StatProfGstStateImport;
571 STAMPROFILEADV StatProfGstStateExport;
572#endif
573 /** @} */
574
575 /** @} */
576#endif /* RT_OS_DARWIN */
577} NEMCPU;
578/** Pointer to NEM VMCPU instance data. */
579typedef NEMCPU *PNEMCPU;
580
581/** NEMCPU::u32Magic value. */
582#define NEMCPU_MAGIC UINT32_C(0x4d454e20)
583/** NEMCPU::u32Magic value after termination. */
584#define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
585
586
587#ifdef IN_RING0
588# ifdef RT_OS_WINDOWS
589/**
590 * Windows: Hypercall input/ouput page info.
591 */
592typedef struct NEMR0HYPERCALLDATA
593{
594 /** Host physical address of the hypercall input/output page. */
595 RTHCPHYS HCPhysPage;
596 /** Pointer to the hypercall input/output page. */
597 uint8_t *pbPage;
598 /** Handle to the memory object of the hypercall input/output page. */
599 RTR0MEMOBJ hMemObj;
600} NEMR0HYPERCALLDATA;
601/** Pointer to a Windows hypercall input/output page info. */
602typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
603# endif /* RT_OS_WINDOWS */
604
605/**
606 * NEM GVMCPU instance data.
607 */
608typedef struct NEMR0PERVCPU
609{
610 uint32_t uDummy;
611} NEMR0PERVCPU;
612
613/**
614 * NEM GVM instance data.
615 */
616typedef struct NEMR0PERVM
617{
618 uint32_t uDummy;
619} NEMR0PERVM;
620
621#endif /* IN_RING*/
622
623
624#ifdef IN_RING3
625int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
626int nemR3NativeInitAfterCPUM(PVM pVM);
627int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
628int nemR3NativeTerm(PVM pVM);
629void nemR3NativeReset(PVM pVM);
630void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
631VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
632bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
633bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
634
635/**
636 * Forced flag notification call from VMEmt.h.
637 *
638 * This is only called when pVCpu is in the VMCPUSTATE_STARTED_EXEC_NEM state.
639 *
640 * @param pVM The cross context VM structure.
641 * @param pVCpu The cross context virtual CPU structure of the CPU
642 * to be notified.
643 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_XXX.
644 */
645void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
646
647/**
648 * Called by NEMR3NotifyDebugEventChanged() to let the native backend take the final decision
649 * on whether to switch to the debug loop.
650 *
651 * @returns Final flag whether to switch to the debug loop.
652 * @param pVM The VM cross context VM structure.
653 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChanged().
654 * @thread EMT(0)
655 */
656DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChanged(PVM pVM, bool fUseDebugLoop);
657
658
659/**
660 * Called by NEMR3NotifyDebugEventChangedPerCpu() to let the native backend take the final decision
661 * on whether to switch to the debug loop.
662 *
663 * @returns Final flag whether to switch to the debug loop.
664 * @param pVM The VM cross context VM structure.
665 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
666 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChangedPerCpu().
667 */
668DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu, bool fUseDebugLoop);
669#endif
670
671void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
672void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
673 RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
674int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
675 PGMPAGETYPE enmType, uint8_t *pu2State);
676
677
678#ifdef RT_OS_WINDOWS
679/** Maximum number of pages we can map in a single NEMR0MapPages call. */
680# define NEM_MAX_MAP_PAGES ((HOST_PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
681/** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
682# define NEM_MAX_UNMAP_PAGES 4095
683
684#endif
685/** @} */
686
687RT_C_DECLS_END
688
689#endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
690
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette