HWSVMR0.h revision 947b87e71c5715ba34af83cac29dd4aaaff8e27a
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/* $Id$ */
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/** @file
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * HWACCM AMD-V - Internal header file.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/*
adbb0da2a65fc315cb37869fd2c6c80c7d8d5b8bvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * available from http://www.virtualbox.org. This file is free software;
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * you can redistribute it and/or modify it under the terms of the GNU
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * General Public License (GPL) as published by the Free Software
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * additional information or have any questions.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#ifndef ___VMMR0_HWSVMR0_h
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#define ___VMMR0_HWSVMR0_h
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#include <VBox/cdefs.h>
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#include <VBox/types.h>
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#include <VBox/em.h>
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#include <VBox/stam.h>
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#include <VBox/dis.h>
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#include <VBox/hwaccm.h>
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#include <VBox/pgm.h>
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#include <VBox/hwacc_svm.h>
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync__BEGIN_DECLS
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/** @defgroup grp_svm_int Internal
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @ingroup grp_svm
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @internal
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @{
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#ifdef IN_RING0
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Enters the AMD-V session
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVM The VM to operate on.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVCpu VPCPU id.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pCpu CPU info struct
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0Enter(PVM pVM, PVMCPU pVCpu, PHWACCM_CPUINFO pCpu);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Leaves the AMD-V session
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVM The VM to operate on.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVCpu VPCPU id.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pCtx CPU context
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0Leave(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Sets up and activates AMD-V on the current CPU
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pCpu CPU info struct
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVM The VM to operate on. (can be NULL after a resume)
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pvPageCpu Pointer to the global cpu page
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pPageCpuPhys Physical address of the global cpu page
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0EnableCpu(PHWACCM_CPUINFO pCpu, PVM pVM, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Deactivates AMD-V on the current CPU
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pCpu CPU info struct
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pvPageCpu Pointer to the global cpu page
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pPageCpuPhys Physical address of the global cpu page
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0DisableCpu(PHWACCM_CPUINFO pCpu, void *pvPageCpu, RTHCPHYS pPageCpuPhys);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Does Ring-0 per VM AMD-V init.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVM The VM to operate on.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0InitVM(PVM pVM);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Does Ring-0 per VM AMD-V termination.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVM The VM to operate on.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0TermVM(PVM pVM);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Sets up AMD-V for the specified VM
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVM The VM to operate on.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0SetupVM(PVM pVM);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Runs guest code in an AMD-V VM.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVM The VM to operate on.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVCpu VPCPU id.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pCtx Guest context
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0RunGuestCode(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Save the host state
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVM The VM to operate on.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVCpu VPCPU id.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0SaveHostState(PVM pVM, PVMCPU pVCpu);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/**
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * Loads the guest state
6ef855ecf2121f708685307839f1262e0db1a024vboxsync *
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @returns VBox status code.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVM The VM to operate on.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pVCpu VPCPU id.
6ef855ecf2121f708685307839f1262e0db1a024vboxsync * @param pCtx Guest context
6ef855ecf2121f708685307839f1262e0db1a024vboxsync */
6ef855ecf2121f708685307839f1262e0db1a024vboxsyncVMMR0DECL(int) SVMR0LoadGuestState(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/** Convert hidden selector attribute word between VMX and SVM formats. */
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#define SVM_HIDSEGATTR_VMX2SVM(a) (a & 0xFF) | ((a & 0xF000) >> 4)
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#define SVM_HIDSEGATTR_SVM2VMX(a) (a & 0xFF) | ((a & 0x0F00) << 4)
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#define SVM_WRITE_SELREG(REG, reg) \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync{ \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync pVMCB->guest.REG.u16Sel = pCtx->reg; \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync pVMCB->guest.REG.u32Limit = pCtx->reg##Hid.u32Limit; \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync pVMCB->guest.REG.u64Base = pCtx->reg##Hid.u64Base; \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync pVMCB->guest.REG.u16Attr = SVM_HIDSEGATTR_VMX2SVM(pCtx->reg##Hid.Attr.u); \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync}
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#define SVM_READ_SELREG(REG, reg) \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync{ \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync pCtx->reg = pVMCB->guest.REG.u16Sel; \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync pCtx->reg##Hid.u32Limit = pVMCB->guest.REG.u32Limit; \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync pCtx->reg##Hid.u64Base = pVMCB->guest.REG.u64Base; \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync pCtx->reg##Hid.Attr.u = SVM_HIDSEGATTR_SVM2VMX(pVMCB->guest.REG.u16Attr); \
6ef855ecf2121f708685307839f1262e0db1a024vboxsync}
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#endif /* IN_RING0 */
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync/** @} */
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync__END_DECLS
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync#endif
6ef855ecf2121f708685307839f1262e0db1a024vboxsync
6ef855ecf2121f708685307839f1262e0db1a024vboxsync