]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Library/PrePiLib/PrePiLib.c
EmbeddedPkg/PrePiLib: allocate code pages for DxeCore
[mirror_edk2.git] / EmbeddedPkg / Library / PrePiLib / PrePiLib.c
index 9a1ef344df6e4c5f027fb6db050c8ddb500dd0a8..d119cf33a5d36772bbe38437921ff6ead07a9cdb 100644 (file)
@@ -28,6 +28,37 @@ SecWinNtPeiLoadFile (
   IN  EFI_PHYSICAL_ADDRESS    *EntryPoint\r
   );\r
 \r
+STATIC\r
+VOID*\r
+EFIAPI\r
+AllocateCodePages (\r
+  IN  UINTN     Pages\r
+  )\r
+{\r
+  VOID                    *Alloc;\r
+  EFI_PEI_HOB_POINTERS    Hob;\r
+\r
+  Alloc = AllocatePages (Pages);\r
+  if (Alloc == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  // find the HOB we just created, and change the type to EfiBootServicesCode\r
+  Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
+  while (Hob.Raw != NULL) {\r
+    if (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == (UINTN)Alloc) {\r
+      Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiBootServicesCode;\r
+      return Alloc;\r
+    }\r
+    Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (Hob));\r
+  }\r
+\r
+  ASSERT (FALSE);\r
+\r
+  FreePages (Alloc, Pages);\r
+  return NULL;\r
+}\r
+\r
 \r
 EFI_STATUS\r
 EFIAPI\r
@@ -54,7 +85,7 @@ LoadPeCoffImage (
   //\r
   // Allocate Memory for the image\r
   //\r
-  Buffer = AllocatePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize));\r
+  Buffer = AllocateCodePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize));\r
   ASSERT (Buffer != 0);\r
 \r
 \r