]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
Enhance PciCfg2 driver to handle unaligned Pci access according to PI spec.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / PeiDxeDebugLibReportStatusCode / DebugLib.c
CommitLineData
2287f237 1/** @file\r
2 Debug Library that fowards all messages to ReportStatusCode()\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\r
17#include <FrameworkPei.h>\r
551ed06f 18#include <FrameworkModuleBase.h>\r
2287f237 19#include <Guid/StatusCodeDataTypeId.h>\r
20\r
21#include <Library/DebugLib.h>\r
22#include <Library/BaseLib.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/ReportStatusCodeLib.h>\r
25#include <Library/PcdLib.h>\r
26\r
27#include <DebugInfo.h>\r
28\r
29/**\r
30\r
31 Prints a debug message to the debug output device if the specified error level is enabled.\r
32\r
33 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print\r
34 the message specified by Format and the associated variable argument list to\r
35 the debug output device.\r
36\r
37 If Format is NULL, then ASSERT().\r
38\r
39 @param ErrorLevel The error level of the debug message.\r
40 @param Format Format string for the debug message to print.\r
967c09fa 41 @param ... Variable argument list whose contents are accessed \r
42 based on the format string specified by Format.\r
2287f237 43\r
44**/\r
45VOID\r
46EFIAPI\r
47DebugPrint (\r
48 IN UINTN ErrorLevel,\r
49 IN CONST CHAR8 *Format,\r
50 ...\r
51 )\r
52{\r
53 UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)];\r
54 EFI_DEBUG_INFO *DebugInfo;\r
55 UINTN TotalSize;\r
56 UINTN Index;\r
57 VA_LIST Marker;\r
58 UINT64 *ArgumentPointer;\r
59\r
60 //\r
61 // If Format is NULL, then ASSERT().\r
62 //\r
63 ASSERT (Format != NULL);\r
64\r
65 //\r
66 // Check driver Debug Level value and global debug level\r
67 //\r
68 if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r
69 return;\r
70 }\r
71\r
72 TotalSize = sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrLen (Format) + 1;\r
73 if (TotalSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r
74 return;\r
75 }\r
76\r
77 //\r
78 // Then EFI_DEBUG_INFO\r
79 //\r
80 DebugInfo = (EFI_DEBUG_INFO *)Buffer;\r
81 DebugInfo->ErrorLevel = (UINT32)ErrorLevel;\r
82\r
83 //\r
84 // 256 byte mini Var Arg stack. That is followed by the format string.\r
85 //\r
86 VA_START (Marker, Format);\r
87 for (Index = 0, ArgumentPointer = (UINT64 *)(DebugInfo + 1); Index < 12; Index++, ArgumentPointer++) {\r
88 WriteUnaligned64(ArgumentPointer, VA_ARG (Marker, UINT64));\r
89 }\r
90 VA_END (Marker);\r
91 AsciiStrCpy ((CHAR8 *)ArgumentPointer, Format);\r
92\r
93 REPORT_STATUS_CODE_EX (\r
94 EFI_DEBUG_CODE,\r
95 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED),\r
96 0,\r
97 NULL,\r
98 &gEfiStatusCodeDataTypeDebugGuid,\r
99 DebugInfo,\r
100 TotalSize\r
101 );\r
102}\r
103\r
104\r
105/**\r
106\r
107 Prints an assert message containing a filename, line number, and description.\r
108 This may be followed by a breakpoint or a dead loop.\r
109\r
110 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r
111 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r
112 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r
113 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r
114 CpuDeadLoop() is called. If neither of these bits are set, then this function\r
115 returns immediately after the message is printed to the debug output device.\r
584125bc 116 DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r
2287f237 117 processing another DebugAssert(), then DebugAssert() must return immediately.\r
118\r
119 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
120\r
121 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
122\r
123 @param FileName Pointer to the name of the source file that generated the assert condition.\r
124 @param LineNumber The line number in the source file that generated the assert condition\r
125 @param Description Pointer to the description of the assert condition.\r
126\r
127**/\r
128VOID\r
129EFIAPI\r
130DebugAssert (\r
131 IN CONST CHAR8 *FileName,\r
132 IN UINTN LineNumber,\r
133 IN CONST CHAR8 *Description\r
134 )\r
135{\r
136 UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)];\r
137 EFI_DEBUG_ASSERT_DATA *AssertData;\r
138 UINTN TotalSize;\r
139 CHAR8 *Temp;\r
140 UINTN FileNameLength;\r
141 UINTN DescriptionLength;\r
142\r
143 //\r
144 // Make sure it will all fit in the passed in buffer\r
145 //\r
146 FileNameLength = AsciiStrLen (FileName);\r
147 DescriptionLength = AsciiStrLen (Description);\r
148 TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + FileNameLength + 1 + DescriptionLength + 1;\r
149 if (TotalSize <= EFI_STATUS_CODE_DATA_MAX_SIZE) {\r
150 //\r
151 // Fill in EFI_DEBUG_ASSERT_DATA\r
152 //\r
153 AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;\r
154 AssertData->LineNumber = (UINT32)LineNumber;\r
155\r
156 //\r
157 // Copy Ascii FileName including NULL.\r
158 //\r
159 Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName);\r
160\r
161 //\r
162 // Copy Ascii Description\r
163 //\r
164 AsciiStrCpy (Temp + AsciiStrLen (FileName) + 1, Description);\r
165\r
8191cd5e 166 REPORT_STATUS_CODE_EX (\r
2287f237 167 (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),\r
168 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),\r
8191cd5e
LG
169 0,\r
170 NULL,\r
171 &gEfiStatusCodeDataTypeAssertGuid,\r
2287f237 172 AssertData,\r
173 TotalSize\r
174 );\r
175 }\r
176\r
177 //\r
178 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
179 //\r
180 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
181 CpuBreakpoint ();\r
182 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
183 CpuDeadLoop ();\r
184 }\r
185}\r
186\r
187\r
188/**\r
189\r
190 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
191\r
192 This function fills Length bytes of Buffer with the value specified by\r
193 PcdDebugClearMemoryValue, and returns Buffer.\r
194\r
195 If Buffer is NULL, then ASSERT().\r
196\r
197 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r
198\r
199 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
200 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r
201\r
202 @return Buffer\r
203\r
204**/\r
205VOID *\r
206EFIAPI\r
207DebugClearMemory (\r
208 OUT VOID *Buffer,\r
209 IN UINTN Length\r
210 )\r
211{\r
212 //\r
213 // If Buffer is NULL, then ASSERT().\r
214 //\r
215 ASSERT (Buffer != NULL);\r
216\r
217 //\r
218 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
219 //\r
220 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
221}\r
222\r
223\r
224/**\r
225\r
226 Returns TRUE if ASSERT() macros are enabled.\r
227\r
228 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r
229 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
230\r
231 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
232 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
233\r
234**/\r
235BOOLEAN\r
236EFIAPI\r
237DebugAssertEnabled (\r
238 VOID\r
239 )\r
240{\r
241 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
242}\r
243\r
244\r
245/**\r
246\r
247 Returns TRUE if DEBUG()macros are enabled.\r
248\r
249 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r
250 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
251\r
252 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
253 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
254\r
255**/\r
256BOOLEAN\r
257EFIAPI\r
258DebugPrintEnabled (\r
259 VOID\r
260 )\r
261{\r
262 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
263}\r
264\r
265\r
266/**\r
267\r
268 Returns TRUE if DEBUG_CODE()macros are enabled.\r
269\r
270 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r
271 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
272\r
273 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
274 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
275\r
276**/\r
277BOOLEAN\r
278EFIAPI\r
279DebugCodeEnabled (\r
280 VOID\r
281 )\r
282{\r
283 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
284}\r
285\r
286\r
287/**\r
288\r
289 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r
290\r
291 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of\r
292 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
293\r
294 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
295 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
296\r
297**/\r
298BOOLEAN\r
299EFIAPI\r
300DebugClearMemoryEnabled (\r
301 VOID\r
302 )\r
303{\r
304 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
305}\r