]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
IntelFrameworkModulePkg: DebugAssert enhancement
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / PeiDxeDebugLibReportStatusCode / DebugLib.c
index 0d794dfca868b431d2f0f3e8a3f11ba854f7e566..7b07916bbdc955dc230f725debee7cd17abcf197 100644 (file)
@@ -4,7 +4,7 @@
   Note that if the debug message length is larger than the maximum allowable\r
   record length, then the debug message will be ignored directly.\r
 \r
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\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
@@ -15,7 +15,7 @@
 \r
 **/\r
 \r
-#include <FrameworkPei.h>\r
+#include <PiPei.h>\r
 \r
 #include <Guid/StatusCodeDataTypeId.h>\r
 #include <Guid/StatusCodeDataTypeDebug.h>\r
@@ -56,6 +56,7 @@ DebugPrint (
   UINT64          Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1];\r
   EFI_DEBUG_INFO  *DebugInfo;\r
   UINTN           TotalSize;\r
+  UINTN           DestBufferSize;\r
   VA_LIST         VaListMarker;\r
   BASE_LIST       BaseListMarker;\r
   CHAR8           *FormatString;\r
@@ -115,7 +116,13 @@ DebugPrint (
   //\r
   // Copy the Format string into the record\r
   //\r
-  AsciiStrCpy (FormatString, Format);\r
+  // According to the content structure of Buffer shown above, the size of\r
+  // the FormatString buffer is the size of Buffer minus the Padding\r
+  // (4 bytes), minus the size of EFI_DEBUG_INFO, minus the size of\r
+  // variable arguments (12 * sizeof (UINT64)).\r
+  //\r
+  DestBufferSize = sizeof (Buffer) - 4 - sizeof (EFI_DEBUG_INFO) - 12 * sizeof (UINT64);\r
+  AsciiStrCpyS (FormatString, DestBufferSize / sizeof (CHAR8), Format);\r
 \r
   //\r
   // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r
@@ -182,7 +189,7 @@ DebugPrint (
     if ((*Format == 'p') && (sizeof (VOID *) > 4)) {\r
       Long = TRUE;\r
     }\r
-    if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd') {\r
+    if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd' || *Format == 'u') {\r
       if (Long) {\r
         BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);\r
       } else {\r
@@ -261,6 +268,7 @@ DebugAssert (
   UINTN                  HeaderSize;\r
   UINTN                  TotalSize;\r
   CHAR8                  *Temp;\r
+  UINTN                  ModuleNameSize;\r
   UINTN                  FileNameSize;\r
   UINTN                  DescriptionSize;\r
 \r
@@ -268,31 +276,40 @@ DebugAssert (
   // Get string size\r
   //\r
   HeaderSize       = sizeof (EFI_DEBUG_ASSERT_DATA);\r
+  //\r
+  // Compute string size of module name enclosed by []\r
+  //\r
+  ModuleNameSize   = 2 + AsciiStrSize (gEfiCallerBaseName);\r
   FileNameSize     = AsciiStrSize (FileName);\r
   DescriptionSize  = AsciiStrSize (Description);\r
 \r
   //\r
   // Make sure it will all fit in the passed in buffer.\r
   //\r
-  if (HeaderSize + FileNameSize + DescriptionSize > sizeof (Buffer)) {\r
+  if (HeaderSize + ModuleNameSize + FileNameSize + DescriptionSize > sizeof (Buffer)) {\r
     //\r
-    // FileName + Description is too long to be filled into buffer. \r
+    // remove module name if it's too long to be filled into buffer\r
     //\r
-    if (HeaderSize + FileNameSize < sizeof (Buffer)) {\r
-      //\r
-      // Description has enough buffer to be truncated. \r
+    ModuleNameSize = 0;\r
+    if (HeaderSize + FileNameSize + DescriptionSize > sizeof (Buffer)) {\r
       //\r
-      DescriptionSize = sizeof (Buffer) - HeaderSize - FileNameSize;\r
-    } else {\r
+      // FileName + Description is too long to be filled into buffer.\r
       //\r
-      // FileName is too long to be filled into buffer.\r
-      // FileName will be truncated. Reserved one byte for Description NULL terminator.\r
-      //\r
-      DescriptionSize = 1;\r
-      FileNameSize    = sizeof (Buffer) - HeaderSize - DescriptionSize;\r
+      if (HeaderSize + FileNameSize < sizeof (Buffer)) {\r
+        //\r
+        // Description has enough buffer to be truncated.\r
+        //\r
+        DescriptionSize = sizeof (Buffer) - HeaderSize - FileNameSize;\r
+      } else {\r
+        //\r
+        // FileName is too long to be filled into buffer.\r
+        // FileName will be truncated. Reserved one byte for Description NULL terminator.\r
+        //\r
+        DescriptionSize = 1;\r
+        FileNameSize    = sizeof (Buffer) - HeaderSize - DescriptionSize;\r
+      }\r
     }\r
   }\r
\r
   //\r
   // Fill in EFI_DEBUG_ASSERT_DATA\r
   //\r
@@ -300,17 +317,28 @@ DebugAssert (
   AssertData->LineNumber = (UINT32)LineNumber;\r
   TotalSize  = sizeof (EFI_DEBUG_ASSERT_DATA);\r
 \r
+  Temp = (CHAR8 *)(AssertData + 1);\r
+\r
+  //\r
+  // Copy Ascii [ModuleName].\r
+  //\r
+  if (ModuleNameSize != 0) {\r
+    CopyMem(Temp, "[", 1);\r
+    CopyMem(Temp + 1, gEfiCallerBaseName, ModuleNameSize - 3);\r
+    CopyMem(Temp + ModuleNameSize - 2, "] ", 2);\r
+  }\r
+\r
   //\r
   // Copy Ascii FileName including NULL terminator.\r
   //\r
-  Temp = AsciiStrnCpy ((CHAR8 *)(AssertData + 1), FileName, FileNameSize);\r
+  Temp = CopyMem (Temp + ModuleNameSize, FileName, FileNameSize);\r
   Temp[FileNameSize - 1] = 0;\r
-  TotalSize += FileNameSize;\r
+  TotalSize += (ModuleNameSize + FileNameSize);\r
 \r
   //\r
   // Copy Ascii Description include NULL terminator.\r
   //\r
-  Temp = AsciiStrnCpy (Temp + FileNameSize, Description, DescriptionSize);\r
+  Temp = CopyMem (Temp + FileNameSize, Description, DescriptionSize);\r
   Temp[DescriptionSize - 1] = 0;\r
   TotalSize += DescriptionSize;\r
 \r
@@ -441,3 +469,21 @@ DebugClearMemoryEnabled (
 {\r
   return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
 }\r
+\r
+/**\r
+  Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.\r
+\r
+  This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.\r
+\r
+  @retval  TRUE    Current ErrorLevel is supported.\r
+  @retval  FALSE   Current ErrorLevel is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+DebugPrintLevelEnabled (\r
+  IN  CONST UINTN        ErrorLevel\r
+  )\r
+{\r
+  return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);\r
+}\r