VMMInternal.h revision 17ba03925269c071aa1567eb8c5a49c37a65f62f
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * VMM - Internal header file.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Copyright (C) 2006-2007 innotek GmbH
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * This file is part of VirtualBox Open Source Edition (OSE), as
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * available from http://www.virtualbox.org. This file is free software;
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * you can redistribute it and/or modify it under the terms of the GNU
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * General Public License as published by the Free Software Foundation,
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * distribution. VirtualBox OSE is distributed in the hope that it will
e6c3a72a023407f5d1fface64356e1cc81f1af31Phill Cunnington * be useful, but WITHOUT ANY WARRANTY of any kind.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * If you received this file as part of a commercial VirtualBox
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * distribution, then only the terms of your commercial VirtualBox
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * license agreement apply instead of the previous paragraph.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#if !defined(IN_VMM_R3) && !defined(IN_VMM_R0) && !defined(IN_VMM_GC)
c753f6e8a6f0cf7da636e4e27871db14930b577bAndrew Forrest# error "Not in VMM! This is an internal header!"
c753f6e8a6f0cf7da636e4e27871db14930b577bAndrew Forrest/** @defgroup grp_vmm_int Internals
c753f6e8a6f0cf7da636e4e27871db14930b577bAndrew Forrest * @ingroup grp_vmm
f58fb92a804b356de679ca0ad458d59d95dc3af2Andrew Forrest/** @def VBOX_WITH_GC_AND_R0_RELEASE_LOG
f58fb92a804b356de679ca0ad458d59d95dc3af2Andrew Forrest * Enabled GC and R0 release logging (the latter is not implemented yet). */
f36d7fc719bcbc9aba272b40a4723a24a81d6e0cAndrew Forrest * Converts a VMM pointer into a VM pointer.
c753f6e8a6f0cf7da636e4e27871db14930b577bAndrew Forrest * @returns Pointer to the VM structure the VMM is part of.
f36d7fc719bcbc9aba272b40a4723a24a81d6e0cAndrew Forrest * @param pVMM Pointer to VMM instance data.
f36d7fc719bcbc9aba272b40a4723a24a81d6e0cAndrew Forrest#define VMM2VM(pVMM) ( (PVM)((char*)pVMM - pVMM->offVM) )
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest * Switcher function, HC to GC.
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest * @param pVM The VM handle.
c753f6e8a6f0cf7da636e4e27871db14930b577bAndrew Forrest * @returns Return code indicating the action to take.
c753f6e8a6f0cf7da636e4e27871db14930b577bAndrew Forresttypedef DECLASMTYPE(int) FNVMMSWITCHERHC(PVM pVM);
f58fb92a804b356de679ca0ad458d59d95dc3af2Andrew Forrest/** Pointer to switcher function. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Switcher function, GC to HC.
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest * @param rc VBox status code.
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueevatypedef DECLASMTYPE(void) FNVMMSWITCHERGC(int rc);
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest/** Pointer to switcher function. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * The ring-0 logger instance.
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest * We need to be able to find the VM handle from the logger instance.
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** Pointer to the VM handle. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Size of the allocated logger instance (Logger). */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Flag indicating whether we've create the logger Ring-0 instance yet. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** The ring-0 logger instance. This extends beyon the size.*/
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Jump buffer for the setjmp/longjmp like constructs used to
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * quickly 'call' back into Ring-3.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Tranditional jmp_buf stuff
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Flag that indicates that we've done a ring-3 call. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** The number of bytes we've saved. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** Pointer to the buffer used to save the stack.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * This is assumed to be 8KB. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** The esp we should resume execution with after the restore. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * VMM Data (part of VMM)
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forresttypedef struct VMM
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Offset to the VM structure.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * See VMM2VM(). */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Size of the core code. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Physical address of core code. */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest/** @todo pvHCCoreCodeR3 -> pvCoreCodeR3, pvHCCoreCodeR0 -> pvCoreCodeR0 */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Pointer to core code ring-3 mapping - contiguous memory.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * At present this only means the context switcher code. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Pointer to core code ring-0 mapping - contiguous memory.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * At present this only means the context switcher code. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Pointer to core code guest context mapping. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** The guest context address of the APIC (host) mapping. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest RTGCPTR pGCPadding0; /**< Alignment padding */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** The current switcher.
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest * This will be set before the VMM is fully initialized. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Array of offsets to the different switchers within the core code. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Flag to disable the switcher permanently (VMX) (boolean) */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Host to guest switcher entry point. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest R0PTRTYPE(PFNVMMSWITCHERHC) pfnR0HostToGuest;
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Guest to host switcher entry point. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva GCPTRTYPE(PFNVMMSWITCHERGC) pfnGCGuestToHost;
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Call Trampoline. See vmmGCCallTrampoline(). */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Resume Guest Execution. See CPUMGCResumeGuest(). */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** The last GC return code. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest uint32_t u32Padding0; /**< Alignment padding. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** VMM stack, pointer to the top of the stack in HC.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Stack is allocated from the hypervisor heap and is page aligned
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva * and always writable in GC. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Pointer to the bottom of the stack - needed for doing relocations. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Pointer to the bottom of the stack - needed for doing relocations. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** Pointer to the GC logger instance - GC Ptr.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * This is NULL if logging is disabled. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Size of the allocated logger instance (pLoggerGC/pLoggerHC). */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Pointer to the GC logger instance - HC Ptr.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * This is NULL if logging is disabled. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** Pointer to the R0 logger instance.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * This is NULL if logging is disabled. */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** Pointer to the GC release logger instance - GC Ptr. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** Size of the allocated release logger instance (pRelLoggerGC/pRelLoggerHC).
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * This may differ from cbLoggerGC. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Pointer to the GC release logger instance - HC Ptr. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva#endif /* VBOX_WITH_GC_AND_R0_RELEASE_LOG */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Global VM critical section. */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** The EMT yield timer. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** The period to the next timeout when suspended or stopped.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * This is 0 when running. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** The EMT yield timer interval (milliseconds). */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest uint32_t u32Padding0; /**< Alignment padding. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** The timestamp of the previous yield. (nano) */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** @name CallHost
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** The pending operation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** The result of the last operation. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** The argument to the operation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** The Ring-0 jmp buffer. */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** Number of VMMR0_DO_RUN_GC calls. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Statistics for each of the GC return codes.
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva * The VMMGCEntry() codes.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Do GC module init. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** The first Trap testcase. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 0 testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 1 testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 2 testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 3 testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 4 testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 5 testcases, uArg selects the variation. */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** Trap 6 testcases, uArg selects the variation. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** Trap 7 testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 8 testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 9 testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 0a testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 0b testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 0c testcases, uArg selects the variation. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Trap 0d testcases, uArg selects the variation. */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** Trap 0e testcases, uArg selects the variation. */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva /** The last trap testcase (exclusive). */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Testcase for checking interrupt forwarding. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Switching testing and profiling stub. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Testcase for checking interrupt masking.. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest /** Switching testing and profiling stub. */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest /** The usual 32-bit hack. */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * World switcher assembly routine.
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest * It will call VMMGCEntry().
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva * @returns return code from VMMGCEntry().
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @param pVM The VM in question.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @param uArg See VMMGCEntry().
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestDECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Callback function for vmmR0CallHostSetJmp.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @returns VBox status code.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @param pVM The VM handle.
02c49168646ef9cd489c870441375a0d19573001Andrew Forresttypedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM);
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest/** Pointer to FNVMMR0SETJMP(). */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * The setjmp variant used for calling Ring-3.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * This differs from the normal setjmp in that it will resume VMMR0CallHost if we're
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * in the middle of a ring-3 call. Another differences is the function pointer and
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva * argument. This has to do with resuming code and the stack frame of the caller.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallHostLongJmp.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @param pJmpBuf The jmp_buf to set.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @param pfn The function to be called when not resuming..
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest * @param pVM The argument of that function.
2cf2c78315835c58587ed426175184c5d4300a33Eugenia SergueevaDECLASM(int) vmmR0CallHostSetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM);
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Worker for VMMR0CallHost.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * This will save the stack and registers.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @returns rc.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @param pJmpBuf Pointer to the jump buffer.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @param rc The return code.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestDECLASM(int) vmmR0CallHostLongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Internal R0 logger worker: Logger wrapper.
02c49168646ef9cd489c870441375a0d19573001Andrew ForrestVMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Internal R0 logger worker: Flush logger.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @param pLogger The logger instance to flush.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @remark This function must be exported!
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestVMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva#endif /* IN_RING0 */
02c49168646ef9cd489c870441375a0d19573001Andrew Forrest * Internal GC logger worker: Logger wrapper.
2cf2c78315835c58587ed426175184c5d4300a33Eugenia SergueevaVMMGCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Internal GC release logger worker: Logger wrapper.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestVMMGCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * Internal GC logger worker: Flush logger.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @returns VINF_SUCCESS.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @param pLogger The logger instance to flush.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest * @remark This function must be exported!
02c49168646ef9cd489c870441375a0d19573001Andrew ForrestVMMGCDECL(int) vmmGCLoggerFlush(PRTLOGGERGC pLogger);
2cf2c78315835c58587ed426175184c5d4300a33Eugenia Sergueeva/** @name Trap testcases and related labels.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestDECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
2cf2c78315835c58587ed426175184c5d4300a33Eugenia SergueevaDECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#endif /* IN_GC */