]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkNt32Pkg/Sec/SecMain.c
Updated conversion command line option with unicode support
[mirror_edk2.git] / EdkNt32Pkg / Sec / SecMain.c
index 2c3d08e06280030c510ff2ad0455124e73665eb1..4f668b1bc8553ba3d7bd11cb11e8156006247546 100644 (file)
@@ -33,6 +33,7 @@ Abstract:
 --*/\r
 \r
 #include "SecMain.h"\r
+#pragma warning(disable : 4996)\r
 \r
 //\r
 // Globals\r
@@ -159,8 +160,8 @@ Returns:
   CHAR16                *MemorySizeStr;\r
   CHAR16                *FirmwareVolumesStr;\r
 \r
-  MemorySizeStr      = (CHAR16 *)FixedPcdGetPtr (PcdWinNtMemorySize);\r
-  FirmwareVolumesStr = (CHAR16 *)FixedPcdGetPtr (PcdWinNtFirmwareVolume);\r
+  MemorySizeStr      = (CHAR16 *)PcdGetPtr (PcdWinNtMemorySizeForSecMain);\r
+  FirmwareVolumesStr = (CHAR16 *)PcdGetPtr (PcdWinNtFirmwareVolume);\r
 \r
   printf ("\nEDK SEC Main NT Emulation Environment from www.TianoCore.org\n");\r
 \r
@@ -421,6 +422,69 @@ Returns:
 \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
+\r
 EFI_STATUS\r
 EFIAPI\r
 SecPeiReportStatusCode (\r
@@ -473,24 +537,30 @@ Returns:
     // The first 12 * UINT64 bytes of the string are really an\r
     // arguement stack to support varargs on the Format string.\r
     //\r
-    DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
-    Marker    = (VA_LIST) (DebugInfo + 1);\r
-    Format    = (CHAR8 *) (((UINT64 *) Marker) + 12);\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
+      AsciiVSPrint (PrintBuffer, BYTES_PER_RECORD, Format, Marker);\r
+      printf (PrintBuffer);\r
+    } else {\r
+      printf ("DEBUG <null>\n");\r
+    }\r
   }\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 (ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\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
-      CpuBreakpoint ();\r
+    } else {\r
+      printf ("ASSERT <null>\n");\r
     }\r
+    CpuBreakpoint ();\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -531,12 +601,13 @@ Returns:
   //\r
   // Compute Top Of Memory for Stack and PEI Core Allocations\r
   //\r
-  TopOfMemory = LargestRegion + ((LargestRegionSize) & (~15));\r
+  TopOfMemory = LargestRegion + LargestRegionSize;\r
 \r
   //\r
   // Allocate 128KB for the Stack\r
   //\r
-  TopOfStack  = (VOID *) (UINTN) (TopOfMemory - sizeof (EFI_PEI_STARTUP_DESCRIPTOR));\r
+  TopOfStack  = (VOID *)((UINTN)TopOfMemory - sizeof (EFI_PEI_STARTUP_DESCRIPTOR) - CPU_STACK_ALIGNMENT);\r
+  TopOfStack  = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
   TopOfMemory = TopOfMemory - STACK_SIZE;\r
 \r
   //\r
@@ -1161,3 +1232,5 @@ _ModuleEntryPoint (
   )\r
 {\r
 }\r
+\r
+#pragma warning(default : 4996)\r