1 | /* $Id: PGMShw.h 2291 2007-04-20 23:26:42Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox - Page Manager / Monitor, Shadow Paging Template.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*******************************************************************************
|
---|
23 | * Defined Constants And Macros *
|
---|
24 | *******************************************************************************/
|
---|
25 | #undef SHWPT
|
---|
26 | #undef PSHWPT
|
---|
27 | #undef SHWPTE
|
---|
28 | #undef PSHWPTE
|
---|
29 | #undef SHWPD
|
---|
30 | #undef PSHWPD
|
---|
31 | #undef SHWPDE
|
---|
32 | #undef PSHWPDE
|
---|
33 | #undef SHW_PDE_PG_MASK
|
---|
34 | #undef SHW_PD_SHIFT
|
---|
35 | #undef SHW_PD_MASK
|
---|
36 | #undef SHW_PTE_PG_MASK
|
---|
37 | #undef SHW_PT_SHIFT
|
---|
38 | #undef SHW_PT_MASK
|
---|
39 | #undef SHW_POOL_ROOT_IDX
|
---|
40 |
|
---|
41 | #if PGM_SHW_TYPE == PGM_TYPE_32BIT
|
---|
42 | # define SHWPT X86PT
|
---|
43 | # define PSHWPT PX86PT
|
---|
44 | # define SHWPTE X86PTE
|
---|
45 | # define PSHWPTE PX86PTE
|
---|
46 | # define SHWPD X86PD
|
---|
47 | # define PSHWPD PX86PD
|
---|
48 | # define SHWPDE X86PDE
|
---|
49 | # define PSHWPDE PX86PDE
|
---|
50 | # define SHW_PDE_PG_MASK X86_PDE_PG_MASK
|
---|
51 | # define SHW_PD_SHIFT X86_PD_SHIFT
|
---|
52 | # define SHW_PD_MASK X86_PD_MASK
|
---|
53 | # define SHW_PTE_PG_MASK X86_PTE_PG_MASK
|
---|
54 | # define SHW_PT_SHIFT X86_PT_SHIFT
|
---|
55 | # define SHW_PT_MASK X86_PT_MASK
|
---|
56 | # define SHW_POOL_ROOT_IDX PGMPOOL_IDX_PD
|
---|
57 | #else
|
---|
58 | # define SHWPT X86PTPAE
|
---|
59 | # define PSHWPT PX86PTPAE
|
---|
60 | # define SHWPTE X86PTEPAE
|
---|
61 | # define PSHWPTE PX86PTEPAE
|
---|
62 | # define SHWPD X86PDPAE
|
---|
63 | # define PSHWPD PX86PDPAE
|
---|
64 | # define SHWPDE X86PDEPAE
|
---|
65 | # define PSHWPDE PX86PDEPAE
|
---|
66 | # define SHW_PDE_PG_MASK X86_PDE_PAE_PG_MASK
|
---|
67 | # define SHW_PD_SHIFT X86_PD_PAE_SHIFT
|
---|
68 | # define SHW_PD_MASK X86_PD_PAE_MASK
|
---|
69 | # define SHW_PTE_PG_MASK X86_PTE_PAE_PG_MASK
|
---|
70 | # define SHW_PT_SHIFT X86_PT_PAE_SHIFT
|
---|
71 | # define SHW_PT_MASK X86_PT_PAE_MASK
|
---|
72 | # define SHW_POOL_ROOT_IDX PGMPOOL_IDX_PAE_PD
|
---|
73 | #endif
|
---|
74 |
|
---|
75 |
|
---|
76 | /*******************************************************************************
|
---|
77 | * Internal Functions *
|
---|
78 | *******************************************************************************/
|
---|
79 | __BEGIN_DECLS
|
---|
80 | /* r3 */
|
---|
81 | PGM_SHW_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0);
|
---|
82 | PGM_SHW_DECL(int, Enter)(PVM pVM);
|
---|
83 | PGM_SHW_DECL(int, Relocate)(PVM pVM, RTGCUINTPTR offDelta);
|
---|
84 | PGM_SHW_DECL(int, Exit)(PVM pVM);
|
---|
85 |
|
---|
86 | /* all */
|
---|
87 | PGM_SHW_DECL(int, GetPage)(PVM pVM, RTGCUINTPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys);
|
---|
88 | PGM_SHW_DECL(int, ModifyPage)(PVM pVM, RTGCUINTPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
|
---|
89 | PGM_SHW_DECL(int, GetPDEByIndex)(PVM pVM, uint32_t iPD, PX86PDEPAE pPde);
|
---|
90 | PGM_SHW_DECL(int, SetPDEByIndex)(PVM pVM, uint32_t iPD, X86PDEPAE Pde);
|
---|
91 | PGM_SHW_DECL(int, ModifyPDEByIndex)(PVM pVM, uint32_t iPD, uint64_t fFlags, uint64_t fMask);
|
---|
92 | __END_DECLS
|
---|
93 |
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Initializes the guest bit of the paging mode data.
|
---|
97 | *
|
---|
98 | * @returns VBox status code.
|
---|
99 | * @param pVM The VM handle.
|
---|
100 | * @param fResolveGCAndR0 Indicate whether or not GC and Ring-0 symbols can be resolved now.
|
---|
101 | * This is used early in the init process to avoid trouble with PDM
|
---|
102 | * not being initialized yet.
|
---|
103 | */
|
---|
104 | PGM_SHW_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0)
|
---|
105 | {
|
---|
106 | Assert(pModeData->uShwType == PGM_SHW_TYPE);
|
---|
107 |
|
---|
108 | /* Ring-3 */
|
---|
109 | pModeData->pfnR3ShwRelocate = PGM_SHW_NAME(Relocate);
|
---|
110 | pModeData->pfnR3ShwExit = PGM_SHW_NAME(Exit);
|
---|
111 | pModeData->pfnR3ShwGetPage = PGM_SHW_NAME(GetPage);
|
---|
112 | pModeData->pfnR3ShwModifyPage = PGM_SHW_NAME(ModifyPage);
|
---|
113 | pModeData->pfnR3ShwGetPDEByIndex = PGM_SHW_NAME(GetPDEByIndex);
|
---|
114 | pModeData->pfnR3ShwSetPDEByIndex = PGM_SHW_NAME(SetPDEByIndex);
|
---|
115 | pModeData->pfnR3ShwModifyPDEByIndex = PGM_SHW_NAME(ModifyPDEByIndex);
|
---|
116 |
|
---|
117 | if (fResolveGCAndR0)
|
---|
118 | {
|
---|
119 | int rc;
|
---|
120 |
|
---|
121 | /* GC */
|
---|
122 | rc = PDMR3GetSymbolGC(pVM, NULL, PGM_SHW_NAME_GC_STR(GetPage), &pModeData->pfnGCShwGetPage);
|
---|
123 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_GC_STR(GetPage), rc), rc);
|
---|
124 | rc = PDMR3GetSymbolGC(pVM, NULL, PGM_SHW_NAME_GC_STR(ModifyPage), &pModeData->pfnGCShwModifyPage);
|
---|
125 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_GC_STR(ModifyPage), rc), rc);
|
---|
126 | rc = PDMR3GetSymbolGC(pVM, NULL, PGM_SHW_NAME_GC_STR(GetPDEByIndex), &pModeData->pfnGCShwGetPDEByIndex);
|
---|
127 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_GC_STR(GetPDEByIndex), rc), rc);
|
---|
128 | rc = PDMR3GetSymbolGC(pVM, NULL, PGM_SHW_NAME_GC_STR(SetPDEByIndex), &pModeData->pfnGCShwSetPDEByIndex);
|
---|
129 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_GC_STR(SetPDEByIndex), rc), rc);
|
---|
130 | rc = PDMR3GetSymbolGC(pVM, NULL, PGM_SHW_NAME_GC_STR(ModifyPDEByIndex), &pModeData->pfnGCShwModifyPDEByIndex);
|
---|
131 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_GC_STR(ModifyPDEByIndex), rc), rc);
|
---|
132 |
|
---|
133 | /* Ring-0 */
|
---|
134 | rc = PDMR3GetSymbolR0(pVM, NULL, PGM_SHW_NAME_R0_STR(GetPage), &pModeData->pfnR0ShwGetPage);
|
---|
135 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_R0_STR(GetPage), rc), rc);
|
---|
136 | rc = PDMR3GetSymbolR0(pVM, NULL, PGM_SHW_NAME_R0_STR(ModifyPage), &pModeData->pfnR0ShwModifyPage);
|
---|
137 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_R0_STR(ModifyPage), rc), rc);
|
---|
138 | rc = PDMR3GetSymbolR0(pVM, NULL, PGM_SHW_NAME_R0_STR(GetPDEByIndex), &pModeData->pfnR0ShwGetPDEByIndex);
|
---|
139 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_R0_STR(GetPDEByIndex), rc), rc);
|
---|
140 | rc = PDMR3GetSymbolR0(pVM, NULL, PGM_SHW_NAME_R0_STR(SetPDEByIndex), &pModeData->pfnR0ShwSetPDEByIndex);
|
---|
141 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_R0_STR(SetPDEByIndex), rc), rc);
|
---|
142 | rc = PDMR3GetSymbolR0(pVM, NULL, PGM_SHW_NAME_R0_STR(ModifyPDEByIndex), &pModeData->pfnR0ShwModifyPDEByIndex);
|
---|
143 | AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_R0_STR(ModifyPDEByIndex), rc), rc);
|
---|
144 | }
|
---|
145 | return VINF_SUCCESS;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Enters the shadow mode.
|
---|
150 | *
|
---|
151 | * @returns VBox status code.
|
---|
152 | * @param pVM VM handle.
|
---|
153 | */
|
---|
154 | PGM_SHW_DECL(int, Enter)(PVM pVM)
|
---|
155 | {
|
---|
156 | #if PGM_SHW_MODE == PGM_MODE_AMD64
|
---|
157 | /*
|
---|
158 | * Set the RW, US and A flags for the fixed PDPEs.
|
---|
159 | */
|
---|
160 | #endif
|
---|
161 | return VINF_SUCCESS;
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Relocate any GC pointers related to shadow mode paging.
|
---|
167 | *
|
---|
168 | * @returns VBox status code.
|
---|
169 | * @param pVM The VM handle.
|
---|
170 | * @param offDelta The reloation offset.
|
---|
171 | */
|
---|
172 | PGM_SHW_DECL(int, Relocate)(PVM pVM, RTGCUINTPTR offDelta)
|
---|
173 | {
|
---|
174 | /* nothing special to do here - InitData does the job. */
|
---|
175 | return VINF_SUCCESS;
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Exits the shadow mode.
|
---|
181 | *
|
---|
182 | * @returns VBox status code.
|
---|
183 | * @param pVM VM handle.
|
---|
184 | */
|
---|
185 | PGM_SHW_DECL(int, Exit)(PVM pVM)
|
---|
186 | {
|
---|
187 | #if PGM_SHW_MODE == PGM_MODE_AMD64
|
---|
188 | /*
|
---|
189 | * Clear the RW, US and A flags for the fixed PDPEs.
|
---|
190 | */
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | return VINF_SUCCESS;
|
---|
194 | }
|
---|
195 |
|
---|
196 |
|
---|
197 |
|
---|