[FREELDR]

- Use TYPE_OF_MEMORY from the beginning instead of MEMORY_TYPE and later converting it.
- Disable tracing, accidentally comitted in previous revision

svn path=/trunk/; revision=53818
This commit is contained in:
Timo Kreuzer 2011-09-23 20:09:54 +00:00
parent 2fd4c9a560
commit 551ca94879
5 changed files with 64 additions and 171 deletions

View file

@ -1,5 +1,4 @@
/* $Id$ /*
*
* FreeLoader * FreeLoader
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -47,16 +46,16 @@ ULONG PcBiosMapCount;
MEMORY_DESCRIPTOR PcMemoryMap[MAX_BIOS_DESCRIPTORS + 1] = MEMORY_DESCRIPTOR PcMemoryMap[MAX_BIOS_DESCRIPTORS + 1] =
{ {
{ MemoryFirmwarePermanent, 0x00, 1 }, // realmode int vectors { LoaderFirmwarePermanent, 0x00, 1 }, // realmode int vectors
{ MemoryFirmwareTemporary, 0x01, FREELDR_BASE_PAGE - 1 }, // freeldr stack + cmdline { LoaderFirmwareTemporary, 0x01, FREELDR_BASE_PAGE - 1 }, // freeldr stack + cmdline
{ MemoryLoadedProgram, FREELDR_BASE_PAGE, FREELDR_PAGE_COUNT }, // freeldr image { LoaderLoadedProgram, FREELDR_BASE_PAGE, FREELDR_PAGE_COUNT }, // freeldr image
{ MemoryFirmwareTemporary, FILEBUF_BASE_PAGE, FILEBUF_PAGE_COUNT }, // File system read buffer. FILESYSBUFFER { LoaderFirmwareTemporary, FILEBUF_BASE_PAGE, FILEBUF_PAGE_COUNT }, // File system read buffer. FILESYSBUFFER
{ MemoryFirmwareTemporary, DISKBUF_BASE_PAGE, DISKBUF_PAGE_COUNT }, // Disk read buffer for int 13h. DISKREADBUFFER { LoaderFirmwareTemporary, DISKBUF_BASE_PAGE, DISKBUF_PAGE_COUNT }, // Disk read buffer for int 13h. DISKREADBUFFER
{ MemorySpecialMemory, STACK_BASE_PAGE, STACK_PAGE_COUNT }, // prot mode stack. { LoaderOsloaderStack, STACK_BASE_PAGE, STACK_PAGE_COUNT }, // prot mode stack.
{ MemoryFirmwareTemporary, BIOSBUF_BASE_PAGE, BIOSBUF_PAGE_COUNT }, // BIOSCALLBUFFER { LoaderFirmwareTemporary, BIOSBUF_BASE_PAGE, BIOSBUF_PAGE_COUNT }, // BIOSCALLBUFFER
{ MemoryFirmwarePermanent, 0xA0, 0x60 }, // ROM / Video { LoaderFirmwarePermanent, 0xA0, 0x60 }, // ROM / Video
{ MemorySpecialMemory, 0xFFF, 1 }, // unusable memory { LoaderSpecialMemory, 0xFFF, 1 }, // unusable memory
{ MemorySpecialMemory, MAXULONG_PTR, 0 }, // end of map { 0, 0, 0 }, // end of map
}; };
ULONG ULONG
@ -65,7 +64,7 @@ AddMemoryDescriptor(
IN ULONG MaxCount, IN ULONG MaxCount,
IN PFN_NUMBER BasePage, IN PFN_NUMBER BasePage,
IN PFN_NUMBER PageCount, IN PFN_NUMBER PageCount,
IN MEMORY_TYPE MemoryType); IN TYPE_OF_MEMORY MemoryType);
static static
BOOLEAN BOOLEAN
@ -261,12 +260,12 @@ PcMemGetBiosMemoryMap(PMEMORY_DESCRIPTOR MemoryMap, ULONG MaxMemoryMapSize)
/* Check if we can add this descriptor */ /* Check if we can add this descriptor */
if ((RealSize >= MM_PAGE_SIZE) && (MapCount < MaxMemoryMapSize)) if ((RealSize >= MM_PAGE_SIZE) && (MapCount < MaxMemoryMapSize))
{ {
MEMORY_TYPE MemoryType; TYPE_OF_MEMORY MemoryType;
if (PcBiosMemoryMap[PcBiosMapCount].Type == BiosMemoryUsable) if (PcBiosMemoryMap[PcBiosMapCount].Type == BiosMemoryUsable)
MemoryType = MemoryFree; MemoryType = LoaderFree;
else else
MemoryType = MemoryFirmwarePermanent; MemoryType = LoaderFirmwarePermanent;
/* Add the descriptor */ /* Add the descriptor */
MapCount = AddMemoryDescriptor(PcMemoryMap, MapCount = AddMemoryDescriptor(PcMemoryMap,
@ -312,14 +311,14 @@ PcMemGetMemoryMap(ULONG *MemoryMapSize)
MAX_BIOS_DESCRIPTORS, MAX_BIOS_DESCRIPTORS,
0, 0,
PcMemGetConventionalMemorySize() * 1024 / PAGE_SIZE, PcMemGetConventionalMemorySize() * 1024 / PAGE_SIZE,
MemoryFree); LoaderFree);
/* Extended memory */ /* Extended memory */
EntryCount = AddMemoryDescriptor(PcMemoryMap, EntryCount = AddMemoryDescriptor(PcMemoryMap,
MAX_BIOS_DESCRIPTORS, MAX_BIOS_DESCRIPTORS,
1024 * 1024 / PAGE_SIZE, 1024 * 1024 / PAGE_SIZE,
ExtendedMemorySizeAtOneMB * 1024 / PAGE_SIZE, ExtendedMemorySizeAtOneMB * 1024 / PAGE_SIZE,
MemoryFree); LoaderFree);
EntryCount++; EntryCount++;
if (ExtendedMemorySizeAtSixteenMB != 0) if (ExtendedMemorySizeAtSixteenMB != 0)
@ -329,7 +328,7 @@ PcMemGetMemoryMap(ULONG *MemoryMapSize)
MAX_BIOS_DESCRIPTORS, MAX_BIOS_DESCRIPTORS,
0x1000000 / PAGE_SIZE, 0x1000000 / PAGE_SIZE,
ExtendedMemorySizeAtSixteenMB * 64 * 1024 / PAGE_SIZE, ExtendedMemorySizeAtSixteenMB * 64 * 1024 / PAGE_SIZE,
MemoryFree); LoaderFree);
} }
} }

