Author: fireball Date: Sat Oct 14 17:36:21 2006 New Revision: 24509
URL: http://svn.reactos.org/svn/reactos?rev=24509&view=rev Log: - Use loader memory types in memory allocation bitmap instead of 0 for free memory and 1 for allocated - Slightly change / add comments
Modified: trunk/reactos/boot/freeldr/freeldr/include/mm.h trunk/reactos/boot/freeldr/freeldr/mm/meminit.c trunk/reactos/boot/freeldr/freeldr/mm/mm.c
Modified: trunk/reactos/boot/freeldr/freeldr/include/mm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/mm.h (original) +++ trunk/reactos/boot/freeldr/freeldr/include/mm.h Sat Oct 14 17:36:21 2006 @@ -50,8 +50,8 @@
typedef struct { - ULONG PageAllocated; // Zero = free, non-zero = allocated - ULONG PageAllocationLength; // Number of pages allocated (or zero if this isn't the first page in the chain) + TYPE_OF_MEMORY PageAllocated; // Type of allocated memory (LoaderFree if this memory is free) + ULONG PageAllocationLength; // Number of pages allocated (or zero if this isn't the first page in the chain) } PACKED PAGE_LOOKUP_TABLE_ITEM, *PPAGE_LOOKUP_TABLE_ITEM;
// @@ -78,7 +78,7 @@ PVOID MmFindLocationForPageLookupTable(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MapCount); // Returns the address for a memory chunk big enough to hold the page lookup table (starts search from end of memory) VOID MmSortBiosMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MapCount); // Sorts the BIOS_MEMORY_MAP array so the first element corresponds to the first address in memory VOID MmInitPageLookupTable(PVOID PageLookupTable, ULONG TotalPageCount, PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MapCount); // Inits the page lookup table according to the memory types in the memory map -VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount, ULONG PageAllocated); // Marks the specified pages as allocated or free in the lookup table +VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount, TYPE_OF_MEMORY PageAllocated); // Marks the specified pages as allocated or free in the lookup table VOID MmAllocatePagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount); // Allocates the specified pages in the lookup table ULONG MmCountFreePagesInLookupTable(PVOID PageLookupTable, ULONG TotalPageCount); // Returns the number of free pages in the lookup table ULONG MmFindAvailablePages(PVOID PageLookupTable, ULONG TotalPageCount, ULONG PagesNeeded, BOOLEAN FromEnd); // Returns the page number of the first available page range from the beginning or end of memory
Modified: trunk/reactos/boot/freeldr/freeldr/mm/meminit.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/mem... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/mm/meminit.c (original) +++ trunk/reactos/boot/freeldr/freeldr/mm/meminit.c Sat Oct 14 17:36:21 2006 @@ -77,6 +77,7 @@ MmFixupSystemMemoryMap(BiosMemoryMap, &BiosMemoryMapEntryCount); }
+ // Find address for the page lookup table TotalPagesInLookupTable = MmGetAddressablePageCountIncludingHoles(BiosMemoryMap, BiosMemoryMapEntryCount); PageLookupTableAddress = MmFindLocationForPageLookupTable(BiosMemoryMap, BiosMemoryMapEntryCount); LastFreePageHint = TotalPagesInLookupTable; @@ -90,6 +91,7 @@ return FALSE; }
+ // Initialize the page lookup table MmInitPageLookupTable(PageLookupTableAddress, TotalPagesInLookupTable, BiosMemoryMap, BiosMemoryMapEntryCount); MmUpdateLastFreePageHint(PageLookupTableAddress, TotalPagesInLookupTable);
@@ -248,23 +250,23 @@ MemoryMapStartPage = MmGetPageNumberFromAddress((PVOID)(ULONG)BiosMemoryMap[Index].BaseAddress); MemoryMapEndPage = MmGetPageNumberFromAddress((PVOID)(ULONG)(BiosMemoryMap[Index].BaseAddress + BiosMemoryMap[Index].Length - 1)); MemoryMapPageCount = (MemoryMapEndPage - MemoryMapStartPage) + 1; - MemoryMapPageAllocated = (BiosMemoryMap[Index].Type == BiosMemoryUsable) ? 0 : BiosMemoryMap[Index].Type; + MemoryMapPageAllocated = (BiosMemoryMap[Index].Type == BiosMemoryUsable) ? LoaderFree : LoaderFirmwarePermanent;/*BiosMemoryMap[Index].Type*/; DbgPrint((DPRINT_MEMORY, "Marking pages as type %d: StartPage: %d PageCount: %d\n", MemoryMapPageAllocated, MemoryMapStartPage, MemoryMapPageCount)); MmMarkPagesInLookupTable(PageLookupTable, MemoryMapStartPage, MemoryMapPageCount, MemoryMapPageAllocated); }
// Mark the low memory region below 1MB as reserved (256 pages in region) DbgPrint((DPRINT_MEMORY, "Marking the low 1MB region as reserved.\n")); - MmMarkPagesInLookupTable(PageLookupTable, 0, 256, BiosMemoryReserved); - - // Mark the pages that the lookup tabel occupies as reserved + MmMarkPagesInLookupTable(PageLookupTable, 0, 256, LoaderFirmwarePermanent); + + // Mark the pages that the lookup table occupies as reserved PageLookupTableStartPage = MmGetPageNumberFromAddress(PageLookupTable); PageLookupTablePageCount = MmGetPageNumberFromAddress((PVOID)((ULONG_PTR)PageLookupTable + ROUND_UP(TotalPageCount * sizeof(PAGE_LOOKUP_TABLE_ITEM), MM_PAGE_SIZE))) - PageLookupTableStartPage; DbgPrint((DPRINT_MEMORY, "Marking the page lookup table pages as reserved StartPage: %d PageCount: %d\n", PageLookupTableStartPage, PageLookupTablePageCount)); - MmMarkPagesInLookupTable(PageLookupTable, PageLookupTableStartPage, PageLookupTablePageCount, BiosMemoryReserved); -} - -VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount, ULONG PageAllocated) + MmMarkPagesInLookupTable(PageLookupTable, PageLookupTableStartPage, PageLookupTablePageCount, LoaderFirmwareTemporary); +} + +VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount, TYPE_OF_MEMORY PageAllocated) { PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable; ULONG Index; @@ -276,7 +278,7 @@ DbgPrint((DPRINT_MEMORY, "Index = %d StartPage = %d PageCount = %d\n", Index, StartPage, PageCount)); } RealPageLookupTable[Index].PageAllocated = PageAllocated; - RealPageLookupTable[Index].PageAllocationLength = PageAllocated ? 1 : 0; + RealPageLookupTable[Index].PageAllocationLength = (PageAllocated != LoaderFree) ? 1 : 0; } DbgPrint((DPRINT_MEMORY, "MmMarkPagesInLookupTable() Done\n")); } @@ -288,7 +290,7 @@
for (Index=StartPage; Index<(StartPage+PageCount); Index++) { - RealPageLookupTable[Index].PageAllocated = 1; + RealPageLookupTable[Index].PageAllocated = LoaderSystemCode; RealPageLookupTable[Index].PageAllocationLength = (Index == StartPage) ? PageCount : 0; } } @@ -302,7 +304,7 @@ FreePageCount = 0; for (Index=0; Index<TotalPageCount; Index++) { - if (RealPageLookupTable[Index].PageAllocated == 0) + if (RealPageLookupTable[Index].PageAllocated == LoaderFree) { FreePageCount++; } @@ -328,7 +330,7 @@ /* Allocate "high" (from end) pages */ for (Index=LastFreePageHint-1; Index>0; Index--) { - if (RealPageLookupTable[Index].PageAllocated != 0) + if (RealPageLookupTable[Index].PageAllocated != LoaderFree) { AvailablePagesSoFar = 0; continue; @@ -350,7 +352,7 @@ /* Allocate "low" pages */ for (Index=1; Index < LastFreePageHint; Index++) { - if (RealPageLookupTable[Index].PageAllocated != 0) + if (RealPageLookupTable[Index].PageAllocated != LoaderFree) { AvailablePagesSoFar = 0; continue; @@ -384,7 +386,7 @@ AvailablePagesSoFar = 0; for (Index=LastPage-1; Index>0; Index--) { - if (RealPageLookupTable[Index].PageAllocated != 0) + if (RealPageLookupTable[Index].PageAllocated != LoaderFree) { AvailablePagesSoFar = 0; continue; @@ -434,7 +436,7 @@
for (Index=TotalPageCount-1; Index>0; Index--) { - if (RealPageLookupTable[Index].PageAllocated == 0) + if (RealPageLookupTable[Index].PageAllocated == LoaderFree) { LastFreePageHint = Index + 1; break; @@ -461,7 +463,7 @@ { // If this page is allocated then there obviously isn't // memory availabe so return FALSE - if (RealPageLookupTable[Index].PageAllocated != 0) + if (RealPageLookupTable[Index].PageAllocated != LoaderFree) { return FALSE; }
Modified: trunk/reactos/boot/freeldr/freeldr/mm/mm.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/mm.... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/mm/mm.c (original) +++ trunk/reactos/boot/freeldr/freeldr/mm/mm.c Sat Oct 14 17:36:21 2006 @@ -271,7 +271,7 @@ // to make sure they are allocated with a length of 0 for (Idx=PageNumber+1; Idx<(PageNumber + PageCount); Idx++) { - if ((RealPageLookupTable[Idx].PageAllocated != 1) || + if ((RealPageLookupTable[Idx].PageAllocated == LoaderFree) || (RealPageLookupTable[Idx].PageAllocationLength != 0)) { BugCheck((DPRINT_MEMORY, "Invalid page entry in lookup table, PageAllocated should = 1 and PageAllocationLength should = 0 because this is not the first block in the run. PageLookupTable[%d].PageAllocated = %d PageLookupTable[%d].PageAllocationLength = %d\n", PageNumber, RealPageLookupTable[PageNumber].PageAllocated, PageNumber, RealPageLookupTable[PageNumber].PageAllocationLength)); @@ -291,7 +291,7 @@ // blocks as free for (Idx=PageNumber; Idx<(PageNumber + PageCount); Idx++) { - RealPageLookupTable[Idx].PageAllocated = 0; + RealPageLookupTable[Idx].PageAllocated = LoaderFree; RealPageLookupTable[Idx].PageAllocationLength = 0; }
@@ -322,7 +322,7 @@ for (Idx=0; Idx<TotalPagesInLookupTable; Idx++) { // Check if this block is allocated - if (RealPageLookupTable[Idx].PageAllocated != 0) + if (RealPageLookupTable[Idx].PageAllocated != LoaderFree) { // This is the first block in the run so it // had better have a length that is within range @@ -339,7 +339,7 @@ for (Idx2=1; Idx2<Count; Idx2++) { // Make sure it's allocated - if (RealPageLookupTable[Idx + Idx2].PageAllocated == 0) + if (RealPageLookupTable[Idx + Idx2].PageAllocated == LoaderFree) { BugCheck((DPRINT_MEMORY, "Lookup table indicates hole in memory allocation. RealPageLookupTable[Idx + Idx2].PageAllocated == 0\n")); } @@ -386,23 +386,53 @@
switch (RealPageLookupTable[Idx].PageAllocated) { - case 0: + case LoaderFree: DbgPrint((DPRINT_MEMORY, "*")); break; - case 1: - DbgPrint((DPRINT_MEMORY, "A")); - break; - case BiosMemoryReserved: + case LoaderBad: + DbgPrint((DPRINT_MEMORY, "-")); + break; + case LoaderLoadedProgram: + DbgPrint((DPRINT_MEMORY, "O")); + break; + case LoaderFirmwareTemporary: + DbgPrint((DPRINT_MEMORY, "T")); + break; + case LoaderFirmwarePermanent: + DbgPrint((DPRINT_MEMORY, "P")); + break; + case LoaderOsloaderHeap: + DbgPrint((DPRINT_MEMORY, "H")); + break; + case LoaderOsloaderStack: + DbgPrint((DPRINT_MEMORY, "S")); + break; + case LoaderSystemCode: + DbgPrint((DPRINT_MEMORY, "K")); + break; + case LoaderHalCode: + DbgPrint((DPRINT_MEMORY, "L")); + break; + case LoaderBootDriver: + DbgPrint((DPRINT_MEMORY, "B")); + break; + case LoaderStartupPcrPage: + DbgPrint((DPRINT_MEMORY, "G")); + break; + case LoaderRegistryData: DbgPrint((DPRINT_MEMORY, "R")); break; - case BiosMemoryAcpiReclaim: + case LoaderMemoryData: DbgPrint((DPRINT_MEMORY, "M")); break; - case BiosMemoryAcpiNvs: + case LoaderNlsData: DbgPrint((DPRINT_MEMORY, "N")); break; + case LoaderSpecialMemory: + DbgPrint((DPRINT_MEMORY, "C")); + break; default: - DbgPrint((DPRINT_MEMORY, "X")); + DbgPrint((DPRINT_MEMORY, "?")); break; } }