]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDebugLibConOut/DebugLib.c
Update the copyright notice format
[mirror_edk2.git] / MdePkg / Library / UefiDebugLibConOut / DebugLib.c
CommitLineData
e386b444 1/** @file\r
eceb3a4c 2 UEFI Debug Library that sends messages to the Console Output Device in the EFI System Table.\r
e386b444 3\r
19388d29
HT
4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials \r
e386b444 6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php \r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13**/\r
14\r
c7d265a9 15#include <Uefi.h>\r
c892d846 16\r
c7d265a9 17#include <Library/DebugLib.h>\r
18#include <Library/UefiBootServicesTableLib.h>\r
19#include <Library/PrintLib.h>\r
20#include <Library/PcdLib.h>\r
21#include <Library/BaseLib.h>\r
22#include <Library/BaseMemoryLib.h>\r
23\r
e386b444 24//\r
25// Define the maximum debug and assert message length that this library supports \r
26//\r
27#define MAX_DEBUG_MESSAGE_LENGTH 0x100\r
28\r
e386b444 29/**\r
e386b444 30 Prints a debug message to the debug output device if the specified error level is enabled.\r
31\r
32 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
33 the message specified by Format and the associated variable argument list to \r
34 the debug output device.\r
35\r
36 If Format is NULL, then ASSERT().\r
37\r
38 @param ErrorLevel The error level of the debug message.\r
39 @param Format Format string for the debug message to print.\r
285010e7 40 @param ... Variable argument list whose contents are accessed \r
41 based on the format string specified by Format.\r
e386b444 42\r
43**/\r
44VOID\r
45EFIAPI\r
46DebugPrint (\r
47 IN UINTN ErrorLevel,\r
48 IN CONST CHAR8 *Format,\r
49 ...\r
50 )\r
51{\r
52 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
53 VA_LIST Marker;\r
54\r
55 //\r
56 // If Format is NULL, then ASSERT().\r
57 //\r
58 ASSERT (Format != NULL);\r
59\r
60 //\r
61 // Check driver debug mask value and global mask\r
62 //\r
63 if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r
64 return;\r
65 }\r
66\r
67 //\r
68 // Convert the DEBUG() message to a Unicode String\r
69 //\r
70 VA_START (Marker, Format);\r
7c6d32a5 71 UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, Marker);\r
e386b444 72 VA_END (Marker);\r
73\r
457cfbae 74\r
e386b444 75 //\r
76 // Send the print string to the Console Output device\r
77 //\r
78 if ((gST != NULL) && (gST->ConOut != NULL)) {\r
79 gST->ConOut->OutputString (gST->ConOut, Buffer);\r
80 }\r
81}\r
82\r
83\r
84/**\r
e386b444 85 Prints an assert message containing a filename, line number, and description. \r
86 This may be followed by a breakpoint or a dead loop.\r
87\r
3e5c3238 88 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r
e386b444 89 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
90 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
91 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
92 CpuDeadLoop() is called. If neither of these bits are set, then this function \r
93 returns immediately after the message is printed to the debug output device.\r
3e5c3238 94 DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r
e386b444 95 processing another DebugAssert(), then DebugAssert() must return immediately.\r
96\r
97 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
e386b444 98 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
99\r
100 @param FileName Pointer to the name of the source file that generated the assert condition.\r
101 @param LineNumber The line number in the source file that generated the assert condition\r
102 @param Description Pointer to the description of the assert condition.\r
103\r
104**/\r
105VOID\r
106EFIAPI\r
107DebugAssert (\r
108 IN CONST CHAR8 *FileName,\r
109 IN UINTN LineNumber,\r
110 IN CONST CHAR8 *Description\r
111 )\r
112{\r
113 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
114\r
115 //\r
116 // Generate the ASSERT() message in Unicode format\r
117 //\r
7c6d32a5 118 UnicodeSPrintAsciiFormat (\r
119 Buffer, \r
120 MAX_DEBUG_MESSAGE_LENGTH, \r
121 "ASSERT %a(%d): %a\n", \r
122 FileName, \r
123 LineNumber, \r
124 Description\r
125 );\r
126 \r
e386b444 127 //\r
128 // Send the print string to the Console Output device\r
129 //\r
130 if ((gST != NULL) && (gST->ConOut != NULL)) {\r
131 gST->ConOut->OutputString (gST->ConOut, Buffer);\r
132 }\r
133\r
134 //\r
135 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
136 //\r
137 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
138 CpuBreakpoint ();\r
139 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
140 CpuDeadLoop ();\r
141 }\r
142}\r
143\r
144\r
145/**\r
e386b444 146 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
147\r
148 This function fills Length bytes of Buffer with the value specified by \r
149 PcdDebugClearMemoryValue, and returns Buffer.\r
150\r
151 If Buffer is NULL, then ASSERT().\r
4ef55dfc 152 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
e386b444 153\r
eceb3a4c 154 @param Buffer Pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r
e386b444 155 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
156\r
eceb3a4c 157 @return Buffer Pointer to the target buffer filled with PcdDebugClearMemoryValue.\r
e386b444 158\r
159**/\r
160VOID *\r
161EFIAPI\r
162DebugClearMemory (\r
163 OUT VOID *Buffer,\r
164 IN UINTN Length\r
165 )\r
166{\r
167 //\r
168 // If Buffer is NULL, then ASSERT().\r
169 //\r
170 ASSERT (Buffer != NULL);\r
171\r
172 //\r
173 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
174 //\r
175 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
176}\r
177\r
178\r
179/**\r
e386b444 180 Returns TRUE if ASSERT() macros are enabled.\r
181\r
182 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
183 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
184\r
185 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
186 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
187\r
188**/\r
189BOOLEAN\r
190EFIAPI\r
191DebugAssertEnabled (\r
192 VOID\r
193 )\r
194{\r
195 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
196}\r
197\r
198\r
3e5c3238 199/** \r
200 Returns TRUE if DEBUG() macros are enabled.\r
e386b444 201\r
202 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
203 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
204\r
205 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
206 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
207\r
208**/\r
209BOOLEAN\r
210EFIAPI\r
211DebugPrintEnabled (\r
212 VOID\r
213 )\r
214{\r
215 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
216}\r
217\r
218\r
3e5c3238 219/** \r
220 Returns TRUE if DEBUG_CODE() macros are enabled.\r
e386b444 221\r
222 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
223 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
224\r
225 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
226 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
227\r
228**/\r
229BOOLEAN\r
230EFIAPI\r
231DebugCodeEnabled (\r
232 VOID\r
233 )\r
234{\r
235 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
236}\r
237\r
238\r
3e5c3238 239/** \r
240 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
e386b444 241\r
eceb3a4c 242 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of \r
e386b444 243 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
244\r
eceb3a4c
LG
245 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
246 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
e386b444 247\r
248**/\r
249BOOLEAN\r
250EFIAPI\r
251DebugClearMemoryEnabled (\r
252 VOID\r
253 )\r
254{\r
255 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
256}\r