diff --git a/AdvLoggerPkg/AdvLoggerPkg.dsc b/AdvLoggerPkg/AdvLoggerPkg.dsc index e1d4b2ba54..0c30761f78 100644 --- a/AdvLoggerPkg/AdvLoggerPkg.dsc +++ b/AdvLoggerPkg/AdvLoggerPkg.dsc @@ -122,6 +122,7 @@ [Components] AdvLoggerPkg/Library/BaseDebugLibAdvancedLogger/BaseDebugLibAdvancedLogger.inf + AdvLoggerPkg/Library/BasePanicLibAdvancedLogger/BasePanicLibAdvancedLogger.inf [Components.IA32] AdvLoggerPkg/Library/AdvancedLoggerLib/Pei/AdvancedLoggerLib.inf diff --git a/AdvLoggerPkg/Docs/ReadMe.md b/AdvLoggerPkg/Docs/ReadMe.md index 18f4216899..6f166b030f 100644 --- a/AdvLoggerPkg/Docs/ReadMe.md +++ b/AdvLoggerPkg/Docs/ReadMe.md @@ -43,6 +43,7 @@ The following libraries are used with AdvancedLogger: | AdvancedLoggerLib | One per module type - used to provide access to the in memory log buffer | | AdvLoggerSmmAccessLib | Used to intercept GetVariable in order to provide an OS utility the ability to read the log | | BaseDebugLibAdvancedLogger | Basic Dxe etc DebugLib | +| BasePanicLibAdvancedLogger | Basic PanicLib that applies to all PI boot phases that AdvancedLoggerLib supports. | | DebugAgent | Used to intercept SEC initialization | | PeiDebugLibAdvancedLogger | Basic Pei DebugLib | | AdvancedLoggerHdwPortLib | Hook for a hardware port to capture debug messages as they are written to the log. | @@ -267,5 +268,5 @@ result in hardware printing not functional. ## Copyright -Copyright (C) Microsoft Corporation. All rights reserved. +Copyright (C) Microsoft Corporation. All rights reserved. \ SPDX-License-Identifier: BSD-2-Clause-Patent diff --git a/AdvLoggerPkg/Library/BasePanicLibAdvancedLogger/BasePanicLibAdvancedLogger.c b/AdvLoggerPkg/Library/BasePanicLibAdvancedLogger/BasePanicLibAdvancedLogger.c new file mode 100644 index 0000000000..cc617d420a --- /dev/null +++ b/AdvLoggerPkg/Library/BasePanicLibAdvancedLogger/BasePanicLibAdvancedLogger.c @@ -0,0 +1,64 @@ +/** @file + An instance of the Panic Library that outputs to advanced logger. + + Copyright (c) Microsoft Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +// +// Define the maximum panic message length that this library supports +// +#define MAX_PANIC_MESSAGE_LENGTH 0x100 + +/** + Prints a panic message containing a filename, line number, and description. + This is always followed by a dead loop. + + Print a message of the form "PANIC (): \n" + to the debug output device. Immediately after that CpuDeadLoop() is called. + + If FileName is NULL, then a string of "(NULL) Filename" is printed. + If Description is NULL, then a string of "(NULL) Description" is printed. + + @param FileName The pointer to the name of the source file that generated the panic condition. + @param LineNumber The line number in the source file that generated the panic condition + @param Description The pointer to the description of the panic condition. + +**/ +VOID +EFIAPI +PanicReport ( + IN CONST CHAR8 *FileName, + IN UINTN LineNumber, + IN CONST CHAR8 *Description + ) +{ + CHAR8 Buffer[MAX_PANIC_MESSAGE_LENGTH]; + + if (FileName == NULL) { + FileName = "(NULL) Filename"; + } + + if (Description == NULL) { + Description = "(NULL) Description"; + } + + AsciiSPrint (Buffer, sizeof (Buffer), "PANIC [%a] %a(%d): %a\n", gEfiCallerBaseName, FileName, LineNumber, Description); + + // Note: 0x80000000 is used instead of DEBUG_ERROR to avoid a dependency on DebugLib.h just for that value. + // The high bit being set for error status codes is defined per the UEFI Specification (2.10 section below). + // https://uefi.org/specs/UEFI/2.10/Apx_D_Status_Codes.html#status-codes + AdvancedLoggerWrite (0x80000000, Buffer, AsciiStrnLenS (Buffer, sizeof (Buffer))); + + // + // Deadloop since the system is in an unrecoverable state. + // + CpuDeadLoop (); +} diff --git a/AdvLoggerPkg/Library/BasePanicLibAdvancedLogger/BasePanicLibAdvancedLogger.inf b/AdvLoggerPkg/Library/BasePanicLibAdvancedLogger/BasePanicLibAdvancedLogger.inf new file mode 100644 index 0000000000..3c8a92f553 --- /dev/null +++ b/AdvLoggerPkg/Library/BasePanicLibAdvancedLogger/BasePanicLibAdvancedLogger.inf @@ -0,0 +1,31 @@ +## @file +# An instance of the Panic Library that outputs to advanced logger. +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BasePanicLibAdvancedLogger + FILE_GUID = 536D781D-A6A6-4831-AAB8-1E391DA2DD06 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = PanicLib + +# +# VALID_ARCHITECTURES = ANY +# + +[Packages] + MdePkg/MdePkg.dec + AdvLoggerPkg/AdvLoggerPkg.dec + +[LibraryClasses] + AdvancedLoggerLib + BaseLib + PrintLib + +[Sources] + BasePanicLibAdvancedLogger.c