VirtualBox

source: vbox/trunk/src/VBox/VMM/include/PGMGstDefs.h@ 93554

Last change on this file since 93554 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 16.6 KB
Line 
1/* $Id: PGMGstDefs.h 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * VBox - Page Manager, Guest Paging Template - All context code.
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle Corporation
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
18
19/*******************************************************************************
20* Defined Constants And Macros *
21*******************************************************************************/
22#undef GST_ATOMIC_OR
23#undef GSTPT
24#undef PGSTPT
25#undef GSTPTE
26#undef PGSTPTE
27#undef GSTPD
28#undef PGSTPD
29#undef GSTPDE
30#undef PGSTPDE
31#undef GSTPTWALK
32#undef PGSTPTWALK
33#undef PCGSTPTWALK
34#undef GST_BIG_PAGE_SIZE
35#undef GST_BIG_PAGE_OFFSET_MASK
36#undef GST_GIGANT_PAGE_SIZE
37#undef GST_GIGANT_PAGE_OFFSET_MASK
38#undef GST_PDPE_BIG_PG_MASK
39#undef GST_PDE_PG_MASK
40#undef GST_PDE_BIG_PG_MASK
41#undef GST_PD_SHIFT
42#undef GST_PD_MASK
43#undef GST_PTE_PG_MASK
44#undef GST_GET_PTE_SHW_FLAGS
45#undef GST_PT_SHIFT
46#undef GST_PT_MASK
47#undef GST_CR3_PAGE_MASK
48#undef GST_PDPE_ENTRIES
49#undef GST_PDPT_SHIFT
50#undef GST_PDPT_MASK
51#undef GST_PDPE_PG_MASK
52#undef GST_GET_PTE_GCPHYS
53#undef GST_GET_PDE_GCPHYS
54#undef GST_GET_BIG_PDE_GCPHYS
55#undef GST_GET_BIG_PDPE_GCPHYS
56#undef GST_GET_PDE_SHW_FLAGS
57#undef GST_GET_BIG_PDE_SHW_FLAGS
58#undef GST_GET_BIG_PDE_SHW_FLAGS_4_PTE
59#undef GST_IS_PTE_VALID
60#undef GST_IS_PDE_VALID
61#undef GST_IS_BIG_PDE_VALID
62#undef GST_IS_PDPE_VALID
63#undef GST_IS_BIG_PDPE_VALID
64#undef GST_IS_PML4E_VALID
65#undef GST_IS_PGENTRY_PRESENT
66#undef GST_IS_PSE_ACTIVE
67#undef GST_IS_NX_ACTIVE
68#undef BTH_IS_NP_ACTIVE
69
70#if PGM_GST_TYPE == PGM_TYPE_REAL \
71 || PGM_GST_TYPE == PGM_TYPE_PROT
72
73# if PGM_SHW_TYPE == PGM_TYPE_EPT
74# define GST_ATOMIC_OR(a_pu, a_fFlags) ASMAtomicOrU64((a_pu), (a_fFlags))
75# define GSTPT X86PTPAE
76# define PGSTPT PX86PTPAE
77# define GSTPTE X86PTEPAE
78# define PGSTPTE PX86PTEPAE
79# define GSTPD X86PDPAE
80# define PGSTPD PX86PDPAE
81# define GSTPDE X86PDEPAE
82# define PGSTPDE PX86PDEPAE
83# define GST_PTE_PG_MASK X86_PTE_PAE_PG_MASK
84# define GST_IS_NX_ACTIVE(pVCpu) (true && This_should_perhaps_not_be_used_in_this_context)
85# define BTH_IS_NP_ACTIVE(pVM) (true)
86# else
87# if PGM_SHW_TYPE == PGM_TYPE_32BIT /* Same as shadow paging, but no PGMSHWPTEPAE. */
88# define GST_ATOMIC_OR(a_pu, a_fFlags) ASMAtomicOrU32((a_pu), (a_fFlags))
89# define GSTPT X86PT
90# define PGSTPT PX86PT
91# define GSTPTE X86PTE
92# define PGSTPTE PX86PTE
93# define GSTPD X86PD
94# define PGSTPD PX86PD
95# define GSTPDE X86PDE
96# define PGSTPDE PX86PDE
97# define GST_PTE_PG_MASK X86_PTE_PG_MASK
98# else
99# define GST_ATOMIC_OR(a_pu, a_fFlags) ASMAtomicOrU64((a_pu), (a_fFlags))
100# define GSTPT X86PTPAE
101# define PGSTPT PX86PTPAE
102# define GSTPTE X86PTEPAE
103# define PGSTPTE PX86PTEPAE
104# define GSTPD X86PDPAE
105# define PGSTPD PX86PDPAE
106# define GSTPDE X86PDEPAE
107# define PGSTPDE PX86PDEPAE
108# define GST_PTE_PG_MASK X86_PTE_PAE_PG_MASK
109# endif
110# define GST_IS_NX_ACTIVE(pVCpu) (pgmGstIsNoExecuteActive(pVCpu))
111# if PGM_GST_TYPE == PGM_TYPE_PROT /* (comment at top of PGMAllBth.h) */
112# define BTH_IS_NP_ACTIVE(pVM) (pVM->pgm.s.fNestedPaging)
113# else
114# define BTH_IS_NP_ACTIVE(pVM) (false)
115# endif
116# endif
117# define GST_GET_PTE_GCPHYS(Pte) PGM_A20_APPLY(pVCpu, ((Pte).u & GST_PTE_PG_MASK))
118# define GST_GET_PDE_GCPHYS(Pde) (true && This_should_perhaps_not_be_used_in_this_context) //??
119# define GST_GET_BIG_PDE_GCPHYS(Pde) (true && This_should_perhaps_not_be_used_in_this_context) //??
120# define GST_GET_PTE_SHW_FLAGS(pVCpu, Pte) ((Pte).u & (X86_PTE_P | X86_PTE_RW | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G)) /**< @todo Could return P|RW|US|A|D here without consulting the PTE. */
121# define GST_GET_PDE_SHW_FLAGS(pVCpu, Pde) (true && This_should_perhaps_not_be_used_in_this_context) //??
122# define GST_GET_BIG_PDE_SHW_FLAGS(pVCpu, Pde) (true && This_should_perhaps_not_be_used_in_this_context) //??
123# define GST_GET_BIG_PDE_SHW_FLAGS_4_PTE(pVCpu, Pde) (true && This_should_perhaps_not_be_used_in_this_context) //??
124# define GST_IS_PTE_VALID(pVCpu, Pte) (true)
125# define GST_IS_PDE_VALID(pVCpu, Pde) (true)
126# define GST_IS_BIG_PDE_VALID(pVCpu, Pde) (true)
127# define GST_IS_PDPE_VALID(pVCpu, Pdpe) (true)
128# define GST_IS_BIG_PDPE_VALID(pVCpu, Pdpe) (true)
129# define GST_IS_PML4E_VALID(pVCpu, Pml4e) (true)
130# define GST_IS_PGENTRY_PRESENT(pVCpu, Pge) ((Pge.u) & X86_PTE_P)
131# define GST_IS_PSE_ACTIVE(pVCpu) (false && This_should_not_be_used_in_this_context)
132
133#elif PGM_GST_TYPE == PGM_TYPE_32BIT
134# define GST_ATOMIC_OR(a_pu, a_fFlags) ASMAtomicOrU32((a_pu), (a_fFlags))
135# define GSTPT X86PT
136# define PGSTPT PX86PT
137# define GSTPTE X86PTE
138# define PGSTPTE PX86PTE
139# define GSTPD X86PD
140# define PGSTPD PX86PD
141# define GSTPDE X86PDE
142# define PGSTPDE PX86PDE
143# define GSTPTWALK PGMPTWALKGST32BIT
144# define PGSTPTWALK PPGMPTWALKGST32BIT
145# define PCGSTPTWALK PCPGMPTWALKGST32BIT
146# define GST_BIG_PAGE_SIZE X86_PAGE_4M_SIZE
147# define GST_BIG_PAGE_OFFSET_MASK X86_PAGE_4M_OFFSET_MASK
148# define GST_PDE_PG_MASK X86_PDE_PG_MASK
149# define GST_PDE_BIG_PG_MASK X86_PDE4M_PG_MASK
150# define GST_GET_PTE_GCPHYS(Pte) PGM_A20_APPLY(pVCpu, ((Pte).u & GST_PDE_PG_MASK))
151# define GST_GET_PDE_GCPHYS(Pde) PGM_A20_APPLY(pVCpu, ((Pde).u & GST_PDE_PG_MASK))
152# define GST_GET_BIG_PDE_GCPHYS(pVM, Pde) PGM_A20_APPLY(pVCpu, pgmGstGet4MBPhysPage((pVM), Pde))
153# define GST_GET_PDE_SHW_FLAGS(pVCpu, Pde) ((Pde).u & (X86_PDE_P | X86_PDE_RW | X86_PDE_US | X86_PDE_A))
154# define GST_GET_BIG_PDE_SHW_FLAGS(pVCpu, Pde) \
155 ( ((Pde).u & (X86_PDE4M_P | X86_PDE4M_RW | X86_PDE4M_US | X86_PDE4M_A)) | PGM_PDFLAGS_BIG_PAGE )
156# define GST_GET_BIG_PDE_SHW_FLAGS_4_PTE(pVCpu, Pde) \
157 ((Pde).u & (X86_PDE4M_P | X86_PDE4M_RW | X86_PDE4M_US | X86_PDE4M_A | X86_PDE4M_D | X86_PDE4M_G))
158# define GST_PD_SHIFT X86_PD_SHIFT
159# define GST_PD_MASK X86_PD_MASK
160# define GST_PTE_PG_MASK X86_PTE_PG_MASK
161# define GST_GET_PTE_SHW_FLAGS(pVCpu, Pte) ((Pte).u & (X86_PTE_P | X86_PTE_RW | X86_PTE_US | X86_PTE_A | X86_PTE_D | X86_PTE_G))
162# define GST_PT_SHIFT X86_PT_SHIFT
163# define GST_PT_MASK X86_PT_MASK
164# define GST_CR3_PAGE_MASK X86_CR3_PAGE_MASK
165# define GST_IS_PTE_VALID(pVCpu, Pte) (true)
166# define GST_IS_PDE_VALID(pVCpu, Pde) (true)
167# define GST_IS_BIG_PDE_VALID(pVCpu, Pde) (!( (Pde).u & (pVCpu)->pgm.s.fGst32BitMbzBigPdeMask ))
168//# define GST_IS_PDPE_VALID(pVCpu, Pdpe) (false)
169//# define GST_IS_BIG_PDPE_VALID(pVCpu, Pdpe) (false)
170//# define GST_IS_PML4E_VALID(pVCpu, Pml4e) (false)
171# define GST_IS_PGENTRY_PRESENT(pVCpu, Pge) ((Pge.u) & X86_PTE_P)
172# define GST_IS_PSE_ACTIVE(pVCpu) pgmGst32BitIsPageSizeExtActive(pVCpu)
173# define GST_IS_NX_ACTIVE(pVCpu) (false)
174# define BTH_IS_NP_ACTIVE(pVM) (false)
175
176#elif PGM_GST_TYPE == PGM_TYPE_PAE \
177 || PGM_GST_TYPE == PGM_TYPE_AMD64
178# define GST_ATOMIC_OR(a_pu, a_fFlags) ASMAtomicOrU64((a_pu), (a_fFlags))
179# define GSTPT X86PTPAE
180# define PGSTPT PX86PTPAE
181# define GSTPTE X86PTEPAE
182# define PGSTPTE PX86PTEPAE
183# define GSTPD X86PDPAE
184# define PGSTPD PX86PDPAE
185# define GSTPDE X86PDEPAE
186# define PGSTPDE PX86PDEPAE
187# define GST_BIG_PAGE_SIZE X86_PAGE_2M_SIZE
188# define GST_BIG_PAGE_OFFSET_MASK X86_PAGE_2M_OFFSET_MASK
189# define GST_PDE_PG_MASK X86_PDE_PAE_PG_MASK
190# define GST_PDE_BIG_PG_MASK X86_PDE2M_PAE_PG_MASK
191# define GST_GET_PTE_GCPHYS(Pte) PGM_A20_APPLY(pVCpu, ((Pte).u & GST_PTE_PG_MASK))
192# define GST_GET_PDE_GCPHYS(Pde) PGM_A20_APPLY(pVCpu, ((Pde).u & GST_PDE_PG_MASK))
193# define GST_GET_BIG_PDE_GCPHYS(pVM, Pde) PGM_A20_APPLY(pVCpu, ((Pde).u & GST_PDE_BIG_PG_MASK))
194# define GST_GET_PTE_SHW_FLAGS(pVCpu, Pte) ((Pte).u & (pVCpu)->pgm.s.fGst64ShadowedPteMask )
195# define GST_GET_PDE_SHW_FLAGS(pVCpu, Pde) ((Pde).u & (pVCpu)->pgm.s.fGst64ShadowedPdeMask )
196# define GST_GET_BIG_PDE_SHW_FLAGS(pVCpu, Pde) ( ((Pde).u & (pVCpu)->pgm.s.fGst64ShadowedBigPdeMask ) | PGM_PDFLAGS_BIG_PAGE)
197# define GST_GET_BIG_PDE_SHW_FLAGS_4_PTE(pVCpu, Pde) ((Pde).u & (pVCpu)->pgm.s.fGst64ShadowedBigPde4PteMask )
198
199# define GST_PD_SHIFT X86_PD_PAE_SHIFT
200# define GST_PD_MASK X86_PD_PAE_MASK
201# if PGM_GST_TYPE == PGM_TYPE_PAE
202# define GSTPTWALK PGMPTWALKGSTPAE
203# define PGSTPTWALK PPGMPTWALKGSTPAE
204# define PCGSTPTWALK PCPGMPTWALKGSTPAE
205# define GST_PDPE_ENTRIES X86_PG_PAE_PDPE_ENTRIES
206# define GST_PDPE_PG_MASK X86_PDPE_PG_MASK
207# define GST_PDPT_SHIFT X86_PDPT_SHIFT
208# define GST_PDPT_MASK X86_PDPT_MASK_PAE
209# define GST_PTE_PG_MASK X86_PTE_PAE_PG_MASK
210# define GST_CR3_PAGE_MASK X86_CR3_PAE_PAGE_MASK
211# define GST_IS_PTE_VALID(pVCpu, Pte) (!( (Pte).u & (pVCpu)->pgm.s.fGstPaeMbzPteMask ))
212# define GST_IS_PDE_VALID(pVCpu, Pde) (!( (Pde).u & (pVCpu)->pgm.s.fGstPaeMbzPdeMask ))
213# define GST_IS_BIG_PDE_VALID(pVCpu, Pde) (!( (Pde).u & (pVCpu)->pgm.s.fGstPaeMbzBigPdeMask ))
214# define GST_IS_PDPE_VALID(pVCpu, Pdpe) (!( (Pdpe).u & (pVCpu)->pgm.s.fGstPaeMbzPdpeMask ))
215//# define GST_IS_BIG_PDPE_VALID(pVCpu, Pdpe) (false)
216//# define GST_IS_PML4E_VALID(pVCpu, Pml4e) (false)
217# else
218# define GSTPTWALK PGMPTWALKGSTAMD64
219# define PGSTPTWALK PPGMPTWALKGSTAMD64
220# define PCGSTPTWALK PCPGMPTWALKGSTAMD64
221# define GST_PDPE_ENTRIES X86_PG_AMD64_PDPE_ENTRIES
222# define GST_PDPT_SHIFT X86_PDPT_SHIFT
223# define GST_PDPE_PG_MASK X86_PDPE_PG_MASK
224# define GST_PDPT_MASK X86_PDPT_MASK_AMD64
225# define GST_PTE_PG_MASK X86_PTE_PAE_PG_MASK
226# define GST_CR3_PAGE_MASK X86_CR3_AMD64_PAGE_MASK
227# define GST_IS_PTE_VALID(pVCpu, Pte) (!( (Pte).u & (pVCpu)->pgm.s.fGstAmd64MbzPteMask ))
228# define GST_IS_PDE_VALID(pVCpu, Pde) (!( (Pde).u & (pVCpu)->pgm.s.fGstAmd64MbzPdeMask ))
229# define GST_IS_BIG_PDE_VALID(pVCpu, Pde) (!( (Pde).u & (pVCpu)->pgm.s.fGstAmd64MbzBigPdeMask ))
230# define GST_IS_PDPE_VALID(pVCpu, Pdpe) (!( (Pdpe).u & (pVCpu)->pgm.s.fGstAmd64MbzPdpeMask ))
231# define GST_IS_BIG_PDPE_VALID(pVCpu, Pdpe) (!( (Pdpe).u & (pVCpu)->pgm.s.fGstAmd64MbzBigPdpeMask ))
232# define GST_IS_PML4E_VALID(pVCpu, Pml4e) (!( (Pml4e).u & (pVCpu)->pgm.s.fGstAmd64MbzPml4eMask ))
233# endif
234# define GST_IS_PGENTRY_PRESENT(pVCpu, Pge) ((Pge.u) & X86_PTE_P)
235# define GST_PT_SHIFT X86_PT_PAE_SHIFT
236# define GST_PT_MASK X86_PT_PAE_MASK
237# define GST_IS_PSE_ACTIVE(pVCpu) (true)
238# define GST_IS_NX_ACTIVE(pVCpu) (pgmGstIsNoExecuteActive(pVCpu))
239# define BTH_IS_NP_ACTIVE(pVM) (false)
240
241#elif PGM_GST_TYPE == PGM_TYPE_EPT
242# define GST_ATOMIC_OR(a_pu, a_fFlags) ASMAtomicOrU64((a_pu), (a_fFlags))
243# define GSTPT EPTPT
244# define PGSTPT PEPTPT
245# define GSTPTE EPTPTE
246# define PGSTPTE PEPTPTE
247# define GSTPD EPTPD
248# define PGSTPD PEPTPD
249# define GSTPDE EPTPDE
250# define PGSTPDE PEPTPDE
251# define GST_GIGANT_PAGE_SIZE X86_PAGE_1G_SIZE
252# define GST_GIGANT_PAGE_OFFSET_MASK X86_PAGE_1G_OFFSET_MASK
253# define GST_PDPE_BIG_PG_MASK X86_PDPE1G_PG_MASK
254# define GST_BIG_PAGE_SIZE X86_PAGE_2M_SIZE
255# define GST_BIG_PAGE_OFFSET_MASK X86_PAGE_2M_OFFSET_MASK
256# define GST_PDE_PG_MASK EPT_PDE_PG_MASK
257# define GST_PDE_BIG_PG_MASK EPT_PDE2M_PG_MASK
258# define GST_PD_SHIFT EPT_PD_SHIFT
259# define GST_PD_MASK EPT_PD_MASK
260# define GSTPTWALK PGMPTWALKGSTEPT
261# define PGSTPTWALK PPGMPTWALKGSTEPT
262# define PCGSTPTWALK PCPGMPTWALKGSTEPT
263# define GST_PDPE_ENTRIES EPT_PG_ENTRIES
264# define GST_PDPT_SHIFT EPT_PDPT_SHIFT
265# define GST_PDPE_PG_MASK EPT_PDPTE_PG_MASK
266# define GST_PDPT_MASK EPT_PDPT_MASK
267# define GST_PTE_PG_MASK EPT_E_PG_MASK
268# define GST_CR3_PAGE_MASK X86_CR3_EPT_PAGE_MASK
269# define GST_PT_SHIFT EPT_PT_SHIFT
270# define GST_PT_MASK EPT_PT_MASK
271# define GST_GET_PTE_GCPHYS(Pte) PGM_A20_APPLY(pVCpu, ((Pte).u & GST_PTE_PG_MASK))
272# define GST_GET_PDE_GCPHYS(Pde) PGM_A20_APPLY(pVCpu, ((Pde).u & GST_PDE_PG_MASK))
273# define GST_GET_BIG_PDE_GCPHYS(pVM, Pde) PGM_A20_APPLY(pVCpu, ((Pde).u & GST_PDE_BIG_PG_MASK))
274# define GST_GET_BIG_PDPE_GCPHYS(pVM, Pde) PGM_A20_APPLY(pVCpu, ((Pde).u & GST_PDPE_BIG_PG_MASK))
275# define GST_GET_PTE_SHW_FLAGS(pVCpu, Pte) (true && This_should_perhaps_not_be_used_in_this_context)
276# define GST_GET_PDE_SHW_FLAGS(pVCpu, Pde) (true && This_should_perhaps_not_be_used_in_this_context)
277# define GST_GET_BIG_PDE_SHW_FLAGS(pVCpu, Pde) (true && This_should_perhaps_not_be_used_in_this_context)
278# define GST_GET_BIG_PDE_SHW_FLAGS_4_PTE(pVCpu, Pde) (true && This_should_perhaps_not_be_used_in_this_context)
279# define GST_IS_PTE_VALID(pVCpu, Pte) (!( (Pte).u & (pVCpu)->pgm.s.fGstEptMbzPteMask ))
280# define GST_IS_PDE_VALID(pVCpu, Pde) (!( (Pde).u & (pVCpu)->pgm.s.fGstEptMbzPdeMask ))
281# define GST_IS_BIG_PDE_VALID(pVCpu, Pde) (!( (Pde).u & (pVCpu)->pgm.s.fGstEptMbzBigPdeMask ))
282# define GST_IS_PDPE_VALID(pVCpu, Pdpe) (!( (Pdpe).u & (pVCpu)->pgm.s.fGstEptMbzPdpteMask ))
283# define GST_IS_BIG_PDPE_VALID(pVCpu, Pdpe) (!( (Pdpe).u & (pVCpu)->pgm.s.fGstEptMbzBigPdpteMask ))
284# define GST_IS_PML4E_VALID(pVCpu, Pml4e) (!( (Pml4e).u & (pVCpu)->pgm.s.fGstEptMbzPml4eMask ))
285# define GST_IS_PGENTRY_PRESENT(pVCpu, Pge) ((Pge).u & (pVCpu)->pgm.s.fGstEptPresentMask)
286# define GST_IS_PSE_ACTIVE(pVCpu) (!((pVCpu)->pgm.s.fGstEptMbzBigPdeMask & EPT_E_BIT_LEAF))
287# define GST_IS_NX_ACTIVE(pVCpu) (pgmGstIsNoExecuteActive(pVCpu))
288# define BTH_IS_NP_ACTIVE(pVM) (false)
289#endif
290
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette