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