VirtualBox

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

Last change on this file since 8889 was 8223, checked in by vboxsync, 17 years ago

Disabled rem code page monitoring (broken since changeset 20831) and conflicts with CSAM page monitoring (see #2784)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
1/* $Id: REMInternal.h 8223 2008-04-21 12:30:34Z vboxsync $ */
2/** @file
3 * REM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ___REMInternal_h
23#define ___REMInternal_h
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27#include <VBox/cpum.h>
28#include <VBox/stam.h>
29#include <VBox/pgm.h>
30#ifdef REM_INCLUDE_CPU_H
31# include "target-i386/cpu.h"
32#endif
33
34
35#if !defined(IN_REM_R3) && !defined(IN_REM_R0) && !defined(IN_REM_GC)
36# error "Not in REM! This is an internal header!"
37#endif
38
39/** @defgroup grp_rem_int Internals
40 * @ingroup grp_rem
41 * @internal
42 * @{
43 */
44
45/** The saved state version number. */
46#define REM_SAVED_STATE_VERSION 6
47
48
49/** @def REM_MONITOR_CODE_PAGES
50 * Enable to monitor code pages that have been translated by the recompiler. */
51/** Currently broken and interferes with CSAM monitoring (see #2784) */
52////#define REM_MONITOR_CODE_PAGES
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 notificiation.
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 PGMPHYSHANDLERTYPE enmType;
85 bool fHasHCHandler;
86 } PhysicalRegister;
87
88 struct
89 {
90 RTGCPHYS GCPhys;
91 RTGCPHYS cb;
92 PGMPHYSHANDLERTYPE enmType;
93 bool fHasHCHandler;
94 bool fRestoreAsRAM;
95 } PhysicalDeregister;
96
97 struct
98 {
99 RTGCPHYS GCPhysOld;
100 RTGCPHYS GCPhysNew;
101 RTGCPHYS cb;
102 PGMPHYSHANDLERTYPE enmType;
103 bool fHasHCHandler;
104 bool fRestoreAsRAM;
105 } PhysicalModify;
106 uint64_t padding[5];
107 } u;
108} REMHANDLERNOTIFICATION, *PREMHANDLERNOTIFICATION;
109
110/**
111 * Dynamically allocated guest RAM chunk information
112 * HC virt to GC Phys
113 *
114 * A RAM chunk can spawn two chunk regions as we don't align them on chunk boundaries.
115 */
116typedef struct REMCHUNKINFO
117{
118 RTHCUINTPTR pChunk1;
119 RTHCUINTPTR pChunk2;
120 RTGCPHYS GCPhys1;
121 RTGCPHYS GCPhys2;
122} REMCHUNKINFO, *PREMCHUNKINFO;
123
124/** Maximum number of external guest RAM/ROM registrations. */
125#define REM_MAX_PHYS_REGISTRATIONS 16
126
127/**
128 * Registration record for external guest RAM & ROM
129 */
130typedef struct REMPHYSREGISTRATION
131{
132 RTGCPHYS GCPhys;
133 RTHCUINTPTR HCVirt;
134 RTUINT cb;
135#if HC_ARCH_BITS == 64
136 uint32_t u32Padding;
137#endif
138} REMPHYSREGISTRATION, *PREMPHYSREGISTRATION;
139
140/**
141 * Converts a REM pointer into a VM pointer.
142 * @returns Pointer to the VM structure the REM is part of.
143 * @param pREM Pointer to REM instance data.
144 */
145#define REM2VM(pREM) ( (PVM)((char*)pREM - pREM->offVM) )
146
147
148/**
149 * REM Data (part of VM)
150 */
151typedef struct REM
152{
153 /** Offset to the VM structure. */
154 RTINT offVM;
155 /** Alignment padding. */
156 RTUINT uPadding0;
157
158 /** Cached guest cpu context pointer. */
159 R3PTRTYPE(PCPUMCTX) pCtx;
160
161 /** In REM mode.
162 * I.e. the correct CPU state and some other bits are with REM. */
163 bool fInREM;
164 /** In REMR3State. */
165 bool fInStateSync;
166
167 /** Ignore all that can be ignored. */
168 bool fIgnoreAll;
169 /** Ignore CR3 load notifications from the REM. */
170 bool fIgnoreCR3Load;
171 /** Ignore invlpg notifications from the REM. */
172 bool fIgnoreInvlPg;
173 /** Ignore CR0, CR4 and EFER load. */
174 bool fIgnoreCpuMode;
175 /** Ignore set page. */
176 bool fIgnoreSetPage;
177
178 /** Number of times REMR3CanExecuteRaw has been called.
179 * It is used to prevent rescheduling on the first call. */
180 RTUINT cCanExecuteRaw;
181
182 /** Pending interrupt (~0 -> nothing). */
183 RTUINT u32PendingInterrupt;
184
185#if HC_ARCH_BITS == 64
186 /** Alignment padding. */
187 uint32_t u32Padding;
188#endif
189 /** Number of recorded invlpg instructions. */
190 RTUINT cInvalidatedPages;
191 /** Array of recorded invlpg instruction.
192 * These instructions are replayed when entering REM. */
193 RTGCPTR aGCPtrInvalidatedPages[48];
194 /** The number of recorded handler notifications. */
195 RTUINT volatile cHandlerNotifications;
196 RTUINT padding0; /**< Padding. */
197 /** Array of recorded handler noticications.
198 * These are replayed when entering REM. */
199 REMHANDLERNOTIFICATION aHandlerNotifications[32];
200
201 /** Pointer to an array of hc virt to gc phys records. */
202 R3PTRTYPE(PREMCHUNKINFO) paHCVirtToGCPhys;
203 /** Pointer to a GC Phys to HC Virt lookup table. */
204 R3PTRTYPE(PRTHCUINTPTR) paGCPhysToHCVirt;
205
206 /** Array of external RAM and ROM registrations (excluding guest RAM). */
207 REMPHYSREGISTRATION aPhysReg[REM_MAX_PHYS_REGISTRATIONS];
208 /** Number of external RAM and ROM registrations (excluding guest RAM). */
209 RTUINT cPhysRegistrations;
210
211 /** MMIO memory type.
212 * This is used to register MMIO physical access handlers. */
213 RTINT iMMIOMemType;
214 /** Handler memory type.
215 * This is used to register non-MMIO physical access handlers which are executed in HC. */
216 RTINT iHandlerMemType;
217
218 /** Pending exception */
219 uint32_t uPendingException;
220 /** Pending exception's EIP */
221 uint32_t uPendingExcptEIP;
222 /** Pending exception's CR2 */
223 uint32_t uPendingExcptCR2;
224 /** Nr of pending exceptions */
225 uint32_t cPendingExceptions;
226
227 /** Pending rc. */
228 RTINT rc;
229
230 /** Time spent in QEMU. */
231 STAMPROFILEADV StatsInQEMU;
232 /** Time spent in rawmode.c. */
233 STAMPROFILEADV StatsInRAWEx;
234 /** Time spent switching state. */
235 STAMPROFILE StatsState;
236 /** Time spent switching state back. */
237 STAMPROFILE StatsStateBack;
238
239#if HC_ARCH_BITS != 32
240 /** Padding the CPUX86State structure to 32 byte. */
241 uint32_t abPadding[HC_ARCH_BITS == 32 ? 0 : 4];
242#endif
243
244#define REM_ENV_SIZE (HC_ARCH_BITS == 32 ? 0x6440 : 0xb4a0)
245 /** Recompiler CPU state. */
246#ifdef REM_INCLUDE_CPU_H
247 CPUX86State Env;
248#else
249 struct FakeEnv
250 {
251 char achPadding[REM_ENV_SIZE];
252 } Env;
253#endif
254} REM;
255
256/** Pointer to the REM Data. */
257typedef REM *PREM;
258
259
260#ifdef REM_INCLUDE_CPU_H
261bool remR3CanExecuteRaw(CPUState *env, RTGCPTR eip, unsigned fFlags, int *piException);
262void remR3CSAMCheckEIP(CPUState *env, RTGCPTR GCPtrCode);
263bool remR3GetOpcode(CPUState *env, RTGCPTR GCPtrInstr, uint8_t *pu8Byte);
264bool remR3DisasInstr(CPUState *env, int f32BitCode, char *pszPrefix);
265bool remR3DisasBlock(CPUState *env, int f32BitCode, int nrInstructions, char *pszPrefix);
266void remR3FlushPage(CPUState *env, RTGCPTR GCPtr);
267void remR3SetPage(CPUState *env, CPUTLBEntry *pRead, CPUTLBEntry *pWrite, int prot, int is_user);
268void remR3FlushTLB(CPUState *env, bool fGlobal);
269void remR3ProtectCode(CPUState *env, RTGCPTR GCPtr);
270void remR3ChangeCpuMode(CPUState *env);
271void remR3DmaRun(CPUState *env);
272void remR3TimersRun(CPUState *env);
273int remR3NotifyTrap(CPUState *env, uint32_t uTrap, uint32_t uErrorCode, uint32_t pvNextEIP);
274void remR3TrapStat(CPUState *env, uint32_t uTrap);
275void remR3CpuId(CPUState *env, unsigned uOperator, void *pvEAX, void *pvEBX, void *pvECX, void *pvEDX);
276void remR3RecordCall(CPUState *env);
277#endif
278void remR3TrapClear(PVM pVM);
279void remR3RaiseRC(PVM pVM, int rc);
280void remR3DumpLnxSyscall(PVM pVM);
281void remR3DumpOBsdSyscall(PVM pVM);
282
283
284/** @todo r=bird: clean up the RAWEx stats. */
285/* temporary hacks */
286#define RAWEx_ProfileStart(a, b) remR3ProfileStart(b)
287#define RAWEx_ProfileStop(a, b) remR3ProfileStop(b)
288
289
290#ifdef VBOX_WITH_STATISTICS
291
292#define STATS_EMULATE_SINGLE_INSTR 1
293#define STATS_QEMU_COMPILATION 2
294#define STATS_QEMU_RUN_EMULATED_CODE 3
295#define STATS_QEMU_TOTAL 4
296#define STATS_QEMU_RUN_TIMERS 5
297#define STATS_TLB_LOOKUP 6
298#define STATS_IRQ_HANDLING 7
299#define STATS_RAW_CHECK 8
300
301
302void remR3ProfileStart(int statcode);
303void remR3ProfileStop(int statcode);
304#else
305#define remR3ProfileStart(c)
306#define remR3ProfileStop(c)
307#endif
308
309/** @} */
310
311#endif
312
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