Author: fireball
Date: Sat Dec 9 19:54:37 2006
New Revision: 25103
URL: http://svn.reactos.org/svn/reactos?rev=25103&view=rev
Log:
- MM: Don't place memory allocation bitmap right into the first 16Mb of memory - revert back to the old algorithm, which places it as high as possible
- MM: Mark space under the mem alloc bitmap as free right before going to virtual mode, thus it doesn't get mapped
- Save NT version which user wants to boot in the extension
Modified:
branches/winldr/mm/meminit.c
branches/winldr/mm/mm.c
branches/winldr/windows/winldr.c
branches/winldr/windows/wlmemory.c
Modified: branches/winldr/mm/meminit.c
URL: http://svn.reactos.org/svn/reactos/branches/winldr/mm/meminit.c?rev=25103&r…
==============================================================================
--- branches/winldr/mm/meminit.c (original)
+++ branches/winldr/mm/meminit.c Sat Dec 9 19:54:37 2006
@@ -1,6 +1,7 @@
/*
* FreeLoader
- * Copyright (C) 1998-2003 Brian Palmer <brianp(a)sginet.com>
+ * Copyright (C) 1998-2003 Brian Palmer <brianp(a)sginet.com>
+ * Copyright (C) 2006 Aleksey Bragin <aleksey(a)reactos.org>
*
* 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
@@ -211,47 +212,22 @@
RtlCopyMemory(TempBiosMemoryMap, BiosMemoryMap, sizeof(BIOS_MEMORY_MAP) * 32);
MmSortBiosMemoryMap(TempBiosMemoryMap, MapCount);
- for (Index=0; Index<MapCount; Index++)
+ // Find a place, starting from the highest memory
+ // (thus leaving low memory for kernel/drivers)
+ for (Index=(MapCount-1); Index>=0; Index--)
{
// If this is usable memory with a big enough length
// then we'll put our page lookup table here
-
- // place it somewhere @ 10Mb if possible
- // (afaik no bad things are placed at 10Mb, if there are
- // - we just fallback to the usual algo)
// skip if this is not usable region
if (TempBiosMemoryMap[Index].Type != BiosMemoryUsable)
continue;
- if (TempBiosMemoryMap[Index].BaseAddress <= 10 * 0x100000 &&
- TempBiosMemoryMap[Index].BaseAddress + TempBiosMemoryMap[Index].Length >=
- 10 * 0x100000 + PageLookupTableSize)
- {
- PageLookupTableMemAddress = (PVOID)(10 * 0x100000);
+ if (TempBiosMemoryMap[Index].Length >= PageLookupTableSize)
+ {
+ PageLookupTableMemAddress = (PVOID)(ULONG)
+ (TempBiosMemoryMap[Index].BaseAddress + (TempBiosMemoryMap[Index].Length - PageLookupTableSize));
break;
- }
- }
-
- // Check if we found a suitable place
- if (PageLookupTableMemAddress == 0)
- {
- // no, let's do a traditional algorithm instead
- for (Index=(MapCount-1); Index>=0; Index--)
- {
- // If this is usable memory with a big enough length
- // then we'll put our page lookup table here
-
- // skip if this is not usable region
- if (TempBiosMemoryMap[Index].Type != BiosMemoryUsable)
- continue;
-
- if (TempBiosMemoryMap[Index].Length >= PageLookupTableSize)
- {
- PageLookupTableMemAddress = (PVOID)(ULONG)
- (TempBiosMemoryMap[Index].BaseAddress + (TempBiosMemoryMap[Index].Length - PageLookupTableSize));
- break;
- }
}
}
Modified: branches/winldr/mm/mm.c
URL: http://svn.reactos.org/svn/reactos/branches/winldr/mm/mm.c?rev=25103&r1=251…
==============================================================================
--- branches/winldr/mm/mm.c (original)
+++ branches/winldr/mm/mm.c Sat Dec 9 19:54:37 2006
@@ -1,6 +1,7 @@
/*
* FreeLoader
- * Copyright (C) 1998-2003 Brian Palmer <brianp(a)sginet.com>
+ * Copyright (C) 1998-2003 Brian Palmer <brianp(a)sginet.com>
+ * Copyright (C) 2006 Aleksey Bragin <aleksey(a)reactos.org>
*
* 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
Modified: branches/winldr/windows/winldr.c
URL: http://svn.reactos.org/svn/reactos/branches/winldr/windows/winldr.c?rev=251…
==============================================================================
--- branches/winldr/windows/winldr.c (original)
+++ branches/winldr/windows/winldr.c Sat Dec 9 19:54:37 2006
@@ -77,7 +77,8 @@
VOID
WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
PCHAR Options,
- PCHAR SystemPath)
+ PCHAR SystemPath,
+ WORD VersionToBoot)
{
/* Examples of correct options and paths */
//CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200";
@@ -187,9 +188,10 @@
}
RtlZeroMemory(Extension, sizeof(LOADER_PARAMETER_EXTENSION));
+ /* Save size and version information */
Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION);
- Extension->MajorVersion = 4;
- Extension->MinorVersion = 0;
+ Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8;
+ Extension->MinorVersion = VersionToBoot & 0xFF;
LoaderBlock->Extension = PaToVa(Extension);
@@ -449,7 +451,7 @@
DbgPrint((DPRINT_WINDOWS, "HAL loaded with status %d at %p\n", Status, HalBase));
/* Load kernel-debugger support dll */
- if (OperatingSystemVersion > _WIN32_WINNT_NT4)
+ if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
{
strcpy(FileName, BootPath);
strcat(FileName, "SYSTEM32\\KDCOM.DLL");
@@ -462,7 +464,7 @@
"WINNT\\SYSTEM32\\NTOSKRNL.EXE", NtosBase, &KernelDTE);
WinLdrAllocateDataTableEntry(LoaderBlock, "hal.dll",
"WINNT\\SYSTEM32\\HAL.DLL", HalBase, &HalDTE);
- if (OperatingSystemVersion > _WIN32_WINNT_NT4)
+ if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
{
WinLdrAllocateDataTableEntry(LoaderBlock, "kdcom.dll",
"WINNT\\SYSTEM32\\KDCOM.DLL", KdComBase, &KdComDTE);
@@ -485,7 +487,7 @@
DbgPrint((DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status));
/* Initialize Phase 1 - no drivers loading anymore */
- WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemPath);
+ WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemPath, OperatingSystemVersion);
/* Alloc PCR, TSS, do magic things with the GDT/IDT */
WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
@@ -507,9 +509,9 @@
DbgPrint((DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
KiSystemStartup, LoaderBlockVA));
- //WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
- //WinLdrpDumpBootDriver(LoaderBlockVA);
- //WinLdrpDumpArcDisks(LoaderBlockVA);
+ WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
+ WinLdrpDumpBootDriver(LoaderBlockVA);
+ WinLdrpDumpArcDisks(LoaderBlockVA);
//FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below
//while (1) {};
Modified: branches/winldr/windows/wlmemory.c
URL: http://svn.reactos.org/svn/reactos/branches/winldr/windows/wlmemory.c?rev=2…
==============================================================================
--- branches/winldr/windows/wlmemory.c (original)
+++ branches/winldr/windows/wlmemory.c Sat Dec 9 19:54:37 2006
@@ -336,8 +336,8 @@
ULONG TssBasePage,
PVOID GdtIdt)
{
- ULONG i, PagesCount;
- ULONG LastPageIndex, LastPageType;
+ ULONG i, PagesCount, MemoryMapSizeInPages;
+ ULONG LastPageIndex, LastPageType, MemoryMapStartPage;
PPAGE_LOOKUP_TABLE_ITEM MemoryMap;
ULONG NoEntries;
PKTSS Tss;
@@ -378,6 +378,10 @@
return FALSE;
}
+ // Calculate parameters of the memory map
+ MemoryMapStartPage = (ULONG_PTR)MemoryMap >> MM_PAGE_SHIFT;
+ MemoryMapSizeInPages = NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM);
+
DbgPrint((DPRINT_WINDOWS, "Got memory map with %d entries\n", NoEntries));
// Always contigiously map low 1Mb of memory
@@ -388,12 +392,24 @@
return FALSE;
}
- // Construct a good memory map from what we've got
+ // Construct a good memory map from what we've got,
+ // but mark entries which the memory allocation bitmap takes
+ // as free entries (this is done in order to have the ability
+ // to place mem alloc bitmap outside lower 16Mb zone)
PagesCount = 1;
LastPageIndex = 0;
LastPageType = MemoryMap[0].PageAllocated;
for(i=1;i<NoEntries;i++)
{
+ // Check if its memory map itself
+ if (i >= MemoryMapStartPage &&
+ i < (MemoryMapStartPage+MemoryMapSizeInPages))
+ {
+ // Exclude it if current page belongs to the memory map
+ MemoryMap[i].PageAllocated = LoaderFree;
+ }
+
+ // Process entry
if (MemoryMap[i].PageAllocated == LastPageType &&
(i != NoEntries-1) )
{