[FREELDR]

- Fix a bug, where the bios memory map could have a bogus entry: according to R.B.'s Interrupt list, in some bioses the function for enumerating the memory can return ebx != 0 for the last descriptor, and fail in the following call returning CF = 1. In that case we were previously counting that last descriptor as well, but its content wouldn't describe a valid memory region.
- Use a static buffer for the bios memory map, stored in the achitecture specific file and return a pointer to that variable from PcMemGetMemoryMap. Reuse the static map from DetectAcpiBios instead of enumerating again. On arm, we don't even need a buffer, we return the pointer from the arm block.

svn path=/trunk/; revision=53803
This commit is contained in:
Timo Kreuzer 2011-09-22 16:38:54 +00:00
parent 1cdfe06ad1
commit b356275262
8 changed files with 57 additions and 69 deletions

View file

@ -143,15 +143,12 @@ ArmHwDetect(VOID)
return RootNode; return RootNode;
} }
ULONG PBIOS_MEMORY_MAP
ArmMemGetMemoryMap(OUT PBIOS_MEMORY_MAP BiosMemoryMap, ArmMemGetMemoryMap(OUT PULONG MaxMemoryMapSize)
IN ULONG MaxMemoryMapSize)
{ {
/* Return whatever the board returned to us (CS0 Base + Size and FLASH0) */ /* Return whatever the board returned to us (CS0 Base + Size and FLASH0) */
memcpy(BiosMemoryMap, *MaxMemoryMapSize = ArmBoardBlock->MemoryMapEntryCount;
ArmBoardBlock->MemoryMap, return ArmBoardBlock->MemoryMap;
ArmBoardBlock->MemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP));
return ArmBoardBlock->MemoryMapEntryCount;
} }
VOID VOID

View file

@ -58,8 +58,7 @@ DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor; PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
PRSDP_DESCRIPTOR Rsdp; PRSDP_DESCRIPTOR Rsdp;
PACPI_BIOS_DATA AcpiBiosData; PACPI_BIOS_DATA AcpiBiosData;
BIOS_MEMORY_MAP BiosMemoryMap[32]; ULONG TableSize;
ULONG BiosMemoryMapEntryCount, TableSize;
Rsdp = FindAcpiBios(); Rsdp = FindAcpiBios();
@ -68,13 +67,8 @@ DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
/* Set up the flag in the loader block */ /* Set up the flag in the loader block */
AcpiPresent = TRUE; AcpiPresent = TRUE;
/* Get BIOS memory map */
RtlZeroMemory(BiosMemoryMap, sizeof(BiosMemoryMap));
BiosMemoryMapEntryCount = PcMemGetMemoryMap(BiosMemoryMap,
sizeof(BiosMemoryMap) / sizeof(BIOS_MEMORY_MAP));
/* Calculate the table size */ /* Calculate the table size */
TableSize = BiosMemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP) + TableSize = PcBiosMapCount * sizeof(BIOS_MEMORY_MAP) +
sizeof(ACPI_BIOS_DATA) - sizeof(BIOS_MEMORY_MAP); sizeof(ACPI_BIOS_DATA) - sizeof(BIOS_MEMORY_MAP);
/* Set 'Configuration Data' value */ /* Set 'Configuration Data' value */
@ -100,9 +94,9 @@ DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
/* Fill the table */ /* Fill the table */
AcpiBiosData = (PACPI_BIOS_DATA)&PartialResourceList->PartialDescriptors[1]; AcpiBiosData = (PACPI_BIOS_DATA)&PartialResourceList->PartialDescriptors[1];
AcpiBiosData->RSDTAddress.LowPart = Rsdp->rsdt_physical_address; AcpiBiosData->RSDTAddress.LowPart = Rsdp->rsdt_physical_address;
AcpiBiosData->Count = BiosMemoryMapEntryCount; AcpiBiosData->Count = PcBiosMapCount;
memcpy(AcpiBiosData->MemoryMap, BiosMemoryMap, memcpy(AcpiBiosData->MemoryMap, PcBiosMemoryMap,
BiosMemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP)); PcBiosMapCount * sizeof(BIOS_MEMORY_MAP));
TRACE("RSDT %p, data size %x\n", Rsdp->rsdt_physical_address, TRACE("RSDT %p, data size %x\n", Rsdp->rsdt_physical_address,
TableSize); TableSize);

View file

