VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PagingInitRootForLM.c

Last change on this file was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: bs3-cmn-PagingInitRootForLM.c 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * BS3Kit - Bs3PagingInitRootForLM
4 */
5
6/*
7 * Copyright (C) 2007-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "bs3kit-template-header.h"
42#include "bs3-cmn-paging.h"
43
44
45#undef Bs3PagingInitRootForLM
46BS3_CMN_DEF(int, Bs3PagingInitRootForLM,(void))
47{
48 X86PML4 BS3_FAR *pPml4;
49
50 BS3_ASSERT(g_PhysPagingRootLM == UINT32_MAX);
51
52 /*
53 * The default is an identity mapping of the first 4GB repeated for the
54 * whole 48-bit virtual address space. So, we need one level more than PAE.
55 */
56 pPml4 = (X86PML4 BS3_FAR *)Bs3MemAlloc(BS3MEMKIND_TILED, _4K);
57 if (pPml4)
58 {
59 X86PDPT BS3_FAR *pPdPtr = (X86PDPT BS3_FAR *)Bs3MemAlloc(BS3MEMKIND_TILED, _4K);
60 BS3_ASSERT((uintptr_t)pPdPtr != (uintptr_t)pPml4);
61 if (pPdPtr)
62 {
63 X86PDPAE BS3_FAR *paPgDirs = (X86PDPAE BS3_FAR *)Bs3MemAlloc(BS3MEMKIND_TILED, _4K * 4U);
64 BS3_ASSERT((uintptr_t)paPgDirs != (uintptr_t)pPml4);
65 if (paPgDirs)
66 {
67 unsigned i;
68 BS3_XPTR_AUTO(X86PML4, XPtrPml4);
69 BS3_XPTR_AUTO(X86PDPT, XPtrPdPtr);
70 BS3_XPTR_AUTO(X86PDPAE, XPtrPgDirs);
71
72 /* Set up the 2048 2MB pages first. */
73 for (i = 0; i < RT_ELEMENTS(paPgDirs->a) * 4U; i++)
74 paPgDirs->a[i].u = ((uint32_t)i << X86_PD_PAE_SHIFT)
75 | X86_PDE4M_P | X86_PDE4M_RW | X86_PDE4M_US | X86_PDE4M_PS | X86_PDE4M_A | X86_PDE4M_D;
76
77 /* Set up the page directory pointer table next (4GB replicated, remember). */
78 BS3_XPTR_SET(X86PDPAE, XPtrPgDirs, paPgDirs);
79 pPdPtr->a[0].u = BS3_XPTR_GET_FLAT(X86PDPAE, XPtrPgDirs)
80 | X86_PDPE_P | X86_PDPE_RW | X86_PDPE_US | X86_PDPE_A;
81 pPdPtr->a[1].u = pPdPtr->a[0].u + _4K;
82 pPdPtr->a[2].u = pPdPtr->a[1].u + _4K;
83 pPdPtr->a[3].u = pPdPtr->a[2].u + _4K;
84
85 for (i = 4; i < RT_ELEMENTS(pPdPtr->a); i += 4)
86 {
87 pPdPtr->a[i + 0].u = pPdPtr->a[0].u;
88 pPdPtr->a[i + 1].u = pPdPtr->a[1].u;
89 pPdPtr->a[i + 2].u = pPdPtr->a[2].u;
90 pPdPtr->a[i + 3].u = pPdPtr->a[3].u;
91 }
92
93 /* Set up the page map level 4 (all entries are the same). */
94 BS3_XPTR_SET(X86PDPT, XPtrPdPtr, pPdPtr);
95 pPml4->a[0].u = BS3_XPTR_GET_FLAT(X86PDPT, XPtrPdPtr)
96 | X86_PML4E_P | X86_PML4E_RW | X86_PML4E_US | X86_PML4E_A;
97 for (i = 1; i < RT_ELEMENTS(pPml4->a); i++)
98 pPml4->a[i].u = pPml4->a[0].u;
99
100 /* Set the global root pointer and we're done. */
101 BS3_XPTR_SET(X86PML4, XPtrPml4, pPml4);
102 g_PhysPagingRootLM = BS3_XPTR_GET_FLAT(X86PML4, XPtrPml4);
103 return VINF_SUCCESS;
104 }
105
106 BS3_ASSERT(false);
107 Bs3MemFree(pPdPtr, _4K);
108 }
109 BS3_ASSERT(false);
110 Bs3MemFree(pPml4, _4K);
111 }
112 BS3_ASSERT(false);
113 return VERR_NO_MEMORY;
114}
115
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