View file

@ -84,12 +84,12 @@ XboxMemGetMemoryMap(ULONG *MemoryMapSize)
/* Available RAM block */ /* Available RAM block */
BiosMemoryMap[0].BasePage = 0; BiosMemoryMap[0].BasePage = 0;
BiosMemoryMap[0].PageCount = AvailableMemoryMb * 1024 * 1024 / MM_PAGE_SIZE; BiosMemoryMap[0].PageCount = AvailableMemoryMb * 1024 * 1024 / MM_PAGE_SIZE;
BiosMemoryMap[0].MemoryType = MemoryFree; BiosMemoryMap[0].MemoryType = LoaderFree;
/* Video memory */ /* Video memory */
BiosMemoryMap[1].BasePage = AvailableMemoryMb * 1024 * 1024 / MM_PAGE_SIZE; BiosMemoryMap[1].BasePage = AvailableMemoryMb * 1024 * 1024 / MM_PAGE_SIZE;
BiosMemoryMap[1].PageCount = (InstalledMemoryMb - AvailableMemoryMb) * 1024 * 1024 / MM_PAGE_SIZE; BiosMemoryMap[1].PageCount = (InstalledMemoryMb - AvailableMemoryMb) * 1024 * 1024 / MM_PAGE_SIZE;
BiosMemoryMap[1].MemoryType = MemoryFirmwarePermanent; BiosMemoryMap[1].MemoryType = LoaderFirmwarePermanent;
*MemoryMapSize = 2; *MemoryMapSize = 2;
return BiosMemoryMap; return BiosMemoryMap;

