VirtualBox

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

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

Only 64 bits

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.5 KB
Line 
1/* $Id: REMInternal.h 7622 2008-03-28 10:23:22Z 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[5];
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 RTGCPHYS GCPhys;
128 RTHCUINTPTR HCVirt;
129 RTUINT cb;
130#if HC_ARCH_BITS == 64
131 uint32_t u32Padding;
132#endif
133} REMPHYSREGISTRATION, *PREMPHYSREGISTRATION;
134
135/**
136 * Converts a REM pointer into a VM pointer.
137 * @returns Pointer to the VM structure the REM is part of.
138 * @param pREM Pointer to REM instance data.
139 */
140#define REM2VM(pREM) ( (PVM)((char*)pREM - pREM->offVM) )
141
142
143/**
144 * REM Data (part of VM)
145 */
146typedef struct REM
147{
148 /** Offset to the VM structure. */
149 RTINT offVM;
150 /** Alignment padding. */
151 RTUINT uPadding0;
152
153 /** Cached guest cpu context pointer. */
154 R3PTRTYPE(PCPUMCTX) pCtx;
155
156 /** In REM mode.
157 * I.e. the correct CPU state and some other bits are with REM. */
158 bool fInREM;
159 /** In REMR3State. */
160 bool fInStateSync;
161
162 /** Ignore all that can be ignored. */
163 bool fIgnoreAll;
164 /** Ignore CR3 load notifications from the REM. */
165 bool fIgnoreCR3Load;
166 /** Ignore invlpg notifications from the REM. */
167 bool fIgnoreInvlPg;
168 /** Ignore CR0, CR4 and EFER load. */
169 bool fIgnoreCpuMode;
170 /** Ignore set page. */
171 bool fIgnoreSetPage;
172
173 /** Number of times REMR3CanExecuteRaw has been called.
174 * It is used to prevent rescheduling on the first call. */
175 RTUINT cCanExecuteRaw;
176
177 /** Pending interrupt (~0 -> nothing). */
178 RTUINT u32PendingInterrupt;
179
180#if HC_ARCH_BITS == 64
181 /** Alignment padding. */
182 uint32_t u32Padding;
183#endif
184 /** Number of recorded invlpg instructions. */
185 RTUINT cInvalidatedPages;
186 /** Array of recorded invlpg instruction.
187 * These instructions are replayed when entering REM. */
188 RTGCPTR aGCPtrInvalidatedPages[48];
189 /** The number of recorded handler notifications. */
190 RTUINT volatile cHandlerNotifications;
191 RTUINT padding0; /**< Padding. */
192 /** Array of recorded handler noticications.
193 * These are replayed when entering REM. */
194 REMHANDLERNOTIFICATION aHandlerNotifications[32];
195
196 /** Pointer to an array of hc virt to gc phys records. */
197 R3PTRTYPE(PREMCHUNKINFO) paHCVirtToGCPhys;
198 /** Pointer to a GC Phys to HC Virt lookup table. */
199 R3PTRTYPE(PRTHCUINTPTR) paGCPhysToHCVirt;
200
201 /** Array of external RAM and ROM registrations (excluding guest RAM). */
202 REMPHYSREGISTRATION aPhysReg[REM_MAX_PHYS_REGISTRATIONS];
203 /** Number of external RAM and ROM registrations (excluding guest RAM). */
204 RTUINT cPhysRegistrations;
205
206 /** MMIO memory type.
207 * This is used to register MMIO physical access handlers. */
208 RTINT iMMIOMemType;
209 /** Handler memory type.
210 * This is used to register non-MMIO physical access handlers which are executed in HC. */
211 RTINT iHandlerMemType;
212
213 /** Pending exception */
214 uint32_t uPendingException;
215 /** Pending exception's EIP */
216 uint32_t uPendingExcptEIP;
217 /** Pending exception's CR2 */
218 uint32_t uPendingExcptCR2;
219 /** Nr of pending exceptions */
220 uint32_t cPendingExceptions;
221
222 /** Pending rc. */
223 RTINT rc;
224
225 /** Time spent in QEMU. */
226 STAMPROFILEADV StatsInQEMU;
227 /** Time spent in rawmode.c. */
228 STAMPROFILEADV StatsInRAWEx;
229 /** Time spent switching state. */
230 STAMPROFILE StatsState;
231 /** Time spent switching state back. */
232 STAMPROFILE StatsStateBack;
233
234#if HC_ARCH_BITS != 32
235 /** Padding the CPUX86State structure to 32 byte. */
236 uint32_t abPadding[HC_ARCH_BITS == 32 ? 0 : 4];
237#endif
238
239#define REM_ENV_SIZE (HC_ARCH_BITS == 32 ? 0x6440 : 0xb4a0)
240 /** Recompiler CPU state. */
241#ifdef REM_INCLUDE_CPU_H
242 CPUX86State Env;
243#else
244 struct FakeEnv
245 {
246 char achPadding[REM_ENV_SIZE];
247 } Env;
248#endif
249} REM;
250
251/** Pointer to the REM Data. */
252typedef REM *PREM;
253
254
255#ifdef REM_INCLUDE_CPU_H
256bool remR3CanExecuteRaw(CPUState *env, RTGCPTR eip, unsigned fFlags, int *piException);
257void remR3CSAMCheckEIP(CPUState *env, RTGCPTR GCPtrCode);
258bool remR3GetOpcode(CPUState *env, RTGCPTR GCPtrInstr, uint8_t *pu8Byte);
259bool remR3DisasInstr(CPUState *env, int f32BitCode, char *pszPrefix);
260bool remR3DisasBlock(CPUState *env, int f32BitCode, int nrInstructions, char *pszPrefix);
261void remR3FlushPage(CPUState *env, RTGCPTR GCPtr);
262void remR3SetPage(CPUState *env, CPUTLBEntry *pRead, CPUTLBEntry *pWrite, int prot, int is_user);
263void remR3FlushTLB(CPUState *env, bool fGlobal);
264void remR3ProtectCode(CPUState *env, RTGCPTR GCPtr);
265void remR3ChangeCpuMode(CPUState *env);
266void remR3DmaRun(CPUState *env);
267void remR3TimersRun(CPUState *env);
268int remR3NotifyTrap(CPUState *env, uint32_t uTrap, uint32_t uErrorCode, uint32_t pvNextEIP);
269void remR3TrapStat(CPUState *env, uint32_t uTrap);
270void remR3CpuId(CPUState *env, unsigned uOperator, void *pvEAX, void *pvEBX, void *pvECX, void *pvEDX);
271void remR3RecordCall(CPUState *env);
272#endif
273void remR3TrapClear(PVM pVM);
274void remR3RaiseRC(PVM pVM, int rc);
275void remR3DumpLnxSyscall(PVM pVM);
276void remR3DumpOBsdSyscall(PVM pVM);
277
278
279/** @todo r=bird: clean up the RAWEx stats. */
280/* temporary hacks */
281#define RAWEx_ProfileStart(a, b) remR3ProfileStart(b)
282#define RAWEx_ProfileStop(a, b) remR3ProfileStop(b)
283
284
285#ifdef VBOX_WITH_STATISTICS
286
287#define STATS_EMULATE_SINGLE_INSTR 1
288#define STATS_QEMU_COMPILATION 2
289#define STATS_QEMU_RUN_EMULATED_CODE 3
290#define STATS_QEMU_TOTAL 4
291#define STATS_QEMU_RUN_TIMERS 5
292#define STATS_TLB_LOOKUP 6
293#define STATS_IRQ_HANDLING 7
294#define STATS_RAW_CHECK 8
295
296
297void remR3ProfileStart(int statcode);
298void remR3ProfileStop(int statcode);
299#else
300#define remR3ProfileStart(c)
301#define remR3ProfileStop(c)
302#endif
303
304/** @} */
305
306#endif
307
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