VirtualBox

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

Last change on this file since 93831 was 93831, checked in by vboxsync, 3 years ago

VMM/{VMXAllTemplate.cpp.h,NEMR3Native-darwin}: Add code to allow for single stepping and sharing the guest's DRx state with th hypervisor debugger (hardware breakpoints, etc.), bugref:9044

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