]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Library/PrePiLib/PrePiLib.c
EmbeddedPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmbeddedPkg / Library / PrePiLib / PrePiLib.c
index 4cc974f1a9b3cc152b86c71ad8e48fb5b777bbf8..afbe1466326b5330f13c2008a60140366b7901a4 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
-  \r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -28,6 +22,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
@@ -43,18 +68,18 @@ LoadPeCoffImage (
   VOID                           *Buffer;\r
 \r
   ZeroMem (&ImageContext, sizeof (ImageContext));\r
-    \r
+\r
   ImageContext.Handle    = PeCoffImage;\r
   ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
 \r
   Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
 \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
@@ -88,7 +113,7 @@ LoadPeCoffImage (
 \r
 \r
 \r
-typedef \r
+typedef\r
 VOID\r
 (EFIAPI *DXE_CORE_ENTRY_POINT) (\r
   IN  VOID *HobStart\r
@@ -116,7 +141,7 @@ LoadDxeCoreFromFfsFile (
     return Status;\r
   }\r
 \r
-  \r
+\r
   Status = LoadPeCoffImage (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);\r
 // For NT32 Debug  Status = SecWinNtPeiLoadFile (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);\r
   ASSERT_EFI_ERROR (Status);\r
@@ -128,22 +153,22 @@ LoadDxeCoreFromFfsFile (
   ASSERT_EFI_ERROR (Status);\r
 \r
   BuildModuleHob (&FvFileInfo.FileName, (EFI_PHYSICAL_ADDRESS)(UINTN)ImageAddress, EFI_SIZE_TO_PAGES ((UINT32) ImageSize) * EFI_PAGE_SIZE, EntryPoint);\r
-  \r
+\r
   DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading DxeCore at 0x%10p EntryPoint=0x%10p\n", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)EntryPoint));\r
 \r
   Hob = GetHobList ();\r
   if (StackSize == 0) {\r
     // User the current stack\r
-  \r
+\r
     ((DXE_CORE_ENTRY_POINT)(UINTN)EntryPoint) (Hob);\r
   } else {\r
-    \r
+\r
     //\r
     // Allocate 128KB for the Stack\r
     //\r
     BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (StackSize));\r
     ASSERT (BaseOfStack != NULL);\r
-  \r
+\r
     //\r
     // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
     // for safety.\r
@@ -153,7 +178,7 @@ LoadDxeCoreFromFfsFile (
 \r
     //\r
     // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.\r
-    //    \r
+    //\r
     UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, StackSize);\r
 \r
     SwitchStack (\r
@@ -164,11 +189,11 @@ LoadDxeCoreFromFfsFile (
       );\r
 \r
   }\r
-  \r
+\r
   // Should never get here as DXE Core does not return\r
   DEBUG ((EFI_D_ERROR, "DxeCore returned\n"));\r
   ASSERT (FALSE);\r
-  \r
+\r
   return EFI_DEVICE_ERROR;\r
 }\r
 \r
@@ -199,9 +224,9 @@ LoadDxeCoreFromFv (
 \r
   if (!EFI_ERROR (Status)) {\r
     return LoadDxeCoreFromFfsFile (FileHandle, StackSize);\r
-  } \r
-  \r
-  return Status;  \r
+  }\r
+\r
+  return Status;\r
 }\r
 \r
 \r
@@ -219,7 +244,7 @@ DecompressFirstFv (
   if (!EFI_ERROR (Status)) {\r
     Status = FfsProcessFvFile (FileHandle);\r
   }\r
-  \r
+\r
   return Status;\r
 }\r
 \r