VirtualBox

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

Last change on this file since 28 was 23, checked in by vboxsync, 18 years ago

string.h & stdio.h + header cleanups.

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