@ -27,6 +27,11 @@
DBG_DEFAULT_CHANNEL(MEMORY); DBG_DEFAULT_CHANNEL(MEMORY);
#define MAX_BIOS_DESCRIPTORS 32
BIOS_MEMORY_MAP PcBiosMemoryMap[MAX_BIOS_DESCRIPTORS];
ULONG PcBiosMapCount;
static static
BOOLEAN BOOLEAN
GetExtendedMemoryConfiguration(ULONG* pMemoryAtOneMB /* in KB */, ULONG* pMemoryAtSixteenMB /* in 64KB */) GetExtendedMemoryConfiguration(ULONG* pMemoryAtOneMB /* in KB */, ULONG* pMemoryAtSixteenMB /* in 64KB */)
@ -174,14 +179,17 @@ PcMemGetBiosMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize)
* CF set on error * CF set on error
* AH = error code (86h) * AH = error code (86h)
*/ */
Regs.x.eax = 0x0000E820;
Regs.x.edx = 0x534D4150; /* ('SMAP') */
Regs.x.ebx = 0x00000000; Regs.x.ebx = 0x00000000;
Regs.x.ecx = sizeof(BIOS_MEMORY_MAP);
Regs.w.es = BIOSCALLBUFSEGMENT;
Regs.w.di = BIOSCALLBUFOFFSET;
for (MapCount = 0; MapCount < MaxMemoryMapSize; MapCount++) for (MapCount = 0; MapCount < MaxMemoryMapSize; MapCount++)
{ {
/* Setup the registers for the BIOS call */
Regs.x.eax = 0x0000E820;
Regs.x.edx = 0x534D4150; /* ('SMAP') */
/* Regs.x.ebx = 0x00000001; Continuation value already set */
Regs.x.ecx = sizeof(BIOS_MEMORY_MAP);
Regs.w.es = BIOSCALLBUFSEGMENT;
Regs.w.di = BIOSCALLBUFOFFSET;
Int386(0x15, &Regs, &Regs); Int386(0x15, &Regs, &Regs);
TRACE("Memory Map Entry %d\n", MapCount); TRACE("Memory Map Entry %d\n", MapCount);
@ -192,8 +200,8 @@ PcMemGetBiosMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize)
TRACE("CF set = %s\n", (Regs.x.eflags & EFLAGS_CF) ? "TRUE" : "FALSE"); TRACE("CF set = %s\n", (Regs.x.eflags & EFLAGS_CF) ? "TRUE" : "FALSE");
/* If the BIOS didn't return 'SMAP' in EAX then /* If the BIOS didn't return 'SMAP' in EAX then
* it doesn't support this call */ * it doesn't support this call. If CF is set, we're done */
if (Regs.x.eax != 0x534D4150) if (Regs.x.eax != 0x534D4150 || !INT386_SUCCESS(Regs))
{ {
break; break;
} }
@ -210,62 +218,57 @@ PcMemGetBiosMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize)
/* If the continuation value is zero or the /* If the continuation value is zero or the
* carry flag is set then this was * carry flag is set then this was
* the last entry so we're done */ * the last entry so we're done */
if (Regs.x.ebx == 0x00000000 || !INT386_SUCCESS(Regs)) if (Regs.x.ebx == 0x00000000)
{ {
MapCount++;
TRACE("End Of System Memory Map!\n\n"); TRACE("End Of System Memory Map!\n\n");
break; break;
} }
/* Setup the registers for the next call */
Regs.x.eax = 0x0000E820;
Regs.x.edx = 0x534D4150; /* ('SMAP') */
/* Regs.x.ebx = 0x00000001; Continuation value already set by the BIOS */
Regs.x.ecx = sizeof(BIOS_MEMORY_MAP);
Regs.w.es = BIOSCALLBUFSEGMENT;
Regs.w.di = BIOSCALLBUFOFFSET;
} }
return MapCount; return MapCount;
} }
ULONG PBIOS_MEMORY_MAP
PcMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize) PcMemGetMemoryMap(ULONG *MemoryMapSize)
{ {
ULONG EntryCount; ULONG EntryCount;
ULONG ExtendedMemorySizeAtOneMB; ULONG ExtendedMemorySizeAtOneMB;
ULONG ExtendedMemorySizeAtSixteenMB; ULONG ExtendedMemorySizeAtSixteenMB;
EntryCount = PcMemGetBiosMemoryMap(BiosMemoryMap, MaxMemoryMapSize); EntryCount = PcMemGetBiosMemoryMap(PcBiosMemoryMap, MAX_BIOS_DESCRIPTORS);
PcBiosMapCount = EntryCount;
/* If the BIOS didn't provide a memory map, synthesize one */ /* If the BIOS didn't provide a memory map, synthesize one */
if (0 == EntryCount && 3 <= MaxMemoryMapSize) if (0 == EntryCount)
{ {
GetExtendedMemoryConfiguration(&ExtendedMemorySizeAtOneMB, &ExtendedMemorySizeAtSixteenMB); GetExtendedMemoryConfiguration(&ExtendedMemorySizeAtOneMB, &ExtendedMemorySizeAtSixteenMB);
/* Conventional memory */ /* Conventional memory */
BiosMemoryMap[EntryCount].BaseAddress = 0; PcBiosMemoryMap[EntryCount].BaseAddress = 0;
BiosMemoryMap[EntryCount].Length = PcMemGetConventionalMemorySize() * 1024; PcBiosMemoryMap[EntryCount].Length = PcMemGetConventionalMemorySize() * 1024;
BiosMemoryMap[EntryCount].Type = BiosMemoryUsable; PcBiosMemoryMap[EntryCount].Type = BiosMemoryUsable;
EntryCount++; EntryCount++;
/* Extended memory at 1MB */ /* Extended memory at 1MB */
BiosMemoryMap[EntryCount].BaseAddress = 1024 * 1024; PcBiosMemoryMap[EntryCount].BaseAddress = 1024 * 1024;
BiosMemoryMap[EntryCount].Length = ExtendedMemorySizeAtOneMB * 1024; PcBiosMemoryMap[EntryCount].Length = ExtendedMemorySizeAtOneMB * 1024;
BiosMemoryMap[EntryCount].Type = BiosMemoryUsable; PcBiosMemoryMap[EntryCount].Type = BiosMemoryUsable;
EntryCount++; EntryCount++;
if (ExtendedMemorySizeAtSixteenMB != 0) if (ExtendedMemorySizeAtSixteenMB != 0)
{ {
/* Extended memory at 16MB */ /* Extended memory at 16MB */
BiosMemoryMap[EntryCount].BaseAddress = 0x1000000; PcBiosMemoryMap[EntryCount].BaseAddress = 0x1000000;
BiosMemoryMap[EntryCount].Length = ExtendedMemorySizeAtSixteenMB * 64 * 1024; PcBiosMemoryMap[EntryCount].Length = ExtendedMemorySizeAtSixteenMB * 64 * 1024;
BiosMemoryMap[EntryCount].Type = BiosMemoryUsable; PcBiosMemoryMap[EntryCount].Type = BiosMemoryUsable;
EntryCount++; EntryCount++;
} }
} }
return EntryCount; *MemoryMapSize = EntryCount;
return PcBiosMemoryMap;
} }
/* EOF */ /* EOF */

