2 Report status code lib on top of either SerialLib and/or EFI Serial Protocol.
3 Based on PcdStatusCodeUseEfiSerial & PcdStatusCodeUseHardSerial settings
5 There is just a single runtime memory buffer that contans all the data.
7 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
8 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 //////////#include "DxeStatusCode.h"
23 EFI_SERIAL_IO_PROTOCOL
*mSerialIoProtocol
= NULL
;
28 IN EFI_STATUS_CODE_TYPE CodeType
,
29 IN EFI_STATUS_CODE_VALUE Value
,
31 IN EFI_GUID
*CallerId
,
32 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
38 CHAR8 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
];
43 EFI_DEBUG_INFO
*DebugInfo
;
47 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial
)) {
48 if (EfiAtRuntime ()) {
49 return EFI_DEVICE_ERROR
;
51 CurrentTpl
= gBS
->RaiseTPL (EFI_TPL_HIGH_LEVEL
);
52 gBS
->RestoreTPL (CurrentTpl
);
54 if (CurrentTpl
> EFI_TPL_CALLBACK
) {
55 return EFI_DEVICE_ERROR
;
62 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
64 // Print ASSERT() information into output buffer.
66 CharCount
= AsciiSPrint (
68 EFI_STATUS_CODE_DATA_MAX_SIZE
,
69 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
74 } else if (Data
!= NULL
&&
75 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
77 // Print DEBUG() information into output buffer.
79 CharCount
= AsciiVSPrint (
81 EFI_STATUS_CODE_DATA_MAX_SIZE
,
85 } else if (Data
!= NULL
&&
86 CompareGuid (&Data
->Type
, &gEfiStatusCodeSpecificDataGuid
) &&
87 (CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
89 // Print specific data into output buffer.
91 DebugInfo
= (EFI_DEBUG_INFO
*) (Data
+ 1);
92 Marker
= (VA_LIST
) (DebugInfo
+ 1);
93 Format
= (CHAR8
*) (((UINT64
*) (DebugInfo
+ 1)) + 12);
95 CharCount
= AsciiVSPrint (Buffer
, EFI_STATUS_CODE_DATA_MAX_SIZE
, Format
, Marker
);
96 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
98 // Print ERROR information into output buffer.
100 CharCount
= AsciiSPrint (
102 EFI_STATUS_CODE_DATA_MAX_SIZE
,
103 "ERROR: C%x:V%x I%x",
110 // Make sure we don't try to print values that weren't
111 // intended to be printed, especially NULL GUID pointers.
114 if (CallerId
!= NULL
) {
115 CharCount
+= AsciiSPrint (
116 &Buffer
[CharCount
- 1],
117 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
124 CharCount
+= AsciiSPrint (
125 &Buffer
[CharCount
- 1],
126 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
132 CharCount
+= AsciiSPrint (
133 &Buffer
[CharCount
- 1],
134 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
137 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
138 CharCount
= AsciiSPrint (
140 EFI_STATUS_CODE_DATA_MAX_SIZE
,
141 "PROGRESS CODE: V%x I%x\n\r",
146 CharCount
= AsciiSPrint (
148 EFI_STATUS_CODE_DATA_MAX_SIZE
,
149 "Undefined: C%x:V%x I%x\n\r",
157 if (FeaturePcdGet (PcdStatusCodeUseHardSerial
)) {
159 // Callout to SerialPort Lib function to do print.
161 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);
163 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial
)) {
164 if (mSerialIoProtocol
== NULL
) {
165 gBS
->LocateProtocol (&gEfiSerialIoProtocolGuid
, NULL
, (VOID
**) &mSerialIoProtocol
);
168 if (mSerialIoProtocol
== NULL
) {
169 mSerialIoProtocol
->Write (
182 LibReportStatusCodeVirtualAddressChangeEvent (
190 LibReportStatusCodeInitialize (