VirtualBox

source: vbox/trunk/src/VBox/VMM/include/TRPMInternal.h@ 44397

Last change on this file since 44397 was 43872, checked in by vboxsync, 12 years ago

Make VBOX_WITH_RAW_MODE= link.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.0 KB
Line 
1/* $Id: TRPMInternal.h 43872 2012-11-15 08:52:11Z vboxsync $ */
2/** @file
3 * TRPM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
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
18#ifndef ___TRPMInternal_h
19#define ___TRPMInternal_h
20
21#include <VBox/cdefs.h>
22#include <VBox/types.h>
23#include <VBox/vmm/stam.h>
24#include <VBox/vmm/cpum.h>
25
26
27
28/** Enable to allow trap forwarding in GC. */
29#ifdef VBOX_WITH_RAW_MODE
30# define TRPM_FORWARD_TRAPS_IN_GC
31#endif
32
33/** First interrupt handler. Used for validating input. */
34#define TRPM_HANDLER_INT_BASE 0x20
35
36RT_C_DECLS_BEGIN
37
38
39/** @defgroup grp_trpm_int Internals
40 * @ingroup grp_trpm
41 * @internal
42 * @{
43 */
44
45/** @name TRPMGCTrapIn* flags.
46 * The lower bits are offsets into the CPUMCTXCORE structure.
47 * @{ */
48/** The mask for the operation. */
49#define TRPM_TRAP_IN_OP_MASK 0xffff
50/** Traps on MOV GS, eax. */
51#define TRPM_TRAP_IN_MOV_GS 1
52/** Traps on MOV FS, eax. */
53#define TRPM_TRAP_IN_MOV_FS 2
54/** Traps on MOV ES, eax. */
55#define TRPM_TRAP_IN_MOV_ES 3
56/** Traps on MOV DS, eax. */
57#define TRPM_TRAP_IN_MOV_DS 4
58/** Traps on IRET. */
59#define TRPM_TRAP_IN_IRET 5
60/** Set if this is a V86 resume. */
61#define TRPM_TRAP_IN_V86 RT_BIT(30)
62/** @} */
63
64
65#if 0 /* not used */
66/**
67 * Converts a TRPM pointer into a VM pointer.
68 * @returns Pointer to the VM structure the TRPM is part of.
69 * @param pTRPM Pointer to TRPM instance data.
70 */
71#define TRPM_2_VM(pTRPM) ( (PVM)((uint8_t *)(pTRPM) - (pTRPM)->offVM) )
72#endif
73
74/**
75 * Converts a TRPM pointer into a TRPMCPU pointer.
76 * @returns Pointer to the VM structure the TRPMCPU is part of.
77 * @param pTRPM Pointer to TRPMCPU instance data.
78 * @remarks Raw-mode only, not SMP safe.
79 */
80#define TRPM_2_TRPMCPU(pTrpmCpu) ( (PTRPMCPU)((uint8_t *)(pTrpmCpu) + (pTrpmCpu)->offTRPMCPU) )
81
82
83/**
84 * TRPM Data (part of VM)
85 *
86 * IMPORTANT! Keep the nasm version of this struct up-to-date.
87 */
88#pragma pack(4)
89typedef struct TRPM
90{
91 /** Offset to the VM structure.
92 * See TRPM_2_VM(). */
93 RTINT offVM;
94 /** Offset to the TRPMCPU structure.
95 * See TRPM2TRPMCPU(). */
96 RTINT offTRPMCPU;
97
98 /** IDT monitoring and sync flag (HWACC). */
99 bool fDisableMonitoring; /** @todo r=bird: bool and 7 byte achPadding1. */
100
101 /** Whether monitoring of the guest IDT is enabled or not.
102 *
103 * This configuration option is provided for speeding up guest like Solaris
104 * that put the IDT on the same page as a whole lot of other data that is
105 * frequently updated. The updates will cause #PFs and have to be interpreted
106 * by PGMInterpretInstruction which is slow compared to raw execution.
107 *
108 * If the guest is well behaved and doesn't change the IDT after loading it,
109 * there is no problem with dropping the IDT monitoring.
110 *
111 * @cfgm /TRPM/SafeToDropGuestIDTMonitoring boolean defaults to false.
112 */
113 bool fSafeToDropGuestIDTMonitoring;
114
115 /** Padding to get the IDTs at a 16 byte alignment. */
116 uint8_t abPadding1[6];
117 /** IDTs. Aligned at 16 byte offset for speed. */
118 VBOXIDTE aIdt[256];
119
120 /** Bitmap for IDTEs that contain PATM handlers. (needed for relocation) */
121 uint32_t au32IdtPatched[8];
122
123 /** Temporary Hypervisor trap handlers.
124 * NULL means default action. */
125 RCPTRTYPE(void *) aTmpTrapHandlers[256];
126
127 /** RC Pointer to the IDT shadow area (aIdt) in HMA. */
128 RCPTRTYPE(void *) pvMonShwIdtRC;
129 /** Current (last) Guest's IDTR. */
130 VBOXIDTR GuestIdtr;
131
132 /** padding. */
133 uint8_t au8Padding[2];
134
135 /** Checked trap & interrupt handler array */
136 RCPTRTYPE(void *) aGuestTrapHandler[256];
137
138 /** RC: The number of times writes to the Guest IDT were detected. */
139 STAMCOUNTER StatRCWriteGuestIDTFault;
140 STAMCOUNTER StatRCWriteGuestIDTHandled;
141
142 /** HC: Profiling of the TRPMR3SyncIDT() method. */
143 STAMPROFILE StatSyncIDT;
144 /** GC: Statistics for the trap handlers. */
145 STAMPROFILEADV aStatGCTraps[0x14];
146
147 STAMPROFILEADV StatForwardProfR3;
148 STAMPROFILEADV StatForwardProfRZ;
149 STAMCOUNTER StatForwardFailNoHandler;
150 STAMCOUNTER StatForwardFailPatchAddr;
151 STAMCOUNTER StatForwardFailR3;
152 STAMCOUNTER StatForwardFailRZ;
153
154 STAMPROFILE StatTrap0dDisasm;
155 STAMCOUNTER StatTrap0dRdTsc; /**< Number of RDTSC #GPs. */
156
157#ifdef VBOX_WITH_STATISTICS
158 /** Statistics for interrupt handlers (allocated on the hypervisor heap) - R3
159 * pointer. */
160 R3PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR3;
161 /** Statistics for interrupt handlers - R0 pointer. */
162 R0PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR0;
163 /** Statistics for interrupt handlers - RC pointer. */
164 RCPTRTYPE(PSTAMCOUNTER) paStatForwardedIRQRC;
165
166 /** Host interrupt statistics (allocated on the hypervisor heap) - RC ptr. */
167 RCPTRTYPE(PSTAMCOUNTER) paStatHostIrqRC;
168 /** Host interrupt statistics (allocated on the hypervisor heap) - R3 ptr. */
169 R3PTRTYPE(PSTAMCOUNTER) paStatHostIrqR3;
170 /** Host interrupt statistics (allocated on the hypervisor heap) - R0 ptr. */
171 R0PTRTYPE(PSTAMCOUNTER) paStatHostIrqR0;
172#endif
173} TRPM;
174
175/** Pointer to TRPM Data. */
176typedef TRPM *PTRPM;
177
178
179/**
180 * Converts a TRPMCPU pointer into a VM pointer.
181 * @returns Pointer to the VM structure the TRPMCPU is part of.
182 * @param pTRPM Pointer to TRPMCPU instance data.
183 */
184#define TRPMCPU_2_VM(pTrpmCpu) ( (PVM)((uint8_t *)(pTrpmCpu) - (pTrpmCpu)->offVM) )
185
186/**
187 * Converts a TRPMCPU pointer into a VMCPU pointer.
188 * @returns Pointer to the VMCPU structure the TRPMCPU is part of.
189 * @param pTRPM Pointer to TRPMCPU instance data.
190 */
191#define TRPMCPU_2_VMCPU(pTrpmCpu) ( (PVMCPU)((uint8_t *)(pTrpmCpu) - (pTrpmCpu)->offVMCpu) )
192
193
194/**
195 * Per CPU data for TRPM.
196 */
197typedef struct TRPMCPU
198{
199 /** Offset into the VM structure.
200 * See TRPMCPU_2_VM(). */
201 uint32_t offVM;
202 /** Offset into the VMCPU structure.
203 * See TRPMCPU_2_VMCPU(). */
204 uint32_t offVMCpu;
205
206 /** Active Interrupt or trap vector number.
207 * If not UINT32_MAX this indicates that we're currently processing a
208 * interrupt, trap, fault, abort, whatever which have arrived at that
209 * vector number.
210 */
211 uint32_t uActiveVector;
212
213 /** Active trap type. */
214 TRPMEVENT enmActiveType;
215
216 /** Errorcode for the active interrupt/trap. */
217 RTGCUINT uActiveErrorCode; /**< @todo don't use RTGCUINT */
218
219 /** CR2 at the time of the active exception. */
220 RTGCUINTPTR uActiveCR2;
221
222 /** Saved trap vector number. */
223 RTGCUINT uSavedVector; /**< @todo don't use RTGCUINT */
224
225 /** Saved trap type. */
226 TRPMEVENT enmSavedType;
227
228 /** Saved errorcode. */
229 RTGCUINT uSavedErrorCode;
230
231 /** Saved cr2. */
232 RTGCUINTPTR uSavedCR2;
233
234 /** Previous trap vector # - for debugging. */
235 RTGCUINT uPrevVector;
236} TRPMCPU;
237
238/** Pointer to TRPMCPU Data. */
239typedef TRPMCPU *PTRPMCPU;
240
241#pragma pack()
242
243
244VMMRCDECL(int) trpmRCGuestIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
245VMMRCDECL(int) trpmRCShadowIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
246
247/**
248 * Clear guest trap/interrupt gate handler
249 *
250 * @returns VBox status code.
251 * @param pVM Pointer to the VM.
252 * @param iTrap Interrupt/trap number.
253 */
254VMMDECL(int) trpmClearGuestTrapHandler(PVM pVM, unsigned iTrap);
255
256
257#ifdef IN_RING3
258
259/**
260 * Clear passthrough interrupt gate handler (reset to default handler)
261 *
262 * @returns VBox status code.
263 * @param pVM Pointer to the VM.
264 * @param iTrap Trap/interrupt gate number.
265 */
266VMMR3DECL(int) trpmR3ClearPassThroughHandler(PVM pVM, unsigned iTrap);
267
268#endif
269
270
271#ifdef IN_RING0
272
273/**
274 * Calls the interrupt gate as if we received an interrupt while in Ring-0.
275 *
276 * @param uIP The interrupt gate IP.
277 * @param SelCS The interrupt gate CS.
278 * @param RSP The interrupt gate RSP. ~0 if no stack switch should take place. (only AMD64)
279 */
280DECLASM(void) trpmR0DispatchHostInterrupt(RTR0UINTPTR uIP, RTSEL SelCS, RTR0UINTPTR RSP);
281
282/**
283 * Issues a software interrupt to the specified interrupt vector.
284 *
285 * @param uActiveVector The vector number.
286 */
287DECLASM(void) trpmR0DispatchHostInterruptSimple(RTUINT uActiveVector);
288
289#endif /* IN_RING0 */
290
291/** @} */
292
293RT_C_DECLS_END
294
295#endif
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