]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
Make MDE package pass intel IPF compiler with /W4 /WX switched on.
[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 WriteUnaligned64(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 UINTN FileNameLength;
126 UINTN DescriptionLength;
127
128 //
129 // Make sure it will all fit in the passed in buffer
130 //
131 FileNameLength = AsciiStrLen (FileName);
132 DescriptionLength = AsciiStrLen (Description);
133 TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + FileNameLength + 1 + DescriptionLength + 1;
134 if (TotalSize <= EFI_STATUS_CODE_DATA_MAX_SIZE) {
135 //
136 // Fill in EFI_DEBUG_ASSERT_DATA
137 //
138 AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;
139 AssertData->LineNumber = (UINT32)LineNumber;
140
141 //
142 // Copy Ascii FileName including NULL.
143 //
144 Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName);
145
146 //
147 // Copy Ascii Description
148 //
149 AsciiStrCpy (Temp + AsciiStrLen (FileName) + 1, Description);
150
151 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
152 (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),
153 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),
154 AssertData,
155 TotalSize
156 );
157 }
158
159 //
160 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
161 //
162 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
163 CpuBreakpoint ();
164 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
165 CpuDeadLoop ();
166 }
167 }
168
169
170 /**
171
172 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
173
174 This function fills Length bytes of Buffer with the value specified by
175 PcdDebugClearMemoryValue, and returns Buffer.
176
177 If Buffer is NULL, then ASSERT().
178
179 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
180
181 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
182 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
183
184 @return Buffer
185
186 **/
187 VOID *
188 EFIAPI
189 DebugClearMemory (
190 OUT VOID *Buffer,
191 IN UINTN Length
192 )
193 {
194 //
195 // If Buffer is NULL, then ASSERT().
196 //
197 ASSERT (Buffer != NULL);
198
199 //
200 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
201 //
202 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));
203 }
204
205
206 /**
207
208 Returns TRUE if ASSERT() macros are enabled.
209
210 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
211 PcdDebugProperyMask is set. Otherwise FALSE is returned.
212
213 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
214 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
215
216 **/
217 BOOLEAN
218 EFIAPI
219 DebugAssertEnabled (
220 VOID
221 )
222 {
223 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
224 }
225
226
227 /**
228
229 Returns TRUE if DEBUG()macros are enabled.
230
231 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
232 PcdDebugProperyMask is set. Otherwise FALSE is returned.
233
234 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
235 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
236
237 **/
238 BOOLEAN
239 EFIAPI
240 DebugPrintEnabled (
241 VOID
242 )
243 {
244 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
245 }
246
247
248 /**
249
250 Returns TRUE if DEBUG_CODE()macros are enabled.
251
252 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
253 PcdDebugProperyMask is set. Otherwise FALSE is returned.
254
255 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
256 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
257
258 **/
259 BOOLEAN
260 EFIAPI
261 DebugCodeEnabled (
262 VOID
263 )
264 {
265 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
266 }
267
268
269 /**
270
271 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
272
273 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
274 PcdDebugProperyMask is set. Otherwise FALSE is returned.
275
276 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
277 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
278
279 **/
280 BOOLEAN
281 EFIAPI
282 DebugClearMemoryEnabled (
283 VOID
284 )
285 {
286 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
287 }