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