2
* REM - The Recompiled Execution Manager.
6
* Copyright (C) 2006-2007 innotek GmbH
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.
20
#include <VBox/cdefs.h>
21
#include <VBox/types.h>
23
#include <VBox/vmapi.h>
28
/** @defgroup grp_rem The Recompiled Execution Manager API
32
/** No pending interrupt. */
33
#define REM_NO_PENDING_IRQ (~(uint32_t)0)
36
#if defined(IN_RING0) || defined(IN_GC)
39
* Records a invlpg instruction for replaying upon REM entry.
41
* @returns VINF_SUCCESS on success.
42
* @returns VERR_REM_FLUSHED_PAGES_OVERFLOW if a return to HC for flushing of
43
* recorded pages is required before the call can succeed.
44
* @param pVM The VM handle.
45
* @param GCPtrPage The address of the invalidated page.
47
REMDECL(int) REMNotifyInvalidatePage(PVM pVM, RTGCPTR GCPtrPage);
50
* Notification about a successful PGMR3HandlerPhysicalRegister() call.
52
* @param pVM VM Handle.
53
* @param enmType Handler type.
54
* @param GCPhys Handler range address.
55
* @param cb Size of the handler range.
56
* @param fHasHCHandler Set if the handler have a HC callback function.
58
REMDECL(void) REMNotifyHandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler);
61
* Notification about a successful PGMR3HandlerPhysicalDeregister() operation.
63
* @param pVM VM Handle.
64
* @param enmType Handler type.
65
* @param GCPhys Handler range address.
66
* @param cb Size of the handler range.
67
* @param fHasHCHandler Set if the handler have a HC callback function.
68
* @param pvHCPtr The HC virtual address corresponding to GCPhys if available.
70
REMDECL(void) REMNotifyHandlerPhysicalDeregister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler, RTHCPTR pvHCPtr);
73
* Notification about a successful PGMR3HandlerPhysicalModify() call.
75
* @param pVM VM Handle.
76
* @param enmType Handler type.
77
* @param GCPhysOld Old handler range address.
78
* @param GCPhysNew New handler range address.
79
* @param cb Size of the handler range.
80
* @param fHasHCHandler Set if the handler have a HC callback function.
81
* @param pvHCPtr The HC virtual address corresponding to GCPhys if available.
83
REMDECL(void) REMNotifyHandlerPhysicalModify(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fHasHCHandler, RTHCPTR pvHCPtr);
85
#endif /* IN_RING0 || IN_GC */
89
/** @defgroup grp_rem_r3 REM Host Context Ring 3 API
95
* Initializes the REM.
97
* @returns VBox status code.
98
* @param pVM The VM to operate on.
100
REMR3DECL(int) REMR3Init(PVM pVM);
103
* Terminates the REM.
105
* Termination means cleaning up and freeing all resources,
106
* the VM it self is at this point powered off or suspended.
108
* @returns VBox status code.
109
* @param pVM The VM to operate on.
111
REMR3DECL(int) REMR3Term(PVM pVM);
114
* The VM is being reset.
116
* For the REM component this means to call the cpu_reset() and
117
* reinitialize some state variables.
119
* @param pVM VM handle.
121
REMR3DECL(void) REMR3Reset(PVM pVM);
124
* Runs code in recompiled mode.
126
* Before calling this function the REM state needs to be in sync with
127
* the VM. Call REMR3State() to perform the sync. It's only necessary
128
* (and permitted) to sync at the first call to REMR3Step()/REMR3Run()
129
* and after calling REMR3StateBack().
131
* @returns VBox status code.
133
* @param pVM VM Handle.
135
REMR3DECL(int) REMR3Run(PVM pVM);
138
* Emulate an instruction.
140
* This function executes one instruction without letting anyone
141
* interrupt it. This is intended for being called while being in
142
* raw mode and thus will take care of all the state syncing between
145
* @returns VBox status code.
146
* @param pVM VM handle.
148
REMR3DECL(int) REMR3EmulateInstruction(PVM pVM);
151
* Single steps an instruction in recompiled mode.
153
* Before calling this function the REM state needs to be in sync with
154
* the VM. Call REMR3State() to perform the sync. It's only necessary
155
* (and permitted) to sync at the first call to REMR3Step()/REMR3Run()
156
* and after calling REMR3StateBack().
158
* @returns VBox status code.
160
* @param pVM VM Handle.
162
REMR3DECL(int) REMR3Step(PVM pVM);
165
* Set a breakpoint using the REM facilities.
167
* @returns VBox status code.
168
* @param pVM The VM handle.
169
* @param Address The breakpoint address.
170
* @thread The emulation thread.
172
REMR3DECL(int) REMR3BreakpointSet(PVM pVM, RTGCUINTPTR Address);
175
* Clears a breakpoint set by REMR3BreakpointSet().
177
* @returns VBox status code.
178
* @param pVM The VM handle.
179
* @param Address The breakpoint address.
180
* @thread The emulation thread.
182
REMR3DECL(int) REMR3BreakpointClear(PVM pVM, RTGCUINTPTR Address);
185
* Syncs the internal REM state with the VM.
187
* This must be called before REMR3Run() is invoked whenever when the REM
188
* state is not up to date. Calling it several times in a row is not
191
* @returns VBox status code.
193
* @param pVM VM Handle.
195
* @remark The caller has to check for important FFs before calling REMR3Run. REMR3State will
196
* no do this since the majority of the callers don't want any unnecessary of events
197
* pending that would immediatly interrupt execution.
199
REMR3DECL(int) REMR3State(PVM pVM);
202
* Syncs back changes in the REM state to the the VM state.
204
* This must be called after invoking REMR3Run().
205
* Calling it several times in a row is not permitted.
207
* @returns VBox status code.
209
* @param pVM VM Handle.
211
REMR3DECL(int) REMR3StateBack(PVM pVM);
214
* Update the VMM state information if we're currently in REM.
216
* This method is used by the DBGF and PDMDevice when there is any uncertainty of whether
217
* we're currently executing in REM and the VMM state is invalid. This method will of
218
* course check that we're executing in REM before syncing any data over to the VMM.
220
* @param pVM The VM handle.
222
REMR3DECL(void) REMR3StateUpdate(PVM pVM);
225
* Notify the recompiler about Address Gate 20 state change.
227
* This notification is required since A20 gate changes are
228
* initialized from a device driver and the VM might just as
229
* well be in REM mode as in RAW mode.
231
* @param pVM VM handle.
232
* @param fEnable True if the gate should be enabled.
233
* False if the gate should be disabled.
235
REMR3DECL(void) REMR3A20Set(PVM pVM, bool fEnable);
238
* Enables or disables singled stepped disassembly.
240
* @returns VBox status code.
241
* @param pVM VM handle.
242
* @param fEnable To enable set this flag, to disable clear it.
244
REMR3DECL(int) REMR3DisasEnableStepping(PVM pVM, bool fEnable);
247
* Replays the recorded invalidated pages.
248
* Called in response to VERR_REM_FLUSHED_PAGES_OVERFLOW from the RAW execution loop.
250
* @param pVM VM handle.
252
REMR3DECL(void) REMR3ReplayInvalidatedPages(PVM pVM);
255
* Replays the recorded physical handler notifications.
257
* @param pVM VM handle.
259
REMR3DECL(void) REMR3ReplayHandlerNotifications(PVM pVM);
262
* Notify REM about changed code page.
264
* @returns VBox status code.
265
* @param pVM VM handle.
266
* @param pvCodePage Code page address
268
REMR3DECL(int) REMR3NotifyCodePageChanged(PVM pVM, RTGCPTR pvCodePage);
271
* Notification about a successful MMR3RamRegister() call.
273
* @param pVM VM handle.
274
* @param GCPhys The physical address the RAM.
275
* @param cb Size of the memory.
276
* @param fFlags Flags of the MM_RAM_FLAGS_* defines.
277
* @param pvRam The HC address of the RAM.
279
REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, void *pvRam, unsigned fFlags);
282
* Notification about a successful PGMR3PhysRegisterChunk() call.
284
* @param pVM VM handle.
285
* @param GCPhys The physical address the RAM.
286
* @param cb Size of the memory.
287
* @param pvRam The HC address of the RAM.
288
* @param fFlags Flags of the MM_RAM_FLAGS_* defines.
290
REMR3DECL(void) REMR3NotifyPhysRamChunkRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, RTHCUINTPTR pvRam, unsigned fFlags);
293
* Notification about a successful MMR3PhysRomRegister() call.
295
* @param pVM VM handle.
296
* @param GCPhys The physical address of the ROM.
297
* @param cb The size of the ROM.
298
* @param pvCopy Pointer to the ROM copy.
299
* @param fShadow Whether it's currently writable shadow ROM or normal readonly ROM.
300
* This function will be called when ever the protection of the
301
* shadow ROM changes (at reset and end of POST).
303
REMR3DECL(void) REMR3NotifyPhysRomRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, void *pvCopy, bool fShadow);
306
* Notification about a successful MMR3PhysRegister() call.
308
* @param pVM VM Handle.
309
* @param GCPhys Start physical address.
310
* @param cb The size of the range.
312
REMR3DECL(void) REMR3NotifyPhysReserve(PVM pVM, RTGCPHYS GCPhys, RTUINT cb);
315
* Notification about a successful PGMR3HandlerPhysicalRegister() call.
317
* @param pVM VM Handle.
318
* @param enmType Handler type.
319
* @param GCPhys Handler range address.
320
* @param cb Size of the handler range.
321
* @param fHasHCHandler Set if the handler have a HC callback function.
323
REMR3DECL(void) REMR3NotifyHandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler);
326
* Notification about a successful PGMR3HandlerPhysicalDeregister() operation.
328
* @param pVM VM Handle.
329
* @param enmType Handler type.
330
* @param GCPhys Handler range address.
331
* @param cb Size of the handler range.
332
* @param fHasHCHandler Set if the handler have a HC callback function.
333
* @param pvHCPtr The HC virtual address corresponding to GCPhys if available.
335
REMR3DECL(void) REMR3NotifyHandlerPhysicalDeregister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler, void *pvHCPtr);
338
* Notification about a successful PGMR3HandlerPhysicalModify() call.
340
* @param pVM VM Handle.
341
* @param enmType Handler type.
342
* @param GCPhysOld Old handler range address.
343
* @param GCPhysNew New handler range address.
344
* @param cb Size of the handler range.
345
* @param fHasHCHandler Set if the handler have a HC callback function.
346
* @param pvHCPtr The HC virtual address corresponding to GCPhys if available.
348
REMR3DECL(void) REMR3NotifyHandlerPhysicalModify(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fHasHCHandler, void *pvHCPtr);
351
* Notification about a pending interrupt.
353
* @param pVM VM Handle.
354
* @param u8Interrupt Interrupt
355
* @thread The emulation thread.
357
REMR3DECL(void) REMR3NotifyPendingInterrupt(PVM pVM, uint8_t u8Interrupt);
360
* Notification about a pending interrupt.
362
* @returns Pending interrupt or REM_NO_PENDING_IRQ
363
* @param pVM VM Handle.
364
* @thread The emulation thread.
366
REMR3DECL(uint32_t) REMR3QueryPendingInterrupt(PVM pVM);
369
* Notification about the interrupt FF being set.
371
* @param pVM VM Handle.
372
* @thread The emulation thread.
374
REMR3DECL(void) REMR3NotifyInterruptSet(PVM pVM);
377
* Notification about the interrupt FF being set.
379
* @param pVM VM Handle.
380
* @thread The emulation thread.
382
REMR3DECL(void) REMR3NotifyInterruptClear(PVM pVM);
385
* Notification about pending timer(s).
387
* @param pVM VM Handle.
390
REMR3DECL(void) REMR3NotifyTimerPending(PVM pVM);
393
* Notification about pending DMA transfers.
395
* @param pVM VM Handle.
398
REMR3DECL(void) REMR3NotifyDmaPending(PVM pVM);
401
* Notification about pending timer(s).
403
* @param pVM VM Handle.
406
REMR3DECL(void) REMR3NotifyQueuePending(PVM pVM);
409
* Notification about pending FF set by an external thread.
411
* @param pVM VM handle.
414
REMR3DECL(void) REMR3NotifyFF(PVM pVM);
418
* Checks if we're handling access to this page or not.
420
* @returns true if we're trapping access.
421
* @returns false if we aren't.
422
* @param pVM The VM handle.
423
* @param GCPhys The physical address.
425
* @remark This function will only work correctly in VBOX_STRICT builds!
427
REMDECL(bool) REMR3IsPageAccessHandled(PVM pVM, RTGCPHYS GCPhys);