VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstMicroRC.cpp@ 42621

Last change on this file since 42621 was 41965, checked in by vboxsync, 12 years ago

VMM: ran scm. Mostly svn:keywords changes (adding Revision).

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