VirtualBox

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

Last change on this file since 10700 was 9288, checked in by vboxsync, 17 years ago

More type changes.

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