1 /**
2  * Describes functions for converting processor-generic CPER sections from binary and JSON format
3  * into an intermediate format.
4  *
5  * Author: Lawrence.Tang@arm.com
6  **/
7 
8 #include <stdio.h>
9 #include "json.h"
10 #include "../edk/Cper.h"
11 #include "../cper-utils.h"
12 #include "cper-section-generic.h"
13 
14 //Converts the given processor-generic CPER section into JSON IR.
15 json_object* cper_section_generic_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
16 {
17     EFI_PROCESSOR_GENERIC_ERROR_DATA* section_generic = (EFI_PROCESSOR_GENERIC_ERROR_DATA*)section;
18     json_object* section_ir = json_object_new_object();
19 
20     //Validation bits.
21     json_object* validation = bitfield64_to_ir(section_generic->ValidFields, 13, GENERIC_VALIDATION_BITFIELD_NAMES);
22     json_object_object_add(section_ir, "validationBits", validation);
23 
24     //Processor type, with human readable name if possible.
25     json_object* processor_type = integer_to_readable_pair(section_generic->Type,
26         sizeof(GENERIC_PROC_TYPES_KEYS) / sizeof(int),
27         GENERIC_PROC_TYPES_KEYS,
28         GENERIC_PROC_TYPES_VALUES,
29         "Unknown (Reserved)");
30     json_object_object_add(section_ir, "processorType", processor_type);
31 
32     //Processor ISA, with human readable name if possible.
33     json_object* processor_isa = integer_to_readable_pair(section_generic->Isa,
34         sizeof(GENERIC_ISA_TYPES_KEYS) / sizeof(int),
35         GENERIC_ISA_TYPES_KEYS,
36         GENERIC_ISA_TYPES_VALUES,
37         "Unknown (Reserved");
38     json_object_object_add(section_ir, "processorISA", processor_isa);
39 
40     //Processor error type, with human readable name if possible.
41     json_object* processor_error_type = integer_to_readable_pair(section_generic->ErrorType,
42         sizeof(GENERIC_ERROR_TYPES_KEYS) / sizeof(int),
43         GENERIC_ERROR_TYPES_KEYS,
44         GENERIC_ERROR_TYPES_VALUES,
45         "Unknown (Reserved");
46     json_object_object_add(section_ir, "errorType", processor_error_type);
47 
48     //The operation performed, with a human readable name if possible.
49     json_object* operation = integer_to_readable_pair(section_generic->Operation,
50         sizeof(GENERIC_OPERATION_TYPES_KEYS) / sizeof(int),
51         GENERIC_OPERATION_TYPES_KEYS,
52         GENERIC_OPERATION_TYPES_VALUES,
53         "Unknown (Reserved");
54     json_object_object_add(section_ir, "operation", operation);
55 
56     //Flags, additional information about the error.
57     json_object* flags = bitfield8_to_ir(section_generic->Flags, 4, GENERIC_FLAGS_BITFIELD_NAMES);
58     json_object_object_add(section_ir, "flags", flags);
59 
60     //The level of the error.
61     json_object_object_add(section_ir, "level", json_object_new_int(section_generic->Level));
62 
63     //CPU version information (todo)
64     //...
65 
66     //CPU brand string. May not exist if on ARM.
67     json_object_object_add(section_ir, "cpuBrandString", json_object_new_string(section_generic->BrandString));
68 
69     //Remaining 64-bit fields.
70     json_object_object_add(section_ir, "processorID", json_object_new_uint64(section_generic->ApicId));
71     json_object_object_add(section_ir, "targetAddress", json_object_new_uint64(section_generic->TargetAddr));
72     json_object_object_add(section_ir, "requestorID", json_object_new_uint64(section_generic->RequestorId));
73     json_object_object_add(section_ir, "responderID", json_object_new_uint64(section_generic->ResponderId));
74     json_object_object_add(section_ir, "instructionIP", json_object_new_uint64(section_generic->InstructionIP));
75 
76     return section_ir;
77 }