[BOOTLIB]: Implement MmArchTranslateVirtualAddress for non-paging mode. Stub Mmx86TranslateVirtualAddress.

[BOOTLIB]: Support EfiPrintf in Protected mode.
[BOOTLIB]: Support EfiGetMemoryMap in Protected Mode.

svn path=/trunk/; revision=73721
This commit is contained in:
Alex Ionescu
2017-02-05 22:34:47 +00:00
parent 0348b64178
commit 88dcf31856
5 changed files with 89 additions and 10 deletions
+7
View File
@@ -2175,6 +2175,13 @@ BlMmTranslateVirtualAddress (
_Out_ PPHYSICAL_ADDRESS PhysicalAddress _Out_ PPHYSICAL_ADDRESS PhysicalAddress
); );
BOOLEAN
MmArchTranslateVirtualAddress (
_In_ PVOID VirtualAddress,
_Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress,
_Out_opt_ PULONG CachingFlags
);
/* BLOCK ALLOCATOR ROUTINES **************************************************/ /* BLOCK ALLOCATOR ROUTINES **************************************************/
NTSTATUS NTSTATUS
@@ -143,12 +143,17 @@ EfiPrintf (
} }
else else
{ {
/* FIXME: @TODO: Not yet supported */ /* Switch to real mode */
// FIXME: Hack while we are in early rosload mode BlpArchSwitchContext(BlRealMode);
/* Call EFI directly */
if (EfiConOut != NULL) if (EfiConOut != NULL)
{ {
EfiConOut->OutputString(EfiConOut, BlScratchBuffer); EfiConOut->OutputString(EfiConOut, BlScratchBuffer);
} }
/* Switch back to protected mode */
BlpArchSwitchContext(BlProtectedMode);
} }
/* All done */ /* All done */
@@ -559,13 +564,27 @@ EfiGetMemoryMap (
{ {
BL_ARCH_MODE OldMode; BL_ARCH_MODE OldMode;
EFI_STATUS EfiStatus; EFI_STATUS EfiStatus;
PHYSICAL_ADDRESS MemoryMapSizePhysical, MemoryMapPhysical, MapKeyPhysical;
PHYSICAL_ADDRESS DescriptorSizePhysical, DescriptorVersionPhysical;
/* Are we in protected mode? */ /* Are we in protected mode? */
OldMode = CurrentExecutionContext->Mode; OldMode = CurrentExecutionContext->Mode;
if (OldMode != BlRealMode) if (OldMode != BlRealMode)
{ {
/* FIXME: Not yet implemented */ /* Convert all of the addresses to physical */
return STATUS_NOT_IMPLEMENTED; BlMmTranslateVirtualAddress(MemoryMapSize, &MemoryMapSizePhysical);
MemoryMapSize = (UINTN*)MemoryMapSizePhysical.LowPart;
BlMmTranslateVirtualAddress(MemoryMap, &MemoryMapPhysical);
MemoryMap = (EFI_MEMORY_DESCRIPTOR*)MemoryMapPhysical.LowPart;
BlMmTranslateVirtualAddress(MapKey, &MapKeyPhysical);
MapKey = (UINTN*)MapKeyPhysical.LowPart;
BlMmTranslateVirtualAddress(DescriptorSize, &DescriptorSizePhysical);
DescriptorSize = (UINTN*)DescriptorSizePhysical.LowPart;
BlMmTranslateVirtualAddress(DescriptorVersion, &DescriptorVersionPhysical);
DescriptorVersion = (UINTN*)DescriptorVersionPhysical.LowPart;
/* Switch to real mode */
BlpArchSwitchContext(BlProtectedMode);
} }
/* Make the EFI call */ /* Make the EFI call */
+53
View File
@@ -78,6 +78,59 @@ Mmx86pMapMemoryRegions (
return STATUS_NOT_IMPLEMENTED; return STATUS_NOT_IMPLEMENTED;
} }
BOOLEAN
Mmx86TranslateVirtualAddress (
_In_ PVOID VirtualAddress,
_Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress,
_Out_opt_ PULONG CachingFlags
)
{
EfiPrintf(L"paging TODO\r\n");
return FALSE;
}
BOOLEAN
MmArchTranslateVirtualAddress (
_In_ PVOID VirtualAddress,
_Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress,
_Out_opt_ PULONG CachingFlags
)
{
PBL_MEMORY_DESCRIPTOR Descriptor;
/* Check if paging is on */
if ((CurrentExecutionContext) &&
(CurrentExecutionContext->ContextFlags & BL_CONTEXT_PAGING_ON))
{
/* Yes -- we have to translate this from virtual */
return Mmx86TranslateVirtualAddress(VirtualAddress,
PhysicalAddress,
CachingFlags);
}
/* Look in all descriptors except truncated and firmware ones */
Descriptor = MmMdFindDescriptor(BL_MM_INCLUDE_NO_FIRMWARE_MEMORY &
~BL_MM_INCLUDE_TRUNCATED_MEMORY,
BL_MM_REMOVE_PHYSICAL_REGION_FLAG,
(ULONG_PTR)VirtualAddress >> PAGE_SHIFT);
/* Return the virtual address as the physical address */
if (PhysicalAddress)
{
PhysicalAddress->HighPart = 0;
PhysicalAddress->LowPart = (ULONG_PTR)VirtualAddress;
}
/* There's no caching on physical memory */
if (CachingFlags)
{
*CachingFlags = 0;
}
/* Success is if we found a descriptor */
return Descriptor != NULL;
}
NTSTATUS NTSTATUS
MmArchInitialize ( MmArchInitialize (
_In_ ULONG Phase, _In_ ULONG Phase,
+2 -3
View File
@@ -312,9 +312,8 @@ BlMmTranslateVirtualAddress (
return FALSE; return FALSE;
} }
EfiPrintf(L"Unhandled virtual path\r\n"); /* Do the architecture-specific translation */
return FALSE; return MmArchTranslateVirtualAddress(VirtualAddress, PhysicalAddress, NULL);
//return MmArchTranslateVirtualAddress(VirtualAddress, PhysicalAddress, NULL);
} }
NTSTATUS NTSTATUS
+4 -3
View File
@@ -888,8 +888,9 @@ BlMmGetMemoryMap (
/* Free the previous entries, if any */ /* Free the previous entries, if any */
MmMdFreeList(&FirmwareMdList); MmMdFreeList(&FirmwareMdList);
/* Get the firmware map */ /* Get the firmware map, coalesced */
Status = MmFwGetMemoryMap(&FirmwareMdList, 2); Status = MmFwGetMemoryMap(&FirmwareMdList,
BL_MM_FLAG_REQUEST_COALESCING);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
goto Quickie; goto Quickie;
@@ -905,7 +906,7 @@ BlMmGetMemoryMap (
/* Free the previous entries, if any */ /* Free the previous entries, if any */
MmMdFreeList(&FirmwareMdList); MmMdFreeList(&FirmwareMdList);
/* Get the firmware map */ /* Get the firmware map, uncoalesced */
Status = MmFwGetMemoryMap(&FirmwareMdList, 0); Status = MmFwGetMemoryMap(&FirmwareMdList, 0);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {