]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmulatorPkg/Win/Host/WinHost.c
EmulatorPkg/WinHost: pre-allocate "physical" RAM
[mirror_edk2.git] / EmulatorPkg / Win / Host / WinHost.c
index 93247c5043085e9437f7c274f12b8f7894221a43..5b780ca8afef1a98626de9e79b7d7ea350ec89ba 100644 (file)
@@ -8,7 +8,7 @@
   This code produces 128 K of temporary memory for the SEC stack by directly\r
   allocate memory space with ReadWrite and Execute attribute.\r
 \r
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016-2020 Hewlett Packard Enterprise Development LP<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
@@ -87,14 +87,6 @@ WinPeiAutoScan (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  //\r
-  // Allocate enough memory space for emulator\r
-  //\r
-  gSystemMemory[Index].Memory = (EFI_PHYSICAL_ADDRESS)(UINTN)VirtualAlloc (NULL, (SIZE_T)(gSystemMemory[Index].Size), MEM_COMMIT, PAGE_EXECUTE_READWRITE);\r
-  if (gSystemMemory[Index].Memory == 0) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
   *MemoryBase = gSystemMemory[Index].Memory;\r
   *MemorySize = gSystemMemory[Index].Size;\r
 \r
@@ -457,6 +449,30 @@ Returns:
     exit (1);\r
   }\r
 \r
+  //\r
+  // Allocate "physical" memory space for emulator. It will be reported out later throuth MemoryAutoScan()\r
+  //\r
+  for (Index = 0, Done = FALSE; !Done; Index++) {\r
+    ASSERT (Index < gSystemMemoryCount);\r
+    gSystemMemory[Index].Size   = ((UINT64)_wtoi (MemorySizeStr)) * ((UINT64)SIZE_1MB);\r
+    gSystemMemory[Index].Memory = (EFI_PHYSICAL_ADDRESS)(UINTN)VirtualAlloc (NULL, (SIZE_T)(gSystemMemory[Index].Size), MEM_COMMIT, PAGE_EXECUTE_READWRITE);\r
+    if (gSystemMemory[Index].Memory == 0) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    //\r
+    // Find the next region\r
+    //\r
+    for (Index1 = 0; MemorySizeStr[Index1] != '!' && MemorySizeStr[Index1] != 0; Index1++) {\r
+    }\r
+\r
+    if (MemorySizeStr[Index1] == 0) {\r
+      Done = TRUE;\r
+    }\r
+\r
+    MemorySizeStr = MemorySizeStr + Index1 + 1;\r
+  }\r
+\r
   //\r
   // Allocate space for gSystemMemory Array\r
   //\r
@@ -575,32 +591,6 @@ Returns:
     SecPrint ("\n\r");\r
   }\r
 \r
-  //\r
-  // Calculate memory regions and store the information in the gSystemMemory\r
-  //  global for later use. The autosizing code will use this data to\r
-  //  map this memory into the SEC process memory space.\r
-  //\r
-  for (Index = 0, Done = FALSE; !Done; Index++) {\r
-    //\r
-    // Save the size of the memory and make a Unicode filename SystemMemory00, ...\r
-    //\r
-    gSystemMemory[Index].Size = ((UINT64)_wtoi (MemorySizeStr)) * ((UINT64)SIZE_1MB);\r
-\r
-    //\r
-    // Find the next region\r
-    //\r
-    for (Index1 = 0; MemorySizeStr[Index1] != '!' && MemorySizeStr[Index1] != 0; Index1++) {\r
-    }\r
-\r
-    if (MemorySizeStr[Index1] == 0) {\r
-      Done = TRUE;\r
-    }\r
-\r
-    MemorySizeStr = MemorySizeStr + Index1 + 1;\r
-  }\r
-\r
-  SecPrint ("\n\r");\r
-\r
   //\r
   // Hand off to SEC Core\r
   //\r