]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Sec/SecMain.c
OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones
[mirror_edk2.git] / OvmfPkg / Sec / SecMain.c
index a12e6768ae26c28447a5c80e314e7c76fffa6b64..6dea6e771a29db4d388b55bbee0f473cc19960e6 100644 (file)
@@ -2,14 +2,9 @@
   Main SEC phase code.  Transitions to PEI.\r
 \r
   Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<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
@@ -56,7 +51,7 @@ TemporaryRamMigration (
 \r
 //\r
 //\r
-//  \r
+//\r
 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi = {\r
   TemporaryRamMigration\r
 };\r
@@ -79,7 +74,7 @@ IA32_IDT_GATE_DESCRIPTOR  mIdtEntryTemplate = {
     0x0,                                 // Reserved_0\r
     IA32_IDT_GATE_TYPE_INTERRUPT_32,     // GateType\r
     0xffff                               // OffsetHigh\r
-  }    \r
+  }\r
 };\r
 \r
 /**\r
@@ -261,7 +256,7 @@ FindFfsFileAndSection (
   EFI_PHYSICAL_ADDRESS        EndOfFile;\r
 \r
   if (Fv->Signature != EFI_FVH_SIGNATURE) {\r
-    DEBUG ((EFI_D_ERROR, "FV at %p does not have FV header signature\n", Fv));\r
+    DEBUG ((DEBUG_ERROR, "FV at %p does not have FV header signature\n", Fv));\r
     return EFI_VOLUME_CORRUPTED;\r
   }\r
 \r
@@ -279,7 +274,7 @@ FindFfsFileAndSection (
     }\r
 \r
     File = (EFI_FFS_FILE_HEADER*)(UINTN) CurrentAddress;\r
-    Size = *(UINT32*) File->Size & 0xffffff;\r
+    Size = FFS_FILE_SIZE (File);\r
     if (Size < (sizeof (*File) + sizeof (EFI_COMMON_SECTION_HEADER))) {\r
       return EFI_VOLUME_CORRUPTED;\r
     }\r
@@ -332,11 +327,13 @@ DecompressMemFvs (
   UINT32                            AuthenticationStatus;\r
   VOID                              *OutputBuffer;\r
   VOID                              *ScratchBuffer;\r
-  EFI_FIRMWARE_VOLUME_IMAGE_SECTION *FvSection;\r
+  EFI_COMMON_SECTION_HEADER         *FvSection;\r
   EFI_FIRMWARE_VOLUME_HEADER        *PeiMemFv;\r
   EFI_FIRMWARE_VOLUME_HEADER        *DxeMemFv;\r
+  UINT32                            FvHeaderSize;\r
+  UINT32                            FvSectionSize;\r
 \r
-  FvSection = (EFI_FIRMWARE_VOLUME_IMAGE_SECTION*) NULL;\r
+  FvSection = (EFI_COMMON_SECTION_HEADER*) NULL;\r
 \r
   Status = FindFfsFileAndSection (\r
              *Fv,\r
@@ -345,7 +342,7 @@ DecompressMemFvs (
              (EFI_COMMON_SECTION_HEADER**) &Section\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "Unable to find GUID defined section\n"));\r
+    DEBUG ((DEBUG_ERROR, "Unable to find GUID defined section\n"));\r
     return Status;\r
   }\r
 \r
@@ -356,14 +353,14 @@ DecompressMemFvs (
              &SectionAttribute\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "Unable to GetInfo for GUIDed section\n"));\r
+    DEBUG ((DEBUG_ERROR, "Unable to GetInfo for GUIDed section\n"));\r
     return Status;\r
   }\r
 \r
   OutputBuffer = (VOID*) ((UINT8*)(UINTN) PcdGet32 (PcdOvmfDxeMemFvBase) + SIZE_1MB);\r
   ScratchBuffer = ALIGN_POINTER ((UINT8*) OutputBuffer + OutputBufferSize, SIZE_1MB);\r
 \r
-  DEBUG ((EFI_D_VERBOSE, "%a: OutputBuffer@%p+0x%x ScratchBuffer@%p+0x%x "\r
+  DEBUG ((DEBUG_VERBOSE, "%a: OutputBuffer@%p+0x%x ScratchBuffer@%p+0x%x "\r
     "PcdOvmfDecompressionScratchEnd=0x%x\n", __FUNCTION__, OutputBuffer,\r
     OutputBufferSize, ScratchBuffer, ScratchBufferSize,\r
     PcdGet32 (PcdOvmfDecompressionScratchEnd)));\r
@@ -377,7 +374,7 @@ DecompressMemFvs (
              &AuthenticationStatus\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "Error during GUID section decode\n"));\r
+    DEBUG ((DEBUG_ERROR, "Error during GUID section decode\n"));\r
     return Status;\r
   }\r
 \r
@@ -386,10 +383,10 @@ DecompressMemFvs (
              OutputBufferSize,\r
              EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r
              0,\r
-             (EFI_COMMON_SECTION_HEADER**) &FvSection\r
+             &FvSection\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "Unable to find PEI FV section\n"));\r
+    DEBUG ((DEBUG_ERROR, "Unable to find PEI FV section\n"));\r
     return Status;\r
   }\r
 \r
@@ -401,7 +398,7 @@ DecompressMemFvs (
   CopyMem (PeiMemFv, (VOID*) (FvSection + 1), PcdGet32 (PcdOvmfPeiMemFvSize));\r
 \r
   if (PeiMemFv->Signature != EFI_FVH_SIGNATURE) {\r
-    DEBUG ((EFI_D_ERROR, "Extracted FV at %p does not have FV header signature\n", PeiMemFv));\r
+    DEBUG ((DEBUG_ERROR, "Extracted FV at %p does not have FV header signature\n", PeiMemFv));\r
     CpuDeadLoop ();\r
     return EFI_VOLUME_CORRUPTED;\r
   }\r
@@ -411,22 +408,30 @@ DecompressMemFvs (
              OutputBufferSize,\r
              EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r
              1,\r
-             (EFI_COMMON_SECTION_HEADER**) &FvSection\r
+             &FvSection\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "Unable to find DXE FV section\n"));\r
+    DEBUG ((DEBUG_ERROR, "Unable to find DXE FV section\n"));\r
     return Status;\r
   }\r
 \r
   ASSERT (FvSection->Type == EFI_SECTION_FIRMWARE_VOLUME_IMAGE);\r
-  ASSERT (SECTION_SIZE (FvSection) ==\r
-          (PcdGet32 (PcdOvmfDxeMemFvSize) + sizeof (*FvSection)));\r
+\r
+  if (IS_SECTION2 (FvSection)) {\r
+    FvSectionSize = SECTION2_SIZE (FvSection);\r
+    FvHeaderSize = sizeof (EFI_COMMON_SECTION_HEADER2);\r
+  } else {\r
+    FvSectionSize = SECTION_SIZE (FvSection);\r
+    FvHeaderSize = sizeof (EFI_COMMON_SECTION_HEADER);\r
+  }\r
+\r
+  ASSERT (FvSectionSize == (PcdGet32 (PcdOvmfDxeMemFvSize) + FvHeaderSize));\r
 \r
   DxeMemFv = (EFI_FIRMWARE_VOLUME_HEADER*)(UINTN) PcdGet32 (PcdOvmfDxeMemFvBase);\r
-  CopyMem (DxeMemFv, (VOID*) (FvSection + 1), PcdGet32 (PcdOvmfDxeMemFvSize));\r
+  CopyMem (DxeMemFv, (VOID*) ((UINTN)FvSection + FvHeaderSize), PcdGet32 (PcdOvmfDxeMemFvSize));\r
 \r
   if (DxeMemFv->Signature != EFI_FVH_SIGNATURE) {\r
-    DEBUG ((EFI_D_ERROR, "Extracted FV at %p does not have FV header signature\n", DxeMemFv));\r
+    DEBUG ((DEBUG_ERROR, "Extracted FV at %p does not have FV header signature\n", DxeMemFv));\r
     CpuDeadLoop ();\r
     return EFI_VOLUME_CORRUPTED;\r
   }\r
@@ -469,7 +474,7 @@ FindPeiCoreImageBaseInFv (
                &Section\r
                );\r
     if (EFI_ERROR (Status)) {\r
-      DEBUG ((EFI_D_ERROR, "Unable to find PEI Core image\n"));\r
+      DEBUG ((DEBUG_ERROR, "Unable to find PEI Core image\n"));\r
       return Status;\r
     }\r
   }\r
@@ -549,14 +554,14 @@ FindPeiCoreImageBase (
     // A malicious runtime OS may have injected something into our previously\r
     // decoded PEI FV, but we don't care about that unless SMM/SMRAM is required.\r
     //\r
-    DEBUG ((EFI_D_VERBOSE, "SEC: S3 resume\n"));\r
+    DEBUG ((DEBUG_VERBOSE, "SEC: S3 resume\n"));\r
     GetS3ResumePeiFv (BootFv);\r
   } else {\r
     //\r
     // We're either not resuming, or resuming "securely" -- we'll decompress\r
     // both PEI FV and DXE FV from pristine flash.\r
     //\r
-    DEBUG ((EFI_D_VERBOSE, "SEC: %a\n",\r
+    DEBUG ((DEBUG_VERBOSE, "SEC: %a\n",\r
       S3Resume ? "S3 resume (with PEI decompression)" : "Normal boot"));\r
     FindMainFv (BootFv);\r
 \r
@@ -600,7 +605,7 @@ FindImageBase (
     }\r
 \r
     File = (EFI_FFS_FILE_HEADER*)(UINTN) CurrentAddress;\r
-    Size = *(UINT32*) File->Size & 0xffffff;\r
+    Size = FFS_FILE_SIZE (File);\r
     if (Size < sizeof (*File)) {\r
       return EFI_NOT_FOUND;\r
     }\r
@@ -625,7 +630,7 @@ FindImageBase (
       CurrentAddress = (EndOfSection + 3) & 0xfffffffffffffffcULL;\r
       Section = (EFI_COMMON_SECTION_HEADER*)(UINTN) CurrentAddress;\r
 \r
-      Size = *(UINT32*) Section->Size & 0xffffff;\r
+      Size = SECTION_SIZE (Section);\r
       if (Size < sizeof (*Section)) {\r
         return EFI_NOT_FOUND;\r
       }\r
@@ -658,7 +663,7 @@ FindImageBase (
 /*\r
   Find and return Pei Core entry point.\r
 \r
-  It also find SEC and PEI Core file debug inforamtion. It will report them if\r
+  It also find SEC and PEI Core file debug information. It will report them if\r
   remote debug is enabled.\r
 \r
 **/\r
