[BOOTLIB]: Correctly bias access to GDT/IDT registers by 2 bytes since this is a 48-bit instruction. The loaded GDT/IDT was previously invalid and causing random GPFs.
[BOOTLIB]: Fix EfiStall in protected mode. It was previously not stalling.
[BOOTLIB]: Fix calculation in MmMapPhysicalAddress
[BOOTLIB]: Fix missing goto in MmSelectMappingAddress which broke the function in real mode.
[BOOTLIB]: Fix incorrect ranges in MmSelectMappingAddress.
[BOOTLIB]: Fix incorrect offset calculation in MmSelectMappingAddress.
Now hitting (as expected), unimplemented virtual code path in BlMmMapPhysicalAddressEx.
svn path=/trunk/; revision=73801
/* MEMORY DESCRIPTOR ROUTINES ************************************************/
+VOID
+MmMdDbgDumpList (
+ _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
+);
+
VOID
MmMdInitializeList (
_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
/* FUNCTIONS ****************************************************************/
.code
+ASSUME nothing
PUBLIC _Archx86TransferTo32BitApplicationAsm
_Archx86TransferTo32BitApplicationAsm:
mov ebx, esp
/* Save current GDT/IDT, then load new one */
- sgdt _GdtRegister
- sidt _IdtRegister
- lgdt _BootAppGdtRegister
- lidt _BootAppIdtRegister
+ sgdt _GdtRegister+2
+ sidt _IdtRegister+2
+ lgdt _BootAppGdtRegister+2
+ lidt _BootAppIdtRegister+2
/* Load the new stack */
xor ebp, ebp
mov esp, ebx
/* Restore old GDT/IDT */
- lgdt _GdtRegister
- lidt _IdtRegister
+ lgdt _GdtRegister+2
+ lidt _IdtRegister+2
/* Retore old segments */
pop ds
OldMode = CurrentExecutionContext->Mode;
if (OldMode != BlRealMode)
{
- /* FIXME: Not yet implemented */
- return STATUS_NOT_IMPLEMENTED;
+ /* Switch to real mode */
+ BlpArchSwitchContext(BlProtectedMode);
}
/* Make the EFI call */
/* Initialize EFI memory map attributes */
EfiMemoryMapSize = MapKey = DescriptorSize = DescriptorVersion = 0;
+ LibraryBuffer = NULL;
/* Increment the nesting depth */
MmDescriptorCallTreeCount++;
!(GraphicsConsole) ||
!(((PBL_GRAPHICS_CONSOLE_VTABLE)GraphicsConsole->TextConsole.Callbacks)->IsEnabled(GraphicsConsole)))
{
- EfiPrintf(L"Nothing to do for re-init\r\n");
return Status;
}
_In_ ULONG Count
)
{
- EfiPrintf(L"dynamic switch NOT SUPPORTED!!!\r\n");
- while (1);
+ EfiPrintf(L"Dynamic switch NOT SUPPORTED!!!\r\n");
+ EfiStall(10000000);
}
NTSTATUS
else
{
/* It's a dynamic descriptor, so free it */
- EfiPrintf(L"Dynamic descriptors not yet supported\r\n");
+ EfiPrintf(L"Freeing dynamic descriptors not yet supported\r\n");
+ EfiStall(10000000);
Status = STATUS_NOT_IMPLEMENTED;
}
/* Check for start overflow */
if (BaseMin > BaseMax)
{
- EfiPrintf(L"Descriptor overflow\r\n");
return FALSE;
}
/* Loop every current global descriptor */
while (Index < MmGlobalMemoryDescriptorsUsed)
{
- /* Does it have any valid pageS? */
+ /* Does it have any valid pages? */
OldDescriptor = &MmGlobalMemoryDescriptors[Index];
if (OldDescriptor->PageCount)
{
_In_ ULONG CacheAttributes
)
{
- ULONGLONG Size, TotalSize;
+ ULONGLONG Size;
ULONGLONG PhysicalAddress;
PVOID VirtualAddress;
PHYSICAL_ADDRESS TranslatedAddress;
VirtualAddress = (PVOID)PAGE_ROUND_DOWN(VirtualAddress);
/* Round up the size */
- TotalSize = ROUND_TO_PAGES(PhysicalAddressPtr->QuadPart -
- PhysicalAddress +
- Size);
+ Size = ROUND_TO_PAGES(PhysicalAddressPtr->QuadPart -
+ PhysicalAddress +
+ Size);
/* Loop every virtual page */
CurrentAddress = (ULONG_PTR)VirtualAddress;
- VirtualAddressEnd = CurrentAddress + TotalSize - 1;
+ VirtualAddressEnd = CurrentAddress + Size - 1;
while (CurrentAddress < VirtualAddressEnd)
{
/* Get the physical page of this virtual page */
EfiPrintf(L"Existing mapping exists: %lx vs %lx\r\n",
TranslatedAddress.QuadPart,
PhysicalAddress + (CurrentAddress - (ULONG_PTR)VirtualAddress));
+ EfiStall(10000000);
return STATUS_INVALID_PARAMETER;
}
}
return Status;
}
+VOID
+MmMdDbgDumpList (
+ _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
+ )
+{
+ ULONGLONG EndPage, VirtualEndPage;
+ PBL_MEMORY_DESCRIPTOR MemoryDescriptor;
+ PLIST_ENTRY NextEntry;
+
+ NextEntry = DescriptorList->First->Flink;
+ while (NextEntry != DescriptorList->First)
+ {
+ MemoryDescriptor = CONTAINING_RECORD(NextEntry,
+ BL_MEMORY_DESCRIPTOR,
+ ListEntry);
+
+ EndPage = MemoryDescriptor->BasePage + MemoryDescriptor->PageCount;
+ if (MemoryDescriptor->VirtualPage != 0)
+ {
+ VirtualEndPage = MemoryDescriptor->VirtualPage + MemoryDescriptor->PageCount;
+ }
+ else
+ {
+ VirtualEndPage = 0;
+ }
+
+ EfiPrintf(L"%p - [%08llx-%08llx @ %08llx-%08llx]:%x\r\n",
+ MemoryDescriptor,
+ MemoryDescriptor->BasePage << PAGE_SHIFT,
+ (EndPage << PAGE_SHIFT) - 1,
+ MemoryDescriptor->VirtualPage << PAGE_SHIFT,
+ VirtualEndPage ? (VirtualEndPage << PAGE_SHIFT) - 1 : 0,
+ (ULONG)MemoryDescriptor->Type);
+
+ NextEntry = NextEntry->Flink;
+ }
+}
+
NTSTATUS
Mmx86pMapMemoryRegions (
_In_ ULONG Phase,
MmArchKsegAddressRange.Maximum = (ULONGLONG)~0;
/* Set the boot application top maximum */
- MmArchTopOfApplicationAddressSpace = 0x70000000;
+ MmArchTopOfApplicationAddressSpace = 0x70000000 - 1; // Windows bug
/* Initialize virtual address space translation */
Status = MmDefInitializeTranslation(MemoryData, TranslationType);
MapSize = Size;
CacheAttributes = ((Flags & BlMemoryValidCacheAttributeMask) != 0x20) ?
(Flags & BlMemoryValidCacheAttributeMask) : 0;
- EfiPrintf(L"Selected address: %p for %lx\r\n", MappingAddress, MappedAddress.LowPart);
Status = MmMapPhysicalAddress(&MappedAddress,
&MappingAddress,
&MapSize,
if (MmTranslationType != BlNone)
{
/* We don't support virtual memory yet @TODO */
- EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__);
+ EfiPrintf(L"not yet implemented in BlMmMapPhysicalAddressEx\r\n");
EfiStall(1000000);
Status = STATUS_NOT_IMPLEMENTED;
goto Quickie;
FoundDescriptor = CONTAINING_RECORD(NextEntry,
BL_MEMORY_DESCRIPTOR,
ListEntry);
-
- /* See if it matches the request */
+
+ /* See if it matches the request */
if (MmMdFindSatisfyingRegion(FoundDescriptor,
&LocalDescriptor,
Request->Pages,
/* Handle virtual memory scenario */
if (MmTranslationType != BlNone)
{
- EfiPrintf(L"Unimplemented virtual path\r\n");
+ EfiPrintf(L"Unimplemented free virtual path\r\n");
return STATUS_SUCCESS;
}
{
/* Just return the physical address as the mapping address */
PreferredAddress = (PVOID)PhysicalAddress.LowPart;
+ goto Success;
}
/* If no physical address, or caller wants a fixed address... */
if (AllocationAttributes & BlMemoryKernelRange)
{
/* Use kernel range */
- Request.BaseRange = MmArchKsegAddressRange;
+ Request.BaseRange.Minimum = MmArchKsegAddressRange.Minimum >> PAGE_SHIFT;
+ Request.BaseRange.Maximum = MmArchKsegAddressRange.Maximum >> PAGE_SHIFT;
Request.Type = BL_MM_REQUEST_DEFAULT_TYPE;
}
else
{
/* User user/application range */
- Request.BaseRange.Minimum = 0;
- Request.BaseRange.Maximum = MmArchTopOfApplicationAddressSpace;
+ Request.BaseRange.Minimum = 0 >> PAGE_SHIFT;
+ Request.BaseRange.Maximum = MmArchTopOfApplicationAddressSpace >> PAGE_SHIFT;
Request.Type = BL_MM_REQUEST_TOP_DOWN_TYPE;
}
{
/* Add the offset to the returned virtual address */
PreferredAddress = (PVOID)((ULONG_PTR)PreferredAddress +
- PhysicalAddress.LowPart -
- BYTE_OFFSET(PhysicalAddress.LowPart));
+ BYTE_OFFSET(PhysicalAddress.QuadPart));
}
Success: