Add support for processor generic sections.
diff --git a/cper-parse.c b/cper-parse.c
index 86fa80d..58f8360 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -187,23 +187,11 @@
json_object_object_add(header_ir, "recordID", json_object_new_uint64(header->RecordID));
//Flag for the record, and a human readable form.
- json_object* flags = json_object_new_object();
- json_object_object_add(flags, "value", json_object_new_int(header->Flags));
- char* flags_readable = "Unknown";
- switch (header->Flags)
- {
- case 1:
- flags_readable = "HW_ERROR_FLAGS_RECOVERED";
- break;
- case 2:
- flags_readable = "HW_ERROR_FLAGS_PREVERR";
- break;
- case 3:
- flags_readable = "HW_ERROR_FLAGS_SIMULATED";
- break;
-
- }
- json_object_object_add(flags, "type", json_object_new_string(flags_readable));
+ json_object* flags = integer_to_readable_pair(header->Flags,
+ sizeof(CPER_HEADER_FLAG_TYPES_KEYS) / sizeof(int),
+ CPER_HEADER_FLAG_TYPES_KEYS,
+ CPER_HEADER_FLAG_TYPES_VALUES,
+ "Unknown");
json_object_object_add(header_ir, "flags", flags);
//Persistence information. Outside the scope of specification, so just a uint32 here.
diff --git a/cper-parse.h b/cper-parse.h
index 0fc08b8..8bb883a 100644
--- a/cper-parse.h
+++ b/cper-parse.h
@@ -2,6 +2,9 @@
#define CPER_PARSE_H
#include "json.h"
+#define CPER_HEADER_FLAG_TYPES_KEYS (int []){1, 2, 3}
+#define CPER_HEADER_FLAG_TYPES_VALUES (const char*[]){"HW_ERROR_FLAGS_RECOVERED", "HW_ERROR_FLAGS_PREVERR", "HW_ERROR_FLAGS_SIMULATED"}
+
json_object* cper_to_ir(const char* filename);
#endif
\ No newline at end of file
diff --git a/cper-utils.c b/cper-utils.c
index 454d93d..b76ca0f 100644
--- a/cper-utils.c
+++ b/cper-utils.c
@@ -12,6 +12,24 @@
//The available severity types for CPER.
const char* CPER_SEVERITY_TYPES[4] = {"Recoverable", "Fatal", "Corrected", "Informational"};
+//Converts a single integer value to an object containing a value, and a readable name if possible.
+json_object* integer_to_readable_pair(int value, int len, int keys[], const char* values[], const char* default_value)
+{
+ json_object* result = json_object_new_object();
+ json_object_object_add(result, "value", json_object_new_int(value));
+
+ //Search for human readable name, add.
+ char* name = default_value;
+ for (int i=0; i<len; i++)
+ {
+ if (keys[i] == value)
+ name = values[i];
+ }
+
+ json_object_object_add(result, "name", json_object_new_string(name));
+ return result;
+}
+
//Converts a single UINT16 revision number into JSON IR representation.
json_object* revision_to_ir(UINT16 revision)
{
diff --git a/cper-utils.h b/cper-utils.h
index f24f927..aa5265b 100644
--- a/cper-utils.h
+++ b/cper-utils.h
@@ -4,6 +4,7 @@
#define GUID_STRING_LENGTH 30
#define TIMESTAMP_LENGTH 24
+json_object* integer_to_readable_pair(int value, int len, int keys[], const char* values[], const char* default_value);
json_object* revision_to_ir(UINT16 revision);
const char* severity_to_string(UINT8 severity);
void guid_to_string(char* out, EFI_GUID* guid);
diff --git a/sections/cper-section-generic.c b/sections/cper-section-generic.c
index 8550339..c83679c 100644
--- a/sections/cper-section-generic.c
+++ b/sections/cper-section-generic.c
@@ -9,9 +9,86 @@
#include "json.h"
#include "../edk/Cper.h"
#include "../cper-utils.h"
+#include "cper-section-generic.h"
//Converts the given processor-generic CPER section into JSON IR.
json_object* cper_section_generic_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
{
- return NULL; //todo
+ EFI_PROCESSOR_GENERIC_ERROR_DATA* section_generic = (EFI_PROCESSOR_GENERIC_ERROR_DATA*)section;
+ json_object* section_ir = json_object_new_object();
+
+ //Validation bits.
+ json_object* validation = json_object_new_object();
+ json_object_object_add(validation, "processorTypeValid", json_object_new_boolean(section_generic->ValidFields >> 63));
+ json_object_object_add(validation, "processorISAValid", json_object_new_boolean((section_generic->ValidFields >> 62) & 0x1));
+ json_object_object_add(validation, "processorErrorTypeValid", json_object_new_boolean((section_generic->ValidFields >> 61) & 0x1));
+ json_object_object_add(validation, "operationValid", json_object_new_boolean((section_generic->ValidFields >> 60) & 0x1));
+ json_object_object_add(validation, "flagsValid", json_object_new_boolean((section_generic->ValidFields >> 59) & 0x1));
+ json_object_object_add(validation, "levelValid", json_object_new_boolean((section_generic->ValidFields >> 58) & 0x1));
+ json_object_object_add(validation, "cpuVersionValid", json_object_new_boolean((section_generic->ValidFields >> 57) & 0x1));
+ json_object_object_add(validation, "cpuBrandInfoValid", json_object_new_boolean((section_generic->ValidFields >> 56) & 0x1));
+ json_object_object_add(validation, "cpuIDValid", json_object_new_boolean((section_generic->ValidFields >> 55) & 0x1));
+ json_object_object_add(validation, "targetAddressValid", json_object_new_boolean((section_generic->ValidFields >> 54) & 0x1));
+ json_object_object_add(validation, "requesterIDValid", json_object_new_boolean((section_generic->ValidFields >> 53) & 0x1));
+ json_object_object_add(validation, "responderIDValid", json_object_new_boolean((section_generic->ValidFields >> 52) & 0x1));
+ json_object_object_add(validation, "instructionIPValid", json_object_new_boolean((section_generic->ValidFields >> 51) & 0x1));
+ json_object_object_add(section_ir, "validationBits", validation);
+
+ //Processor type, with human readable name if possible.
+ json_object* processor_type = integer_to_readable_pair(section_generic->Type,
+ sizeof(GENERIC_PROC_TYPES_KEYS) / sizeof(int),
+ GENERIC_PROC_TYPES_KEYS,
+ GENERIC_PROC_TYPES_VALUES,
+ "Unknown (Reserved)");
+ json_object_object_add(section_ir, "processorType", processor_type);
+
+ //Processor ISA, with human readable name if possible.
+ json_object* processor_isa = integer_to_readable_pair(section_generic->Isa,
+ sizeof(GENERIC_ISA_TYPES_KEYS) / sizeof(int),
+ GENERIC_ISA_TYPES_KEYS,
+ GENERIC_ISA_TYPES_VALUES,
+ "Unknown (Reserved");
+ json_object_object_add(section_ir, "processorISA", processor_isa);
+
+ //Processor error type, with human readable name if possible.
+ json_object* processor_error_type = integer_to_readable_pair(section_generic->ErrorType,
+ sizeof(GENERIC_ERROR_TYPES_KEYS) / sizeof(int),
+ GENERIC_ERROR_TYPES_KEYS,
+ GENERIC_ERROR_TYPES_VALUES,
+ "Unknown (Reserved");
+ json_object_object_add(section_ir, "errorType", processor_error_type);
+
+ //The operation performed, with a human readable name if possible.
+ json_object* operation = integer_to_readable_pair(section_generic->Operation,
+ sizeof(GENERIC_OPERATION_TYPES_KEYS) / sizeof(int),
+ GENERIC_OPERATION_TYPES_KEYS,
+ GENERIC_OPERATION_TYPES_VALUES,
+ "Unknown (Reserved");
+ json_object_object_add(section_ir, "operation", operation);
+
+ //Flags, additional information about the error.
+ json_object* flags = json_object_new_object();
+ json_object_object_add(flags, "restartable", json_object_new_boolean(section_generic->Flags >> 7));
+ json_object_object_add(flags, "preciseIP", json_object_new_boolean((section_generic->Flags >> 6) & 0b1));
+ json_object_object_add(flags, "overflow", json_object_new_boolean((section_generic->Flags >> 5) & 0b1));
+ json_object_object_add(flags, "corrected", json_object_new_boolean((section_generic->Flags >> 4) & 0b1));
+ json_object_object_add(section_ir, "flags", flags);
+
+ //The level of the error.
+ json_object_object_add(section_ir, "level", json_object_new_int(section_generic->Level));
+
+ //CPU version information (todo)
+ //...
+
+ //CPU brand string. May not exist if on ARM.
+ json_object_object_add(section_ir, "cpuBrandString", json_object_new_string(section_generic->BrandString));
+
+ //Remaining 64-bit fields.
+ json_object_object_add(section_ir, "processorID", json_object_new_uint64(section_generic->ApicId));
+ json_object_object_add(section_ir, "targetAddress", json_object_new_uint64(section_generic->TargetAddr));
+ json_object_object_add(section_ir, "requestorID", json_object_new_uint64(section_generic->RequestorId));
+ json_object_object_add(section_ir, "responderID", json_object_new_uint64(section_generic->ResponderId));
+ json_object_object_add(section_ir, "instructionIP", json_object_new_uint64(section_generic->InstructionIP));
+
+ return section_ir;
}
\ No newline at end of file
diff --git a/sections/cper-section-generic.h b/sections/cper-section-generic.h
index 56868f7..a5fb930 100644
--- a/sections/cper-section-generic.h
+++ b/sections/cper-section-generic.h
@@ -1,6 +1,15 @@
#ifndef CPER_SECTION_GENERIC_H
#define CPER_SECTION_GENERIC_H
+#define GENERIC_PROC_TYPES_KEYS (int []){0, 1, 2}
+#define GENERIC_PROC_TYPES_VALUES (const char*[]){"IA32/X64", "IA64", "ARM"}
+#define GENERIC_ISA_TYPES_KEYS (int []){0, 1, 2, 3, 4}
+#define GENERIC_ISA_TYPES_VALUES (const char*[]){"IA32", "IA64", "X64", "ARM A32/T32", "ARM A64"}
+#define GENERIC_ERROR_TYPES_KEYS (int []){0, 1, 2, 4, 8}
+#define GENERIC_ERROR_TYPES_VALUES (const char*[]){"Unknown", "Cache Error", "TLB Error", "Bus Error", "Micro-Architectural Error"}
+#define GENERIC_OPERATION_TYPES_KEYS (int []){0, 1, 2, 3}
+#define GENERIC_OPERATION_TYPES_VALUES (const char*[]){"Unknown or generic", "Data Read", "Data Write", "Instruction Execution"}
+
json_object* cper_section_generic_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
#endif
\ No newline at end of file