VirtualBox

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

Last change on this file since 768 was 164, checked in by vboxsync, 18 years ago

Corrected padding.

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