/** Prints a debug message to the debug output device if the specified error level is enabled. If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function GetDebugPrintErrorLevel (), then print the message specified by Format and the associated variable argument list to the debug output device. If Format is NULL, then ASSERT(). @param ErrorLevel The error level of the debug message. @param Format Format string for the debug message to print. @param ... A variable argument list whose contents are accessed based on the format string specified by Format. **/ VOID EFIAPI DebugPrint ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ... ) { CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; VA_LIST Marker; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); // // Check driver debug mask value and global mask // if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { return; } // // Convert the DEBUG() message to an ASCII String // VA_START (Marker, Format); AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); VA_END (Marker); // // Send the print string to EFI_DEBUGPORT_PROTOCOL.Write. // UefiDebugLibDebugPortProtocolWrite (Buffer, AsciiStrLen (Buffer)); }
/** The constructor function caches the PCI Express Base Address and creates a Set Virtual Address Map event to convert physical address to virtual addresses. @param ImageHandle The firmware allocated handle for the EFI image. @param SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The constructor completed successfully. @retval Other value The constructor did not complete successfully. **/ EFI_STATUS EFIAPI DxeDebugPrintErrorLevelLibConstructor ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; // // Initialize the error level mask from PCD setting. // mDebugPrintErrorLevel = PcdGet32 (PcdDebugPrintErrorLevel); // // Install Debug Mask Protocol onto ImageHandle // mSystemTable = SystemTable; Status = SystemTable->BootServices->InstallMultipleProtocolInterfaces ( &ImageHandle, &gEfiDebugMaskProtocolGuid, &mDebugMaskProtocol, NULL ); // // Attempt to retrieve the global debug print error level mask from the EFI Variable // If the EFI Variable can not be accessed when this module's library constructors are // executed a HOB can be used to set the global debug print error level. If no value // was found then the EFI Variable access will be reattempted on every DEBUG() print // from this module until the EFI Variable services are available. // GetDebugPrintErrorLevel (); return Status; }
/** Prints a debug message to the debug output device if the specified error level is enabled base on Null-terminated format string and a VA_LIST argument list or a BASE_LIST argument list. If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function GetDebugPrintErrorLevel (), then print the message specified by Format and the associated variable argument list to the debug output device. If Format is NULL, then ASSERT(). @param ErrorLevel The error level of the debug message. @param Format Format string for the debug message to print. @param VaListMarker VA_LIST marker for the variable argument list. @param BaseListMarker BASE_LIST marker for the variable argument list. **/ VOID DebugPrintMarker ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN VA_LIST VaListMarker, IN BASE_LIST BaseListMarker ) { CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); // // Check driver debug mask value and global mask // if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { return; } // // Convert the DEBUG() message to a Unicode String // if (BaseListMarker == NULL) { UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, VaListMarker); } else { UnicodeBSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, BaseListMarker); } // // Send the print string to the Console Output device // if ((gST != NULL) && (gST->ConOut != NULL)) { gST->ConOut->OutputString (gST->ConOut, Buffer); } }
/** Prints a debug message to the debug output device if the specified error level is enabled. If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function GetDebugPrintErrorLevel (), then print the message specified by Format and the associated variable argument list to the debug output device. If Format is NULL, then ASSERT(). @param ErrorLevel The error level of the debug message. @param Format Format string for the debug message to print. @param ... A variable argument list whose contents are accessed based on the format string specified by Format. **/ VOID EFIAPI DebugPrint ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ... ) { CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; VA_LIST Marker; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); // // Check driver debug mask value and global mask // if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { return; } // // Convert the DEBUG() message to a Unicode String // VA_START (Marker, Format); UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, Marker); VA_END (Marker); // // Send the print string to the Console Output device // if ((gST != NULL) && (gST->ConOut != NULL)) { gST->ConOut->OutputString (gST->ConOut, Buffer); } }
/** Prints a debug message to the debug output device if the specified error level is enabled. If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function GetDebugPrintErrorLevel (), then print the message specified by Format and the associated variable argument list to the debug output device. If Format is NULL, then ASSERT(). @param ErrorLevel The error level of the debug message. @param Format Format string for the debug message to print. @param ... Variable argument list whose contents are accessed based on the format string specified by Format. **/ VOID EFIAPI DebugPrint ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ... ) { CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; VA_LIST Marker; UINT8 *Ptr; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); // // Check driver debug mask value and global mask // if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { return; } // // Convert the DEBUG() message to an ASCII String // VA_START (Marker, Format); AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); VA_END (Marker); // // Send the print string to the debug I/O port // for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) { IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr); } }
/** Prints a debug message to the debug output device if the specified error level is enabled. If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print the message specified by Format and the associated variable argument list to the debug output device. If Format is NULL, then ASSERT(). @param ErrorLevel The error level of the debug message. @param Format Format string for the debug message to print. @param ... Variable argument list whose contents are accessed based on the format string specified by Format. **/ VOID EFIAPI DebugPrint ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ... ) { CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; VA_LIST Marker; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); // // Check driver debug mask value and global mask // if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { return; } // // Convert the DEBUG() message to an ASCII String // VA_START (Marker, Format); AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); VA_END (Marker); // // Send the print string to a Serial Port // AcquireSpinLock (&mInternalDebugLock); SerialPortWrite ((UINT8 *) Buffer, AsciiStrLen(Buffer)); ReleaseSpinLock (&mInternalDebugLock); }
/** Prints a debug message to the debug output device if the specified error level is enabled. If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function GetDebugPrintErrorLevel (), then print the message specified by Format and the associated variable argument list to the debug output device. If Format is NULL, then ASSERT(). If the length of the message string specificed by Format is larger than the maximum allowable record length, then directly return and not print it. @param ErrorLevel The error level of the debug message. @param Format Format string for the debug message to print. @param ... Variable argument list whose contents are accessed based on the format string specified by Format. **/ VOID EFIAPI DebugPrint ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ... ) { UINT64 Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1]; EFI_DEBUG_INFO *DebugInfo; UINTN TotalSize; UINTN DestBufferSize; VA_LIST VaListMarker; BASE_LIST BaseListMarker; CHAR8 *FormatString; BOOLEAN Long; // // If Format is NULL, then ASSERT(). // ASSERT (Format != NULL); // // Check driver Debug Level value and global debug level // if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { return; } // // Compute the total size of the record. // Note that the passing-in format string and variable parameters will be constructed to // the following layout: // // Buffer->|------------------------| // | Padding | 4 bytes // DebugInfo->|------------------------| // | EFI_DEBUG_INFO | sizeof(EFI_DEBUG_INFO) // BaseListMarker->|------------------------| // | ... | // | variable arguments | 12 * sizeof (UINT64) // | ... | // |------------------------| // | Format String | // |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer) // TotalSize = 4 + sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrSize (Format); // // If the TotalSize is larger than the maximum record size, then return // if (TotalSize > sizeof (Buffer)) { return; } // // Fill in EFI_DEBUG_INFO // // Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarker is // 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarker will cause // exception on IPF. Buffer starts at 64-bit aligned address, so skipping 4 types (sizeof(EFI_DEBUG_INFO)) // just makes address of BaseListMarker, which follows DebugInfo, 64-bit aligned. // DebugInfo = (EFI_DEBUG_INFO *)(Buffer) + 1; DebugInfo->ErrorLevel = (UINT32)ErrorLevel; BaseListMarker = (BASE_LIST)(DebugInfo + 1); FormatString = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12); // // Copy the Format string into the record // // According to the content structure of Buffer shown above, the size of // the FormatString buffer is the size of Buffer minus the Padding // (4 bytes), minus the size of EFI_DEBUG_INFO, minus the size of // variable arguments (12 * sizeof (UINT64)). // DestBufferSize = sizeof (Buffer) - 4 - sizeof (EFI_DEBUG_INFO) - 12 * sizeof (UINT64); AsciiStrCpyS (FormatString, DestBufferSize / sizeof (CHAR8), Format); // // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments // of format in DEBUG string, which is followed by the DEBUG format string. // Here we will process the variable arguments and pack them in this area. // VA_START (VaListMarker, Format); for (; *Format != '\0'; Format++) { // // Only format with prefix % is processed. // if (*Format != '%') { continue; } Long = FALSE; // // Parse Flags and Width // for (Format++; TRUE; Format++) { if (*Format == '.' || *Format == '-' || *Format == '+' || *Format == ' ') { // // These characters in format field are omitted. // continue; } if (*Format >= '0' && *Format <= '9') { // // These characters in format field are omitted. // continue; } if (*Format == 'L' || *Format == 'l') { // // 'L" or "l" in format field means the number being printed is a UINT64 // Long = TRUE; continue; } if (*Format == '*') { // // '*' in format field means the precision of the field is specified by // a UINTN argument in the argument list. // BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN); continue; } if (*Format == '\0') { // // Make no output if Format string terminates unexpectedly when // looking up for flag, width, precision and type. // Format--; } // // When valid argument type detected or format string terminates unexpectedly, // the inner loop is done. // break; } // // Pack variable arguments into the storage area following EFI_DEBUG_INFO. // if ((*Format == 'p') && (sizeof (VOID *) > 4)) { Long = TRUE; } if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd' || *Format == 'u') { if (Long) { BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64); } else { BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int); } } else if (*Format == 's' || *Format == 'S' || *Format == 'a' || *Format == 'g' || *Format == 't') { BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *); } else if (*Format == 'c') {