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