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