Author: sir_richard
Date: Sun Jun 5 20:48:34 2011
New Revision: 52098
URL:
http://svn.reactos.org/svn/reactos?rev=52098&view=rev
Log:
[FREELDR]: Some ARM architectures do not necessarily have CS0_BASE at 0x00000000, for
example, most Ti OMAP Platforms have DDR at 0x80000000. The current FreeLDR algorithms
would build FreeLDR "page entries" for every page from 0 to 0x7FFF0000 and mark
it as unusable, then build the actual valid entries from 0x80000000 -> end of RAM, thus
resulting in large memory consumption (and in the bloat of the PFN database later once
NTOS loads) and boot time. Therefore, the algorithm is changed to start the PFN database
at the lowest valid RAM page described by the Firemware descriptors, and entries therefore
will be offset. This means a 128MB embedded system no longer appears to have 2048+128MB of
RAM worth of PFN entries.
NOTE: Windows does not do this, opting instead to force manufacturers/use pull-up
resistors/reconfigure the ARM Bus to map RAM at 0x00000000. For wider portability, I
believe it makes more sense to simply do this "trick" in the boot loader.
Modified:
trunk/reactos/boot/freeldr/freeldr/arcemul/mm.c
trunk/reactos/boot/freeldr/freeldr/mm/meminit.c
Modified: trunk/reactos/boot/freeldr/freeldr/arcemul/mm.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arcem…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arcemul/mm.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arcemul/mm.c [iso-8859-1] Sun Jun 5 20:48:34 2011
@@ -30,7 +30,6 @@
{ { MemoryFirmwareTemporary, 0x80, 0x10 }, 4, }, // File system read buffer.
FILESYSBUFFER
{ { MemoryFirmwareTemporary, 0x90, 0x10 }, 5, }, // Disk read buffer for int 13h.
DISKREADBUFFER
{ { MemoryFirmwarePermanent, 0xA0, 0x60 }, 6, }, // ROM / Video
- { { MemorySpecialMemory, 0xFFF, 1 }, 7, }, // unusable memory
#elif __arm__ // This needs to be done per-platform specific way
#endif
@@ -55,7 +54,8 @@
//
RtlZeroMemory(BiosMemoryMap, sizeof(BIOS_MEMORY_MAP) * 32);
BiosMemoryMapEntryCount = MachVtbl.GetMemoryMap(BiosMemoryMap,
- sizeof(BiosMemoryMap) / sizeof(BIOS_MEMORY_MAP));
+ sizeof(BiosMemoryMap) /
+ sizeof(BIOS_MEMORY_MAP));
//
// Copy the entries to our structure
Modified: trunk/reactos/boot/freeldr/freeldr/mm/meminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/me…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/mm/meminit.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/mm/meminit.c [iso-8859-1] Sun Jun 5 20:48:34 2011
@@ -48,6 +48,8 @@
ULONG TotalPagesInLookupTable = 0;
ULONG FreePagesInLookupTable = 0;
ULONG LastFreePageHint = 0;
+ULONG MmLowestPhysicalPage = 0xFFFFFFFF;
+ULONG MmHighestPhysicalPage = 0;
extern ULONG_PTR MmHeapPointer;
extern ULONG_PTR MmHeapStart;
@@ -75,7 +77,7 @@
// Find address for the page lookup table
TotalPagesInLookupTable = MmGetAddressablePageCountIncludingHoles();
PageLookupTableAddress = MmFindLocationForPageLookupTable(TotalPagesInLookupTable);
- LastFreePageHint = TotalPagesInLookupTable;
+ LastFreePageHint = MmHighestPhysicalPage;
if (PageLookupTableAddress == 0)
{
@@ -102,20 +104,21 @@
{
ULONG PagesNeeded;
ULONG HeapStart;
+#ifndef _M_ARM
MEMORY_TYPE Type;
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
// HACK: Make it so it doesn't overlap kernel space
Type = RealPageLookupTable[0x100].PageAllocated;
MmMarkPagesInLookupTable(PageLookupTableAddress, 0x100, 0xFF, LoaderSystemCode);
-
+#endif
// Find contigious memory block for HEAP:STACK
PagesNeeded = HEAP_PAGES + STACK_PAGES;
HeapStart = MmFindAvailablePages(PageLookupTable, TotalPagesInLookupTable, PagesNeeded,
FALSE);
-
+#ifndef _M_ARM
// Unapply the hack
MmMarkPagesInLookupTable(PageLookupTableAddress, 0x100, 0xFF, Type);
-
+#endif
if (HeapStart == 0)
{
UiMessageBox("Critical error: Can't allocate heap!");
@@ -156,7 +159,7 @@
ULONG MmGetAddressablePageCountIncludingHoles(VOID)
{
MEMORY_DESCRIPTOR* MemoryDescriptor = NULL;
- ULONG EndPage = 0;
+ ULONG PageCount;
//
// Go through the whole memory map to get max address
@@ -166,18 +169,30 @@
//
// Check if we got a higher end page address
//
- if (MemoryDescriptor->BasePage + MemoryDescriptor->PageCount > EndPage)
+ if (MemoryDescriptor->BasePage + MemoryDescriptor->PageCount >
MmHighestPhysicalPage)
{
//
- // Yes, remember it
- //
- EndPage = MemoryDescriptor->BasePage + MemoryDescriptor->PageCount;
+ // Yes, remember it if this is real memory
+ //
+ if (MemoryDescriptor->MemoryType == MemoryFree) MmHighestPhysicalPage =
MemoryDescriptor->BasePage + MemoryDescriptor->PageCount;
+ }
+
+ //
+ // Check if we got a higher (usable) start page address
+ //
+ if (MemoryDescriptor->BasePage < MmLowestPhysicalPage)
+ {
+ //
+ // Yes, remember it if this is real memory
+ //
+ if (MemoryDescriptor->MemoryType == MemoryFree) MmLowestPhysicalPage =
MemoryDescriptor->BasePage;
}
}
-
- DPRINTM(DPRINT_MEMORY, "MmGetAddressablePageCountIncludingHoles() returning
0x%x\n", EndPage);
-
- return EndPage;
+
+ DPRINTM(DPRINT_MEMORY, "lo/hi %lx %lxn", MmLowestPhysicalPage,
MmHighestPhysicalPage);
+ PageCount = MmHighestPhysicalPage - MmLowestPhysicalPage;
+ DPRINTM(DPRINT_MEMORY, "MmGetAddressablePageCountIncludingHoles() returning
0x%x\n", PageCount);
+ return PageCount;
}
PVOID MmFindLocationForPageLookupTable(ULONG TotalPageCount)
@@ -260,7 +275,7 @@
// We will go through and mark pages again according to the memory map
// But this will mark any holes not described in the map as allocated
//
- MmMarkPagesInLookupTable(PageLookupTable, 0, TotalPageCount,
LoaderFirmwarePermanent);
+ MmMarkPagesInLookupTable(PageLookupTable, MmLowestPhysicalPage, TotalPageCount,
LoaderFirmwarePermanent);
//
// Parse the whole memory map
@@ -307,9 +322,9 @@
case MemorySpecialMemory:
{
//
- // Special reserved memory
- //
- MemoryMapPageAllocated = LoaderSpecialMemory;
+ // OS Loader Stack
+ //
+ MemoryMapPageAllocated = LoaderOsloaderStack;
break;
}
default:
@@ -343,6 +358,7 @@
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable =
(PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG Index;
+ StartPage -= MmLowestPhysicalPage;
for (Index=StartPage; Index<(StartPage+PageCount); Index++)
{
#if 0
@@ -362,6 +378,7 @@
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable =
(PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG Index;
+ StartPage -= MmLowestPhysicalPage;
for (Index=StartPage; Index<(StartPage+PageCount); Index++)
{
RealPageLookupTable[Index].PageAllocated = MemoryType;
@@ -416,7 +433,7 @@
if (AvailablePagesSoFar >= PagesNeeded)
{
- return Index;
+ return Index + MmLowestPhysicalPage;
}
}
}
@@ -438,7 +455,7 @@
if (AvailablePagesSoFar >= PagesNeeded)
{
- return Index - AvailablePagesSoFar + 1;
+ return Index - AvailablePagesSoFar + 1 + MmLowestPhysicalPage;
}
}
}
@@ -472,7 +489,7 @@
if (AvailablePagesSoFar >= PagesNeeded)
{
- return Index;
+ return Index + MmLowestPhysicalPage;
}
}
@@ -488,7 +505,7 @@
{
if (RealPageLookupTable[Index].PageAllocated == LoaderFree)
{
- LastFreePageHint = Index + 1;
+ LastFreePageHint = Index + 1 + MmLowestPhysicalPage;
break;
}
}
@@ -501,6 +518,7 @@
ULONG Index;
StartPage = MmGetPageNumberFromAddress(PageAddress);
+ StartPage -= MmLowestPhysicalPage;
// Make sure they aren't trying to go past the
// end of availabe memory