View file

@ -75,31 +75,24 @@ XboxMemInit(VOID)
AvailableMemoryMb = InstalledMemoryMb; AvailableMemoryMb = InstalledMemoryMb;
} }
ULONG BIOS_MEMORY_MAP BiosMemoryMap[2];
XboxMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize)
{
ULONG EntryCount = 0;
PBIOS_MEMORY_MAP
XboxMemGetMemoryMap(ULONG *MemoryMapSize)
{
/* Synthesize memory map */ /* Synthesize memory map */
if (1 <= MaxMemoryMapSize)
{
/* Available RAM block */ /* Available RAM block */
BiosMemoryMap[0].BaseAddress = 0; BiosMemoryMap[0].BaseAddress = 0;
BiosMemoryMap[0].Length = AvailableMemoryMb * 1024 * 1024; BiosMemoryMap[0].Length = AvailableMemoryMb * 1024 * 1024;
BiosMemoryMap[0].Type = BiosMemoryUsable; BiosMemoryMap[0].Type = BiosMemoryUsable;
EntryCount = 1;
}
if (2 <= MaxMemoryMapSize)
{
/* Video memory */ /* Video memory */
BiosMemoryMap[1].BaseAddress = AvailableMemoryMb * 1024 * 1024; BiosMemoryMap[1].BaseAddress = AvailableMemoryMb * 1024 * 1024;
BiosMemoryMap[1].Length = (InstalledMemoryMb - AvailableMemoryMb) * 1024 * 1024; BiosMemoryMap[1].Length = (InstalledMemoryMb - AvailableMemoryMb) * 1024 * 1024;
BiosMemoryMap[1].Type = BiosMemoryReserved; BiosMemoryMap[1].Type = BiosMemoryReserved;
EntryCount = 2;
}
return EntryCount; *MemoryMapSize = 2;
return BiosMemoryMap;
} }
PVOID PVOID

View file

