VirtualBox

source: vbox/trunk/src/VBox/VMM/PGMShw.h@ 13538

Last change on this file since 13538 was 13236, checked in by vboxsync, 16 years ago

#1865: More polish.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1/* $Id: PGMShw.h 13236 2008-10-13 21:25:50Z vboxsync $ */
2/** @file
3 * VBox - Page Manager / Monitor, Shadow 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* 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 */
81PGM_SHW_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0);
82PGM_SHW_DECL(int, Enter)(PVM pVM);
83PGM_SHW_DECL(int, Relocate)(PVM pVM, RTGCUINTPTR offDelta);
84PGM_SHW_DECL(int, Exit)(PVM pVM);
85
86/* all */
87PGM_SHW_DECL(int, GetPage)(PVM pVM, RTGCUINTPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys);
88PGM_SHW_DECL(int, ModifyPage)(PVM pVM, RTGCUINTPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
89__END_DECLS
90
91
92/**
93 * Initializes the guest bit of the paging mode data.
94 *
95 * @returns VBox status code.
96 * @param pVM The VM handle.
97 * @param fResolveGCAndR0 Indicate whether or not GC and Ring-0 symbols can be resolved now.
98 * This is used early in the init process to avoid trouble with PDM
99 * not being initialized yet.
100 */
101PGM_SHW_DECL(int, InitData)(PVM pVM, PPGMMODEDATA pModeData, bool fResolveGCAndR0)
102{
103 Assert(pModeData->uShwType == PGM_SHW_TYPE || pModeData->uShwType == PGM_TYPE_NESTED);
104
105 /* Ring-3 */
106 pModeData->pfnR3ShwRelocate = PGM_SHW_NAME(Relocate);
107 pModeData->pfnR3ShwExit = PGM_SHW_NAME(Exit);
108 pModeData->pfnR3ShwGetPage = PGM_SHW_NAME(GetPage);
109 pModeData->pfnR3ShwModifyPage = PGM_SHW_NAME(ModifyPage);
110
111 if (fResolveGCAndR0)
112 {
113 int rc;
114
115#if PGM_SHW_TYPE != PGM_TYPE_AMD64 && PGM_SHW_TYPE != PGM_TYPE_NESTED && PGM_SHW_TYPE != PGM_TYPE_EPT /* No AMD64 for traditional virtualization, only VT-x and AMD-V. */
116 /* GC */
117 rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_SHW_NAME_RC_STR(GetPage), &pModeData->pfnRCShwGetPage);
118 AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_RC_STR(GetPage), rc), rc);
119 rc = PDMR3LdrGetSymbolRC(pVM, NULL, PGM_SHW_NAME_RC_STR(ModifyPage), &pModeData->pfnRCShwModifyPage);
120 AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_RC_STR(ModifyPage), rc), rc);
121#endif /* Not AMD64 shadow paging. */
122
123 /* Ring-0 */
124 rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_SHW_NAME_R0_STR(GetPage), &pModeData->pfnR0ShwGetPage);
125 AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_R0_STR(GetPage), rc), rc);
126 rc = PDMR3LdrGetSymbolR0(pVM, NULL, PGM_SHW_NAME_R0_STR(ModifyPage), &pModeData->pfnR0ShwModifyPage);
127 AssertMsgRCReturn(rc, ("%s -> rc=%Vrc\n", PGM_SHW_NAME_R0_STR(ModifyPage), rc), rc);
128 }
129 return VINF_SUCCESS;
130}
131
132/**
133 * Enters the shadow mode.
134 *
135 * @returns VBox status code.
136 * @param pVM VM handle.
137 */
138PGM_SHW_DECL(int, Enter)(PVM pVM)
139{
140#if PGM_SHW_TYPE == PGM_TYPE_NESTED
141 Assert(HWACCMIsNestedPagingActive(pVM));
142
143 Log(("Enter nested shadow paging mode: root %VHv phys %VHp\n", pVM->pgm.s.pHCNestedRoot, pVM->pgm.s.HCPhysNestedRoot));
144 /* In non-nested mode we allocate the PML4 page on-demand; in nested mode we just use our fixed nested paging root. */
145 pVM->pgm.s.pHCPaePML4 = (PX86PML4)pVM->pgm.s.pHCNestedRoot;
146 pVM->pgm.s.HCPhysPaePML4 = pVM->pgm.s.HCPhysNestedRoot;
147#endif
148 return VINF_SUCCESS;
149}
150
151
152/**
153 * Relocate any GC pointers related to shadow mode paging.
154 *
155 * @returns VBox status code.
156 * @param pVM The VM handle.
157 * @param offDelta The reloation offset.
158 */
159PGM_SHW_DECL(int, Relocate)(PVM pVM, RTGCUINTPTR offDelta)
160{
161 /* nothing special to do here - InitData does the job. */
162 return VINF_SUCCESS;
163}
164
165
166/**
167 * Exits the shadow mode.
168 *
169 * @returns VBox status code.
170 * @param pVM VM handle.
171 */
172PGM_SHW_DECL(int, Exit)(PVM pVM)
173{
174#if PGM_SHW_TYPE == PGM_TYPE_NESTED
175 Assert(HWACCMIsNestedPagingActive(pVM));
176 pVM->pgm.s.pHCPaePML4 = 0;
177 pVM->pgm.s.HCPhysPaePML4 = 0;
178 Log(("Leave nested shadow paging mode\n"));
179#endif
180
181 return VINF_SUCCESS;
182}
183
184
185
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use