VirtualBox

source: vbox/trunk/src/VBox/VMM/include/REMInternal.h@ 77922

Last change on this file since 77922 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 9.0 KB
Line 
1/* $Id: REMInternal.h 76585 2019-01-01 06:31:29Z vboxsync $ */
2/** @file
3 * REM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2019 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_REMInternal_h
19#define VMM_INCLUDED_SRC_include_REMInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBox/types.h>
25#include <VBox/vmm/cpum.h>
26#include <VBox/vmm/stam.h>
27#include <VBox/vmm/pgm.h>
28#include <VBox/vmm/pdmcritsect.h>
29#ifdef REM_INCLUDE_CPU_H
30# include "target-i386/cpu.h"
31#endif
32
33
34
35/** @defgroup grp_rem_int Internals
36 * @ingroup grp_rem
37 * @internal
38 * @{
39 */
40
41/** The saved state version number. */
42#define REM_SAVED_STATE_VERSION_VER1_6 6
43#define REM_SAVED_STATE_VERSION 7
44
45
46/** @def REM_MONITOR_CODE_PAGES
47 * Enable to monitor code pages that have been translated by the recompiler. */
48/** Currently broken and interferes with CSAM monitoring (see @bugref{2784}) */
49////#define REM_MONITOR_CODE_PAGES
50#ifdef DOXYGEN_RUNNING
51# define REM_MONITOR_CODE_PAGES
52#endif
53
54typedef enum REMHANDLERNOTIFICATIONKIND
55{
56 /** The usual invalid 0 entry. */
57 REMHANDLERNOTIFICATIONKIND_INVALID = 0,
58 /** REMR3NotifyHandlerPhysicalRegister. */
59 REMHANDLERNOTIFICATIONKIND_PHYSICAL_REGISTER,
60 /** REMR3NotifyHandlerPhysicalDeregister. */
61 REMHANDLERNOTIFICATIONKIND_PHYSICAL_DEREGISTER,
62 /** REMR3NotifyHandlerPhysicalModify. */
63 REMHANDLERNOTIFICATIONKIND_PHYSICAL_MODIFY,
64 /** The usual 32-bit hack. */
65 REMHANDLERNOTIFICATIONKIND_32BIT_HACK = 0x7fffffff
66} REMHANDLERNOTIFICATIONKIND;
67
68
69/**
70 * A recorded handler notification.
71 */
72typedef struct REMHANDLERNOTIFICATION
73{
74 /** The notification kind. */
75 REMHANDLERNOTIFICATIONKIND enmKind;
76 uint32_t padding;
77 /** Type specific data. */
78 union
79 {
80 struct
81 {
82 RTGCPHYS GCPhys;
83 RTGCPHYS cb;
84 PGMPHYSHANDLERKIND enmKind;
85 bool fHasHCHandler;
86 } PhysicalRegister;
87
88 struct
89 {
90 RTGCPHYS GCPhys;
91 RTGCPHYS cb;
92 PGMPHYSHANDLERKIND enmKind;
93 bool fHasHCHandler;
94 bool fRestoreAsRAM;
95 } PhysicalDeregister;
96
97 struct
98 {
99 RTGCPHYS GCPhysOld;
100 RTGCPHYS GCPhysNew;
101 RTGCPHYS cb;
102 PGMPHYSHANDLERKIND enmKind;
103 bool fHasHCHandler;
104 bool fRestoreAsRAM;
105 } PhysicalModify;
106 uint64_t padding[5];
107 } u;
108 uint32_t idxSelf;
109 uint32_t volatile idxNext;
110} REMHANDLERNOTIFICATION;
111/** Pointer to a handler notification record. */
112typedef REMHANDLERNOTIFICATION *PREMHANDLERNOTIFICATION;
113
114/**
115 * Converts a REM pointer into a VM pointer.
116 * @returns Pointer to the VM structure the REM is part of.
117 * @param pREM Pointer to REM instance data.
118 */
119#define REM2VM(pREM) ( (PVM)((char*)pREM - pREM->offVM) )
120
121
122/**
123 * REM Data (part of VM)
124 */
125typedef struct REM
126{
127 /** Offset to the VM structure. */
128 RTINT offVM;
129 /** Alignment padding. */
130 RTUINT uPadding0;
131
132 /** Cached pointer of the register context of the current VCPU. */
133 R3PTRTYPE(PCPUMCTX) pCtx;
134
135 /** In REM mode.
136 * I.e. the correct CPU state and some other bits are with REM. */
137 bool volatile fInREM;
138 /** In REMR3State. */
139 bool fInStateSync;
140
141 /** Set when the translation blocks cache need to be flushed. */
142 bool fFlushTBs;
143
144 /** Ignore CR3 load notifications from the REM. */
145 bool fIgnoreCR3Load;
146 /** Ignore invlpg notifications from the REM. */
147 bool fIgnoreInvlPg;
148 /** Ignore CR0, CR4 and EFER load. */
149 bool fIgnoreCpuMode;
150 /** Ignore set page. */
151 bool fIgnoreSetPage;
152 bool bPadding1;
153
154 /** Ignore all that can be ignored. */
155 uint32_t cIgnoreAll;
156
157 /** Number of times REMR3CanExecuteRaw has been called.
158 * It is used to prevent rescheduling on the first call. */
159 uint32_t cCanExecuteRaw;
160
161 /** Pending interrupt that remR3LoadDone will assert with TRPM. */
162 uint32_t uStateLoadPendingInterrupt;
163
164 /** Number of recorded invlpg instructions. */
165 uint32_t volatile cInvalidatedPages;
166#if HC_ARCH_BITS == 32
167 uint32_t uPadding2;
168#endif
169 /** Array of recorded invlpg instruction.
170 * These instructions are replayed when entering REM. */
171 RTGCPTR aGCPtrInvalidatedPages[48];
172
173 /** Array of recorded handler notifications.
174 * These are replayed when entering REM. */
175 REMHANDLERNOTIFICATION aHandlerNotifications[64];
176 volatile uint32_t idxPendingList;
177 volatile uint32_t idxFreeList;
178
179 /** MMIO memory type.
180 * This is used to register MMIO physical access handlers. */
181 int32_t iMMIOMemType;
182 /** Handler memory type.
183 * This is used to register non-MMIO physical access handlers which are executed in HC. */
184 int32_t iHandlerMemType;
185
186 /** Pending exception */
187 uint32_t uPendingException;
188 /** Nr of pending exceptions */
189 uint32_t cPendingExceptions;
190 /** Pending exception's EIP */
191 RTGCPTR uPendingExcptEIP;
192 /** Pending exception's CR2 */
193 RTGCPTR uPendingExcptCR2;
194
195 /** The highest known RAM address. */
196 RTGCPHYS GCPhysLastRam;
197 /** Whether GCPhysLastRam has been fixed (see REMR3Init()). */
198 bool fGCPhysLastRamFixed;
199
200 /** Pending rc. */
201 int32_t rc;
202
203 /** REM critical section.
204 * This protects cpu_register_physical_memory usage
205 */
206 PDMCRITSECT CritSectRegister;
207
208 /** Time spent in QEMU. */
209 STAMPROFILEADV StatsInQEMU;
210 /** Time spent in rawmode.c. */
211 STAMPROFILEADV StatsInRAWEx;
212 /** Time spent switching state. */
213 STAMPROFILE StatsState;
214 /** Time spent switching state back. */
215 STAMPROFILE StatsStateBack;
216
217 /** Padding the CPUX86State structure to 64 byte. */
218 uint32_t abPadding[HC_ARCH_BITS == 32 ? 4 : 4];
219
220# define REM_ENV_SIZE 0xff00
221
222 /** Recompiler CPU state. */
223#ifdef REM_INCLUDE_CPU_H
224 CPUX86State Env;
225#else
226 struct FakeEnv
227 {
228 char achPadding[REM_ENV_SIZE];
229 } Env;
230#endif /* !REM_INCLUDE_CPU_H */
231} REM;
232
233/** Pointer to the REM Data. */
234typedef REM *PREM;
235
236
237#ifdef REM_INCLUDE_CPU_H
238bool remR3CanExecuteRaw(CPUState *env, RTGCPTR eip, unsigned fFlags, int *piException);
239void remR3CSAMCheckEIP(CPUState *env, RTGCPTR GCPtrCode);
240# ifdef VBOX_WITH_RAW_MODE
241bool remR3GetOpcode(CPUState *env, RTGCPTR GCPtrInstr, uint8_t *pu8Byte);
242# endif
243bool remR3DisasInstr(CPUState *env, int f32BitCode, char *pszPrefix);
244void remR3FlushPage(CPUState *env, RTGCPTR GCPtr);
245void remR3FlushTLB(CPUState *env, bool fGlobal);
246void remR3ProtectCode(CPUState *env, RTGCPTR GCPtr);
247void remR3ChangeCpuMode(CPUState *env);
248void remR3DmaRun(CPUState *env);
249void remR3TimersRun(CPUState *env);
250int remR3NotifyTrap(CPUState *env, uint32_t uTrap, uint32_t uErrorCode, RTGCPTR pvNextEIP);
251void remR3TrapStat(CPUState *env, uint32_t uTrap);
252void remR3RecordCall(CPUState *env);
253#endif /* REM_INCLUDE_CPU_H */
254void remR3TrapClear(PVM pVM);
255void remR3RaiseRC(PVM pVM, int rc);
256void remR3DumpLnxSyscall(PVMCPU pVCpu);
257void remR3DumpOBsdSyscall(PVMCPU pVCpu);
258
259
260/** @todo r=bird: clean up the RAWEx stats. */
261/* temporary hacks */
262#define RAWEx_ProfileStart(a, b) remR3ProfileStart(b)
263#define RAWEx_ProfileStop(a, b) remR3ProfileStop(b)
264
265
266#ifdef VBOX_WITH_STATISTICS
267
268# define STATS_EMULATE_SINGLE_INSTR 1
269# define STATS_QEMU_COMPILATION 2
270# define STATS_QEMU_RUN_EMULATED_CODE 3
271# define STATS_QEMU_TOTAL 4
272# define STATS_QEMU_RUN_TIMERS 5
273# define STATS_TLB_LOOKUP 6
274# define STATS_IRQ_HANDLING 7
275# define STATS_RAW_CHECK 8
276
277void remR3ProfileStart(int statcode);
278void remR3ProfileStop(int statcode);
279
280#else /* !VBOX_WITH_STATISTICS */
281# define remR3ProfileStart(c) do { } while (0)
282# define remR3ProfileStop(c) do { } while (0)
283#endif /* !VBOX_WITH_STATISTICS */
284
285/** @} */
286
287#endif /* !VMM_INCLUDED_SRC_include_REMInternal_h */
288
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