]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EdkModulePkg/Library/EdkUefiDebugLibStdErr/DebugLib.c
Add two files for List editor.
[mirror_edk2.git] / EdkModulePkg / Library / EdkUefiDebugLibStdErr / DebugLib.c
... / ...
CommitLineData
1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
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
12Module Name:\r
13\r
14 DebugLib.c\r
15\r
16Abstract:\r
17\r
18 UEFI Debug Library that uses PrintLib to send messages to STDERR\r
19\r
20--*/\r
21\r
22static BOOLEAN mDebugLevelInstalled = FALSE;\r
23static EFI_DEBUG_LEVEL_PROTOCOL mDebugLevel = { 0 };\r
24\r
25EFI_STATUS\r
26DebugLibConstructor (\r
27 IN EFI_HANDLE ImageHandle,\r
28 IN EFI_SYSTEM_TABLE *SystemTable\r
29 )\r
30/*++\r
31\r
32Routine Description:\r
33\r
34Arguments:\r
35\r
36Returns:\r
37\r
38--*/\r
39{\r
40 EFI_STATUS Status;\r
41\r
42 //\r
43 // Initialize Debug Level Protocol\r
44 //\r
45 mDebugLevel.DebugLevel = PcdGet32(PcdDebugPrintErrorLevel);\r
46\r
47 //\r
48 // Install Debug Level Protocol \r
49 //\r
50 Status = gBS->InstallMultipleProtocolInterfaces (\r
51 &ImageHandle,\r
52 &gEfiDebugLevelProtocolGuid, &mDebugLevel,\r
53 NULL\r
54 );\r
55 ASSERT_EFI_ERROR (Status);\r
56\r
57 //\r
58 // Set flag to show that the Debug Level Protocol has been installed\r
59 //\r
60 mDebugLevelInstalled = TRUE;\r
61\r
62 return EFI_SUCCESS;\r
63}\r
64\r
65VOID\r
66EFIAPI\r
67DebugPrint (\r
68 IN UINTN ErrorLevel,\r
69 IN CHAR8 *Format,\r
70 ...\r
71 )\r
72/*++\r
73\r
74Routine Description:\r
75\r
76 Wrapper for DebugVPrint ()\r
77 \r
78Arguments:\r
79\r
80 ErrorLevel - If error level is set do the debug print.\r
81\r
82 Format - String to use for the print, followed by Print arguments.\r
83\r
84 ... - Print arguments.\r
85\r
86Returns:\r
87 \r
88 None\r
89\r
90--*/\r
91{\r
92 CHAR16 Buffer[0x100];\r
93 CHAR16 UnicodeBuffer[0x100];\r
94 UINT32 Index;\r
95 VA_LIST Marker;\r
96\r
97 //\r
98 // Check to see if STDERR is avilable\r
99 //\r
100 if (gST->StdErr == NULL) {\r
101 return;\r
102 }\r
103\r
104 //\r
105 // Check driver Debug Level value and global debug level\r
106 //\r
107 if (mDebugLevelInstalled) {\r
108 if ((ErrorLevel & mDebugLevel.DebugLevel) == 0) {\r
109 return;\r
110 }\r
111 } else {\r
112 if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r
113 return;\r
114 }\r
115 }\r
116\r
117 //\r
118 // BUGBUG: Need print that take CHAR8 Format and returns CHAR16 Buffer\r
119 //\r
120 for (Index = 0; Format[Index] != 0; Index++) {\r
121 UnicodeBuffer[Index] = Format[Index];\r
122 }\r
123 UnicodeBuffer[Index] = Format[Index];\r
124\r
125 //\r
126 // Convert the DEBUG() message to a Unicode String\r
127 //\r
128 VA_START (Marker, Format);\r
129 UnicodeVSPrint (Buffer, sizeof (Buffer), UnicodeBuffer, Marker);\r
130 VA_END (Marker);\r
131\r
132 //\r
133 // Send the print string to the Standard Error device\r
134 //\r
135 gST->StdErr->OutputString (gST->StdErr, Buffer);\r
136}\r
137\r
138VOID\r
139EFIAPI\r
140DebugAssert (\r
141 IN CHAR8 *FileName,\r
142 IN UINTN LineNumber,\r
143 IN CHAR8 *Description\r
144 )\r
145/*++\r
146\r
147Routine Description:\r
148\r
149 Worker function for ASSERT(). If Error Logging hub is loaded log ASSERT\r
150 information. If Error Logging hub is not loaded CpuBreakpoint ().\r
151\r
152 We use UINT64 buffers due to IPF alignment concerns.\r
153\r
154Arguments:\r
155\r
156 FileName - File name of failing routine.\r
157\r
158 LineNumber - Line number of failing ASSERT().\r
159\r
160 Description - Descritption, usally the assertion,\r
161 \r
162Returns:\r
163 \r
164 None\r
165\r
166--*/\r
167{\r
168 CHAR16 Buffer[0x100];\r
169\r
170 //\r
171 // Check to see if STDERR is avilable\r
172 //\r
173 if (gST->StdErr == NULL) {\r
174 return;\r
175 }\r
176\r
177 //\r
178 // Generate the ASSERT() message in Unicode format\r
179 //\r
180 UnicodeSPrint (Buffer, sizeof (Buffer), (CHAR16 *)L"ASSERT %s(%d): %s\n", FileName, LineNumber, Description);\r
181\r
182 //\r
183 // Send the print string to the Standard Error device\r
184 //\r
185 gST->StdErr->OutputString (gST->StdErr, Buffer);\r
186\r
187 //\r
188 // Put break point in module that contained the error.\r
189 //\r
190 CpuBreakpoint ();\r
191}\r
192\r
193/**\r
194 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
195\r
196 This function fills Length bytes of Buffer with the value specified by \r
197 PcdDebugClearMemoryValue, and returns Buffer.\r
198\r
199 If Buffer is NULL, then ASSERT().\r
200\r
201