]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / OvmfPkg / Library / PlatformDebugLibIoPort / DebugLib.c
index 36cde54976d8a78816044cc32c9c732ef180bc18..6895458cf09f6003da437ecec9e562e462238b91 100644 (file)
@@ -1,16 +1,10 @@
 /** @file\r
-  Base Debug library instance for QEMU debug port.\r
+  Base Debug library instance for hypervisor debug port.\r
   It uses PrintLib to send debug messages to a fixed I/O port.\r
 \r
-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2012, Red Hat, Inc.<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
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 //\r
 // Define the maximum debug and assert message length that this library supports\r
 //\r
-#define MAX_DEBUG_MESSAGE_LENGTH  0x100\r
+#define MAX_DEBUG_MESSAGE_LENGTH  0x200\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
@@ -52,9 +52,40 @@ DebugPrint (
   ...\r
   )\r
 {\r
-  CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
   VA_LIST  Marker;\r
-  UINTN    Length;\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
+  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
+  UINTN  Length;\r
 \r
   //\r
   // If Format is NULL, then ASSERT().\r
@@ -64,17 +95,20 @@ DebugPrint (
   //\r
   // Check if the global mask disables this message or the device is inactive\r
   //\r
-  if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0 ||\r
-      !PlatformDebugLibIoPortFound ()) {\r
+  if (((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) ||\r
+      !PlatformDebugLibIoPortFound ())\r
+  {\r
     return;\r
   }\r
 \r
   //\r
   // Convert the DEBUG() message to an ASCII String\r
   //\r
-  VA_START (Marker, Format);\r
-  Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
-  VA_END (Marker);\r
+  if (BaseListMarker == NULL) {\r
+    Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);\r
+  } else {\r
+    Length = AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);\r
+  }\r
 \r
   //\r
   // Send the print string to the debug I/O port\r
@@ -82,6 +116,59 @@ DebugPrint (
   IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\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
@@ -118,8 +205,14 @@ DebugAssert (
   //\r
   // Generate the ASSERT() message in Ascii format\r
   //\r
-  Length = AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n",\r
-             FileName, (UINT64)LineNumber, Description);\r
+  Length = AsciiSPrint (\r
+             Buffer,\r
+             sizeof Buffer,\r
+             "ASSERT %a(%Lu): %a\n",\r
+             FileName,\r
+             (UINT64)LineNumber,\r
+             Description\r
+             );\r
 \r
   //\r
   // Send the print string to the debug I/O port, if present\r
@@ -131,14 +224,13 @@ DebugAssert (
   //\r
   // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
   //\r
-  if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
+  if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
     CpuBreakpoint ();\r
-  } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
+  } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
     CpuDeadLoop ();\r
   }\r
 }\r
 \r
-\r
 /**\r
   Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
 \r
@@ -167,12 +259,11 @@ DebugClearMemory (
   ASSERT (Buffer != NULL);\r
 \r
   //\r
-  // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
+  // SetMem() checks for the ASSERT() condition on Length and returns Buffer\r
   //\r
-  return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
+  return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));\r
 }\r
 \r
-\r
 /**\r
   Returns TRUE if ASSERT() macros are enabled.\r
 \r
@@ -189,10 +280,9 @@ DebugAssertEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
 }\r
 \r
-\r
 /**\r
   Returns TRUE if DEBUG() macros are enabled.\r
 \r
@@ -209,10 +299,9 @@ DebugPrintEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
 }\r
 \r
-\r
 /**\r
   Returns TRUE if DEBUG_CODE() macros are enabled.\r
 \r
@@ -229,10 +318,9 @@ DebugCodeEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
 }\r
 \r
-\r
 /**\r
   Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
 \r
@@ -249,7 +337,7 @@ DebugClearMemoryEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
 }\r
 \r
 /**\r
@@ -264,24 +352,8 @@ DebugClearMemoryEnabled (
 BOOLEAN\r
 EFIAPI\r
 DebugPrintLevelEnabled (\r
-  IN  CONST UINTN        ErrorLevel\r
-  )\r
-{\r
-  return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);\r
-}\r
-\r
-/**\r
-  Return the result of detecting the debug I/O port device.\r
-\r
-  @retval TRUE   if the debug I/O port device was detected.\r
-  @retval FALSE  otherwise\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-PlatformDebugLibIoPortDetect (\r
-  VOID\r
+  IN  CONST UINTN  ErrorLevel\r
   )\r
 {\r
-  return IoRead8 (PcdGet16 (PcdDebugIoPort)) == BOCHS_DEBUG_PORT_MAGIC;\r
+  return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != 0);\r
 }\r