VirtualBox

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

Last change on this file since 46175 was 45728, checked in by vboxsync, 12 years ago

TRPM: Sprinkled HMIsEnabled around the place.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.7 KB
Line 
1/* $Id: TRPMInternal.h 45728 2013-04-25 12:08:17Z 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 /** Whether monitoring of the guest IDT is enabled or not.
99 *
100 * This configuration option is provided for speeding up guest like Solaris
101 * that put the IDT on the same page as a whole lot of other data that is
102 * frequently updated. The updates will cause #PFs and have to be interpreted
103 * by PGMInterpretInstruction which is slow compared to raw execution.
104 *
105 * If the guest is well behaved and doesn't change the IDT after loading it,
106 * there is no problem with dropping the IDT monitoring.
107 *
108 * @cfgm /TRPM/SafeToDropGuestIDTMonitoring boolean defaults to false.
109 */
110 bool fSafeToDropGuestIDTMonitoring;
111
112 /** Padding to get the IDTs at a 16 byte alignment. */
113 uint8_t abPadding1[7];
114 /** IDTs. Aligned at 16 byte offset for speed. */
115 VBOXIDTE aIdt[256];
116
117 /** Bitmap for IDTEs that contain PATM handlers. (needed for relocation) */
118 uint32_t au32IdtPatched[8];
119
120 /** Temporary Hypervisor trap handlers.
121 * NULL means default action. */
122 RCPTRTYPE(void *) aTmpTrapHandlers[256];
123
124 /** RC Pointer to the IDT shadow area (aIdt) in HMA. */
125 RCPTRTYPE(void *) pvMonShwIdtRC;
126 /** Current (last) Guest's IDTR. */
127 VBOXIDTR GuestIdtr;
128
129 /** padding. */
130 uint8_t au8Padding[2];
131
132 /** Checked trap & interrupt handler array */
133 RCPTRTYPE(void *) aGuestTrapHandler[256];
134
135 /** RC: The number of times writes to the Guest IDT were detected. */
136 STAMCOUNTER StatRCWriteGuestIDTFault;
137 STAMCOUNTER StatRCWriteGuestIDTHandled;
138
139 /** HC: Profiling of the TRPMR3SyncIDT() method. */
140 STAMPROFILE StatSyncIDT;
141 /** GC: Statistics for the trap handlers. */
142 STAMPROFILEADV aStatGCTraps[0x14];
143
144 STAMPROFILEADV StatForwardProfR3;
145 STAMPROFILEADV StatForwardProfRZ;
146 STAMCOUNTER StatForwardFailNoHandler;
147 STAMCOUNTER StatForwardFailPatchAddr;
148 STAMCOUNTER StatForwardFailR3;
149 STAMCOUNTER StatForwardFailRZ;
150
151 STAMPROFILE StatTrap0dDisasm;
152 STAMCOUNTER StatTrap0dRdTsc; /**< Number of RDTSC #GPs. */
153
154#ifdef VBOX_WITH_STATISTICS
155 /** Statistics for interrupt handlers (allocated on the hypervisor heap) - R3
156 * pointer. */
157 R3PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR3;
158 /** Statistics for interrupt handlers - RC pointer. */
159 RCPTRTYPE(PSTAMCOUNTER) paStatForwardedIRQRC;
160
161 /** Host interrupt statistics (allocated on the hypervisor heap) - RC ptr. */
162 RCPTRTYPE(PSTAMCOUNTER) paStatHostIrqRC;
163 /** Host interrupt statistics (allocated on the hypervisor heap) - R3 ptr. */
164 R3PTRTYPE(PSTAMCOUNTER) paStatHostIrqR3;
165#endif
166} TRPM;
167
168/** Pointer to TRPM Data. */
169typedef TRPM *PTRPM;
170
171
172/**
173 * Converts a TRPMCPU pointer into a VM pointer.
174 * @returns Pointer to the VM structure the TRPMCPU is part of.
175 * @param pTRPM Pointer to TRPMCPU instance data.
176 */
177#define TRPMCPU_2_VM(pTrpmCpu) ( (PVM)((uint8_t *)(pTrpmCpu) - (pTrpmCpu)->offVM) )
178
179/**
180 * Converts a TRPMCPU pointer into a VMCPU pointer.
181 * @returns Pointer to the VMCPU structure the TRPMCPU is part of.
182 * @param pTRPM Pointer to TRPMCPU instance data.
183 */
184#define TRPMCPU_2_VMCPU(pTrpmCpu) ( (PVMCPU)((uint8_t *)(pTrpmCpu) - (pTrpmCpu)->offVMCpu) )
185
186
187/**
188 * Per CPU data for TRPM.
189 */
190typedef struct TRPMCPU
191{
192 /** Offset into the VM structure.
193 * See TRPMCPU_2_VM(). */
194 uint32_t offVM;
195 /** Offset into the VMCPU structure.
196 * See TRPMCPU_2_VMCPU(). */
197 uint32_t offVMCpu;
198
199 /** Active Interrupt or trap vector number.
200 * If not UINT32_MAX this indicates that we're currently processing a
201 * interrupt, trap, fault, abort, whatever which have arrived at that
202 * vector number.
203 */
204 uint32_t uActiveVector;
205
206 /** Active trap type. */
207 TRPMEVENT enmActiveType;
208
209 /** Errorcode for the active interrupt/trap. */
210 RTGCUINT uActiveErrorCode; /**< @todo don't use RTGCUINT */
211
212 /** CR2 at the time of the active exception. */
213 RTGCUINTPTR uActiveCR2;
214
215 /** Saved trap vector number. */
216 RTGCUINT uSavedVector; /**< @todo don't use RTGCUINT */
217
218 /** Saved trap type. */
219 TRPMEVENT enmSavedType;
220
221 /** Saved errorcode. */
222 RTGCUINT uSavedErrorCode;
223
224 /** Saved cr2. */
225 RTGCUINTPTR uSavedCR2;
226
227 /** Previous trap vector # - for debugging. */
228 RTGCUINT uPrevVector;
229
230 /** Instruction length for software interrupts and software exceptions (#BP,
231 * #OF) */
232 uint8_t cbInstr;
233
234 /** Saved instruction length. */
235 uint8_t cbSavedInstr;
236
237 /** Padding. */
238 uint8_t au8Padding[2];
239} TRPMCPU;
240
241/** Pointer to TRPMCPU Data. */
242typedef TRPMCPU *PTRPMCPU;
243
244#pragma pack()
245
246
247VMMRCDECL(int) trpmRCGuestIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
248VMMRCDECL(int) trpmRCShadowIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
249
250/**
251 * Clear guest trap/interrupt gate handler
252 *
253 * @returns VBox status code.
254 * @param pVM Pointer to the VM.
255 * @param iTrap Interrupt/trap number.
256 */
257VMMDECL(int) trpmClearGuestTrapHandler(PVM pVM, unsigned iTrap);
258
259
260#ifdef IN_RING3
261int trpmR3ClearPassThroughHandler(PVM pVM, unsigned iTrap);
262#endif
263
264
265#ifdef IN_RING0
266
267/**
268 * Calls the interrupt gate as if we received an interrupt while in Ring-0.
269 *
270 * @param uIP The interrupt gate IP.
271 * @param SelCS The interrupt gate CS.
272 * @param RSP The interrupt gate RSP. ~0 if no stack switch should take place. (only AMD64)
273 */
274DECLASM(void) trpmR0DispatchHostInterrupt(RTR0UINTPTR uIP, RTSEL SelCS, RTR0UINTPTR RSP);
275
276/**
277 * Issues a software interrupt to the specified interrupt vector.
278 *
279 * @param uActiveVector The vector number.
280 */
281DECLASM(void) trpmR0DispatchHostInterruptSimple(RTUINT uActiveVector);
282
283#endif /* IN_RING0 */
284
285/** @} */
286
287RT_C_DECLS_END
288
289#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