Initial import.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
314
EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/DebugLib.c
Normal file
314
EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/DebugLib.c
Normal file
@ -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 <20> 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);
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<LibraryModuleBuildDescription xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
|
||||
<MbdLibHeader>
|
||||
<BaseName>EdkDxeDebugLibReportStatusCode</BaseName>
|
||||
<Guid>76a2a4d8-f605-407a-8057-4a17dcdc4c6d</Guid>
|
||||
<Version>EDK_RELEASE_VERSION 0x00020000</Version>
|
||||
<Description>FIX ME!</Description>
|
||||
<Copyright>Copyright (c) 2004-2006, Intel Corporation</Copyright>
|
||||
<License>
|
||||
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.
|
||||
</License>
|
||||
<Created>2006-03-12 17:09</Created>
|
||||
<Modified>2006-03-31 13:12</Modified>
|
||||
</MbdLibHeader>
|
||||
</LibraryModuleBuildDescription>
|
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<LibraryModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
|
||||
<MsaLibHeader>
|
||||
<BaseName>EdkDxeDebugLibReportStatusCode</BaseName>
|
||||
<ModuleType>DXE_DRIVER</ModuleType>
|
||||
<ComponentType>LIBRARY</ComponentType>
|
||||
<Guid>76a2a4d8-f605-407a-8057-4a17dcdc4c6d</Guid>
|
||||
<Version>EDK_RELEASE_VERSION 0x00020000</Version>
|
||||
<Abstract>Debug Library for DXE drivers</Abstract>
|
||||
<Description>FIX ME!</Description>
|
||||
<Copyright>Copyright (c) 2004-2006, Intel Corporation</Copyright>
|
||||
<License>
|
||||
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.
|
||||
</License>
|
||||
<Specification>EFI_SPECIFICATION_VERSION 0x00000000</Specification>
|
||||
<Created>2006-03-12 17:09</Created>
|
||||
<Updated>2006-03-31 13:12</Updated>
|
||||
</MsaLibHeader>
|
||||
<LibraryClassDefinitions>
|
||||
<LibraryClass Usage="ALWAYS_PRODUCED">DebugLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">ReportStatusCodeLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">BaseMemoryLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">BaseLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">PcdLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">UefiBootServicesTableLib</LibraryClass>
|
||||
</LibraryClassDefinitions>
|
||||
<SourceFiles>
|
||||
<Filename>DebugLib.c</Filename>
|
||||
</SourceFiles>
|
||||
<Includes>
|
||||
<PackageName>MdePkg</PackageName>
|
||||
<PackageName>EdkModulePkg</PackageName>
|
||||
</Includes>
|
||||
<Protocols>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">DebugLevel</Protocol>
|
||||
</Protocols>
|
||||
<Externs>
|
||||
<Extern>
|
||||
<Constructor>DebugLibConstructor</Constructor>
|
||||
</Extern>
|
||||
</Externs>
|
||||
<PCDs>
|
||||
<PcdData ItemType="FIXED_AT_BUILD">
|
||||
<C_Name>PcdDebugPropertyMask</C_Name>
|
||||
<Token>0x00000005</Token>
|
||||
<DatumType>UINT8</DatumType>
|
||||
</PcdData>
|
||||
<PcdData ItemType="PATCHABLE_IN_MODULE">
|
||||
<C_Name>PcdDebugPrintErrorLevel</C_Name>
|
||||
<Token>0x00000006</Token>
|
||||
<DatumType>UINT32</DatumType>
|
||||
</PcdData>
|
||||
</PCDs>
|
||||
</LibraryModuleSurfaceArea>
|
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><!-- 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.-->
|
||||
<project basedir="." default="EdkDxeDebugLibReportStatusCode"><!--Apply external ANT tasks-->
|
||||
<taskdef resource="GenBuild.tasks"/>
|
||||
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
|
||||
<property environment="env"/>
|
||||
<property name="WORKSPACE_DIR" value="${env.WORKSPACE}"/>
|
||||
<import file="${WORKSPACE_DIR}\Tools\Conf\BuildMacro.xml"/><!--MODULE_RELATIVE PATH is relative to PACKAGE_DIR-->
|
||||
<property name="MODULE_RELATIVE_PATH" value="Library\EdkDxeDebugLibReportStatusCode"/>
|
||||
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
|
||||
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
|
||||
<target name="EdkDxeDebugLibReportStatusCode">
|
||||
<GenBuild baseName="EdkDxeDebugLibReportStatusCode" mbdFilename="${MODULE_DIR}\EdkDxeDebugLibReportStatusCode.mbd" msaFilename="${MODULE_DIR}\EdkDxeDebugLibReportStatusCode.msa"/>
|
||||
</target>
|
||||
<target depends="EdkDxeDebugLibReportStatusCode_clean" name="clean"/>
|
||||
<target depends="EdkDxeDebugLibReportStatusCode_cleanall" name="cleanall"/>
|
||||
<target name="EdkDxeDebugLibReportStatusCode_clean">
|
||||
<OutputDirSetup baseName="EdkDxeDebugLibReportStatusCode" mbdFilename="${MODULE_DIR}\EdkDxeDebugLibReportStatusCode.mbd" msaFilename="${MODULE_DIR}\EdkDxeDebugLibReportStatusCode.msa"/>
|
||||
<if>
|
||||
<available file="${DEST_DIR_OUTPUT}\EdkDxeDebugLibReportStatusCode_build.xml"/>
|
||||
<then>
|
||||
<ant antfile="${DEST_DIR_OUTPUT}\EdkDxeDebugLibReportStatusCode_build.xml" target="clean"/>
|
||||
</then>
|
||||
</if>
|
||||
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
|
||||
</target>
|
||||
<target name="EdkDxeDebugLibReportStatusCode_cleanall">
|
||||
<OutputDirSetup baseName="EdkDxeDebugLibReportStatusCode" mbdFilename="${MODULE_DIR}\EdkDxeDebugLibReportStatusCode.mbd" msaFilename="${MODULE_DIR}\EdkDxeDebugLibReportStatusCode.msa"/>
|
||||
<if>
|
||||
<available file="${DEST_DIR_OUTPUT}\EdkDxeDebugLibReportStatusCode_build.xml"/>
|
||||
<then>
|
||||
<ant antfile="${DEST_DIR_OUTPUT}\EdkDxeDebugLibReportStatusCode_build.xml" target="cleanall"/>
|
||||
</then>
|
||||
</if>
|
||||
<delete dir="${DEST_DIR_OUTPUT}"/>
|
||||
<delete dir="${DEST_DIR_DEBUG}"/>
|
||||
<delete>
|
||||
<fileset dir="${BIN_DIR}" includes="**EdkDxeDebugLibReportStatusCode*"/>
|
||||
</delete>
|
||||
</target>
|
||||
</project>
|
Reference in New Issue
Block a user