/** * Describes utility functions for parsing CPER into JSON IR. * * Author: Lawrence.Tang@arm.com **/ #include #include "json.h" #include "edk/Cper.h" #include "cper-utils.h" //The available severity types for CPER. const char* CPER_SEVERITY_TYPES[4] = {"Recoverable", "Fatal", "Corrected", "Informational"}; //Converts the given generic CPER error status to JSON IR. json_object* cper_generic_error_status_to_ir(EFI_GENERIC_ERROR_STATUS* error_status) { json_object* error_status_ir = json_object_new_object(); //Error type. json_object_object_add(error_status_ir, "errorType", integer_to_readable_pair_with_desc(error_status->Type, 18, CPER_GENERIC_ERROR_TYPES_KEYS, CPER_GENERIC_ERROR_TYPES_VALUES, CPER_GENERIC_ERROR_TYPES_DESCRIPTIONS, "Unknown (Reserved)")); //Boolean bit fields. json_object_object_add(error_status_ir, "addressSignal", json_object_new_boolean(error_status->AddressSignal)); json_object_object_add(error_status_ir, "controlSignal", json_object_new_boolean(error_status->ControlSignal)); json_object_object_add(error_status_ir, "dataSignal", json_object_new_boolean(error_status->DataSignal)); json_object_object_add(error_status_ir, "detectedByResponder", json_object_new_boolean(error_status->DetectedByResponder)); json_object_object_add(error_status_ir, "detectedByRequester", json_object_new_boolean(error_status->DetectedByRequester)); json_object_object_add(error_status_ir, "firstError", json_object_new_boolean(error_status->FirstError)); json_object_object_add(error_status_ir, "overflowNotLogged", json_object_new_boolean(error_status->OverflowNotLogged)); return error_status_ir; } //Converts a single uniform struct of UINT64s into intermediate JSON IR format, given names for each field in byte order. json_object* uniform_struct64_to_ir(UINT64* start, int len, const char* names[]) { json_object* result = json_object_new_object(); UINT64* cur = start; for (int i=0; i> i) & 0b1)); } return result; } //Converts the given UINT64 array into a JSON IR array, given the length. json_object* uint64_array_to_ir_array(UINT64* array, int len) { json_object* array_ir = json_object_new_array(); for (int i=0; i> 8)); json_object_object_add(revision_info, "minor", json_object_new_int(revision & 0xFF)); return revision_info; } //Returns the appropriate string for the given integer severity. const char* severity_to_string(UINT8 severity) { return severity < 4 ? CPER_SEVERITY_TYPES[severity] : "Unknown"; } //Helper function to convert an EDK EFI GUID into a string for intermediate use. void guid_to_string(char* out, EFI_GUID* guid) { sprintf(out, "%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x", guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); } //Returns one if two EFI GUIDs are equal, zero otherwise. int guid_equal(EFI_GUID* a, EFI_GUID* b) { //Check top base 3 components. if (a->Data1 != b->Data1 || a->Data2 != b->Data2 || a->Data3 != b->Data3) { return 0; } //Check Data4 array for equality. for (int i=0; i<8; i++) { if (a->Data4[i] != b->Data4[i]) return 0; } return 1; } //Converts the given BCD byte to a standard integer. int bcd_to_int(UINT8 bcd) { return ((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F); }