]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
Fix VS2013 build failure.
[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
5 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
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
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
123VOID\r
124EFIAPI\r
125DebugAssert (\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
137 AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT %a(%d): %a\n", FileName, LineNumber, Description);\r
138\r
139 //\r
140 // Send the print string to the Console Output device\r
141 //\r
142 for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) {\r
143 IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr);\r
144 }\r
145\r
146 //\r
147 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
148 //\r
149 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
150 CpuBreakpoint ();\r
151 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
152 CpuDeadLoop ();\r
153 }\r
154}\r
155\r
156\r
157/**\r
158 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
159\r
160 This function fills Length bytes of Buffer with the value specified by\r
161 PcdDebugClearMemoryValue, and returns Buffer.\r
162\r
163 If Buffer is NULL, then ASSERT().\r
164 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
165\r
166 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r
167 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r
168\r
169 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.\r
170\r
171**/\r
172VOID *\r
173EFIAPI\r
174DebugClearMemory (\r
175 OUT VOID *Buffer,\r
176 IN UINTN Length\r
177 )\r
178{\r
179 //\r
180 // If Buffer is NULL, then ASSERT().\r
181 //\r
182 ASSERT (Buffer != NULL);\r
183\r
184 //\r
185 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
186 //\r
187 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
188}\r
189\r
190\r
191/**\r
192 Returns TRUE if ASSERT() macros are enabled.\r
193\r
194 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r
195 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
196\r
197 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
198 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
199\r
200**/\r
201BOOLEAN\r
202EFIAPI\r
203DebugAssertEnabled (\r
204 VOID\r
205 )\r
206{\r
207 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
208}\r
209\r
210\r
211/**\r
212 Returns TRUE if DEBUG() macros are enabled.\r
213\r
214 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r
215 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
216\r
217 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
218 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
219\r
220**/\r
221BOOLEAN\r
222EFIAPI\r
223DebugPrintEnabled (\r
224 VOID\r
225 )\r
226{\r
227 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
228}\r
229\r
230\r
231/**\r
232 Returns TRUE if DEBUG_CODE() macros are enabled.\r
233\r
234 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r
235 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
236\r
237 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
238 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
239\r
240**/\r
241BOOLEAN\r
242EFIAPI\r
243DebugCodeEnabled (\r
244 VOID\r
245 )\r
246{\r
247 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
248}\r
249\r
250\r
251/**\r
252 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
253\r
254 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of\r
255 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
256\r
257 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
258 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
259\r
260**/\r
261BOOLEAN\r
262EFIAPI\r
263DebugClearMemoryEnabled (\r
264 VOID\r
265 )\r
266{\r
267 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
268}\r
269\r