[BOOTLIB] Additional EfiPrintf conversion like r73736 for MSVC 2013
[reactos.git] / reactos / boot / environ / lib / mm / i386 / mmx86.c
index cde5afd..48632a9 100644 (file)
@@ -507,10 +507,8 @@ MmSelectMappingAddress (
     }
 
     /* We don't support virtual memory yet @TODO */
-#ifdef _MSC_VER // Fuck gcc.
-    EfiPrintf(L"not yet implemented in " __FUNCTION__ "\r\n");
+    EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__);
     EfiStall(1000000);
-#endif
     return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -677,10 +675,13 @@ Mmx86pMapMemoryRegions (
     ULONGLONG Size;
     NTSTATUS Status;
     PVOID VirtualAddress;
+    BL_MEMORY_DESCRIPTOR_LIST FirmwareMdl;
+    PLIST_ENTRY Head, NextEntry;
 
-    /* In phase 1 we don't initialize deferred mappings*/
+    /* Check which phase this is */
     if (Phase == 1)
     {
+        /* In phase 1 we don't initialize deferred mappings */
         DoDeferred = FALSE;
     }
     else
@@ -691,6 +692,7 @@ Mmx86pMapMemoryRegions (
             return STATUS_SUCCESS;
         }
 
+        /* We'll do deferred descriptors in phase 2 */
         DoDeferred = TRUE;
     }
 
@@ -756,10 +758,59 @@ Mmx86pMapMemoryRegions (
     /* In phase 1, also do UEFI mappings */
     if (Phase != 2)
     {
-        EfiPrintf(L"Phase 1 TODO UEFI mappings \r\n");
+        /* Get the memory map */
+        MmMdInitializeListHead(&FirmwareMdl);
+        Status = MmFwGetMemoryMap(&FirmwareMdl, BL_MM_FLAG_REQUEST_COALESCING);
+        if (!NT_SUCCESS(Status))
+        {
+            return Status;
+        }
+
+        /* Iterate over it */
+        Head = FirmwareMdl.First;
+        NextEntry = Head->Flink;
+        while (NextEntry != Head)
+        {
+            /* Check if this is a UEFI-related descriptor, unless it's the self-map page */
+            Descriptor = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, ListEntry);
+            if (((Descriptor->Type == BlEfiBootMemory) ||
+                 (Descriptor->Type == BlEfiRuntimeMemory) ||
+                 (Descriptor->Type == BlLoaderMemory)) &&
+                ((Descriptor->BasePage << PAGE_SHIFT) != Mmx86SelfMapBase.QuadPart))
+            {
+                /* Identity-map it */
+                PhysicalAddress.QuadPart = Descriptor->BasePage << PAGE_SHIFT;
+                Status = Mmx86MapInitStructure((PVOID)((ULONG_PTR)Descriptor->BasePage << PAGE_SHIFT),
+                                               Descriptor->PageCount << PAGE_SHIFT,
+                                               PhysicalAddress);
+                if (!NT_SUCCESS(Status))
+                {
+                    return Status;
+                }
+            }
+
+            /* Move to the next descriptor */
+            NextEntry = NextEntry->Flink;
+        }
+
+        /* Reset */
+        NextEntry = Head->Flink;
+        while (NextEntry != Head)
+        {
+            /* Get the descriptor */
+            Descriptor = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, ListEntry);
+
+            /* Skip to the next entry before we free */
+            NextEntry = NextEntry->Flink;
+
+            /* Remove and free it */
+            MmMdRemoveDescriptorFromList(&FirmwareMdl, Descriptor);
+            MmMdFreeDescriptor(Descriptor);
+        }
     }
 
-    return STATUS_NOT_IMPLEMENTED;
+    /* All library mappings identity mapped now */
+    return STATUS_SUCCESS;
 }
 
 NTSTATUS
@@ -1114,14 +1165,17 @@ MmArchInitialize (
 
         case BlPae:
 
+            /* We don't support PAE */
             Status = STATUS_NOT_SUPPORTED;
             break;
 
         default:
+
+            /* Invalid architecture type*/
             Status = STATUS_INVALID_PARAMETER;
             break;
     }
 
+    /* Back to caller */
     return Status;
-
 }