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