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