From 878ddf1fc3540a715f63594ed22b6929e881afb4 Mon Sep 17 00:00:00 2001 From: bbahnsen Date: Fri, 21 Apr 2006 22:54:32 +0000 Subject: Initial import. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524 --- .../EdkDxeDebugLibReportStatusCode/DebugLib.c | 314 +++++++++++++++++++++ .../EdkDxeDebugLibReportStatusCode.mbd | 30 ++ .../EdkDxeDebugLibReportStatusCode.msa | 69 +++++ .../EdkDxeDebugLibReportStatusCode/build.xml | 47 +++ 4 files changed, 460 insertions(+) create mode 100644 EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/DebugLib.c create mode 100644 EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/EdkDxeDebugLibReportStatusCode.mbd create mode 100644 EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/EdkDxeDebugLibReportStatusCode.msa create mode 100644 EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/build.xml (limited to 'EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode') diff --git a/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/DebugLib.c b/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/DebugLib.c new file mode 100644 index 0000000000..5a7300faba --- /dev/null +++ b/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/DebugLib.c @@ -0,0 +1,314 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + DebugLib.c + +Abstract: + + EFI Debug Library + +--*/ + +static BOOLEAN mDebugLevelInstalled = FALSE; +static EFI_DEBUG_LEVEL_PROTOCOL mDebugLevel = { 0 }; + +EFI_STATUS +DebugLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +/*++ + +Routine Description: + +Arguments: + +Returns: + +--*/ +{ + EFI_STATUS Status; + + // + // Initialize Debug Level Protocol + // + mDebugLevel.DebugLevel = PcdGet32(PcdDebugPrintErrorLevel); + + // + // Install Debug Level Protocol + // + Status = gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gEfiDebugLevelProtocolGuid, &mDebugLevel, + NULL + ); + ASSERT_EFI_ERROR (Status); + + // + // Set flag to show that the Debug Level Protocol has been installed + // + mDebugLevelInstalled = TRUE; + + return EFI_SUCCESS; +} + +VOID +EFIAPI +DebugAssert ( + IN CHAR8 *FileName, + IN INTN LineNumber, + IN CHAR8 *Description + ) +/*++ + +Routine Description: + + Worker function for ASSERT(). If Error Logging hub is loaded log ASSERT + information. If Error Logging hub is not loaded CpuBreakpoint (). + + We use UINT64 buffers due to IPF alignment concerns. + +Arguments: + + FileName - File name of failing routine. + + LineNumber - Line number of failing ASSERT(). + + Description - Descritption, usally the assertion, + +Returns: + + None + +--*/ +{ + UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)]; + EFI_DEBUG_ASSERT_DATA *AssertData; + UINTN TotalSize; + CHAR8 *Temp; + + if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) == 0) { + return; + } + + // + // Make sure it will all fit in the passed in buffer + // + TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + AsciiStrLen (FileName) + 1 + AsciiStrLen (Description) + 1; + if (TotalSize <= EFI_STATUS_CODE_DATA_MAX_SIZE) { + // + // Fill in EFI_DEBUG_ASSERT_DATA + // + AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer; + AssertData->LineNumber = (UINT32)LineNumber; + + // + // Copy Ascii FileName including NULL. + // + Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName); + + // + // Copy Ascii Description + // + AsciiStrCpy (Temp + AsciiStrLen(FileName) + 1, Description); + + REPORT_STATUS_CODE_WITH_EXTENDED_DATA ( + (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED), + (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE), + AssertData, + TotalSize + ); + } + + // + // Put break point in module that contained the error. + // + CpuBreakpoint (); +} + +VOID +DebugVPrint ( + IN UINTN ErrorLevel, + IN CHAR8 *Format, + IN VA_LIST Marker + ) +/*++ + +Routine Description: + + Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT + information. If Error Logging hub is not loaded do nothing. + + We use UINT64 buffers due to IPF alignment concerns. + +Arguments: + + ErrorLevel - If error level is set do the debug print. + + Format - String to use for the print, followed by Print arguments. + + Marker - VarArgs + +Returns: + + None + +--*/ +{ + UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)]; + EFI_DEBUG_INFO *DebugInfo; + UINTN TotalSize; + UINTN Index; + UINT64 *ArgumentPointer; + + // + // Check driver Debug Level value and global debug level + // + if (mDebugLevelInstalled) { + if ((ErrorLevel & mDebugLevel.DebugLevel) == 0) { + return; + } + } else { + if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) { + return; + } + } + + TotalSize = sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64 *) + AsciiStrLen (Format) + 1; + if (TotalSize > EFI_STATUS_CODE_DATA_MAX_SIZE) { + return; + } + + // + // Then EFI_DEBUG_INFO + // + DebugInfo = (EFI_DEBUG_INFO *)Buffer; + DebugInfo->ErrorLevel = (UINT32)ErrorLevel; + + // + // 256 byte mini Var Arg stack. That is followed by the format string. + // + for (Index = 0, ArgumentPointer = (UINT64 *)(DebugInfo + 1); Index < 12; Index++, ArgumentPointer++) { + *ArgumentPointer = VA_ARG (Marker, UINT64); + } + AsciiStrCpy ((CHAR8 *)ArgumentPointer, Format); + + // + // + // + REPORT_STATUS_CODE_WITH_EXTENDED_DATA ( + EFI_DEBUG_CODE, + (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED), + DebugInfo, + TotalSize + ); +} + +VOID +EFIAPI +DebugPrint ( + IN UINTN ErrorLevel, + IN CHAR8 *Format, + ... + ) +/*++ + +Routine Description: + + Wrapper for DebugVPrint () + +Arguments: + + ErrorLevel - If error level is set do the debug print. + + Format - String to use for the print, followed by Print arguments. + + ... - Print arguments. + +Returns: + + None + +--*/ +{ + VA_LIST Marker; + + VA_START (Marker, Format); + DebugVPrint (ErrorLevel, Format, Marker); + VA_END (Marker); +} + +/** + Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer. + + This function fills Length bytes of Buffer with the value specified by + PcdDebugClearMemoryValue, and returns Buffer. + + If Buffer is NULL, then ASSERT(). + + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). + + @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue. + @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. + + @return Buffer + +**/ +VOID * +EFIAPI +DebugClearMemory ( + OUT VOID *Buffer, + IN UINTN Length + ) +{ +// SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue)); + SetMem (Buffer, Length, 0xAF); + return Buffer; +} + +BOOLEAN +EFIAPI +DebugAssertEnabled ( + VOID + ) +{ + return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0); +} + +BOOLEAN +EFIAPI +DebugPrintEnabled ( + VOID + ) +{ + return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0); +} + +BOOLEAN +EFIAPI +DebugCodeEnabled ( + VOID + ) +{ + return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0); +} + +BOOLEAN +EFIAPI +DebugClearMemoryEnabled ( + VOID + ) +{ + return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0); +} + diff --git a/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/EdkDxeDebugLibReportStatusCode.mbd b/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/EdkDxeDebugLibReportStatusCode.mbd new file mode 100644 index 0000000000..9825a208c4 --- /dev/null +++ b/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/EdkDxeDebugLibReportStatusCode.mbd @@ -0,0 +1,30 @@ + + + + + EdkDxeDebugLibReportStatusCode + 76a2a4d8-f605-407a-8057-4a17dcdc4c6d + EDK_RELEASE_VERSION 0x00020000 + FIX ME! + Copyright (c) 2004-2006, Intel Corporation + + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + 2006-03-12 17:09 + 2006-03-31 13:12 + + diff --git a/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/EdkDxeDebugLibReportStatusCode.msa b/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/EdkDxeDebugLibReportStatusCode.msa new file mode 100644 index 0000000000..e80bee2a87 --- /dev/null +++ b/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/EdkDxeDebugLibReportStatusCode.msa @@ -0,0 +1,69 @@ + + + + + EdkDxeDebugLibReportStatusCode + DXE_DRIVER + LIBRARY + 76a2a4d8-f605-407a-8057-4a17dcdc4c6d + EDK_RELEASE_VERSION 0x00020000 + Debug Library for DXE drivers + FIX ME! + Copyright (c) 2004-2006, Intel Corporation + + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + EFI_SPECIFICATION_VERSION 0x00000000 + 2006-03-12 17:09 + 2006-03-31 13:12 + + + DebugLib + ReportStatusCodeLib + BaseMemoryLib + BaseLib + PcdLib + UefiBootServicesTableLib + + + DebugLib.c + + + MdePkg + EdkModulePkg + + + DebugLevel + + + + DebugLibConstructor + + + + + PcdDebugPropertyMask + 0x00000005 + UINT8 + + + PcdDebugPrintErrorLevel + 0x00000006 + UINT32 + + + diff --git a/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/build.xml b/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/build.xml new file mode 100644 index 0000000000..fb105466c7 --- /dev/null +++ b/EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3