]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/Sec/SecMain.c
PI Enable:
[mirror_edk2.git] / Nt32Pkg / Sec / SecMain.c
index 3d2d4279e8c05d5be273fd666955c082291f9ce3..a1ab3f20ef818ba4625c1ecccfe8dc0f41ecc7b2 100644 (file)
@@ -33,7 +33,7 @@ Abstract:
 --*/\r
 \r
 #include "SecMain.h"\r
-#pragma warning(disable : 4996)\r
+\r
 \r
 //\r
 // Globals\r
@@ -420,80 +420,18 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-#define BYTES_PER_RECORD  512\r
-\r
-/**\r
-  Extracts ASSERT() information from a status code structure.\r
-\r
-  Converts the status code specified by CodeType, Value, and Data to the ASSERT()\r
-  arguments specified by Filename, Description, and LineNumber.  If CodeType is \r
-  an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and \r
-  Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract \r
-  Filename, Description, and LineNumber from the optional data area of the \r
-  status code buffer specified by Data.  The optional data area of Data contains \r
-  a Null-terminated ASCII string for the FileName, followed by a Null-terminated \r
-  ASCII string for the Description, followed by a 32-bit LineNumber.  If the \r
-  ASSERT() information could be extracted from Data, then return TRUE.  \r
-  Otherwise, FALSE is returned.  \r
-\r
-  If Data is NULL, then ASSERT().\r
-  If Filename is NULL, then ASSERT().\r
-  If Description is NULL, then ASSERT().\r
-  If LineNumber is NULL, then ASSERT().\r
-\r
-  @param  CodeType     The type of status code being converted.\r
-  @param  Value        The status code value being converted.\r
-  @param  Data         Pointer to status code data buffer. \r
-  @param  Filename     Pointer to the source file name that generated the ASSERT().\r
-  @param  Description  Pointer to the description of the ASSERT().\r
-  @param  LineNumber   Pointer to source line number that generated the ASSERT().\r
-\r
-  @retval  TRUE   The status code specified by CodeType, Value, and Data was \r
-                  converted ASSERT() arguments specified by Filename, Description, \r
-                  and LineNumber.\r
-  @retval  FALSE  The status code specified by CodeType, Value, and Data could \r
-                  not be converted to ASSERT() arguments.\r
 \r
-**/\r
-STATIC\r
-BOOLEAN\r
-ReportStatusCodeExtractAssertInfo (\r
-  IN EFI_STATUS_CODE_TYPE        CodeType,\r
-  IN EFI_STATUS_CODE_VALUE       Value,  \r
-  IN CONST EFI_STATUS_CODE_DATA  *Data, \r
-  OUT CHAR8                      **Filename,\r
-  OUT CHAR8                      **Description,\r
-  OUT UINT32                     *LineNumber\r
-  )\r
-{\r
-  EFI_DEBUG_ASSERT_DATA  *AssertData;\r
-\r
-  ASSERT (Data        != NULL);\r
-  ASSERT (Filename    != NULL);\r
-  ASSERT (Description != NULL);\r
-  ASSERT (LineNumber  != NULL);\r
-\r
-  if (((CodeType & EFI_STATUS_CODE_TYPE_MASK)      == EFI_ERROR_CODE) && \r
-      ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK)  == EFI_ERROR_UNRECOVERED) &&\r
-      ((Value    & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {\r
-    AssertData   = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r
-    *Filename    = (CHAR8 *)(AssertData + 1);\r
-    *Description = *Filename + AsciiStrLen (*Filename) + 1;\r
-    *LineNumber  = AssertData->LineNumber;\r
-    return TRUE;\r
-  }\r
-  return FALSE;\r
-}\r
+#define BYTES_PER_RECORD  512\r
 \r
 EFI_STATUS\r
 EFIAPI\r
 SecPeiReportStatusCode (\r
-  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN CONST EFI_PEI_SERVICES           **PeiServices,\r
   IN EFI_STATUS_CODE_TYPE       CodeType,\r
   IN EFI_STATUS_CODE_VALUE      Value,\r
   IN UINT32                     Instance,\r
-  IN EFI_GUID                   * CallerId,\r
-  IN EFI_STATUS_CODE_DATA       * Data OPTIONAL\r
+  IN CONST EFI_GUID                   *CallerId,\r
+  IN CONST EFI_STATUS_CODE_DATA       *Data OPTIONAL\r
   )\r
 /*++\r
 \r
@@ -520,52 +458,89 @@ Returns:
 // TODO:    Data - add argument and description to function comment\r
 {\r
   CHAR8           *Format;\r
-  EFI_DEBUG_INFO  *DebugInfo;\r
   VA_LIST         Marker;\r
   CHAR8           PrintBuffer[BYTES_PER_RECORD * 2];\r
   CHAR8           *Filename;\r
   CHAR8           *Description;\r
   UINT32          LineNumber;\r
+  UINT32          ErrorLevel;\r
 \r
-  if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
-    //\r
-    // This supports DEBUG () marcos\r
-    // Data format\r
-    //  EFI_STATUS_CODE_DATA\r
-    //  EFI_DEBUG_INFO\r
+\r
+  if (Data == NULL) {\r
+  } else if (ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
     //\r
-    // The first 12 * UINT64 bytes of the string are really an\r
-    // arguement stack to support varargs on the Format string.\r
+    // Processes ASSERT ()\r
     //\r
-    if (Data != NULL) {\r
-      DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
-      Marker    = (VA_LIST) (DebugInfo + 1);\r
-      Format    = (CHAR8 *) (((UINT64 *) Marker) + 12);\r
-\r
-      AsciiVSPrint (PrintBuffer, BYTES_PER_RECORD, Format, Marker);\r
-      printf (PrintBuffer);\r
-    } else {\r
-      printf ("DEBUG <null>\n");\r
-    }\r
-  }\r
+    printf ("ASSERT %s(%d): %s\n", Filename, LineNumber, Description);\r
 \r
-  if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) &&\r
-      ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED)\r
-      ) {\r
-    if (Data != NULL && ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
-      //\r
-      // Support ASSERT () macro\r
-      //\r
-      printf ("ASSERT %s(%d): %s\n", Filename, LineNumber, Description);\r
-    } else {\r
-      printf ("ASSERT <null>\n");\r
-    }\r
-    CpuBreakpoint ();\r
+  } else if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
+    //\r
+    // Process DEBUG () macro \r
+    //\r
+    AsciiVSPrint (PrintBuffer, BYTES_PER_RECORD, Format, Marker);\r
+    printf (PrintBuffer);\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Transfers control to a function starting with a new stack.\r
+\r
+  Transfers control to the function specified by EntryPoint using the new stack\r
+  specified by NewStack and passing in the parameters specified by Context1 and\r
+  Context2. Context1 and Context2 are optional and may be NULL. The function\r
+  EntryPoint must never return.\r
+\r
+  If EntryPoint is NULL, then ASSERT().\r
+  If NewStack is NULL, then ASSERT().\r
+\r
+  @param  EntryPoint  A pointer to function to call with the new stack.\r
+  @param  Context1    A pointer to the context to pass into the EntryPoint\r
+                      function.\r
+  @param  Context2    A pointer to the context to pass into the EntryPoint\r
+                      function.\r
+  @param  NewStack    A pointer to the new stack to use for the EntryPoint\r
+                      function.\r
+  @param  NewBsp      A pointer to the new BSP for the EntryPoint on IPF. It's\r
+                      Reserved on other architectures.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PeiSwitchStacks (\r
+  IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,\r
+  IN      VOID                      *Context1,  OPTIONAL\r
+  IN      VOID                      *Context2,  OPTIONAL\r
+  IN      VOID                      *Context3,  OPTIONAL\r
+  IN      VOID                      *NewStack\r
+  )\r
+{\r
+  BASE_LIBRARY_JUMP_BUFFER  JumpBuffer;\r
+  \r
+  ASSERT (EntryPoint != NULL);\r
+  ASSERT (NewStack != NULL);\r
+\r
+  //\r
+  // Stack should be aligned with CPU_STACK_ALIGNMENT\r
+  //\r
+  ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);\r
+\r
+  JumpBuffer.Eip = (UINTN)EntryPoint;\r
+  JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*);\r
+  JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2) + sizeof(Context3);\r
+  ((VOID**)JumpBuffer.Esp)[1] = Context1;\r
+  ((VOID**)JumpBuffer.Esp)[2] = Context2;\r
+  ((VOID**)JumpBuffer.Esp)[3] = Context3;\r
+\r
+  LongJump (&JumpBuffer, (UINTN)-1);\r
+  \r
+\r
+  //\r
+  // InternalSwitchStack () will never return\r
+  //\r
+  ASSERT (FALSE);  \r
+}\r
 \r
 VOID\r
 SecLoadFromCore (\r
@@ -596,7 +571,7 @@ Returns:
   UINT64                      PeiCoreSize;\r
   EFI_PHYSICAL_ADDRESS        PeiCoreEntryPoint;\r
   EFI_PHYSICAL_ADDRESS        PeiImageAddress;\r
-  EFI_PEI_STARTUP_DESCRIPTOR  *PeiStartup;\r
+  EFI_SEC_PEI_HAND_OFF        *SecCoreData;\r
 \r
   //\r
   // Compute Top Of Memory for Stack and PEI Core Allocations\r
@@ -606,7 +581,7 @@ Returns:
   //\r
   // Allocate 128KB for the Stack\r
   //\r
-  TopOfStack  = (VOID *)((UINTN)TopOfMemory - sizeof (EFI_PEI_STARTUP_DESCRIPTOR) - CPU_STACK_ALIGNMENT);\r
+  TopOfStack  = (VOID *)((UINTN)TopOfMemory - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);\r
   TopOfStack  = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
   TopOfMemory = TopOfMemory - STACK_SIZE;\r
 \r
@@ -618,10 +593,16 @@ Returns:
   //\r
   // Bind this information into the SEC hand-off state\r
   //\r
-  PeiStartup = (EFI_PEI_STARTUP_DESCRIPTOR *) (UINTN) TopOfStack;\r
-  PeiStartup->DispatchTable      = (EFI_PEI_PPI_DESCRIPTOR *) &gPrivateDispatchTable;\r
-  PeiStartup->SizeOfCacheAsRam   = STACK_SIZE;\r
-  PeiStartup->BootFirmwareVolume = BootFirmwareVolumeBase;\r
+  SecCoreData                        = (EFI_SEC_PEI_HAND_OFF*)(UINTN) TopOfStack;\r
+  SecCoreData->DataSize               = sizeof(EFI_SEC_PEI_HAND_OFF);\r
+  SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase;\r
+  SecCoreData->BootFirmwareVolumeSize = FixedPcdGet32(PcdWinNtFirmwareFdSize);\r
+  SecCoreData->TemporaryRamBase       = (VOID*)(UINTN)TopOfMemory; \r
+  SecCoreData->TemporaryRamSize       = STACK_SIZE;\r
+  SecCoreData->PeiTemporaryRamBase    = SecCoreData->TemporaryRamBase;\r
+  SecCoreData->PeiTemporaryRamSize    = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);\r
+  SecCoreData->StackBase              = (VOID*)((UINTN)SecCoreData->TemporaryRamBase + (UINTN)SecCoreData->TemporaryRamSize);\r
+  SecCoreData->StackSize              = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);\r
 \r
   //\r
   // Load the PEI Core from a Firmware Volume\r
@@ -635,12 +616,14 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     return ;\r
   }\r
+  \r
   //\r
   // Transfer control to the PEI Core\r
   //\r
-  SwitchStack (\r
+  PeiSwitchStacks (\r
     (SWITCH_STACK_ENTRY_POINT) (UINTN) PeiCoreEntryPoint,\r
-    PeiStartup,\r
+    SecCoreData,\r
+    (VOID *) (UINTN) ((EFI_PEI_PPI_DESCRIPTOR *) &gPrivateDispatchTable),\r
     NULL,\r
     TopOfStack\r
     );\r
@@ -1233,4 +1216,3 @@ _ModuleEntryPoint (
 {\r
 }\r
 \r
-#pragma warning(default : 4996)\r