Author: tkreuzer Date: Fri Sep 23 20:09:54 2011 New Revision: 53818
URL: http://svn.reactos.org/svn/reactos?rev=53818&view=rev Log: [FREELDR] - Use TYPE_OF_MEMORY from the beginning instead of MEMORY_TYPE and later converting it. - Disable tracing, accidentally comitted in previous revision
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxmem.c trunk/reactos/boot/freeldr/freeldr/debug.c trunk/reactos/boot/freeldr/freeldr/include/mm.h trunk/reactos/boot/freeldr/freeldr/mm/meminit.c
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c [iso-8859-1] Fri Sep 23 20:09:54 2011 @@ -1,5 +1,4 @@ -/* $Id$ - * +/* * FreeLoader * * This program is free software; you can redistribute it and/or modify @@ -47,16 +46,16 @@
MEMORY_DESCRIPTOR PcMemoryMap[MAX_BIOS_DESCRIPTORS + 1] = { - { MemoryFirmwarePermanent, 0x00, 1 }, // realmode int vectors - { MemoryFirmwareTemporary, 0x01, FREELDR_BASE_PAGE - 1 }, // freeldr stack + cmdline - { MemoryLoadedProgram, FREELDR_BASE_PAGE, FREELDR_PAGE_COUNT }, // freeldr image - { MemoryFirmwareTemporary, 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 - { MemorySpecialMemory, STACK_BASE_PAGE, STACK_PAGE_COUNT }, // prot mode stack. - { MemoryFirmwareTemporary, BIOSBUF_BASE_PAGE, BIOSBUF_PAGE_COUNT }, // BIOSCALLBUFFER - { MemoryFirmwarePermanent, 0xA0, 0x60 }, // ROM / Video - { MemorySpecialMemory, 0xFFF, 1 }, // unusable memory - { MemorySpecialMemory, MAXULONG_PTR, 0 }, // end of map + { LoaderFirmwarePermanent, 0x00, 1 }, // realmode int vectors + { LoaderFirmwareTemporary, 0x01, FREELDR_BASE_PAGE - 1 }, // freeldr stack + cmdline + { LoaderLoadedProgram, FREELDR_BASE_PAGE, FREELDR_PAGE_COUNT }, // freeldr image + { LoaderFirmwareTemporary, FILEBUF_BASE_PAGE, FILEBUF_PAGE_COUNT }, // File system read buffer. FILESYSBUFFER + { LoaderFirmwareTemporary, DISKBUF_BASE_PAGE, DISKBUF_PAGE_COUNT }, // Disk read buffer for int 13h. DISKREADBUFFER + { LoaderOsloaderStack, STACK_BASE_PAGE, STACK_PAGE_COUNT }, // prot mode stack. + { LoaderFirmwareTemporary, BIOSBUF_BASE_PAGE, BIOSBUF_PAGE_COUNT }, // BIOSCALLBUFFER + { LoaderFirmwarePermanent, 0xA0, 0x60 }, // ROM / Video + { LoaderSpecialMemory, 0xFFF, 1 }, // unusable memory + { 0, 0, 0 }, // end of map };
ULONG @@ -65,7 +64,7 @@ IN ULONG MaxCount, IN PFN_NUMBER BasePage, IN PFN_NUMBER PageCount, - IN MEMORY_TYPE MemoryType); + IN TYPE_OF_MEMORY MemoryType);
static BOOLEAN @@ -261,12 +260,12 @@ /* Check if we can add this descriptor */ if ((RealSize >= MM_PAGE_SIZE) && (MapCount < MaxMemoryMapSize)) { - MEMORY_TYPE MemoryType; + TYPE_OF_MEMORY MemoryType;
if (PcBiosMemoryMap[PcBiosMapCount].Type == BiosMemoryUsable) - MemoryType = MemoryFree; + MemoryType = LoaderFree; else - MemoryType = MemoryFirmwarePermanent; + MemoryType = LoaderFirmwarePermanent;
/* Add the descriptor */ MapCount = AddMemoryDescriptor(PcMemoryMap, @@ -312,14 +311,14 @@ MAX_BIOS_DESCRIPTORS, 0, PcMemGetConventionalMemorySize() * 1024 / PAGE_SIZE, - MemoryFree); + LoaderFree);
/* Extended memory */ EntryCount = AddMemoryDescriptor(PcMemoryMap, MAX_BIOS_DESCRIPTORS, 1024 * 1024 / PAGE_SIZE, ExtendedMemorySizeAtOneMB * 1024 / PAGE_SIZE, - MemoryFree); + LoaderFree); EntryCount++;
if (ExtendedMemorySizeAtSixteenMB != 0) @@ -329,7 +328,7 @@ MAX_BIOS_DESCRIPTORS, 0x1000000 / PAGE_SIZE, ExtendedMemorySizeAtSixteenMB * 64 * 1024 / PAGE_SIZE, - MemoryFree); + LoaderFree); } }
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxmem.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxmem.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxmem.c [iso-8859-1] Fri Sep 23 20:09:54 2011 @@ -84,12 +84,12 @@ /* Available RAM block */ BiosMemoryMap[0].BasePage = 0; BiosMemoryMap[0].PageCount = AvailableMemoryMb * 1024 * 1024 / MM_PAGE_SIZE; - BiosMemoryMap[0].MemoryType = MemoryFree; + BiosMemoryMap[0].MemoryType = LoaderFree;
/* Video memory */ BiosMemoryMap[1].BasePage = 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; return BiosMemoryMap;
Modified: trunk/reactos/boot/freeldr/freeldr/debug.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/debug.... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] Fri Sep 23 20:09:54 2011 @@ -26,7 +26,7 @@ //#define DEBUG_ALL //#define DEBUG_INIFILE //#define DEBUG_REACTOS -#define DEBUG_CUSTOM +//#define DEBUG_CUSTOM #define DEBUG_NONE
#if defined (DEBUG_ALL) @@ -38,7 +38,7 @@ #elif defined (DEBUG_REACTOS) ULONG DebugPrintMask = DPRINT_REACTOS | DPRINT_REGISTRY; #elif defined (DEBUG_CUSTOM) -ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY; +ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_WINDOWS; #else //#elif defined (DEBUG_NONE) ULONG DebugPrintMask = 0; #endif
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 [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/mm.h [iso-8859-1] Fri Sep 23 20:09:54 2011 @@ -89,7 +89,7 @@ extern ULONG LastFreePageHint;
#if DBG -PCSTR MmGetSystemMemoryMapTypeString(MEMORY_TYPE Type); +PCSTR MmGetSystemMemoryMapTypeString(TYPE_OF_MEMORY Type); #endif
ULONG MmGetPageNumberFromAddress(PVOID Address); // Returns the page number that contains a linear address
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 [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/mm/meminit.c [iso-8859-1] Fri Sep 23 20:09:54 2011 @@ -26,22 +26,28 @@ #if DBG typedef struct { - MEMORY_TYPE Type; + TYPE_OF_MEMORY Type; PCSTR TypeString; } FREELDR_MEMORY_TYPE, *PFREELDR_MEMORY_TYPE;
FREELDR_MEMORY_TYPE MemoryTypeArray[] = { - { MemoryMaximum, "Unknown memory" }, - { MemoryExceptionBlock, "Exception block" }, - { MemorySystemBlock, "System block" }, - { MemoryFree, "Free memory" }, - { MemoryBad, "Bad memory" }, - { MemoryLoadedProgram, "Loaded program" }, - { MemoryFirmwareTemporary, "Firmware temporary" }, - { MemoryFirmwarePermanent, "Firmware permanent" }, - { MemoryFreeContiguous, "Free contiguous memory" }, - { MemorySpecialMemory, "Special memory" }, + { LoaderMaximum, "Unknown memory" }, + { LoaderFree, "Free memory" }, + { LoaderBad, "Bad memory" }, + { LoaderLoadedProgram, "LoadedProgram" }, + { LoaderFirmwareTemporary, "FirmwareTemporary" }, + { LoaderFirmwarePermanent, "FirmwarePermanent" }, + { LoaderOsloaderHeap, "OsloaderHeap" }, + { LoaderOsloaderStack, "OsloaderStack" }, + { LoaderSystemCode, "SystemCode" }, + { LoaderHalCode, "HalCode" }, + { LoaderBootDriver, "BootDriver" }, + { LoaderRegistryData, "RegistryData" }, + { LoaderMemoryData, "MemoryData" }, + { LoaderNlsData, "NlsData" }, + { LoaderSpecialMemory, "SpecialMemory" }, + { LoaderReserve, "Reserve" }, }; ULONG MemoryTypeCount = sizeof(MemoryTypeArray) / sizeof(MemoryTypeArray[0]); #endif @@ -196,28 +202,10 @@ // Initialize the page lookup table 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);
- FreePagesInLookupTable = MmCountFreePagesInLookupTable(PageLookupTableAddress, TotalPagesInLookupTable); + FreePagesInLookupTable = MmCountFreePagesInLookupTable(PageLookupTableAddress, + TotalPagesInLookupTable);
MmInitializeHeap(PageLookupTableAddress);
@@ -228,7 +216,7 @@ }
#if DBG -PCSTR MmGetSystemMemoryMapTypeString(MEMORY_TYPE Type) +PCSTR MmGetSystemMemoryMapTypeString(TYPE_OF_MEMORY Type) { ULONG Index;
@@ -267,7 +255,7 @@ // // 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 @@ ULONG PageLookupTableStartPage = 0; PVOID PageLookupTableMemAddress = NULL;
- // // Calculate how much pages we need to keep the page lookup table - // PageLookupTableSize = TotalPageCount * sizeof(PAGE_LOOKUP_TABLE_ITEM); PageLookupTablePages = PageLookupTableSize / MM_PAGE_SIZE;
- // // Search the highest memory block big enough to contain lookup table - // while ((MemoryDescriptor = ArcGetMemoryDescriptor(MemoryDescriptor)) != NULL) { - // - // Is it suitable memory? - // - if (MemoryDescriptor->MemoryType != MemoryFree) - { - // - // No. Process next descriptor - // - continue; - } - - // - // Is the block big enough? - // - if (MemoryDescriptor->PageCount < PageLookupTablePages) - { - // - // No. Process next descriptor - // - continue; - } - - // - // Is it at a higher address than previous suitable address? - // - if (MemoryDescriptor->BasePage < PageLookupTableStartPage) - { - // - // No. Process next descriptor - // - continue; - } - - // - // Can we use this address? - // - if (MemoryDescriptor->BasePage >= MM_MAX_PAGE) - { - // - // No. Process next descriptor - // - continue; - } - - // + // Continue, if memory is not free + if (MemoryDescriptor->MemoryType != LoaderFree) continue; + + // Continue, if the block is not big enough? + if (MemoryDescriptor->PageCount < PageLookupTablePages) continue; + + // Continue, if it is not at a higher address than previous address + if (MemoryDescriptor->BasePage < PageLookupTableStartPage) continue; + + // Continue, if the address is too high + if (MemoryDescriptor->BasePage >= MM_MAX_PAGE) continue; + // Memory block is more suitable than the previous one - // PageLookupTableStartPage = MemoryDescriptor->BasePage; PageLookupTableMemAddress = (PVOID)((ULONG_PTR) (MemoryDescriptor->BasePage + MemoryDescriptor->PageCount) * MM_PAGE_SIZE @@ -374,87 +324,31 @@
TRACE("MmInitPageLookupTable()\n");
- // // Mark every page as allocated initially // 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, MmLowestPhysicalPage, TotalPageCount, LoaderFirmwarePermanent);
- // // Parse the whole memory map - // while ((MemoryDescriptor = ArcGetMemoryDescriptor(MemoryDescriptor)) != NULL) { TRACE("Got range: 0x%lx-0x%lx, type=%s\n", MemoryDescriptor->BasePage, MemoryDescriptor->BasePage + MemoryDescriptor->PageCount, 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 - // - TRACE("Marking pages as type %d: StartPage: %d PageCount: %d\n", MemoryMapPageAllocated, MemoryDescriptor->BasePage, MemoryDescriptor->PageCount); - MmMarkPagesInLookupTable(PageLookupTable, MemoryDescriptor->BasePage, MemoryDescriptor->PageCount, MemoryMapPageAllocated); - } - - // + TRACE("Marking pages as type %d: StartPage: %d PageCount: %d\n", + MemoryMapPageAllocated, MemoryDescriptor->BasePage, MemoryDescriptor->PageCount); + MmMarkPagesInLookupTable(PageLookupTable, + MemoryDescriptor->BasePage, + MemoryDescriptor->PageCount, + MemoryMapPageAllocated); + } + // 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; TRACE("Marking the page lookup table pages as reserved StartPage: %d PageCount: %d\n", PageLookupTableStartPage, PageLookupTablePageCount); @@ -515,9 +409,9 @@
ULONG MmFindAvailablePages(PVOID PageLookupTable, ULONG TotalPageCount, ULONG PagesNeeded, BOOLEAN FromEnd) { - PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable; - ULONG AvailablePagesSoFar; - ULONG Index; + PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable; + ULONG AvailablePagesSoFar; + ULONG Index;
if (LastFreePageHint > TotalPageCount) { @@ -639,7 +533,7 @@ 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 // memory availabe so return FALSE