]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | EFI Debug Library that installs Debug Level Protocol.\r | |
3 | \r | |
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 | |
9 | \r | |
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 | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | STATIC BOOLEAN mDebugLevelInstalled = FALSE;\r | |
16 | STATIC EFI_DEBUG_LEVEL_PROTOCOL mDebugLevel = { 0 };\r | |
17 | \r | |
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 | |
23 | \r | |
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 | |
28 | \r | |
29 | **/\r | |
30 | EFI_STATUS\r | |
31 | EFIAPI\r | |
32 | DebugLibConstructor (\r | |
33 | IN EFI_HANDLE ImageHandle,\r | |
34 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
35 | )\r | |
36 | {\r | |
37 | EFI_STATUS Status;\r | |
38 | \r | |
39 | //\r | |
40 | // Initialize Debug Level Protocol.\r | |
41 | //\r | |
42 | mDebugLevel.DebugLevel = PcdGet32(PcdDebugPrintErrorLevel);\r | |
43 | \r | |
44 | //\r | |
45 | // Install Debug Level Protocol. \r | |
46 | //\r | |
47 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
48 | &ImageHandle,\r | |
49 | &gEfiDebugLevelProtocolGuid,\r | |
50 | &mDebugLevel,\r | |
51 | NULL\r | |
52 | );\r | |
53 | ASSERT_EFI_ERROR (Status);\r | |
54 | \r | |
55 | //\r | |
56 | // Set flag to show that the Debug Level Protocol has been installed.\r | |
57 | //\r | |
58 | mDebugLevelInstalled = TRUE;\r | |
59 | \r | |
60 | return Status;\r | |
61 | }\r | |
62 | \r | |
63 | /**\r | |
64 | \r | |
65 | Prints a debug message to the debug output device if the specified error level is enabled.\r | |
66 | \r | |
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 | |
70 | \r | |
71 | If Format is NULL, then ASSERT().\r | |
72 | \r | |
73 | @param ErrorLevel The error level of the debug message.\r | |
74 | @param Format Format string for the debug message to print.\r | |
75 | \r | |
76 | **/\r | |
77 | VOID\r | |
78 | EFIAPI\r | |
79 | DebugPrint (\r | |
80 | IN UINTN ErrorLevel,\r | |
81 | IN CONST CHAR8 *Format,\r | |
82 | ...\r | |
83 | )\r | |
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 | |
89 | VA_LIST Marker;\r | |
90 | UINT64 *ArgumentPointer;\r | |
91 | \r | |
92 | //\r | |
93 | // If Format is NULL, then ASSERT().\r | |
94 | //\r | |
95 | ASSERT (Format != NULL);\r | |
96 | \r | |
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 | |
110 | TotalSize = sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrLen (Format) + 1;\r | |
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 | |
124 | VA_START (Marker, Format);\r | |
125 | for (Index = 0, ArgumentPointer = (UINT64 *)(DebugInfo + 1); Index < 12; Index++, ArgumentPointer++) {\r | |
126 | *ArgumentPointer = VA_ARG (Marker, UINT64);\r | |
127 | }\r | |
128 | VA_END (Marker);\r | |
129 | AsciiStrCpy ((CHAR8 *)ArgumentPointer, Format);\r | |
130 | \r | |
131 | REPORT_STATUS_CODE_EX (\r | |
132 | EFI_DEBUG_CODE,\r | |
133 | (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED),\r | |
134 | 0,\r | |
135 | NULL,\r | |
136 | &gEfiStatusCodeDataTypeDebugGuid,\r | |
137 | DebugInfo,\r | |
138 | TotalSize\r | |
139 | );\r | |
140 | }\r | |
141 | \r | |
142 | \r | |
143 | /**\r | |
144 | \r | |
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 | |
147 | \r | |
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 | |
156 | \r | |
157 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r | |
158 | \r | |
159 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r | |
160 | \r | |
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 | |
164 | \r | |
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 | |
173 | {\r | |
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 | |
178 | \r | |
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 | |
216 | }\r | |
217 | \r | |
218 | \r | |
219 | /**\r | |
220 | \r | |
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 |