]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLib.c
MdePkg/UefiDebugLibDebugPortProtocol: Make it runtime safe
[mirror_edk2.git] / MdePkg / Library / UefiDebugLibDebugPortProtocol / DebugLib.c
index 24bfb4f37e8e587b227d25cb96821ff8276eddc8..cd7e2abbd3b22c198973cf819fb004b6f944ead7 100644 (file)
@@ -9,7 +9,6 @@
 #include <Uefi.h>\r
 \r
 #include <Library/DebugLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/PrintLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/BaseLib.h>\r
@@ -37,6 +36,9 @@ EFI_DEBUGPORT_PROTOCOL *mDebugPort = NULL;
 //\r
 VA_LIST     mVaListNull;\r
 \r
+extern BOOLEAN                mPostEBS;\r
+extern EFI_BOOT_SERVICES     *mDebugBS;\r
+\r
 /**\r
   Send message to DebugPort Protocol.\r
 \r
@@ -56,31 +58,33 @@ UefiDebugLibDebugPortProtocolWrite (
   UINTN      Length;\r
   EFI_STATUS Status;\r
 \r
-  //\r
-  // If mDebugPort is NULL, initialize first.\r
-  //\r
-  if (mDebugPort == NULL) {\r
-      Status = gBS->LocateProtocol (&gEfiDebugPortProtocolGuid, NULL, (VOID **)&mDebugPort);\r
-      if (EFI_ERROR (Status)) {\r
-          return;\r
-      }\r
+  if (!mPostEBS) {\r
+    //\r
+    // If mDebugPort is NULL, initialize first.\r
+    //\r
+    if (mDebugPort == NULL) {\r
+        Status = mDebugBS->LocateProtocol (&gEfiDebugPortProtocolGuid, NULL, (VOID **)&mDebugPort);\r
+        if (EFI_ERROR (Status)) {\r
+            return;\r
+        }\r
+\r
+        mDebugPort->Reset (mDebugPort);\r
+    }\r
 \r
-      mDebugPort->Reset (mDebugPort);\r
-  }\r
+    //\r
+    // EFI_DEBUGPORT_PROTOCOL.Write is called until all message is sent.\r
+    //\r
+    while (BufferLength > 0) {\r
+      Length = BufferLength;\r
 \r
-  //\r
-  // EFI_DEBUGPORT_PROTOCOL.Write is called until all message is sent.\r
-  //\r
-  while (BufferLength > 0) {\r
-    Length = BufferLength;\r
+      Status = mDebugPort->Write (mDebugPort, WRITE_TIMEOUT, &Length, (VOID *) Buffer);\r
+      if (EFI_ERROR (Status) || BufferLength < Length) {\r
+        break;\r
+      }\r
 \r
-    Status = mDebugPort->Write (mDebugPort, WRITE_TIMEOUT, &Length, (VOID *) Buffer);\r
-    if (EFI_ERROR (Status) || BufferLength < Length) {\r
-      break;\r
+      Buffer += Length;\r
+      BufferLength -= Length;\r
     }\r
-\r
-    Buffer += Length;\r
-    BufferLength -= Length;\r
   }\r
 }\r
 \r
@@ -142,31 +146,33 @@ DebugPrintMarker (
 {\r
   CHAR8      Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
 \r
-  //\r
-  // If Format is NULL, then ASSERT().\r
-  //\r
-  ASSERT (Format != NULL);\r
+  if (!mPostEBS) {\r
+    //\r
+    // If Format is NULL, then ASSERT().\r
+    //\r
+    ASSERT (Format != NULL);\r
+\r
+    //\r
+    // Check driver debug mask value and global mask\r
+    //\r
+    if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {\r
+      return;\r
+    }\r
 \r
-  //\r
-  // Check driver debug mask value and global mask\r
-  //\r
-  if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {\r
-    return;\r
-  }\r
+    //\r
+    // Convert the DEBUG() message to an ASCII String\r
+    //\r
+    if (BaseListMarker == NULL) {\r
+      AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);\r
+    } else {\r
+      AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);\r
+    }\r
 \r
-  //\r
-  // Convert the DEBUG() message to an ASCII String\r
-  //\r
-  if (BaseListMarker == NULL) {\r
-    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);\r
-  } else {\r
-    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);\r
+    //\r
+    // Send the print string to EFI_DEBUGPORT_PROTOCOL.Write.\r
+    //\r
+    UefiDebugLibDebugPortProtocolWrite (Buffer, AsciiStrLen (Buffer));\r
   }\r
-\r
-  //\r
-  // Send the print string to EFI_DEBUGPORT_PROTOCOL.Write.\r
-  //\r
-  UefiDebugLibDebugPortProtocolWrite (Buffer, AsciiStrLen (Buffer));\r
 }\r
 \r
 \r
@@ -259,31 +265,33 @@ DebugAssert (
 {\r
   CHAR8  Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
 \r
-  //\r
-  // Generate the ASSERT() message in ASCII format\r
-  //\r
-  AsciiSPrint (\r
-    Buffer,\r
-    sizeof (Buffer),\r
-    "ASSERT [%a] %a(%d): %a\n",\r
-    gEfiCallerBaseName,\r
-    FileName,\r
-    LineNumber,\r
-    Description\r
-    );\r
-\r
-  //\r
-  // Send the print string to EFI_DEBUGPORT_PROTOCOL.Write.\r
-  //\r
-  UefiDebugLibDebugPortProtocolWrite (Buffer, AsciiStrLen (Buffer));\r
-\r
-  //\r
-  // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
-  //\r
-  if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
-    CpuBreakpoint ();\r
-  } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
-    CpuDeadLoop ();\r
+  if (!mPostEBS) {\r
+    //\r
+    // Generate the ASSERT() message in ASCII format\r
+    //\r
+    AsciiSPrint (\r
+      Buffer,\r
+      sizeof (Buffer),\r
+      "ASSERT [%a] %a(%d): %a\n",\r
+      gEfiCallerBaseName,\r
+      FileName,\r
+      LineNumber,\r
+      Description\r
+      );\r
+\r
+    //\r
+    // Send the print string to EFI_DEBUGPORT_PROTOCOL.Write.\r
+    //\r
+    UefiDebugLibDebugPortProtocolWrite (Buffer, AsciiStrLen (Buffer));\r
+\r
+    //\r
+    // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
+    //\r
+    if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
+      CpuBreakpoint ();\r
+    } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
+      CpuDeadLoop ();\r
+    }\r
   }\r
 }\r
 \r