1 | /* $Id: REMInternal.h 161 2007-01-18 18:25:45Z 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 |
|
---|
53 | typedef 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 | */
|
---|
71 | typedef 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 | */
|
---|
115 | typedef 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 | */
|
---|
129 | typedef 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 | */
|
---|
147 | typedef 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 | /** Number of recorded invlpg instructions. */
|
---|
175 | RTUINT cInvalidatedPages;
|
---|
176 | /** Array of recorded invlpg instruction.
|
---|
177 | * These instructions are replayed when entering REM. */
|
---|
178 | RTGCPTR aGCPtrInvalidatedPages[48];
|
---|
179 | /** The number of recorded handler notifications. */
|
---|
180 | RTUINT volatile cHandlerNotifications;
|
---|
181 | RTUINT padding0; /**< Padding. */
|
---|
182 | /** Array of recorded handler noticications.
|
---|
183 | * These are replayed when entering REM. */
|
---|
184 | REMHANDLERNOTIFICATION aHandlerNotifications[32];
|
---|
185 |
|
---|
186 | /** Pointer to an array of hc virt to gc phys records. */
|
---|
187 | HCPTRTYPE(PREMCHUNKINFO) paHCVirtToGCPhys;
|
---|
188 | /** Pointer to a GC Phys to HC Virt lookup table. */
|
---|
189 | HCPTRTYPE(PRTHCUINTPTR) paGCPhysToHCVirt;
|
---|
190 |
|
---|
191 | /** Array of external RAM and ROM registrations (excluding guest RAM). */
|
---|
192 | REMPHYSREGISTRATION aPhysReg[REM_MAX_PHYS_REGISTRATIONS];
|
---|
193 | /** Number of external RAM and ROM registrations (excluding guest RAM). */
|
---|
194 | RTUINT cPhysRegistrations;
|
---|
195 |
|
---|
196 | /** MMIO memory type.
|
---|
197 | * This is used to register MMIO physical access handlers. */
|
---|
198 | RTINT iMMIOMemType;
|
---|
199 | /** Handler memory type.
|
---|
200 | * This is used to register non-MMIO physical access handlers which are executed in HC. */
|
---|
201 | RTINT iHandlerMemType;
|
---|
202 |
|
---|
203 | /** Pending exception */
|
---|
204 | uint32_t uPendingException;
|
---|
205 | /** Pending exception's EIP */
|
---|
206 | uint32_t uPendingExcptEIP;
|
---|
207 | /** Pending exception's CR2 */
|
---|
208 | uint32_t uPendingExcptCR2;
|
---|
209 | /** Nr of pending exceptions */
|
---|
210 | uint32_t cPendingExceptions;
|
---|
211 |
|
---|
212 | /** Pending rc. */
|
---|
213 | RTINT rc;
|
---|
214 |
|
---|
215 | /** Padding for MS / GC alignment difference. */
|
---|
216 | uint32_t u32Padding;
|
---|
217 | /** Time spent in QEMU. */
|
---|
218 | STAMPROFILEADV StatsInQEMU;
|
---|
219 | /** Time spent in rawmode.c. */
|
---|
220 | STAMPROFILEADV StatsInRAWEx;
|
---|
221 | /** Time spent switching state. */
|
---|
222 | STAMPROFILE StatsState;
|
---|
223 | /** Time spent switching state back. */
|
---|
224 | STAMPROFILE StatsStateBack;
|
---|
225 |
|
---|
226 | #if HC_ARCH_BITS != 32
|
---|
227 | /** Padding the CPUX86State structure to 32 byte. */
|
---|
228 | uint32_t abPadding[HC_ARCH_BITS == 32 ? 0 : 6];
|
---|
229 | #endif
|
---|
230 |
|
---|
231 | #define REM_ENV_SIZE (HC_ARCH_BITS == 32 ? 0x6440 : 0xb4a0)
|
---|
232 | /** Recompiler CPU state. */
|
---|
233 | #ifdef REM_INCLUDE_CPU_H
|
---|
234 | CPUX86State Env;
|
---|
235 | #else
|
---|
236 | struct FakeEnv
|
---|
237 | {
|
---|
238 | char achPadding[REM_ENV_SIZE];
|
---|
239 | } Env;
|
---|
240 | #endif
|
---|
241 | } REM;
|
---|
242 |
|
---|
243 | /** Pointer to the REM Data. */
|
---|
244 | typedef REM *PREM;
|
---|
245 |
|
---|
246 |
|
---|
247 | #ifdef REM_INCLUDE_CPU_H
|
---|
248 | bool remR3CanExecuteRaw(CPUState *env, RTGCPTR eip, unsigned fFlags, uint32_t *pExceptionIndex);
|
---|
249 | void remR3CSAMCheckEIP(CPUState *env, RTGCPTR GCPtrCode);
|
---|
250 | bool remR3GetOpcode(CPUState *env, RTGCPTR GCPtrInstr, uint8_t *pu8Byte);
|
---|
251 | bool remR3DisasInstr(CPUState *env, int f32BitCode, char *pszPrefix);
|
---|
252 | bool remR3DisasBlock(CPUState *env, int f32BitCode, int nrInstructions, char *pszPrefix);
|
---|
253 | void remR3FlushPage(CPUState *env, RTGCPTR GCPtr);
|
---|
254 | void remR3SetPage(CPUState *env, CPUTLBEntry *pRead, CPUTLBEntry *pWrite, int prot, int is_user);
|
---|
255 | void remR3FlushTLB(CPUState *env, bool fGlobal);
|
---|
256 | void remR3ProtectCode(CPUState *env, RTGCPTR GCPtr);
|
---|
257 | void remR3ChangeCpuMode(CPUState *env);
|
---|
258 | void remR3DmaRun(CPUState *env);
|
---|
259 | void remR3TimersRun(CPUState *env);
|
---|
260 | int remR3NotifyTrap(CPUState *env, uint32_t uTrap, uint32_t uErrorCode, uint32_t pvNextEIP);
|
---|
261 | void remR3TrapStat(CPUState *env, uint32_t uTrap);
|
---|
262 | void remR3CpuId(CPUState *env, unsigned uOperator, void *pvEAX, void *pvEBX, void *pvECX, void *pvEDX);
|
---|
263 | #endif
|
---|
264 | void remR3TrapClear(PVM pVM);
|
---|
265 | void remR3RaiseRC(PVM pVM, int rc);
|
---|
266 | void remR3DumpLnxSyscall(PVM pVM);
|
---|
267 | void remR3DumpOBsdSyscall(PVM pVM);
|
---|
268 |
|
---|
269 |
|
---|
270 | /** @todo r=bird: clean up the RAWEx stats. */
|
---|
271 | /* temporary hacks */
|
---|
272 | #define RAWEx_ProfileStart(a, b) remR3ProfileStart(b)
|
---|
273 | #define RAWEx_ProfileStop(a, b) remR3ProfileStop(b)
|
---|
274 |
|
---|
275 |
|
---|
276 | #ifdef VBOX_WITH_STATISTICS
|
---|
277 |
|
---|
278 | #define STATS_EMULATE_SINGLE_INSTR 1
|
---|
279 | #define STATS_QEMU_COMPILATION 2
|
---|
280 | #define STATS_QEMU_RUN_EMULATED_CODE 3
|
---|
281 | #define STATS_QEMU_TOTAL 4
|
---|
282 | #define STATS_QEMU_RUN_TIMERS 5
|
---|
283 | #define STATS_TLB_LOOKUP 6
|
---|
284 | #define STATS_IRQ_HANDLING 7
|
---|
285 | #define STATS_RAW_CHECK 8
|
---|
286 |
|
---|
287 |
|
---|
288 | void remR3ProfileStart(int statcode);
|
---|
289 | void remR3ProfileStop(int statcode);
|
---|
290 | #else
|
---|
291 | #define remR3ProfileStart(c)
|
---|
292 | #define remR3ProfileStop(c)
|
---|
293 | #endif
|
---|
294 |
|
---|
295 | /** @} */
|
---|
296 |
|
---|
297 | #endif
|
---|
298 |
|
---|