VMMGC.cpp revision 45e76334ad1656c268b639ac7a0d62f9ea58ffb5
/* $Id$ */
/** @file
* VMM - Raw-mode Context.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_VMM
#include "VMMInternal.h"
#include <iprt/initterm.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Default logger instance. */
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
/**
* The GC entry point.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param uOperation Which operation to execute (VMMGCOPERATION).
* @param uArg Argument to that operation.
*/
{
/* todo */
switch (uOperation)
{
/*
* Init RC modules.
*/
case VMMGC_DO_VMMGC_INIT:
{
/*
* Validate the svn revision (uArg).
*/
if (uArg != VMMGetSvnRev())
return VERR_VERSION_MISMATCH;
/*
* Initialize the runtime.
* (The program timestamp is found in the elipsis.)
*/
Log(("VMMGCEntry: VMMGC_DO_VMMGC_INIT - uArg=%u (svn revision) u64TS=%RX64; rc=%Rrc\n", uArg, u64TS, rc));
return VINF_SUCCESS;
}
/*
* Testcase which is used to test interrupt forwarding.
* It spins for a while with interrupts enabled.
*/
{
uint32_t volatile i = 0;
ASMIntEnable();
while (i < _2G32)
i++;
return 0;
}
/*
* Testcase which simply returns, this is used for
* profiling of the switcher.
*/
case VMMGC_DO_TESTCASE_NOP:
return 0;
/*
* Testcase executes a privileged instruction to force a world switch. (in both SVM & VMX)
*/
return 0;
/*
* Delay for ~100us.
*/
{
: _2G)
/ 10000;
uint32_t volatile i = 0;
do
{
/* waste some time and protect against getting stuck. */
for (uint32_t volatile j = 0; j < 1000; j++, i++)
if (i > _2G32)
return VERR_GENERAL_FAILURE;
/* check if we're done.*/
} while (u64TicksNow < u64MaxTicks);
return VINF_SUCCESS;
}
/*
* Trap testcases and unknown operations.
*/
default:
return VERR_INVALID_PARAMETER;
}
}
/**
* Internal RC logger worker: Flush logger.
*
* @returns VINF_SUCCESS.
* @param pLogger The logger instance to flush.
* @remark This function must be exported!
*/
{
}
/**
* Disables the GC logger temporarily
*
* @param pVM The VM handle.
*/
{
}
/**
* Enables the GC logger again
*
* @param pVM The VM handle.
*/
{
}
/**
* Switches from guest context to host context.
*
* @param pVM The VM handle.
* @param rc The status code.
*/
{
}
/**
* Calls the ring-3 host code.
*
* @returns VBox status code of the ring-3 call.
* @param pVM The VM handle.
* @param enmOperation The operation.
* @param uArg The argument to the operation.
*/
{
/** @todo profile this! */
}
/**
* Execute the trap testcase.
*
* There is some common code here, that's why we're collecting them
* like this. Odd numbered variation (uArg) are executed with write
* protection (WP) enabled.
*
* @returns VINF_SUCCESS if it was a testcase setup up to continue and did so successfully.
* @returns VERR_NOT_IMPLEMENTED if the testcase wasn't implemented.
* @returns VERR_GENERAL_FAILURE if the testcase continued when it shouldn't.
*
* @param pVM The VM handle.
* @param uOperation The testcase.
* @param uArg The variation. See function description for odd / even details.
*
* @remark Careful with the trap 08 testcase and WP, it will tripple
* fault the box if the TSS, the Trap8 TSS and the fault TSS
* GDTE are in pages which are read-only.
* See bottom of SELMR3Init().
*/
{
/*
* Set up the testcase.
*/
#if 0
switch (uOperation)
{
default:
break;
}
#endif
/*
* Enable WP if odd variation.
*/
if (uArg & 1)
/*
* Execute the testcase.
*/
int rc = VERR_NOT_IMPLEMENTED;
switch (uOperation)
{
//case VMMGC_DO_TESTCASE_TRAP_0:
//case VMMGC_DO_TESTCASE_TRAP_1:
//case VMMGC_DO_TESTCASE_TRAP_2:
case VMMGC_DO_TESTCASE_TRAP_3:
{
if (uArg <= 1)
rc = vmmGCTestTrap3();
break;
}
//case VMMGC_DO_TESTCASE_TRAP_4:
//case VMMGC_DO_TESTCASE_TRAP_5:
//case VMMGC_DO_TESTCASE_TRAP_6:
//case VMMGC_DO_TESTCASE_TRAP_7:
case VMMGC_DO_TESTCASE_TRAP_8:
{
#ifndef DEBUG_bird /** @todo dynamic check that this won't tripple fault... */
if (uArg & 1)
break;
#endif
if (uArg <= 1)
rc = vmmGCTestTrap8();
break;
}
//VMMGC_DO_TESTCASE_TRAP_9,
//VMMGC_DO_TESTCASE_TRAP_0A,
//VMMGC_DO_TESTCASE_TRAP_0B,
//VMMGC_DO_TESTCASE_TRAP_0C,
{
if (uArg <= 1)
rc = vmmGCTestTrap0d();
break;
}
{
if (uArg <= 1)
rc = vmmGCTestTrap0e();
{
/*
* Test the use of a temporary #PF handler.
*/
rc = TRPMGCSetTempHandler(pVM, X86_XCPT_PF, uArg != 4 ? vmmGCTestTmpPFHandler : vmmGCTestTmpPFHandlerCorruptFS);
if (RT_SUCCESS(rc))
{
rc = vmmGCTestTrap0e();
/* in case it didn't fire. */
}
}
break;
}
}
/*
* Re-enable WP.
*/
if (uArg & 1)
return rc;
}
/**
* Temporary #PF trap handler for the #PF test case.
*
* @returns VBox status code (appropriate for GC return).
* In this context RT_SUCCESS means to restart the instruction.
* @param pVM VM handle.
* @param pRegFrame Trap register frame.
*/
{
{
return VINF_SUCCESS;
}
return VERR_INTERNAL_ERROR;
}
/**
* Temporary #PF trap handler for the #PF test case, this one messes up the fs selector.
*
* @returns VBox status code (appropriate for GC return).
* In this context RT_SUCCESS means to restart the instruction.
* @param pVM VM handle.
* @param pRegFrame Trap register frame.
*/
{
return rc;
}