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