[23] | 1 | /* $Id: PGMGst.h 45808 2013-04-29 12:41:07Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
| 3 | * VBox - Page Manager / Monitor, Guest Paging Template.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[44528] | 7 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
[1] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
[1] | 16 | */
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | /*******************************************************************************
|
---|
| 20 | * Internal Functions *
|
---|
| 21 | *******************************************************************************/
|
---|
[20374] | 22 | RT_C_DECLS_BEGIN
|
---|
[1] | 23 | /* r3 */
|
---|
| 24 | PGM_GST_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0);
|
---|
[18988] | 25 | PGM_GST_DECL(int, Enter)(PVMCPU pVCpu, RTGCPHYS GCPhysCR3);
|
---|
| 26 | PGM_GST_DECL(int, Relocate)(PVMCPU pVCpu, RTGCPTR offDelta);
|
---|
| 27 | PGM_GST_DECL(int, Exit)(PVMCPU pVCpu);
|
---|
[1] | 28 |
|
---|
| 29 | /* all */
|
---|
[18988] | 30 | PGM_GST_DECL(int, GetPage)(PVMCPU pVCpu, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys);
|
---|
| 31 | PGM_GST_DECL(int, ModifyPage)(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
|
---|
| 32 | PGM_GST_DECL(int, GetPDE)(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDEPAE pPDE);
|
---|
[20374] | 33 | RT_C_DECLS_END
|
---|
[1] | 34 |
|
---|
| 35 |
|
---|
| 36 | /**
|
---|
| 37 | * Initializes the guest bit of the paging mode data.
|
---|
| 38 | *
|
---|
| 39 | * @returns VBox status code.
|
---|
[41783] | 40 | * @param pVM Pointer to the VM.
|
---|
[1] | 41 | * @param fResolveGCAndR0 Indicate whether or not GC and Ring-0 symbols can be resolved now.
|
---|
| 42 | * This is used early in the init process to avoid trouble with PDM
|
---|
| 43 | * not being initialized yet.
|
---|
| 44 | */
|
---|
| 45 | PGM_GST_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0)
|
---|
| 46 | {
|
---|
| 47 | Assert(pModeData->uGstType == PGM_GST_TYPE);
|
---|
| 48 |
|
---|
| 49 | /* Ring-3 */
|
---|
[13236] | 50 | pModeData->pfnR3GstRelocate = PGM_GST_NAME(Relocate);
|
---|
| 51 | pModeData->pfnR3GstExit = PGM_GST_NAME(Exit);
|
---|
| 52 | pModeData->pfnR3GstGetPDE = PGM_GST_NAME(GetPDE);
|
---|
| 53 | pModeData->pfnR3GstGetPage = PGM_GST_NAME(GetPage);
|
---|
| 54 | pModeData->pfnR3GstModifyPage = PGM_GST_NAME(ModifyPage);
|
---|
[1] | 55 |
|
---|
| 56 | if (fResolveGCAndR0)
|
---|
| 57 | {
|
---|
| 58 | int rc;
|
---|
| 59 |
|
---|
[45808] | 60 | if (!HMIsEnabled(pVM))
|
---|
| 61 | {
|
---|
[8415] | 62 | #if PGM_SHW_TYPE != PGM_TYPE_AMD64 /* No AMD64 for traditional virtualization, only VT-x and AMD-V. */
|
---|
[45808] | 63 | /* RC */
|
---|
| 64 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(GetPage), &pModeData->pfnRCGstGetPage);
|
---|
| 65 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(GetPage), rc), rc);
|
---|
| 66 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(ModifyPage), &pModeData->pfnRCGstModifyPage);
|
---|
| 67 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(ModifyPage), rc), rc);
|
---|
| 68 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(GetPDE), &pModeData->pfnRCGstGetPDE);
|
---|
| 69 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(GetPDE), rc), rc);
|
---|
[8415] | 70 | #endif /* Not AMD64 shadow paging. */
|
---|
[45808] | 71 | }
|
---|
[1] | 72 |
|
---|
| 73 | /* Ring-0 */
|
---|
[13236] | 74 | rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(GetPage), &pModeData->pfnR0GstGetPage);
|
---|
[13818] | 75 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(GetPage), rc), rc);
|
---|
[13236] | 76 | rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(ModifyPage), &pModeData->pfnR0GstModifyPage);
|
---|
[13818] | 77 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(ModifyPage), rc), rc);
|
---|
[13236] | 78 | rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(GetPDE), &pModeData->pfnR0GstGetPDE);
|
---|
[13818] | 79 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(GetPDE), rc), rc);
|
---|
[1] | 80 | }
|
---|
| 81 |
|
---|
| 82 | return VINF_SUCCESS;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | * Enters the guest mode.
|
---|
| 88 | *
|
---|
| 89 | * @returns VBox status code.
|
---|
[41801] | 90 | * @param pVCpu Pointer to the VMCPU.
|
---|
[1] | 91 | * @param GCPhysCR3 The physical address from the CR3 register.
|
---|
| 92 | */
|
---|
[18988] | 93 | PGM_GST_DECL(int, Enter)(PVMCPU pVCpu, RTGCPHYS GCPhysCR3)
|
---|
[1] | 94 | {
|
---|
| 95 | /*
|
---|
| 96 | * Map and monitor CR3
|
---|
| 97 | */
|
---|
[18992] | 98 | int rc = PGM_BTH_PFN(MapCR3, pVCpu)(pVCpu, GCPhysCR3);
|
---|
[1] | 99 | return rc;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | /**
|
---|
| 104 | * Relocate any GC pointers related to guest mode paging.
|
---|
| 105 | *
|
---|
| 106 | * @returns VBox status code.
|
---|
[41801] | 107 | * @param pVCpu Pointer to the VMCPU.
|
---|
[33540] | 108 | * @param offDelta The relocation offset.
|
---|
[1] | 109 | */
|
---|
[18988] | 110 | PGM_GST_DECL(int, Relocate)(PVMCPU pVCpu, RTGCPTR offDelta)
|
---|
[1] | 111 | {
|
---|
[18927] | 112 | pVCpu->pgm.s.pGst32BitPdRC += offDelta;
|
---|
| 113 |
|
---|
| 114 | for (unsigned i = 0; i < RT_ELEMENTS(pVCpu->pgm.s.apGstPaePDsRC); i++)
|
---|
| 115 | {
|
---|
| 116 | pVCpu->pgm.s.apGstPaePDsRC[i] += offDelta;
|
---|
| 117 | }
|
---|
| 118 | pVCpu->pgm.s.pGstPaePdptRC += offDelta;
|
---|
| 119 |
|
---|
[1] | 120 | return VINF_SUCCESS;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | /**
|
---|
| 125 | * Exits the guest mode.
|
---|
| 126 | *
|
---|
| 127 | * @returns VBox status code.
|
---|
[41801] | 128 | * @param pVCpu Pointer to the VMCPU.
|
---|
[1] | 129 | */
|
---|
[18988] | 130 | PGM_GST_DECL(int, Exit)(PVMCPU pVCpu)
|
---|
[1] | 131 | {
|
---|
[14301] | 132 | int rc;
|
---|
| 133 |
|
---|
[18992] | 134 | rc = PGM_BTH_PFN(UnmapCR3, pVCpu)(pVCpu);
|
---|
[1] | 135 | return rc;
|
---|
| 136 | }
|
---|
| 137 |
|
---|