]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLib.c
MdePkg/UefiDebuglibDebugPortProtocol: Add new APIs
[mirror_edk2.git] / MdePkg / Library / UefiDebugLibDebugPortProtocol / DebugLib.c
index c2209f412336bd18e6fe9f8ed2e08c60098378a2..b1ad2af20ab7de8fecc6471adc77e4a44f5ff5d4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   UEFI Debug Library that sends messages to EFI_DEBUGPORT_PROTOCOL.Write.\r
 \r
-  Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 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
 \r
 EFI_DEBUGPORT_PROTOCOL *mDebugPort = NULL;\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
   Send message to DebugPort Protocol.\r
 \r
@@ -106,9 +112,41 @@ 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
+/**\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
+  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
   CHAR8      Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
-  VA_LIST    Marker;\r
 \r
   //\r
   // If Format is NULL, then ASSERT().\r
@@ -125,9 +163,11 @@ DebugPrint (
   //\r
   // Convert the DEBUG() message to an ASCII String\r
   //\r
-  VA_START (Marker, Format);\r
-  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
-  VA_END (Marker);\r
+  if (BaseListMarker == NULL) {\r
+    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);\r
+  } else {\r
+    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);\r
+  }\r
 \r
   //\r
   // Send the print string to EFI_DEBUGPORT_PROTOCOL.Write.\r
@@ -136,6 +176,62 @@ 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
+/**\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
 /**\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