1 | /** @file
|
---|
2 | * REM - Internal header file.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * If you received this file as part of a commercial VirtualBox
|
---|
17 | * distribution, then only the terms of your commercial VirtualBox
|
---|
18 | * license agreement apply instead of the previous paragraph.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef __REMInternal_h__
|
---|
22 | #define __REMInternal_h__
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #include <VBox/types.h>
|
---|
26 | #include <VBox/cpum.h>
|
---|
27 | #include <VBox/stam.h>
|
---|
28 | #include <VBox/pgm.h>
|
---|
29 | #ifdef REM_INCLUDE_CPU_H
|
---|
30 | # include "target-i386/cpu.h"
|
---|
31 | #endif
|
---|
32 |
|
---|
33 |
|
---|
34 | #if !defined(IN_REM_R3) && !defined(IN_REM_R0) && !defined(IN_REM_GC)
|
---|
35 | # error "Not in REM! This is an internal header!"
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | /** @defgroup grp_rem_int Internals
|
---|
39 | * @ingroup grp_rem
|
---|
40 | * @internal
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /** The saved state version number. */
|
---|
45 | #define REM_SAVED_STATE_VERSION 4
|
---|
46 |
|
---|
47 |
|
---|
48 | /** @def REM_MONITOR_CODE_PAGES
|
---|
49 | * Enable to monitor code pages that have been translated by the recompiler. */
|
---|
50 | #define REM_MONITOR_CODE_PAGES
|
---|
51 |
|
---|
52 | typedef enum REMHANDLERNOTIFICATIONKIND
|
---|
53 | {
|
---|
54 | /** The usual invalid 0 entry. */
|
---|
55 | REMHANDLERNOTIFICATIONKIND_INVALID = 0,
|
---|
56 | /** REMR3NotifyHandlerPhysicalRegister. */
|
---|
57 | REMHANDLERNOTIFICATIONKIND_PHYSICAL_REGISTER,
|
---|
58 | /** REMR3NotifyHandlerPhysicalDeregister. */
|
---|
59 | REMHANDLERNOTIFICATIONKIND_PHYSICAL_DEREGISTER,
|
---|
60 | /** REMR3NotifyHandlerPhysicalModify. */
|
---|
61 | REMHANDLERNOTIFICATIONKIND_PHYSICAL_MODIFY,
|
---|
62 | /** The usual 32-bit hack. */
|
---|
63 | REMHANDLERNOTIFICATIONKIND_32BIT_HACK = 0x7fffffff
|
---|
64 | } REMHANDLERNOTIFICATIONKIND;
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * A recorded handler notificiation.
|
---|
69 | */
|
---|
70 | typedef struct REMHANDLERNOTIFICATION
|
---|
71 | {
|
---|
72 | /** The notification kind. */
|
---|
73 | REMHANDLERNOTIFICATIONKIND enmKind;
|
---|
74 | uint32_t padding;
|
---|
75 | /** Type specific data. */
|
---|
76 | union
|
---|
77 | {
|
---|
78 | struct
|
---|
79 | {
|
---|
80 | RTGCPHYS GCPhys;
|
---|
81 | RTGCPHYS cb;
|
---|
82 | PGMPHYSHANDLERTYPE enmType;
|
---|
83 | bool fHasHCHandler;
|
---|
84 | } PhysicalRegister;
|
---|
85 |
|
---|
86 | struct
|
---|
87 | {
|
---|
88 | RTGCPHYS GCPhys;
|
---|
89 | RTGCPHYS cb;
|
---|
90 | RTHCPTR pvHCPtr;
|
---|
91 | PGMPHYSHANDLERTYPE enmType;
|
---|
92 | bool fHasHCHandler;
|
---|
93 | } PhysicalDeregister;
|
---|
94 |
|
---|
95 | struct
|
---|
96 | {
|
---|
97 | RTHCPTR pvHCPtr;
|
---|
98 | RTGCPHYS GCPhysOld;
|
---|
99 | RTGCPHYS GCPhysNew;
|
---|
100 | RTGCPHYS cb;
|
---|
101 | PGMPHYSHANDLERTYPE enmType;
|
---|
102 | bool fHasHCHandler;
|
---|
103 | } PhysicalModify;
|
---|
104 | uint64_t padding[3 + (HC_ARCH_BITS == 64)];
|
---|
105 | } u;
|
---|
106 | } REMHANDLERNOTIFICATION, *PREMHANDLERNOTIFICATION;
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Dynamically allocated guest RAM chunk information
|
---|
110 | * HC virt to GC Phys
|
---|
111 | *
|
---|
112 | * A RAM chunk can spawn two chunk regions as we don't align them on chunk boundaries.
|
---|
113 | */
|
---|
114 | typedef struct REMCHUNKINFO
|
---|
115 | {
|
---|
116 | RTHCUINTPTR pChunk1;
|
---|
117 | RTGCPHYS GCPhys1;
|
---|
118 | RTHCUINTPTR pChunk2;
|
---|
119 | RTGCPHYS GCPhys2;
|
---|
120 | } REMCHUNKINFO, *PREMCHUNKINFO;
|
---|
121 |
|
---|
122 | /** Maximum number of external guest RAM/ROM registrations. */
|
---|
123 | #define REM_MAX_PHYS_REGISTRATIONS 16
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Registration record for external guest RAM & ROM
|
---|
127 | */
|
---|
128 | typedef struct REMPHYSREGISTRATION
|
---|
129 | {
|
---|
130 | RTGCPHYS GCPhys;
|
---|
131 | RTHCUINTPTR HCVirt;
|
---|
132 | RTUINT cb;
|
---|
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 | */
|
---|
146 | typedef 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 | HCPTRTYPE(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 |
|
---|
160 | /** Ignore CR3 load notifications from the REM. */
|
---|
161 | bool fIgnoreCR3Load;
|
---|
162 | /** Ignore invlpg notifications from the REM. */
|
---|
163 | bool fIgnoreInvlPg;
|
---|
164 | /** Ignore CR0, CR4 and EFER load. */
|
---|
165 | bool fIgnoreCpuMode;
|
---|
166 | /** Number of times REMR3CanExecuteRaw has been called.
|
---|
167 | * It is used to prevent rescheduling on the first call. */
|
---|
168 | RTUINT cCanExecuteRaw;
|
---|
169 |
|
---|
170 | /** Pending interrupt (~0 -> nothing). */
|
---|
171 | RTUINT u32PendingInterrupt;
|
---|
172 |
|
---|
173 | /** Number of recorded invlpg instructions. */
|
---|
174 | RTUINT cInvalidatedPages;
|
---|
175 | /** Array of recorded invlpg instruction.
|
---|
176 | * These instructions are replayed when entering REM. */
|
---|
177 | RTGCPTR aGCPtrInvalidatedPages[48];
|
---|
178 |
|
---|
179 | /** The number of recorded handler notifications. */
|
---|
180 | RTUINT volatile cHandlerNotifications;
|
---|
181 | /** Array of recorded handler noticications.
|
---|
182 | * These are replayed when entering REM. */
|
---|
183 | REMHANDLERNOTIFICATION aHandlerNotifications[32];
|
---|
184 |
|
---|
185 | /** Pointer to an array of hc virt to gc phys records. */
|
---|
186 | PREMCHUNKINFO paHCVirtToGCPhys;
|
---|
187 | /** Pointer to a GC Phys to HC Virt lookup table. */
|
---|
188 | RTHCUINTPTR *paGCPhysToHCVirt;
|
---|
189 |
|
---|
190 | /** Number of external RAM and ROM registrations (excluding guest RAM) */
|
---|
191 | RTUINT cPhysRegistrations;
|
---|
192 | REMPHYSREGISTRATION aPhysReg[REM_MAX_PHYS_REGISTRATIONS];
|
---|
193 |
|
---|
194 | /** MMIO memory type.
|
---|
195 | * This is used to register MMIO physical access handlers. */
|
---|
196 | RTINT iMMIOMemType;
|
---|
197 | /** Handler memory type.
|
---|
198 | * This is used to register non-MMIO physical access handlers which are executed in HC. */
|
---|
199 | RTINT iHandlerMemType;
|
---|
200 |
|
---|
201 | /** Pending exception */
|
---|
202 | uint32_t uPendingException;
|
---|
203 | /** Pending exception's EIP */
|
---|
204 | uint32_t uPendingExcptEIP;
|
---|
205 | /** Pending exception's CR2 */
|
---|
206 | uint32_t uPendingExcptCR2;
|
---|
207 | /** Nr of pending exceptions */
|
---|
208 | uint32_t cPendingExceptions;
|
---|
209 |
|
---|
210 | /** Pending rc. */
|
---|
211 | RTINT rc;
|
---|
212 |
|
---|
213 | /** Padding for MS / GC alignment difference. */
|
---|
214 | //uint32_t u32Padding;
|
---|
215 | /** Time spent in QEMU. */
|
---|
216 | STAMPROFILEADV StatsInQEMU;
|
---|
217 | /** Time spent in rawmode.c. */
|
---|
218 | STAMPROFILEADV StatsInRAWEx;
|
---|
219 | /** Time spent switching state. */
|
---|
220 | STAMPROFILE StatsState;
|
---|
221 | /** Time spent switching state back. */
|
---|
222 | STAMPROFILE StatsStateBack;
|
---|
223 |
|
---|
224 | /** Padding the CPUX86State structure to 32 byte. */
|
---|
225 | uint8_t abPadding[8];
|
---|
226 |
|
---|
227 | #define REM_ENV_SIZE (HC_ARCH_BITS == 32 ? 0x6440 : 0xb3e0)
|
---|
228 | /** Recompiler CPU state. */
|
---|
229 | #ifdef REM_INCLUDE_CPU_H
|
---|
230 | CPUX86State Env;
|
---|
231 | #else
|
---|
232 | struct FakeEnv
|
---|
233 | {
|
---|
234 | char achPadding[REM_ENV_SIZE];
|
---|
235 | } Env;
|
---|
236 | #endif
|
---|
237 | } REM;
|
---|
238 |
|
---|
239 | /** Pointer to the REM Data. */
|
---|
240 | typedef REM *PREM;
|
---|
241 |
|
---|
242 |
|
---|
243 | #ifdef REM_INCLUDE_CPU_H
|
---|
244 | bool remR3CanExecuteRaw(CPUState *env, RTGCPTR eip, unsigned fFlags, uint32_t *pExceptionIndex);
|
---|
245 | void remR3CSAMCheckEIP(CPUState *env, RTGCPTR GCPtrCode);
|
---|
246 | bool remR3GetOpcode(CPUState *env, RTGCPTR GCPtrInstr, uint8_t *pu8Byte);
|
---|
247 | bool remR3DisasInstr(CPUState *env, int f32BitCode, char *pszPrefix);
|
---|
248 | bool remR3DisasBlock(CPUState *env, int f32BitCode, int nrInstructions, char *pszPrefix);
|
---|
249 | void remR3FlushPage(CPUState *env, RTGCPTR GCPtr);
|
---|
250 | void remR3SetPage(CPUState *env, CPUTLBEntry *pRead, CPUTLBEntry *pWrite, int prot, int is_user);
|
---|
251 | void remR3FlushTLB(CPUState *env, bool fGlobal);
|
---|
252 | void remR3ProtectCode(CPUState *env, RTGCPTR GCPtr);
|
---|
253 | void remR3ChangeCpuMode(CPUState *env);
|
---|
254 | void remR3DmaRun(CPUState *env);
|
---|
255 | void remR3TimersRun(CPUState *env);
|
---|
256 | int remR3NotifyTrap(CPUState *env, uint32_t uTrap, uint32_t uErrorCode, uint32_t pvNextEIP);
|
---|
257 | void remR3TrapStat(CPUState *env, uint32_t uTrap);
|
---|
258 | void remR3CpuId(CPUState *env, unsigned uOperator, void *pvEAX, void *pvEBX, void *pvECX, void *pvEDX);
|
---|
259 | #endif
|
---|
260 | void remR3TrapClear(PVM pVM);
|
---|
261 | void remR3RaiseRC(PVM pVM, int rc);
|
---|
262 | void remR3DumpLnxSyscall(PVM pVM);
|
---|
263 | void remR3DumpOBsdSyscall(PVM pVM);
|
---|
264 |
|
---|
265 |
|
---|
266 | /** @todo r=bird: clean up the RAWEx stats. */
|
---|
267 | /* temporary hacks */
|
---|
268 | #define RAWEx_ProfileStart(a, b) remR3ProfileStart(b)
|
---|
269 | #define RAWEx_ProfileStop(a, b) remR3ProfileStop(b)
|
---|
270 |
|
---|
271 |
|
---|
272 | #ifdef VBOX_WITH_STATISTICS
|
---|
273 |
|
---|
274 | #define STATS_EMULATE_SINGLE_INSTR 1
|
---|
275 | #define STATS_QEMU_COMPILATION 2
|
---|
276 | #define STATS_QEMU_RUN_EMULATED_CODE 3
|
---|
277 | #define STATS_QEMU_TOTAL 4
|
---|
278 | #define STATS_QEMU_RUN_TIMERS 5
|
---|
279 | #define STATS_TLB_LOOKUP 6
|
---|
280 | #define STATS_IRQ_HANDLING 7
|
---|
281 | #define STATS_RAW_CHECK 8
|
---|
282 |
|
---|
283 |
|
---|
284 | void remR3ProfileStart(int statcode);
|
---|
285 | void remR3ProfileStop(int statcode);
|
---|
286 | #else
|
---|
287 | #define remR3ProfileStart(c)
|
---|
288 | #define remR3ProfileStop(c)
|
---|
289 | #endif
|
---|
290 |
|
---|
291 | /** @} */
|
---|
292 |
|
---|
293 | #endif
|
---|
294 |
|
---|