@@ -680,7 +685,7 @@ FindAndReportEntryPoints (
   ASSERT_EFI_ERROR (Status);\r
 \r
   FindPeiCoreImageBase (BootFirmwareVolumePtr, &PeiCoreImageBase);\r
-  \r
+\r
   ZeroMem ((VOID *) &ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT));\r
   //\r
   // Report SEC Core debug information when remote debug is enabled\r
@@ -734,7 +739,7 @@ SecCoreStartupWithStack (
 \r
   ProcessLibraryConstructorList (NULL, NULL);\r
 \r
-  DEBUG ((EFI_D_INFO,\r
+  DEBUG ((DEBUG_INFO,\r
     "SecCoreStartupWithStack(0x%x, 0x%x)\n",\r
     (UINT32)(UINTN)BootFv,\r
     (UINT32)(UINTN)TopOfCurrentStack\r
@@ -748,7 +753,7 @@ SecCoreStartupWithStack (
 \r
   //\r
   // Initialize IDT\r
-  //  \r
+  //\r
   IdtTableInStack.PeiService = NULL;\r
   for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) {\r
     CopyMem (&IdtTableInStack.IdtTable[Index], &mIdtEntryTemplate, sizeof (mIdtEntryTemplate));\r
@@ -809,13 +814,13 @@ SecCoreStartupWithStack (
   //\r
   InitializeApicTimer (0, MAX_UINT32, TRUE, 5);\r
   DisableApicTimerInterrupt ();\r
-  \r
+\r
   //\r
   // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.\r
   //\r
   InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, &SecCoreData, SecStartupPhase2);\r
 }\r
-  \r
+\r
 /**\r
   Caller provided function to be invoked at the end of InitializeDebugAgent().\r
 \r
@@ -835,9 +840,9 @@ SecStartupPhase2(
   EFI_SEC_PEI_HAND_OFF        *SecCoreData;\r
   EFI_FIRMWARE_VOLUME_HEADER  *BootFv;\r
   EFI_PEI_CORE_ENTRY_POINT    PeiCoreEntryPoint;\r
-  \r
+\r
   SecCoreData = (EFI_SEC_PEI_HAND_OFF *) Context;\r
-  \r
+\r
   //\r
   // Find PEI Core entry point. It will report SEC and Pei Core debug information if remote debug\r
   // is enabled.\r
@@ -851,7 +856,7 @@ SecStartupPhase2(
   // Transfer the control to the PEI core\r
   //\r
   (*PeiCoreEntryPoint) (SecCoreData, (EFI_PEI_PPI_DESCRIPTOR *)&mPrivateDispatchTable);\r
-  \r
+\r
   //\r
   // If we get here then the PEI Core returned, which is not recoverable.\r
   //\r
@@ -876,23 +881,23 @@ TemporaryRamMigration (
   DEBUG_AGENT_CONTEXT_POSTMEM_SEC  DebugAgentContext;\r
   BOOLEAN                          OldStatus;\r
   BASE_LIBRARY_JUMP_BUFFER         JumpBuffer;\r
-  \r
-  DEBUG ((EFI_D_INFO,\r
+\r
+  DEBUG ((DEBUG_INFO,\r
     "TemporaryRamMigration(0x%Lx, 0x%Lx, 0x%Lx)\n",\r
     TemporaryMemoryBase,\r
     PermanentMemoryBase,\r
     (UINT64)CopySize\r
     ));\r
-  \r
+\r
   OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;\r
   NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1));\r
-  \r
+\r
   OldStack = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1));\r
   NewStack = (VOID*)(UINTN)PermanentMemoryBase;\r
 \r
   DebugAgentContext.HeapMigrateOffset = (UINTN)NewHeap - (UINTN)OldHeap;\r
   DebugAgentContext.StackMigrateOffset = (UINTN)NewStack - (UINTN)OldStack;\r
-  \r
+\r
   OldStatus = SaveAndSetDebugTimerInterrupt (FALSE);\r
   InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, (VOID *) &DebugAgentContext, NULL);\r
 \r
@@ -905,7 +910,7 @@ TemporaryRamMigration (
   // Migrate Stack\r
   //\r
   CopyMem (NewStack, OldStack, CopySize >> 1);\r
-  \r
+\r
   //\r
   // Rebase IDT table in permanent memory\r
   //\r
@@ -916,14 +921,16 @@ TemporaryRamMigration (
 \r
   //\r
   // Use SetJump()/LongJump() to switch to a new stack.\r
-  // \r
+  //\r
   if (SetJump (&JumpBuffer) == 0) {\r
 #if defined (MDE_CPU_IA32)\r
     JumpBuffer.Esp = JumpBuffer.Esp + DebugAgentContext.StackMigrateOffset;\r
-#endif    \r
+    JumpBuffer.Ebp = JumpBuffer.Ebp + DebugAgentContext.StackMigrateOffset;\r
+#endif\r
 #if defined (MDE_CPU_X64)\r
     JumpBuffer.Rsp = JumpBuffer.Rsp + DebugAgentContext.StackMigrateOffset;\r
-#endif    \r
+    JumpBuffer.Rbp = JumpBuffer.Rbp + DebugAgentContext.StackMigrateOffset;\r
+#endif\r
     LongJump (&JumpBuffer, (UINTN)-1);\r
   }\r
 \r