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