VirtualBox

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

Last change on this file since 12287 was 11813, checked in by vboxsync, 16 years ago

Deal with 1.6 saved states in the recompiler.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.9 KB
Line 
1/* $Id: REMInternal.h 11813 2008-08-29 12:01:13Z 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_VER1_6 6
47#define REM_SAVED_STATE_VERSION 7
48
49
50/** @def REM_MONITOR_CODE_PAGES
51 * Enable to monitor code pages that have been translated by the recompiler. */
52/** Currently broken and interferes with CSAM monitoring (see #2784) */
53////#define REM_MONITOR_CODE_PAGES
54
55typedef enum REMHANDLERNOTIFICATIONKIND
56{
57 /** The usual invalid 0 entry. */
58 REMHANDLERNOTIFICATIONKIND_INVALID = 0,
59 /** REMR3NotifyHandlerPhysicalRegister. */
60 REMHANDLERNOTIFICATIONKIND_PHYSICAL_REGISTER,
61 /** REMR3NotifyHandlerPhysicalDeregister. */
62 REMHANDLERNOTIFICATIONKIND_PHYSICAL_DEREGISTER,
63 /** REMR3NotifyHandlerPhysicalModify. */
64 REMHANDLERNOTIFICATIONKIND_PHYSICAL_MODIFY,
65 /** The usual 32-bit hack. */
66 REMHANDLERNOTIFICATIONKIND_32BIT_HACK = 0x7fffffff
67} REMHANDLERNOTIFICATIONKIND;
68
69
70/**
71 * A recorded handler notificiation.
72 */
73typedef struct REMHANDLERNOTIFICATION
74{
75 /** The notification kind. */
76 REMHANDLERNOTIFICATIONKIND enmKind;
77 uint32_t padding;
78 /** Type specific data. */
79 union
80 {
81 struct
82 {
83 RTGCPHYS GCPhys;
84 RTGCPHYS cb;
85 PGMPHYSHANDLERTYPE enmType;
86 bool fHasHCHandler;
87 } PhysicalRegister;
88
89 struct
90 {
91 RTGCPHYS GCPhys;
92 RTGCPHYS cb;
93 PGMPHYSHANDLERTYPE enmType;
94 bool fHasHCHandler;
95 bool fRestoreAsRAM;
96 } PhysicalDeregister;
97
98 struct
99 {
100 RTGCPHYS GCPhysOld;
101 RTGCPHYS GCPhysNew;
102 RTGCPHYS cb;
103 PGMPHYSHANDLERTYPE enmType;
104 bool fHasHCHandler;
105 bool fRestoreAsRAM;
106 } PhysicalModify;
107 uint64_t padding[5];
108 } u;
109} REMHANDLERNOTIFICATION, *PREMHANDLERNOTIFICATION;
110
111/**
112 * Dynamically allocated guest RAM chunk information
113 * HC virt to GC Phys
114 *
115 * A RAM chunk can spawn two chunk regions as we don't align them on chunk boundaries.
116 */
117typedef struct REMCHUNKINFO
118{
119 RTHCUINTPTR pChunk1;
120 RTHCUINTPTR pChunk2;
121 RTGCPHYS GCPhys1;
122 RTGCPHYS GCPhys2;
123} REMCHUNKINFO, *PREMCHUNKINFO;
124
125/** Maximum number of external guest RAM/ROM registrations. */
126#define REM_MAX_PHYS_REGISTRATIONS 16
127
128/**
129 * Registration record for external guest RAM & ROM
130 */
131typedef struct REMPHYSREGISTRATION
132{
133 RTGCPHYS GCPhys;
134 RTHCUINTPTR HCVirt;
135 RTUINT cb;
136#if HC_ARCH_BITS == 64
137 uint32_t u32Padding;
138#endif
139} REMPHYSREGISTRATION, *PREMPHYSREGISTRATION;
140
141/**
142 * Converts a REM pointer into a VM pointer.
143 * @returns Pointer to the VM structure the REM is part of.
144 * @param pREM Pointer to REM instance data.
145 */
146#define REM2VM(pREM) ( (PVM)((char*)pREM - pREM->offVM) )
147
148
149/**
150 * REM Data (part of VM)
151 */
152typedef struct REM
153{
154 /** Offset to the VM structure. */
155 RTINT offVM;
156 /** Alignment padding. */
157 RTUINT uPadding0;
158
159 /** Cached guest cpu context pointer. */
160 R3PTRTYPE(PCPUMCTX) pCtx;
161
162 /** In REM mode.
163 * I.e. the correct CPU state and some other bits are with REM. */
164 bool fInREM;
165 /** In REMR3State. */
166 bool fInStateSync;
167
168 /** Ignore all that can be ignored. */
169 bool fIgnoreAll;
170 /** Ignore CR3 load notifications from the REM. */
171 bool fIgnoreCR3Load;
172 /** Ignore invlpg notifications from the REM. */
173 bool fIgnoreInvlPg;
174 /** Ignore CR0, CR4 and EFER load. */
175 bool fIgnoreCpuMode;
176 /** Ignore set page. */
177 bool fIgnoreSetPage;
178
179 /** Number of times REMR3CanExecuteRaw has been called.
180 * It is used to prevent rescheduling on the first call. */
181 RTUINT cCanExecuteRaw;
182
183 /** Pending interrupt (~0 -> nothing). */
184 RTUINT u32PendingInterrupt;
185
186#if HC_ARCH_BITS == 64
187 /** Alignment padding. */
188 uint32_t u32Padding;
189#endif
190 /** Number of recorded invlpg instructions. */
191 RTUINT cInvalidatedPages;
192 /** Array of recorded invlpg instruction.
193 * These instructions are replayed when entering REM. */
194 RTGCPTR aGCPtrInvalidatedPages[48];
195 /** The number of recorded handler notifications. */
196 RTUINT volatile cHandlerNotifications;
197 RTUINT padding0; /**< Padding. */
198 /** Array of recorded handler noticications.
199 * These are replayed when entering REM. */
200 REMHANDLERNOTIFICATION aHandlerNotifications[32];
201
202 /** Pointer to an array of hc virt to gc phys records. */
203 R3PTRTYPE(PREMCHUNKINFO) paHCVirtToGCPhys;
204 /** Pointer to a GC Phys to HC Virt lookup table. */
205 R3PTRTYPE(PRTHCUINTPTR) paGCPhysToHCVirt;
206
207 /** Array of external RAM and ROM registrations (excluding guest RAM). */
208 REMPHYSREGISTRATION aPhysReg[REM_MAX_PHYS_REGISTRATIONS];
209 /** Number of external RAM and ROM registrations (excluding guest RAM). */
210 RTUINT cPhysRegistrations;
211
212 /** MMIO memory type.
213 * This is used to register MMIO physical access handlers. */
214 RTINT iMMIOMemType;
215 /** Handler memory type.
216 * This is used to register non-MMIO physical access handlers which are executed in HC. */
217 RTINT iHandlerMemType;
218
219 /** Pending exception */
220 uint32_t uPendingException;
221 /** Pending exception's EIP */
222 uint32_t uPendingExcptEIP;
223 /** Pending exception's CR2 */
224 uint32_t uPendingExcptCR2;
225 /** Nr of pending exceptions */
226 uint32_t cPendingExceptions;
227
228 /** Pending rc. */
229 RTINT rc;
230
231 /** Time spent in QEMU. */
232 STAMPROFILEADV StatsInQEMU;
233 /** Time spent in rawmode.c. */
234 STAMPROFILEADV StatsInRAWEx;
235 /** Time spent switching state. */
236 STAMPROFILE StatsState;
237 /** Time spent switching state back. */
238 STAMPROFILE StatsStateBack;
239
240#if HC_ARCH_BITS != 32
241 /** Padding the CPUX86State structure to 32 byte. */
242 uint32_t abPadding[HC_ARCH_BITS == 32 ? 0 : 4];
243#endif
244
245#if GC_ARCH_BITS == 32
246#define REM_ENV_SIZE (HC_ARCH_BITS == 32 ? 0x6550 : 0xb4a0)
247#else
248#define REM_ENV_SIZE (HC_ARCH_BITS == 32 ? 0x9440 : 0xd4a0)
249#endif
250
251 /** Recompiler CPU state. */
252#ifdef REM_INCLUDE_CPU_H
253 CPUX86State Env;
254#else
255 struct FakeEnv
256 {
257 char achPadding[REM_ENV_SIZE];
258 } Env;
259#endif
260} REM;
261
262/** Pointer to the REM Data. */
263typedef REM *PREM;
264
265
266#ifdef REM_INCLUDE_CPU_H
267bool remR3CanExecuteRaw(CPUState *env, RTGCPTR eip, unsigned fFlags, int *piException);
268void remR3CSAMCheckEIP(CPUState *env, RTGCPTR GCPtrCode);
269bool remR3GetOpcode(CPUState *env, RTGCPTR GCPtrInstr, uint8_t *pu8Byte);
270bool remR3DisasInstr(CPUState *env, int f32BitCode, char *pszPrefix);
271bool remR3DisasBlock(CPUState *env, int f32BitCode, int nrInstructions, char *pszPrefix);
272void remR3FlushPage(CPUState *env, RTGCPTR GCPtr);
273void remR3SetPage(CPUState *env, CPUTLBEntry *pRead, CPUTLBEntry *pWrite, int prot, int is_user);
274void remR3FlushTLB(CPUState *env, bool fGlobal);
275void remR3ProtectCode(CPUState *env, RTGCPTR GCPtr);
276void remR3ChangeCpuMode(CPUState *env);
277void remR3DmaRun(CPUState *env);
278void remR3TimersRun(CPUState *env);
279int remR3NotifyTrap(CPUState *env, uint32_t uTrap, uint32_t uErrorCode, uint32_t pvNextEIP);
280void remR3TrapStat(CPUState *env, uint32_t uTrap);
281void remR3CpuId(CPUState *env, unsigned uOperator, void *pvEAX, void *pvEBX, void *pvECX, void *pvEDX);
282void remR3RecordCall(CPUState *env);
283#endif
284void remR3TrapClear(PVM pVM);
285void remR3RaiseRC(PVM pVM, int rc);
286void remR3DumpLnxSyscall(PVM pVM);
287void remR3DumpOBsdSyscall(PVM pVM);
288
289
290/** @todo r=bird: clean up the RAWEx stats. */
291/* temporary hacks */
292#define RAWEx_ProfileStart(a, b) remR3ProfileStart(b)
293#define RAWEx_ProfileStop(a, b) remR3ProfileStop(b)
294
295
296#ifdef VBOX_WITH_STATISTICS
297
298#define STATS_EMULATE_SINGLE_INSTR 1
299#define STATS_QEMU_COMPILATION 2
300#define STATS_QEMU_RUN_EMULATED_CODE 3
301#define STATS_QEMU_TOTAL 4
302#define STATS_QEMU_RUN_TIMERS 5
303#define STATS_TLB_LOOKUP 6
304#define STATS_IRQ_HANDLING 7
305#define STATS_RAW_CHECK 8
306
307
308void remR3ProfileStart(int statcode);
309void remR3ProfileStop(int statcode);
310#else
311#define remR3ProfileStart(c)
312#define remR3ProfileStop(c)
313#endif
314
315/** @} */
316
317#endif
318
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