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
//\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