VirtualBox

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

Last change on this file since 2233 was 2124, checked in by vboxsync, 18 years ago

TRPM changes to assert and report trap/interrupt types accurately.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.8 KB
Line 
1/* $Id: TRPMInternal.h 2124 2007-04-17 12:25:17Z vboxsync $ */
2/** @file
3 * TRPM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
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 BIT(30)
67/** If set this is a hypervisor register set. If cleared it's a guest set. */
68#define TRPM_TRAP_IN_HYPER 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 */
124 RTUINT fDisableMonitoring; /** @todo r=bird: bool and 7 byte achPadding1. */
125
126 /** Padding to get the IDTs at a 16 byte alignement. */
127 char achPadding1[4];
128
129 /** IDTs. Aligned at 16 byte offset for speed. */
130 VBOXIDTE aIdt[256];
131
132 /** Bitmap for IDTEs that contain PATM handlers. (needed for relocation) */
133 uint32_t au32IdtPatched[8];
134
135 /** Temporary Hypervisor trap handlers.
136 * NULL means default action. */
137 RTGCPTR aTmpTrapHandlers[256];
138
139 /** GC Pointer to the IDT shadow area (aIdt) placed in Hypervisor memory arena. */
140 RTGCPTR GCPtrIdt;
141 /** Current (last) Guest's IDTR. */
142 VBOXIDTR GuestIdtr;
143
144 /** padding. */
145 uint8_t au8Padding[2];
146
147 /** Checked trap & interrupt handler array */
148 RTGCPTR aGuestTrapHandler[256];
149
150 /** GC: The number of times writes to the Guest IDT were detected. */
151 STAMCOUNTER StatGCWriteGuestIDTFault;
152 STAMCOUNTER StatGCWriteGuestIDTHandled;
153
154 /** HC: Profiling of the TRPMR3SyncIDT() method. */
155 STAMPROFILE StatSyncIDT;
156 /** GC: Statistics for the trap handlers. */
157 STAMPROFILEADV aStatGCTraps[0x14];
158
159 STAMCOUNTER StatForwardFailNoHandler;
160 STAMCOUNTER StatForwardFailPatchAddr;
161 STAMCOUNTER StatForwardFailGC;
162 STAMCOUNTER StatForwardFailHC;
163
164 STAMPROFILEADV StatForwardProfGC;
165 STAMPROFILEADV StatForwardProfHC;
166 STAMPROFILEADV StatTrap0dDisasm;
167
168 /* R3: Statistics for interrupt handlers (allocated on the hypervisor heap). */
169 R3PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR3;
170 /* R0: Statistics for interrupt handlers (allocated on the hypervisor heap). */
171 R0PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR0;
172 /* GC: Statistics for interrupt handlers (allocated on the hypervisor heap). */
173 GCPTRTYPE(PSTAMCOUNTER) paStatForwardedIRQGC;
174} TRPM;
175#pragma pack()
176
177/** Pointer to TRPM Data. */
178typedef TRPM *PTRPM;
179
180TRPMGCDECL(int) trpmgcGuestIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, void *pvRange, uintptr_t offRange);
181TRPMGCDECL(int) trpmgcShadowIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, void *pvRange, uintptr_t offRange);
182
183/**
184 * Clear guest trap/interrupt gate handler
185 *
186 * @returns VBox status code.
187 * @param pVM The VM to operate on.
188 * @param iTrap Interrupt/trap number.
189 */
190TRPMDECL(int) trpmClearGuestTrapHandler(PVM pVM, unsigned iTrap);
191
192
193#ifdef IN_RING3
194
195/**
196 * Clear passthrough interrupt gate handler (reset to default handler)
197 *
198 * @returns VBox status code.
199 * @param pVM The VM to operate on.
200 * @param iTrap Trap/interrupt gate number.
201 */
202TRPMR3DECL(int) trpmR3ClearPassThroughHandler(PVM pVM, unsigned iTrap);
203
204#endif
205
206
207#ifdef IN_RING0
208
209/**
210 * Calls the interrupt gate as if we received an interrupt while in Ring-0.
211 *
212 * @param uIP The interrupt gate IP.
213 * @param SelCS The interrupt gate CS.
214 * @param RSP The interrupt gate RSP. ~0 if no stack switch should take place. (only AMD64)
215 */
216DECLASM(void) trpmR0DispatchHostInterrupt(RTR0UINTPTR uIP, RTSEL SelCS, RTR0UINTPTR RSP);
217
218/**
219 * Issues a software interrupt to the specified interrupt vector.
220 *
221 * @param uActiveVector The vector number.
222 */
223DECLASM(void) trpmR0DispatchHostInterruptSimple(RTUINT uActiveVector);
224
225# ifndef VBOX_WITHOUT_IDT_PATCHING
226/**
227 * Code used for the dispatching of interrupts in HC.
228 * @internal
229 */
230DECLASM(int) trpmR0InterruptDispatcher(void);
231# endif /* !VBOX_WITHOUT_IDT_PATCHING */
232
233#endif
234
235/** @} */
236
237__END_DECLS
238
239#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