VirtualBox

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

Last change on this file since 8863 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1/* $Id: TRPMInternal.h 8155 2008-04-18 15:16:47Z 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 uint8_t abPadding1[6];
142
143 /** IDTs. Aligned at 16 byte offset for speed. */
144 VBOXIDTE aIdt[256];
145
146 /** Bitmap for IDTEs that contain PATM handlers. (needed for relocation) */
147 uint32_t au32IdtPatched[8];
148
149 /** Temporary Hypervisor trap handlers.
150 * NULL means default action. */
151 RTGCPTR aTmpTrapHandlers[256];
152
153 /** GC Pointer to the IDT shadow area (aIdt) placed in Hypervisor memory arena. */
154 RTGCPTR GCPtrIdt;
155 /** Current (last) Guest's IDTR. */
156 VBOXIDTR GuestIdtr;
157
158 /** padding. */
159 uint8_t au8Padding[2];
160
161 /** Checked trap & interrupt handler array */
162 RTGCPTR aGuestTrapHandler[256];
163
164 /** GC: The number of times writes to the Guest IDT were detected. */
165 STAMCOUNTER StatGCWriteGuestIDTFault;
166 STAMCOUNTER StatGCWriteGuestIDTHandled;
167
168 /** HC: Profiling of the TRPMR3SyncIDT() method. */
169 STAMPROFILE StatSyncIDT;
170 /** GC: Statistics for the trap handlers. */
171 STAMPROFILEADV aStatGCTraps[0x14];
172
173 STAMCOUNTER StatForwardFailNoHandler;
174 STAMCOUNTER StatForwardFailPatchAddr;
175 STAMCOUNTER StatForwardFailGC;
176 STAMCOUNTER StatForwardFailHC;
177
178 STAMPROFILEADV StatForwardProfGC;
179 STAMPROFILEADV StatForwardProfHC;
180 STAMPROFILE StatTrap0dDisasm;
181 STAMCOUNTER StatTrap0dRdTsc; /**< Number of RDTSC #GPs. */
182
183 /* R3: Statistics for interrupt handlers (allocated on the hypervisor heap). */
184 R3PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR3;
185 /* R0: Statistics for interrupt handlers (allocated on the hypervisor heap). */
186 R0PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR0;
187 /* GC: Statistics for interrupt handlers (allocated on the hypervisor heap). */
188 GCPTRTYPE(PSTAMCOUNTER) paStatForwardedIRQGC;
189} TRPM;
190#pragma pack()
191
192/** Pointer to TRPM Data. */
193typedef TRPM *PTRPM;
194
195TRPMGCDECL(int) trpmgcGuestIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, void *pvRange, uintptr_t offRange);
196TRPMGCDECL(int) trpmgcShadowIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, void *pvRange, uintptr_t offRange);
197
198/**
199 * Clear guest trap/interrupt gate handler
200 *
201 * @returns VBox status code.
202 * @param pVM The VM to operate on.
203 * @param iTrap Interrupt/trap number.
204 */
205TRPMDECL(int) trpmClearGuestTrapHandler(PVM pVM, unsigned iTrap);
206
207
208#ifdef IN_RING3
209
210/**
211 * Clear passthrough interrupt gate handler (reset to default handler)
212 *
213 * @returns VBox status code.
214 * @param pVM The VM to operate on.
215 * @param iTrap Trap/interrupt gate number.
216 */
217TRPMR3DECL(int) trpmR3ClearPassThroughHandler(PVM pVM, unsigned iTrap);
218
219#endif
220
221
222#ifdef IN_RING0
223
224/**
225 * Calls the interrupt gate as if we received an interrupt while in Ring-0.
226 *
227 * @param uIP The interrupt gate IP.
228 * @param SelCS The interrupt gate CS.
229 * @param RSP The interrupt gate RSP. ~0 if no stack switch should take place. (only AMD64)
230 */
231DECLASM(void) trpmR0DispatchHostInterrupt(RTR0UINTPTR uIP, RTSEL SelCS, RTR0UINTPTR RSP);
232
233/**
234 * Issues a software interrupt to the specified interrupt vector.
235 *
236 * @param uActiveVector The vector number.
237 */
238DECLASM(void) trpmR0DispatchHostInterruptSimple(RTUINT uActiveVector);
239
240# ifdef VBOX_WITH_IDT_PATCHING
241/**
242 * Code used for the dispatching of interrupts in HC.
243 * @internal
244 */
245DECLASM(int) trpmR0InterruptDispatcher(void);
246# endif /* VBOX_WITH_IDT_PATCHING */
247
248#endif
249
250/** @} */
251
252__END_DECLS
253
254#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