1 | /* $Id: TRPMInternal.h 39078 2011-10-21 14:18:22Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * TRPM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 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 | #define TRPM_FORWARD_TRAPS_IN_GC
|
---|
30 |
|
---|
31 | /** First interrupt handler. Used for validating input. */
|
---|
32 | #define TRPM_HANDLER_INT_BASE 0x20
|
---|
33 |
|
---|
34 | RT_C_DECLS_BEGIN
|
---|
35 |
|
---|
36 |
|
---|
37 | /** @defgroup grp_trpm_int Internals
|
---|
38 | * @ingroup grp_trpm
|
---|
39 | * @internal
|
---|
40 | * @{
|
---|
41 | */
|
---|
42 |
|
---|
43 | /** @name TRPMGCTrapIn* flags.
|
---|
44 | * The lower bits are offsets into the CPUMCTXCORE structure.
|
---|
45 | * @{ */
|
---|
46 | /** The mask for the operation. */
|
---|
47 | #define TRPM_TRAP_IN_OP_MASK 0xffff
|
---|
48 | /** Traps on MOV GS, eax. */
|
---|
49 | #define TRPM_TRAP_IN_MOV_GS 1
|
---|
50 | /** Traps on MOV FS, eax. */
|
---|
51 | #define TRPM_TRAP_IN_MOV_FS 2
|
---|
52 | /** Traps on MOV ES, eax. */
|
---|
53 | #define TRPM_TRAP_IN_MOV_ES 3
|
---|
54 | /** Traps on MOV DS, eax. */
|
---|
55 | #define TRPM_TRAP_IN_MOV_DS 4
|
---|
56 | /** Traps on IRET. */
|
---|
57 | #define TRPM_TRAP_IN_IRET 5
|
---|
58 | /** Set if this is a V86 resume. */
|
---|
59 | #define TRPM_TRAP_IN_V86 RT_BIT(30)
|
---|
60 | /** If set this is a hypervisor register set. If cleared it's a guest set. */
|
---|
61 | #define TRPM_TRAP_IN_HYPER RT_BIT(31)
|
---|
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)
|
---|
89 | typedef 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. */
|
---|
176 | typedef 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 | */
|
---|
197 | typedef 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. */
|
---|
239 | typedef TRPMCPU *PTRPMCPU;
|
---|
240 |
|
---|
241 | #pragma pack()
|
---|
242 |
|
---|
243 |
|
---|
244 | VMMRCDECL(int) trpmRCGuestIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
|
---|
245 | VMMRCDECL(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 The VM to operate on.
|
---|
252 | * @param iTrap Interrupt/trap number.
|
---|
253 | */
|
---|
254 | VMMDECL(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 The VM to operate on.
|
---|
264 | * @param iTrap Trap/interrupt gate number.
|
---|
265 | */
|
---|
266 | VMMR3DECL(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 | */
|
---|
280 | DECLASM(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 | */
|
---|
287 | DECLASM(void) trpmR0DispatchHostInterruptSimple(RTUINT uActiveVector);
|
---|
288 |
|
---|
289 | #endif /* IN_RING0 */
|
---|
290 |
|
---|
291 | /** @} */
|
---|
292 |
|
---|
293 | RT_C_DECLS_END
|
---|
294 |
|
---|
295 | #endif
|
---|