VirtualBox

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

Last change on this file since 20426 was 20426, checked in by vboxsync, 15 years ago

Protect pgm handler notifications in the recompiler.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.1 KB
Line 
1/* $Id: REMInternal.h 20426 2009-06-09 11:21:44Z vboxsync $ */
2/** @file
3 * REM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
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#include <VBox/pdmcritsect.h>
31#ifdef REM_INCLUDE_CPU_H
32# include "target-i386/cpu.h"
33#endif
34
35
36
37/** @defgroup grp_rem_int Internals
38 * @ingroup grp_rem
39 * @internal
40 * @{
41 */
42
43/** The saved state version number. */
44#define REM_SAVED_STATE_VERSION_VER1_6 6
45#define REM_SAVED_STATE_VERSION 7
46
47
48/** @def REM_MONITOR_CODE_PAGES
49 * Enable to monitor code pages that have been translated by the recompiler. */
50/** Currently broken and interferes with CSAM monitoring (see #2784) */
51////#define REM_MONITOR_CODE_PAGES
52#ifdef DOXYGEN_RUNNING
53# define REM_MONITOR_CODE_PAGES
54#endif
55
56typedef enum REMHANDLERNOTIFICATIONKIND
57{
58 /** The usual invalid 0 entry. */
59 REMHANDLERNOTIFICATIONKIND_INVALID = 0,
60 /** REMR3NotifyHandlerPhysicalRegister. */
61 REMHANDLERNOTIFICATIONKIND_PHYSICAL_REGISTER,
62 /** REMR3NotifyHandlerPhysicalDeregister. */
63 REMHANDLERNOTIFICATIONKIND_PHYSICAL_DEREGISTER,
64 /** REMR3NotifyHandlerPhysicalModify. */
65 REMHANDLERNOTIFICATIONKIND_PHYSICAL_MODIFY,
66 /** The usual 32-bit hack. */
67 REMHANDLERNOTIFICATIONKIND_32BIT_HACK = 0x7fffffff
68} REMHANDLERNOTIFICATIONKIND;
69
70
71/**
72 * A recorded handler notificiation.
73 */
74typedef struct REMHANDLERNOTIFICATION
75{
76 /** The notification kind. */
77 REMHANDLERNOTIFICATIONKIND enmKind;
78 uint32_t padding;
79 /** Type specific data. */
80 union
81 {
82 struct
83 {
84 RTGCPHYS GCPhys;
85 RTGCPHYS cb;
86 PGMPHYSHANDLERTYPE enmType;
87 bool fHasHCHandler;
88 } PhysicalRegister;
89
90 struct
91 {
92 RTGCPHYS GCPhys;
93 RTGCPHYS cb;
94 PGMPHYSHANDLERTYPE enmType;
95 bool fHasHCHandler;
96 bool fRestoreAsRAM;
97 } PhysicalDeregister;
98
99 struct
100 {
101 RTGCPHYS GCPhysOld;
102 RTGCPHYS GCPhysNew;
103 RTGCPHYS cb;
104 PGMPHYSHANDLERTYPE enmType;
105 bool fHasHCHandler;
106 bool fRestoreAsRAM;
107 } PhysicalModify;
108 uint64_t padding[5];
109 } u;
110 uint32_t idxSelf;
111 uint32_t idxNext;
112} REMHANDLERNOTIFICATION, *PREMHANDLERNOTIFICATION;
113
114/**
115 * Converts a REM pointer into a VM pointer.
116 * @returns Pointer to the VM structure the REM is part of.
117 * @param pREM Pointer to REM instance data.
118 */
119#define REM2VM(pREM) ( (PVM)((char*)pREM - pREM->offVM) )
120
121
122/**
123 * REM Data (part of VM)
124 */
125typedef struct REM
126{
127 /** Offset to the VM structure. */
128 RTINT offVM;
129 /** Alignment padding. */
130 RTUINT uPadding0;
131
132 /** Cached pointer of the register context of the current VCPU. */
133 R3PTRTYPE(PCPUMCTX) pCtx;
134
135 /** In REM mode.
136 * I.e. the correct CPU state and some other bits are with REM. */
137 bool volatile fInREM;
138 /** In REMR3State. */
139 bool fInStateSync;
140
141 /** Set when the translation blocks cache need to be flushed. */
142 bool fFlushTBs;
143
144 /** Ignore CR3 load notifications from the REM. */
145 bool fIgnoreCR3Load;
146 /** Ignore invlpg notifications from the REM. */
147 bool fIgnoreInvlPg;
148 /** Ignore CR0, CR4 and EFER load. */
149 bool fIgnoreCpuMode;
150 /** Ignore set page. */
151 bool fIgnoreSetPage;
152 bool bPadding1;
153
154 /** Ignore all that can be ignored. */
155 uint32_t cIgnoreAll;
156
157 /** Number of times REMR3CanExecuteRaw has been called.
158 * It is used to prevent rescheduling on the first call. */
159 uint32_t cCanExecuteRaw;
160
161 /** Pending interrupt (~0 -> nothing). */
162 uint32_t u32PendingInterrupt;
163
164 /** Number of recorded invlpg instructions. */
165 uint32_t cInvalidatedPages;
166 /** Array of recorded invlpg instruction.
167 * These instructions are replayed when entering REM. */
168 RTGCPTR aGCPtrInvalidatedPages[48];
169
170 /** Array of recorded handler noticications.
171 * These are replayed when entering REM. */
172 REMHANDLERNOTIFICATION aHandlerNotifications[32];
173 volatile uint32_t idxPendingList;
174 volatile uint32_t idxFreeList;
175
176 /** MMIO memory type.
177 * This is used to register MMIO physical access handlers. */
178 int32_t iMMIOMemType;
179 /** Handler memory type.
180 * This is used to register non-MMIO physical access handlers which are executed in HC. */
181 int32_t iHandlerMemType;
182
183 /** Pending exception */
184 uint32_t uPendingException;
185 /** Nr of pending exceptions */
186 uint32_t cPendingExceptions;
187 /** Pending exception's EIP */
188 uint32_t uPendingExcptEIP;
189 uint32_t reserved_for_future_uPendingExcptRIP;
190 /** Pending exception's CR2 */
191 uint32_t uPendingExcptCR2;
192 uint32_t reserved_for_future_64bit_uPendingExcptCR2;
193
194 /** The highest known RAM address. */
195 RTGCPHYS GCPhysLastRam;
196 /** Whether GCPhysLastRam has been fixed (see REMR3Init()). */
197 bool fGCPhysLastRamFixed;
198
199 /** Pending rc. */
200 int32_t rc;
201
202 /** REM critical section.
203 * This protects cpu_register_physical_memory usage
204 */
205 PDMCRITSECT CritSectRegister;
206
207 /** Time spent in QEMU. */
208 STAMPROFILEADV StatsInQEMU;
209 /** Time spent in rawmode.c. */
210 STAMPROFILEADV StatsInRAWEx;
211 /** Time spent switching state. */
212 STAMPROFILE StatsState;
213 /** Time spent switching state back. */
214 STAMPROFILE StatsStateBack;
215
216 /** Padding the CPUX86State structure to 32 byte. */
217 uint32_t abPadding[HC_ARCH_BITS == 32 ? 2 : 6];
218
219# define REM_ENV_SIZE 0xff00
220
221 /** Recompiler CPU state. */
222#ifdef REM_INCLUDE_CPU_H
223 CPUX86State Env;
224#else
225 struct FakeEnv
226 {
227 char achPadding[REM_ENV_SIZE];
228 } Env;
229#endif /* !REM_INCLUDE_CPU_H */
230} REM;
231
232/** Pointer to the REM Data. */
233typedef REM *PREM;
234
235
236#ifdef REM_INCLUDE_CPU_H
237bool remR3CanExecuteRaw(CPUState *env, RTGCPTR eip, unsigned fFlags, int *piException);
238void remR3CSAMCheckEIP(CPUState *env, RTGCPTR GCPtrCode);
239bool remR3GetOpcode(CPUState *env, RTGCPTR GCPtrInstr, uint8_t *pu8Byte);
240bool remR3DisasInstr(CPUState *env, int f32BitCode, char *pszPrefix);
241void remR3FlushPage(CPUState *env, RTGCPTR GCPtr);
242void remR3SetPage(CPUState *env, CPUTLBEntry *pRead, CPUTLBEntry *pWrite, int prot, int is_user);
243void remR3FlushTLB(CPUState *env, bool fGlobal);
244void remR3ProtectCode(CPUState *env, RTGCPTR GCPtr);
245void remR3ChangeCpuMode(CPUState *env);
246void remR3DmaRun(CPUState *env);
247void remR3TimersRun(CPUState *env);
248int remR3NotifyTrap(CPUState *env, uint32_t uTrap, uint32_t uErrorCode, RTGCPTR pvNextEIP);
249void remR3TrapStat(CPUState *env, uint32_t uTrap);
250void remR3CpuId(CPUState *env, unsigned uOperator, void *pvEAX, void *pvEBX, void *pvECX, void *pvEDX);
251void remR3RecordCall(CPUState *env);
252#endif /* REM_INCLUDE_CPU_H */
253void remR3TrapClear(PVM pVM);
254void remR3RaiseRC(PVM pVM, int rc);
255void remR3DumpLnxSyscall(PVMCPU pVCpu);
256void remR3DumpOBsdSyscall(PVMCPU pVCpu);
257
258
259/** @todo r=bird: clean up the RAWEx stats. */
260/* temporary hacks */
261#define RAWEx_ProfileStart(a, b) remR3ProfileStart(b)
262#define RAWEx_ProfileStop(a, b) remR3ProfileStop(b)
263
264
265#ifdef VBOX_WITH_STATISTICS
266
267# define STATS_EMULATE_SINGLE_INSTR 1
268# define STATS_QEMU_COMPILATION 2
269# define STATS_QEMU_RUN_EMULATED_CODE 3
270# define STATS_QEMU_TOTAL 4
271# define STATS_QEMU_RUN_TIMERS 5
272# define STATS_TLB_LOOKUP 6
273# define STATS_IRQ_HANDLING 7
274# define STATS_RAW_CHECK 8
275
276void remR3ProfileStart(int statcode);
277void remR3ProfileStop(int statcode);
278
279#else /* !VBOX_WITH_STATISTICS */
280# define remR3ProfileStart(c) do { } while (0)
281# define remR3ProfileStop(c) do { } while (0)
282#endif /* !VBOX_WITH_STATISTICS */
283
284/** @} */
285
286#endif
287
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