[FREELDR]

- Return const pointers instead of converting them
- Fix MemoryMapSizeInPages calculation
- Don't use pages after 4GB limit on x86 (PAE is not supported yet)
- Should fix starting ROS on 4GB machines
See issue #6031 for more details.

svn path=/trunk/; revision=52234
This commit is contained in:
Rafal Harabien
2011-06-14 17:33:56 +00:00
parent 9e24b605cb
commit d53b93507f
6 changed files with 39 additions and 15 deletions
+5 -5
View File
@@ -34,8 +34,8 @@ static const MEMORY_DESCRIPTOR_INT MemoryDescriptors[] =
#endif
};
MEMORY_DESCRIPTOR*
ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current)
const MEMORY_DESCRIPTOR*
ArcGetMemoryDescriptor(const MEMORY_DESCRIPTOR* Current)
{
MEMORY_DESCRIPTOR_INT* CurrentDescriptor;
BIOS_MEMORY_MAP BiosMemoryMap[32];
@@ -114,7 +114,7 @@ ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current)
//
// Return first fixed memory descriptor
//
return (MEMORY_DESCRIPTOR*)&MemoryDescriptors[0].m;
return &MemoryDescriptors[0].m;
}
else
{
@@ -141,7 +141,7 @@ ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current)
//
// Return first fixed memory descriptor
//
return (MEMORY_DESCRIPTOR*)&MemoryDescriptors[0].m;
return &MemoryDescriptors[0].m;
}
else
{
@@ -161,7 +161,7 @@ ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current)
//
// Return next fixed descriptor
//
return (MEMORY_DESCRIPTOR*)&MemoryDescriptors[CurrentDescriptor->Index + 1].m;
return &MemoryDescriptors[CurrentDescriptor->Index + 1].m;
}
else
{
@@ -35,8 +35,8 @@ ArcGetConfigurationData(
CONFIGURATION_COMPONENT* Component);
/* mm.c */
MEMORY_DESCRIPTOR*
ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current);
const MEMORY_DESCRIPTOR*
ArcGetMemoryDescriptor(const MEMORY_DESCRIPTOR* Current);
/* time.c */
TIMEINFO* ArcGetTime(VOID);
@@ -92,7 +92,6 @@ VOID MachVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue);
VOID MachVideoGetPaletteColor(UCHAR Color, UCHAR *Red, UCHAR *Green, UCHAR *Blue);
VOID MachVideoSync(VOID);
VOID MachBeep(VOID);
MEMORY_DESCRIPTOR* ArcGetMemoryDescriptor(MEMORY_DESCRIPTOR* Current);
BOOLEAN MachDiskGetBootPath(char *BootPath, unsigned Size);
BOOLEAN MachDiskNormalizeSystemPath(char *SystemPath, unsigned Size);
BOOLEAN MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
@@ -42,6 +42,7 @@ typedef struct
#define MM_PAGE_SIZE 4096
#define MM_PAGE_MASK 0xFFF
#define MM_PAGE_SHIFT 12
#define MM_MAX_PAGE 0xFFFFF
#define MM_SIZE_TO_PAGES(a) \
( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) )
@@ -53,6 +54,7 @@ typedef struct
#define MM_PAGE_SIZE 4096
#define MM_PAGE_MASK 0xFFF
#define MM_PAGE_SHIFT 12
#define MM_MAX_PAGE 0xFFFFFFFFFFFFF
#define MM_SIZE_TO_PAGES(a) \
( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) )
+15 -4
View File
@@ -57,7 +57,7 @@ extern ULONG_PTR MmHeapStart;
BOOLEAN MmInitializeMemoryManager(VOID)
{
#if DBG
MEMORY_DESCRIPTOR* MemoryDescriptor = NULL;
const MEMORY_DESCRIPTOR* MemoryDescriptor = NULL;
#endif
DPRINTM(DPRINT_MEMORY, "Initializing Memory Manager.\n");
@@ -158,7 +158,7 @@ ULONG MmGetPageNumberFromAddress(PVOID Address)
ULONG MmGetAddressablePageCountIncludingHoles(VOID)
{
MEMORY_DESCRIPTOR* MemoryDescriptor = NULL;
const MEMORY_DESCRIPTOR* MemoryDescriptor = NULL;
ULONG PageCount;
//
@@ -197,7 +197,7 @@ ULONG MmGetAddressablePageCountIncludingHoles(VOID)
PVOID MmFindLocationForPageLookupTable(ULONG TotalPageCount)
{
MEMORY_DESCRIPTOR* MemoryDescriptor = NULL;
const MEMORY_DESCRIPTOR* MemoryDescriptor = NULL;
ULONG PageLookupTableSize;
ULONG PageLookupTablePages;
ULONG PageLookupTableStartPage = 0;
@@ -247,6 +247,17 @@ PVOID MmFindLocationForPageLookupTable(ULONG TotalPageCount)
continue;
}
//
// Can we use this address?
//
if (MemoryDescriptor->BasePage >= MM_MAX_PAGE)
{
//
// No. Process next descriptor
//
continue;
}
//
// Memory block is more suitable than the previous one
//
@@ -263,7 +274,7 @@ PVOID MmFindLocationForPageLookupTable(ULONG TotalPageCount)
VOID MmInitPageLookupTable(PVOID PageLookupTable, ULONG TotalPageCount)
{
MEMORY_DESCRIPTOR* MemoryDescriptor = NULL;
const MEMORY_DESCRIPTOR* MemoryDescriptor = NULL;
TYPE_OF_MEMORY MemoryMapPageAllocated;
ULONG PageLookupTableStartPage;
ULONG PageLookupTablePageCount;
@@ -139,9 +139,10 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
BOOLEAN Status;
//
// Check for some weird stuff at the top
// Check for memory block after 4GB - we don't support it yet
// Note: Even last page before 4GB limit is not supported
//
if (BasePage + PageCount > 0xF0000)
if (BasePage >= MM_MAX_PAGE)
{
//
// Just skip this, without even adding to MAD list
@@ -149,6 +150,17 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
return;
}
//
// Check if last page is after 4GB limit and shorten this block if needed
//
if (BasePage + PageCount > MM_MAX_PAGE)
{
//
// shorten this block
//
PageCount = MM_MAX_PAGE - BasePage;
}
//
// Set Base page, page count and type
//
@@ -255,7 +267,7 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
// Calculate parameters of the memory map
MemoryMapStartPage = (ULONG_PTR)MemoryMap >> MM_PAGE_SHIFT;
MemoryMapSizeInPages = NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM);
MemoryMapSizeInPages = (NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM) + MM_PAGE_SIZE - 1) / MM_PAGE_SIZE;
DPRINTM(DPRINT_WINDOWS, "Got memory map with %d entries\n", NoEntries);