VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PagingMapRamAbove4GForLM.c@ 92263

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

ValKit/bs3kit: Added Bs3PagingMapRamAbove4GForLM and made Bs3InitMemory_rm_far produce global variable g_uBs3EndOfRamAbove4G. [scm] bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: bs3-cmn-PagingMapRamAbove4GForLM.c 92263 2021-11-08 11:16:15Z vboxsync $ */
2/** @file
3 * BS3Kit - Bs3PagingInitMapAbove4GForLM
4 */
5
6/*
7 * Copyright (C) 2007-2021 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/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "bs3kit-template-header.h"
32#include "bs3-cmn-paging.h"
33
34#if ARCH_BITS == 16
35# error "This does not work in 16-bit mode, only 32-bit and 64-bit"
36#endif
37
38#undef Bs3PagingMapRamAbove4GForLM
39BS3_CMN_DEF(int, Bs3PagingMapRamAbove4GForLM,(uint64_t *puFailurePoint))
40{
41 X86PML4 * const pPml4 = (X86PML4 *)((uintptr_t)g_PhysPagingRootLM);
42 unsigned iPml4 = 0;
43 unsigned iPdpt = 4;
44 uint64_t uAddr = _4G;
45 X86PDPT * pPdpt;
46
47 if (puFailurePoint)
48 *puFailurePoint = 0;
49
50 /* Must call Bs3PagingInitRootForLM first! */
51 if (g_PhysPagingRootLM == UINT32_MAX)
52 return VERR_WRONG_ORDER;
53
54 /* Done already? */
55 if (pPml4->a[0].u != pPml4->a[4].u)
56 return VINF_ALREADY_INITIALIZED;
57
58 /*
59 * Map RAM pages up to g_uBs3EndOfRamAbove4G.
60 */
61 pPdpt = (X86PDPT *)(pPml4->a[0].u & X86_PML4E_PG_MASK);
62 while (uAddr < g_uBs3EndOfRamAbove4G)
63 {
64 X86PDPAE *pPd;
65 unsigned i;
66
67 /* Do we need a new PDPT? */
68 if (iPdpt >= RT_ELEMENTS(pPdpt->a))
69 {
70 if (iPml4 >= RT_ELEMENTS(pPml4->a) / 2)
71 {
72 if (puFailurePoint)
73 *puFailurePoint = uAddr;
74 return VERR_OUT_OF_RANGE;
75 }
76 pPdpt = (X86PDPT *)Bs3MemAllocZ(BS3MEMKIND_FLAT32, X86_PAGE_SIZE);
77 if (!pPdpt || ((uintptr_t)pPdpt & X86_PAGE_OFFSET_MASK))
78 {
79 if (puFailurePoint)
80 *puFailurePoint = uAddr;
81 return !pPdpt ? VERR_NO_MEMORY : VERR_UNSUPPORTED_ALIGNMENT;
82 }
83 pPml4->a[++iPml4].u = X86_PML4E_P | X86_PML4E_RW | X86_PML4E_US | X86_PML4E_A
84 | (uintptr_t)pPdpt;
85 iPdpt = 0;
86 }
87
88 /* Allocate a new page directory. */
89 pPd = (X86PDPAE *)Bs3MemAlloc(BS3MEMKIND_FLAT32, X86_PAGE_SIZE);
90 if (!pPd || ((uintptr_t)pPd & X86_PAGE_OFFSET_MASK))
91 {
92 if (puFailurePoint)
93 *puFailurePoint = uAddr;
94 return !pPd ? VERR_NO_MEMORY : VERR_UNSUPPORTED_ALIGNMENT;
95 }
96
97 /* Initialize it. */
98 for (i = 0; i < RT_ELEMENTS(pPd->a); i++)
99 {
100 pPd->a[i].u = uAddr | X86_PDE4M_P | X86_PDE4M_RW | X86_PDE4M_US | X86_PDE4M_PS | X86_PDE4M_A | X86_PDE4M_D;
101 uAddr += _2M;
102 }
103
104 /* Insert it into the page directory pointer table. */
105 pPdpt->a[iPdpt++].u = (uintptr_t)pPd | X86_PDPE_P | X86_PDPE_RW | X86_PDPE_US | X86_PDPE_A;
106 }
107
108 return VINF_SUCCESS;
109}
110
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