VirtualBox

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

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

Biggest check-in ever. New source code headers for all (C) innotek files.

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