EmbeddedPkg: drop unused Pcds from package .dsc
[mirror_edk2.git] / EmbeddedPkg / Library / HalRuntimeServicesExampleLib / ReportStatusCode.c
CommitLineData
2ef2b01e
A
1/** @file\r
2 Report status code lib on top of either SerialLib and/or EFI Serial Protocol.\r
3 Based on PcdStatusCodeUseEfiSerial & PcdStatusCodeUseHardSerial settings\r
4\r
3402aac7 5 There is just a single runtime memory buffer that contans all the data.\r
2ef2b01e 6\r
60274cca
HT
7 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
8 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
9 This program and the accompanying materials\r
2ef2b01e
A
10 are licensed and made available under the terms and conditions of the BSD License\r
11 which accompanies this distribution. The full text of the license may be found at\r
12 http://opensource.org/licenses/bsd-license.php\r
13\r
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17\r
18**/\r
19\r
20//////////#include "DxeStatusCode.h"\r
21\r
22\r
23EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol = NULL;\r
24\r
25\r
26EFI_STATUS\r
27LibReportStatusCode (\r
28 IN EFI_STATUS_CODE_TYPE CodeType,\r
29 IN EFI_STATUS_CODE_VALUE Value,\r
30 IN UINT32 Instance,\r
31 IN EFI_GUID *CallerId,\r
32 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
33 )\r
34{\r
35 CHAR8 *Filename;\r
36 CHAR8 *Description;\r
37 CHAR8 *Format;\r
38 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
39 UINT32 ErrorLevel;\r
40 UINT32 LineNumber;\r
41 UINTN CharCount;\r
42 VA_LIST Marker;\r
43 EFI_DEBUG_INFO *DebugInfo;\r
44 EFI_TPL CurrentTpl;\r
45\r
46\r
47 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {\r
48 if (EfiAtRuntime ()) {\r
49 return EFI_DEVICE_ERROR;\r
50 }\r
51 CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);\r
52 gBS->RestoreTPL (CurrentTpl);\r
53\r
54 if (CurrentTpl > EFI_TPL_CALLBACK ) {\r
55 return EFI_DEVICE_ERROR;\r
56 }\r
57 }\r
58\r
59 Buffer[0] = '\0';\r
60\r
61 if (Data != NULL &&\r
62 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
63 //\r
64 // Print ASSERT() information into output buffer.\r
65 //\r
66 CharCount = AsciiSPrint (\r
67 Buffer,\r
68 EFI_STATUS_CODE_DATA_MAX_SIZE,\r
69 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",\r
70 Filename,\r
71 LineNumber,\r
72 Description\r
73 );\r
74 } else if (Data != NULL &&\r
75 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
76 //\r
77 // Print DEBUG() information into output buffer.\r
78 //\r
79 CharCount = AsciiVSPrint (\r
3402aac7
RC
80 Buffer,\r
81 EFI_STATUS_CODE_DATA_MAX_SIZE,\r
82 Format,\r
2ef2b01e
A
83 Marker\r
84 );\r
3402aac7 85 } else if (Data != NULL &&\r
2ef2b01e
A
86 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&\r
87 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
88 //\r
89 // Print specific data into output buffer.\r
90 //\r
91 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
92 Marker = (VA_LIST) (DebugInfo + 1);\r
93 Format = (CHAR8 *) (((UINT64 *) (DebugInfo + 1)) + 12);\r
94\r
95 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);\r
96 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
97 //\r
98 // Print ERROR information into output buffer.\r
99 //\r
100 CharCount = AsciiSPrint (\r
3402aac7
RC
101 Buffer,\r
102 EFI_STATUS_CODE_DATA_MAX_SIZE,\r
103 "ERROR: C%x:V%x I%x",\r
104 CodeType,\r
105 Value,\r
2ef2b01e
A
106 Instance\r
107 );\r
108\r
109 //\r
3402aac7 110 // Make sure we don't try to print values that weren't\r
2ef2b01e
A
111 // intended to be printed, especially NULL GUID pointers.\r
112 //\r
3402aac7 113\r
2ef2b01e
A
114 if (CallerId != NULL) {\r
115 CharCount += AsciiSPrint (\r
116 &Buffer[CharCount - 1],\r
117 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
118 " %g",\r
119 CallerId\r
120 );\r
121 }\r
122\r
123 if (Data != NULL) {\r
124 CharCount += AsciiSPrint (\r
125 &Buffer[CharCount - 1],\r
126 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
127 " %x",\r
128 Data\r
129 );\r
130 }\r
131\r
132 CharCount += AsciiSPrint (\r
133 &Buffer[CharCount - 1],\r
134 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
135 "\n\r"\r
136 );\r
137 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
138 CharCount = AsciiSPrint (\r
3402aac7
RC
139 Buffer,\r
140 EFI_STATUS_CODE_DATA_MAX_SIZE,\r
141 "PROGRESS CODE: V%x I%x\n\r",\r
142 Value,\r
2ef2b01e
A
143 Instance\r
144 );\r
145 } else {\r
146 CharCount = AsciiSPrint (\r
3402aac7
RC
147 Buffer,\r
148 EFI_STATUS_CODE_DATA_MAX_SIZE,\r
149 "Undefined: C%x:V%x I%x\n\r",\r
150 CodeType,\r
151 Value,\r
2ef2b01e
A
152 Instance\r
153 );\r
154 }\r
155\r
156\r
157 if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {\r
158 //\r
159 // Callout to SerialPort Lib function to do print.\r
160 //\r
161 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
162 }\r
163 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {\r
164 if (mSerialIoProtocol == NULL) {\r
165 gBS->LocateProtocol (&gEfiSerialIoProtocolGuid, NULL, (VOID **) &mSerialIoProtocol);\r
166 }\r
167\r
3402aac7 168 if (mSerialIoProtocol == NULL) {\r
2ef2b01e
A
169 mSerialIoProtocol->Write (\r
170 mSerialIoProtocol,\r
171 &CharCount,\r
172 Buffer\r
173 );\r
174 }\r
175 }\r
176\r
177 return EFI_SUCCESS;\r
178}\r
179\r
180\r
181VOID\r
182LibReportStatusCodeVirtualAddressChangeEvent (\r
183 VOID\r
184 )\r
185{\r
186 return;\r
187}\r
188\r
189VOID\r
190LibReportStatusCodeInitialize (\r
191 VOID\r
192 )\r
193{\r
194 return;\r
195}\r
196\r
197\r
198\r