VMMAll.cpp revision e5df2db7934a997e0e390ccb0172bfd96cc10c95
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/* $Id$ */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/** @file
248c89033c87fed7229aa29bbbc4f4698fb13687vboxsync * VMM All Contexts.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*
248c89033c87fed7229aa29bbbc4f4698fb13687vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * available from http://www.virtualbox.org. This file is free software;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * General Public License (GPL) as published by the Free Software
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * additional information or have any questions.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Header Files *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#define LOG_GROUP LOG_GROUP_VMM
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/vmm.h>
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#include "VMMInternal.h"
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#include <VBox/vm.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/param.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/hwaccm.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Gets the bottom of the hypervisor stack - RC Ptr.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * (The returned address is not actually writable, only after it's decremented
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * by a push/ret/whatever does it become writable.)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync *
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @returns bottom of the stack.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * @param pVM The VM handle.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncRTRCPTR VMMGetStackRC(PVM pVM)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync{
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync return (RTRCPTR)pVM->vmm.s.pbEMTStackBottomRC;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync}
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Gets the current virtual CPU ID.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync *
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @returns The CPU ID.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param pVM Pointer to the shared VM handle.
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * @thread EMT
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsyncVMCPUID VMMGetCpuId(PVM pVM)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync{
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync#ifdef IN_RING3
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* Only emulation thread(s) allowed to ask for CPU id */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (!VM_IS_EMT(pVM))
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync return 0;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Only emulation thread(s) allowed to ask for CPU id */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync VM_ASSERT_EMT(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#if defined(IN_RC)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* There is only one CPU if we're in GC. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return 0;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#elif defined(IN_RING3)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VMR3GetVMCPUId(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#else /* IN_RING0 */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync return HWACCMGetVMCPUId(pVM);
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#endif /* IN_RING0 */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync}
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync/**
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * Returns the VMCPU of the current EMT thread.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync *
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @returns The VMCPU pointer.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param pVM The VM to operate on.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsyncPVMCPU VMMGetCpu(PVM pVM)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync{
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#ifdef IN_RING3
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync /* Only emulation thread(s) allowed to ask for CPU id */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync if (!VM_IS_EMT(pVM))
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync return &pVM->aCpus[0];
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#endif
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync /* Only emulation thread(s) allowed to ask for CPU id */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync VM_ASSERT_EMT(pVM);
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#if defined(IN_RC)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* There is only one CPU if we're in GC. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return &pVM->aCpus[0];
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#elif defined(IN_RING3)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return &pVM->aCpus[VMR3GetVMCPUId(pVM)];
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#else /* IN_RING0 */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return &pVM->aCpus[HWACCMGetVMCPUId(pVM)];
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif /* IN_RING0 */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync/**
ffb50166c9adb4ae583b914d405197035cf890advboxsync * Returns the VMCPU of the specified virtual CPU.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
ffb50166c9adb4ae583b914d405197035cf890advboxsync * @returns The VMCPU pointer.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM to operate on.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMDECL(PVMCPU) VMMGetCpuEx(PVM pVM, RTCPUID idCpu)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertReturn(idCpu < pVM->cCPUs, NULL);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return &pVM->aCpus[idCpu];
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Gets the VBOX_SVN_REV.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is just to avoid having to compile a bunch of big files
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * and requires less Makefile mess.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBOX_SVN_REV.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMDECL(uint32_t) VMMGetSvnRev(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VBOX_SVN_REV;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Queries the current switcher
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns active switcher
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM VM handle.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMDECL(VMMSWITCHER) VMMGetSwitcher(PVM pVM)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
248c89033c87fed7229aa29bbbc4f4698fb13687vboxsync return pVM->vmm.s.enmSwitcher;
248c89033c87fed7229aa29bbbc4f4698fb13687vboxsync}
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync