VirtualBox

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

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

Realigning after RTGCPHYS change.

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