]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
OvmfPkg/PlatformDebugLibIoPort: write messages with IoWriteFifo8()
[mirror_edk2.git] / OvmfPkg / Library / PlatformDebugLibIoPort / DebugLib.c
CommitLineData
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
38RETURN_STATUS\r
39EFIAPI\r
40PlatformDebugLibIoPortConstructor (\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
62VOID\r
63EFIAPI\r
64DebugPrint (\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
80886a69 72 UINTN Length;\r
b90aefa9 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
80886a69 90 Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
b90aefa9 91 VA_END (Marker);\r
92\r
93 //\r
94 // Send the print string to the debug I/O port\r
95 //\r
80886a69 96 IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r
b90aefa9 97}\r
98\r
99\r
100/**\r
101 Prints an assert message containing a filename, line number, and description.\r
102 This may be followed by a breakpoint or a dead loop.\r
103\r
104 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r
105 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r
106 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r
107 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r
108 CpuDeadLoop() is called. If neither of these bits are set, then this function\r
109 returns immediately after the message is printed to the debug output device.\r
110 DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r
111 processing another DebugAssert(), then DebugAssert() must return immediately.\r
112\r
113 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
114 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
115\r
116 @param FileName The pointer to the name of the source file that generated the assert condition.\r
117 @param LineNumber The line number in the source file that generated the assert condition\r
118 @param Description The pointer to the description of the assert condition.\r
119\r
120**/\r
121VOID\r
122EFIAPI\r
123DebugAssert (\r
124 IN CONST CHAR8 *FileName,\r
125 IN UINTN LineNumber,\r
126 IN CONST CHAR8 *Description\r
127 )\r
128{\r
129 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
80886a69 130 UINTN Length;\r
b90aefa9 131\r
132 //\r
133 // Generate the ASSERT() message in Ascii format\r
134 //\r
80886a69
LE
135 Length = AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n",\r
136 FileName, (UINT64)LineNumber, Description);\r
b90aefa9 137\r
138 //\r
80886a69 139 // Send the print string to the debug I/O port\r
b90aefa9 140 //\r
80886a69 141 IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r
b90aefa9 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
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
161 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
162\r
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
165\r
166 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.\r
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
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
208/**\r
209 Returns TRUE if DEBUG() macros are enabled.\r
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
228/**\r
229 Returns TRUE if DEBUG_CODE() macros are enabled.\r
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
248/**\r
249 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
250\r
251 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of\r
252 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
253\r
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
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
266\r
5e795f93
LG
267/**\r
268 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.\r
269\r
270 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.\r
271\r
272 @retval TRUE Current ErrorLevel is supported.\r
273 @retval FALSE Current ErrorLevel is not supported.\r
274\r
275**/\r
276BOOLEAN\r
277EFIAPI\r
278DebugPrintLevelEnabled (\r
279 IN CONST UINTN ErrorLevel\r
280 )\r
281{\r
282 return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);\r
283}\r