**/\r
\r
#include <Base.h>\r
-#include <Uefi.h>\r
#include <Library/DebugLib.h>\r
#include <Library/BaseLib.h>\r
#include <Library/IoLib.h>\r
#include <Library/PcdLib.h>\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugPrintErrorLevelLib.h>\r
+#include "DebugLibDetect.h"\r
\r
//\r
// Define the maximum debug and assert message length that this library supports\r
//\r
#define MAX_DEBUG_MESSAGE_LENGTH 0x100\r
\r
-/**\r
- This constructor function does not have to do anything.\r
-\r
- @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
-\r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-PlatformDebugLibIoPortConstructor (\r
- VOID\r
- )\r
-{\r
- return EFI_SUCCESS;\r
-}\r
-\r
/**\r
Prints a debug message to the debug output device if the specified error level is enabled.\r
\r
{\r
CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
VA_LIST Marker;\r
- UINT8 *Ptr;\r
+ UINTN Length;\r
\r
//\r
// If Format is NULL, then ASSERT().\r
ASSERT (Format != NULL);\r
\r
//\r
- // Check driver debug mask value and global mask\r
+ // Check if the global mask disables this message or the device is inactive\r
//\r
- if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {\r
+ if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0 ||\r
+ !PlatformDebugLibIoPortFound ()) {\r
return;\r
}\r
\r
// Convert the DEBUG() message to an ASCII String\r
//\r
VA_START (Marker, Format);\r
- AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
+ Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
VA_END (Marker);\r
\r
//\r
// Send the print string to the debug I/O port\r
//\r
- for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) {\r
- IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr);\r
- }\r
+ IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r
}\r
\r
\r
)\r
{\r
CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
- UINT8 *Ptr;\r
+ UINTN Length;\r
\r
//\r
// Generate the ASSERT() message in Ascii format\r
//\r
- AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT %a(%d): %a\n", FileName, LineNumber, Description);\r
+ Length = AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n",\r
+ FileName, (UINT64)LineNumber, Description);\r
\r
//\r
- // Send the print string to the Console Output device\r
+ // Send the print string to the debug I/O port, if present\r
//\r
- for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) {\r
- IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr);\r
+ if (PlatformDebugLibIoPortFound ()) {\r
+ IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r
}\r
\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
+ )\r
+{\r
+ return IoRead8 (PcdGet16 (PcdDebugIoPort)) == BOCHS_DEBUG_PORT_MAGIC;\r
+}\r