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