Author: ion
Date: Sun May 14 16:07:21 2017
New Revision: 74545
URL:
http://svn.reactos.org/svn/reactos?rev=74545&view=rev
Log:
Virtual memory works baby! Virtual Heap at 0x80000000 fully enabled. Next up, EFI
Protocols with Paging Enabled.
[BOOTLIB]: Fix dumb bug in BlMmIsTranslationEnabled which would always return FALSE.
[BOOTLIB]: Fix dumber bug in MmDefInitializeTranslation which was freeing the page
directories and self-map pages even in the success path. Causing us to zero out paging
structures...
[BOOTLIB]: Cleanup and extend MmMdDbgDumpList for internal use, and add
MmMdListPointerToName as another debug function.
[BOOTLIB]: Add a few more checkpoints in unimplemented paths.
Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/heapalloc.c
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c
Modified: trunk/reactos/boot/environ/include/bl.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?…
==============================================================================
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun May 14 16:07:21 2017
@@ -2023,9 +2023,10 @@
VOID
MmMdDbgDumpList (
- _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
+ _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
+ _In_opt_ ULONG MaxCount
);
-
+
VOID
MmMdInitializeList (
_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/…
==============================================================================
--- trunk/reactos/boot/environ/lib/firmware/efi/firmware.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/firmware/efi/firmware.c [iso-8859-1] Sun May 14
16:07:21 2017
@@ -176,6 +176,8 @@
{
/* We need complex tracking to make this work */
//Status = EfiVmOpenProtocol(Handle, Protocol, Interface);
+ EfiPrintf(L"Paging path hit!\r\n");
+ EfiStall(1000000);
Status = STATUS_NOT_SUPPORTED;
}
else
@@ -185,6 +187,8 @@
if (OldMode != BlRealMode)
{
/* FIXME: Not yet implemented */
+ EfiPrintf(L"Paging path hit!\r\n");
+ EfiStall(1000000);
return STATUS_NOT_IMPLEMENTED;
}
Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descri…
==============================================================================
--- trunk/reactos/boot/environ/lib/mm/descriptor.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c [iso-8859-1] Sun May 14 16:07:21 2017
@@ -1267,7 +1267,7 @@
/* Don't let the base overflow */
if (VirtualMin > VirtualMax)
{
- return 0;
+ return FALSE;
}
/* Adjust the base by the alignment delta */
@@ -1277,7 +1277,7 @@
if (((VirtualMin + Pages - 1) < VirtualMin) ||
((VirtualMin + Pages - 1) > VirtualMax))
{
- return 0;
+ return FALSE;
}
/* Finally, pick the correct address based on direction */
@@ -1302,7 +1302,7 @@
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;
}
Modified: trunk/reactos/boot/environ/lib/mm/heapalloc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/heapal…
==============================================================================
--- trunk/reactos/boot/environ/lib/mm/heapalloc.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/heapalloc.c [iso-8859-1] Sun May 14 16:07:21 2017
@@ -155,6 +155,8 @@
0);
if (!NT_SUCCESS(Status))
{
+ EfiPrintf(L"HEAP ALLOCATION FAILED\r\n");
+ EfiStall(1000000);
return Status;
}
Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/m…
==============================================================================
--- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] Sun May 14 16:07:21 2017
@@ -127,7 +127,7 @@
{
/* Return if paging is on */
return ((CurrentExecutionContext) &&
- (CurrentExecutionContext->Mode & BL_CONTEXT_PAGING_ON));
+ (CurrentExecutionContext->ContextFlags & BL_CONTEXT_PAGING_ON));
}
VOID
@@ -327,6 +327,8 @@
0);
if (!NT_SUCCESS(Status))
{
+ EfiPrintf(L"PDE alloc failed!\r\n");
+ EfiStall(1000000);
return STATUS_NO_MEMORY;
}
@@ -583,6 +585,7 @@
if (!NT_SUCCESS(Status))
{
EfiPrintf(L"Failed to map!: %lx\r\n", Status);
+ EfiStall(1000000);
return Status;
}
@@ -641,30 +644,43 @@
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,
@@ -673,6 +689,7 @@
VirtualEndPage ? (VirtualEndPage << PAGE_SHIFT) - 1 : 0,
(ULONG)MemoryDescriptor->Type);
+ /* Next entry */
NextEntry = NextEntry->Flink;
}
}
@@ -943,7 +960,7 @@
Status = MmPaTruncateMemory(0x100000);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Allocate a page directory */
@@ -957,7 +974,7 @@
0);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Zero out the page directory */
@@ -978,7 +995,7 @@
0);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Set the reference page */
@@ -993,7 +1010,7 @@
(4 * 1024 * 1024) >> PAGE_SHIFT);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Zero them out */
@@ -1020,7 +1037,7 @@
0);
if (!NT_SUCCESS(Status))
{
- goto Quickie;
+ goto Failure;
}
/* Remove HAL_HEAP from free virtual memory */
@@ -1031,22 +1048,25 @@
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");
-
-Quickie:
+ EfiPrintf(L"Paging... %d\r\n", BlMmIsTranslationEnabled());
+
+ /* Return success */
+ return Status;
+
+Failure:
/* Free reference page if we allocated it */
if (MmArchReferencePage)
{
Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pageal…
==============================================================================
--- trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] Sun May 14 16:07:21 2017
@@ -148,6 +148,31 @@
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,
@@ -207,7 +232,6 @@
Request->Flags,
Request->Alignment))
{
- /* It does, get out */
break;
}
@@ -225,7 +249,6 @@
/* Check if we exhausted the list */
if (NextEntry == ListHead)
{
- EfiPrintf(L"No matching memory found\r\n");
return Status;
}
@@ -246,6 +269,7 @@
if (!NT_SUCCESS(Status))
{
EfiPrintf(L"EFI memory allocation failure\r\n");
+ EfiStall(10000000);
return Status;
}
@@ -392,9 +416,18 @@
/* 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 */
@@ -601,7 +634,7 @@
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;
}