]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/Library/PeiNt32OemHookStatusCodeLib/Nt32OemHookStatusCodeLib.c
Increase source portability by replace the use of EFI_STATUS_CODE_DATA_MAX_SIZE with...
[mirror_edk2.git] / Nt32Pkg / Library / PeiNt32OemHookStatusCodeLib / Nt32OemHookStatusCodeLib.c
CommitLineData
869f8e34 1/** @file\r
2 OEM hook status code library functions with no library constructor/destructor\r
3\r
4 Copyright (c) 2006, Intel Corporation\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 Module Name: Nt32OemHookStatusCodeLib.c\r
14\r
15**/\r
16\r
17//\r
55206596 18// The package level header files this module uses\r
869f8e34 19//\r
55206596 20#include <FrameworkPei.h>\r
184cf404 21#include <FrameworkModulePei.h>\r
55206596 22#include <WinNtPeim.h>\r
2f053c92 23\r
55206596 24//\r
25// The protocols, PPI and GUID defintions for this module\r
26//\r
27#include <Guid/StatusCodeDataTypeId.h>\r
28#include <Ppi/NtThunk.h>\r
29//\r
30// The Library classes this module consumes\r
31//\r
32#include <Library/OemHookStatusCodeLib.h>\r
33#include <Library/DebugLib.h>\r
34#include <Library/PrintLib.h>\r
35#include <Library/BaseMemoryLib.h>\r
36#include <Library/ReportStatusCodeLib.h>\r
37#include <Library/PeiServicesLib.h>\r
869f8e34 38\r
39//\r
55206596 40// Cache of WinNtThunk protocol\r
869f8e34 41//\r
869f8e34 42EFI_WIN_NT_THUNK_PROTOCOL *mWinNt;\r
43\r
44//\r
55206596 45// Cache of standard output handle .\r
869f8e34 46//\r
869f8e34 47HANDLE mStdOut;\r
48\r
49/**\r
50\r
51 Initialize OEM status code device .\r
52\r
53 @return Always return EFI_SUCCESS.\r
54\r
55**/\r
56EFI_STATUS\r
57EFIAPI\r
58OemHookStatusCodeInitialize (\r
59 VOID\r
60 )\r
61{\r
62 PEI_NT_THUNK_PPI *NtThunkPpi;\r
63 EFI_STATUS Status;\r
64\r
55206596 65\r
869f8e34 66 //\r
67 // Locate NtThunkPpi for retrieving standard output handle\r
68 //\r
69 Status = PeiServicesLocatePpi (\r
70 &gPeiNtThunkPpiGuid,\r
71 0,\r
72 NULL,\r
73 (VOID **) &NtThunkPpi\r
74 );\r
75\r
76 ASSERT_EFI_ERROR (Status);\r
77\r
78 mWinNt = (EFI_WIN_NT_THUNK_PROTOCOL *) NtThunkPpi->NtThunk ();\r
55206596 79\r
869f8e34 80\r
81 //\r
82 // Cache standard output handle.\r
83 //\r
84 mStdOut = mWinNt->GetStdHandle (STD_OUTPUT_HANDLE);\r
85\r
86 return EFI_SUCCESS;\r
87}\r
88\r
89/**\r
90 Report status code to OEM device.\r
55206596 91\r
869f8e34 92 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
55206596 93\r
94 @param Value Describes the current status of a hardware or software entity.\r
95 This included information about the class and subclass that is used to classify the entity\r
96 as well as an operation. For progress codes, the operation is the current activity.\r
97 For error codes, it is the exception. For debug codes, it is not defined at this time.\r
98 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.\r
869f8e34 99 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
55206596 100\r
101 @param Instance The enumeration of a hardware or software entity within the system.\r
102 A system may contain multiple entities that match a class/subclass pairing.\r
103 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,\r
869f8e34 104 not meaningful, or not relevant. Valid instance numbers start with 1.\r
105\r
106\r
55206596 107 @param CallerId This optional parameter may be used to identify the caller.\r
108 This parameter allows the status code driver to apply different rules to different callers.\r
8a7d75b0 109 Type EFI_GUID is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.\r
869f8e34 110\r
111\r
112 @param Data This optional parameter may be used to pass additional data\r
55206596 113\r
869f8e34 114 @return The function always return EFI_SUCCESS.\r
115\r
116**/\r
117EFI_STATUS\r
118EFIAPI\r
119OemHookStatusCodeReport (\r
120 IN EFI_STATUS_CODE_TYPE CodeType,\r
121 IN EFI_STATUS_CODE_VALUE Value,\r
122 IN UINT32 Instance,\r
123 IN EFI_GUID *CallerId, OPTIONAL\r
124 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
125 )\r
126{\r
127 CHAR8 *Filename;\r
128 CHAR8 *Description;\r
129 CHAR8 *Format;\r
130 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
131 UINT32 ErrorLevel;\r
132 UINT32 LineNumber;\r
133 UINTN CharCount;\r
53d74081 134 BASE_LIST Marker;\r
869f8e34 135\r
136 Buffer[0] = '\0';\r
137\r
138 if (Data != NULL &&\r
139 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
140 //\r
141 // Print ASSERT() information into output buffer.\r
142 //\r
143 CharCount = AsciiSPrint (\r
144 Buffer,\r
be71cc9f 145 sizeof (Buffer),\r
869f8e34 146 "\n\rASSERT!: %a (%d): %a\n\r",\r
147 Filename,\r
148 LineNumber,\r
149 Description\r
150 );\r
151\r
152 //\r
153 // Callout to standard output.\r
154 //\r
155 mWinNt->WriteFile (\r
156 mStdOut,\r
157 Buffer,\r
158 CharCount,\r
24c28238 159 (LPDWORD)&CharCount,\r
869f8e34 160 NULL\r
161 );\r
162\r
163 return EFI_SUCCESS;\r
164\r
165 } else if (Data != NULL &&\r
166 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
167 //\r
168 // Print DEBUG() information into output buffer.\r
169 //\r
53d74081 170 CharCount = AsciiBSPrint (\r
55206596 171 Buffer,\r
be71cc9f 172 sizeof (Buffer),\r
55206596 173 Format,\r
869f8e34 174 Marker\r
175 );\r
869f8e34 176 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
177 //\r
178 // Print ERROR information into output buffer.\r
179 //\r
180 CharCount = AsciiSPrint (\r
55206596 181 Buffer,\r
be71cc9f 182 sizeof (Buffer),\r
55206596 183 "ERROR: C%x:V%x I%x",\r
184 CodeType,\r
185 Value,\r
869f8e34 186 Instance\r
187 );\r
188\r
189 //\r
190 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.\r
191 //\r
55206596 192\r
869f8e34 193 if (CallerId != NULL) {\r
194 CharCount += AsciiSPrint (\r
195 &Buffer[CharCount - 1],\r
be71cc9f 196 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
869f8e34 197 " %g",\r
198 CallerId\r
199 );\r
200 }\r
201\r
202 if (Data != NULL) {\r
203 CharCount += AsciiSPrint (\r
204 &Buffer[CharCount - 1],\r
be71cc9f 205 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
d251b34d 206 " %p",\r
869f8e34 207 Data\r
208 );\r
209 }\r
210\r
211 CharCount += AsciiSPrint (\r
212 &Buffer[CharCount - 1],\r
be71cc9f 213 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
869f8e34 214 "\n\r"\r
215 );\r
216 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
217 CharCount = AsciiSPrint (\r
55206596 218 Buffer,\r
be71cc9f 219 sizeof (Buffer),\r
55206596 220 "PROGRESS CODE: V%x I%x\n\r",\r
221 Value,\r
869f8e34 222 Instance\r
223 );\r
224 } else {\r
225 CharCount = AsciiSPrint (\r
55206596 226 Buffer,\r
be71cc9f 227 sizeof (Buffer),\r
55206596 228 "Undefined: C%x:V%x I%x\n\r",\r
229 CodeType,\r
230 Value,\r
869f8e34 231 Instance\r
232 );\r
233 }\r
234\r
235 //\r
236 // Callout to standard output.\r
237 //\r
238 mWinNt->WriteFile (\r
239 mStdOut,\r
240 Buffer,\r
241 CharCount,\r
24c28238 242 (LPDWORD)&CharCount,\r
869f8e34 243 NULL\r
244 );\r
245\r
246 return EFI_SUCCESS;\r
247}\r
248\r