VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstMicroGC.cpp@ 23194

Last change on this file since 23194 was 20374, checked in by vboxsync, 16 years ago

*: s/RT_\(BEGIN|END\)_DECLS/RT_C_DECLS_\1/g

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1/* $Id: tstMicroGC.cpp 20374 2009-06-08 00:43:21Z vboxsync $ */
2/** @file
3 * Micro Testcase, profiling special CPU operations - GC Code (hacks).
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/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include <VBox/vm.h>
26#include <VBox/vmm.h>
27#include <VBox/selm.h>
28#include "tstMicro.h"
29
30#include <VBox/err.h>
31#include <iprt/asm.h>
32#include <VBox/log.h>
33#include <iprt/assert.h>
34#include <iprt/string.h>
35
36
37/*******************************************************************************
38* Internal Functions *
39*******************************************************************************/
40RT_C_DECLS_BEGIN
41DECLEXPORT(int) tstMicroGC(PTSTMICRO pTst, unsigned uTestcase);
42RT_C_DECLS_END
43
44
45/**
46 * Save and load our IDT.
47 *
48 * @param pTst Pointer to the instance data.
49 * @param iIDT The index of the IDT entry which should be hooked.
50 */
51void idtInstall(PTSTMICRO pTst, int iIDT)
52{
53 RTIDTR Idtr;
54 ASMGetIDTR(&Idtr);
55 if (Idtr.pIdt == (uintptr_t)&pTst->aIDT[0])
56 return;
57 pTst->OriginalIDTR.cbIdt = Idtr.cbIdt;
58 pTst->OriginalIDTR.pIdt = Idtr.pIdt;
59
60 /*
61 * Copy the IDT.
62 */
63 if (Idtr.cbIdt >= sizeof(pTst->aIDT))
64 Idtr.cbIdt = sizeof(pTst->aIDT) - 1;
65 memcpy(&pTst->aIDT[0], (void *)Idtr.pIdt, Idtr.cbIdt + 1);
66
67
68 /* Hook up IDT entry. */
69 if (iIDT >= 0)
70 {
71 uintptr_t uHandler = (uintptr_t)tstTrapHandlerNoErr;
72 if ( iIDT == 8
73 || iIDT == 0xa
74 || iIDT == 0xb
75 || iIDT == 0xc
76 || iIDT == 0xd
77 || iIDT == 0xe
78 || iIDT == 0x11)
79 uHandler = (uintptr_t)tstTrapHandler;
80 pTst->aIDT[iIDT].Int.u16OffsetHigh = uHandler >> 16;
81 pTst->aIDT[iIDT].Int.u16OffsetLow = uHandler & 0xffff;
82 pTst->aIDT[iIDT].Int.u16SegSel = SELMGetHyperCS(&g_VM);
83 pTst->aIDT[iIDT].Int.u2DPL = 3;
84 pTst->aIDT[iIDT].Int.u1Present = 1;
85 pTst->aIDT[iIDT].Int.u1Fixed0 = 0;
86 pTst->aIDT[iIDT].Int.u1Fixed1 = 0;
87 pTst->aIDT[iIDT].Int.u1Fixed2 = 0;
88 pTst->aIDT[iIDT].Int.u1Fixed3 = 0;
89 pTst->aIDT[iIDT].Int.u1Fixed4 = 1;
90 pTst->aIDT[iIDT].Int.u1Fixed5 = 1;
91 pTst->aIDT[iIDT].Int.u132BitGate = 1;
92 pTst->aIDT[iIDT].Int.u1Fixed6 = 0;
93 pTst->aIDT[iIDT].Int.u5Reserved2 = 0;
94 }
95
96 /* Install int 42h, R3 gate */
97 pTst->aIDT[0x42].Int.u16OffsetHigh = (uintptr_t)tstInterrupt42 >> 16;
98 pTst->aIDT[0x42].Int.u16OffsetLow = (uintptr_t)tstInterrupt42 & 0xffff;
99 pTst->aIDT[0x42].Int.u16SegSel = SELMGetHyperCS(&g_VM);
100 pTst->aIDT[0x42].Int.u2DPL = 3;
101 pTst->aIDT[0x42].Int.u1Present = 1;
102 pTst->aIDT[0x42].Int.u1Fixed0 = 0;
103 pTst->aIDT[0x42].Int.u1Fixed1 = 0;
104 pTst->aIDT[0x42].Int.u1Fixed2 = 0;
105 pTst->aIDT[0x42].Int.u1Fixed3 = 0;
106 pTst->aIDT[0x42].Int.u1Fixed4 = 1;
107 pTst->aIDT[0x42].Int.u1Fixed5 = 1;
108 pTst->aIDT[0x42].Int.u132BitGate = 1;
109 pTst->aIDT[0x42].Int.u1Fixed6 = 0;
110 pTst->aIDT[0x42].Int.u5Reserved2 = 0;
111
112 /*
113 * Load our IDT.
114 */
115 Idtr.pIdt = (uintptr_t)&pTst->aIDT[0];
116 ASMSetIDTR(&Idtr);
117
118 RTIDTR Idtr2;
119 ASMGetIDTR(&Idtr2);
120 Assert(Idtr2.pIdt == (uintptr_t)&pTst->aIDT[0]);
121}
122
123
124/**
125 * Removes all trap overrides except for gate 42.
126 */
127DECLASM(void) idtOnly42(PTSTMICRO pTst)
128{
129 if (pTst->OriginalIDTR.pIdt)
130 memcpy(&pTst->aIDT[0], (void *)pTst->OriginalIDTR.pIdt, sizeof(VBOXIDTE) * 32);
131}
132
133
134
135DECLEXPORT(int) tstMicroGC(PTSTMICRO pTst, unsigned uTestcase)
136{
137 RTLogPrintf("pTst=%p uTestcase=%d\n", pTst, uTestcase);
138
139 /*
140 * Validate input.
141 */
142 if (uTestcase >= TSTMICROTEST_MAX)
143 return VERR_INVALID_PARAMETER;
144
145 /*
146 * Clear the results.
147 */
148 pTst->u64TSCR0Start = 0;
149 pTst->u64TSCRxStart = 0;
150 pTst->u64TSCR0Enter = 0;
151 pTst->u64TSCR0Exit = 0;
152 pTst->u64TSCRxEnd = 0;
153 pTst->u64TSCR0End = 0;
154 pTst->cHits = 0;
155 pTst->offEIPAdd = 0;
156 pTst->u32CR2 = 0;
157 pTst->u32EIP = 0;
158 pTst->u32ErrCd = 0;
159 PTSTMICRORESULT pRes = &pTst->aResults[uTestcase];
160 memset(&pTst->aResults[uTestcase], 0, sizeof(pTst->aResults[uTestcase]));
161
162
163 /*
164 * Do the testcase.
165 */
166 int rc = VINF_SUCCESS;
167 switch (uTestcase)
168 {
169 case TSTMICROTEST_OVERHEAD:
170 {
171 tstOverhead(pTst);
172 break;
173 }
174
175 case TSTMICROTEST_INVLPG_0:
176 {
177 tstInvlpg0(pTst);
178 break;
179 }
180
181 case TSTMICROTEST_INVLPG_EIP:
182 {
183 tstInvlpgEIP(pTst);
184 break;
185 }
186
187 case TSTMICROTEST_INVLPG_ESP:
188 {
189 tstInvlpgESP(pTst);
190 break;
191 }
192
193 case TSTMICROTEST_CR3_RELOAD:
194 {
195 tstCR3Reload(pTst);
196 break;
197 }
198
199 case TSTMICROTEST_WP_DISABLE:
200 {
201 tstWPDisable(pTst);
202 break;
203 }
204
205 case TSTMICROTEST_WP_ENABLE:
206 {
207 tstWPEnable(pTst);
208 break;
209 }
210
211 case TSTMICROTEST_PF_R0:
212 {
213 idtInstall(pTst, 0xe);
214 pTst->offEIPAdd = 2;
215 rc = tstPFR0(pTst);
216 break;
217 }
218
219 case TSTMICROTEST_PF_R1:
220 {
221 idtInstall(pTst, 0xe);
222 pTst->offEIPAdd = 2;
223 rc = tstPFR1(pTst);
224 break;
225 }
226
227 case TSTMICROTEST_PF_R2:
228 {
229 idtInstall(pTst, 0xe);
230 pTst->offEIPAdd = 2;
231 rc = tstPFR2(pTst);
232 break;
233 }
234
235 case TSTMICROTEST_PF_R3:
236 {
237 idtInstall(pTst, 0xe);
238 pTst->offEIPAdd = 2;
239 rc = tstPFR3(pTst);
240 break;
241 }
242
243 }
244
245 /*
246 * Compute the results.
247 */
248 if (pTst->u64TSCR0End && pTst->u64TSCR0Start)
249 pRes->cTotalTicks = pTst->u64TSCR0End - pTst->u64TSCR0Start - pTst->u64Overhead;
250 if (pTst->u64TSCRxStart && pTst->u64TSCR0Start)
251 pRes->cToRxFirstTicks = pTst->u64TSCRxStart - pTst->u64TSCR0Start - pTst->u64Overhead;
252 if (pTst->u64TSCR0Enter && pTst->u64TSCRxStart)
253 pRes->cTrapTicks = pTst->u64TSCR0Enter - pTst->u64TSCRxStart - pTst->u64Overhead;
254 if (pTst->u64TSCRxEnd && pTst->u64TSCR0Exit)
255 pRes->cToRxTrapTicks = pTst->u64TSCRxEnd - pTst->u64TSCR0Exit - pTst->u64Overhead;
256 if (pTst->u64TSCR0End && pTst->u64TSCRxEnd)
257 pRes->cToR0Ticks = pTst->u64TSCR0End - pTst->u64TSCRxEnd - pTst->u64Overhead;
258
259 return rc;
260}
261
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