/* Don't let the base overflow */
if (VirtualMin > VirtualMax)
{
- return 0;
+ return FALSE;
}
/* Adjust the base by the alignment delta */
if (((VirtualMin + Pages - 1) < VirtualMin) ||
((VirtualMin + Pages - 1) > VirtualMax))
{
- return 0;
+ return FALSE;
}
/* Finally, pick the correct address based on direction */
if ((((Flags & 0xFF) & (Descriptor->Flags & 0xFF)) != (Flags & 0xFF)) ||
(((Flags & 0xFF00) & (Descriptor->Flags & 0xFF00)) != (Flags & 0xFF00)))
{
- EfiPrintf(L"Incorrect memory attributes\r\n");
+ //EfiPrintf(L"Incorrect memory attributes\r\n");
return FALSE;
}
{
/* Return if paging is on */
return ((CurrentExecutionContext) &&
- (CurrentExecutionContext->Mode & BL_CONTEXT_PAGING_ON));
+ (CurrentExecutionContext->ContextFlags & BL_CONTEXT_PAGING_ON));
}
VOID
0);
if (!NT_SUCCESS(Status))
{
+ EfiPrintf(L"PDE alloc failed!\r\n");
+ EfiStall(1000000);
return STATUS_NO_MEMORY;
}
if (!NT_SUCCESS(Status))
{
EfiPrintf(L"Failed to map!: %lx\r\n", Status);
+ EfiStall(1000000);
return Status;
}
VOID
MmMdDbgDumpList (
- _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
+ _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
+ _In_opt_ ULONG MaxCount
)
{
ULONGLONG EndPage, VirtualEndPage;
PBL_MEMORY_DESCRIPTOR MemoryDescriptor;
PLIST_ENTRY NextEntry;
+ /* If no maximum was provided, use essentially infinite */
+ if (MaxCount == 0)
+ {
+ MaxCount = 0xFFFFFFFF;
+ }
+
+ /* Loop the list as long as there's entries and max isn't reached */
NextEntry = DescriptorList->First->Flink;
- while (NextEntry != DescriptorList->First)
+ while ((NextEntry != DescriptorList->First) && (MaxCount--))
{
+ /* Get the descriptor */
MemoryDescriptor = CONTAINING_RECORD(NextEntry,
BL_MEMORY_DESCRIPTOR,
ListEntry);
+ /* Get the descriptor end page, and see if it was virtually mapepd */
EndPage = MemoryDescriptor->BasePage + MemoryDescriptor->PageCount;
- if (MemoryDescriptor->VirtualPage != 0)
+ if (MemoryDescriptor->VirtualPage)
{
- VirtualEndPage = MemoryDescriptor->VirtualPage + MemoryDescriptor->PageCount;
+ /* Get the virtual end page too, then */
+ VirtualEndPage = MemoryDescriptor->VirtualPage +
+ MemoryDescriptor->PageCount;
}
else
{
VirtualEndPage = 0;
}
+ /* Print out the descriptor, physical range, virtual range, and type */
EfiPrintf(L"%p - [%08llx-%08llx @ %08llx-%08llx]:%x\r\n",
MemoryDescriptor,
MemoryDescriptor->BasePage << PAGE_SHIFT,
VirtualEndPage ? (VirtualEndPage << PAGE_SHIFT) - 1 : 0,
(ULONG)MemoryDescriptor->Type);
+ /* Next entry */
NextEntry = NextEntry->Flink;
}
}
Status = MmPaTruncateMemory(0x100000);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Allocate a page directory */
0);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Zero out the page directory */
0);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Set the reference page */
(4 * 1024 * 1024) >> PAGE_SHIFT);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Zero them out */
0);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Remove HAL_HEAP from free virtual memory */
0);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Initialize the virtual->physical memory mappings */
Status = Mmx86InitializeMemoryMap(1, MemoryData);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Turn on paging with the new CR3 */
__writecr3((ULONG_PTR)MmPdpt);
BlpArchEnableTranslation();
- EfiPrintf(L"Paging... ON\r\n");
+ EfiPrintf(L"Paging... %d\r\n", BlMmIsTranslationEnabled());
+
+ /* Return success */
+ return Status;
-Quickie:
+Failure:
/* Free reference page if we allocated it */
if (MmArchReferencePage)
{
return ReturnStatus;
}
+PWCHAR
+MmMdListPointerToName (_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList)
+{
+ if (MdList == &MmMdlUnmappedAllocated)
+ {
+ return L"UnmapAlloc";
+ }
+ else if (MdList == &MmMdlUnmappedUnallocated)
+ {
+ return L"UnmapUnalloc";
+ }
+ else if (MdList == &MmMdlMappedAllocated)
+ {
+ return L"MapAlloc";
+ }
+ else if (MdList == &MmMdlMappedUnallocated)
+ {
+ return L"MapUnalloc";
+ }
+ else
+ {
+ return L"Other";
+ }
+}
+
NTSTATUS
MmPapAllocateRegionFromMdl (
_In_ PBL_MEMORY_DESCRIPTOR_LIST NewList,
Request->Flags,
Request->Alignment))
{
- /* It does, get out */
break;
}
/* Check if we exhausted the list */
if (NextEntry == ListHead)
{
- EfiPrintf(L"No matching memory found\r\n");
return Status;
}
if (!NT_SUCCESS(Status))
{
EfiPrintf(L"EFI memory allocation failure\r\n");
+ EfiStall(10000000);
return Status;
}
/* Are we failing due to some attributes? */
if (Request->Flags & BlMemoryValidAllocationAttributeMask)
{
- EfiPrintf(L"alloc fail not yet implemented %lx in %S\r\n", Status, __FUNCTION__);
- EfiStall(1000000);
- return STATUS_NOT_IMPLEMENTED;
+ if (Request->Flags & BlMemoryLargePages)
+ {
+ EfiPrintf(L"large alloc fail not yet implemented %lx\r\n", Status);
+ EfiStall(1000000);
+ return STATUS_NOT_IMPLEMENTED;
+ }
+ if (Request->Flags & BlMemoryFixed)
+ {
+ EfiPrintf(L"fixed alloc fail not yet implemented %lx\r\n", Status);
+ EfiStall(1000000);
+ return STATUS_NOT_IMPLEMENTED;
+ }
}
/* Nope, just fail the entire call */
BlConventionalMemory);
if (!NT_SUCCESS(Status))
{
- EfiPrintf(L"Failed to get unmapped,unallocated memory!\r\n");
+ EfiPrintf(L"Failed to get unmapped, unallocated memory!\r\n");
EfiStall(10000000);
return Status;
}