]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Core/DxeIplPeim/DxeLoad.c
Make EDK Module Package pass Intel IPF compiler with /Ox switch.
[mirror_edk2.git] / EdkModulePkg / Core / DxeIplPeim / DxeLoad.c
index 8c3de0522d9ca46f8a84e5cf26f8247b956127ba..4d9ec5218a1de05c6a443ca89329850ed771fed5 100644 (file)
@@ -22,10 +22,6 @@ Abstract:
 \r
 #include "DxeIpl.h"\r
 \r
-#ifndef __GNUC__\r
-#pragma warning( disable : 4305 )\r
-#endif\r
-\r
 BOOLEAN gInMemory = FALSE;\r
 \r
 //\r
@@ -151,9 +147,6 @@ Returns:
 --*/\r
 {\r
   EFI_STATUS                                Status;\r
-  EFI_PHYSICAL_ADDRESS                      TopOfStack;\r
-  EFI_PHYSICAL_ADDRESS                      BaseOfStack;\r
-  EFI_PHYSICAL_ADDRESS                      BspStore;\r
   EFI_GUID                                  DxeCoreFileName;\r
   EFI_GUID                                  FirmwareFileName;\r
   VOID                                      *Pe32Data;\r
@@ -165,13 +158,8 @@ Returns:
   EFI_BOOT_MODE                             BootMode;\r
   EFI_PEI_RECOVERY_MODULE_PPI               *PeiRecovery;\r
   EFI_PEI_S3_RESUME_PPI                     *S3Resume;\r
-  EFI_PHYSICAL_ADDRESS                      PageTables;\r
 \r
 //  PERF_START (PeiServices, L"DxeIpl", NULL, 0);\r
-  TopOfStack  = 0;\r
-  BaseOfStack = 0;\r
-  BspStore    = 0;\r
-  PageTables  = 0;\r
 \r
   //\r
   // if in S3 Resume, restore configure\r
@@ -217,17 +205,6 @@ Returns:
   PeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)GetPeCoffLoaderProtocol ();\r
   ASSERT (PeiEfiPeiPeCoffLoader != NULL);\r
 \r
-  //\r
-  // Allocate 128KB for the Stack\r
-  //\r
-  PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);\r
-  ASSERT (BaseOfStack != 0);\r
-\r
-  //\r
-  // Add architecture-specifc HOBs (including the BspStore HOB)\r
-  //\r
-  Status = CreateArchSpecificHobs (&BspStore);\r
-  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Find the EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE type compressed Firmware Volume file\r
@@ -264,14 +241,6 @@ Returns:
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  //\r
-  // Transfer control to the DXE Core\r
-  // The handoff state is simply a pointer to the HOB list\r
-  //\r
-\r
-  Status = PeiServicesInstallPpi (&mPpiSignal);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   //\r
   // Add HOB for the DXE Core\r
   //\r
@@ -290,70 +259,37 @@ Returns:
     EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT\r
     );\r
 \r
