1 | /* $Id: bs3-cmn-PagingInitRootForLM.c 59941 2016-03-07 15:13:51Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * BS3Kit - Bs3PagingInitRootForLM
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2016 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 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*********************************************************************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *********************************************************************************************************************************/
|
---|
30 | #include "bs3kit-template-header.h"
|
---|
31 | #include "bs3-cmn-paging.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | BS3_DECL(int) Bs3PagingInitRootForLM(void)
|
---|
35 | {
|
---|
36 | X86PML4 BS3_FAR *pPml4;
|
---|
37 |
|
---|
38 | BS3_ASSERT(BS3_DATA_NM(g_PhysPagingRootLM) == UINT32_MAX);
|
---|
39 |
|
---|
40 | /*
|
---|
41 | * The default is an identity mapping of the first 4GB repeated for the
|
---|
42 | * whole 48-bit virtual address space. So, we need one level more than PAE.
|
---|
43 | */
|
---|
44 | pPml4 = (X86PML4 BS3_FAR *)Bs3MemAlloc(BS3MEMKIND_TILED, _4K);
|
---|
45 | if (pPml4)
|
---|
46 | {
|
---|
47 | X86PDPT BS3_FAR *pPdPtr = (X86PDPT BS3_FAR *)Bs3MemAlloc(BS3MEMKIND_TILED, _4K);
|
---|
48 | BS3_ASSERT((uintptr_t)pPdPtr != (uintptr_t)pPml4);
|
---|
49 | if (pPdPtr)
|
---|
50 | {
|
---|
51 | X86PDPAE BS3_FAR *paPgDirs = (X86PDPAE BS3_FAR *)Bs3MemAlloc(BS3MEMKIND_TILED, _4K * 4U);
|
---|
52 | BS3_ASSERT((uintptr_t)paPgDirs != (uintptr_t)pPml4);
|
---|
53 | if (paPgDirs)
|
---|
54 | {
|
---|
55 | unsigned i;
|
---|
56 | BS3_XPTR_AUTO(X86PML4, XPtrPml4);
|
---|
57 | BS3_XPTR_AUTO(X86PDPT, XPtrPdPtr);
|
---|
58 | BS3_XPTR_AUTO(X86PDPAE, XPtrPgDirs);
|
---|
59 |
|
---|
60 | /* Set up the 2048 2MB pages first. */
|
---|
61 | for (i = 0; i < RT_ELEMENTS(paPgDirs->a) * 4U; i++)
|
---|
62 | paPgDirs->a[i].u = ((uint32_t)i << X86_PD_PAE_SHIFT)
|
---|
63 | | X86_PDE4M_P | X86_PDE4M_RW | X86_PDE4M_US | X86_PDE4M_PS | X86_PDE4M_A | X86_PDE4M_D;
|
---|
64 |
|
---|
65 | /* Set up the page directory pointer table next (4GB replicated, remember). */
|
---|
66 | BS3_XPTR_SET(X86PDPAE, XPtrPgDirs, paPgDirs);
|
---|
67 | pPdPtr->a[0].u = BS3_XPTR_GET_FLAT(X86PDPAE, XPtrPgDirs)
|
---|
68 | | X86_PDPE_P | X86_PDPE_RW | X86_PDPE_US | X86_PDPE_A;
|
---|
69 | pPdPtr->a[1].u = pPdPtr->a[0].u + _4K;
|
---|
70 | pPdPtr->a[2].u = pPdPtr->a[1].u + _4K;
|
---|
71 | pPdPtr->a[3].u = pPdPtr->a[2].u + _4K;
|
---|
72 |
|
---|
73 | for (i = 4; i < RT_ELEMENTS(pPdPtr->a); i += 4)
|
---|
74 | {
|
---|
75 | pPdPtr->a[i + 0].u = pPdPtr->a[0].u;
|
---|
76 | pPdPtr->a[i + 1].u = pPdPtr->a[1].u;
|
---|
77 | pPdPtr->a[i + 2].u = pPdPtr->a[2].u;
|
---|
78 | pPdPtr->a[i + 3].u = pPdPtr->a[3].u;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* Set up the page map level 4 (all entries are the same). */
|
---|
82 | BS3_XPTR_SET(X86PDPT, XPtrPdPtr, pPdPtr);
|
---|
83 | pPml4->a[0].u = BS3_XPTR_GET_FLAT(X86PDPT, XPtrPdPtr)
|
---|
84 | | X86_PML4E_P | X86_PML4E_RW | X86_PML4E_US | X86_PML4E_A;
|
---|
85 | for (i = 1; i < RT_ELEMENTS(pPml4->a); i++)
|
---|
86 | pPml4->a[i].u = pPml4->a[0].u;
|
---|
87 |
|
---|
88 | /* Set the global root pointer and we're done. */
|
---|
89 | BS3_XPTR_SET(X86PML4, XPtrPml4, pPml4);
|
---|
90 | BS3_DATA_NM(g_PhysPagingRootLM) = BS3_XPTR_GET_FLAT(X86PML4, XPtrPml4);
|
---|
91 | return VINF_SUCCESS;
|
---|
92 | }
|
---|
93 |
|
---|
94 | BS3_ASSERT(false);
|
---|
95 | Bs3MemFree(pPdPtr, _4K);
|
---|
96 | }
|
---|
97 | BS3_ASSERT(false);
|
---|
98 | Bs3MemFree(pPml4, _4K);
|
---|
99 | }
|
---|
100 | BS3_ASSERT(false);
|
---|
101 | return VERR_NO_MEMORY;
|
---|
102 | }
|
---|
103 |
|
---|