]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c
Update BASE_NAME to match the file names of the shell binaries so the INF files can...
[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
7bc232b2 4\r
1815f5bb
HT
5 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
6 This program and the accompanying materials \r
7bc232b2
LG
7 are licensed and made available under the terms and conditions of the BSD License \r
8 which accompanies this distribution. The full text of the license may be found at \r
35a17154 9 http://opensource.org/licenses/bsd-license.php. \r
7bc232b2
LG
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
13\r
14**/\r
15\r
0eeb6d1f 16#include <Base.h>\r
859b72fa
A
17#include <Library/DebugLib.h>\r
18#include <Library/BaseLib.h>\r
19#include <Library/PrintLib.h>\r
20#include <Library/PcdLib.h>\r
21#include <Library/BaseMemoryLib.h>\r
22#include <Library/SerialPortLib.h>\r
23\r
7bc232b2
LG
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
7bc232b2 29/**\r
7bc232b2
LG
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
7bc232b2
LG
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 CHAR8 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 an ASCII String\r
69 //\r
70 VA_START (Marker, Format);\r
71 AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
72 VA_END (Marker);\r
73\r
74 //\r
75 // Send the print string to a Serial Port \r
76 //\r
77 SerialPortWrite ((UINT8 *) Buffer, AsciiStrLen(Buffer));\r
78}\r
79\r
80\r
81/**\r
7bc232b2
LG
82 Prints an assert message containing a filename, line number, and description. \r
83 This may be followed by a breakpoint or a dead loop.\r
84\r
3e5c3238 85 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r
7bc232b2
LG
86 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
87 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
88 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
89 CpuDeadLoop() is called. If neither of these bits are set, then this function \r
90 returns immediately after the message is printed to the debug output device.\r
3e5c3238 91 DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r
7bc232b2
LG
92 processing another DebugAssert(), then DebugAssert() must return immediately.\r
93\r
94 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
7bc232b2
LG
95 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
96\r
97 @param FileName Pointer to the name of the source file that generated the assert condition.\r
98 @param LineNumber The line number in the source file that generated the assert condition\r
99 @param Description Pointer to the description of the assert condition.\r
100\r
101**/\r
102VOID\r
103EFIAPI\r
104DebugAssert (\r
105 IN CONST CHAR8 *FileName,\r
106 IN UINTN LineNumber,\r
107 IN CONST CHAR8 *Description\r
108 )\r
109{\r
110 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
111\r
112 //\r
7c366ec9 113 // Generate the ASSERT() message in Ascii format\r
7bc232b2
LG
114 //\r
115 AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT %a(%d): %a\n", FileName, LineNumber, Description);\r
116\r
117 //\r
118 // Send the print string to the Console Output device\r
119 //\r
120 SerialPortWrite ((UINT8 *) Buffer, AsciiStrLen(Buffer));\r
121\r
122 //\r
123 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
124 //\r
125 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
126 CpuBreakpoint ();\r
127 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
128 CpuDeadLoop ();\r
129 }\r
130}\r
131\r
132\r
133/**\r
7bc232b2
LG
134 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
135\r
136 This function fills Length bytes of Buffer with the value specified by \r
137 PcdDebugClearMemoryValue, and returns Buffer.\r
138\r
139 If Buffer is NULL, then ASSERT().\r
efb23117 140 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
7bc232b2 141\r
eceb3a4c 142 @param Buffer Pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r
7bc232b2
LG
143 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
144\r
3e5c3238 145 @return Buffer Pointer to the target buffer filled with PcdDebugClearMemoryValue.\r
7bc232b2
LG
146\r
147**/\r
148VOID *\r
149EFIAPI\r
150DebugClearMemory (\r
151 OUT VOID *Buffer,\r
152 IN UINTN Length\r
153 )\r
154{\r
155 //\r
156 // If Buffer is NULL, then ASSERT().\r
157 //\r
158 ASSERT (Buffer != NULL);\r
159\r
160 //\r
161 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
162 //\r
163 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
164}\r
165\r
166\r
167/**\r
7bc232b2
LG
168 Returns TRUE if ASSERT() macros are enabled.\r
169\r
170 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
171 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
172\r
173 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
174 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
175\r
176**/\r
177BOOLEAN\r
178EFIAPI\r
179DebugAssertEnabled (\r
180 VOID\r
181 )\r
182{\r
183 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
184}\r
185\r
186\r
3e5c3238 187/** \r
188 Returns TRUE if DEBUG() macros are enabled.\r
7bc232b2
LG
189\r
190 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
191 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
192\r
193 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
194 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
195\r
196**/\r
197BOOLEAN\r
198EFIAPI\r
199DebugPrintEnabled (\r
200 VOID\r
201 )\r
202{\r
203 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
204}\r
205\r
206\r
3e5c3238 207/** \r
208 Returns TRUE if DEBUG_CODE() macros are enabled.\r
7bc232b2
LG
209\r
210 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
211 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
212\r
213 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
214 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
215\r
216**/\r
217BOOLEAN\r
218EFIAPI\r
219DebugCodeEnabled (\r
220 VOID\r
221 )\r
222{\r
223 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
224}\r
225\r
226\r
3e5c3238 227/** \r
228 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
7bc232b2 229\r
eceb3a4c 230 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of \r
7bc232b2
LG
231 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
232\r
eceb3a4c
LG
233 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
234 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
7bc232b2
LG
235\r
236**/\r
237BOOLEAN\r
238EFIAPI\r
239DebugClearMemoryEnabled (\r
240 VOID\r
241 )\r
242{\r
243 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
244}\r