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