]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Include/Library/EdkIIGlueDebugLib.h
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Include / Library / EdkIIGlueDebugLib.h
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 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
8
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.
11
12
13 Module Name:
14
15 EdkIIGlueDebugLib.h
16
17 Abstract:
18
19 Public include file for the Debug Library
20
21 --*/
22
23 #ifndef __EDKII_GLUE_DEBUG_LIB_H__
24 #define __EDKII_GLUE_DEBUG_LIB_H__
25
26 //
27 // To use EdkII code, these R8.x macros are undefined
28 //
29 #undef ASSERT
30 #undef DEBUG
31 #undef ASSERT_EFI_ERROR
32 #undef ASSERT_PROTOCOL_ALREADY_INSTALLED
33 #undef DEBUG_CODE
34 #undef CR
35
36 #undef EFI_D_INIT
37 #undef EFI_D_WARN
38 #undef EFI_D_LOAD
39 #undef EFI_D_FS
40 #undef EFI_D_POOL
41 #undef EFI_D_PAGE
42 #undef EFI_D_INFO
43 #undef EFI_D_VARIABLE
44 #undef EFI_D_BM
45 #undef EFI_D_BLKIO
46 #undef EFI_D_NET
47 #undef EFI_D_UNDI
48 #undef EFI_D_LOADFILE
49 #undef EFI_D_EVENT
50 #undef EFI_D_ERROR
51
52 //
53 // Declare bits for PcdDebugPropertyMask
54 //
55 #define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01
56 #define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02
57 #define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04
58 #define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08
59 #define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10
60 #define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20
61
62 //
63 // Declare bits for PcdDebugPrintErrorLevel and the ErrorLevel parameter of DebugPrint()
64 //
65 #define DEBUG_INIT 0x00000001 // Initialization
66 #define DEBUG_WARN 0x00000002 // Warnings
67 #define DEBUG_LOAD 0x00000004 // Load events
68 #define DEBUG_FS 0x00000008 // EFI File system
69 #define DEBUG_POOL 0x00000010 // Alloc & Free's
70 #define DEBUG_PAGE 0x00000020 // Alloc & Free's
71 #define DEBUG_INFO 0x00000040 // Verbose
72 #define DEBUG_VARIABLE 0x00000100 // Variable
73 #define DEBUG_BM 0x00000400 // Boot Manager
74 #define DEBUG_BLKIO 0x00001000 // BlkIo Driver
75 #define DEBUG_NET 0x00004000 // SNI Driver
76 #define DEBUG_UNDI 0x00010000 // UNDI Driver
77 #define DEBUG_LOADFILE 0x00020000 // UNDI Driver
78 #define DEBUG_EVENT 0x00080000 // Event messages
79 #define DEBUG_ERROR 0x80000000 // Error
80
81 //
82 // Aliases of debug message mask bits
83 //
84 #define EFI_D_INIT DEBUG_INIT
85 #define EFI_D_WARN DEBUG_WARN
86 #define EFI_D_LOAD DEBUG_LOAD
87 #define EFI_D_FS DEBUG_FS
88 #define EFI_D_POOL DEBUG_POOL
89 #define EFI_D_PAGE DEBUG_PAGE
90 #define EFI_D_INFO DEBUG_INFO
91 #define EFI_D_VARIABLE DEBUG_VARIABLE
92 #define EFI_D_BM DEBUG_BM
93 #define EFI_D_BLKIO DEBUG_BLKIO
94 #define EFI_D_NET DEBUG_NET
95 #define EFI_D_UNDI DEBUG_UNDI
96 #define EFI_D_LOADFILE DEBUG_LOADFILE
97 #define EFI_D_EVENT DEBUG_EVENT
98 #define EFI_D_ERROR DEBUG_ERROR
99
100
101 //
102 // Use the following 4 macros to save size
103 //
104 #define DebugAssertEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0))
105
106 #define DebugPrintEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0))
107
108 #define DebugCodeEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0))
109
110 #define DebugClearMemoryEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0))
111
112
113 /**
114
115 Prints a debug message to the debug output device if the specified error level is enabled.
116
117 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
118 the message specified by Format and the associated variable argument list to
119 the debug output device.
120
121 If Format is NULL, then ASSERT().
122
123 @param ErrorLevel The error level of the debug message.
124 @param Format Format string for the debug message to print.
125
126 **/
127 VOID
128 EFIAPI
129 DebugPrint (
130 IN UINTN ErrorLevel,
131 IN CONST CHAR8 *Format,
132 ...
133 );
134
135
136 /**
137
138 Prints an assert message containing a filename, line number, and description.
139 This may be followed by a breakpoint or a dead loop.
140
141 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
142 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
143 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
144 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
145 CpuDeadLoop() is called. If neither of these bits are set, then this function
146 returns immediately after the message is printed to the debug output device.
147 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
148 processing another DebugAssert(), then DebugAssert() must return immediately.
149
150 If FileName is NULL, then a <FileName> string of ?NULL) Filename?is printed.
151
152 If Description is NULL, then a <Description> string of ?NULL) Description?is printed.
153
154 @param FileName Pointer to the name of the source file that generated the assert condition.
155 @param LineNumber The line number in the source file that generated the assert condition
156 @param Description Pointer to the description of the assert condition.
157
158 **/
159 VOID
160 EFIAPI
161 DebugAssert (
162 IN CONST CHAR8 *FileName,
163 IN UINTN LineNumber,
164 IN CONST CHAR8 *Description
165 );
166
167
168 /**
169
170 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
171
172 This function fills Length bytes of Buffer with the value specified by
173 PcdDebugClearMemoryValue, and returns Buffer.
174
175 If Buffer is NULL, then ASSERT().
176
177 If Length is greater than (MAX_ADDRESS ?Buffer + 1), then ASSERT().
178
179 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
180 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
181
182 @return Buffer
183
184 **/
185 VOID *
186 EFIAPI
187 DebugClearMemory (
188 OUT VOID *Buffer,
189 IN UINTN Length
190 );
191
192
193 /**
194
195 Internal worker macro that calls DebugAssert().
196
197 This macro calls DebugAssert() passing in the filename, line number, and
198 expression that evailated to FALSE.
199
200 @param Expression Boolean expression that evailated to FALSE
201
202 **/
203 #ifdef EFI_DEBUG
204 #define _ASSERT(Expression) DebugAssert (__FILE__, __LINE__, #Expression)
205 #else
206 #define _ASSERT(Expression)
207
208 #endif
209
210 /**
211
212 Internal worker macro that calls DebugPrint().
213
214 This macro calls DebugPrint() passing in the debug error level, a format
215 string, and a variable argument list.
216
217 @param Expression Expression containing an error level, a format string,
218 and a variable argument list based on the format string.
219
220 **/
221 #ifdef EFI_DEBUG
222 /*
223 EdkCompatibilityPkg\Foundation\Include\EfiDebug.h
224 //
225 // DEBUG((DebugLevel, "format string", ...)) - if DebugLevel is active do
226 // the a debug print.
227 //
228 #define DEBUG(arg) EfiDebugPrint arg
229
230 To pass ICC build, undef the previously defined _DEBUG.
231 */
232 #undef _DEBUG
233 #define _DEBUG(Expression) DebugPrint Expression
234 #else
235 #define _DEBUG(Expression)
236
237 #endif
238
239 /**
240
241 Macro that calls DebugAssert() if a expression evaluates to FALSE.
242
243 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
244 then this macro evaluates the Boolean expression specified by Expression. If
245 Expression evaluates to FALSE, then DebugAssert() is called passing in the
246 source filename, source line number, and Expression.
247
248 @param Expression Boolean expression
249
250 **/
251 #ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION
252 // Glue Library internal
253
254 #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE
255 #ifdef EFI_DEBUG
256 #define ASSERT(Expression) \
257 do { \
258 if (DebugAssertEnabled ()) { \
259 if (!(Expression)) { \
260 _ASSERT (Expression); \
261 } \
262 } \
263 } while (FALSE)
264 #endif
265 #else
266 #define ASSERT(Expression) do{} while(0)
267 #endif
268
269 #else
270 // External usage
271
272 #ifdef EFI_DEBUG
273 #define ASSERT(Expression) \
274 do { \
275 if (DebugAssertEnabled ()) { \
276 if (!(Expression)) { \
277 _ASSERT (Expression); \
278 } \
279 } \
280 } while (FALSE)
281 #else
282 #define ASSERT(Expression) do{} while(0)
283 #endif
284
285 #endif
286
287 /**
288
289 Macro that calls DebugPrint().
290
291 If the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set,
292 then this macro passes Expression to DebugPrint().
293
294 @param Expression Expression containing an error level, a format string,
295 and a variable argument list based on the format string.
296
297
298 **/
299 #ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION
300 // Glue Library internal
301
302 #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE
303 #ifdef EFI_DEBUG
304 #define DEBUG(Expression) \
305 do { \
306 if (DebugPrintEnabled ()) { \
307 _DEBUG (Expression); \
308 } \
309 } while (FALSE)
310 #endif
311 #else
312 #define DEBUG(Expression) do{} while(0)
313 #endif
314
315 #else
316 // External usage
317
318 #ifdef EFI_DEBUG
319 #define DEBUG(Expression) \
320 do { \
321 if (DebugPrintEnabled ()) { \
322 _DEBUG (Expression); \
323 } \
324 } while (FALSE)
325 #else
326 #define DEBUG(Expression) do{} while(0)
327 #endif
328
329 #endif
330
331
332 /**
333
334 Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.
335
336 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
337 then this macro evaluates the EFI_STATUS value specified by StatusParameter.
338 If StatusParameter is an error code, then DebugAssert() is called passing in
339 the source filename, source line number, and StatusParameter.
340
341 @param StatusParameter EFI_STATUS value to evaluate.
342
343 **/
344 #ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION
345 // Glue Library internal
346
347 #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE
348 #ifdef EFI_DEBUG
349 #define ASSERT_EFI_ERROR(StatusParameter) \
350 do { \
351 if (DebugAssertEnabled ()) { \
352 if (EFI_ERROR (StatusParameter)) { \
353 DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
354 _ASSERT (!EFI_ERROR (StatusParameter)); \
355 } \
356 } \
357 } while (FALSE)
358 #endif
359 #else
360 #define ASSERT_EFI_ERROR(Expression) do{} while(0)
361 #endif
362
363 #else
364 // External usage
365
366 #ifdef EFI_DEBUG
367 #define ASSERT_EFI_ERROR(StatusParameter) \
368 do { \
369 if (DebugAssertEnabled ()) { \
370 if (EFI_ERROR (StatusParameter)) { \
371 DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
372 _ASSERT (!EFI_ERROR (StatusParameter)); \
373 } \
374 } \
375 } while (FALSE)
376 #else
377 #define ASSERT_EFI_ERROR(Expression) do{} while(0)
378 #endif
379
380 #endif
381
382
383 /**
384
385 Macro that calls DebugAssert() if a protocol is already installed in the
386 handle database.
387
388 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear,
389 then return.
390
391 If Handle is NULL, then a check is made to see if the protocol specified by Guid
392 is present on any handle in the handle database. If Handle is not NULL, then
393 a check is made to see if the protocol specified by Guid is present on the
394 handle specified by Handle. If the check finds the protocol, then DebugAssert()
395 is called passing in the source filename, source line number, and Guid.
396
397 If Guid is NULL, then ASSERT().
398
399 @param Handle The handle to check for the protocol. This is an optional
400 parameter that may be NULL. If it is NULL, then the entire
401 handle database is searched.
402
403 @param Guid Pointer to a protocol GUID.
404
405 **/
406 #ifdef EFI_DEBUG
407 #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
408 do { \
409 if (DebugAssertEnabled ()) { \
410 VOID *Instance; \
411 ASSERT (Guid != NULL); \
412 if (Handle == NULL) { \
413 if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \
414 _ASSERT (Guid already installed in database); \
415 } \
416 } else { \
417 if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \
418 _ASSERT (Guid already installed on Handle); \
419 } \
420 } \
421 } \
422 } while (FALSE)
423 #else
424 #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
425 do {} while(0);
426 #endif
427
428
429 /**
430 Macro that marks the beginning of debug source code.
431
432 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
433 then this macro marks the beginning of source code that is included in a module.
434 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()
435 are not included in a module.
436
437 **/
438 #define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal
439
440
441 /**
442
443 Macro that marks the end of debug source code.
444
445 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
446 then this macro marks the end of source code that is included in a module.
447 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()
448 are not included in a module.
449
450 **/
451 #define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)
452
453
454 /**
455
456 Macro that declares a section of debug source code.
457
458 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
459 then the source code specified by Expression is included in a module.
460 Otherwise, the source specified by Expression is not included in a module.
461
462 **/
463 #define DEBUG_CODE(Expression) \
464 DEBUG_CODE_BEGIN (); \
465 Expression \
466 DEBUG_CODE_END ()
467
468
469 /**
470
471 Macro that calls DebugClearMemory() to clear a buffer to a default value.
472
473 If the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set,
474 then this macro calls DebugClearMemory() passing in Address and Length.
475
476 @param Address Pointer to a buffer.
477 @param Length The number of bytes in the buffer to set.
478
479 **/
480 #define DEBUG_CLEAR_MEMORY(Address, Length) \
481 do { \
482 if (DebugClearMemoryEnabled ()) { \
483 DebugClearMemory (Address, Length); \
484 } \
485 } while (FALSE)
486
487
488 /**
489
490 Macro that calls DebugAssert() if the containing record does not have a
491 matching signature. If the signatures matches, then a pointer to the data
492 structure that contains a specified field of that data structure is returned.
493 This is a light weight method hide information by placing a public data
494 structure inside a larger private data structure and using a pointer to the
495 public data structure to retrieve a pointer to the private data structure.
496
497 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear,
498 then this macro computes the offset, in bytes, of field specified by Field
499 from the beginning of the data structure specified by TYPE. This offset is
500 subtracted from Record, and is used to return a pointer to a data structure
501 of the type specified by TYPE.
502
503 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
504 then this macro computes the offset, in bytes, of field specified by Field from
505 the beginning of the data structure specified by TYPE. This offset is
506 subtracted from Record, and is used to compute a pointer to a data structure of
507 the type specified by TYPE. The Signature field of the data structure specified
508 by TYPE is compared to TestSignature. If the signatures match, then a pointer
509 to the pointer to a data structure of the type specified by TYPE is returned.
510 If the signatures do not match, then DebugAssert() is called with a description
511 of "CR has a bad signature" and Record is returned.
512
513 If the data type specified by TYPE does not contain the field specified by Field,
514 then the module will not compile.
515
516 If TYPE does not contain a field called Signature, then the module will not
517 compile.
518
519 @param Record Pointer to the field specified by Field within a data
520 structure of type TYPE.
521
522 @param TYPE The name of the data structure type to return This
523 data structure must contain the field specified by Field.
524
525 @param Field The name of the field in the data structure specified
526 by TYPE to which Record points.
527
528 @param TestSignature The 32-bit signature value to match.
529
530 **/
531 #ifdef EFI_DEBUG
532 #define CR(Record, TYPE, Field, TestSignature) \
533 (DebugAssertEnabled () && (_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
534 (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
535 _CR (Record, TYPE, Field)
536 #else
537 #define CR(Record, TYPE, Field, TestSignature) \
538 _CR (Record, TYPE, Field)
539 #endif
540
541
542 #endif