VirtualBox

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

Last change on this file since 33000 was 28800, checked in by vboxsync, 14 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.8 KB
Line 
1/* $Id: TRPMInternal.h 28800 2010-04-27 08:22:32Z 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/stam.h>
24#include <VBox/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
34RT_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)
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 * freqently 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 alignement. */
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 /* R3: Statistics for interrupt handlers (allocated on the hypervisor heap). */
159 R3PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR3;
160 /* R0: Statistics for interrupt handlers (allocated on the hypervisor heap). */
161 R0PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR0;
162 /* RC: Statistics for interrupt handlers (allocated on the hypervisor heap). */
163 RCPTRTYPE(PSTAMCOUNTER) paStatForwardedIRQRC;
164#endif
165} TRPM;
166
167/** Pointer to TRPM Data. */
168typedef TRPM *PTRPM;
169
170
171/**
172 * Converts a TRPMCPU pointer into a VM pointer.
173 * @returns Pointer to the VM structure the TRPMCPU is part of.
174 * @param pTRPM Pointer to TRPMCPU instance data.
175 */
176#define TRPMCPU_2_VM(pTrpmCpu) ( (PVM)((uint8_t *)(pTrpmCpu) - (pTrpmCpu)->offVM) )
177
178/**
179 * Converts a TRPMCPU pointer into a VMCPU pointer.
180 * @returns Pointer to the VMCPU structure the TRPMCPU is part of.
181 * @param pTRPM Pointer to TRPMCPU instance data.
182 */
183#define TRPMCPU_2_VMCPU(pTrpmCpu) ( (PVMCPU)((uint8_t *)(pTrpmCpu) - (pTrpmCpu)->offVMCpu) )
184
185
186/**
187 * Per CPU data for TRPM.
188 */
189typedef struct TRPMCPU
190{
191 /** Offset into the VM structure.
192 * See TRPMCPU_2_VM(). */
193 uint32_t offVM;
194 /** Offset into the VMCPU structure.
195 * See TRPMCPU_2_VMCPU(). */
196 uint32_t offVMCpu;
197
198 /** Active Interrupt or trap vector number.
199 * If not ~0U this indicates that we're currently processing
200 * a interrupt, trap, fault, abort, whatever which have arrived
201 * at that vector number.
202 */
203 RTUINT uActiveVector;
204
205 /** Active trap type. */
206 TRPMEVENT enmActiveType;
207
208 /** Errorcode for the active interrupt/trap. */
209 RTGCUINT uActiveErrorCode; /**< @todo don't use RTGCUINT */
210
211 /** CR2 at the time of the active exception. */
212 RTGCUINTPTR uActiveCR2;
213
214 /** Saved trap vector number. */
215 RTGCUINT uSavedVector; /**< @todo don't use RTGCUINT */
216
217 /** Saved trap type. */
218 TRPMEVENT enmSavedType;
219
220 /** Saved errorcode. */
221 RTGCUINT uSavedErrorCode;
222
223 /** Saved cr2. */
224 RTGCUINTPTR uSavedCR2;
225
226 /** Previous trap vector # - for debugging. */
227 RTGCUINT uPrevVector;
228} TRPMCPU;
229
230/** Pointer to TRPMCPU Data. */
231typedef TRPMCPU *PTRPMCPU;
232
233#pragma pack()
234
235
236VMMRCDECL(int) trpmRCGuestIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
237VMMRCDECL(int) trpmRCShadowIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
238
239/**
240 * Clear guest trap/interrupt gate handler
241 *
242 * @returns VBox status code.
243 * @param pVM The VM to operate on.
244 * @param iTrap Interrupt/trap number.
245 */
246VMMDECL(int) trpmClearGuestTrapHandler(PVM pVM, unsigned iTrap);
247
248
249#ifdef IN_RING3
250
251/**
252 * Clear passthrough interrupt gate handler (reset to default handler)
253 *
254 * @returns VBox status code.
255 * @param pVM The VM to operate on.
256 * @param iTrap Trap/interrupt gate number.
257 */
258VMMR3DECL(int) trpmR3ClearPassThroughHandler(PVM pVM, unsigned iTrap);
259
260#endif
261
262
263#ifdef IN_RING0
264
265/**
266 * Calls the interrupt gate as if we received an interrupt while in Ring-0.
267 *
268 * @param uIP The interrupt gate IP.
269 * @param SelCS The interrupt gate CS.
270 * @param RSP The interrupt gate RSP. ~0 if no stack switch should take place. (only AMD64)
271 */
272DECLASM(void) trpmR0DispatchHostInterrupt(RTR0UINTPTR uIP, RTSEL SelCS, RTR0UINTPTR RSP);
273
274/**
275 * Issues a software interrupt to the specified interrupt vector.
276 *
277 * @param uActiveVector The vector number.
278 */
279DECLASM(void) trpmR0DispatchHostInterruptSimple(RTUINT uActiveVector);
280
281#endif /* IN_RING0 */
282
283/** @} */
284
285RT_C_DECLS_END
286
287#endif
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use