TianoCore EDK2 master
Loading...
Searching...
No Matches
DebugLib.c
Go to the documentation of this file.
1
20#include <Base.h>
21#include <Library/DebugLib.h>
22#include <Library/BaseLib.h>
23#include <Library/PrintLib.h>
24#include <Library/PcdLib.h>
27
28#include "Write.h"
29
30//
31// Define the maximum debug and assert message length that this library supports
32//
33#define MAX_DEBUG_MESSAGE_LENGTH 0x100
34
35//
36// VA_LIST can not initialize to NULL for all compiler, so we use this to
37// indicate a null VA_LIST
38//
39VA_LIST mVaListNull;
40
56VOID
57EFIAPI
59 IN UINTN ErrorLevel,
60 IN CONST CHAR8 *Format,
61 ...
62 )
63{
64 VA_LIST Marker;
65
66 VA_START (Marker, Format);
67 DebugVPrint (ErrorLevel, Format, Marker);
68 VA_END (Marker);
69}
70
88VOID
90 IN UINTN ErrorLevel,
91 IN CONST CHAR8 *Format,
92 IN VA_LIST VaListMarker,
93 IN BASE_LIST BaseListMarker
94 )
95{
96 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
97
98 //
99 // If Format is NULL, then ASSERT().
100 //
101 ASSERT (Format != NULL);
102
103 //
104 // Check driver debug mask value and global mask
105 //
106 if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
107 return;
108 }
109
110 //
111 // Convert the DEBUG() message to an ASCII String
112 //
113 if (BaseListMarker == NULL) {
114 AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
115 } else {
116 AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
117 }
118
119 //
120 // Send the print string to a Serial Port
121 //
122 DebugLibFdtPL011UartWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
123}
124
140VOID
141EFIAPI
143 IN UINTN ErrorLevel,
144 IN CONST CHAR8 *Format,
145 IN VA_LIST VaListMarker
146 )
147{
148 DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
149}
150
168VOID
169EFIAPI
171 IN UINTN ErrorLevel,
172 IN CONST CHAR8 *Format,
173 IN BASE_LIST BaseListMarker
174 )
175{
176 DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
177}
178
200VOID
201EFIAPI
203 IN CONST CHAR8 *FileName,
204 IN UINTN LineNumber,
205 IN CONST CHAR8 *Description
206 )
207{
208 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
209
210 //
211 // Generate the ASSERT() message in Ascii format
212 //
213 AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT [%a] %a(%d): %a\n", gEfiCallerBaseName, FileName, LineNumber, Description);
214
215 //
216 // Send the print string to the Console Output device
217 //
218 DebugLibFdtPL011UartWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
219
220 //
221 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
222 //
223 if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
224 CpuBreakpoint ();
225 } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
226 CpuDeadLoop ();
227 }
228}
229
245VOID *
246EFIAPI
248 OUT VOID *Buffer,
249 IN UINTN Length
250 )
251{
252 //
253 // If Buffer is NULL, then ASSERT().
254 //
255 ASSERT (Buffer != NULL);
256
257 //
258 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
259 //
260 return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));
261}
262
273BOOLEAN
274EFIAPI
276 VOID
277 )
278{
279 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
280}
281
292BOOLEAN
293EFIAPI
295 VOID
296 )
297{
298 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
299}
300
311BOOLEAN
312EFIAPI
314 VOID
315 )
316{
317 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
318}
319
330BOOLEAN
331EFIAPI
333 VOID
334 )
335{
336 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
337}
338
348BOOLEAN
349EFIAPI
351 IN CONST UINTN ErrorLevel
352 )
353{
354 return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != 0);
355}
UINT64 UINTN
VOID EFIAPI DebugAssert(IN CONST CHAR8 *FileName, IN UINTN LineNumber, IN CONST CHAR8 *Description)
Definition: DebugLib.c:188
VOID EFIAPI DebugVPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN VA_LIST VaListMarker)
Definition: DebugLib.c:126
VOID DebugPrintMarker(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN VA_LIST VaListMarker, IN BASE_LIST BaseListMarker)
Definition: DebugLib.c:76
VOID EFIAPI DebugBPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN BASE_LIST BaseListMarker)
Definition: DebugLib.c:154
VOID *EFIAPI DebugClearMemory(OUT VOID *Buffer, IN UINTN Length)
Definition: DebugLib.c:232
VOID EFIAPI DebugPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format,...)
Definition: DebugLib.c:45
BOOLEAN EFIAPI DebugCodeEnabled(VOID)
Definition: DebugLib.c:301
BOOLEAN EFIAPI DebugClearMemoryEnabled(VOID)
Definition: DebugLib.c:321
BOOLEAN EFIAPI DebugPrintEnabled(VOID)
Definition: DebugLib.c:281
BOOLEAN EFIAPI DebugAssertEnabled(VOID)
Definition: DebugLib.c:261
BOOLEAN EFIAPI DebugPrintLevelEnabled(IN CONST UINTN ErrorLevel)
Definition: DebugLib.c:350
UINTN DebugLibFdtPL011UartWrite(IN UINT8 *Buffer, IN UINTN NumberOfBytes)
Definition: Flash.c:34
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
VOID EFIAPI CpuDeadLoop(VOID)
Definition: CpuDeadLoop.c:25
VOID EFIAPI CpuBreakpoint(VOID)
Definition: CpuBreakpoint.c:26
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
UINT32 EFIAPI GetDebugPrintErrorLevel(VOID)
UINTN EFIAPI AsciiBSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN BASE_LIST Marker)
Definition: PrintLib.c:763
UINTN EFIAPI AsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:702
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VA_START(Marker, Parameter)
Definition: Base.h:661
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
UINTN * BASE_LIST
Definition: Base.h:711
#define OUT
Definition: Base.h:284
#define VA_END(Marker)
Definition: Base.h:691
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PcdGet32(TokenName)
Definition: PcdLib.h:362