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