-  DEBUG ((EFI_D_INFO, "DXE Core Entry\n"));\r
-  if (FeaturePcdGet(PcdDxeIplSwitchToLongMode)) {\r
-    //\r
-    // Compute the top of the stack we were allocated, which is used to load X64 dxe core. \r
-    // Pre-allocate a 32 bytes which confroms to x64 calling convention.\r
-    //\r
-    // The first four parameters to a function are passed in rcx, rdx, r8 and r9. \r
-    // Any further parameters are pushed on the stack. Furthermore, space (4 * 8bytes) for the \r
-    // register parameters is reserved on the stack, in case the called function \r
-    // wants to spill them; this is important if the function is variadic. \r
-    //\r
-    TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - 32;\r
-\r
-    //\r
-    //  X64 Calling Conventions requires that the stack must be aligned to 16 bytes\r
-    //\r
-    TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16);\r
-    //\r
-    // Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA\r
-    // memory, it may be corrupted when copying FV to high-end memory \r
-    //\r
-    LoadGo64Gdt();\r
-    //\r
-    // Limit to 36 bits of addressing for debug. Should get it from CPU\r
-    //\r
-    PageTables = CreateIdentityMappingPageTables (36);\r
-    //\r
-    // Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.\r
-    // Call x64 drivers passing in single argument, a pointer to the HOBs.\r
-    //\r
-    ActivateLongMode (\r
-      PageTables, \r
-      (EFI_PHYSICAL_ADDRESS)(UINTN)(HobList.Raw), \r
-      TopOfStack,\r
-      0x00000000,\r
-      DxeCoreEntryPoint\r
-      );\r
-  } else {\r
-    //\r
-    // Add HOB for the EFI Decompress Protocol\r
-    //\r
-    BuildGuidDataHob (\r
-      &gEfiDecompressProtocolGuid,\r
-      (VOID *)&gEfiDecompress,\r
-      sizeof (gEfiDecompress)\r
-      );\r
-\r
-    //\r
-    // Add HOB for the Tiano Decompress Protocol\r
-    //\r
-    BuildGuidDataHob (\r
-      &gEfiTianoDecompressProtocolGuid,\r
-      (VOID *)&gTianoDecompress,\r
-      sizeof (gTianoDecompress)\r
-      );\r
-\r
-    //\r
-    // Add HOB for the user customized Decompress Protocol\r
-    //\r
-    BuildGuidDataHob (\r
-      &gEfiCustomizedDecompressProtocolGuid,\r
-      (VOID *)&gCustomDecompress,\r
-      sizeof (gCustomDecompress)\r
-      );\r
+  if (FeaturePcdGet (PcdDxeIplBuildShareCodeHobs)) {\r
+    if (FeaturePcdGet (PcdDxeIplSupportEfiDecompress)) {\r
+      //\r
+      // Add HOB for the EFI Decompress Protocol\r
+      //\r
+      BuildGuidDataHob (\r
+        &gEfiDecompressProtocolGuid,\r
+        (VOID *)&gEfiDecompress,\r
+        sizeof (gEfiDecompress)\r
+        );\r
+    }\r
+    if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress)) {\r
+      //\r
+      // Add HOB for the Tiano Decompress Protocol\r
+      //\r
+      BuildGuidDataHob (\r
+        &gEfiTianoDecompressProtocolGuid,\r
+        (VOID *)&gTianoDecompress,\r
+        sizeof (gTianoDecompress)\r
+        );\r
+    }\r
+    if (FeaturePcdGet (PcdDxeIplSupportCustomDecompress)) {\r
+      //\r
+      // Add HOB for the user customized Decompress Protocol\r
+      //\r
+      BuildGuidDataHob (\r
+        &gEfiCustomizedDecompressProtocolGuid,\r
+        (VOID *)&gCustomDecompress,\r
+        sizeof (gCustomDecompress)\r
+        );\r
+    }\r
 \r
     //\r
     // Add HOB for the PE/COFF Loader Protocol\r
@@ -363,21 +299,15 @@ Returns:
       (VOID *)&PeiEfiPeiPeCoffLoader,\r
       sizeof (VOID *)\r
       );\r
-    //\r
-    // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
-    // for safety.\r
-    //\r
-    TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT;\r
-    TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
-\r
-    SwitchIplStacks (\r
-      (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
-      HobList.Raw,\r
-      NULL,\r
-      (VOID *) (UINTN) TopOfStack,\r
-      (VOID *) (UINTN) BspStore\r
-      );\r
-  } \r
+  }\r
+\r
+  //\r
+  // Transfer control to the DXE Core\r
+  // The handoff state is simply a pointer to the HOB list\r
+  //\r
+\r
+  DEBUG ((EFI_D_INFO, "DXE Core Entry Point 0x%08x\n", (UINTN) DxeCoreEntryPoint));\r
+  HandOffToDxeCore (DxeCoreEntryPoint, HobList, &mPpiSignal);\r
   //\r
   // If we get here, then the DXE Core returned.  This is an error\r
   // Dxe Core should not return.\r
