[BOOTLIB]: Fix assembly file containing Archx86TransferTo32BitApplicationAsm to use assume:nothing, otherwise we end up with SS segment overrides everywhere.

[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
This commit is contained in:
Alex Ionescu
2017-02-15 00:53:15 +00:00
parent 18d52d4336
commit 126cfbc810
8 changed files with 75 additions and 30 deletions
+5
View File
@@ -2014,6 +2014,11 @@ Archx86TransferTo32BitApplicationAsm (
/* MEMORY DESCRIPTOR ROUTINES ************************************************/
VOID
MmMdDbgDumpList (
_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
);
VOID
MmMdInitializeList (
_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
@@ -21,6 +21,7 @@ EXTERN _BootApp32Parameters:DWORD
/* FUNCTIONS ****************************************************************/
.code
ASSUME nothing
PUBLIC _Archx86TransferTo32BitApplicationAsm
_Archx86TransferTo32BitApplicationAsm:
@@ -39,10 +40,10 @@ _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
@@ -62,8 +63,8 @@ _Archx86TransferTo32BitApplicationAsm:
mov esp, ebx
/* Restore old GDT/IDT */
lgdt _GdtRegister
lidt _IdtRegister
lgdt _GdtRegister+2
lidt _IdtRegister+2
/* Retore old segments */
pop ds
@@ -646,8 +646,8 @@ EfiStall (
OldMode = CurrentExecutionContext->Mode;
if (OldMode != BlRealMode)
{
/* FIXME: Not yet implemented */
return STATUS_NOT_IMPLEMENTED;
/* Switch to real mode */
BlpArchSwitchContext(BlProtectedMode);
}
/* Make the EFI call */
@@ -1406,6 +1406,7 @@ MmFwGetMemoryMap (
/* Initialize EFI memory map attributes */
EfiMemoryMapSize = MapKey = DescriptorSize = DescriptorVersion = 0;
LibraryBuffer = NULL;
/* Increment the nesting depth */
MmDescriptorCallTreeCount++;
@@ -460,7 +460,6 @@ DsppReinitialize (
!(GraphicsConsole) ||
!(((PBL_GRAPHICS_CONSOLE_VTABLE)GraphicsConsole->TextConsole.Callbacks)->IsEnabled(GraphicsConsole)))
{
EfiPrintf(L"Nothing to do for re-init\r\n");
return Status;
}
+5 -5
View File
@@ -149,8 +149,8 @@ MmMdpSwitchToDynamicDescriptors (
_In_ ULONG Count
)
{
EfiPrintf(L"dynamic switch NOT SUPPORTED!!!\r\n");
while (1);
EfiPrintf(L"Dynamic switch NOT SUPPORTED!!!\r\n");
EfiStall(10000000);
}
NTSTATUS
@@ -173,7 +173,8 @@ MmMdFreeDescriptor (
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;
}
@@ -1043,7 +1044,6 @@ MmMdFindSatisfyingRegion (
/* Check for start overflow */
if (BaseMin > BaseMax)
{
EfiPrintf(L"Descriptor overflow\r\n");
return FALSE;
}
@@ -1145,7 +1145,7 @@ MmMdFreeGlobalDescriptors (
/* 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)
{
+45 -6
View File
@@ -497,7 +497,7 @@ MmMapPhysicalAddress (
_In_ ULONG CacheAttributes
)
{
ULONGLONG Size, TotalSize;
ULONGLONG Size;
ULONGLONG PhysicalAddress;
PVOID VirtualAddress;
PHYSICAL_ADDRESS TranslatedAddress;
@@ -541,13 +541,13 @@ MmMapPhysicalAddress (
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 */
@@ -564,6 +564,7 @@ MmMapPhysicalAddress (
EfiPrintf(L"Existing mapping exists: %lx vs %lx\r\n",
TranslatedAddress.QuadPart,
PhysicalAddress + (CurrentAddress - (ULONG_PTR)VirtualAddress));
EfiStall(10000000);
return STATUS_INVALID_PARAMETER;
}
}
@@ -638,6 +639,44 @@ Mmx86MapInitStructure (
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,
@@ -1126,7 +1165,7 @@ MmArchInitialize (
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);
+1 -2
View File
@@ -196,7 +196,6 @@ BlMmMapPhysicalAddressEx (
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,
@@ -215,7 +214,7 @@ BlMmMapPhysicalAddressEx (
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;
+9 -8
View File
@@ -126,8 +126,8 @@ MmPapAllocateRegionFromMdl (
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,
@@ -1082,7 +1082,7 @@ MmPapFreePages (
/* 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;
}
@@ -1519,6 +1519,7 @@ MmSelectMappingAddress (
{
/* 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... */
@@ -1532,14 +1533,15 @@ MmSelectMappingAddress (
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;
}
@@ -1569,8 +1571,7 @@ MmSelectMappingAddress (
{
/* Add the offset to the returned virtual address */
PreferredAddress = (PVOID)((ULONG_PTR)PreferredAddress +
PhysicalAddress.LowPart -
BYTE_OFFSET(PhysicalAddress.LowPart));
BYTE_OFFSET(PhysicalAddress.QuadPart));
}
Success: