1 | /* $Id: PGMGC.cpp 13087 2008-10-08 15:38:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PGM - Page Monitor, Guest Context.
|
---|
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 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #define LOG_GROUP LOG_GROUP_PGM
|
---|
27 | #include <VBox/pgm.h>
|
---|
28 | #include <VBox/cpum.h>
|
---|
29 | #include <VBox/mm.h>
|
---|
30 | #include <VBox/em.h>
|
---|
31 | #include <VBox/selm.h>
|
---|
32 | #include <VBox/iom.h>
|
---|
33 | #include <VBox/trpm.h>
|
---|
34 | #include <VBox/rem.h>
|
---|
35 | #include "PGMInternal.h"
|
---|
36 | #include <VBox/vm.h>
|
---|
37 |
|
---|
38 | #include <iprt/asm.h>
|
---|
39 | #include <iprt/assert.h>
|
---|
40 | #include <VBox/log.h>
|
---|
41 | #include <VBox/param.h>
|
---|
42 | #include <VBox/err.h>
|
---|
43 | #include <VBox/dis.h>
|
---|
44 | #include <VBox/disopcode.h>
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | /*******************************************************************************
|
---|
49 | * Internal Functions *
|
---|
50 | *******************************************************************************/
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 | #ifndef RT_ARCH_AMD64
|
---|
55 | /*
|
---|
56 | * Shadow - 32-bit mode
|
---|
57 | */
|
---|
58 | #define PGM_SHW_TYPE PGM_TYPE_32BIT
|
---|
59 | #define PGM_SHW_NAME(name) PGM_SHW_NAME_32BIT(name)
|
---|
60 | #include "PGMGCShw.h"
|
---|
61 |
|
---|
62 | /* Guest - real mode */
|
---|
63 | #define PGM_GST_TYPE PGM_TYPE_REAL
|
---|
64 | #define PGM_GST_NAME(name) PGM_GST_NAME_REAL(name)
|
---|
65 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_32BIT_REAL(name)
|
---|
66 | #include "PGMGCGst.h"
|
---|
67 | #include "PGMGCBth.h"
|
---|
68 | #undef PGM_BTH_NAME
|
---|
69 | #undef PGM_GST_TYPE
|
---|
70 | #undef PGM_GST_NAME
|
---|
71 |
|
---|
72 | /* Guest - protected mode */
|
---|
73 | #define PGM_GST_TYPE PGM_TYPE_PROT
|
---|
74 | #define PGM_GST_NAME(name) PGM_GST_NAME_PROT(name)
|
---|
75 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_32BIT_PROT(name)
|
---|
76 | #include "PGMGCGst.h"
|
---|
77 | #include "PGMGCBth.h"
|
---|
78 | #undef PGM_BTH_NAME
|
---|
79 | #undef PGM_GST_TYPE
|
---|
80 | #undef PGM_GST_NAME
|
---|
81 |
|
---|
82 | /* Guest - 32-bit mode */
|
---|
83 | #define PGM_GST_TYPE PGM_TYPE_32BIT
|
---|
84 | #define PGM_GST_NAME(name) PGM_GST_NAME_32BIT(name)
|
---|
85 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_32BIT_32BIT(name)
|
---|
86 | #include "PGMGCGst.h"
|
---|
87 | #include "PGMGCBth.h"
|
---|
88 | #undef PGM_BTH_NAME
|
---|
89 | #undef PGM_GST_TYPE
|
---|
90 | #undef PGM_GST_NAME
|
---|
91 |
|
---|
92 | #undef PGM_SHW_TYPE
|
---|
93 | #undef PGM_SHW_NAME
|
---|
94 | #endif /* !RT_ARCH_AMD64 */
|
---|
95 |
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * Shadow - PAE mode
|
---|
99 | */
|
---|
100 | #define PGM_SHW_TYPE PGM_TYPE_PAE
|
---|
101 | #define PGM_SHW_NAME(name) PGM_SHW_NAME_PAE(name)
|
---|
102 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_REAL(name)
|
---|
103 | #include "PGMGCShw.h"
|
---|
104 |
|
---|
105 | /* Guest - real mode */
|
---|
106 | #define PGM_GST_TYPE PGM_TYPE_REAL
|
---|
107 | #define PGM_GST_NAME(name) PGM_GST_NAME_REAL(name)
|
---|
108 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_REAL(name)
|
---|
109 | #include "PGMGCBth.h"
|
---|
110 | #undef PGM_BTH_NAME
|
---|
111 | #undef PGM_GST_TYPE
|
---|
112 | #undef PGM_GST_NAME
|
---|
113 |
|
---|
114 | /* Guest - protected mode */
|
---|
115 | #define PGM_GST_TYPE PGM_TYPE_PROT
|
---|
116 | #define PGM_GST_NAME(name) PGM_GST_NAME_PROT(name)
|
---|
117 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_PROT(name)
|
---|
118 | #include "PGMGCBth.h"
|
---|
119 | #undef PGM_BTH_NAME
|
---|
120 | #undef PGM_GST_TYPE
|
---|
121 | #undef PGM_GST_NAME
|
---|
122 |
|
---|
123 | /* Guest - 32-bit mode */
|
---|
124 | #define PGM_GST_TYPE PGM_TYPE_32BIT
|
---|
125 | #define PGM_GST_NAME(name) PGM_GST_NAME_32BIT(name)
|
---|
126 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_32BIT(name)
|
---|
127 | #include "PGMGCBth.h"
|
---|
128 | #undef PGM_BTH_NAME
|
---|
129 | #undef PGM_GST_TYPE
|
---|
130 | #undef PGM_GST_NAME
|
---|
131 |
|
---|
132 | /* Guest - PAE mode */
|
---|
133 | #define PGM_GST_TYPE PGM_TYPE_PAE
|
---|
134 | #define PGM_GST_NAME(name) PGM_GST_NAME_PAE(name)
|
---|
135 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_PAE(name)
|
---|
136 | #include "PGMGCGst.h"
|
---|
137 | #include "PGMGCBth.h"
|
---|
138 | #undef PGM_BTH_NAME
|
---|
139 | #undef PGM_GST_TYPE
|
---|
140 | #undef PGM_GST_NAME
|
---|
141 |
|
---|
142 | #undef PGM_SHW_TYPE
|
---|
143 | #undef PGM_SHW_NAME
|
---|
144 |
|
---|
145 |
|
---|
146 | /*
|
---|
147 | * Shadow - AMD64 mode
|
---|
148 | */
|
---|
149 | #define PGM_SHW_TYPE PGM_TYPE_AMD64
|
---|
150 | #define PGM_SHW_NAME(name) PGM_SHW_NAME_AMD64(name)
|
---|
151 | #include "PGMGCShw.h"
|
---|
152 |
|
---|
153 | /* Guest - AMD64 mode */
|
---|
154 | #define PGM_GST_TYPE PGM_TYPE_AMD64
|
---|
155 | #define PGM_GST_NAME(name) PGM_GST_NAME_AMD64(name)
|
---|
156 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_AMD64_AMD64(name)
|
---|
157 | #include "PGMGCGst.h"
|
---|
158 | #include "PGMGCBth.h"
|
---|
159 | #undef PGM_BTH_NAME
|
---|
160 | #undef PGM_GST_TYPE
|
---|
161 | #undef PGM_GST_NAME
|
---|
162 |
|
---|
163 | #undef PGM_SHW_TYPE
|
---|
164 | #undef PGM_SHW_NAME
|
---|
165 |
|
---|
166 |
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Emulation of the invlpg instruction.
|
---|
170 | *
|
---|
171 | * @returns VBox status code suitable for scheduling.
|
---|
172 | * @param pVM VM handle.
|
---|
173 | * @param GCPtrPage Page to invalidate.
|
---|
174 | */
|
---|
175 | VMMRCDECL(int) PGMGCInvalidatePage(PVM pVM, RTGCPTR GCPtrPage)
|
---|
176 | {
|
---|
177 | LogFlow(("PGMGCInvalidatePage: GCPtrPage=%VGv\n", GCPtrPage));
|
---|
178 |
|
---|
179 | STAM_PROFILE_START(&pVM->pgm.s.StatRCInvalidatePage, a);
|
---|
180 |
|
---|
181 | /*
|
---|
182 | * Check for conflicts and pending CR3 monitoring updates.
|
---|
183 | */
|
---|
184 | if (!pVM->pgm.s.fMappingsFixed)
|
---|
185 | {
|
---|
186 | if ( pgmGetMapping(pVM, GCPtrPage)
|
---|
187 | /** @todo && (PGMGstGetPDE(pVM, GCPtrPage) & X86_PDE_P) - FIX THIS NOW!!! */ )
|
---|
188 | {
|
---|
189 | LogFlow(("PGMGCInvalidatePage: Conflict!\n"));
|
---|
190 | VM_FF_SET(pVM, VM_FF_PGM_SYNC_CR3);
|
---|
191 | STAM_PROFILE_STOP(&pVM->pgm.s.StatRCInvalidatePage, a);
|
---|
192 | return VINF_PGM_SYNC_CR3;
|
---|
193 | }
|
---|
194 |
|
---|
195 | if (pVM->pgm.s.fSyncFlags & PGM_SYNC_MONITOR_CR3)
|
---|
196 | {
|
---|
197 | LogFlow(("PGMGCInvalidatePage: PGM_SYNC_MONITOR_CR3 -> reinterpret instruction in HC\n"));
|
---|
198 | STAM_PROFILE_STOP(&pVM->pgm.s.StatRCInvalidatePage, a);
|
---|
199 | /** @todo counter for these... */
|
---|
200 | return VINF_EM_RAW_EMULATE_INSTR;
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 | /*
|
---|
205 | * Notify the recompiler so it can record this instruction.
|
---|
206 | * Failure happens when it's out of space. We'll return to HC in that case.
|
---|
207 | */
|
---|
208 | int rc = REMNotifyInvalidatePage(pVM, GCPtrPage);
|
---|
209 | if (rc == VINF_SUCCESS)
|
---|
210 | rc = PGM_BTH_PFN(InvalidatePage, pVM)(pVM, GCPtrPage);
|
---|
211 |
|
---|
212 | STAM_PROFILE_STOP(&pVM->pgm.s.StatRCInvalidatePage, a);
|
---|
213 | return rc;
|
---|
214 | }
|
---|