https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d0f6d2cf6eb781b188103ae5157f67fa6040a493

commit d0f6d2cf6eb781b188103ae5157f67fa6040a493
Author:     Timo Kreuzer <[email protected]>
AuthorDate: Sun Jun 13 11:26:06 2021 +0200
Commit:     Timo Kreuzer <[email protected]>
CommitDate: Sat Jun 19 12:01:24 2021 +0200

    [FREELDR/x64] Allow using memory above 4GB on x64
    
    This splits MM_MAX_PAGE into the maximum addressable PFN (which is 2^20-1 
on x86, 2^26-1 on x86PAE and 2^36-1 on x64) and the maximum mapped/accessible 
virtual memory MM_MAX_PAGE_LOADER (which is 4 GB on x86, since paging is 
disabled, but only 1 GB on x64, since only that much is identity-mapped).
---
 boot/freeldr/freeldr/include/mm.h     | 10 ++++++++--
 boot/freeldr/freeldr/lib/mm/meminit.c |  6 +++---
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/boot/freeldr/freeldr/include/mm.h 
b/boot/freeldr/freeldr/include/mm.h
index dd1bb195633..a3f34a55f78 100644
--- a/boot/freeldr/freeldr/include/mm.h
+++ b/boot/freeldr/freeldr/include/mm.h
@@ -51,7 +51,12 @@ typedef struct _FREELDR_MEMORY_DESCRIPTOR
 #define MM_PAGE_SIZE    4096
 #define MM_PAGE_MASK    0xFFF
 #define MM_PAGE_SHIFT    12
-#define MM_MAX_PAGE        0xFFFFF
+#if defined(_X86PAE_)
+#define MM_MAX_PAGE        0x3FFFFFF /* 26 bits for the PFN */
+#else
+#define MM_MAX_PAGE        0xFFFFF /* 20 bits for the PFN */
+#endif
+#define MM_MAX_PAGE_LOADER 0xFFFFF /* 4 GB flat address range */
 
 #define MM_SIZE_TO_PAGES(a)  \
     ( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) )
@@ -63,7 +68,8 @@ typedef struct _FREELDR_MEMORY_DESCRIPTOR
 #define MM_PAGE_SIZE    4096
 #define MM_PAGE_MASK    0xFFF
 #define MM_PAGE_SHIFT    12
-#define MM_MAX_PAGE     0x3FFFF /* freeldr only maps 1 GB */
+#define MM_MAX_PAGE        0xFFFFFFFFF /* 36 bits for the PFN */
+#define MM_MAX_PAGE_LOADER 0x3FFFF /* on x64 freeldr only maps 1 GB */
 
 #define MM_SIZE_TO_PAGES(a)  \
     ( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) )
diff --git a/boot/freeldr/freeldr/lib/mm/meminit.c 
b/boot/freeldr/freeldr/lib/mm/meminit.c
index 8276cb8ca57..37a705a0c68 100644
--- a/boot/freeldr/freeldr/lib/mm/meminit.c
+++ b/boot/freeldr/freeldr/lib/mm/meminit.c
@@ -1,7 +1,7 @@
 /*
  *  FreeLoader
  *  Copyright (C) 2006-2008     Aleksey Bragin  <[email protected]>
- *  Copyright (C) 2006-2009     Herv� Poussineau  <[email protected]>
+ *  Copyright (C) 2006-2009     Hervé Poussineau  <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -438,7 +438,7 @@ PVOID MmFindLocationForPageLookupTable(PFN_NUMBER 
TotalPageCount)
         if (MemoryDescriptor->BasePage < CandidateBasePage) continue;
 
         // Continue, if the address is too high
-        if (MemoryDescriptor->BasePage + RequiredPages >= MM_MAX_PAGE) 
continue;
+        if (MemoryDescriptor->BasePage + RequiredPages >= MM_MAX_PAGE_LOADER) 
continue;
 
         // Memory block is more suitable than the previous one
         CandidateBasePage = MemoryDescriptor->BasePage;
@@ -447,7 +447,7 @@ PVOID MmFindLocationForPageLookupTable(PFN_NUMBER 
TotalPageCount)
 
     // Calculate the end address for the lookup table
     PageLookupTableEndPage = min(CandidateBasePage + CandidatePageCount,
-                                 MM_MAX_PAGE);
+                                 MM_MAX_PAGE_LOADER);
 
     // Calculate the virtual address
     PageLookupTableMemAddress = (PVOID)((PageLookupTableEndPage * PAGE_SIZE)

Reply via email to