VirtualBox

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

Last change on this file since 100696 was 100102, checked in by vboxsync, 19 months ago

VMM/NEMR3Native-darwin-armv8: Some basic PSCI implementation required to boot secondary CPUs + fixes the vTimer offset implementation for SMP support, bugref:10454, bugref:10390

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.7 KB
Line 
1/* $Id: NEMInternal.h 100102 2023-06-07 17:54:44Z 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_UNMAPPED 0
125# define NEM_DARWIN_PAGE_STATE_RX 1
126# define NEM_DARWIN_PAGE_STATE_RW 2
127# define NEM_DARWIN_PAGE_STATE_RWX 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 /** @name vTimer related state.
290 * @{ */
291 /** The counter frequency in Hz as obtained from CNTFRQ_EL0. */
292 uint64_t u64CntFrqHz;
293 /** The vTimer offset programmed. */
294 uint64_t u64VTimerOff;
295 /** @} */
296# else
297 /** Set if hv_vm_space_create() was called successfully. */
298 bool fCreatedAsid : 1;
299 /** Set if Last Branch Record (LBR) is enabled. */
300 bool fLbr;
301 /** The ASID for this VM (only valid if fCreatedAsid is true). */
302 hv_vm_space_t uVmAsid;
303 /** Number of mach time units per NS, for hv_vcpu_run_until(). */
304 uint64_t cMachTimePerNs;
305 /** Pause-loop exiting (PLE) gap in ticks. */
306 uint32_t cPleGapTicks;
307 /** Pause-loop exiting (PLE) window in ticks. */
308 uint32_t cPleWindowTicks;
309
310 /** The host LBR TOS (top-of-stack) MSR id. */
311 uint32_t idLbrTosMsr;
312 /** The host LBR select MSR id. */
313 uint32_t idLbrSelectMsr;
314 /** The host last event record from IP MSR id. */
315 uint32_t idLerFromIpMsr;
316 /** The host last event record to IP MSR id. */
317 uint32_t idLerToIpMsr;
318
319 /** The first valid host LBR branch-from-IP stack range. */
320 uint32_t idLbrFromIpMsrFirst;
321 /** The last valid host LBR branch-from-IP stack range. */
322 uint32_t idLbrFromIpMsrLast;
323
324 /** The first valid host LBR branch-to-IP stack range. */
325 uint32_t idLbrToIpMsrFirst;
326 /** The last valid host LBR branch-to-IP stack range. */
327 uint32_t idLbrToIpMsrLast;
328
329 /** The first valid host LBR info stack range. */
330 uint32_t idLbrInfoMsrFirst;
331 /** The last valid host LBR info stack range. */
332 uint32_t idLbrInfoMsrLast;
333# endif
334
335 STAMCOUNTER StatMapPage;
336 STAMCOUNTER StatUnmapPage;
337 STAMCOUNTER StatMapPageFailed;
338 STAMCOUNTER StatUnmapPageFailed;
339#endif /* RT_OS_WINDOWS */
340} NEM;
341/** Pointer to NEM VM instance data. */
342typedef NEM *PNEM;
343
344/** NEM::u32Magic value. */
345#define NEM_MAGIC UINT32_C(0x004d454e)
346/** NEM::u32Magic value after termination. */
347#define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
348
349
350/**
351 * NEM VMCPU Instance data.
352 */
353typedef struct NEMCPU
354{
355 /** NEMCPU_MAGIC. */
356 uint32_t u32Magic;
357 /** Whether \#UD needs to be intercepted and presented to GIM. */
358 bool fGIMTrapXcptUD : 1;
359 /** Whether \#GP needs to be intercept for mesa driver workaround. */
360 bool fTrapXcptGpForLovelyMesaDrv: 1;
361 /** Whether we should use the debug loop because of single stepping or special
362 * debug breakpoints / events are armed. */
363 bool fUseDebugLoop : 1;
364 /** Whether we're executing a single instruction. */
365 bool fSingleInstruction : 1;
366 /** Set if we using the debug loop and wish to intercept RDTSC. */
367 bool fDebugWantRdTscExit : 1;
368 /** Whether we are currently executing in the debug loop.
369 * Mainly for assertions. */
370 bool fUsingDebugLoop : 1;
371 /** Set if we need to clear the trap flag because of single stepping. */
372 bool fClearTrapFlag : 1;
373 /** Whether we're using the hyper DR7 or guest DR7. */
374 bool fUsingHyperDR7 : 1;
375 /** Whether \#DE needs to be intercepted for GIM. */
376 bool fGCMTrapXcptDE : 1;
377
378#if defined(RT_OS_LINUX)
379 uint8_t abPadding[3];
380 /** The KVM VCpu file descriptor. */
381 int32_t fdVCpu;
382 /** Pointer to the KVM_RUN data exchange region. */
383 R3PTRTYPE(struct kvm_run *) pRun;
384 /** The MSR_IA32_APICBASE value known to KVM. */
385 uint64_t uKvmApicBase;
386
387 /** @name Statistics
388 * @{ */
389 STAMCOUNTER StatExitTotal;
390 STAMCOUNTER StatExitIo;
391 STAMCOUNTER StatExitMmio;
392 STAMCOUNTER StatExitSetTpr;
393 STAMCOUNTER StatExitTprAccess;
394 STAMCOUNTER StatExitRdMsr;
395 STAMCOUNTER StatExitWrMsr;
396 STAMCOUNTER StatExitIrqWindowOpen;
397 STAMCOUNTER StatExitHalt;
398 STAMCOUNTER StatExitIntr;
399 STAMCOUNTER StatExitHypercall;
400 STAMCOUNTER StatExitDebug;
401 STAMCOUNTER StatExitBusLock;
402 STAMCOUNTER StatExitInternalErrorEmulation;
403 STAMCOUNTER StatExitInternalErrorFatal;
404# if 0
405 STAMCOUNTER StatExitCpuId;
406 STAMCOUNTER StatExitUnrecoverable;
407 STAMCOUNTER StatGetMsgTimeout;
408 STAMCOUNTER StatStopCpuSuccess;
409 STAMCOUNTER StatStopCpuPending;
410 STAMCOUNTER StatStopCpuPendingAlerts;
411 STAMCOUNTER StatStopCpuPendingOdd;
412 STAMCOUNTER StatCancelChangedState;
413 STAMCOUNTER StatCancelAlertedThread;
414# endif
415 STAMCOUNTER StatBreakOnCancel;
416 STAMCOUNTER StatBreakOnFFPre;
417 STAMCOUNTER StatBreakOnFFPost;
418 STAMCOUNTER StatBreakOnStatus;
419 STAMCOUNTER StatFlushExitOnReturn;
420 STAMCOUNTER StatFlushExitOnReturn1Loop;
421 STAMCOUNTER StatFlushExitOnReturn2Loops;
422 STAMCOUNTER StatFlushExitOnReturn3Loops;
423 STAMCOUNTER StatFlushExitOnReturn4PlusLoops;
424 STAMCOUNTER StatImportOnDemand;
425 STAMCOUNTER StatImportOnReturn;
426 STAMCOUNTER StatImportOnReturnSkipped;
427 STAMCOUNTER StatImportPendingInterrupt;
428 STAMCOUNTER StatExportPendingInterrupt;
429 STAMCOUNTER StatQueryCpuTick;
430 /** @} */
431
432
433#elif defined(RT_OS_WINDOWS)
434 /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
435 uint8_t fCurrentInterruptWindows;
436 /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
437 uint8_t fDesiredInterruptWindows;
438 /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
439 bool fLastInterruptShadow : 1;
440 uint32_t uPadding;
441 /** The VID_MSHAGN_F_XXX flags.
442 * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
443 uint32_t fHandleAndGetFlags;
444 /** What VidMessageSlotMap returns and is used for passing exit info. */
445 RTR3PTR pvMsgSlotMapping;
446 /** The windows thread handle. */
447 RTR3PTR hNativeThreadHandle;
448
449 /** @name Statistics
450 * @{ */
451 STAMCOUNTER StatExitPortIo;
452 STAMCOUNTER StatExitMemUnmapped;
453 STAMCOUNTER StatExitMemIntercept;
454 STAMCOUNTER StatExitHalt;
455 STAMCOUNTER StatExitInterruptWindow;
456 STAMCOUNTER StatExitCpuId;
457 STAMCOUNTER StatExitMsr;
458 STAMCOUNTER StatExitException;
459 STAMCOUNTER StatExitExceptionBp;
460 STAMCOUNTER StatExitExceptionDb;
461 STAMCOUNTER StatExitExceptionGp;
462 STAMCOUNTER StatExitExceptionGpMesa;
463 STAMCOUNTER StatExitExceptionUd;
464 STAMCOUNTER StatExitExceptionUdHandled;
465 STAMCOUNTER StatExitUnrecoverable;
466 STAMCOUNTER StatGetMsgTimeout;
467 STAMCOUNTER StatStopCpuSuccess;
468 STAMCOUNTER StatStopCpuPending;
469 STAMCOUNTER StatStopCpuPendingAlerts;
470 STAMCOUNTER StatStopCpuPendingOdd;
471 STAMCOUNTER StatCancelChangedState;
472 STAMCOUNTER StatCancelAlertedThread;
473 STAMCOUNTER StatBreakOnCancel;
474 STAMCOUNTER StatBreakOnFFPre;
475 STAMCOUNTER StatBreakOnFFPost;
476 STAMCOUNTER StatBreakOnStatus;
477 STAMCOUNTER StatImportOnDemand;
478 STAMCOUNTER StatImportOnReturn;
479 STAMCOUNTER StatImportOnReturnSkipped;
480 STAMCOUNTER StatQueryCpuTick;
481 /** @} */
482
483#elif defined(RT_OS_DARWIN)
484# if defined(VBOX_VMM_TARGET_ARMV8)
485 /** The vCPU handle associated with the EMT executing this vCPU. */
486 hv_vcpu_t hVCpu;
487 /** Pointer to the exit information structure. */
488 hv_vcpu_exit_t *pHvExit;
489 /** Flag whether an event is pending. */
490 bool fEventPending;
491 /** Flag whether the vTimer got activated and is masked. */
492 bool fVTimerActivated;
493 /** Flag whether to update the vTimer offset. */
494 bool fVTimerOffUpdate;
495# else
496 /** The vCPU handle associated with the EMT executing this vCPU. */
497 hv_vcpuid_t hVCpuId;
498
499 /** @name State shared with the VT-x code.
500 * @{ */
501 /** An additional error code used for some gurus. */
502 uint32_t u32HMError;
503 /** The last exit-to-ring-3 reason. */
504 int32_t rcLastExitToR3;
505 /** CPU-context changed flags (see HM_CHANGED_xxx). */
506 uint64_t fCtxChanged;
507
508 /** The guest VMCS information. */
509 VMXVMCSINFO VmcsInfo;
510
511 /** VT-x data. */
512 struct HMCPUVMX
513 {
514 /** @name Guest information.
515 * @{ */
516 /** Guest VMCS information shared with ring-3. */
517 VMXVMCSINFOSHARED VmcsInfo;
518 /** Nested-guest VMCS information shared with ring-3. */
519 VMXVMCSINFOSHARED VmcsInfoNstGst;
520 /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
521 * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
522 bool fSwitchedToNstGstVmcsCopyForRing3;
523 /** Whether the static guest VMCS controls has been merged with the
524 * nested-guest VMCS controls. */
525 bool fMergedNstGstCtls;
526 /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
527 bool fCopiedNstGstToShadowVmcs;
528 /** Whether flushing the TLB is required due to switching to/from the
529 * nested-guest. */
530 bool fSwitchedNstGstFlushTlb;
531 /** Alignment. */
532 bool afAlignment0[4];
533 /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
534 uint64_t u64GstMsrApicBase;
535 /** @} */
536
537 /** @name Error reporting and diagnostics.
538 * @{ */
539 /** VT-x error-reporting (mainly for ring-3 propagation). */
540 struct
541 {
542 RTCPUID idCurrentCpu;
543 RTCPUID idEnteredCpu;
544 RTHCPHYS HCPhysCurrentVmcs;
545 uint32_t u32VmcsRev;
546 uint32_t u32InstrError;
547 uint32_t u32ExitReason;
548 uint32_t u32GuestIntrState;
549 } LastError;
550 /** @} */
551 } vmx;
552
553 /** Event injection state. */
554 HMEVENT Event;
555
556 /** Current shadow paging mode for updating CR4.
557 * @todo move later (@bugref{9217}). */
558 PGMMODE enmShadowMode;
559 uint32_t u32TemporaryPadding;
560
561 /** The PAE PDPEs used with Nested Paging (only valid when
562 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
563 X86PDPE aPdpes[4];
564 /** Pointer to the VMX statistics. */
565 PVMXSTATISTICS pVmxStats;
566# endif
567
568 /** @name Statistics
569 * @{ */
570 STAMCOUNTER StatExitAll;
571 STAMCOUNTER StatBreakOnCancel;
572 STAMCOUNTER StatBreakOnFFPre;
573 STAMCOUNTER StatBreakOnFFPost;
574 STAMCOUNTER StatBreakOnStatus;
575 STAMCOUNTER StatImportOnDemand;
576 STAMCOUNTER StatImportOnReturn;
577 STAMCOUNTER StatImportOnReturnSkipped;
578 STAMCOUNTER StatQueryCpuTick;
579#ifdef VBOX_WITH_STATISTICS
580 STAMPROFILEADV StatProfGstStateImport;
581 STAMPROFILEADV StatProfGstStateExport;
582#endif
583 /** @} */
584
585 /** @} */
586#endif /* RT_OS_DARWIN */
587} NEMCPU;
588/** Pointer to NEM VMCPU instance data. */
589typedef NEMCPU *PNEMCPU;
590
591/** NEMCPU::u32Magic value. */
592#define NEMCPU_MAGIC UINT32_C(0x4d454e20)
593/** NEMCPU::u32Magic value after termination. */
594#define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
595
596
597#ifdef IN_RING0
598# ifdef RT_OS_WINDOWS
599/**
600 * Windows: Hypercall input/ouput page info.
601 */
602typedef struct NEMR0HYPERCALLDATA
603{
604 /** Host physical address of the hypercall input/output page. */
605 RTHCPHYS HCPhysPage;
606 /** Pointer to the hypercall input/output page. */
607 uint8_t *pbPage;
608 /** Handle to the memory object of the hypercall input/output page. */
609 RTR0MEMOBJ hMemObj;
610} NEMR0HYPERCALLDATA;
611/** Pointer to a Windows hypercall input/output page info. */
612typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
613# endif /* RT_OS_WINDOWS */
614
615/**
616 * NEM GVMCPU instance data.
617 */
618typedef struct NEMR0PERVCPU
619{
620 uint32_t uDummy;
621} NEMR0PERVCPU;
622
623/**
624 * NEM GVM instance data.
625 */
626typedef struct NEMR0PERVM
627{
628 uint32_t uDummy;
629} NEMR0PERVM;
630
631#endif /* IN_RING*/
632
633
634#ifdef IN_RING3
635
636int nemR3DisableCpuIsaExt(PVM pVM, const char *pszIsaExt);
637
638int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
639int nemR3NativeInitAfterCPUM(PVM pVM);
640int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
641int nemR3NativeTerm(PVM pVM);
642void nemR3NativeReset(PVM pVM);
643void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
644VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
645bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
646bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
647
648/**
649 * Forced flag notification call from VMEmt.h.
650 *
651 * This is only called when pVCpu is in the VMCPUSTATE_STARTED_EXEC_NEM state.
652 *
653 * @param pVM The cross context VM structure.
654 * @param pVCpu The cross context virtual CPU structure of the CPU
655 * to be notified.
656 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_XXX.
657 */
658void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
659
660/**
661 * Called by NEMR3NotifyDebugEventChanged() to let the native backend take the final decision
662 * on whether to switch to the debug loop.
663 *
664 * @returns Final flag whether to switch to the debug loop.
665 * @param pVM The VM cross context VM structure.
666 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChanged().
667 * @thread EMT(0)
668 */
669DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChanged(PVM pVM, bool fUseDebugLoop);
670
671
672/**
673 * Called by NEMR3NotifyDebugEventChangedPerCpu() to let the native backend take the final decision
674 * on whether to switch to the debug loop.
675 *
676 * @returns Final flag whether to switch to the debug loop.
677 * @param pVM The VM cross context VM structure.
678 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
679 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChangedPerCpu().
680 */
681DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu, bool fUseDebugLoop);
682
683#endif /* IN_RING3 */
684
685void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
686void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
687 RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
688int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
689 PGMPAGETYPE enmType, uint8_t *pu2State);
690
691
692#ifdef RT_OS_WINDOWS
693/** Maximum number of pages we can map in a single NEMR0MapPages call. */
694# define NEM_MAX_MAP_PAGES ((HOST_PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
695/** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
696# define NEM_MAX_UNMAP_PAGES 4095
697
698#endif
699/** @} */
700
701RT_C_DECLS_END
702
703#endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
704
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