VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMGC/VMMGC.cpp@ 850

Last change on this file since 850 was 847, checked in by vboxsync, 18 years ago

Interrupt masking testcase. (attempt at debugging amd64 issue)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.7 KB
Line 
1/* $Id: VMMGC.cpp 847 2007-02-12 13:46:39Z vboxsync $ */
2/** @file
3 * VMM - Guest Context.
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
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_VMM
27#include <VBox/vmm.h>
28#include "VMMInternal.h"
29#include <VBox/vm.h>
30#include <VBox/sup.h>
31#include <VBox/err.h>
32#include <VBox/log.h>
33#include <iprt/asm.h>
34#include <iprt/assert.h>
35
36
37/*******************************************************************************
38* Global Variables *
39*******************************************************************************/
40/** Default logger instance. */
41extern "C" DECLIMPORT(RTLOGGERGC) g_Logger;
42extern "C" DECLIMPORT(RTLOGGERGC) g_RelLogger;
43
44
45/*******************************************************************************
46* Internal Functions *
47*******************************************************************************/
48static int vmmGCTest(PVM pVM, unsigned uOperation, unsigned uArg);
49
50
51
52/**
53 * The GC entry point.
54 *
55 * @returns VBox status code.
56 * @param pVM The VM to operate on.
57 * @param uOperation Which operation to execute (VMMGCOPERATION).
58 * @param uArg Argument to that operation.
59 */
60VMMGCDECL(int) VMMGCEntry(PVM pVM, unsigned uOperation, unsigned uArg)
61{
62 /* todo */
63 switch (uOperation)
64 {
65 /*
66 * Init GC modules.
67 */
68 case VMMGC_DO_VMMGC_INIT:
69 {
70 Log(("VMMGCEntry: VMMGC_DO_VMMGC_INIT - uArg=%#x\n", uArg));
71 /** @todo validate version. */
72 return VINF_SUCCESS;
73 }
74
75 /*
76 * Testcase which is used to test interrupt forwarding.
77 * It spins for a while with interrupts enabled.
78 */
79 case VMMGC_DO_TESTCASE_HYPER_INTERRUPT:
80 {
81 uint32_t volatile i = 0;
82 ASMIntEnable();
83 while (i < _2G32)
84 i++;
85 ASMIntDisable();
86 return 0;
87 }
88
89 /*
90 * Testcase which simply returns, this is used for
91 * profiling of the switcher.
92 */
93 case VMMGC_DO_TESTCASE_NOP:
94 return 0;
95
96 /*
97 * Delay for ~100us.
98 */
99 case VMMGC_DO_TESTCASE_INTERRUPT_MASKING:
100 {
101 uint64_t u64MaxTicks = (g_pSUPGlobalInfoPage ? g_pSUPGlobalInfoPage->u64CpuHz : _2G) / 10000;
102 uint64_t u64StartTSC = ASMReadTSC();
103 uint64_t u64TicksNow;
104 uint32_t volatile i = 0;
105
106 do
107 {
108 /* waste some time and protect against getting stuck. */
109 for (uint32_t volatile j = 0; j < 1000; j++, i++)
110 if (i > _2G32)
111 return VERR_GENERAL_FAILURE;
112
113 /* check if we're done.*/
114 u64TicksNow = ASMReadTSC() - u64StartTSC;
115 } while (u64TicksNow < u64MaxTicks);
116
117 return VINF_SUCCESS;
118 }
119
120 /*
121 * Trap testcases and unknown operations.
122 */
123 default:
124 if ( uOperation >= VMMGC_DO_TESTCASE_TRAP_FIRST
125 && uOperation < VMMGC_DO_TESTCASE_TRAP_LAST)
126 return vmmGCTest(pVM, uOperation, uArg);
127 return VERR_INVALID_PARAMETER;
128 }
129}
130
131
132/**
133 * Internal GC logger worker: Flush logger.
134 *
135 * @returns VINF_SUCCESS.
136 * @param pLogger The logger instance to flush.
137 * @remark This function must be exported!
138 */
139VMMGCDECL(int) vmmGCLoggerFlush(PRTLOGGERGC pLogger)
140{
141 PVM pVM = &g_VM;
142 NOREF(pLogger);
143 return VMMGCCallHost(pVM, VMMCALLHOST_VMM_LOGGER_FLUSH, 0);
144}
145
146
147/**
148 * Switches from guest context to host context.
149 *
150 * @param pVM The VM handle.
151 * @param rc The status code.
152 */
153VMMGCDECL(void) VMMGCGuestToHost(PVM pVM, int rc)
154{
155 pVM->vmm.s.pfnGCGuestToHost(rc);
156}
157
158
159/**
160 * Calls the ring-3 host code.
161 *
162 * @returns VBox status code of the ring-3 call.
163 * @param pVM The VM handle.
164 * @param enmOperation The operation.
165 * @param uArg The argument to the operation.
166 */
167VMMGCDECL(int) VMMGCCallHost(PVM pVM, VMMCALLHOST enmOperation, uint64_t uArg)
168{
169/** @todo profile this! */
170 pVM->vmm.s.enmCallHostOperation = enmOperation;
171 pVM->vmm.s.u64CallHostArg = uArg;
172 pVM->vmm.s.rcCallHost = VERR_INTERNAL_ERROR;
173 pVM->vmm.s.pfnGCGuestToHost(VINF_VMM_CALL_HOST);
174 return pVM->vmm.s.rcCallHost;
175}
176
177
178/**
179 * Execute the trap testcase.
180 *
181 * There is some common code here, that's why we're collecting them
182 * like this. Odd numbered variation (uArg) are executed with write
183 * protection (WP) enabled.
184 *
185 * @returns VINF_SUCCESS if it was a testcase setup up to continue and did so successfully.
186 * @returns VERR_NOT_IMPLEMENTED if the testcase wasn't implemented.
187 * @returns VERR_GENERAL_FAILURE if the testcase continued when it shouldn't.
188 *
189 * @param pVM The VM handle.
190 * @param uOperation The testcase.
191 * @param uArg The variation. See function description for odd / even details.
192 *
193 * @remark Careful with the trap 08 testcase and WP, it will tripple
194 * fault the box if the TSS, the Trap8 TSS and the fault TSS
195 * GDTE are in pages which are read-only.
196 * See bottom of SELMR3Init().
197 */
198static int vmmGCTest(PVM pVM, unsigned uOperation, unsigned uArg)
199{
200 /*
201 * Set up the testcase.
202 */
203#if 0
204 switch (uOperation)
205 {
206 default:
207 break;
208 }
209#endif
210
211 /*
212 * Enable WP if odd variation.
213 */
214 if (uArg & 1)
215 vmmGCEnableWP();
216
217 /*
218 * Execute the testcase.
219 */
220 int rc = VERR_NOT_IMPLEMENTED;
221 switch (uOperation)
222 {
223 //case VMMGC_DO_TESTCASE_TRAP_0:
224 //case VMMGC_DO_TESTCASE_TRAP_1:
225 //case VMMGC_DO_TESTCASE_TRAP_2:
226
227 case VMMGC_DO_TESTCASE_TRAP_3:
228 {
229 if (uArg <= 1)
230 rc = vmmGCTestTrap3();
231 break;
232 }
233
234 //case VMMGC_DO_TESTCASE_TRAP_4:
235 //case VMMGC_DO_TESTCASE_TRAP_5:
236 //case VMMGC_DO_TESTCASE_TRAP_6:
237 //case VMMGC_DO_TESTCASE_TRAP_7:
238
239 case VMMGC_DO_TESTCASE_TRAP_8:
240 {
241#ifndef DEBUG_bird /** @todo dynamic check that this won't tripple fault... */
242 if (uArg & 1)
243 break;
244#endif
245 if (uArg <= 1)
246 rc = vmmGCTestTrap8();
247 break;
248 }
249
250 //VMMGC_DO_TESTCASE_TRAP_9,
251 //VMMGC_DO_TESTCASE_TRAP_0A,
252 //VMMGC_DO_TESTCASE_TRAP_0B,
253 //VMMGC_DO_TESTCASE_TRAP_0C,
254
255 case VMMGC_DO_TESTCASE_TRAP_0D:
256 {
257 if (uArg <= 1)
258 rc = vmmGCTestTrap0d();
259 break;
260 }
261
262 case VMMGC_DO_TESTCASE_TRAP_0E:
263 {
264 if (uArg <= 1)
265 rc = vmmGCTestTrap0e();
266 break;
267 }
268 }
269
270 /*
271 * Re-enable WP.
272 */
273 if (uArg & 1)
274 vmmGCDisableWP();
275
276 return rc;
277}
278
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