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