SUPLibAll.cpp revision b4b911e46c81fcc3d1d4a69194eb9eb24434c8bb
/* $Id$ */
/** @file
* VirtualBox Support Library - All Contexts Code.
*/
/*
* Copyright (C) 2006-2015 Oracle Corporation
*
* 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifdef IN_RC
#endif
#ifdef IN_RING0
#endif
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
# include <iprt/asm-amd64-x86.h>
#endif
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
/**
* The slow case for SUPReadTsc where we need to apply deltas.
*
* Must only be called when deltas are applicable, so please do not call it
* directly.
*
* @returns TSC with delta applied.
* @param pGip Pointer to the GIP.
*
* @remarks May be called with interrupts disabled in ring-0! This is why the
* ring-0 code doesn't attempt to figure the delta.
*
* @internal
*/
{
/*
* Read the TSC and get the corresponding aCPUs index.
*/
#ifdef IN_RING3
{
}
{
/* Storing the IDTR is normally very quick, but we need to loop. */
for (;;)
{
uTsc = ASMReadTSC();
{
break;
}
if (cTries >= 16)
{
break;
}
cTries++;
}
}
else
{
/* Get APIC ID via the slow CPUID instruction, requires looping. */
for (;;)
{
uTsc = ASMReadTSC();
{
break;
}
if (cTries >= 16)
{
break;
}
cTries++;
}
}
/* Ring-0: Use use RTMpCpuId(), no loops. */
else
uTsc = ASMReadTSC();
/* Raw-mode context: We can get the host CPU set index via VMCPU, no loops. */
else
uTsc = ASMReadTSC();
#else
# error "IN_RING3, IN_RC or IN_RING0 must be defined!"
#endif
/*
* If the delta is valid, apply it.
*/
{
# ifdef IN_RING3
/*
* The delta needs calculating, call supdrv to get the TSC.
*/
if (RT_SUCCESS(rc))
return uTsc;
uTsc = ASMReadTSC();
# endif /* IN_RING3 */
}
/*
* This shouldn't happen, especially not in ring-3 and raw-mode context.
* But if it does, return something that's half useful.
*/
AssertMsgFailed(("iGipCpu=%d (%#x) cCpus=%d fGetGipCpu=%#x\n", iGipCpu, iGipCpu, pGip->cCpus, pGip->fGetGipCpu));
return uTsc;
}
/**
* Internal worker for getting the GIP CPU array index for the calling CPU.
*
* @returns Index into SUPGLOBALINFOPAGE::aCPUs or UINT16_MAX.
* @param pGip The GIP.
*/
{
#ifdef IN_RING3
{
/* Storing the IDTR is normally very fast. */
}
{
/* RDTSCP gives us what need need and more. */
}
else
{
/* Get APIC ID via the slow CPUID instruction. */
}
/* Ring-0: Use use RTMpCpuId() (disables cli to avoid host OS assertions about unsafe CPU number usage). */
else
/* Raw-mode context: We can get the host CPU set index via VMCPU. */
else
#else
# error "IN_RING3, IN_RC or IN_RING0 must be defined!"
#endif
return iGipCpu;
}
/**
* Slow path in SUPGetTscDelta, don't call directly.
*
* @returns See SUPGetTscDelta.
* @param pGip The GIP.
* @internal
*/
{
{
return iTscDelta;
}
AssertFailed();
return 0;
}
/**
* Slow path in SUPGetCpuHzFromGip, don't call directly.
*
* @returns See SUPGetCpuHzFromGip.
* @param pGip The GIP.
* @internal
*/
{
AssertFailed();
}
#endif /* RT_ARCH_AMD64 || RT_ARCH_X86 */