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