]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/EdkDxeDebugLibReportStatusCode/DebugLib.c
converted all surface area description files to new schema
[mirror_edk2.git] / EdkModulePkg / Library / EdkDxeDebugLibReportStatusCode / DebugLib.c
1 /*++
2
3 Copyright (c) 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 Module Name:
13
14 DebugLib.c
15
16 Abstract:
17
18 EFI Debug Library
19
20 --*/
21
22 static BOOLEAN mDebugLevelInstalled = FALSE;
23 static EFI_DEBUG_LEVEL_PROTOCOL mDebugLevel = { 0 };
24
25 EFI_STATUS
26 DebugLibConstructor (
27 IN EFI_HANDLE ImageHandle,
28 IN EFI_SYSTEM_TABLE *SystemTable
29 )
30 /*++
31
32 Routine Description:
33
34 Arguments:
35
36 Returns:
37
38 --*/
39 {
40 EFI_STATUS Status;
41
42 //
43 // Initialize Debug Level Protocol
44 //
45 mDebugLevel.DebugLevel = PcdGet32(PcdDebugPrintErrorLevel);
46
47 //
48 // Install Debug Level Protocol
49 //
50 Status = gBS->InstallMultipleProtocolInterfaces (
51 &ImageHandle,
52 &gEfiDebugLevelProtocolGuid, &mDebugLevel,
53 NULL
54 );
55 ASSERT_EFI_ERROR (Status);
56
57 //
58 // Set flag to show that the Debug Level Protocol has been installed
59 //
60 mDebugLevelInstalled = TRUE;
61
62 return EFI_SUCCESS;
63 }
64
65 VOID
66 EFIAPI
67 DebugAssert (
68 IN CHAR8 *FileName,
69 IN UINTN LineNumber,
70 IN CHAR8 *Description
71 )
72 /*++
73
74 Routine Description:
75
76 Worker function for ASSERT(). If Error Logging hub is loaded log ASSERT
77 information. If Error Logging hub is not loaded CpuBreakpoint ().
78
79 We use UINT64 buffers due to IPF alignment concerns.
80
81 Arguments:
82
83 FileName - File name of failing routine.
84
85 LineNumber - Line number of failing ASSERT().
86
87 Description - Descritption, usally the assertion,
88
89 Returns:
90
91 None
92
93 --*/
94 {
95 UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)];
96 EFI_DEBUG_ASSERT_DATA *AssertData;
97 UINTN TotalSize;
98 CHAR8 *Temp;
99
100 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) == 0) {
101 return;
102 }
103
104 //
105 // Make sure it will all fit in the passed in buffer
106 //
107 TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + AsciiStrLen (FileName) + 1 + AsciiStrLen (Description) + 1;
108 if (TotalSize <= EFI_STATUS_CODE_DATA_MAX_SIZE) {
109 //
110 // Fill in EFI_DEBUG_ASSERT_DATA
111 //
112 AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;
113 AssertData->LineNumber = (UINT32)LineNumber;
114
115 //
116 // Copy Ascii FileName including NULL.
117 //
118 Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName);
119
120 //
121 // Copy Ascii Description
122 //
123 AsciiStrCpy (Temp + AsciiStrLen(FileName) + 1, Description);
124
125 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
126 (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),
127 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),
128 AssertData,
129 TotalSize
130 );
131 }
132
133 //
134 // Put break point in module that contained the error.
135 //
136 CpuBreakpoint ();
137 }
138
139 VOID
140 DebugVPrint (
141 IN UINTN ErrorLevel,
142 IN CHAR8 *Format,
143 IN VA_LIST Marker
144 )
145 /*++
146
147 Routine Description:
148
149 Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT
150 information. If Error Logging hub is not loaded do nothing.
151
152 We use UINT64 buffers due to IPF alignment concerns.
153
154 Arguments:
155
156 ErrorLevel - If error level is set do the debug print.
157
158 Format - String to use for the print, followed by Print arguments.
159
160 Marker - VarArgs
161
162 Returns:
163
164 None
165
166 --*/
167 {
168 UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)];
169 EFI_DEBUG_INFO *DebugInfo;
170 UINTN TotalSize;
171 UINTN Index;
172 UINT64 *ArgumentPointer;
173
174 //
175 // Check driver Debug Level value and global debug level
176 //
177 if (mDebugLevelInstalled) {
178 if ((ErrorLevel & mDebugLevel.DebugLevel) == 0) {
179 return;
180 }
181 } else {
182 if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {
183 return;
184 }
185 }
186
187 TotalSize = sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64 *) + AsciiStrLen (Format) + 1;
188 if (TotalSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {
189 return;
190 }
191
192 //
193 // Then EFI_DEBUG_INFO
194 //
195 DebugInfo = (EFI_DEBUG_INFO *)Buffer;
196 DebugInfo->ErrorLevel = (UINT32)ErrorLevel;
197
198 //
199 // 256 byte mini Var Arg stack. That is followed by the format string.
200 //
201 for (Index = 0, ArgumentPointer = (UINT64 *)(DebugInfo + 1); Index < 12; Index++, ArgumentPointer++) {
202 *ArgumentPointer = VA_ARG (Marker, UINT64);
203 }
204 AsciiStrCpy ((CHAR8 *)ArgumentPointer, Format);
205
206 //
207 //
208 //
209 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
210 EFI_DEBUG_CODE,
211 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED),
212 DebugInfo,
213 TotalSize
214 );
215 }
216
217 VOID
218 EFIAPI
219 DebugPrint (
220 IN UINTN ErrorLevel,
221 IN CHAR8 *Format,
222 ...
223 )
224 /*++
225
226 Routine Description:
227
228 Wrapper for DebugVPrint ()
229
230 Arguments:
231
232 ErrorLevel - If error level is set do the debug print.
233
234 Format - String to use for the print, followed by Print arguments.
235
236 ... - Print arguments.
237
238 Returns:
239
240 None
241
242 --*/
243 {
244 VA_LIST Marker;
245
246 VA_START (Marker, Format);
247 DebugVPrint (ErrorLevel, Format, Marker);
248 VA_END (Marker);
249 }
250
251 /**
252 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
253
254 This function fills Length bytes of Buffer with the value specified by
255 PcdDebugClearMemoryValue, and returns Buffer.
256
257 If Buffer is NULL, then ASSERT().
258
259 If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT().
260
261 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
262 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
263
264 @return Buffer
265
266 **/
267 VOID *
268 EFIAPI
269 DebugClearMemory (
270 OUT VOID *Buffer,
271 IN UINTN Length
272 )
273 {
274 // SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));
275 SetMem (Buffer, Length, 0xAF);
276 return Buffer;
277 }
278
279 BOOLEAN
280 EFIAPI
281 DebugAssertEnabled (
282 VOID
283 )
284 {
285 return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
286 }
287
288 BOOLEAN
289 EFIAPI
290 DebugPrintEnabled (
291 VOID
292 )
293 {
294 return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
295 }
296
297 BOOLEAN
298 EFIAPI
299 DebugCodeEnabled (
300 VOID
301 )
302 {
303 return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
304 }
305
306 BOOLEAN
307 EFIAPI
308 DebugClearMemoryEnabled (
309 VOID
310 )
311 {
312 return ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
313 }
314