View file

@ -26,7 +26,7 @@
//#define DEBUG_ALL //#define DEBUG_ALL
//#define DEBUG_INIFILE //#define DEBUG_INIFILE
//#define DEBUG_REACTOS //#define DEBUG_REACTOS
#define DEBUG_CUSTOM //#define DEBUG_CUSTOM
#define DEBUG_NONE #define DEBUG_NONE
#if defined (DEBUG_ALL) #if defined (DEBUG_ALL)
@ -38,7 +38,7 @@ ULONG DebugPrintMask = DPRINT_INIFILE;
#elif defined (DEBUG_REACTOS) #elif defined (DEBUG_REACTOS)
ULONG DebugPrintMask = DPRINT_REACTOS | DPRINT_REGISTRY; ULONG DebugPrintMask = DPRINT_REACTOS | DPRINT_REGISTRY;
#elif defined (DEBUG_CUSTOM) #elif defined (DEBUG_CUSTOM)
ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY; ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_WINDOWS;
#else //#elif defined (DEBUG_NONE) #else //#elif defined (DEBUG_NONE)
ULONG DebugPrintMask = 0; ULONG DebugPrintMask = 0;
#endif #endif

View file

@ -89,7 +89,7 @@ extern ULONG FreePagesInLookupTable;
extern ULONG LastFreePageHint; extern ULONG LastFreePageHint;
#if DBG #if DBG
PCSTR MmGetSystemMemoryMapTypeString(MEMORY_TYPE Type); PCSTR MmGetSystemMemoryMapTypeString(TYPE_OF_MEMORY Type);
#endif #endif
ULONG MmGetPageNumberFromAddress(PVOID Address); // Returns the page number that contains a linear address ULONG MmGetPageNumberFromAddress(PVOID Address); // Returns the page number that contains a linear address

View file

