Add untested IA32/x64 log support.
diff --git a/cper-parse.c b/cper-parse.c
index 58f8360..ffdd45f 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -11,6 +11,7 @@
#include "cper-parse.h"
#include "cper-utils.h"
#include "sections/cper-section-generic.h"
+#include "sections/cper-section-ia32x64.h"
//Private pre-definitions.
json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header);
@@ -158,27 +159,27 @@
char* notification_type_readable = "Unknown";
if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCmcGuid))
notification_type_readable = "CMC";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCpeGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCpeGuid))
notification_type_readable = "CPE";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeMceGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeMceGuid))
notification_type_readable = "MCE";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePcieGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePcieGuid))
notification_type_readable = "PCIe";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeInitGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeInitGuid))
notification_type_readable = "INIT";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeNmiGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeNmiGuid))
notification_type_readable = "NMI";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeBootGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeBootGuid))
notification_type_readable = "Boot";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeDmarGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeDmarGuid))
notification_type_readable = "DMAr";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeaGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeaGuid))
notification_type_readable = "SEA";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeiGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeiGuid))
notification_type_readable = "SEI";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePeiGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePeiGuid))
notification_type_readable = "PEI";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCxlGuid))
+ else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCxlGuid))
notification_type_readable = "CXL Component";
json_object_object_add(notification_type, "type", json_object_new_string(notification_type_readable));
json_object_object_add(header_ir, "notificationType", notification_type);
@@ -308,8 +309,8 @@
json_object* result = NULL;
if (guid_equal(&descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
result = cper_section_generic_to_ir(handle, descriptor);
- // if (guid_equal(&descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
- // result = cper_section_ia32x64_to_ir(handle);
+ if (guid_equal(&descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
+ result = cper_section_ia32x64_to_ir(handle, descriptor);
// //todo: Why does IPF have an overly long GUID?
// // if (guid_equal(&descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid))
// if (guid_equal(&descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid))
diff --git a/cper-utils.c b/cper-utils.c
index b76ca0f..61a796a 100644
--- a/cper-utils.c
+++ b/cper-utils.c
@@ -19,7 +19,7 @@
json_object_object_add(result, "value", json_object_new_int(value));
//Search for human readable name, add.
- char* name = default_value;
+ const char* name = default_value;
for (int i=0; i<len; i++)
{
if (keys[i] == value)
@@ -30,6 +30,43 @@
return result;
}
+//Converts the given uint8 bitfield to IR, assuming bit 0 starts on the left.
+json_object* bitfield8_to_ir(UINT8 bitfield, int num_fields, const char* names[])
+{
+ json_object* result = json_object_new_object();
+ for (int i=0; i<num_fields; i++)
+ {
+ json_object_object_add(result, names[i], json_object_new_boolean((bitfield >> (7 - i)) & 0b1));
+ }
+
+ return result;
+}
+
+//Converts the given bitfield to IR, assuming bit 0 starts on the left.
+json_object* bitfield_to_ir(UINT32 bitfield, int num_fields, const char* names[])
+{
+ json_object* result = json_object_new_object();
+ for (int i=0; i<num_fields; i++)
+ {
+ json_object_object_add(result, names[i], json_object_new_boolean((bitfield >> (31 - i)) & 0b1));
+ }
+
+ return result;
+}
+
+//Converts the given 64 bit bitfield to IR, assuming bit 0 starts on the left.
+json_object* bitfield64_to_ir(UINT64 bitfield, int num_fields, const char* names[])
+{
+ json_object* result = json_object_new_object();
+ for (int i=0; i<num_fields; i++)
+ {
+ json_object_object_add(result, names[i], json_object_new_boolean((bitfield >> (63 - i)) & 0b1));
+ }
+
+ 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 aa5265b..9446237 100644
--- a/cper-utils.h
+++ b/cper-utils.h
@@ -5,6 +5,9 @@
#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* bitfield8_to_ir(UINT8 bitfield, int num_fields, const char* names[]);
+json_object* bitfield_to_ir(UINT32 bitfield, int num_fields, const char* names[]);
+json_object* bitfield64_to_ir(UINT64 bitfield, int num_fields, const char* names[]);
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/edk/Cper.c b/edk/Cper.c
index 6870628..6f557d8 100644
--- a/edk/Cper.c
+++ b/edk/Cper.c
@@ -5,6 +5,7 @@
**/
#include "Cper.h"
+//Event notification type GUIDs.
EFI_GUID gEfiEventNotificationTypeCmcGuid = { 0x2DCE8BB1, 0xBDD7, 0x450e, { 0xB9, 0xAD, 0x9C, 0xF4, 0xEB, 0xD4, 0xF8, 0x90 }};
EFI_GUID gEfiEventNotificationTypeCpeGuid = { 0x4E292F96, 0xD843, 0x4a55, { 0xA8, 0xC2, 0xD4, 0x81, 0xF2, 0x7E, 0xBE, 0xEE }};
EFI_GUID gEfiEventNotificationTypeMceGuid = { 0xE8F56FFE, 0x919C, 0x4cc5, { 0xBA, 0x88, 0x65, 0xAB, 0xE1, 0x49, 0x13, 0xBB }};
@@ -17,6 +18,8 @@
EFI_GUID gEfiEventNotificationTypeSeiGuid = { 0x5C284C81, 0xB0AE, 0x4E87, { 0xA3, 0x22, 0xB0, 0x4C, 0x85, 0x62, 0x43, 0x23 }};
EFI_GUID gEfiEventNotificationTypePeiGuid = { 0x09A9D5AC, 0x5204, 0x4214, { 0x96, 0xE5, 0x94, 0x99, 0x2E, 0x75, 0x2B, 0xCD }};
EFI_GUID gEfiEventNotificationTypeCxlGuid = { 0x69293BC9, 0x41DF, 0x49A3, { 0xB4, 0xBD, 0x4F, 0xB0, 0xDB, 0x30, 0x41, 0xF6 }};
+
+//Error section GUIDs.
EFI_GUID gEfiProcessorGenericErrorSectionGuid = { 0x9876ccad, 0x47b4, 0x4bdb, { 0xb6, 0x5e, 0x16, 0xf1, 0x93, 0xc4, 0xf3, 0xdb }};
EFI_GUID gEfiProcessorSpecificErrorSectionGuid = { 0xdc3ea0b0, 0xa144, 0x4797, { 0xb9, 0x5b, 0x53, 0xfa, 0x24, 0x2b, 0x6e, 0x1d }};
EFI_GUID gEfiIa32X64ProcessorErrorSectionGuid = { 0xdc3ea0b0, 0xa144, 0x4797, { 0xb9, 0x5b, 0x53, 0xfa, 0x24, 0x2b, 0x6e, 0x1d }};
@@ -30,4 +33,10 @@
EFI_GUID gEfiPciDevErrorSectionGuid = { 0xeb5e4685, 0xca66, 0x4769, { 0xb6, 0xa2, 0x26, 0x06, 0x8b, 0x00, 0x13, 0x26 }};
EFI_GUID gEfiDMArGenericErrorSectionGuid = { 0x5b51fef7, 0xc79d, 0x4434, { 0x8f, 0x1b, 0xaa, 0x62, 0xde, 0x3e, 0x2c, 0x64 }};
EFI_GUID gEfiDirectedIoDMArErrorSectionGuid = { 0x71761d37, 0x32b2, 0x45cd, { 0xa7, 0xd0, 0xb0, 0xfe, 0xdd, 0x93, 0xe8, 0xcf }};
-EFI_GUID gEfiIommuDMArErrorSectionGuid = { 0x036f84e1, 0x7f37, 0x428c, { 0xa7, 0x9e, 0x57, 0x5f, 0xdf, 0xaa, 0x84, 0xec }};
\ No newline at end of file
+EFI_GUID gEfiIommuDMArErrorSectionGuid = { 0x036f84e1, 0x7f37, 0x428c, { 0xa7, 0x9e, 0x57, 0x5f, 0xdf, 0xaa, 0x84, 0xec }};
+
+//IA32/x64 error segment GUIDs.
+EFI_GUID gEfiIa32x64ErrorTypeCacheCheckGuid = { 0xA55701F5, 0xE3EF, 0x43de, {0xAC, 0x72, 0x24, 0x9B, 0x57, 0x3F, 0xAD, 0x2C } };
+EFI_GUID gEfiIa32x64ErrorTypeTlbCheckGuid = { 0xFC06B535, 0x5E1F, 0x4562, {0x9F, 0x25, 0x0A, 0x3B, 0x9A, 0xDB, 0x63, 0xC3 } };
+EFI_GUID gEfiIa32x64ErrorTypeBusCheckGuid = { 0x1CF3F8B3, 0xC5B1, 0x49a2, {0xAA, 0x59, 0x5E, 0xEF, 0x92, 0xFF, 0xA6, 0x3C } };
+EFI_GUID gEfiIa32x64ErrorTypeMsCheckGuid = { 0x48AB7F57, 0xDC34, 0x4f6c, {0xA7, 0xD3, 0xB0, 0xB5, 0xB0, 0xA7, 0x43, 0x14 } };
\ No newline at end of file
diff --git a/edk/Cper.h b/edk/Cper.h
index 7a3f510..3723f5f 100644
--- a/edk/Cper.h
+++ b/edk/Cper.h
@@ -328,7 +328,6 @@
UINT64 InstructionIP;
} EFI_PROCESSOR_GENERIC_ERROR_DATA;
-#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
///
/// IA32 and x64 Specific definitions.
///
@@ -353,6 +352,11 @@
{ \
0x48AB7F57, 0xDC34, 0x4f6c, {0xA7, 0xD3, 0xB0, 0xB5, 0xB0, 0xA7, 0x43, 0x14 } \
}
+extern EFI_GUID gEfiIa32x64ErrorTypeCacheCheckGuid;
+extern EFI_GUID gEfiIa32x64ErrorTypeTlbCheckGuid;
+extern EFI_GUID gEfiIa32x64ErrorTypeBusCheckGuid;
+extern EFI_GUID gEfiIa32x64ErrorTypeMsCheckGuid;
+
///@}
///
@@ -735,8 +739,6 @@
UINT64 Resv1 : 50;
} EFI_IA32_X64_VALID_BITS;
-#endif
-
///
/// Error Status Fields
///
diff --git a/sections/cper-section-generic.c b/sections/cper-section-generic.c
index c83679c..2745b06 100644
--- a/sections/cper-section-generic.c
+++ b/sections/cper-section-generic.c
@@ -18,20 +18,7 @@
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* validation = bitfield64_to_ir(section_generic->ValidFields, 13, GENERIC_VALIDATION_BITFIELD_NAMES);
json_object_object_add(section_ir, "validationBits", validation);
//Processor type, with human readable name if possible.
@@ -67,11 +54,7 @@
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* flags = bitfield8_to_ir(section_generic->Flags, 4, GENERIC_FLAGS_BITFIELD_NAMES);
json_object_object_add(section_ir, "flags", flags);
//The level of the error.
diff --git a/sections/cper-section-generic.h b/sections/cper-section-generic.h
index a5fb930..2b548b6 100644
--- a/sections/cper-section-generic.h
+++ b/sections/cper-section-generic.h
@@ -1,6 +1,9 @@
#ifndef CPER_SECTION_GENERIC_H
#define CPER_SECTION_GENERIC_H
+#include "json.h"
+#include "../edk/Cper.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}
@@ -9,6 +12,12 @@
#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"}
+#define GENERIC_VALIDATION_BITFIELD_NAMES (const char*[]) \
+ {"processorTypeValid", "processorISAValid", "processorErrorTypeValid", "operationValid", "flagsValid" \
+ "levelValid", "cpuVersionValid", "cpuBrandInfoValid", "cpuIDValid", "targetAddressValid", "requesterIDValid" \
+ "responderIDValid", "instructionIPValid"}
+#define GENERIC_FLAGS_BITFIELD_NAMES (const char*[]) \
+ {"restartable", "preciseIP", "overflow", "corrected"}
json_object* cper_section_generic_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
diff --git a/sections/cper-section-ia32x64.c b/sections/cper-section-ia32x64.c
new file mode 100644
index 0000000..187446a
--- /dev/null
+++ b/sections/cper-section-ia32x64.c
@@ -0,0 +1,337 @@
+/**
+ * Describes functions for converting IA32/x64 CPER sections from binary and JSON format
+ * into an intermediate format.
+ *
+ * Author: Lawrence.Tang@arm.com
+ **/
+
+#include <stdio.h>
+#include "json.h"
+#include "../edk/Cper.h"
+#include "../cper-utils.h"
+#include "cper-section-ia32x64.h"
+
+//Private pre-definitions.
+json_object* cper_ia32x64_processor_error_info_to_ir(EFI_IA32_X64_PROCESS_ERROR_INFO* error_info);
+json_object* cper_ia32x64_cache_tlb_check_to_ir(EFI_IA32_X64_CACHE_CHECK_INFO* cache_tlb_check);
+json_object* cper_ia32x64_bus_check_to_ir(EFI_IA32_X64_BUS_CHECK_INFO* bus_check);
+json_object* cper_ia32x64_ms_check_to_ir(EFI_IA32_X64_MS_CHECK_INFO* ms_check);
+json_object* cper_ia32x64_processor_context_info_to_ir(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO* context_info, void** cur_pos);
+json_object* cper_ia32x64_register_32bit_to_ir(EFI_CONTEXT_IA32_REGISTER_STATE* registers);
+json_object* cper_ia32x64_register_64bit_to_ir(EFI_CONTEXT_X64_REGISTER_STATE* registers);
+
+//Converts the IA32/x64 error section described in the given descriptor into intermediate format.
+json_object* cper_section_ia32x64_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+{
+ EFI_IA32_X64_PROCESSOR_ERROR_RECORD* record = (EFI_IA32_X64_PROCESSOR_ERROR_RECORD*)section;
+ json_object* record_ir = json_object_new_object();
+
+ //Flags.
+ json_object* flags = json_object_new_object();
+ json_object_object_add(flags, "localAPICIDValid", json_object_new_boolean(record->ValidFields >> 31));
+ json_object_object_add(flags, "cpuIDInfoValid", json_object_new_boolean((record->ValidFields >> 30) & 0b1));
+ int processor_error_info_num = (record->ValidFields >> 29) & 0b111111;
+ json_object_object_add(flags, "processorErrorInfoNum", json_object_new_int(processor_error_info_num));
+ int processor_context_info_num = (record->ValidFields >> 23) & 0b111111;
+ json_object_object_add(flags, "processorContextInfoNum", json_object_new_int(processor_context_info_num));
+ json_object_object_add(record_ir, "flags", flags);
+
+ //APIC ID.
+ json_object_object_add(record_ir, "localAPICID", json_object_new_uint64(record->ApicId));
+
+ //CPU ID information (todo, see generic).
+ //...
+
+ //Processor error information, of the amount described above.
+ EFI_IA32_X64_PROCESS_ERROR_INFO* current_error_info = (EFI_IA32_X64_PROCESS_ERROR_INFO*)(record + 1);
+ json_object* error_info_array = json_object_new_array();
+ for (int i=0; i<processor_error_info_num; i++)
+ {
+ json_object_array_add(error_info_array, cper_ia32x64_processor_error_info_to_ir(current_error_info));
+ current_error_info++;
+ }
+ json_object_object_add(record_ir, "processorErrorInfo", error_info_array);
+
+ //Processor context information, of the amount described above.
+ EFI_IA32_X64_PROCESSOR_CONTEXT_INFO* current_context_info = (EFI_IA32_X64_PROCESSOR_CONTEXT_INFO*)(current_error_info + 1);
+ json_object* context_info_array = json_object_new_array();
+ for (int i=0; i<processor_context_info_num; i++)
+ {
+ json_object_array_add(context_info_array, cper_ia32x64_processor_context_info_to_ir(current_context_info, (void**)¤t_context_info));
+ //The context array is a non-fixed size, pointer is shifted within the above function.
+ }
+ json_object_object_add(record_ir, "processorContextInfo", context_info_array);
+
+ return record_ir;
+}
+
+//Converts a single IA32/x64 processor error info block into JSON IR format.
+json_object* cper_ia32x64_processor_error_info_to_ir(EFI_IA32_X64_PROCESS_ERROR_INFO* error_info)
+{
+ json_object* error_info_ir = json_object_new_object();
+
+ //Error structure type (as GUID).
+ char error_type[GUID_STRING_LENGTH];
+ guid_to_string(error_type, &error_info->ErrorType);
+ json_object_object_add(error_info_ir, "type", json_object_new_string(error_type));
+
+ //Validation bits.
+ json_object* validation = bitfield64_to_ir(error_info->ValidFields, 5, IA32X64_PROCESSOR_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(error_info_ir, "validationBits", validation);
+
+ //Add the check information on a per-structure basis.
+ //Cache and TLB check information are identical, so can be equated.
+ json_object* checkInformation = NULL;
+ if (guid_equal(&error_info->ErrorType, &gEfiIa32x64ErrorTypeCacheCheckGuid)
+ || guid_equal(&error_info->ErrorType, &gEfiIa32x64ErrorTypeTlbCheckGuid))
+ {
+ checkInformation = cper_ia32x64_cache_tlb_check_to_ir((EFI_IA32_X64_CACHE_CHECK_INFO*)&error_info->CheckInfo);
+ }
+ else if (guid_equal(&error_info->ErrorType, &gEfiIa32x64ErrorTypeBusCheckGuid))
+ checkInformation = cper_ia32x64_bus_check_to_ir((EFI_IA32_X64_BUS_CHECK_INFO*)&error_info->CheckInfo);
+ else if (guid_equal(&error_info->ErrorType, &gEfiIa32x64ErrorTypeMsCheckGuid))
+ checkInformation = cper_ia32x64_ms_check_to_ir((EFI_IA32_X64_MS_CHECK_INFO*)&error_info->CheckInfo);
+ json_object_object_add(error_info_ir, "checkInfo", checkInformation);
+
+ //Target, requestor, and responder identifiers.
+ json_object_object_add(error_info_ir, "targetIdentifier", json_object_new_uint64(error_info->TargetId));
+ json_object_object_add(error_info_ir, "requestorIdentifier", json_object_new_uint64(error_info->RequestorId));
+ json_object_object_add(error_info_ir, "responderIdentifier", json_object_new_uint64(error_info->ResponderId));
+ json_object_object_add(error_info_ir, "instructionPointer", json_object_new_uint64(error_info->InstructionIP));
+
+ return error_info_ir;
+}
+
+//Converts a single IA32/x64 cache or TLB check check info block into JSON IR format.
+json_object* cper_ia32x64_cache_tlb_check_to_ir(EFI_IA32_X64_CACHE_CHECK_INFO* cache_tlb_check)
+{
+ json_object* cache_tlb_check_ir = json_object_new_object();
+
+ //Validation bits.
+ json_object* validation = bitfield_to_ir(cache_tlb_check->ValidFields, 8, IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES);
+ json_object_object_add(cache_tlb_check_ir, "validationBits", validation);
+
+ //Transaction type.
+ json_object* transaction_type = integer_to_readable_pair(cache_tlb_check->TransactionType, 3,
+ IA32X64_CHECK_INFO_TRANSACTION_TYPES_KEYS,
+ IA32X64_CHECK_INFO_TRANSACTION_TYPES_VALUES,
+ "Unknown (Reserved)");
+ json_object_object_add(cache_tlb_check_ir, "transactionType", transaction_type);
+
+ //Operation.
+ json_object* operation = integer_to_readable_pair(cache_tlb_check->Operation, 9,
+ IA32X64_CHECK_INFO_OPERATION_TYPES_KEYS,
+ IA32X64_CHECK_INFO_OPERATION_TYPES_VALUES,
+ "Unknown (Reserved)");
+ json_object_object_add(cache_tlb_check_ir, "operation", operation);
+
+ //Affected cache/TLB level.
+ json_object_object_add(cache_tlb_check_ir, "level", json_object_new_uint64(cache_tlb_check->Level));
+
+ //Miscellaneous boolean fields.
+ json_object_object_add(cache_tlb_check_ir, "processorContextCorrupt", json_object_new_boolean(cache_tlb_check->ContextCorrupt));
+ json_object_object_add(cache_tlb_check_ir, "uncorrected", json_object_new_boolean(cache_tlb_check->ErrorUncorrected));
+ json_object_object_add(cache_tlb_check_ir, "preciseIP", json_object_new_boolean(cache_tlb_check->PreciseIp));
+ json_object_object_add(cache_tlb_check_ir, "restartableIP", json_object_new_boolean(cache_tlb_check->RestartableIp));
+ json_object_object_add(cache_tlb_check_ir, "overflow", json_object_new_boolean(cache_tlb_check->Overflow));
+
+ return cache_tlb_check_ir;
+}
+
+//Converts a single IA32/x64 bus check check info block into JSON IR format.
+json_object* cper_ia32x64_bus_check_to_ir(EFI_IA32_X64_BUS_CHECK_INFO* bus_check)
+{
+ json_object* bus_check_ir = json_object_new_object();
+
+ //Validation bits.
+ json_object* validation = bitfield_to_ir(bus_check->ValidFields, 11, IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES);
+ json_object_object_add(bus_check_ir, "validationBits", validation);
+
+ //Transaction type.
+ json_object* transaction_type = integer_to_readable_pair(bus_check->TransactionType, 3,
+ IA32X64_CHECK_INFO_TRANSACTION_TYPES_KEYS,
+ IA32X64_CHECK_INFO_TRANSACTION_TYPES_VALUES,
+ "Unknown (Reserved)");
+ json_object_object_add(bus_check_ir, "transactionType", transaction_type);
+
+ //Operation.
+ json_object* operation = integer_to_readable_pair(bus_check->Operation, 9,
+ IA32X64_CHECK_INFO_OPERATION_TYPES_KEYS,
+ IA32X64_CHECK_INFO_OPERATION_TYPES_VALUES,
+ "Unknown (Reserved)");
+ json_object_object_add(bus_check_ir, "operation", operation);
+
+ //Affected bus level.
+ json_object_object_add(bus_check_ir, "level", json_object_new_uint64(bus_check->Level));
+
+ //Miscellaneous boolean fields.
+ json_object_object_add(bus_check_ir, "processorContextCorrupt", json_object_new_boolean(bus_check->ContextCorrupt));
+ json_object_object_add(bus_check_ir, "uncorrected", json_object_new_boolean(bus_check->ErrorUncorrected));
+ json_object_object_add(bus_check_ir, "preciseIP", json_object_new_boolean(bus_check->PreciseIp));
+ json_object_object_add(bus_check_ir, "restartableIP", json_object_new_boolean(bus_check->RestartableIp));
+ json_object_object_add(bus_check_ir, "overflow", json_object_new_boolean(bus_check->Overflow));
+ json_object_object_add(bus_check_ir, "timedOut", json_object_new_boolean(bus_check->TimeOut));
+
+ //Participation type.
+ json_object* participation_type = integer_to_readable_pair(bus_check->ParticipationType, 4,
+ IA32X64_BUS_CHECK_INFO_PARTICIPATION_TYPES_KEYS,
+ IA32X64_BUS_CHECK_INFO_PARTICIPATION_TYPES_VALUES,
+ "Unknown");
+ json_object_object_add(bus_check_ir, "participationType", participation_type);
+
+ //Address space.
+ json_object* address_space = integer_to_readable_pair(bus_check->AddressSpace, 4,
+ IA32X64_BUS_CHECK_INFO_ADDRESS_SPACE_TYPES_KEYS,
+ IA32X64_BUS_CHECK_INFO_ADDRESS_SPACE_TYPES_VALUES,
+ "Unknown");
+ json_object_object_add(bus_check_ir, "addressSpace", address_space);
+
+ return bus_check_ir;
+}
+
+//Converts a single IA32/x64 MS check check info block into JSON IR format.
+json_object* cper_ia32x64_ms_check_to_ir(EFI_IA32_X64_MS_CHECK_INFO* ms_check)
+{
+ json_object* ms_check_ir = json_object_new_object();
+
+ //Validation bits.
+ json_object* validation = bitfield_to_ir(ms_check->ValidFields, 6, IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES);
+ json_object_object_add(ms_check_ir, "validationBits", validation);
+
+ //Error type (operation that caused the error).
+ json_object* error_type = integer_to_readable_pair(ms_check->ErrorType, 4,
+ IA32X64_MS_CHECK_INFO_ERROR_TYPES_KEYS,
+ IA32X64_MS_CHECK_INFO_ERROR_TYPES_VALUES,
+ "Unknown (Processor Specific)");
+ json_object_object_add(ms_check_ir, "errorType", error_type);
+
+ //Miscellaneous fields.
+ json_object_object_add(ms_check_ir, "processorContextCorrupt", json_object_new_boolean(ms_check->ContextCorrupt));
+ json_object_object_add(ms_check_ir, "uncorrected", json_object_new_boolean(ms_check->ErrorUncorrected));
+ json_object_object_add(ms_check_ir, "preciseIP", json_object_new_boolean(ms_check->PreciseIp));
+ json_object_object_add(ms_check_ir, "restartableIP", json_object_new_boolean(ms_check->RestartableIp));
+ json_object_object_add(ms_check_ir, "overflow", json_object_new_boolean(ms_check->Overflow));
+
+ return ms_check_ir;
+}
+
+//Converts a single IA32/x64 processor context info entry into JSON IR format.
+json_object* cper_ia32x64_processor_context_info_to_ir(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO* context_info, void** cur_pos)
+{
+ json_object* context_info_ir = json_object_new_object();
+
+ //Register context type.
+ json_object* context_type = integer_to_readable_pair(context_info->RegisterType, 8,
+ IA32X64_REGISTER_CONTEXT_TYPES_KEYS,
+ IA32X64_REGISTER_CONTEXT_TYPES_VALUES,
+ "Unknown (Reserved)");
+ json_object_object_add(context_info_ir, "registerContextType", context_type);
+
+ //Register array size, MSR and MM address.
+ json_object_object_add(context_info_ir, "registerArraySize", json_object_new_uint64(context_info->ArraySize));
+ json_object_object_add(context_info_ir, "msrAddress", json_object_new_uint64(context_info->MsrAddress));
+ json_object_object_add(context_info_ir, "mmRegisterAddress", json_object_new_uint64(context_info->MmRegisterAddress));
+
+ //Register array.
+ json_object* register_array = NULL;
+ if (context_info->RegisterType == 2)
+ {
+ EFI_CONTEXT_IA32_REGISTER_STATE* register_state = (EFI_CONTEXT_IA32_REGISTER_STATE*)(context_info + 1);
+ register_array = cper_ia32x64_register_32bit_to_ir(register_state);
+ *cur_pos = (void*)(register_state + 1);
+ }
+ else if (context_info->RegisterType == 3)
+ {
+ EFI_CONTEXT_X64_REGISTER_STATE* register_state = (EFI_CONTEXT_X64_REGISTER_STATE*)(context_info + 1);
+ register_array = cper_ia32x64_register_64bit_to_ir(register_state);
+ *cur_pos = (void*)(register_state + 1);
+ }
+ else
+ {
+ //No parseable data, just shift the head to the next item.
+ //todo: Dump the unparseable data into JSON IR anyway
+ *cur_pos = (void*)(context_info + 1);
+ *cur_pos = (void*)(((char*)cur_pos) + context_info->ArraySize);
+ }
+ json_object_object_add(context_info_ir, "registerArray", register_array);
+
+ return context_info_ir;
+}
+
+//Converts a single CPER IA32 register state into JSON IR format.
+json_object* cper_ia32x64_register_32bit_to_ir(EFI_CONTEXT_IA32_REGISTER_STATE* registers)
+{
+ json_object* ia32_registers = json_object_new_object();
+ json_object_object_add(ia32_registers, "eax", json_object_new_int(registers->Eax));
+ json_object_object_add(ia32_registers, "ebx", json_object_new_int(registers->Ebx));
+ json_object_object_add(ia32_registers, "ecx", json_object_new_int(registers->Ecx));
+ json_object_object_add(ia32_registers, "edx", json_object_new_int(registers->Edx));
+ json_object_object_add(ia32_registers, "esi", json_object_new_int(registers->Esi));
+ json_object_object_add(ia32_registers, "edi", json_object_new_int(registers->Edi));
+ json_object_object_add(ia32_registers, "ebp", json_object_new_int(registers->Ebp));
+ json_object_object_add(ia32_registers, "esp", json_object_new_int(registers->Esp));
+ json_object_object_add(ia32_registers, "cs", json_object_new_int(registers->Cs));
+ json_object_object_add(ia32_registers, "ds", json_object_new_int(registers->Ds));
+ json_object_object_add(ia32_registers, "ss", json_object_new_int(registers->Ss));
+ json_object_object_add(ia32_registers, "es", json_object_new_int(registers->Es));
+ json_object_object_add(ia32_registers, "fs", json_object_new_int(registers->Fs));
+ json_object_object_add(ia32_registers, "gs", json_object_new_int(registers->Gs));
+ json_object_object_add(ia32_registers, "eflags", json_object_new_int(registers->Eflags));
+ json_object_object_add(ia32_registers, "eip", json_object_new_int(registers->Eip));
+ json_object_object_add(ia32_registers, "cr0", json_object_new_int(registers->Cr0));
+ json_object_object_add(ia32_registers, "cr1", json_object_new_int(registers->Cr1));
+ json_object_object_add(ia32_registers, "cr2", json_object_new_int(registers->Cr2));
+ json_object_object_add(ia32_registers, "cr3", json_object_new_int(registers->Cr3));
+ json_object_object_add(ia32_registers, "cr4", json_object_new_int(registers->Cr4));
+ json_object_object_add(ia32_registers, "gdtr", json_object_new_uint64((registers->Gdtr[0] << 16) + registers->Gdtr[1]));
+ json_object_object_add(ia32_registers, "idtr", json_object_new_uint64((registers->Idtr[0] << 16) + registers->Idtr[1]));
+ json_object_object_add(ia32_registers, "ldtr", json_object_new_int(registers->Ldtr));
+ json_object_object_add(ia32_registers, "tr", json_object_new_int(registers->Tr));
+
+ return ia32_registers;
+}
+
+//Converts a single CPER x64 register state into JSON IR format.
+json_object* cper_ia32x64_register_64bit_to_ir(EFI_CONTEXT_X64_REGISTER_STATE* registers)
+{
+ json_object* x64_registers = json_object_new_object();
+ json_object_object_add(x64_registers, "rax", json_object_new_uint64(registers->Rax));
+ json_object_object_add(x64_registers, "rbx", json_object_new_uint64(registers->Rbx));
+ json_object_object_add(x64_registers, "rcx", json_object_new_uint64(registers->Rcx));
+ json_object_object_add(x64_registers, "rdx", json_object_new_uint64(registers->Rdx));
+ json_object_object_add(x64_registers, "rsi", json_object_new_uint64(registers->Rsi));
+ json_object_object_add(x64_registers, "rdi", json_object_new_uint64(registers->Rdi));
+ json_object_object_add(x64_registers, "rbp", json_object_new_uint64(registers->Rbp));
+ json_object_object_add(x64_registers, "rsp", json_object_new_uint64(registers->Rsp));
+ json_object_object_add(x64_registers, "r8", json_object_new_uint64(registers->R8));
+ json_object_object_add(x64_registers, "r9", json_object_new_uint64(registers->R9));
+ json_object_object_add(x64_registers, "r10", json_object_new_uint64(registers->R10));
+ json_object_object_add(x64_registers, "r11", json_object_new_uint64(registers->R11));
+ json_object_object_add(x64_registers, "r12", json_object_new_uint64(registers->R12));
+ json_object_object_add(x64_registers, "r13", json_object_new_uint64(registers->R13));
+ json_object_object_add(x64_registers, "r14", json_object_new_uint64(registers->R14));
+ json_object_object_add(x64_registers, "r15", json_object_new_uint64(registers->R15));
+ json_object_object_add(x64_registers, "cs", json_object_new_int(registers->Cs));
+ json_object_object_add(x64_registers, "ds", json_object_new_int(registers->Ds));
+ json_object_object_add(x64_registers, "ss", json_object_new_int(registers->Ss));
+ json_object_object_add(x64_registers, "es", json_object_new_int(registers->Es));
+ json_object_object_add(x64_registers, "fs", json_object_new_int(registers->Fs));
+ json_object_object_add(x64_registers, "gs", json_object_new_int(registers->Gs));
+ json_object_object_add(x64_registers, "rflags", json_object_new_uint64(registers->Rflags));
+ json_object_object_add(x64_registers, "eip", json_object_new_uint64(registers->Rip));
+ json_object_object_add(x64_registers, "cr0", json_object_new_uint64(registers->Cr0));
+ json_object_object_add(x64_registers, "cr1", json_object_new_uint64(registers->Cr1));
+ json_object_object_add(x64_registers, "cr2", json_object_new_uint64(registers->Cr2));
+ json_object_object_add(x64_registers, "cr3", json_object_new_uint64(registers->Cr3));
+ json_object_object_add(x64_registers, "cr4", json_object_new_uint64(registers->Cr4));
+ //todo: Where is CR8? On the specification, not in the headers.
+ //json_object_object_add(x64_registers, "cr8", json_object_new_uint64(registers->));
+ json_object_object_add(x64_registers, "gdtr_0", json_object_new_uint64(registers->Gdtr[0]));
+ json_object_object_add(x64_registers, "gdtr_1", json_object_new_uint64(registers->Gdtr[1]));
+ json_object_object_add(x64_registers, "idtr_0", json_object_new_uint64(registers->Idtr[0]));
+ json_object_object_add(x64_registers, "idtr_1", json_object_new_uint64(registers->Idtr[1]));
+ json_object_object_add(x64_registers, "ldtr", json_object_new_int(registers->Ldtr));
+ json_object_object_add(x64_registers, "tr", json_object_new_int(registers->Tr));
+
+ return x64_registers;
+}
\ No newline at end of file
diff --git a/sections/cper-section-ia32x64.h b/sections/cper-section-ia32x64.h
new file mode 100644
index 0000000..81076d0
--- /dev/null
+++ b/sections/cper-section-ia32x64.h
@@ -0,0 +1,35 @@
+#ifndef CPER_SECTION_IA32X64_H
+#define CPER_SECTION_IA32X64_H
+
+#include "json.h"
+#include "../edk/Cper.h"
+
+#define IA32X64_PROCESSOR_ERROR_VALID_BITFIELD_NAMES (const char*[]) \
+ {"checkInfoValid", "targetAddressIdentifierValid", "requestorIdentifierValid", "responderIdentifierValid", \
+ "instructionPointerValid"}
+#define IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES (const char*[]) \
+ {"transactionTypeValid", "operationValid", "levelValid", "processorContextCorruptValid", "uncorrectedValid" \
+ "preciseIPValid", "restartableIPValid", "overflowValid", "participationTypeValid", "timeOutValid" \
+ "addressSpaceValid"}
+#define IA32X64_CHECK_INFO_TRANSACTION_TYPES_KEYS (int []){0, 1, 2}
+#define IA32X64_CHECK_INFO_TRANSACTION_TYPES_VALUES (const char*[]){"Instruction", "Data Access", "Generic"}
+#define IA32X64_CHECK_INFO_OPERATION_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5, 6, 7, 8}
+#define IA32X64_CHECK_INFO_OPERATION_TYPES_VALUES (const char*[]){"Generic Error", "Generic Read", "Generic Write" \
+ "Data Read", "Data Write", "Instruction Fetch", "Prefetch", "Eviction", "Snoop"}
+#define IA32X64_BUS_CHECK_INFO_PARTICIPATION_TYPES_KEYS (int []){0, 1, 2, 3}
+#define IA32X64_BUS_CHECK_INFO_PARTICIPATION_TYPES_VALUES (const char*[]){"Local processor originated request", \
+ "Local processor responded to request", "Local processor observed", "Generic"}
+#define IA32X64_BUS_CHECK_INFO_ADDRESS_SPACE_TYPES_KEYS (int []){0, 1, 2, 3}
+#define IA32X64_BUS_CHECK_INFO_ADDRESS_SPACE_TYPES_VALUES (const char*[]){"Memory Access", "Reserved", "I/O", \
+ "Other Transaction"}
+#define IA32X64_MS_CHECK_INFO_ERROR_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5}
+#define IA32X64_MS_CHECK_INFO_ERROR_TYPES_VALUES (const char*[]){"No Error", "Unclassified", "Microcode ROM Parity Error", \
+ "External Error", "FRC Error", "Internal Unclassified"}
+#define IA32X64_REGISTER_CONTEXT_TYPES_KEYS (int []){0, 1, 2, 3, 4, 5, 6, 7}
+#define IA32X64_REGISTER_CONTEXT_TYPES_VALUES (const char*[]){"Unclassified Data", "MSR Registers", \
+ "32-bit Mode Execution Context", "64-bit Mode Execution Context", "FXSave Context", \
+ "32-bit Mode Debug Registers", "64-bit Mode Debug Registers", "Memory Mapper Registers"}
+
+json_object* cper_section_ia32x64_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
+
+#endif
\ No newline at end of file