@@ -425,14 +355,12 @@ Returns:
 {\r
   EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;\r
   EFI_FFS_FILE_HEADER         *FfsFileHeader;\r
-  VOID                        *SectionData;\r
   EFI_STATUS                  Status;\r
   EFI_PEI_HOB_POINTERS        Hob;\r
 \r
 \r
   FwVolHeader   = NULL;\r
   FfsFileHeader = NULL;\r
-  SectionData   = NULL;\r
   Status        = EFI_SUCCESS;\r
 \r
   //\r
@@ -724,7 +652,6 @@ Returns:
   UINTN                           SectionLength;\r
   UINTN                           OccupiedSectionLength;\r
   UINT64                          FileSize;\r
-  EFI_GUID_DEFINED_SECTION        *GuidedSectionHeader;\r
   UINT32                          AuthenticationStatus;\r
   EFI_PEI_SECTION_EXTRACTION_PPI  *SectionExtract;\r
   UINT32                          BufferSize;\r
@@ -736,6 +663,13 @@ Returns:
   EFI_COMPRESSION_SECTION         *CompressionSection;\r
   UINT32                          FvAlignment;\r
 \r
+  //\r
+  // Initialize local variables.\r
+  //\r
+  DecompressLibrary = NULL;\r
+  DstBuffer         = NULL;\r
+  DstBufferSize     = 0;\r
+\r
   Status = PeiServicesFfsFindSectionData (\r
              EFI_SECTION_COMPRESSION,\r
              FfsFileHeader,\r
@@ -760,10 +694,6 @@ Returns:
       // Was the DXE Core file encapsulated in a GUID'd section?\r
       //\r
       if (Section->Type == EFI_SECTION_GUID_DEFINED) {\r
-        //\r
-        // Locate the GUID'd Section Extractor\r
-        //\r
-        GuidedSectionHeader = (VOID *) (Section + 1);\r
 \r
         //\r
         // This following code constitutes the addition of the security model\r
@@ -851,8 +781,11 @@ Returns:
 \r
         switch (CompressionSection->CompressionType) {\r
         case EFI_STANDARD_COMPRESSION:\r
+          //\r
+          // Load EFI standard compression.\r
+          //\r
           if (FeaturePcdGet (PcdDxeIplSupportTianoDecompress)) {\r
-            DecompressLibrary = &gTianoDecompress;\r
+            DecompressLibrary = &gEfiDecompress;\r
           } else {\r
             ASSERT (FALSE);\r
             return EFI_NOT_FOUND;\r
@@ -861,7 +794,7 @@ Returns:
 \r
         case EFI_CUSTOMIZED_COMPRESSION:\r
           //\r
-          // Load user customized compression protocol.\r
+          // Load user customized compression.\r
           //\r
           if (FeaturePcdGet (PcdDxeIplSupportCustomDecompress)) {\r
             DecompressLibrary = &gCustomDecompress;\r
@@ -872,52 +805,79 @@ Returns:
           break;\r
 \r
         case EFI_NOT_COMPRESSED:\r
+          //\r
+          // Allocate destination buffer\r
+          //\r
+          DstBufferSize = CompressionSection->UncompressedLength;\r
+          DstBuffer     = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r
+          if (DstBuffer == NULL) {\r
+            return EFI_OUT_OF_RESOURCES;\r
+          }\r
+          //\r
+          // stream is not actually compressed, just encapsulated.  So just copy it.\r
+          //\r
+          CopyMem (DstBuffer, CompressionSection + 1, DstBufferSize);\r
+          break;\r
+\r
         default:\r
           //\r
-          // Need to support not compressed file\r
+          // Don't support other unknown compression type.\r
           //\r
           ASSERT_EFI_ERROR (Status);\r
           return EFI_NOT_FOUND;\r
         }\r
-\r
-        Status = DecompressLibrary->GetInfo (\r
-                   (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
-                   (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
-                   &DstBufferSize,\r
-                   &ScratchBufferSize\r
-                   );\r
-        if (EFI_ERROR (Status)) {\r
+        \r
+        if (CompressionSection->CompressionType != EFI_NOT_COMPRESSED) {\r
           //\r
-          // GetInfo failed\r
+          // For compressed data, decompress them to dstbuffer.\r
           //\r
-          return EFI_NOT_FOUND;\r
-        }\r
-\r
-        //\r
-        // Allocate scratch buffer\r
-        //\r
-        ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
-        if (ScratchBuffer == NULL) {\r
-          return EFI_OUT_OF_RESOURCES;\r
-        }\r
-\r
-        //\r
-        // Allocate destination buffer\r
-        //\r
-        DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r
-        if (DstBuffer == NULL) {\r
-          return EFI_OUT_OF_RESOURCES;\r
+          Status = DecompressLibrary->GetInfo (\r
+                     (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                     (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
+                     &DstBufferSize,\r
+                     &ScratchBufferSize\r
+                     );\r
+          if (EFI_ERROR (Status)) {\r
+            //\r
+            // GetInfo failed\r
+            //\r
+            DEBUG ((EFI_D_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r
+            return EFI_NOT_FOUND;\r
+          }\r
+  \r
+          //\r
+          // Allocate scratch buffer\r
+          //\r
+          ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r
+          if (ScratchBuffer == NULL) {\r
+            return EFI_OUT_OF_RESOURCES;\r
+          }\r
+  \r
+          //\r
+          // Allocate destination buffer\r
+          //\r
+          DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));\r
+          if (DstBuffer == NULL) {\r
+            return EFI_OUT_OF_RESOURCES;\r
+          }\r
+  \r
+          //\r
+          // Call decompress function\r
+          //\r
+          Status = DecompressLibrary->Decompress (\r
+                      (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                      DstBuffer,\r
+                      ScratchBuffer\r
+                      );\r
+          if (EFI_ERROR (Status)) {\r
+            //\r
+            // Decompress failed\r
+            //\r
+            DEBUG ((EFI_D_ERROR, "Decompress Failed - %r\n", Status));\r
+            return EFI_NOT_FOUND;\r
+          }\r
         }\r
-\r
-        //\r
-        // Call decompress function\r
-        //\r
-        Status = DecompressLibrary->Decompress (\r
-                    (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
-                    DstBuffer,\r
-                    ScratchBuffer\r
-                    );\r
-\r
+        \r
         CmpSection = (EFI_COMMON_SECTION_HEADER *) DstBuffer;\r
         if (CmpSection->Type == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {\r
           // \r
@@ -976,7 +936,6 @@ Returns:
             } else {\r
               return EFI_NOT_FOUND;\r
             }\r
-\r
           }\r
         }\r
         //\r