]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
00bedfc65b9b60e297c1cf5ed5e6784cefa878c4
[mirror_edk2.git] / UnixPkg / Library / DxeUnixOemHookStatusCodeLib / UnixOemHookStatusCodeLib.c
1 /** @file
2 OEM hook status code library functions with no library constructor/destructor
3
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: UnixOemHookStatusCodeLib.c
14
15 **/
16 #include <Guid/StatusCodeDataTypeId.h>
17 #include <Guid/StatusCodeDataTypeDebug.h>
18 #include "UnixDxe.h"
19 #include <Library/OemHookStatusCodeLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/HobLib.h>
22 #include <Library/PrintLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/ReportStatusCodeLib.h>
25
26 //
27 // Cache of UnixThunk protocol
28 //
29 EFI_UNIX_THUNK_PROTOCOL *mUnix;
30
31 //
32 // Cache of standard output handle .
33 //
34 int mStdOut;
35
36 /**
37
38 Initialize OEM status code device .
39
40 @return Always return EFI_SUCCESS.
41
42 **/
43 EFI_STATUS
44 EFIAPI
45 OemHookStatusCodeInitialize (
46 VOID
47 )
48 {
49 EFI_HOB_GUID_TYPE *GuidHob;
50
51 //
52 // Retrieve UnixThunkProtocol from GUID'ed HOB
53 //
54 GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);
55 ASSERT (GuidHob != NULL);
56 mUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
57 ASSERT (mUnix != NULL);
58
59 //
60 // Cache standard output handle.
61 //
62 mStdOut = 1;
63
64 return EFI_SUCCESS;
65 }
66
67 /**
68 Report status code to OEM device.
69
70 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
71
72 @param Value Describes the current status of a hardware or software entity.
73 This included information about the class and subclass that is used to classify the entity
74 as well as an operation. For progress codes, the operation is the current activity.
75 For error codes, it is the exception. For debug codes, it is not defined at this time.
76 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
77 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
78
79 @param Instance The enumeration of a hardware or software entity within the system.
80 A system may contain multiple entities that match a class/subclass pairing.
81 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
82 not meaningful, or not relevant. Valid instance numbers start with 1.
83
84
85 @param CallerId This optional parameter may be used to identify the caller.
86 This parameter allows the status code driver to apply different rules to different callers.
87 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
88
89
90 @param Data This optional parameter may be used to pass additional data
91
92 @return The function always return EFI_SUCCESS.
93
94 **/
95 EFI_STATUS
96 EFIAPI
97 OemHookStatusCodeReport (
98 IN EFI_STATUS_CODE_TYPE CodeType,
99 IN EFI_STATUS_CODE_VALUE Value,
100 IN UINT32 Instance,
101 IN EFI_GUID *CallerId, OPTIONAL
102 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
103 )
104 {
105 CHAR8 *Filename;
106 CHAR8 *Description;
107 CHAR8 *Format;
108 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
109 UINT32 ErrorLevel;
110 UINT32 LineNumber;
111 UINTN CharCount;
112 BASE_LIST Marker;
113
114 Buffer[0] = '\0';
115
116 if (Data != NULL &&
117 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
118 //
119 // Print ASSERT() information into output buffer.
120 //
121 CharCount = AsciiSPrint (
122 Buffer,
123 sizeof (Buffer),
124 "\n\rASSERT!: %a (%d): %a\n\r",
125 Filename,
126 LineNumber,
127 Description
128 );
129
130 //
131 // Callout to standard output.
132 //
133 mUnix->Write (
134 mStdOut,
135 Buffer,
136 CharCount
137 );
138
139 return EFI_SUCCESS;
140
141 } else if (Data != NULL &&
142 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
143 //
144 // Print DEBUG() information into output buffer.
145 //
146 CharCount = AsciiBSPrint (
147 Buffer,
148 sizeof (Buffer),
149 Format,
150 Marker
151 );
152 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
153 //
154 // Print ERROR information into output buffer.
155 //
156 CharCount = AsciiSPrint (
157 Buffer,
158 sizeof (Buffer),
159 "ERROR: C%x:V%x I%x",
160 CodeType,
161 Value,
162 Instance
163 );
164
165 //
166 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
167 //
168
169 if (CallerId != NULL) {
170 CharCount += AsciiSPrint (
171 &Buffer[CharCount - 1],
172 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
173 " %g",
174 CallerId
175 );
176 }
177
178 if (Data != NULL) {
179 CharCount += AsciiSPrint (
180 &Buffer[CharCount - 1],
181 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
182 " %x",
183 Data
184 );
185 }
186
187 CharCount += AsciiSPrint (
188 &Buffer[CharCount - 1],
189 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
190 "\n\r"
191 );
192 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
193 CharCount = AsciiSPrint (
194 Buffer,
195 sizeof (Buffer),
196 "PROGRESS CODE: V%x I%x\n\r",
197 Value,
198 Instance
199 );
200 } else {
201 CharCount = AsciiSPrint (
202 Buffer,
203 sizeof (Buffer),
204 "Undefined: C%x:V%x I%x\n\r",
205 CodeType,
206 Value,
207 Instance
208 );
209 }
210
211 //
212 // Callout to standard output.
213 //
214 mUnix->Write (
215 mStdOut,
216 Buffer,
217 CharCount
218 );
219
220 return EFI_SUCCESS;
221 }
222