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