EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

EmbeddedPkg/Library/HalRuntimeServicesExampleLib/ReportStatusCode.c

Go to the documentation of this file.
00001 
00020 
00021 
00022 
00023 EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol = NULL;
00024 
00025 
00026 EFI_STATUS
00027 LibReportStatusCode (
00028   IN EFI_STATUS_CODE_TYPE     CodeType,
00029   IN EFI_STATUS_CODE_VALUE    Value,
00030   IN UINT32                   Instance,
00031   IN EFI_GUID                 *CallerId,
00032   IN EFI_STATUS_CODE_DATA     *Data OPTIONAL
00033   )
00034 {
00035   CHAR8           *Filename;
00036   CHAR8           *Description;
00037   CHAR8           *Format;
00038   CHAR8           Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
00039   UINT32          ErrorLevel;
00040   UINT32          LineNumber;
00041   UINTN           CharCount;
00042   VA_LIST         Marker;
00043   EFI_DEBUG_INFO  *DebugInfo;
00044   EFI_TPL         CurrentTpl;
00045 
00046 
00047   if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
00048     if (EfiAtRuntime ()) {
00049       return EFI_DEVICE_ERROR;
00050     }
00051     CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
00052     gBS->RestoreTPL (CurrentTpl);
00053 
00054     if (CurrentTpl > EFI_TPL_CALLBACK ) {
00055       return EFI_DEVICE_ERROR;
00056     }
00057   }
00058 
00059   Buffer[0] = '\0';
00060 
00061   if (Data != NULL &&
00062       ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
00063     //
00064     // Print ASSERT() information into output buffer.
00065     //
00066     CharCount = AsciiSPrint (
00067                   Buffer,
00068                   EFI_STATUS_CODE_DATA_MAX_SIZE,
00069                   "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
00070                   Filename,
00071                   LineNumber,
00072                   Description
00073                   );
00074   } else if (Data != NULL &&
00075              ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
00076     //
00077     // Print DEBUG() information into output buffer.
00078     //
00079     CharCount = AsciiVSPrint (
00080                   Buffer, 
00081                   EFI_STATUS_CODE_DATA_MAX_SIZE, 
00082                   Format, 
00083                   Marker
00084                   );
00085   } else if (Data != NULL && 
00086              CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
00087              (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
00088     //
00089     // Print specific data into output buffer.
00090     //
00091     DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
00092     Marker    = (VA_LIST) (DebugInfo + 1);
00093     Format    = (CHAR8 *) (((UINT64 *) (DebugInfo + 1)) + 12);
00094 
00095     CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
00096   } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
00097     //
00098     // Print ERROR information into output buffer.
00099     //
00100     CharCount = AsciiSPrint (
00101                   Buffer, 
00102                   EFI_STATUS_CODE_DATA_MAX_SIZE, 
00103                   "ERROR: C%x:V%x I%x", 
00104                   CodeType, 
00105                   Value, 
00106                   Instance
00107                   );
00108 
00109     //
00110     // Make sure we don't try to print values that weren't 
00111     // intended to be printed, especially NULL GUID pointers.
00112     //
00113     
00114     if (CallerId != NULL) {
00115       CharCount += AsciiSPrint (
00116                      &Buffer[CharCount - 1],
00117                      (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
00118                      " %g",
00119                      CallerId
00120                      );
00121     }
00122 
00123     if (Data != NULL) {
00124       CharCount += AsciiSPrint (
00125                      &Buffer[CharCount - 1],
00126                      (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
00127                      " %x",
00128                      Data
00129                      );
00130     }
00131 
00132     CharCount += AsciiSPrint (
00133                    &Buffer[CharCount - 1],
00134                    (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
00135                    "\n\r"
00136                    );
00137   } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
00138     CharCount = AsciiSPrint (
00139                   Buffer, 
00140                   EFI_STATUS_CODE_DATA_MAX_SIZE, 
00141                   "PROGRESS CODE: V%x I%x\n\r", 
00142                   Value, 
00143                   Instance
00144                   );
00145   } else {
00146     CharCount = AsciiSPrint (
00147                   Buffer, 
00148                   EFI_STATUS_CODE_DATA_MAX_SIZE, 
00149                   "Undefined: C%x:V%x I%x\n\r", 
00150                   CodeType, 
00151                   Value, 
00152                   Instance
00153                   );
00154   }
00155 
00156 
00157   if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
00158     //
00159     // Callout to SerialPort Lib function to do print.
00160     //
00161     SerialPortWrite ((UINT8 *) Buffer, CharCount);
00162   }
00163   if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
00164     if (mSerialIoProtocol == NULL) {
00165       gBS->LocateProtocol (&gEfiSerialIoProtocolGuid, NULL, (VOID **) &mSerialIoProtocol);
00166     }
00167 
00168     if (mSerialIoProtocol == NULL) {    
00169       mSerialIoProtocol->Write (
00170         mSerialIoProtocol,
00171         &CharCount,
00172         Buffer
00173         );
00174     }
00175   }
00176 
00177   return EFI_SUCCESS;
00178 }
00179 
00180 
00181 VOID
00182 LibReportStatusCodeVirtualAddressChangeEvent (
00183   VOID
00184   )
00185 {
00186   return;
00187 }
00188 
00189 VOID
00190 LibReportStatusCodeInitialize (
00191   VOID
00192   )
00193 {
00194   return;
00195 }
00196 
00197 
00198 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines