]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: Add new APIs
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / PeiDxeDebugLibReportStatusCode / DebugLib.c
index b0445115a9a683983d64c569f44c5976e0607ab7..3f3778d84a07d117e5714bc2a50dd14b8e56a16f 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 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2019, 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
 #include <Library/PcdLib.h>\r
 #include <Library/DebugPrintErrorLevelLib.h>\r
 \r
+//\r
+// VA_LIST can not initialize to NULL for all compiler, so we use this to\r
+// indicate a null VA_LIST\r
+//\r
+VA_LIST     mVaListNull;\r
+\r
 /**\r
   Prints a debug message to the debug output device if the specified error level is enabled.\r
 \r
@@ -52,13 +58,49 @@ DebugPrint (
   IN  CONST CHAR8  *Format,\r
   ...\r
   )\r
+{\r
+  VA_LIST         Marker;\r
+\r
+  VA_START (Marker, Format);\r
+  DebugVPrint (ErrorLevel, Format, Marker);\r
+  VA_END (Marker);\r
+}\r
+\r
+/**\r
+  Prints a debug message to the debug output device if the specified\r
+  error level is enabled base on Null-terminated format string and a\r
+  VA_LIST argument list or a BASE_LIST argument list.\r
+\r
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
+  GetDebugPrintErrorLevel (), then print the message specified by Format and\r
+  the associated variable argument list to the debug output device.\r
+\r
+  Only one list type is used.\r
+  If BaseListMarker == NULL, then use VaListMarker.\r
+  Otherwise use BaseListMarker and the VaListMarker should be initilized as\r
+  mVaListNull.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel      The error level of the debug message.\r
+  @param  Format          Format string for the debug message to print.\r
+  @param  VaListMarker    VA_LIST marker for the variable argument list.\r
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.\r
+\r
+**/\r
+VOID\r
+DebugPrintMarker (\r
+  IN  UINTN         ErrorLevel,\r
+  IN  CONST CHAR8   *Format,\r
+  IN  VA_LIST       VaListMarker,\r
+  IN  BASE_LIST     BaseListMarker\r
+  )\r
 {\r
   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
+  BASE_LIST       BaseListMarkerPointer;\r
   CHAR8           *FormatString;\r
   BOOLEAN         Long;\r
 \r
@@ -79,38 +121,38 @@ DebugPrint (
   // Note that the passing-in format string and variable parameters will be constructed to\r
   // the following layout:\r
   //\r
-  //         Buffer->|------------------------|\r
-  //                 |         Padding        | 4 bytes\r
-  //      DebugInfo->|------------------------|\r
-  //                 |      EFI_DEBUG_INFO    | sizeof(EFI_DEBUG_INFO)\r
-  // BaseListMarker->|------------------------|\r
-  //                 |           ...          |\r
-  //                 |   variable arguments   | 12 * sizeof (UINT64)\r
-  //                 |           ...          |\r
-  //                 |------------------------|\r
-  //                 |       Format String    |\r
-  //                 |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer)\r
+  //                Buffer->|------------------------|\r
+  //                        |         Padding        | 4 bytes\r
+  //             DebugInfo->|------------------------|\r
+  //                        |      EFI_DEBUG_INFO    | sizeof(EFI_DEBUG_INFO)\r
+  // BaseListMarkerPointer->|------------------------|\r
+  //                        |           ...          |\r
+  //                        |   variable arguments   | 12 * sizeof (UINT64)\r
+  //                        |           ...          |\r
+  //                        |------------------------|\r
+  //                        |       Format String    |\r
+  //                        |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer)\r
   //\r
   TotalSize = 4 + sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrSize (Format);\r
 \r
   //\r
-  // If the TotalSize is larger than the maximum record size, then return\r
+  // If the TotalSize is larger than the maximum record size, then truncate it.\r
   //\r
   if (TotalSize > sizeof (Buffer)) {\r
-    return;\r
+    TotalSize = sizeof (Buffer);\r
   }\r
 \r
   //\r
   // Fill in EFI_DEBUG_INFO\r
   //\r
-  // Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarker is\r
-  // 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarker will cause\r
+  // Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarkerPointer is\r
+  // 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarkerPointer will cause\r
   // exception on IPF. Buffer starts at 64-bit aligned address, so skipping 4 types (sizeof(EFI_DEBUG_INFO))\r
-  // just makes address of BaseListMarker, which follows DebugInfo, 64-bit aligned.\r
+  // just makes address of BaseListMarkerPointer, which follows DebugInfo, 64-bit aligned.\r
   //\r
   DebugInfo             = (EFI_DEBUG_INFO *)(Buffer) + 1;\r
   DebugInfo->ErrorLevel = (UINT32)ErrorLevel;\r
-  BaseListMarker        = (BASE_LIST)(DebugInfo + 1);\r
+  BaseListMarkerPointer = (BASE_LIST)(DebugInfo + 1);\r
   FormatString          = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);\r
 \r
   //\r
@@ -129,7 +171,6 @@ DebugPrint (
   // of format in DEBUG string, which is followed by the DEBUG format string.\r
   // Here we will process the variable arguments and pack them in this area.\r
   //\r
-  VA_START (VaListMarker, Format);\r
   for (; *Format != '\0'; Format++) {\r
     //\r
     // Only format with prefix % is processed.\r
@@ -166,7 +207,11 @@ DebugPrint (
         // '*' in format field means the precision of the field is specified by\r
         // a UINTN argument in the argument list.\r
         //\r
-        BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
+        if (BaseListMarker == NULL) {\r
+          BASE_ARG (BaseListMarkerPointer, UINTN) = VA_ARG (VaListMarker, UINTN);\r
+        } else {\r
+          BASE_ARG (BaseListMarkerPointer, UINTN) = BASE_ARG (BaseListMarker, UINTN);\r
+        }\r
         continue;\r
       }\r
       if (*Format == '\0') {\r
@@ -191,16 +236,36 @@ DebugPrint (
     }\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
+        if (BaseListMarker == NULL) {\r
+          BASE_ARG (BaseListMarkerPointer, INT64) = VA_ARG (VaListMarker, INT64);\r
+        } else {\r
+          BASE_ARG (BaseListMarkerPointer, INT64) = BASE_ARG (BaseListMarker, INT64);\r
+        }\r
       } else {\r
-        BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);\r
+        if (BaseListMarker == NULL) {\r
+          BASE_ARG (BaseListMarkerPointer, int) = VA_ARG (VaListMarker, int);\r
+        } else {\r
+          BASE_ARG (BaseListMarkerPointer, int) = BASE_ARG (BaseListMarker, int);\r
+        }\r
       }\r
     } else if (*Format == 's' || *Format == 'S' || *Format == 'a' || *Format == 'g' || *Format == 't') {\r
-      BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);\r
+      if (BaseListMarker == NULL) {\r
+        BASE_ARG (BaseListMarkerPointer, VOID *) = VA_ARG (VaListMarker, VOID *);\r
+      } else {\r
+        BASE_ARG (BaseListMarkerPointer, VOID *) = BASE_ARG (BaseListMarker, VOID *);\r
+      }\r
     } else if (*Format == 'c') {\r
-      BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
+      if (BaseListMarker == NULL) {\r
+        BASE_ARG (BaseListMarkerPointer, UINTN) = VA_ARG (VaListMarker, UINTN);\r
+      } else {\r
+        BASE_ARG (BaseListMarkerPointer, UINTN) = BASE_ARG (BaseListMarker, UINTN);\r
+      }\r
     } else if (*Format == 'r') {\r
-      BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r
+      if (BaseListMarker == NULL) {\r
+        BASE_ARG (BaseListMarkerPointer, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r
+      } else {\r
+        BASE_ARG (BaseListMarkerPointer, RETURN_STATUS) = BASE_ARG (BaseListMarker, RETURN_STATUS);\r
+      }\r
     }\r
 \r
     //\r
@@ -208,17 +273,15 @@ DebugPrint (
     // This indicates that the DEBUG() macro is passing in more argument than can be handled by\r
     // the EFI_DEBUG_INFO record\r
     //\r
-    ASSERT ((CHAR8 *)BaseListMarker <= FormatString);\r
+    ASSERT ((CHAR8 *)BaseListMarkerPointer <= FormatString);\r
 \r
     //\r
     // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return\r
     //\r
-    if ((CHAR8 *)BaseListMarker > FormatString) {\r
-      VA_END (VaListMarker);\r
+    if ((CHAR8 *)BaseListMarkerPointer > FormatString) {\r
       return;\r
     }\r
   }\r
-  VA_END (VaListMarker);\r
 \r
   //\r
   // Send the DebugInfo record\r
@@ -234,6 +297,60 @@ DebugPrint (
     );\r
 }\r
 \r
+/**\r
+  Prints a debug message to the debug output device if the specified\r
+  error level is enabled.\r
+\r
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
+  GetDebugPrintErrorLevel (), then print the message specified by Format and\r
+  the associated variable argument list to the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel    The error level of the debug message.\r
+  @param  Format        Format string for the debug message to print.\r
+  @param  VaListMarker  VA_LIST marker for the variable argument list.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugVPrint (\r
+  IN  UINTN         ErrorLevel,\r
+  IN  CONST CHAR8   *Format,\r
+  IN  VA_LIST       VaListMarker\r
+  )\r
+{\r
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);\r
+}\r
+\r
+/**\r
+  Prints a debug message to the debug output device if the specified\r
+  error level is enabled.\r
+  This function use BASE_LIST which would provide a more compatible\r
+  service than VA_LIST.\r
+\r
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
+  GetDebugPrintErrorLevel (), then print the message specified by Format and\r
+  the associated variable argument list to the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel      The error level of the debug message.\r
+  @param  Format          Format string for the debug message to print.\r
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugBPrint (\r
+  IN  UINTN         ErrorLevel,\r
+  IN  CONST CHAR8   *Format,\r
+  IN  BASE_LIST     BaseListMarker\r
+  )\r
+{\r
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);\r
+}\r
+\r
 /**\r
   Prints an assert message containing a filename, line number, and description.\r
   This may be followed by a breakpoint or a dead loop.\r