]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Core/Dxe/Image/Image.c
Integrated FV memory map into R9
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / Image / Image.c
index 4e6bd0843e8edaba79d170c6365748ce55864f34..9a2723765d015227600143dc359d636f406b9600 100644 (file)
@@ -219,8 +219,8 @@ Returns:
 \r
   if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine)) {\r
     //\r
-    // The PE/COFF loader can support loading image types that can be executed. \r
-    // If we loaded an image type that we can not execute return EFI_UNSUPORTED. \r
+    // The PE/COFF loader can support loading image types that can be executed.\r
+    // If we loaded an image type that we can not execute return EFI_UNSUPORTED.\r
     //\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -247,17 +247,30 @@ Returns:
     // If the image relocations have not been stripped, then load at any address.\r
     // Otherwise load at the address at which it was linked.\r
     //\r
-    Status = CoreAllocatePages (\r
-               (Image->ImageContext.RelocationsStripped) ? AllocateAddress : AllocateAnyPages,\r
-               Image->ImageContext.ImageCodeMemoryType,\r
-               Image->NumberOfPages,\r
-               &Image->ImageContext.ImageAddress\r
-               );\r
+    // Memory below 1MB should be treated reserved for CSM and there should be\r
+    // no modules whose preferred load addresses are below 1MB.\r
+    //\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    if (Image->ImageContext.ImageAddress >= 0x100000 || Image->ImageContext.RelocationsStripped) {\r
+      Status = CoreAllocatePages (\r
+                 AllocateAddress,\r
+                 Image->ImageContext.ImageCodeMemoryType,\r
+                 Image->NumberOfPages,\r
+                 &Image->ImageContext.ImageAddress\r
+                 );\r
+    }\r
+    if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) {\r
+      Status = CoreAllocatePages (\r
+                 AllocateAnyPages,\r
+                 Image->ImageContext.ImageCodeMemoryType,\r
+                 Image->NumberOfPages,\r
+                 &Image->ImageContext.ImageAddress\r
+                 );\r
+    }\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
     DstBufAlocated = TRUE;\r
-\r
   } else {\r
     //\r
     // Caller provided the destination buffer\r
@@ -394,7 +407,7 @@ Returns:
       InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Fill in the entry point of the image if it is available\r
   //\r
@@ -407,7 +420,7 @@ Returns:
   //\r
 \r
   DEBUG_CODE_BEGIN ();\r
\r
+\r
     UINTN Index;\r
     UINTN StartIndex;\r
     CHAR8 EfiFileName[256];\r
@@ -439,7 +452,7 @@ Returns:
       DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));\r
     }\r
     DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));\r
-  \r
+\r
   DEBUG_CODE_END ();\r
 \r
   return EFI_SUCCESS;\r
@@ -449,11 +462,11 @@ Done:
   //\r
   // Free memory.\r
   //\r
-  \r
+\r
   if (DstBufAlocated) {\r
     CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);\r
   }\r
-  \r
+\r
   if (Image->ImageContext.FixupData != NULL) {\r
     CoreFreePool (Image->ImageContext.FixupData);\r
   }\r
@@ -927,8 +940,8 @@ Returns:
 \r
   SetJumpFlag = SetJump (Image->JumpContext);\r
   //\r
-  // The initial call to SetJump() must always return 0.  \r
-  // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump(). \r
+  // The initial call to SetJump() must always return 0.\r
+  // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump().\r
   //\r
   if (!SetJumpFlag) {\r
     //\r
@@ -1142,7 +1155,7 @@ Returns:
     }\r
     CoreFreePool (Image->RuntimeData);\r
   }\r
-  \r
+\r
   //\r
   // Free the Image from memory\r
   //\r