@ -49,7 +49,7 @@ VOID XboxPrepareForReactOS(IN BOOLEAN Setup);
VOID XboxMemInit(VOID); VOID XboxMemInit(VOID);
PVOID XboxMemReserveMemory(ULONG MbToReserve); PVOID XboxMemReserveMemory(ULONG MbToReserve);
ULONG XboxMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize); PBIOS_MEMORY_MAP XboxMemGetMemoryMap(ULONG *MemoryMapSize);
BOOLEAN XboxDiskReadLogicalSectors(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); BOOLEAN XboxDiskReadLogicalSectors(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
BOOLEAN XboxDiskGetPartitionEntry(UCHAR DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); BOOLEAN XboxDiskGetPartitionEntry(UCHAR DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);

View file

@ -46,7 +46,7 @@ VOID PcVideoSync(VOID);
VOID PcVideoPrepareForReactOS(IN BOOLEAN Setup); VOID PcVideoPrepareForReactOS(IN BOOLEAN Setup);
VOID PcPrepareForReactOS(IN BOOLEAN Setup); VOID PcPrepareForReactOS(IN BOOLEAN Setup);
ULONG PcMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize); PBIOS_MEMORY_MAP PcMemGetMemoryMap(ULONG *MemoryMapSize);
BOOLEAN PcDiskGetBootPath(char *BootPath, unsigned Size); BOOLEAN PcDiskGetBootPath(char *BootPath, unsigned Size);
BOOLEAN PcDiskReadLogicalSectors(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); BOOLEAN PcDiskReadLogicalSectors(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
@ -58,4 +58,7 @@ TIMEINFO* PcGetTime(VOID);
PCONFIGURATION_COMPONENT_DATA PcHwDetect(VOID); PCONFIGURATION_COMPONENT_DATA PcHwDetect(VOID);
extern BIOS_MEMORY_MAP PcBiosMemoryMap[];
extern ULONG PcBiosMapCount;
/* EOF */ /* EOF */

View file

@ -59,7 +59,7 @@ typedef struct tagMACHVTBL
VOID (*PrepareForReactOS)(IN BOOLEAN Setup); VOID (*PrepareForReactOS)(IN BOOLEAN Setup);
MEMORY_DESCRIPTOR* (*GetMemoryDescriptor)(MEMORY_DESCRIPTOR* Current); MEMORY_DESCRIPTOR* (*GetMemoryDescriptor)(MEMORY_DESCRIPTOR* Current);
ULONG (*GetMemoryMap)(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize); PBIOS_MEMORY_MAP (*GetMemoryMap)(PULONG MemoryMapSize);
BOOLEAN (*DiskGetBootPath)(char *BootPath, unsigned Size); BOOLEAN (*DiskGetBootPath)(char *BootPath, unsigned Size);
BOOLEAN (*DiskReadLogicalSectors)(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); BOOLEAN (*DiskReadLogicalSectors)(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);

View file

@ -124,7 +124,7 @@ const MEMORY_DESCRIPTOR*
ArcGetMemoryDescriptor(const MEMORY_DESCRIPTOR* Current) ArcGetMemoryDescriptor(const MEMORY_DESCRIPTOR* Current)
{ {
MEMORY_DESCRIPTOR_INT* CurrentDescriptor; MEMORY_DESCRIPTOR_INT* CurrentDescriptor;
BIOS_MEMORY_MAP BiosMemoryMap[32]; PBIOS_MEMORY_MAP BiosMemoryMap;
static ULONG BiosMemoryMapEntryCount; static ULONG BiosMemoryMapEntryCount;
static MEMORY_DESCRIPTOR_INT BiosMemoryDescriptors[32]; static MEMORY_DESCRIPTOR_INT BiosMemoryDescriptors[32];
static BOOLEAN MemoryMapInitialized = FALSE; static BOOLEAN MemoryMapInitialized = FALSE;
@ -138,10 +138,7 @@ ArcGetMemoryDescriptor(const MEMORY_DESCRIPTOR* Current)
// //
// Get the machine generated memory map // Get the machine generated memory map
// //
RtlZeroMemory(BiosMemoryMap, sizeof(BIOS_MEMORY_MAP) * 32); BiosMemoryMap = MachVtbl.GetMemoryMap(&BiosMemoryMapEntryCount);
BiosMemoryMapEntryCount = MachVtbl.GetMemoryMap(BiosMemoryMap,
sizeof(BiosMemoryMap) /
sizeof(BIOS_MEMORY_MAP));
// //
// Fix entries that are not page aligned // Fix entries that are not page aligned
@ -545,6 +542,7 @@ VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG Page
{ {
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable; PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTable;
ULONG Index; ULONG Index;
TRACE("MmMarkPagesInLookupTable()\n");
StartPage -= MmLowestPhysicalPage; StartPage -= MmLowestPhysicalPage;
for (Index=StartPage; Index<(StartPage+PageCount); Index++) for (Index=StartPage; Index<(StartPage+PageCount); Index++)