VMMRC.cpp revision 24f999b2de96dbbd04541167293a869ea9851ad1
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * VMM - Raw-mode Context.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Copyright (C) 2006-2012 Oracle Corporation
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * This file is part of VirtualBox Open Source Edition (OSE), as
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * available from http://www.virtualbox.org. This file is free software;
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * you can redistribute it and/or modify it under the terms of the GNU
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * General Public License (GPL) as published by the Free Software
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Foundation, in version 2 as it comes in the "COPYING" file of the
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest/*******************************************************************************
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest* Header Files *
919ca0cd7bf1dee3c8021e1c80bd699c7a386001Andrew Forrest*******************************************************************************/
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest#include <iprt/asm-amd64-x86.h> /* for SUPGetCpuHzFromGIP */
919ca0cd7bf1dee3c8021e1c80bd699c7a386001Andrew Forrest/*******************************************************************************
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest* Global Variables *
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest*******************************************************************************/
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest/** Default logger instance. */
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrestextern "C" DECLIMPORT(RTLOGGERRC) g_RelLogger;
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest/*******************************************************************************
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest* Internal Functions *
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest*******************************************************************************/
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forreststatic int vmmGCTest(PVM pVM, unsigned uOperation, unsigned uArg);
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forreststatic DECLCALLBACK(int) vmmGCTestTmpPFHandler(PVM pVM, PCPUMCTXCORE pRegFrame);
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forreststatic DECLCALLBACK(int) vmmGCTestTmpPFHandlerCorruptFS(PVM pVM, PCPUMCTXCORE pRegFrame);
864e2a74d7dc5e572cd895466611cc57e3523083Andrew ForrestDECLASM(bool) vmmRCSafeMsrRead(uint32_t uMsr, uint64_t *pu64Value);
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * The GC entry point.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * @returns VBox status code.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * @param pVM Pointer to the VM.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * @param uOperation Which operation to execute (VMMGCOPERATION).
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * @param uArg Argument to that operation.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew ForrestVMMRCDECL(int) VMMGCEntry(PVM pVM, unsigned uOperation, unsigned uArg, ...)
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Init RC modules.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Validate the svn revision (uArg) and build type (ellipsis).
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Initialize the runtime.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest Log(("VMMGCEntry: VMMGC_DO_VMMGC_INIT - uArg=%u (svn revision) u64TS=%RX64; rc=%Rrc\n", uArg, u64TS, rc));
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Testcase which is used to test interrupt forwarding.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * It spins for a while with interrupts enabled.
ece5a262d20a50d0abf584d0f7ec73929ede9cfdJaco Jooste uint32_t volatile i = 0;
919ca0cd7bf1dee3c8021e1c80bd699c7a386001Andrew Forrest * Testcase which simply returns, this is used for
919ca0cd7bf1dee3c8021e1c80bd699c7a386001Andrew Forrest * profiling of the switcher.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Testcase executes a privileged instruction to force a world switch. (in both SVM & VMX)
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Delay for ~100us.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest uint64_t u64MaxTicks = (SUPGetCpuHzFromGIP(g_pSUPGlobalInfoPage) != ~(uint64_t)0
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest uint32_t volatile i = 0;
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest /* waste some time and protect against getting stuck. */
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest for (uint32_t volatile j = 0; j < 1000; j++, i++)
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest /* check if we're done.*/
919ca0cd7bf1dee3c8021e1c80bd699c7a386001Andrew Forrest * Trap testcases and unknown operations.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest if ( uOperation >= VMMGC_DO_TESTCASE_TRAP_FIRST
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Internal RC logger worker: Flush logger.
60d290d5a2f0643d86ef3f8eb5d4381022cdfa68Jaco Jooste * @returns VINF_SUCCESS.
60d290d5a2f0643d86ef3f8eb5d4381022cdfa68Jaco Jooste * @param pLogger The logger instance to flush.
60d290d5a2f0643d86ef3f8eb5d4381022cdfa68Jaco Jooste * @remark This function must be exported!
60d290d5a2f0643d86ef3f8eb5d4381022cdfa68Jaco JoosteVMMRCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger)
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest return VMMRZCallRing3NoCpu(pVM, VMMCALLRING3_VMM_LOGGER_FLUSH, 0);
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Flush logger if almost full.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * @param pVM Pointer to the VM.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest && pVM->vmm.s.pRCLoggerRC->offScratch >= (sizeof(pVM->vmm.s.pRCLoggerRC->achScratch)*3/4))
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest return; /* fail quietly. */
f52ca8f9ce43f7765e8c5959e45a667b496526eeAndrew Forrest VMMRZCallRing3NoCpu(pVM, VMMCALLRING3_VMM_LOGGER_FLUSH, 0);
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * Switches from guest context to host context.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * @param pVM Pointer to the VM.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * @param rc The status code.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew ForrestVMMRCDECL(void) VMMGCGuestToHost(PVM pVM, int rc)
60d290d5a2f0643d86ef3f8eb5d4381022cdfa68Jaco Jooste * Calls the ring-0 host code.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest * @param pVM Pointer to the VM.
864e2a74d7dc5e572cd895466611cc57e3523083Andrew Forrest pVM->vmm.s.pfnRCToHost(VINF_VMM_CALL_TRACER);
switch (uOperation)
switch (uOperation)
case VMMGC_DO_TESTCASE_TRAP_3:
case VMMGC_DO_TESTCASE_TRAP_8:
rc = TRPMGCSetTempHandler(pVM, X86_XCPT_PF, uArg != 4 ? vmmGCTestTmpPFHandler : vmmGCTestTmpPFHandlerCorruptFS);
return rc;
return VINF_SUCCESS;
return VINF_SUCCESS;
return VERR_INTERNAL_ERROR;
return rc;