]>
Commit | Line | Data |
---|---|---|
b90aefa9 | 1 | /** @file\r |
2 | Base Debug library instance for QEMU debug port.\r | |
3 | It uses PrintLib to send debug messages to a fixed I/O port.\r | |
4 | \r | |
5e795f93 | 5 | Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r |
b90aefa9 | 6 | Copyright (c) 2012, Red Hat, Inc.<BR>\r |
7 | This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php.\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include <Base.h>\r | |
18 | #include <Uefi.h>\r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/BaseLib.h>\r | |
21 | #include <Library/IoLib.h>\r | |
22 | #include <Library/PrintLib.h>\r | |
23 | #include <Library/PcdLib.h>\r | |
24 | #include <Library/BaseMemoryLib.h>\r | |
25 | #include <Library/DebugPrintErrorLevelLib.h>\r | |
26 | \r | |
27 | //\r | |
28 | // Define the maximum debug and assert message length that this library supports\r | |
29 | //\r | |
30 | #define MAX_DEBUG_MESSAGE_LENGTH 0x100\r | |
31 | \r | |
32 | /**\r | |
33 | This constructor function does not have to do anything.\r | |
34 | \r | |
35 | @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r | |
36 | \r | |
37 | **/\r | |
38 | RETURN_STATUS\r | |
39 | EFIAPI\r | |
40 | PlatformDebugLibIoPortConstructor (\r | |
41 | VOID\r | |
42 | )\r | |
43 | {\r | |
44 | return EFI_SUCCESS;\r | |
45 | }\r | |
46 | \r | |
47 | /**\r | |
48 | Prints a debug message to the debug output device if the specified error level is enabled.\r | |
49 | \r | |
50 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
51 | GetDebugPrintErrorLevel (), then print the message specified by Format and the\r | |
52 | associated variable argument list to the debug output device.\r | |
53 | \r | |
54 | If Format is NULL, then ASSERT().\r | |
55 | \r | |
56 | @param ErrorLevel The error level of the debug message.\r | |
57 | @param Format Format string for the debug message to print.\r | |
58 | @param ... Variable argument list whose contents are accessed\r | |
59 | based on the format string specified by Format.\r | |
60 | \r | |
61 | **/\r | |
62 | VOID\r | |
63 | EFIAPI\r | |
64 | DebugPrint (\r | |
65 | IN UINTN ErrorLevel,\r | |
66 | IN CONST CHAR8 *Format,\r | |
67 | ...\r | |
68 | )\r | |
69 | {\r | |
70 | CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r | |
71 | VA_LIST Marker;\r | |
72 | UINT8 *Ptr;\r | |
73 | \r | |
74 | //\r | |
75 | // If Format is NULL, then ASSERT().\r | |
76 | //\r | |
77 | ASSERT (Format != NULL);\r | |
78 | \r | |
79 | //\r | |
80 | // Check driver debug mask value and global mask\r | |
81 | //\r | |
82 | if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {\r | |
83 | return;\r | |
84 | }\r | |
85 | \r | |
86 | //\r | |
87 | // Convert the DEBUG() message to an ASCII String\r | |
88 | //\r | |
89 | VA_START (Marker, Format);\r | |
90 | AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r | |
91 | VA_END (Marker);\r | |
92 | \r | |
93 | //\r | |
94 | // Send the print string to the debug I/O port\r | |
95 | //\r | |
96 | for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) {\r | |
97 | IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr);\r | |
98 | }\r | |
99 | }\r | |
100 | \r | |
101 | \r | |
102 | /**\r | |
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 | |
106 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r | |
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 | |
112 | DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r | |
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 | |
116 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r | |
117 | \r | |
118 | @param FileName The pointer to the name of the source file that generated the assert condition.\r | |
119 | @param LineNumber The line number in the source file that generated the assert condition\r | |
120 | @param Description The pointer to the description of the assert condition.\r | |
121 | \r | |
122 | **/\r | |
123 | VOID\r | |
124 | EFIAPI\r | |
125 | DebugAssert (\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 | UINT8 *Ptr;\r | |
133 | \r | |
134 | //\r | |
135 | // Generate the ASSERT() message in Ascii format\r | |
136 | //\r | |
3d8ac52a LE |
137 | AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n", FileName,\r |
138 | (UINT64)LineNumber, Description);\r | |
b90aefa9 | 139 | \r |
140 | //\r | |
141 | // Send the print string to the Console Output device\r | |
142 | //\r | |
143 | for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) {\r | |
144 | IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr);\r | |
145 | }\r | |
146 | \r | |
147 | //\r | |
148 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r | |
149 | //\r | |
150 | if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r | |
151 | CpuBreakpoint ();\r | |
152 | } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r | |
153 | CpuDeadLoop ();\r | |
154 | }\r | |
155 | }\r | |
156 | \r | |
157 | \r | |
158 | /**\r | |
159 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r | |
160 | \r | |
161 | This function fills Length bytes of Buffer with the value specified by\r | |
162 | PcdDebugClearMemoryValue, and returns Buffer.\r | |
163 | \r | |
164 | If Buffer is NULL, then ASSERT().\r | |
165 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
166 | \r | |
167 | @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r | |
168 | @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r | |
169 | \r | |
170 | @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.\r | |
171 | \r | |
172 | **/\r | |
173 | VOID *\r | |
174 | EFIAPI\r | |
175 | DebugClearMemory (\r | |
176 | OUT VOID *Buffer,\r | |
177 | IN UINTN Length\r | |
178 | )\r | |
179 | {\r | |
180 | //\r | |
181 | // If Buffer is NULL, then ASSERT().\r | |
182 | //\r | |
183 | ASSERT (Buffer != NULL);\r | |
184 | \r | |
185 | //\r | |
186 | // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r | |
187 | //\r | |
188 | return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r | |
189 | }\r | |
190 | \r | |
191 | \r | |
192 | /**\r | |
193 | Returns TRUE if ASSERT() macros are enabled.\r | |
194 | \r | |
195 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r | |
196 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
197 | \r | |
198 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r | |
199 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
200 | \r | |
201 | **/\r | |
202 | BOOLEAN\r | |
203 | EFIAPI\r | |
204 | DebugAssertEnabled (\r | |
205 | VOID\r | |
206 | )\r | |
207 | {\r | |
208 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r | |
209 | }\r | |
210 | \r | |
211 | \r | |
212 | /**\r | |
213 | Returns TRUE if DEBUG() macros are enabled.\r | |
214 | \r | |
215 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r | |
216 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
217 | \r | |
218 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r | |
219 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
220 | \r | |
221 | **/\r | |
222 | BOOLEAN\r | |
223 | EFIAPI\r | |
224 | DebugPrintEnabled (\r | |
225 | VOID\r | |
226 | )\r | |
227 | {\r | |
228 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r | |
229 | }\r | |
230 | \r | |
231 | \r | |
232 | /**\r | |
233 | Returns TRUE if DEBUG_CODE() macros are enabled.\r | |
234 | \r | |
235 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r | |
236 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
237 | \r | |
238 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r | |
239 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r | |
240 | \r | |
241 | **/\r | |
242 | BOOLEAN\r | |
243 | EFIAPI\r | |
244 | DebugCodeEnabled (\r | |
245 | VOID\r | |
246 | )\r | |
247 | {\r | |
248 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r | |
249 | }\r | |
250 | \r | |
251 | \r | |
252 | /**\r | |
253 | Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r | |
254 | \r | |
255 | This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of\r | |
256 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
257 | \r | |
258 | @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r | |
259 | @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r | |
260 | \r | |
261 | **/\r | |
262 | BOOLEAN\r | |
263 | EFIAPI\r | |
264 | DebugClearMemoryEnabled (\r | |
265 | VOID\r | |
266 | )\r | |
267 | {\r | |
268 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r | |
269 | }\r | |
270 | \r | |
5e795f93 LG |
271 | /**\r |
272 | Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
273 | \r | |
274 | This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
275 | \r | |
276 | @retval TRUE Current ErrorLevel is supported.\r | |
277 | @retval FALSE Current ErrorLevel is not supported.\r | |
278 | \r | |
279 | **/\r | |
280 | BOOLEAN\r | |
281 | EFIAPI\r | |
282 | DebugPrintLevelEnabled (\r | |
283 | IN CONST UINTN ErrorLevel\r | |
284 | )\r | |
285 | {\r | |
286 | return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);\r | |
287 | }\r |