VMM.cpp revision 2ea60b08a2ca8ead348840004cac31e558ae9602
/* $Id$ */
/** @file
* VMM - The Virtual Machine Monitor Core.
*/
/*
* 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.
*/
//#define NO_SUPCALLR0VMM
/** @page pg_vmm VMM - The Virtual Machine Monitor
*
* !Revise this! It's already incorrect!
*
* The Virtual Machine Monitor (VMM) is the core of the virtual machine. It
* manages the alternate reality; controlling the virtualization, managing
* resources, tracking CPU state, it's resources and so on...
*
* We will split the VMM into smaller entities:
*
* - Virtual Machine Core Monitor (VMCM), which purpose it is to
* provide ring and world switching, that including routing
* interrupts to the host OS and traps to the appropriate trap
* handlers. It will implement an external interface for
* managing trap handlers.
*
* - CPU Monitor (CM), tracking the state of the CPU (in the alternate
* reality) and implementing external interfaces to read and change
* the state.
*
* - Memory Monitor (MM), which purpose it is to virtualize physical
* pages, segment descriptor tables, interrupt descriptor tables, task
* segments, and keep track of all memory providing external interfaces
* to access content and map pages. (Internally splitt into smaller entities!)
*
* - IO Monitor (IOM), which virtualizes in and out I/O operations. It
* interacts with the MM to implement memory mapped I/O. External
* interfaces for adding and removing I/O ranges are implemented.
*
* - External Interrupt Monitor (EIM), which purpose it is to manage
* interrupts generated by virtual devices. This monitor provides
* an interfaces for raising interrupts which is accessible at any
* time and from all thread.
* <p>
* A subentity of the EIM is the vitual Programmable Interrupt
* Controller Device (VPICD), and perhaps a virtual I/O Advanced
* Programmable Interrupt Controller Device (VAPICD).
*
* - Direct Memory Access Monitor (DMAM), which purpose it is to support
* virtual device using the DMA controller. Interfaces must be as the
* EIM interfaces independent and threadable.
* <p>
* A subentity of the DMAM is a virtual DMA Controller Device (VDMACD).
*
*
* Entities working on a higher level:
*
* - Device Manager (DM), which is a support facility for virtualized
* hardware. This provides generic facilities for efficient device
* virtualization. It will manage device attaching and detaching
* conversing with EIM and IOM.
*
* - Debugger Facility (DBGF) provides the basic features for
* debugging the alternate reality execution.
*
*
*
* @section pg_vmm_s_use_cases Use Cases
*
* @subsection pg_vmm_s_use_case_boot Bootstrap
*
* - Basic Init:
* - Init SUPDRV.
*
* - Init Virtual Machine Instance:
* - Load settings.
* - Check resource requirements (memory, com, stuff).
*
* - Init Host Ring 3 part:
* - Init Core code.
* - Load Pluggable Components.
* - Init Pluggable Components.
*
* - Init Host Ring 0 part:
* - Load Core (core = core components like VMM, RMI, CA, and so on) code.
* - Init Core code.
* - Load Pluggable Component code.
* - Init Pluggable Component code.
*
* - Allocate first chunk of memory and pin it down. This block of memory
* will fit the following pieces:
* - Virtual Machine Instance data. (Config, CPU state, VMM state, ++)
* (This is available from everywhere (at different addresses though)).
* - VMM Guest Context code.
* - Pluggable devices Guest Context code.
* - Page tables (directory and everything) for the VMM Guest
*
* - Setup Guest (Ring 0) part:
* - Setup initial page tables (i.e. directory all the stuff).
* - Load Core Guest Context code.
* - Load Pluggable Devices Guest Context code.
*
*
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_VMM
#include <VBox/pdmqueue.h>
#include "VMMInternal.h"
#include "VMMSwitcher/VMMSwitcher.h"
/** The saved state version. */
#define VMM_SAVED_STATE_VERSION 3
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Array of switcher defininitions.
* The type and index shall match!
*/
{
NULL, /* invalid entry */
#ifndef RT_ARCH_AMD64
NULL, //&vmmR3Switcher32BitToAMD64_Def,
NULL, //&vmmR3SwitcherPAEToAMD64_Def,
# ifdef VBOX_WITH_HYBIRD_32BIT_KERNEL
# else
NULL, //&vmmR3SwitcherAMD64ToPAE_Def,
# endif
NULL //&vmmR3SwitcherAMD64ToAMD64_Def,
#else
NULL, //&vmmR3Switcher32BitTo32Bit_Def,
NULL, //&vmmR3Switcher32BitToPAE_Def,
NULL, //&vmmR3Switcher32BitToAMD64_Def,
NULL, //&vmmR3SwitcherPAETo32Bit_Def,
NULL, //&vmmR3SwitcherPAEToPAE_Def,
NULL, //&vmmR3SwitcherPAEToAMD64_Def,
NULL //&vmmR3SwitcherAMD64ToAMD64_Def,
#endif
};
/**
* Initiates the core code.
*
* are put on linear contiguous backing.
*
* @returns VBox status code.
* @param pVM Pointer to VM structure.
*/
{
/*
* Calc the size.
*/
unsigned cbCoreCode = 0;
{
if (pSwitcher)
{
}
}
/*
* Allocate continguous pages for switchers and deal with
* conflicts in the intermediate mapping of the code.
*/
pVM->vmm.s.pvHCCoreCodeR3 = SUPContAlloc2(pVM->vmm.s.cbCoreCode >> PAGE_SHIFT, &pVM->vmm.s.pvHCCoreCodeR0, &pVM->vmm.s.HCPhysCoreCode);
int rc = VERR_NO_MEMORY;
{
{
/* try more allocations. */
struct
{
void *pvR3;
} aBadTries[128];
unsigned i = 0;
do
{
i++;
pVM->vmm.s.pvHCCoreCodeR3 = SUPContAlloc2(pVM->vmm.s.cbCoreCode >> PAGE_SHIFT, &pVM->vmm.s.pvHCCoreCodeR0, &pVM->vmm.s.HCPhysCoreCode);
break;
} while ( rc == VERR_PGM_INTERMEDIATE_PAGING_CONFLICT
/* cleanup */
if (VBOX_FAILURE(rc))
{
i++;
}
while (i-- > 0)
{
LogRel(("Core code alloc attempt #%d: pvR3=%p pvR0=%p HCPhys=%VHp\n",
}
}
}
if (VBOX_SUCCESS(rc))
{
/*
* copy the code.
*/
{
if (pSwitcher)
}
/*
* Map the code into the GC address space.
*/
rc = MMR3HyperMapHCPhys(pVM, pVM->vmm.s.pvHCCoreCodeR3, pVM->vmm.s.HCPhysCoreCode, cbCoreCode, "Core Code", &GCPtr);
if (VBOX_SUCCESS(rc))
{
LogRel(("CoreCode: R3=%VHv R0=%VHv GC=%VRv Phys=%VHp cb=%#x\n",
pVM->vmm.s.pvHCCoreCodeR3, pVM->vmm.s.pvHCCoreCodeR0, pVM->vmm.s.pvGCCoreCode, pVM->vmm.s.HCPhysCoreCode, pVM->vmm.s.cbCoreCode));
/*
* Finally, PGM probably have selected a switcher already but we need
* to do get the addresses so we'll reselect it.
* This may legally fail so, we're ignoring the rc.
*/
return rc;
}
/* shit */
AssertMsgFailed(("PGMR3Map(,%VRv, %VGp, %#x, 0) failed with rc=%Vrc\n", pVM->vmm.s.pvGCCoreCode, pVM->vmm.s.HCPhysCoreCode, cbCoreCode, rc));
}
else
N_("Failed to allocate %d bytes of contiguous memory for the world switcher code"),
return rc;
}
/**
* Initializes the VMM.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
LogFlow(("VMMR3Init\n"));
/*
* Assert alignment, sizes and order.
*/
("pVM->vmm.padding is too small! vmm.padding %d while vmm.s is %d\n",
/*
* Init basic VM VMM members.
*/
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
pVM->vmm.s.cYieldEveryMillies = 23; /* Value arrived at after experimenting with the grub boot prompt. */
//pVM->vmm.s.cYieldEveryMillies = 8; //debugging
else
AssertMsgRCReturn(rc, ("Configuration error. Failed to query \"YieldEMTInterval\", rc=%Vrc\n", rc), rc);
/* GC switchers are enabled by default. Turned off by HWACCM. */
/*
* Register the saved state data unit.
*/
rc = SSMR3RegisterInternal(pVM, "vmm", 1, VMM_SAVED_STATE_VERSION, VMM_STACK_SIZE + sizeof(RTGCPTR),
if (VBOX_FAILURE(rc))
return rc;
/*
* Register the Ring-0 VM handle with the session for fast ioctl calls.
*/
if (VBOX_FAILURE(rc))
return rc;
/*
* Init core code.
*/
if (VBOX_SUCCESS(rc))
{
/*
* Allocate & init VMM GC stack.
* The stack pages are also used by the VMM R0 when VMMR0CallHost is invoked.
* (The page protection is modifed during R3 init completion.)
*/
#ifdef VBOX_STRICT_VMM_STACK
rc = MMHyperAlloc(pVM, VMM_STACK_SIZE + PAGE_SIZE + PAGE_SIZE, PAGE_SIZE, MM_TAG_VMM, (void **)&pVM->vmm.s.pbHCStack);
#else
#endif
if (VBOX_SUCCESS(rc))
{
/* Set HC and GC stack pointers to top of stack. */
/* Set hypervisor eip. */
/*
* Allocate GC & R0 Logger instances (they are finalized in the relocator).
*/
#ifdef LOG_ENABLED
if (pLogger)
{
if (VBOX_SUCCESS(rc))
{
/*
* Ring-0 logging isn't 100% safe yet (thread id reuse / process exit cleanup), so
* you have to sign up here by adding your defined(DEBUG_<userid>) to the #if.
*
* If you want to log in non-debug modes, you'll have to remember to change SUPDRvShared.c
* to not stub all the log functions.
*
* You might also wish to enable the AssertMsg1/2 overrides in VMMR0.cpp when enabling this.
*/
# if defined(DEBUG_sandervl) || defined(DEBUG_frank)
if (VBOX_SUCCESS(rc))
{
//pVM->vmm.s.pR0Logger->fCreated = false;
}
# endif
}
}
#endif /* LOG_ENABLED */
/*
* Allocate GC Release Logger instances (finalized in the relocator).
*/
if (VBOX_SUCCESS(rc))
{
if (pRelLogger)
{
if (VBOX_SUCCESS(rc))
}
}
#endif /* VBOX_WITH_GC_AND_R0_RELEASE_LOG */
#ifdef VBOX_WITH_NMI
/*
* Allocate mapping for the host APIC.
*/
if (VBOX_SUCCESS(rc))
{
}
#endif
if (VBOX_SUCCESS(rc))
{
if (VBOX_SUCCESS(rc))
{
/*
* Debug info.
*/
/*
* Statistics.
*/
STAM_REG(pVM, &pVM->vmm.s.StatRunGC, STAMTYPE_COUNTER, "/VMM/RunGC", STAMUNIT_OCCURENCES, "Number of context switches.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetNormal, STAMTYPE_COUNTER, "/VMM/GCRet/Normal", STAMUNIT_OCCURENCES, "Number of VINF_SUCCESS returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetInterrupt, STAMTYPE_COUNTER, "/VMM/GCRet/Interrupt", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_INTERRUPT returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetInterruptHyper, STAMTYPE_COUNTER, "/VMM/GCRet/InterruptHyper", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_INTERRUPT_HYPER returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetGuestTrap, STAMTYPE_COUNTER, "/VMM/GCRet/GuestTrap", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_GUEST_TRAP returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetRingSwitch, STAMTYPE_COUNTER, "/VMM/GCRet/RingSwitch", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_RING_SWITCH returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetRingSwitchInt, STAMTYPE_COUNTER, "/VMM/GCRet/RingSwitchInt", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_RING_SWITCH_INT returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetExceptionPrivilege, STAMTYPE_COUNTER, "/VMM/GCRet/ExceptionPrivilege", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_EXCEPTION_PRIVILEGED returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetStaleSelector, STAMTYPE_COUNTER, "/VMM/GCRet/StaleSelector", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_STALE_SELECTOR returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetIRETTrap, STAMTYPE_COUNTER, "/VMM/GCRet/IRETTrap", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_IRET_TRAP returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetEmulate, STAMTYPE_COUNTER, "/VMM/GCRet/Emulate", STAMUNIT_OCCURENCES, "Number of VINF_EM_EXECUTE_INSTRUCTION returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPatchEmulate, STAMTYPE_COUNTER, "/VMM/GCRet/PatchEmulate", STAMUNIT_OCCURENCES, "Number of VINF_PATCH_EMULATE_INSTR returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetIORead, STAMTYPE_COUNTER, "/VMM/GCRet/IORead", STAMUNIT_OCCURENCES, "Number of VINF_IOM_HC_IOPORT_READ returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetIOWrite, STAMTYPE_COUNTER, "/VMM/GCRet/IOWrite", STAMUNIT_OCCURENCES, "Number of VINF_IOM_HC_IOPORT_WRITE returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetMMIORead, STAMTYPE_COUNTER, "/VMM/GCRet/MMIORead", STAMUNIT_OCCURENCES, "Number of VINF_IOM_HC_MMIO_READ returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetMMIOWrite, STAMTYPE_COUNTER, "/VMM/GCRet/MMIOWrite", STAMUNIT_OCCURENCES, "Number of VINF_IOM_HC_MMIO_WRITE returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetMMIOReadWrite, STAMTYPE_COUNTER, "/VMM/GCRet/MMIOReadWrite", STAMUNIT_OCCURENCES, "Number of VINF_IOM_HC_MMIO_READ_WRITE returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetMMIOPatchRead, STAMTYPE_COUNTER, "/VMM/GCRet/MMIOPatchRead", STAMUNIT_OCCURENCES, "Number of VINF_IOM_HC_MMIO_PATCH_READ returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetMMIOPatchWrite, STAMTYPE_COUNTER, "/VMM/GCRet/MMIOPatchWrite", STAMUNIT_OCCURENCES, "Number of VINF_IOM_HC_MMIO_PATCH_WRITE returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetLDTFault, STAMTYPE_COUNTER, "/VMM/GCRet/LDTFault", STAMUNIT_OCCURENCES, "Number of VINF_EM_EXECUTE_INSTRUCTION_GDT_FAULT returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetGDTFault, STAMTYPE_COUNTER, "/VMM/GCRet/GDTFault", STAMUNIT_OCCURENCES, "Number of VINF_EM_EXECUTE_INSTRUCTION_LDT_FAULT returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetIDTFault, STAMTYPE_COUNTER, "/VMM/GCRet/IDTFault", STAMUNIT_OCCURENCES, "Number of VINF_EM_EXECUTE_INSTRUCTION_IDT_FAULT returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetTSSFault, STAMTYPE_COUNTER, "/VMM/GCRet/TSSFault", STAMUNIT_OCCURENCES, "Number of VINF_EM_EXECUTE_INSTRUCTION_TSS_FAULT returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPDFault, STAMTYPE_COUNTER, "/VMM/GCRet/PDFault", STAMUNIT_OCCURENCES, "Number of VINF_EM_EXECUTE_INSTRUCTION_PD_FAULT returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetCSAMTask, STAMTYPE_COUNTER, "/VMM/GCRet/CSAMTask", STAMUNIT_OCCURENCES, "Number of VINF_CSAM_PENDING_ACTION returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetSyncCR3, STAMTYPE_COUNTER, "/VMM/GCRet/SyncCR", STAMUNIT_OCCURENCES, "Number of VINF_PGM_SYNC_CR3 returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetMisc, STAMTYPE_COUNTER, "/VMM/GCRet/Misc", STAMUNIT_OCCURENCES, "Number of misc returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPatchInt3, STAMTYPE_COUNTER, "/VMM/GCRet/PatchInt3", STAMUNIT_OCCURENCES, "Number of VINF_PATM_PATCH_INT3 returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPatchPF, STAMTYPE_COUNTER, "/VMM/GCRet/PatchPF", STAMUNIT_OCCURENCES, "Number of VINF_PATM_PATCH_TRAP_PF returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPatchGP, STAMTYPE_COUNTER, "/VMM/GCRet/PatchGP", STAMUNIT_OCCURENCES, "Number of VINF_PATM_PATCH_TRAP_GP returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPatchIretIRQ, STAMTYPE_COUNTER, "/VMM/GCRet/PatchIret", STAMUNIT_OCCURENCES, "Number of VINF_PATM_PENDING_IRQ_AFTER_IRET returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPageOverflow, STAMTYPE_COUNTER, "/VMM/GCRet/InvlpgOverflow", STAMUNIT_OCCURENCES, "Number of VERR_REM_FLUSHED_PAGES_OVERFLOW returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetRescheduleREM, STAMTYPE_COUNTER, "/VMM/GCRet/ScheduleREM", STAMUNIT_OCCURENCES, "Number of VINF_EM_RESCHEDULE_REM returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetToR3, STAMTYPE_COUNTER, "/VMM/GCRet/ToR3", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_TO_R3 returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetTimerPending, STAMTYPE_COUNTER, "/VMM/GCRet/TimerPending", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_TIMER_PENDING returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetInterruptPending, STAMTYPE_COUNTER, "/VMM/GCRet/InterruptPending", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_INTERRUPT_PENDING returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetCallHost, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/Misc", STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPGMGrowRAM, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/GrowRAM", STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPDMLock, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/PDMLock", STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetLogFlush, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/LogFlush", STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPDMQueueFlush, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/QueueFlush", STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPGMPoolGrow, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/PGMPoolGrow",STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetRemReplay, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/REMReplay", STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetVMSetError, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/VMSetError", STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPGMLock, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/PGMLock", STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetHyperAssertion, STAMTYPE_COUNTER, "/VMM/GCRet/CallHost/HyperAssert", STAMUNIT_OCCURENCES, "Number of VINF_VMM_CALL_HOST returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPATMDuplicateFn, STAMTYPE_COUNTER, "/VMM/GCRet/PATMDuplicateFn", STAMUNIT_OCCURENCES, "Number of VINF_PATM_DUPLICATE_FUNCTION returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPGMChangeMode, STAMTYPE_COUNTER, "/VMM/GCRet/PGMChangeMode", STAMUNIT_OCCURENCES, "Number of VINF_PGM_CHANGE_MODE returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetEmulHlt, STAMTYPE_COUNTER, "/VMM/GCRet/EmulHlt", STAMUNIT_OCCURENCES, "Number of VINF_EM_RAW_EMULATE_INSTR_HLT returns.");
STAM_REG(pVM, &pVM->vmm.s.StatGCRetPendingRequest, STAMTYPE_COUNTER, "/VMM/GCRet/PendingRequest", STAMUNIT_OCCURENCES, "Number of VINF_EM_PENDING_REQUEST returns.");
return VINF_SUCCESS;
}
}
}
/** @todo: Need failure cleanup. */
//more todo in here?
//if (VBOX_SUCCESS(rc))
//{
//}
//int rc2 = vmmR3TermCoreCode(pVM);
//AssertRC(rc2));
}
return rc;
}
/**
* Ring-3 init finalizing.
*
* @returns VBox status code.
* @param pVM The VM handle.
*/
{
#ifdef VBOX_STRICT_VMM_STACK
/*
* Two inaccessible pages at each sides of the stack to catch over/under-flows.
*/
#endif
/*
* Set page attributes to r/w for stack pages.
*/
int rc = PGMMapSetPage(pVM, pVM->vmm.s.pbGCStack, VMM_STACK_SIZE, X86_PTE_P | X86_PTE_A | X86_PTE_D | X86_PTE_RW);
if (VBOX_SUCCESS(rc))
{
/*
* Create the EMT yield timer.
*/
rc = TMR3TimerCreateInternal(pVM, TMCLOCK_REAL, vmmR3YieldEMT, NULL, "EMT Yielder", &pVM->vmm.s.pYieldTimer);
if (VBOX_SUCCESS(rc))
}
#ifdef VBOX_WITH_NMI
/*
* Map the host APIC into GC - This may be host os specific!
*/
if (VBOX_SUCCESS(rc))
#endif
return rc;
}
/**
* Initializes the R0 VMM.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
int rc;
/*
* Initialize the ring-0 logger if we haven't done so yet.
*/
{
if (VBOX_FAILURE(rc))
return rc;
}
/*
* Call Ring-0 entry with init code.
*/
for (;;)
{
#ifdef NO_SUPCALLR0VMM
//rc = VERR_GENERAL_FAILURE;
rc = VINF_SUCCESS;
#else
#endif
if (rc != VINF_VMM_CALL_HOST)
break;
break;
/* Resume R0 */
}
{
if (VBOX_SUCCESS(rc))
}
return rc;
}
/**
* Initializes the GC VMM.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
/* In VMX mode, there's no need to init GC. */
return VINF_SUCCESS;
/*
* Call VMMGCInit():
* -# resolve the address.
* -# setup stackframe and EIP to use the trampoline.
* -# do a generic hypervisor call.
*/
if (VBOX_SUCCESS(rc))
{
#if GC_ARCH_BITS == 32
#else /* 64-bit GC */
#endif
for (;;)
{
#ifdef NO_SUPCALLR0VMM
//rc = VERR_GENERAL_FAILURE;
rc = VINF_SUCCESS;
#else
#endif
#ifdef LOG_ENABLED
if ( pLogger
&& pLogger->offScratch > 0)
#endif
#endif
if (rc != VINF_VMM_CALL_HOST)
break;
break;
}
{
}
}
return rc;
}
/**
* Terminate the VMM bits.
*
* @returns VINF_SUCCESS.
* @param pVM The VM handle.
*/
{
/*
* Call Ring-0 entry with termination code.
*/
int rc;
for (;;)
{
#ifdef NO_SUPCALLR0VMM
//rc = VERR_GENERAL_FAILURE;
rc = VINF_SUCCESS;
#else
#endif
if (rc != VINF_VMM_CALL_HOST)
break;
break;
/* Resume R0 */
}
{
if (VBOX_SUCCESS(rc))
}
#ifdef VBOX_STRICT_VMM_STACK
/*
* Make the two stack guard pages present again.
*/
#endif
return rc;
}
/**
* Applies relocations to data and code managed by this
* component. This function will be called at init and
* whenever the VMM need to relocate it self inside the GC.
*
* The VMM will need to apply relocations to the core code.
*
* @param pVM The VM handle.
* @param offDelta The relocation delta.
*/
{
/*
* Recalc the GC address.
*/
/*
* The stack.
*/
/*
* All the switchers.
*/
{
{
}
}
/*
* Recalc the GC address for the current switcher.
*/
/*
* Get other GC entry points.
*/
int rc = PDMR3GetSymbolGC(pVM, VMMGC_MAIN_MODULE_NAME, "CPUMGCResumeGuest", &pVM->vmm.s.pfnCPUMGCResumeGuest);
rc = PDMR3GetSymbolGC(pVM, VMMGC_MAIN_MODULE_NAME, "CPUMGCResumeGuestV86", &pVM->vmm.s.pfnCPUMGCResumeGuestV86);
/*
* Update the logger.
*/
}
/**
* Updates the settings for the GC and R0 loggers.
*
* @returns VBox status code.
* @param pVM The VM handle.
*/
{
/*
* Simply clone the logger instance (for GC).
*/
int rc = VINF_SUCCESS;
#endif
)
{
}
{
}
{
}
#endif /* VBOX_WITH_GC_AND_R0_RELEASE_LOG */
/*
* For the ring-0 EMT logger, we use a per-thread logger
* instance in ring-0. Only initialize it once.
*/
if (pR0Logger)
{
{
}
}
return rc;
}
/**
* Generic switch code relocator.
*
* @param pVM The VM handle.
* @param pSwitcher The switcher definition.
* @param pu8CodeR3 Pointer to the core code block for the switcher, ring-3 mapping.
* @param pu8CodeR0 Pointer to the core code block for the switcher, ring-0 mapping.
* @param GCPtrCode The guest context address corresponding to pu8Code.
* @param u32IDCode The identity mapped (ID) address corresponding to pu8Code.
* @param SelCS The hypervisor CS selector.
* @param SelDS The hypervisor DS selector.
* @param SelTSS The hypervisor TSS selector.
* @param GCPtrGDT The GC address of the hypervisor GDT.
* @param SelCS64 The 64-bit mode hypervisor CS selector.
*/
static void vmmR3SwitcherGenericRelocate(PVM pVM, PVMMSWITCHERDEF pSwitcher, uint8_t *pu8CodeR0, uint8_t *pu8CodeR3, RTGCPTR GCPtrCode, uint32_t u32IDCode,
{
union
{
const void *pv;
uintptr_t u;
} u;
/*
* Process fixups.
*/
{
/*
* Get the source (where to write the fixup).
*/
union
{
uintptr_t u;
} uSrc;
/* The fixup target and method depends on the type. */
switch (u8)
{
/*
* 32-bit relative, source in HC and target in GC.
*/
case FIX_HC_2_GC_NEAR_REL:
{
Assert(offSrc - pSwitcher->offHCCode0 < pSwitcher->cbHCCode0 || offSrc - pSwitcher->offHCCode1 < pSwitcher->cbHCCode1);
break;
}
/*
* 32-bit relative, source in HC and target in ID.
*/
case FIX_HC_2_ID_NEAR_REL:
{
Assert(offSrc - pSwitcher->offHCCode0 < pSwitcher->cbHCCode0 || offSrc - pSwitcher->offHCCode1 < pSwitcher->cbHCCode1);
Assert(offTrg - pSwitcher->offIDCode0 < pSwitcher->cbIDCode0 || offTrg - pSwitcher->offIDCode1 < pSwitcher->cbIDCode1);
break;
}
/*
* 32-bit relative, source in GC and target in HC.
*/
case FIX_GC_2_HC_NEAR_REL:
{
Assert(offTrg - pSwitcher->offHCCode0 < pSwitcher->cbHCCode0 || offTrg - pSwitcher->offHCCode1 < pSwitcher->cbHCCode1);
break;
}
/*
* 32-bit relative, source in GC and target in ID.
*/
case FIX_GC_2_ID_NEAR_REL:
{
Assert(offTrg - pSwitcher->offIDCode0 < pSwitcher->cbIDCode0 || offTrg - pSwitcher->offIDCode1 < pSwitcher->cbIDCode1);
break;
}
/*
* 32-bit relative, source in ID and target in HC.
*/
case FIX_ID_2_HC_NEAR_REL:
{
Assert(offSrc - pSwitcher->offIDCode0 < pSwitcher->cbIDCode0 || offSrc - pSwitcher->offIDCode1 < pSwitcher->cbIDCode1);
Assert(offTrg - pSwitcher->offHCCode0 < pSwitcher->cbHCCode0 || offTrg - pSwitcher->offHCCode1 < pSwitcher->cbHCCode1);
break;
}
/*
* 32-bit relative, source in ID and target in HC.
*/
case FIX_ID_2_GC_NEAR_REL:
{
Assert(offSrc - pSwitcher->offIDCode0 < pSwitcher->cbIDCode0 || offSrc - pSwitcher->offIDCode1 < pSwitcher->cbIDCode1);
break;
}
/*
* 16:32 far jump, target in GC.
*/
case FIX_GC_FAR32:
{
break;
}
/*
* Make 32-bit GC pointer given CPUM offset.
*/
case FIX_GC_CPUM_OFF:
{
break;
}
/*
* Make 32-bit GC pointer given VM offset.
*/
case FIX_GC_VM_OFF:
{
break;
}
/*
* Make 32-bit HC pointer given CPUM offset.
*/
case FIX_HC_CPUM_OFF:
{
break;
}
/*
* Make 32-bit R0 pointer given VM offset.
*/
case FIX_HC_VM_OFF:
{
break;
}
/*
* Store the 32-Bit CR3 (32-bit) for the intermediate memory context.
*/
case FIX_INTER_32BIT_CR3:
{
break;
}
/*
* Store the PAE CR3 (32-bit) for the intermediate memory context.
*/
case FIX_INTER_PAE_CR3:
{
break;
}
/*
* Store the AMD64 CR3 (32-bit) for the intermediate memory context.
*/
case FIX_INTER_AMD64_CR3:
{
break;
}
/*
* Store the 32-Bit CR3 (32-bit) for the hypervisor (shadow) memory context.
*/
case FIX_HYPER_32BIT_CR3:
{
break;
}
/*
* Store the PAE CR3 (32-bit) for the hypervisor (shadow) memory context.
*/
case FIX_HYPER_PAE_CR3:
{
break;
}
/*
* Store the AMD64 CR3 (32-bit) for the hypervisor (shadow) memory context.
*/
case FIX_HYPER_AMD64_CR3:
{
break;
}
/*
* Store Hypervisor CS (16-bit).
*/
case FIX_HYPER_CS:
{
break;
}
/*
* Store Hypervisor DS (16-bit).
*/
case FIX_HYPER_DS:
{
break;
}
/*
* Store Hypervisor TSS (16-bit).
*/
case FIX_HYPER_TSS:
{
break;
}
/*
* Store the 32-bit GC address of the 2nd dword of the TSS descriptor (in the GDT).
*/
case FIX_GC_TSS_GDTE_DW2:
{
break;
}
///@todo case FIX_CR4_MASK:
///@todo case FIX_CR4_OSFSXR:
/*
*/
case FIX_NO_FXSAVE_JMP:
{
if (!CPUMSupportsFXSR(pVM))
{
}
else
{
}
break;
}
/*
* Insert relative jump to specified target it SYSENTER isn't used by the host.
*/
case FIX_NO_SYSENTER_JMP:
{
if (!CPUMIsHostUsingSysEnter(pVM))
{
}
else
{
}
break;
}
/*
* Insert relative jump to specified target it SYSENTER isn't used by the host.
*/
case FIX_NO_SYSCALL_JMP:
{
if (!CPUMIsHostUsingSysEnter(pVM))
{
}
else
{
}
break;
}
/*
* 32-bit HC pointer fixup to (HC) target within the code (32-bit offset).
*/
case FIX_HC_32BIT:
{
Assert(offTrg - pSwitcher->offHCCode0 < pSwitcher->cbHCCode0 || offTrg - pSwitcher->offHCCode1 < pSwitcher->cbHCCode1);
break;
}
#if defined(RT_ARCH_AMD64) || defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
/*
* 64-bit HC pointer fixup to (HC) target within the code (32-bit offset).
*/
case FIX_HC_64BIT:
{
Assert(offTrg - pSwitcher->offHCCode0 < pSwitcher->cbHCCode0 || offTrg - pSwitcher->offHCCode1 < pSwitcher->cbHCCode1);
break;
}
/*
* 64-bit HC Code Selector (no argument).
*/
case FIX_HC_64BIT_CS:
{
#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_HYBIRD_32BIT_KERNEL)
#else
AssertFatalMsgFailed(("FIX_HC_64BIT_CS not implemented for this host\n"));
#endif
break;
}
/*
* 64-bit HC pointer to the CPUM instance data (no argument).
*/
case FIX_HC_64BIT_CPUM:
{
break;
}
#endif
/*
* 32-bit ID pointer to (ID) target within the code (32-bit offset).
*/
case FIX_ID_32BIT:
{
Assert(offTrg - pSwitcher->offIDCode0 < pSwitcher->cbIDCode0 || offTrg - pSwitcher->offIDCode1 < pSwitcher->cbIDCode1);
break;
}
/*
* 64-bit ID pointer to (ID) target within the code (32-bit offset).
*/
case FIX_ID_64BIT:
{
Assert(offTrg - pSwitcher->offIDCode0 < pSwitcher->cbIDCode0 || offTrg - pSwitcher->offIDCode1 < pSwitcher->cbIDCode1);
break;
}
/*
* Far 16:32 ID pointer to 64-bit mode (ID) target within the code (32-bit offset).
*/
{
Assert(offTrg - pSwitcher->offIDCode0 < pSwitcher->cbIDCode0 || offTrg - pSwitcher->offIDCode1 < pSwitcher->cbIDCode1);
break;
}
#ifdef VBOX_WITH_NMI
/*
* 32-bit address to the APIC base.
*/
case FIX_GC_APIC_BASE_32BIT:
{
break;
}
#endif
default:
break;
}
}
#ifdef LOG_ENABLED
/*
* If Log2 is enabled disassemble the switcher code.
*
* The switcher code have 1-2 HC parts, 1 GC part and 0-2 ID parts.
*/
if (LogIs2Enabled())
{
RTLogPrintf("*** Disassembly of switcher %d '%s' %#x bytes ***\n"
" pu8CodeR0 = %p\n"
" pu8CodeR3 = %p\n"
" GCPtrCode = %VGv\n"
" u32IDCode = %08x\n"
" pVMGC = %VGv\n"
" pCPUMGC = %VGv\n"
" pVMHC = %p\n"
" pCPUMHC = %p\n"
" GCPtrGDT = %VGv\n"
" InterCR3s = %08x, %08x, %08x (32-Bit, PAE, AMD64)\n"
" HyperCR3s = %08x, %08x, %08x (32-Bit, PAE, AMD64)\n"
" SelCS = %04x\n"
" SelDS = %04x\n"
" SelCS64 = %04x\n"
" SelTSS = %04x\n",
{
/*
* Figure out where this is.
*/
{
pszDesc = "HCCode0";
}
{
pszDesc = "HCCode1";
}
{
pszDesc = "GCCode";
}
{
pszDesc = "IDCode0";
}
{
pszDesc = "IDCode1";
}
else
{
RTLogPrintf(" %04x: %02x '%c' (nowhere)\n",
offCode++;
continue;
}
/*
* Disassemble it.
*/
while (cbCode > 0)
{
/* try label it */
RTLogPrintf(" *R0HostToGuest:\n");
RTLogPrintf(" *GCGuestToHost:\n");
RTLogPrintf(" *GCCallTrampoline:\n");
RTLogPrintf(" *GCGuestToHostAsm:\n");
RTLogPrintf(" *GCGuestToHostAsmHyperCtx:\n");
RTLogPrintf(" *GCGuestToHostAsmGuestCtx:\n");
/* disas */
char szDisas[256];
if (RT_SUCCESS(DISInstr(&Cpu, (RTUINTPTR)pu8CodeR3 + offCode, uBase - (RTUINTPTR)pu8CodeR3, &cbInstr, szDisas)))
else
{
RTLogPrintf(" %04x: %02x '%c'\n",
cbInstr = 1;
}
}
}
}
#endif
}
/**
* Relocator for the 32-Bit to 32-Bit world switcher.
*/
DECLCALLBACK(void) vmmR3Switcher32BitTo32Bit_Relocate(PVM pVM, PVMMSWITCHERDEF pSwitcher, uint8_t *pu8CodeR0, uint8_t *pu8CodeR3, RTGCPTR GCPtrCode, uint32_t u32IDCode)
{
}
/**
* Relocator for the 32-Bit to PAE world switcher.
*/
DECLCALLBACK(void) vmmR3Switcher32BitToPAE_Relocate(PVM pVM, PVMMSWITCHERDEF pSwitcher, uint8_t *pu8CodeR0, uint8_t *pu8CodeR3, RTGCPTR GCPtrCode, uint32_t u32IDCode)
{
}
/**
* Relocator for the PAE to 32-Bit world switcher.
*/
DECLCALLBACK(void) vmmR3SwitcherPAETo32Bit_Relocate(PVM pVM, PVMMSWITCHERDEF pSwitcher, uint8_t *pu8CodeR0, uint8_t *pu8CodeR3, RTGCPTR GCPtrCode, uint32_t u32IDCode)
{
}
/**
* Relocator for the PAE to PAE world switcher.
*/
DECLCALLBACK(void) vmmR3SwitcherPAEToPAE_Relocate(PVM pVM, PVMMSWITCHERDEF pSwitcher, uint8_t *pu8CodeR0, uint8_t *pu8CodeR3, RTGCPTR GCPtrCode, uint32_t u32IDCode)
{
}
/**
* Relocator for the AMD64 to PAE world switcher.
*/
DECLCALLBACK(void) vmmR3SwitcherAMD64ToPAE_Relocate(PVM pVM, PVMMSWITCHERDEF pSwitcher, uint8_t *pu8CodeR0, uint8_t *pu8CodeR3, RTGCPTR GCPtrCode, uint32_t u32IDCode)
{
SELMGetHyperCS(pVM), SELMGetHyperDS(pVM), SELMGetHyperTSS(pVM), SELMGetHyperGDT(pVM), SELMGetHyperCS64(pVM));
}
/**
* Gets the pointer to g_szRTAssertMsg1 in GC.
* @returns Pointer to VMMGC::g_szRTAssertMsg1.
* Returns NULL if not present.
* @param pVM The VM handle.
*/
{
if (VBOX_SUCCESS(rc))
return NULL;
}
/**
* Gets the pointer to g_szRTAssertMsg2 in GC.
* @returns Pointer to VMMGC::g_szRTAssertMsg2.
* Returns NULL if not present.
* @param pVM The VM handle.
*/
{
if (VBOX_SUCCESS(rc))
return NULL;
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
{
LogFlow(("vmmR3Save:\n"));
/*
* The hypervisor stack.
*/
}
/**
* Execute state load operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
* @param u32Version Data layout version.
*/
{
LogFlow(("vmmR3Load:\n"));
/*
* Validate version.
*/
if (u32Version != VMM_SAVED_STATE_VERSION)
{
}
/*
* Check that the stack is in the same place, or that it's fearly empty.
*/
if (VBOX_FAILURE(rc))
return rc;
|| (GCPtrStackBottom - GCPtrESP < 32)) /** @todo This will break if we start preemting the hypervisor. */
{
/*
* We *must* set the ESP because the CPUM load + PGM load relocations will render
* the ESP in CPUM fatally invalid.
*/
/* restore the stack. */
/* terminator */
if (VBOX_FAILURE(rc))
return rc;
if (u32 != ~0U)
{
}
return VINF_SUCCESS;
}
LogRel(("The stack is not in the same place and it's not empty! GCPtrStackBottom=%VGv pbGCStackBottom=%VGv ESP=%VGv\n",
return VINF_SUCCESS; /* ignore this */
AssertFailed();
return VERR_SSM_LOAD_CONFIG_MISMATCH;
}
/**
* Selects the switcher to be used for switching to GC.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param enmSwitcher The new switcher.
* @remark This function may be called before the VMM is initialized.
*/
{
/*
* Validate input.
*/
if ( enmSwitcher < VMMSWITCHER_INVALID
|| enmSwitcher >= VMMSWITCHER_MAX)
{
return VERR_INVALID_PARAMETER;
}
/* Do nothing if the switcher is disabled. */
return VINF_SUCCESS;
/*
* Select the new switcher.
*/
if (pSwitcher)
{
Log(("VMMR3SelectSwitcher: enmSwitcher %d -> %d %s\n", pVM->vmm.s.enmSwitcher, enmSwitcher, pSwitcher->pszDesc));
RTR0PTR pbCodeR0 = (RTR0PTR)pVM->vmm.s.pvHCCoreCodeR0 + pVM->vmm.s.aoffSwitchers[enmSwitcher]; /** @todo fix the pvHCCoreCodeR0 type */
return VINF_SUCCESS;
}
return VERR_NOT_IMPLEMENTED;
}
/**
* Disable the switcher logic permanently.
*
* @returns VBox status code.
* @param pVM VM handle.
*/
{
/** @todo r=bird: I would suggest that we create a dummy switcher which just does something like:
* @code
* mov eax, VERR_INTERNAL_ERROR
* ret
* @endcode
* And then check for fSwitcherDisabled in VMMR3SelectSwitcher() in order to prevent it from being removed.
*/
return VINF_SUCCESS;
}
/**
* Resolve a builtin GC symbol.
* Called by PDM when loading or relocating GC modules.
*
* @returns VBox status
* @param pVM VM Handle.
* @param pszSymbol Symbol to resolv
* @param pGCPtrValue Where to store the symbol value.
* @remark This has to work before VMMR3Relocate() is called.
*/
{
{
}
{
#else
#endif
}
else
return VERR_SYMBOL_NOT_FOUND;
return VINF_SUCCESS;
}
/**
* Suspends the the CPU yielder.
*
* @param pVM The VM handle.
*/
{
{
else
}
}
/**
* Stops the the CPU yielder.
*
* @param pVM The VM handle.
*/
{
}
/**
* Resumes the CPU yielder when it has been a suspended or stopped.
*
* @param pVM The VM handle.
*/
{
{
}
}
/**
* Internal timer callback function.
*
* @param pVM The VM.
* @param pTimer The timer handle.
* @param pvUser User argument specified upon timer creation.
*/
{
/*
* This really needs some careful tuning. While we shouldn't be too gready since
* that'll cause the rest of the system to stop up, we shouldn't be too nice either
* because that'll cause us to stop up.
*
* The current logic is to use the default interval when there is no lag worth
* mentioning, but when we start accumulating lag we don't bother yielding at all.
*
* (This depends on the TMCLOCK_VIRTUAL_SYNC to be scheduled before TMCLOCK_REAL
* so the lag is up to date.)
*/
)
{
#ifdef LOG_ENABLED
#endif
}
}
/**
* Acquire global VM lock.
*
* @returns VBox status code
* @param pVM The VM to operate on.
*/
{
}
/**
* Release global VM lock.
*
* @returns VBox status code
* @param pVM The VM to operate on.
*/
{
}
/**
* Return global VM lock owner.
*
* @returns Thread id of owner.
* @returns NIL_RTTHREAD if no owner.
* @param pVM The VM to operate on.
*/
{
}
/**
* Checks if the current thread is the owner of the global VM lock.
*
* @returns true if owner.
* @returns false if not owner.
* @param pVM The VM to operate on.
*/
{
}
/**
* Executes guest code.
*
* @param pVM VM handle.
*/
{
/*
* Set the EIP and ESP.
*/
/*
* We hide log flushes (outer) and hypervisor interrupts (inner).
*/
for (;;)
{
int rc;
do
{
#ifdef NO_SUPCALLR0VMM
#else
#endif
} while (rc == VINF_EM_RAW_INTERRUPT_HYPER);
/*
* Flush the logs.
*/
#ifdef LOG_ENABLED
if ( pLogger
&& pLogger->offScratch > 0)
#endif
#endif
if (rc != VINF_VMM_CALL_HOST)
{
Log2(("VMMR3RawRunGC: returns %Vrc (cs:eip=%04x:%08x)\n", rc, CPUMGetGuestCS(pVM), CPUMGetGuestEIP(pVM)));
return rc;
}
if (VBOX_FAILURE(rc))
return rc;
/* Resume GC */
}
}
/**
* Executes guest code (Intel VT-x and AMD-V).
*
* @param pVM VM handle.
*/
{
for (;;)
{
int rc;
do
{
#ifdef NO_SUPCALLR0VMM
#else
#endif
} while (rc == VINF_EM_RAW_INTERRUPT_HYPER);
#ifdef LOG_ENABLED
/*
* Flush the log
*/
if ( pR0Logger
#endif /* !LOG_ENABLED */
if (rc != VINF_VMM_CALL_HOST)
{
Log2(("VMMR3HwAccRunGC: returns %Vrc (cs:eip=%04x:%08x)\n", rc, CPUMGetGuestCS(pVM), CPUMGetGuestEIP(pVM)));
return rc;
}
return rc;
/* Resume R0 */
}
}
/**
* Calls GC a function.
*
* @param pVM The VM handle.
* @param GCPtrEntry The GC function address.
* @param cArgs The number of arguments in the ....
* @param ... Arguments to the function.
*/
{
return rc;
}
/**
* Calls GC a function.
*
* @param pVM The VM handle.
* @param GCPtrEntry The GC function address.
* @param cArgs The number of arguments in the ....
* @param args Arguments to the function.
*/
{
/*
* Setup the call frame using the trampoline.
*/
int i = cArgs;
while (i-- > 0)
/*
* We hide log flushes (outer) and hypervisor interrupts (inner).
*/
for (;;)
{
int rc;
do
{
#ifdef NO_SUPCALLR0VMM
#else
#endif
} while (rc == VINF_EM_RAW_INTERRUPT_HYPER);
/*
* Flush the logs.
*/
#ifdef LOG_ENABLED
if ( pLogger
&& pLogger->offScratch > 0)
#endif
#endif
if (rc != VINF_VMM_CALL_HOST)
{
Log2(("VMMR3CallGCV: returns %Vrc (cs:eip=%04x:%08x)\n", rc, CPUMGetGuestCS(pVM), CPUMGetGuestEIP(pVM)));
return rc;
}
if (VBOX_FAILURE(rc))
return rc;
}
}
/**
* Resumes executing hypervisor code when interrupted
* by a queue flush or a debug event.
*
* @returns VBox status code.
* @param pVM VM handle.
*/
{
/*
* We hide log flushes (outer) and hypervisor interrupts (inner).
*/
for (;;)
{
int rc;
do
{
#ifdef NO_SUPCALLR0VMM
#else
#endif
} while (rc == VINF_EM_RAW_INTERRUPT_HYPER);
/*
* Flush the loggers,
*/
#ifdef LOG_ENABLED
if ( pLogger
&& pLogger->offScratch > 0)
#endif
#endif
if (rc != VINF_VMM_CALL_HOST)
{
return rc;
}
if (VBOX_FAILURE(rc))
return rc;
}
}
/**
* Service a call to the ring-3 host code.
*
* @returns VBox status code.
* @param pVM VM handle.
* @remark Careful with critsects.
*/
{
{
/*
* Acquire the PDM lock.
*/
case VMMCALLHOST_PDM_LOCK:
{
break;
}
/*
* Flush a PDM queue.
*/
{
break;
}
/*
* Grow the PGM pool.
*/
{
break;
}
/*
* Maps an page allocation chunk into ring-3 so ring-0 can use it.
*/
{
break;
}
/*
* Allocates more handy pages.
*/
{
break;
}
#ifndef VBOX_WITH_NEW_PHYS_CODE
{
break;
}
#endif
/*
* Acquire the PGM lock.
*/
case VMMCALLHOST_PGM_LOCK:
{
break;
}
/*
* Flush REM handler notifications.
*/
{
break;
}
/*
* This is a noop. We just take this route to avoid unnecessary
* tests in the loops.
*/
break;
/*
* Set the VM error message.
*/
case VMMCALLHOST_VM_SET_ERROR:
break;
/*
* Set the VM runtime error message.
*/
break;
/*
* Signal a ring 0 hypervisor assertion.
* Cancel the longjmp operation that's in progress.
*/
#ifdef RT_ARCH_X86
#else
#endif
return VINF_EM_DBG_HYPER_ASSERTION;
default:
return VERR_INTERNAL_ERROR;
}
return VINF_SUCCESS;
}
/**
* Structure to pass to DBGFR3Info() and for doing all other
* output during fatal dump.
*/
typedef struct VMMR3FATALDUMPINFOHLP
{
/** The helper core. */
/** The release logger instance. */
/** The saved release logger flags. */
/** The logger instance. */
/** The saved logger flags. */
/** The saved logger destination flags. */
/** Whether to output to stderr or not. */
bool fStdErr;
typedef const VMMR3FATALDUMPINFOHLP *PCVMMR3FATALDUMPINFOHLP;
/**
* Print formatted string.
*
* @param pHlp Pointer to this structure.
* @param pszFormat The format string.
* @param ... Arguments.
*/
static DECLCALLBACK(void) vmmR3FatalDumpInfoHlp_pfnPrintf(PCDBGFINFOHLP pHlp, const char *pszFormat, ...)
{
}
/**
* Print formatted string.
*
* @param pHlp Pointer to this structure.
* @param pszFormat The format string.
* @param args Argument list.
*/
static DECLCALLBACK(void) vmmR3FatalDumpInfoHlp_pfnPrintfV(PCDBGFINFOHLP pHlp, const char *pszFormat, va_list args)
{
if (pMyHlp->pRelLogger)
{
}
{
}
{
}
}
/**
* Initializes the fatal dump output helper.
*
* @param pHlp The structure to initialize.
*/
{
/*
* The loggers.
*/
#ifndef LOG_ENABLED
if (!pHlp->pRelLogger)
#endif
if (pHlp->pRelLogger)
{
}
{
#ifndef DEBUG_sandervl
#endif
}
/*
* Check if we need write to stderr.
*/
#ifdef DEBUG_sandervl
#else
pHlp->fStdErr = (!pHlp->pRelLogger || !(pHlp->pRelLogger->fDestFlags & (RTLOGDEST_STDOUT | RTLOGDEST_STDERR)))
#endif
}
/**
* Deletes the fatal dump output helper.
*
* @param pHlp The structure to delete.
*/
{
if (pHlp->pRelLogger)
{
}
{
}
}
/**
* Dumps the VM state on a fatal error.
*
* @param pVM VM Handle.
* @param rcErr VBox status code.
*/
{
/*
* Create our output helper and sync it with the log settings.
* This helper will be used for all the output.
*/
/*
* Header.
*/
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
"!!\n"
"!! Guru Meditation %d (%Vrc)\n"
"!!\n",
/*
* Continue according to context.
*/
bool fDoneHyper = false;
switch (rcErr)
{
/*
* Hyper visor errors.
*/
/* fall thru */
case VERR_TRPM_DONT_PANIC:
case VERR_TRPM_PANIC:
case VINF_EM_RAW_IRET_TRAP:
{
/* Trap? */
if (VBOX_SUCCESS(rc2))
"!! TRAP=%02x ERRCD=%VGv CR2=%VGv EIP=%VGv Type=%d\n",
else
"!! EIP=%VGv NOTRAP\n",
uEIP);
/*
* Try figure out where eip is.
*/
/** @todo make query call for core code or move this function to VMM. */
/* core code? */
// pHlp->pfnPrintf(pHlp,
// "!! EIP is in CoreCode, offset %#x\n",
// uEIP - (RTGCUINTPTR)pVM->vmm.s.pvGCCoreCode);
//else
{ /* ask PDM */
/** @todo ask DBGFR3Sym later. */
char szModName[64];
char szNearSym1[260];
char szNearSym2[260];
if (VBOX_SUCCESS(rc))
{
"!! EIP in %s (%VGv) at rva %x near symbols:\n"
"!! %VGv rva %VGv off %08x %s\n"
"!! %VGv rva %VGv off -%08x %s\n",
}
else
"!! EIP is not in any code known to VMM!\n");
}
/* Disassemble the instruction. */
char szInstr[256];
rc2 = DBGFR3DisasInstrEx(pVM, 0, 0, DBGF_DISAS_FLAGS_CURRENT_HYPER, &szInstr[0], sizeof(szInstr), NULL);
if (VBOX_SUCCESS(rc2))
"!! %s\n", szInstr);
/* Dump the hypervisor cpu state. */
"!!\n"
"!!\n"
"!!\n");
fDoneHyper = true;
/* Callstack. */
DBGFSTACKFRAME Frame = {0};
if (VBOX_SUCCESS(rc2))
{
"!!\n"
"!! Call Stack:\n"
"!!\n"
"EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP Symbol [line]\n");
do
{
"%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
{
if (offDisp > 0)
else if (offDisp < 0)
else
}
/* next */
} while (VBOX_SUCCESS(rc2));
}
/* raw stack */
"!!\n"
"!! Raw stack (mind the direction).\n"
"!!\n"
"%.*Vhxd\n",
break;
}
default:
{
break;
}
} /* switch (rcErr) */
/*
* Generic info dumper loop.
*/
static struct
{
const char *pszInfo;
const char *pszArgs;
} const aInfo[] =
{
{ "mappings", NULL },
{ "hma", NULL },
{ "cpumguest", "verbose" },
{ "cpumguestinstr", "verbose" },
{ "cpumhyper", "verbose" },
{ "cpumhost", "verbose" },
{ "mode", "all" },
{ "cpuid", "verbose" },
{ "gdt", NULL },
{ "ldt", NULL },
//{ "tss", NULL },
{ "ioport", NULL },
{ "mmio", NULL },
{ "phys", NULL },
//{ "pgmpd", NULL }, - doesn't always work at init time...
{ "timers", NULL },
{ "activetimers", NULL },
{ "handlers", "phys virt hyper stats" },
{ "cfgm", NULL },
};
{
continue;
"!!\n"
"!! {%s, %s}\n"
"!!\n",
}
/* done */
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
/*
* Delete the output instance (flushing and restoring of flags).
*/
}
/**
* Displays the Force action Flags.
*
* @param pVM The VM handle.
* @param pHlp The output helpers.
* @param pszArgs The additional arguments (ignored).
*/
{
/* show the flag mnemonics */
int c = 0;
uint32_t f = fForcedActions;
#define PRINT_FLAG(flag) do { \
if (f & (flag)) \
{ \
if (!(c % 6)) \
else \
c++; \
f &= ~(flag); \
} \
} while (0)
if (f)
else
/* the groups */
c = 0;
#define PRINT_GROUP(grp) do { \
if (fForcedActions & (grp)) \
{ \
if (!(c % 5)) \
else \
c++; \
} \
} while (0)
if (c)
}