3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 static BOOLEAN mDebugLevelInstalled
= FALSE
;
23 static EFI_DEBUG_LEVEL_PROTOCOL mDebugLevel
= { 0 };
27 IN EFI_HANDLE ImageHandle
,
28 IN EFI_SYSTEM_TABLE
*SystemTable
43 // Initialize Debug Level Protocol
45 mDebugLevel
.DebugLevel
= PcdGet32(PcdDebugPrintErrorLevel
);
48 // Install Debug Level Protocol
50 Status
= gBS
->InstallMultipleProtocolInterfaces (
52 &gEfiDebugLevelProtocolGuid
, &mDebugLevel
,
55 ASSERT_EFI_ERROR (Status
);
58 // Set flag to show that the Debug Level Protocol has been installed
60 mDebugLevelInstalled
= TRUE
;
76 Worker function for ASSERT(). If Error Logging hub is loaded log ASSERT
77 information. If Error Logging hub is not loaded CpuBreakpoint ().
79 We use UINT64 buffers due to IPF alignment concerns.
83 FileName - File name of failing routine.
85 LineNumber - Line number of failing ASSERT().
87 Description - Descritption, usally the assertion,
95 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof(UINT64
)];
96 EFI_DEBUG_ASSERT_DATA
*AssertData
;
100 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) == 0) {
105 // Make sure it will all fit in the passed in buffer
107 TotalSize
= sizeof (EFI_DEBUG_ASSERT_DATA
) + AsciiStrLen (FileName
) + 1 + AsciiStrLen (Description
) + 1;
108 if (TotalSize
<= EFI_STATUS_CODE_DATA_MAX_SIZE
) {
110 // Fill in EFI_DEBUG_ASSERT_DATA
112 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)Buffer
;
113 AssertData
->LineNumber
= (UINT32
)LineNumber
;
116 // Copy Ascii FileName including NULL.
118 Temp
= AsciiStrCpy ((CHAR8
*)(AssertData
+ 1), FileName
);
121 // Copy Ascii Description
123 AsciiStrCpy (Temp
+ AsciiStrLen(FileName
) + 1, Description
);
125 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
126 (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
),
127 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
),
134 // Put break point in module that contained the error.
149 Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT
150 information. If Error Logging hub is not loaded do nothing.
152 We use UINT64 buffers due to IPF alignment concerns.
156 ErrorLevel - If error level is set do the debug print.
158 Format - String to use for the print, followed by Print arguments.
168 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof (UINT64
)];
169 EFI_DEBUG_INFO
*DebugInfo
;
172 UINT64
*ArgumentPointer
;
175 // Check driver Debug Level value and global debug level
177 if (mDebugLevelInstalled
) {
178 if ((ErrorLevel
& mDebugLevel
.DebugLevel
) == 0) {
182 if ((ErrorLevel
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
187 TotalSize
= sizeof (EFI_DEBUG_INFO
) + 12 * sizeof (UINT64
*) + AsciiStrLen (Format
) + 1;
188 if (TotalSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
193 // Then EFI_DEBUG_INFO
195 DebugInfo
= (EFI_DEBUG_INFO
*)Buffer
;
196 DebugInfo
->ErrorLevel
= (UINT32
)ErrorLevel
;
199 // 256 byte mini Var Arg stack. That is followed by the format string.
201 for (Index
= 0, ArgumentPointer
= (UINT64
*)(DebugInfo
+ 1); Index
< 12; Index
++, ArgumentPointer
++) {
202 *ArgumentPointer
= VA_ARG (Marker
, UINT64
);
204 AsciiStrCpy ((CHAR8
*)ArgumentPointer
, Format
);
209 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
211 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_DC_UNSPECIFIED
),
228 Wrapper for DebugVPrint ()
232 ErrorLevel - If error level is set do the debug print.
234 Format - String to use for the print, followed by Print arguments.
236 ... - Print arguments.
246 VA_START (Marker
, Format
);
247 DebugVPrint (ErrorLevel
, Format
, Marker
);
252 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
254 This function fills Length bytes of Buffer with the value specified by
255 PcdDebugClearMemoryValue, and returns Buffer.
257 If Buffer is NULL, then ASSERT().
259 If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT().
261 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
262 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
274 // SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));
275 SetMem (Buffer
, Length
, 0xAF);
285 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
294 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
303 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
308 DebugClearMemoryEnabled (
312 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);