1 | /* $Id: PGMGst.h 17586 2009-03-09 15:28:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox - Page Manager / Monitor, Guest Paging Template.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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
|
---|
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.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Internal Functions *
|
---|
25 | *******************************************************************************/
|
---|
26 | __BEGIN_DECLS
|
---|
27 | /* r3 */
|
---|
28 | PGM_GST_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0);
|
---|
29 | PGM_GST_DECL(int, Enter)(PVM pVM, RTGCPHYS GCPhysCR3);
|
---|
30 | PGM_GST_DECL(int, Relocate)(PVM pVM, RTGCPTR offDelta);
|
---|
31 | PGM_GST_DECL(int, Exit)(PVM pVM);
|
---|
32 |
|
---|
33 | /* all */
|
---|
34 | PGM_GST_DECL(int, GetPage)(PVM pVM, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys);
|
---|
35 | PGM_GST_DECL(int, ModifyPage)(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
|
---|
36 | PGM_GST_DECL(int, GetPDE)(PVM pVM, RTGCPTR GCPtr, PX86PDEPAE pPDE);
|
---|
37 | __END_DECLS
|
---|
38 |
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Initializes the guest bit of the paging mode data.
|
---|
42 | *
|
---|
43 | * @returns VBox status code.
|
---|
44 | * @param pVM The VM handle.
|
---|
45 | * @param fResolveGCAndR0 Indicate whether or not GC and Ring-0 symbols can be resolved now.
|
---|
46 | * This is used early in the init process to avoid trouble with PDM
|
---|
47 | * not being initialized yet.
|
---|
48 | */
|
---|
49 | PGM_GST_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0)
|
---|
50 | {
|
---|
51 | Assert(pModeData->uGstType == PGM_GST_TYPE);
|
---|
52 |
|
---|
53 | /* Ring-3 */
|
---|
54 | pModeData->pfnR3GstRelocate = PGM_GST_NAME(Relocate);
|
---|
55 | pModeData->pfnR3GstExit = PGM_GST_NAME(Exit);
|
---|
56 | pModeData->pfnR3GstGetPDE = PGM_GST_NAME(GetPDE);
|
---|
57 | pModeData->pfnR3GstGetPage = PGM_GST_NAME(GetPage);
|
---|
58 | pModeData->pfnR3GstModifyPage = PGM_GST_NAME(ModifyPage);
|
---|
59 |
|
---|
60 | if (fResolveGCAndR0)
|
---|
61 | {
|
---|
62 | int rc;
|
---|
63 |
|
---|
64 | #if PGM_SHW_TYPE != PGM_TYPE_AMD64 /* No AMD64 for traditional virtualization, only VT-x and AMD-V. */
|
---|
65 | /* GC */
|
---|
66 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(GetPage), &pModeData->pfnRCGstGetPage);
|
---|
67 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(GetPage), rc), rc);
|
---|
68 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(ModifyPage), &pModeData->pfnRCGstModifyPage);
|
---|
69 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(ModifyPage), rc), rc);
|
---|
70 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_GST_NAME_RC_STR(GetPDE), &pModeData->pfnRCGstGetPDE);
|
---|
71 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_RC_STR(GetPDE), rc), rc);
|
---|
72 | #endif /* Not AMD64 shadow paging. */
|
---|
73 |
|
---|
74 | /* Ring-0 */
|
---|
75 | rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(GetPage), &pModeData->pfnR0GstGetPage);
|
---|
76 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(GetPage), rc), rc);
|
---|
77 | rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(ModifyPage), &pModeData->pfnR0GstModifyPage);
|
---|
78 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(ModifyPage), rc), rc);
|
---|
79 | rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_GST_NAME_R0_STR(GetPDE), &pModeData->pfnR0GstGetPDE);
|
---|
80 | AssertMsgRCReturn(rc, ("%s -> rc=%Rrc\n", PGM_GST_NAME_R0_STR(GetPDE), rc), rc);
|
---|
81 | }
|
---|
82 |
|
---|
83 | return VINF_SUCCESS;
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Enters the guest mode.
|
---|
89 | *
|
---|
90 | * @returns VBox status code.
|
---|
91 | * @param pVM VM handle.
|
---|
92 | * @param GCPhysCR3 The physical address from the CR3 register.
|
---|
93 | */
|
---|
94 | PGM_GST_DECL(int, Enter)(PVM pVM, RTGCPHYS GCPhysCR3)
|
---|
95 | {
|
---|
96 | /*
|
---|
97 | * Map and monitor CR3
|
---|
98 | */
|
---|
99 | int rc = PGM_BTH_PFN(MapCR3, pVM)(pVM, GCPhysCR3);
|
---|
100 | return rc;
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Relocate any GC pointers related to guest mode paging.
|
---|
106 | *
|
---|
107 | * @returns VBox status code.
|
---|
108 | * @param pVM The VM handle.
|
---|
109 | * @param offDelta The reloation offset.
|
---|
110 | */
|
---|
111 | PGM_GST_DECL(int, Relocate)(PVM pVM, RTGCPTR offDelta)
|
---|
112 | {
|
---|
113 | /* nothing special to do here - InitData does the job. */
|
---|
114 | return VINF_SUCCESS;
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Exits the guest mode.
|
---|
120 | *
|
---|
121 | * @returns VBox status code.
|
---|
122 | * @param pVM VM handle.
|
---|
123 | */
|
---|
124 | PGM_GST_DECL(int, Exit)(PVM pVM)
|
---|
125 | {
|
---|
126 | int rc;
|
---|
127 |
|
---|
128 | rc = PGM_BTH_PFN(UnmapCR3, pVM)(pVM);
|
---|
129 | return rc;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|