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