]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDebugLibConOut/DebugLib.c
remove some comments introduced by tools.
[mirror_edk2.git] / MdePkg / Library / UefiDebugLibConOut / DebugLib.c
CommitLineData
e386b444 1/** @file\r
2 UEFI Debug Library that uses PrintLib to send messages to CONOUT.\r
3\r
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials \r
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
c892d846 15\r
c7d265a9 16#include <Uefi.h>\r
c892d846 17\r
18\r
c7d265a9 19#include <Library/DebugLib.h>\r
20#include <Library/UefiBootServicesTableLib.h>\r
21#include <Library/PrintLib.h>\r
22#include <Library/PcdLib.h>\r
23#include <Library/BaseLib.h>\r
24#include <Library/BaseMemoryLib.h>\r
25\r
e386b444 26\r
27//\r
28// Define the maximum debug and assert message length that this library supports \r
29//\r
30#define MAX_DEBUG_MESSAGE_LENGTH 0x100\r
31\r
32\r
33/**\r
34\r
35 Prints a debug message to the debug output device if the specified error level is enabled.\r
36\r
37 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
38 the message specified by Format and the associated variable argument list to \r
39 the debug output device.\r
40\r
41 If Format is NULL, then ASSERT().\r
42\r
43 @param ErrorLevel The error level of the debug message.\r
44 @param Format Format string for the debug message to print.\r
45\r
46**/\r
47VOID\r
48EFIAPI\r
49DebugPrint (\r
50 IN UINTN ErrorLevel,\r
51 IN CONST CHAR8 *Format,\r
52 ...\r
53 )\r
54{\r
55 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
56 VA_LIST Marker;\r
57\r
58 //\r
59 // If Format is NULL, then ASSERT().\r
60 //\r
61 ASSERT (Format != NULL);\r
62\r
63 //\r
64 // Check driver debug mask value and global mask\r
65 //\r
66 if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r
67 return;\r
68 }\r
69\r
70 //\r
71 // Convert the DEBUG() message to a Unicode String\r
72 //\r
73 VA_START (Marker, Format);\r
74 UnicodeVSPrintAsciiFormat (Buffer, sizeof (Buffer), Format, Marker);\r
75 VA_END (Marker);\r
76\r
77 //\r
78 // Send the print string to the Console Output device\r
79 //\r
80 if ((gST != NULL) && (gST->ConOut != NULL)) {\r
81 gST->ConOut->OutputString (gST->ConOut, Buffer);\r
82 }\r
83}\r
84\r
85\r
86/**\r
87\r
88 Prints an assert message containing a filename, line number, and description. \r
89 This may be followed by a breakpoint or a dead loop.\r
90\r
91 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n" \r
92 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
93 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
94 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
95 CpuDeadLoop() is called. If neither of these bits are set, then this function \r
96 returns immediately after the message is printed to the debug output device.\r
97 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while\r
98 processing another DebugAssert(), then DebugAssert() must return immediately.\r
99\r
100 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
101\r
102 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
103\r
104 @param FileName Pointer to the name of the source file that generated the assert condition.\r
105 @param LineNumber The line number in the source file that generated the assert condition\r
106 @param Description Pointer to the description of the assert condition.\r
107\r
108**/\r
109VOID\r
110EFIAPI\r
111DebugAssert (\r
112 IN CONST CHAR8 *FileName,\r
113 IN UINTN LineNumber,\r
114 IN CONST CHAR8 *Description\r
115 )\r
116{\r
117 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
118\r
119 //\r
120 // Generate the ASSERT() message in Unicode format\r
121 //\r
122 UnicodeSPrintAsciiFormat (Buffer, sizeof (Buffer), "ASSERT %s(%d): %s\n", FileName, LineNumber, Description);\r
123\r
124 //\r
125 // Send the print string to the Console Output device\r
126 //\r
127 if ((gST != NULL) && (gST->ConOut != NULL)) {\r
128 gST->ConOut->OutputString (gST->ConOut, Buffer);\r
129 }\r
130\r
131 //\r
132 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
133 //\r
134 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
135 CpuBreakpoint ();\r
136 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
137 CpuDeadLoop ();\r
138 }\r
139}\r
140\r
141\r
142/**\r
143\r
144 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
145\r
146 This function fills Length bytes of Buffer with the value specified by \r
147 PcdDebugClearMemoryValue, and returns Buffer.\r
148\r
149 If Buffer is NULL, then ASSERT().\r
150\r
151 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
152\r
153 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
154 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
155\r
156 @return Buffer\r
157\r
158**/\r
159VOID *\r
160EFIAPI\r
161DebugClearMemory (\r
162 OUT VOID *Buffer,\r
163 IN UINTN Length\r
164 )\r
165{\r
166 //\r
167 // If Buffer is NULL, then ASSERT().\r
168 //\r
169 ASSERT (Buffer != NULL);\r
170\r
171 //\r
172 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
173 //\r
174 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
175}\r
176\r
177\r
178/**\r
179 \r
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
199/**\r
200 \r
201 Returns TRUE if DEBUG()macros are enabled.\r
202\r
203 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
204 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
205\r
206 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
207 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
208\r
209**/\r
210BOOLEAN\r
211EFIAPI\r
212DebugPrintEnabled (\r
213 VOID\r
214 )\r
215{\r
216 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
217}\r
218\r
219\r
220/**\r
221 \r
222 Returns TRUE if DEBUG_CODE()macros are enabled.\r
223\r
224 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
225 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
226\r
227 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
228 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
229\r
230**/\r
231BOOLEAN\r
232EFIAPI\r
233DebugCodeEnabled (\r
234 VOID\r
235 )\r
236{\r
237 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
238}\r
239\r
240\r
241/**\r
242 \r
243 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r
244\r
245 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of \r
246 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
247\r
248 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
249 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
250\r
251**/\r
252BOOLEAN\r
253EFIAPI\r
254DebugClearMemoryEnabled (\r
255 VOID\r
256 )\r
257{\r
258 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
259}\r