@ -26,22 +26,28 @@ DBG_DEFAULT_CHANNEL(MEMORY);
#if DBG #if DBG
typedef struct typedef struct
{ {
MEMORY_TYPE Type; TYPE_OF_MEMORY Type;
PCSTR TypeString; PCSTR TypeString;
} FREELDR_MEMORY_TYPE, *PFREELDR_MEMORY_TYPE; } FREELDR_MEMORY_TYPE, *PFREELDR_MEMORY_TYPE;
FREELDR_MEMORY_TYPE MemoryTypeArray[] = FREELDR_MEMORY_TYPE MemoryTypeArray[] =
{ {
{ MemoryMaximum, "Unknown memory" }, { LoaderMaximum, "Unknown memory" },
{ MemoryExceptionBlock, "Exception block" }, { LoaderFree, "Free memory" },
{ MemorySystemBlock, "System block" }, { LoaderBad, "Bad memory" },
{ MemoryFree, "Free memory" }, { LoaderLoadedProgram, "LoadedProgram" },
{ MemoryBad, "Bad memory" }, { LoaderFirmwareTemporary, "FirmwareTemporary" },
{ MemoryLoadedProgram, "Loaded program" }, { LoaderFirmwarePermanent, "FirmwarePermanent" },
{ MemoryFirmwareTemporary, "Firmware temporary" }, { LoaderOsloaderHeap, "OsloaderHeap" },
{ MemoryFirmwarePermanent, "Firmware permanent" }, { LoaderOsloaderStack, "OsloaderStack" },
{ MemoryFreeContiguous, "Free contiguous memory" }, { LoaderSystemCode, "SystemCode" },
{ MemorySpecialMemory, "Special memory" }, { LoaderHalCode, "HalCode" },
{ LoaderBootDriver, "BootDriver" },
{ LoaderRegistryData, "RegistryData" },
{ LoaderMemoryData, "MemoryData" },
{ LoaderNlsData, "NlsData" },
{ LoaderSpecialMemory, "SpecialMemory" },
{ LoaderReserve, "Reserve" },
}; };
ULONG MemoryTypeCount = sizeof(MemoryTypeArray) / sizeof(MemoryTypeArray[0]); ULONG MemoryTypeCount = sizeof(MemoryTypeArray) / sizeof(MemoryTypeArray[0]);
#endif #endif
@ -196,28 +202,10 @@ BOOLEAN MmInitializeMemoryManager(VOID)
// Initialize the page lookup table // Initialize the page lookup table
MmInitPageLookupTable(PageLookupTableAddress, TotalPagesInLookupTable); MmInitPageLookupTable(PageLookupTableAddress, TotalPagesInLookupTable);
{
ULONG Type, Index, PrevIndex = 0;
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTableAddress;
Type = RealPageLookupTable[0].PageAllocated;
for (Index = 1; Index < TotalPagesInLookupTable; Index++)
{
if ((RealPageLookupTable[Index].PageAllocated != Type) ||
(Index == TotalPagesInLookupTable - 1))
{
TRACE("Range: 0x%lx - 0x%lx Type=%d\n",
PrevIndex, Index - 1, Type);
Type = RealPageLookupTable[Index].PageAllocated;
PrevIndex = Index;
}
}
}
MmUpdateLastFreePageHint(PageLookupTableAddress, TotalPagesInLookupTable); MmUpdateLastFreePageHint(PageLookupTableAddress, TotalPagesInLookupTable);
FreePagesInLookupTable = MmCountFreePagesInLookupTable(PageLookupTableAddress, TotalPagesInLookupTable); FreePagesInLookupTable = MmCountFreePagesInLookupTable(PageLookupTableAddress,
TotalPagesInLookupTable);
MmInitializeHeap(PageLookupTableAddress); MmInitializeHeap(PageLookupTableAddress);
@ -228,7 +216,7 @@ BOOLEAN MmInitializeMemoryManager(VOID)
} }
#if DBG #if DBG
PCSTR MmGetSystemMemoryMapTypeString(MEMORY_TYPE Type) PCSTR MmGetSystemMemoryMapTypeString(TYPE_OF_MEMORY Type)
{ {
ULONG Index; ULONG Index;
@ -267,7 +255,7 @@ ULONG MmGetAddressablePageCountIncludingHoles(VOID)
// //
// Yes, remember it if this is real memory // Yes, remember it if this is real memory
// //
if (MemoryDescriptor->MemoryType == MemoryFree) MmHighestPhysicalPage = MemoryDescriptor->BasePage + MemoryDescriptor->PageCount; if (MemoryDescriptor->MemoryType == LoaderFree) MmHighestPhysicalPage = MemoryDescriptor->BasePage + MemoryDescriptor->PageCount;
} }
// //
@ -296,64 +284,26 @@ PVOID MmFindLocationForPageLookupTable(ULONG TotalPageCount)
ULONG PageLookupTableStartPage = 0; ULONG PageLookupTableStartPage = 0;
PVOID PageLookupTableMemAddress = NULL; PVOID PageLookupTableMemAddress = NULL;
//
// Calculate how much pages we need to keep the page lookup table // Calculate how much pages we need to keep the page lookup table
//
PageLookupTableSize = TotalPageCount * sizeof(PAGE_LOOKUP_TABLE_ITEM); PageLookupTableSize = TotalPageCount * sizeof(PAGE_LOOKUP_TABLE_ITEM);
PageLookupTablePages = PageLookupTableSize / MM_PAGE_SIZE; PageLookupTablePages = PageLookupTableSize / MM_PAGE_SIZE;
//
// Search the highest memory block big enough to contain lookup table // Search the highest memory block big enough to contain lookup table
//
while ((MemoryDescriptor = ArcGetMemoryDescriptor(MemoryDescriptor)) != NULL) while ((MemoryDescriptor = ArcGetMemoryDescriptor(MemoryDescriptor)) != NULL)
{ {
// // Continue, if memory is not free
// Is it suitable memory? if (MemoryDescriptor->MemoryType != LoaderFree) continue;
//
if (MemoryDescriptor->MemoryType != MemoryFree)
{
//
// No. Process next descriptor
//
continue;
}
// // Continue, if the block is not big enough?
// Is the block big enough? if (MemoryDescriptor->PageCount < PageLookupTablePages) continue;
//
if (MemoryDescriptor->PageCount < PageLookupTablePages)
{
//
// No. Process next descriptor
//
continue;
}
// // Continue, if it is not at a higher address than previous address
// Is it at a higher address than previous suitable address? if (MemoryDescriptor->BasePage < PageLookupTableStartPage) continue;
//
if (MemoryDescriptor->BasePage < PageLookupTableStartPage)
{
//
// No. Process next descriptor
//
continue;
}
// // Continue, if the address is too high
// Can we use this address? if (MemoryDescriptor->BasePage >= MM_MAX_PAGE) continue;
//
if (MemoryDescriptor->BasePage >= MM_MAX_PAGE)
{
//
// No. Process next descriptor
//
continue;
}
//
// Memory block is more suitable than the previous one // Memory block is more suitable than the previous one
//
PageLookupTableStartPage = MemoryDescriptor->BasePage; PageLookupTableStartPage = MemoryDescriptor->BasePage;
PageLookupTableMemAddress = (PVOID)((ULONG_PTR) PageLookupTableMemAddress = (PVOID)((ULONG_PTR)
(MemoryDescriptor->BasePage + MemoryDescriptor->PageCount) * MM_PAGE_SIZE (MemoryDescriptor->BasePage + MemoryDescriptor->PageCount) * MM_PAGE_SIZE
@ -374,87 +324,31 @@ VOID MmInitPageLookupTable(PVOID PageLookupTable, ULONG TotalPageCount)
TRACE("MmInitPageLookupTable()\n"); TRACE("MmInitPageLookupTable()\n");
//
// Mark every page as allocated initially // Mark every page as allocated initially
// We will go through and mark pages again according to the memory map // 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 // But this will mark any holes not described in the map as allocated
//
MmMarkPagesInLookupTable(PageLookupTable, MmLowestPhysicalPage, TotalPageCount, LoaderFirmwarePermanent); MmMarkPagesInLookupTable(PageLookupTable, MmLowestPhysicalPage, TotalPageCount, LoaderFirmwarePermanent);
//
// Parse the whole memory map // Parse the whole memory map
//
while ((MemoryDescriptor = ArcGetMemoryDescriptor(MemoryDescriptor)) != NULL) while ((MemoryDescriptor = ArcGetMemoryDescriptor(MemoryDescriptor)) != NULL)
{ {
TRACE("Got range: 0x%lx-0x%lx, type=%s\n", TRACE("Got range: 0x%lx-0x%lx, type=%s\n",
MemoryDescriptor->BasePage, MemoryDescriptor->BasePage,
MemoryDescriptor->BasePage + MemoryDescriptor->PageCount, MemoryDescriptor->BasePage + MemoryDescriptor->PageCount,
MmGetSystemMemoryMapTypeString(MemoryDescriptor->MemoryType)); MmGetSystemMemoryMapTypeString(MemoryDescriptor->MemoryType));
//
// Convert ARC memory type to loader memory type
//
switch (MemoryDescriptor->MemoryType)
{
case MemoryFree:
{
//
// Allocatable memory
//
MemoryMapPageAllocated = LoaderFree;
break;
}
case MemoryFirmwarePermanent:
{
//
// Firmware permanent memory
//
MemoryMapPageAllocated = LoaderFirmwarePermanent;
break;
}
case MemoryFirmwareTemporary:
{
//
// Firmware temporary memory
//
MemoryMapPageAllocated = LoaderFirmwareTemporary;
break;
}
case MemoryLoadedProgram:
{
//
// Bootloader code
//
MemoryMapPageAllocated = LoaderLoadedProgram;
break;
}
case MemorySpecialMemory:
{
//
// OS Loader Stack
//
MemoryMapPageAllocated = LoaderOsloaderStack;
break;
}
default:
{
//
// Put something sensible here, which won't be overwritten
//
MemoryMapPageAllocated = LoaderSpecialMemory;
break;
}
}
// MemoryMapPageAllocated = MemoryDescriptor->MemoryType;
// Mark used pages in the lookup table // Mark used pages in the lookup table
// TRACE("Marking pages as type %d: StartPage: %d PageCount: %d\n",
TRACE("Marking pages as type %d: StartPage: %d PageCount: %d\n", MemoryMapPageAllocated, MemoryDescriptor->BasePage, MemoryDescriptor->PageCount); MemoryMapPageAllocated, MemoryDescriptor->BasePage, MemoryDescriptor->PageCount);
MmMarkPagesInLookupTable(PageLookupTable, MemoryDescriptor->BasePage, MemoryDescriptor->PageCount, MemoryMapPageAllocated); MmMarkPagesInLookupTable(PageLookupTable,
MemoryDescriptor->BasePage,
MemoryDescriptor->PageCount,
MemoryMapPageAllocated);
} }
//
// Mark the pages that the lookup table occupies as reserved // Mark the pages that the lookup table occupies as reserved
//
PageLookupTableStartPage = MmGetPageNumberFromAddress(PageLookupTable); PageLookupTableStartPage = MmGetPageNumberFromAddress(PageLookupTable);
PageLookupTablePageCount = MmGetPageNumberFromAddress((PVOID)((ULONG_PTR)PageLookupTable + ROUND_UP(TotalPageCount * sizeof(PAGE_LOOKUP_TABLE_ITEM), MM_PAGE_SIZE))) - PageLookupTableStartPage; PageLookupTablePageCount = MmGetPageNumberFromAddress((PVOID)((ULONG_PTR)PageLookupTable + ROUND_UP(TotalPageCount * sizeof(PAGE_LOOKUP_TABLE_ITEM), MM_PAGE_SIZE))) - PageLookupTableStartPage;
TRACE("Marking the page lookup table pages as reserved StartPage: %d PageCount: %d\n", PageLookupTableStartPage, PageLookupTablePageCount); TRACE("Marking the page lookup table pages as reserved StartPage: %d PageCount: %d\n", PageLookupTableStartPage, PageLookupTablePageCount);
@ -515,9 +409,9 @@ ULONG MmCountFreePagesInLookupTable(PVOID PageLookupTable, ULONG TotalPageCount)
ULONG MmFindAvailablePages(PVOID PageLookupTable, ULONG TotalPageCount, ULONG PagesNeeded, BOOLEAN FromEnd) ULONG MmFindAvailablePages(PVOID PageLookupTable, ULONG TotalPageCount, ULONG PagesNeeded, BOOLEAN FromEnd)
{ {
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable; PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG AvailablePagesSoFar; ULONG AvailablePagesSoFar;
ULONG Index; ULONG Index;
if (LastFreePageHint > TotalPageCount) if (LastFreePageHint > TotalPageCount)
{ {
@ -639,7 +533,7 @@ BOOLEAN MmAreMemoryPagesAvailable(PVOID PageLookupTable, ULONG TotalPageCount, P
return FALSE; return FALSE;
} }
for (Index=StartPage; Index<(StartPage + PageCount); Index++) for (Index = StartPage; Index < (StartPage + PageCount); Index++)
{ {
// If this page is allocated then there obviously isn't // If this page is allocated then there obviously isn't
// memory availabe so return FALSE // memory availabe so return FALSE