Partial reformat to kernel code style.
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..9b87ea1
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,682 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/process/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \
+# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
+# | LC_ALL=C sort -u
+ForEachMacros:
+ - '__ata_qc_for_each'
+ - '__bio_for_each_bvec'
+ - '__bio_for_each_segment'
+ - '__evlist__for_each_entry'
+ - '__evlist__for_each_entry_continue'
+ - '__evlist__for_each_entry_from'
+ - '__evlist__for_each_entry_reverse'
+ - '__evlist__for_each_entry_safe'
+ - '__for_each_mem_range'
+ - '__for_each_mem_range_rev'
+ - '__for_each_thread'
+ - '__hlist_for_each_rcu'
+ - '__map__for_each_symbol_by_name'
+ - '__perf_evlist__for_each_entry'
+ - '__perf_evlist__for_each_entry_reverse'
+ - '__perf_evlist__for_each_entry_safe'
+ - '__rq_for_each_bio'
+ - '__shost_for_each_device'
+ - 'apei_estatus_for_each_section'
+ - 'ata_for_each_dev'
+ - 'ata_for_each_link'
+ - 'ata_qc_for_each'
+ - 'ata_qc_for_each_raw'
+ - 'ata_qc_for_each_with_internal'
+ - 'ax25_for_each'
+ - 'ax25_uid_for_each'
+ - 'bio_for_each_bvec'
+ - 'bio_for_each_bvec_all'
+ - 'bio_for_each_folio_all'
+ - 'bio_for_each_integrity_vec'
+ - 'bio_for_each_segment'
+ - 'bio_for_each_segment_all'
+ - 'bio_list_for_each'
+ - 'bip_for_each_vec'
+ - 'bond_for_each_slave'
+ - 'bond_for_each_slave_rcu'
+ - 'bpf__perf_for_each_map'
+ - 'bpf__perf_for_each_map_named'
+ - 'bpf_for_each_spilled_reg'
+ - 'bpf_object__for_each_map'
+ - 'bpf_object__for_each_program'
+ - 'bpf_object__for_each_safe'
+ - 'bpf_perf_object__for_each'
+ - 'btree_for_each_safe128'
+ - 'btree_for_each_safe32'
+ - 'btree_for_each_safe64'
+ - 'btree_for_each_safel'
+ - 'card_for_each_dev'
+ - 'cgroup_taskset_for_each'
+ - 'cgroup_taskset_for_each_leader'
+ - 'cpufreq_for_each_efficient_entry_idx'
+ - 'cpufreq_for_each_entry'
+ - 'cpufreq_for_each_entry_idx'
+ - 'cpufreq_for_each_valid_entry'
+ - 'cpufreq_for_each_valid_entry_idx'
+ - 'css_for_each_child'
+ - 'css_for_each_descendant_post'
+ - 'css_for_each_descendant_pre'
+ - 'damon_for_each_region'
+ - 'damon_for_each_region_safe'
+ - 'damon_for_each_scheme'
+ - 'damon_for_each_scheme_safe'
+ - 'damon_for_each_target'
+ - 'damon_for_each_target_safe'
+ - 'data__for_each_file'
+ - 'data__for_each_file_new'
+ - 'data__for_each_file_start'
+ - 'device_for_each_child_node'
+ - 'displayid_iter_for_each'
+ - 'dma_fence_array_for_each'
+ - 'dma_fence_chain_for_each'
+ - 'dma_fence_unwrap_for_each'
+ - 'dma_resv_for_each_fence'
+ - 'dma_resv_for_each_fence_unlocked'
+ - 'do_for_each_ftrace_op'
+ - 'drm_atomic_crtc_for_each_plane'
+ - 'drm_atomic_crtc_state_for_each_plane'
+ - 'drm_atomic_crtc_state_for_each_plane_state'
+ - 'drm_atomic_for_each_plane_damage'
+ - 'drm_client_for_each_connector_iter'
+ - 'drm_client_for_each_modeset'
+ - 'drm_connector_for_each_possible_encoder'
+ - 'drm_for_each_bridge_in_chain'
+ - 'drm_for_each_connector_iter'
+ - 'drm_for_each_crtc'
+ - 'drm_for_each_crtc_reverse'
+ - 'drm_for_each_encoder'
+ - 'drm_for_each_encoder_mask'
+ - 'drm_for_each_fb'
+ - 'drm_for_each_legacy_plane'
+ - 'drm_for_each_plane'
+ - 'drm_for_each_plane_mask'
+ - 'drm_for_each_privobj'
+ - 'drm_mm_for_each_hole'
+ - 'drm_mm_for_each_node'
+ - 'drm_mm_for_each_node_in_range'
+ - 'drm_mm_for_each_node_safe'
+ - 'dsa_switch_for_each_available_port'
+ - 'dsa_switch_for_each_cpu_port'
+ - 'dsa_switch_for_each_port'
+ - 'dsa_switch_for_each_port_continue_reverse'
+ - 'dsa_switch_for_each_port_safe'
+ - 'dsa_switch_for_each_user_port'
+ - 'dsa_tree_for_each_user_port'
+ - 'dso__for_each_symbol'
+ - 'dsos__for_each_with_build_id'
+ - 'elf_hash_for_each_possible'
+ - 'elf_section__for_each_rel'
+ - 'elf_section__for_each_rela'
+ - 'elf_symtab__for_each_symbol'
+ - 'evlist__for_each_cpu'
+ - 'evlist__for_each_entry'
+ - 'evlist__for_each_entry_continue'
+ - 'evlist__for_each_entry_from'
+ - 'evlist__for_each_entry_reverse'
+ - 'evlist__for_each_entry_safe'
+ - 'flow_action_for_each'
+ - 'for_each_acpi_dev_match'
+ - 'for_each_active_dev_scope'
+ - 'for_each_active_drhd_unit'
+ - 'for_each_active_iommu'
+ - 'for_each_aggr_pgid'
+ - 'for_each_available_child_of_node'
+ - 'for_each_bench'
+ - 'for_each_bio'
+ - 'for_each_board_func_rsrc'
+ - 'for_each_btf_ext_rec'
+ - 'for_each_btf_ext_sec'
+ - 'for_each_bvec'
+ - 'for_each_card_auxs'
+ - 'for_each_card_auxs_safe'
+ - 'for_each_card_components'
+ - 'for_each_card_dapms'
+ - 'for_each_card_pre_auxs'
+ - 'for_each_card_prelinks'
+ - 'for_each_card_rtds'
+ - 'for_each_card_rtds_safe'
+ - 'for_each_card_widgets'
+ - 'for_each_card_widgets_safe'
+ - 'for_each_cgroup_storage_type'
+ - 'for_each_child_of_node'
+ - 'for_each_clear_bit'
+ - 'for_each_clear_bit_from'
+ - 'for_each_clear_bitrange'
+ - 'for_each_clear_bitrange_from'
+ - 'for_each_cmd'
+ - 'for_each_cmsghdr'
+ - 'for_each_collection'
+ - 'for_each_comp_order'
+ - 'for_each_compatible_node'
+ - 'for_each_component_dais'
+ - 'for_each_component_dais_safe'
+ - 'for_each_console'
+ - 'for_each_cpu'
+ - 'for_each_cpu_and'
+ - 'for_each_cpu_not'
+ - 'for_each_cpu_wrap'
+ - 'for_each_dapm_widgets'
+ - 'for_each_dedup_cand'
+ - 'for_each_dev_addr'
+ - 'for_each_dev_scope'
+ - 'for_each_dma_cap_mask'
+ - 'for_each_dpcm_be'
+ - 'for_each_dpcm_be_rollback'
+ - 'for_each_dpcm_be_safe'
+ - 'for_each_dpcm_fe'
+ - 'for_each_drhd_unit'
+ - 'for_each_dss_dev'
+ - 'for_each_efi_memory_desc'
+ - 'for_each_efi_memory_desc_in_map'
+ - 'for_each_element'
+ - 'for_each_element_extid'
+ - 'for_each_element_id'
+ - 'for_each_endpoint_of_node'
+ - 'for_each_event'
+ - 'for_each_event_tps'
+ - 'for_each_evictable_lru'
+ - 'for_each_fib6_node_rt_rcu'
+ - 'for_each_fib6_walker_rt'
+ - 'for_each_free_mem_pfn_range_in_zone'
+ - 'for_each_free_mem_pfn_range_in_zone_from'
+ - 'for_each_free_mem_range'
+ - 'for_each_free_mem_range_reverse'
+ - 'for_each_func_rsrc'
+ - 'for_each_group_evsel'
+ - 'for_each_group_member'
+ - 'for_each_hstate'
+ - 'for_each_if'
+ - 'for_each_inject_fn'
+ - 'for_each_insn'
+ - 'for_each_insn_prefix'
+ - 'for_each_intid'
+ - 'for_each_iommu'
+ - 'for_each_ip_tunnel_rcu'
+ - 'for_each_irq_nr'
+ - 'for_each_lang'
+ - 'for_each_link_codecs'
+ - 'for_each_link_cpus'
+ - 'for_each_link_platforms'
+ - 'for_each_lru'
+ - 'for_each_matching_node'
+ - 'for_each_matching_node_and_match'
+ - 'for_each_mem_pfn_range'
+ - 'for_each_mem_range'
+ - 'for_each_mem_range_rev'
+ - 'for_each_mem_region'
+ - 'for_each_member'
+ - 'for_each_memory'
+ - 'for_each_migratetype_order'
+ - 'for_each_missing_reg'
+ - 'for_each_net'
+ - 'for_each_net_continue_reverse'
+ - 'for_each_net_rcu'
+ - 'for_each_netdev'
+ - 'for_each_netdev_continue'
+ - 'for_each_netdev_continue_rcu'
+ - 'for_each_netdev_continue_reverse'
+ - 'for_each_netdev_feature'
+ - 'for_each_netdev_in_bond_rcu'
+ - 'for_each_netdev_rcu'
+ - 'for_each_netdev_reverse'
+ - 'for_each_netdev_safe'
+ - 'for_each_new_connector_in_state'
+ - 'for_each_new_crtc_in_state'
+ - 'for_each_new_mst_mgr_in_state'
+ - 'for_each_new_plane_in_state'
+ - 'for_each_new_plane_in_state_reverse'
+ - 'for_each_new_private_obj_in_state'
+ - 'for_each_new_reg'
+ - 'for_each_node'
+ - 'for_each_node_by_name'
+ - 'for_each_node_by_type'
+ - 'for_each_node_mask'
+ - 'for_each_node_state'
+ - 'for_each_node_with_cpus'
+ - 'for_each_node_with_property'
+ - 'for_each_nonreserved_multicast_dest_pgid'
+ - 'for_each_of_allnodes'
+ - 'for_each_of_allnodes_from'
+ - 'for_each_of_cpu_node'
+ - 'for_each_of_pci_range'
+ - 'for_each_old_connector_in_state'
+ - 'for_each_old_crtc_in_state'
+ - 'for_each_old_mst_mgr_in_state'
+ - 'for_each_old_plane_in_state'
+ - 'for_each_old_private_obj_in_state'
+ - 'for_each_oldnew_connector_in_state'
+ - 'for_each_oldnew_crtc_in_state'
+ - 'for_each_oldnew_mst_mgr_in_state'
+ - 'for_each_oldnew_plane_in_state'
+ - 'for_each_oldnew_plane_in_state_reverse'
+ - 'for_each_oldnew_private_obj_in_state'
+ - 'for_each_online_cpu'
+ - 'for_each_online_node'
+ - 'for_each_online_pgdat'
+ - 'for_each_path'
+ - 'for_each_pci_bridge'
+ - 'for_each_pci_dev'
+ - 'for_each_pcm_streams'
+ - 'for_each_physmem_range'
+ - 'for_each_populated_zone'
+ - 'for_each_possible_cpu'
+ - 'for_each_present_cpu'
+ - 'for_each_prime_number'
+ - 'for_each_prime_number_from'
+ - 'for_each_probe_cache_entry'
+ - 'for_each_process'
+ - 'for_each_process_thread'
+ - 'for_each_prop_codec_conf'
+ - 'for_each_prop_dai_codec'
+ - 'for_each_prop_dai_cpu'
+ - 'for_each_prop_dlc_codecs'
+ - 'for_each_prop_dlc_cpus'
+ - 'for_each_prop_dlc_platforms'
+ - 'for_each_property_of_node'
+ - 'for_each_reg'
+ - 'for_each_reg_filtered'
+ - 'for_each_registered_fb'
+ - 'for_each_requested_gpio'
+ - 'for_each_requested_gpio_in_range'
+ - 'for_each_reserved_mem_range'
+ - 'for_each_reserved_mem_region'
+ - 'for_each_rtd_codec_dais'
+ - 'for_each_rtd_components'
+ - 'for_each_rtd_cpu_dais'
+ - 'for_each_rtd_dais'
+ - 'for_each_script'
+ - 'for_each_sec'
+ - 'for_each_set_bit'
+ - 'for_each_set_bit_from'
+ - 'for_each_set_bitrange'
+ - 'for_each_set_bitrange_from'
+ - 'for_each_set_clump8'
+ - 'for_each_sg'
+ - 'for_each_sg_dma_page'
+ - 'for_each_sg_page'
+ - 'for_each_sgtable_dma_page'
+ - 'for_each_sgtable_dma_sg'
+ - 'for_each_sgtable_page'
+ - 'for_each_sgtable_sg'
+ - 'for_each_shell_test'
+ - 'for_each_sibling_event'
+ - 'for_each_subelement'
+ - 'for_each_subelement_extid'
+ - 'for_each_subelement_id'
+ - 'for_each_sublist'
+ - 'for_each_subsystem'
+ - 'for_each_supported_activate_fn'
+ - 'for_each_supported_inject_fn'
+ - 'for_each_test'
+ - 'for_each_thread'
+ - 'for_each_token'
+ - 'for_each_unicast_dest_pgid'
+ - 'for_each_vsi'
+ - 'for_each_wakeup_source'
+ - 'for_each_zone'
+ - 'for_each_zone_zonelist'
+ - 'for_each_zone_zonelist_nodemask'
+ - 'func_for_each_insn'
+ - 'fwnode_for_each_available_child_node'
+ - 'fwnode_for_each_child_node'
+ - 'fwnode_graph_for_each_endpoint'
+ - 'gadget_for_each_ep'
+ - 'genradix_for_each'
+ - 'genradix_for_each_from'
+ - 'hash_for_each'
+ - 'hash_for_each_possible'
+ - 'hash_for_each_possible_rcu'
+ - 'hash_for_each_possible_rcu_notrace'
+ - 'hash_for_each_possible_safe'
+ - 'hash_for_each_rcu'
+ - 'hash_for_each_safe'
+ - 'hashmap__for_each_entry'
+ - 'hashmap__for_each_entry_safe'
+ - 'hashmap__for_each_key_entry'
+ - 'hashmap__for_each_key_entry_safe'
+ - 'hctx_for_each_ctx'
+ - 'hists__for_each_format'
+ - 'hists__for_each_sort_list'
+ - 'hlist_bl_for_each_entry'
+ - 'hlist_bl_for_each_entry_rcu'
+ - 'hlist_bl_for_each_entry_safe'
+ - 'hlist_for_each'
+ - 'hlist_for_each_entry'
+ - 'hlist_for_each_entry_continue'
+ - 'hlist_for_each_entry_continue_rcu'
+ - 'hlist_for_each_entry_continue_rcu_bh'
+ - 'hlist_for_each_entry_from'
+ - 'hlist_for_each_entry_from_rcu'
+ - 'hlist_for_each_entry_rcu'
+ - 'hlist_for_each_entry_rcu_bh'
+ - 'hlist_for_each_entry_rcu_notrace'
+ - 'hlist_for_each_entry_safe'
+ - 'hlist_for_each_entry_srcu'
+ - 'hlist_for_each_safe'
+ - 'hlist_nulls_for_each_entry'
+ - 'hlist_nulls_for_each_entry_from'
+ - 'hlist_nulls_for_each_entry_rcu'
+ - 'hlist_nulls_for_each_entry_safe'
+ - 'i3c_bus_for_each_i2cdev'
+ - 'i3c_bus_for_each_i3cdev'
+ - 'idr_for_each_entry'
+ - 'idr_for_each_entry_continue'
+ - 'idr_for_each_entry_continue_ul'
+ - 'idr_for_each_entry_ul'
+ - 'in_dev_for_each_ifa_rcu'
+ - 'in_dev_for_each_ifa_rtnl'
+ - 'inet_bind_bucket_for_each'
+ - 'inet_lhash2_for_each_icsk'
+ - 'inet_lhash2_for_each_icsk_continue'
+ - 'inet_lhash2_for_each_icsk_rcu'
+ - 'intlist__for_each_entry'
+ - 'intlist__for_each_entry_safe'
+ - 'kcore_copy__for_each_phdr'
+ - 'key_for_each'
+ - 'key_for_each_safe'
+ - 'klp_for_each_func'
+ - 'klp_for_each_func_safe'
+ - 'klp_for_each_func_static'
+ - 'klp_for_each_object'
+ - 'klp_for_each_object_safe'
+ - 'klp_for_each_object_static'
+ - 'kunit_suite_for_each_test_case'
+ - 'kvm_for_each_memslot'
+ - 'kvm_for_each_memslot_in_gfn_range'
+ - 'kvm_for_each_vcpu'
+ - 'libbpf_nla_for_each_attr'
+ - 'list_for_each'
+ - 'list_for_each_codec'
+ - 'list_for_each_codec_safe'
+ - 'list_for_each_continue'
+ - 'list_for_each_entry'
+ - 'list_for_each_entry_continue'
+ - 'list_for_each_entry_continue_rcu'
+ - 'list_for_each_entry_continue_reverse'
+ - 'list_for_each_entry_from'
+ - 'list_for_each_entry_from_rcu'
+ - 'list_for_each_entry_from_reverse'
+ - 'list_for_each_entry_lockless'
+ - 'list_for_each_entry_rcu'
+ - 'list_for_each_entry_reverse'
+ - 'list_for_each_entry_safe'
+ - 'list_for_each_entry_safe_continue'
+ - 'list_for_each_entry_safe_from'
+ - 'list_for_each_entry_safe_reverse'
+ - 'list_for_each_entry_srcu'
+ - 'list_for_each_from'
+ - 'list_for_each_prev'
+ - 'list_for_each_prev_safe'
+ - 'list_for_each_safe'
+ - 'llist_for_each'
+ - 'llist_for_each_entry'
+ - 'llist_for_each_entry_safe'
+ - 'llist_for_each_safe'
+ - 'map__for_each_symbol'
+ - 'map__for_each_symbol_by_name'
+ - 'map_for_each_event'
+ - 'map_for_each_metric'
+ - 'maps__for_each_entry'
+ - 'maps__for_each_entry_safe'
+ - 'mci_for_each_dimm'
+ - 'media_device_for_each_entity'
+ - 'media_device_for_each_intf'
+ - 'media_device_for_each_link'
+ - 'media_device_for_each_pad'
+ - 'msi_for_each_desc'
+ - 'nanddev_io_for_each_page'
+ - 'netdev_for_each_lower_dev'
+ - 'netdev_for_each_lower_private'
+ - 'netdev_for_each_lower_private_rcu'
+ - 'netdev_for_each_mc_addr'
+ - 'netdev_for_each_uc_addr'
+ - 'netdev_for_each_upper_dev_rcu'
+ - 'netdev_hw_addr_list_for_each'
+ - 'nft_rule_for_each_expr'
+ - 'nla_for_each_attr'
+ - 'nla_for_each_nested'
+ - 'nlmsg_for_each_attr'
+ - 'nlmsg_for_each_msg'
+ - 'nr_neigh_for_each'
+ - 'nr_neigh_for_each_safe'
+ - 'nr_node_for_each'
+ - 'nr_node_for_each_safe'
+ - 'of_for_each_phandle'
+ - 'of_property_for_each_string'
+ - 'of_property_for_each_u32'
+ - 'pci_bus_for_each_resource'
+ - 'pcl_for_each_chunk'
+ - 'pcl_for_each_segment'
+ - 'pcm_for_each_format'
+ - 'perf_config_items__for_each_entry'
+ - 'perf_config_sections__for_each_entry'
+ - 'perf_config_set__for_each_entry'
+ - 'perf_cpu_map__for_each_cpu'
+ - 'perf_evlist__for_each_entry'
+ - 'perf_evlist__for_each_entry_reverse'
+ - 'perf_evlist__for_each_entry_safe'
+ - 'perf_evlist__for_each_evsel'
+ - 'perf_evlist__for_each_mmap'
+ - 'perf_hpp_list__for_each_format'
+ - 'perf_hpp_list__for_each_format_safe'
+ - 'perf_hpp_list__for_each_sort_list'
+ - 'perf_hpp_list__for_each_sort_list_safe'
+ - 'perf_pmu__for_each_hybrid_pmu'
+ - 'ping_portaddr_for_each_entry'
+ - 'plist_for_each'
+ - 'plist_for_each_continue'
+ - 'plist_for_each_entry'
+ - 'plist_for_each_entry_continue'
+ - 'plist_for_each_entry_safe'
+ - 'plist_for_each_safe'
+ - 'pnp_for_each_card'
+ - 'pnp_for_each_dev'
+ - 'protocol_for_each_card'
+ - 'protocol_for_each_dev'
+ - 'queue_for_each_hw_ctx'
+ - 'radix_tree_for_each_slot'
+ - 'radix_tree_for_each_tagged'
+ - 'rb_for_each'
+ - 'rbtree_postorder_for_each_entry_safe'
+ - 'rdma_for_each_block'
+ - 'rdma_for_each_port'
+ - 'rdma_umem_for_each_dma_block'
+ - 'resort_rb__for_each_entry'
+ - 'resource_list_for_each_entry'
+ - 'resource_list_for_each_entry_safe'
+ - 'rhl_for_each_entry_rcu'
+ - 'rhl_for_each_rcu'
+ - 'rht_for_each'
+ - 'rht_for_each_entry'
+ - 'rht_for_each_entry_from'
+ - 'rht_for_each_entry_rcu'
+ - 'rht_for_each_entry_rcu_from'
+ - 'rht_for_each_entry_safe'
+ - 'rht_for_each_from'
+ - 'rht_for_each_rcu'
+ - 'rht_for_each_rcu_from'
+ - 'rq_for_each_bvec'
+ - 'rq_for_each_segment'
+ - 'rq_list_for_each'
+ - 'rq_list_for_each_safe'
+ - 'scsi_for_each_prot_sg'
+ - 'scsi_for_each_sg'
+ - 'sctp_for_each_hentry'
+ - 'sctp_skb_for_each'
+ - 'sec_for_each_insn'
+ - 'sec_for_each_insn_continue'
+ - 'sec_for_each_insn_from'
+ - 'shdma_for_each_chan'
+ - 'shost_for_each_device'
+ - 'sk_for_each'
+ - 'sk_for_each_bound'
+ - 'sk_for_each_entry_offset_rcu'
+ - 'sk_for_each_from'
+ - 'sk_for_each_rcu'
+ - 'sk_for_each_safe'
+ - 'sk_nulls_for_each'
+ - 'sk_nulls_for_each_from'
+ - 'sk_nulls_for_each_rcu'
+ - 'snd_array_for_each'
+ - 'snd_pcm_group_for_each_entry'
+ - 'snd_soc_dapm_widget_for_each_path'
+ - 'snd_soc_dapm_widget_for_each_path_safe'
+ - 'snd_soc_dapm_widget_for_each_sink_path'
+ - 'snd_soc_dapm_widget_for_each_source_path'
+ - 'strlist__for_each_entry'
+ - 'strlist__for_each_entry_safe'
+ - 'sym_for_each_insn'
+ - 'sym_for_each_insn_continue_reverse'
+ - 'symbols__for_each_entry'
+ - 'tb_property_for_each'
+ - 'tcf_act_for_each_action'
+ - 'tcf_exts_for_each_action'
+ - 'udp_portaddr_for_each_entry'
+ - 'udp_portaddr_for_each_entry_rcu'
+ - 'usb_hub_for_each_child'
+ - 'v4l2_device_for_each_subdev'
+ - 'v4l2_m2m_for_each_dst_buf'
+ - 'v4l2_m2m_for_each_dst_buf_safe'
+ - 'v4l2_m2m_for_each_src_buf'
+ - 'v4l2_m2m_for_each_src_buf_safe'
+ - 'virtio_device_for_each_vq'
+ - 'while_for_each_ftrace_op'
+ - 'xa_for_each'
+ - 'xa_for_each_marked'
+ - 'xa_for_each_range'
+ - 'xa_for_each_start'
+ - 'xas_for_each'
+ - 'xas_for_each_conflict'
+ - 'xas_for_each_marked'
+ - 'xbc_array_for_each_value'
+ - 'xbc_for_each_key_value'
+ - 'xbc_node_for_each_array_value'
+ - 'xbc_node_for_each_child'
+ - 'xbc_node_for_each_key_value'
+ - 'xbc_node_for_each_subkey'
+ - 'zorro_for_each_dev'
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/cli-app/cper-convert.c b/cli-app/cper-convert.c
index 488b6c9..03325c2 100644
--- a/cli-app/cper-convert.c
+++ b/cli-app/cper-convert.c
@@ -13,186 +13,178 @@
#include "../cper-parse.h"
#include "../json-schema.h"
-void cper_to_json(int argc, char* argv[]);
-void json_to_cper(int argc, char* argv[]);
+void cper_to_json(int argc, char *argv[]);
+void json_to_cper(int argc, char *argv[]);
void print_help(void);
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
{
- //Ensure at least one argument is present.
- if (argc < 2)
- {
- printf("Invalid number of arguments. See 'cper-convert --help' for command information.\n");
- return -1;
- }
+ //Ensure at least one argument is present.
+ if (argc < 2) {
+ printf("Invalid number of arguments. See 'cper-convert --help' for command information.\n");
+ return -1;
+ }
- //Run the requested command.
- if (strcmp(argv[1], "to-json") == 0)
- cper_to_json(argc, argv);
- else if (strcmp(argv[1], "to-cper") == 0)
- json_to_cper(argc, argv);
- else if (strcmp(argv[1], "--help") == 0)
- print_help();
- else
- {
- printf("Unrecognised argument '%s'. See 'cper-convert --help' for command information.\n", argv[1]);
- return -1;
- }
+ //Run the requested command.
+ if (strcmp(argv[1], "to-json") == 0)
+ cper_to_json(argc, argv);
+ else if (strcmp(argv[1], "to-cper") == 0)
+ json_to_cper(argc, argv);
+ else if (strcmp(argv[1], "--help") == 0)
+ print_help();
+ else {
+ printf("Unrecognised argument '%s'. See 'cper-convert --help' for command information.\n",
+ argv[1]);
+ return -1;
+ }
- return 0;
+ return 0;
}
//Command for converting a provided CPER log file into JSON.
-void cper_to_json(int argc, char* argv[])
+void cper_to_json(int argc, char *argv[])
{
- if (argc < 3)
- {
- printf("Insufficient number of arguments for 'to-json'. See 'cper-convert --help' for command information.\n");
- return;
- }
+ if (argc < 3) {
+ printf("Insufficient number of arguments for 'to-json'. See 'cper-convert --help' for command information.\n");
+ return;
+ }
- //Get a handle for the log file.
- FILE* cper_file = fopen(argv[2], "r");
- if (cper_file == NULL)
- {
- printf("Could not open provided CPER file '%s', file handle returned null.\n", argv[2]);
- return;
- }
+ //Get a handle for the log file.
+ FILE *cper_file = fopen(argv[2], "r");
+ if (cper_file == NULL) {
+ printf("Could not open provided CPER file '%s', file handle returned null.\n",
+ argv[2]);
+ return;
+ }
- //Convert.
- json_object* ir = cper_to_ir(cper_file);
- fclose(cper_file);
- const char* json_output = json_object_to_json_string_ext(ir, JSON_C_TO_STRING_PRETTY);
+ //Convert.
+ json_object *ir = cper_to_ir(cper_file);
+ fclose(cper_file);
+ const char *json_output =
+ json_object_to_json_string_ext(ir, JSON_C_TO_STRING_PRETTY);
- //Check whether there is a "--out" argument, if there is, then output to file instead.
- //Otherwise, just send to console.
- if (argc != 5)
- {
- printf("%s\n", json_output);
- return;
- }
+ //Check whether there is a "--out" argument, if there is, then output to file instead.
+ //Otherwise, just send to console.
+ if (argc != 5) {
+ printf("%s\n", json_output);
+ return;
+ }
- //File out argument exists. Argument valid?
- if (strcmp(argv[3], "--out") != 0)
- {
- printf("Invalid argument '%s' for command 'to-json'. See 'cper-convert --help' for command information.\n", argv[3]);
- return;
- }
+ //File out argument exists. Argument valid?
+ if (strcmp(argv[3], "--out") != 0) {
+ printf("Invalid argument '%s' for command 'to-json'. See 'cper-convert --help' for command information.\n",
+ argv[3]);
+ return;
+ }
- //Try to open a file handle to the desired output file.
- FILE* json_file = fopen(argv[4], "w");
- if (json_file == NULL)
- {
- printf("Could not get a handle for output file '%s', file handle returned null.\n", argv[4]);
- return;
- }
+ //Try to open a file handle to the desired output file.
+ FILE *json_file = fopen(argv[4], "w");
+ if (json_file == NULL) {
+ printf("Could not get a handle for output file '%s', file handle returned null.\n",
+ argv[4]);
+ return;
+ }
- //Write out to file.
- fwrite(json_output, strlen(json_output), 1, json_file);
- fclose(json_file);
+ //Write out to file.
+ fwrite(json_output, strlen(json_output), 1, json_file);
+ fclose(json_file);
}
//Command for converting a provided CPER-JSON JSON file to CPER binary.
-void json_to_cper(int argc, char* argv[])
+void json_to_cper(int argc, char *argv[])
{
- if (argc < 5)
- {
- printf("Insufficient number of arguments for 'to-cper'. See 'cper-convert --help' for command information.\n");
- return;
- }
+ if (argc < 5) {
+ printf("Insufficient number of arguments for 'to-cper'. See 'cper-convert --help' for command information.\n");
+ return;
+ }
- //Read JSON IR from file.
- json_object* ir = json_object_from_file(argv[2]);
- if (ir == NULL)
- {
- printf("Could not read JSON from file '%s', import returned null.\n", argv[2]);
- return;
- }
+ //Read JSON IR from file.
+ json_object *ir = json_object_from_file(argv[2]);
+ if (ir == NULL) {
+ printf("Could not read JSON from file '%s', import returned null.\n",
+ argv[2]);
+ return;
+ }
- //Are we skipping validation?
- int do_validate = 1;
- if (argc >= 6 && argc < 8)
- {
- if (strcmp(argv[5], "--no-validate") == 0)
- {
- do_validate = 0;
- }
- }
+ //Are we skipping validation?
+ int do_validate = 1;
+ if (argc >= 6 && argc < 8) {
+ if (strcmp(argv[5], "--no-validate") == 0) {
+ do_validate = 0;
+ }
+ }
- //Validate the JSON against specification, unless otherwise specified.
- if (do_validate)
- {
- char* specification_path = NULL;
+ //Validate the JSON against specification, unless otherwise specified.
+ if (do_validate) {
+ char *specification_path = NULL;
- //Is there a specification file path?
- if (argc >= 7 && strcmp(argv[argc - 2], "--specification") == 0)
- {
- specification_path = argv[argc - 1];
- }
- else
- {
- //Make the specification path the assumed default (application directory + specification/cper-json.json).
- specification_path = malloc(PATH_MAX);
- char* dir = dirname(argv[0]);
- strcpy(specification_path, dir);
- strcat(specification_path, "/specification/cper-json.json");
- }
+ //Is there a specification file path?
+ if (argc >= 7 &&
+ strcmp(argv[argc - 2], "--specification") == 0) {
+ specification_path = argv[argc - 1];
+ } else {
+ //Make the specification path the assumed default (application directory + specification/cper-json.json).
+ specification_path = malloc(PATH_MAX);
+ char *dir = dirname(argv[0]);
+ strcpy(specification_path, dir);
+ strcat(specification_path,
+ "/specification/cper-json.json");
+ }
- //Enable debug mode if indicated.
- for (int i=5; i<argc; i++)
- {
- if (strcmp(argv[i], "--debug") == 0)
- {
- validate_schema_debug_enable();
- printf("debug enabled.\n");
- break;
- }
- }
+ //Enable debug mode if indicated.
+ for (int i = 5; i < argc; i++) {
+ if (strcmp(argv[i], "--debug") == 0) {
+ validate_schema_debug_enable();
+ printf("debug enabled.\n");
+ break;
+ }
+ }
- //Attempt to verify with the the specification.
- char* error_message = malloc(JSON_ERROR_MSG_MAX_LEN);
- int success = validate_schema_from_file(specification_path, ir, error_message);
+ //Attempt to verify with the the specification.
+ char *error_message = malloc(JSON_ERROR_MSG_MAX_LEN);
+ int success = validate_schema_from_file(specification_path, ir,
+ error_message);
- //Free specification path (if necessary).
- if (argc == 5)
- free(specification_path);
+ //Free specification path (if necessary).
+ if (argc == 5)
+ free(specification_path);
- //If failed, early exit before conversion.
- if (!success)
- {
- printf("JSON format validation failed: %s\n", error_message);
- free(error_message);
- return;
- }
- free(error_message);
- }
+ //If failed, early exit before conversion.
+ if (!success) {
+ printf("JSON format validation failed: %s\n",
+ error_message);
+ free(error_message);
+ return;
+ }
+ free(error_message);
+ }
- //Attempt a conversion.
- //Open a read for the output file.
- FILE* cper_file = fopen(argv[4], "w");
- if (cper_file == NULL)
- {
- printf("Could not open output file '%s', file handle returned null.\n", argv[4]);
- return;
- }
+ //Attempt a conversion.
+ //Open a read for the output file.
+ FILE *cper_file = fopen(argv[4], "w");
+ if (cper_file == NULL) {
+ printf("Could not open output file '%s', file handle returned null.\n",
+ argv[4]);
+ return;
+ }
- //Run the converter.
- ir_to_cper(ir, cper_file);
- fclose(cper_file);
+ //Run the converter.
+ ir_to_cper(ir, cper_file);
+ fclose(cper_file);
}
//Command for printing help information.
void print_help(void)
{
- printf(":: to-json cper.file [--out file.name]\n");
- printf("\tConverts the provided CPER log file into JSON, by default outputting to console. If '--out' is specified,\n");
- printf("\tThe outputted JSON will be written to the provided file name instead.\n");
- printf("\n:: to-cper cper.json --out file.name [--no-validate] [--debug] [--specification some/spec/path.json]\n");
- printf("\tConverts the provided CPER-JSON JSON file into CPER binary. An output file must be specified with '--out'.\n");
- printf("\tBy default, the provided JSON will try to be validated against a specification. If no specification file path\n");
- printf("\tis provided with '--specification', then it will default to 'argv[0] + /specification/cper-json.json'.\n");
- printf("\tIf the '--no-validate' argument is set, then the provided JSON will not be validated. Be warned, this may cause\n");
- printf("\tpremature exit/unexpected behaviour in CPER output.\n");
- printf("\n:: --help\n");
- printf("\tDisplays help information to the console.\n");
+ printf(":: to-json cper.file [--out file.name]\n");
+ printf("\tConverts the provided CPER log file into JSON, by default outputting to console. If '--out' is specified,\n");
+ printf("\tThe outputted JSON will be written to the provided file name instead.\n");
+ printf("\n:: to-cper cper.json --out file.name [--no-validate] [--debug] [--specification some/spec/path.json]\n");
+ printf("\tConverts the provided CPER-JSON JSON file into CPER binary. An output file must be specified with '--out'.\n");
+ printf("\tBy default, the provided JSON will try to be validated against a specification. If no specification file path\n");
+ printf("\tis provided with '--specification', then it will default to 'argv[0] + /specification/cper-json.json'.\n");
+ printf("\tIf the '--no-validate' argument is set, then the provided JSON will not be validated. Be warned, this may cause\n");
+ printf("\tpremature exit/unexpected behaviour in CPER output.\n");
+ printf("\n:: --help\n");
+ printf("\tDisplays help information to the console.\n");
}
\ No newline at end of file
diff --git a/common-utils.c b/common-utils.c
index 9b0780b..38c4317 100644
--- a/common-utils.c
+++ b/common-utils.c
@@ -11,18 +11,18 @@
//Converts the given BCD byte to a standard integer.
int bcd_to_int(UINT8 bcd)
{
- return ((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F);
+ return ((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F);
}
//Converts the given integer to a single byte BCD.
UINT8 int_to_bcd(int value)
{
- UINT8 result = 0;
- int shift = 0;
- while (value > 0) {
- result |= (value % 10) << (shift++ << 2);
- value /= 10;
- }
+ UINT8 result = 0;
+ int shift = 0;
+ while (value > 0) {
+ result |= (value % 10) << (shift++ << 2);
+ value /= 10;
+ }
- return result;
+ return result;
}
\ No newline at end of file
diff --git a/cper-parse.c b/cper-parse.c
index 6ef6a6f..68c8d74 100644
--- a/cper-parse.c
+++ b/cper-parse.c
@@ -28,330 +28,430 @@
#include "sections/cper-section-cxl-component.h"
//Private pre-definitions.
-json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header);
-json_object* cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR* section_descriptor);
-json_object* cper_section_to_ir(FILE* handle, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
+json_object *cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER *header);
+json_object *
+cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR *section_descriptor);
+json_object *cper_section_to_ir(FILE *handle,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor);
//Reads a CPER log file at the given file location, and returns an intermediate
//JSON representation of this CPER record.
-json_object* cper_to_ir(FILE* cper_file)
+json_object *cper_to_ir(FILE *cper_file)
{
- //Ensure this is really a CPER log.
- EFI_COMMON_ERROR_RECORD_HEADER header;
- fseek(cper_file, 0, SEEK_SET);
- if (fread(&header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, cper_file) != 1)
- {
- printf("Invalid CPER file: Invalid length (log too short).\n");
- return NULL;
- }
+ //Ensure this is really a CPER log.
+ EFI_COMMON_ERROR_RECORD_HEADER header;
+ fseek(cper_file, 0, SEEK_SET);
+ if (fread(&header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1,
+ cper_file) != 1) {
+ printf("Invalid CPER file: Invalid length (log too short).\n");
+ return NULL;
+ }
- //Check if the header contains the magic bytes ("CPER").
- if (header.SignatureStart != EFI_ERROR_RECORD_SIGNATURE_START) {
- printf("Invalid CPER file: Invalid header (incorrect signature).\n");
- return NULL;
- }
+ //Check if the header contains the magic bytes ("CPER").
+ if (header.SignatureStart != EFI_ERROR_RECORD_SIGNATURE_START) {
+ printf("Invalid CPER file: Invalid header (incorrect signature).\n");
+ return NULL;
+ }
- //Create the header JSON object from the read bytes.
- json_object* header_ir = cper_header_to_ir(&header);
+ //Create the header JSON object from the read bytes.
+ json_object *header_ir = cper_header_to_ir(&header);
- //Read the appropriate number of section descriptors & sections, and convert them into IR format.
- json_object* section_descriptors_ir = json_object_new_array();
- json_object* sections_ir = json_object_new_array();
- for (int i=0; i<header.SectionCount; i++)
- {
- //Create the section descriptor.
- EFI_ERROR_SECTION_DESCRIPTOR section_descriptor;
- if (fread(§ion_descriptor, sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, cper_file) != 1)
- {
- printf("Invalid number of section headers: Header states %d sections, could not read section %d.\n", header.SectionCount, i+1);
- return NULL;
- }
- json_object_array_add(section_descriptors_ir, cper_section_descriptor_to_ir(§ion_descriptor));
+ //Read the appropriate number of section descriptors & sections, and convert them into IR format.
+ json_object *section_descriptors_ir = json_object_new_array();
+ json_object *sections_ir = json_object_new_array();
+ for (int i = 0; i < header.SectionCount; i++) {
+ //Create the section descriptor.
+ EFI_ERROR_SECTION_DESCRIPTOR section_descriptor;
+ if (fread(§ion_descriptor,
+ sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1,
+ cper_file) != 1) {
+ printf("Invalid number of section headers: Header states %d sections, could not read section %d.\n",
+ header.SectionCount, i + 1);
+ return NULL;
+ }
+ json_object_array_add(
+ section_descriptors_ir,
+ cper_section_descriptor_to_ir(§ion_descriptor));
- //Read the section itself.
- json_object_array_add(sections_ir, cper_section_to_ir(cper_file, §ion_descriptor));
- }
+ //Read the section itself.
+ json_object_array_add(sections_ir,
+ cper_section_to_ir(cper_file,
+ §ion_descriptor));
+ }
- //Add the header, section descriptors, and sections to a parent object.
- json_object* parent = json_object_new_object();
- json_object_object_add(parent, "header", header_ir);
- json_object_object_add(parent, "sectionDescriptors", section_descriptors_ir);
- json_object_object_add(parent, "sections", sections_ir);
+ //Add the header, section descriptors, and sections to a parent object.
+ json_object *parent = json_object_new_object();
+ json_object_object_add(parent, "header", header_ir);
+ json_object_object_add(parent, "sectionDescriptors",
+ section_descriptors_ir);
+ json_object_object_add(parent, "sections", sections_ir);
- return parent;
+ return parent;
}
//Converts a parsed CPER record header into intermediate JSON object format.
-json_object* cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER* header)
+json_object *cper_header_to_ir(EFI_COMMON_ERROR_RECORD_HEADER *header)
{
- json_object* header_ir = json_object_new_object();
+ json_object *header_ir = json_object_new_object();
- //Revision/version information.
- json_object_object_add(header_ir, "revision", revision_to_ir(header->Revision));
+ //Revision/version information.
+ json_object_object_add(header_ir, "revision",
+ revision_to_ir(header->Revision));
- //Section count.
- json_object_object_add(header_ir, "sectionCount", json_object_new_int(header->SectionCount));
+ //Section count.
+ json_object_object_add(header_ir, "sectionCount",
+ json_object_new_int(header->SectionCount));
- //Error severity (with interpreted string version).
- json_object* error_severity = json_object_new_object();
- json_object_object_add(error_severity, "code", json_object_new_uint64(header->ErrorSeverity));
- json_object_object_add(error_severity, "name", json_object_new_string(severity_to_string(header->ErrorSeverity)));
- json_object_object_add(header_ir, "severity", error_severity);
+ //Error severity (with interpreted string version).
+ json_object *error_severity = json_object_new_object();
+ json_object_object_add(error_severity, "code",
+ json_object_new_uint64(header->ErrorSeverity));
+ json_object_object_add(error_severity, "name",
+ json_object_new_string(severity_to_string(
+ header->ErrorSeverity)));
+ json_object_object_add(header_ir, "severity", error_severity);
- //The validation bits for each section.
- json_object* validation_bits = bitfield_to_ir(header->ValidationBits, 3, CPER_HEADER_VALID_BITFIELD_NAMES);
- json_object_object_add(header_ir, "validationBits", validation_bits);
+ //The validation bits for each section.
+ json_object *validation_bits = bitfield_to_ir(
+ header->ValidationBits, 3, CPER_HEADER_VALID_BITFIELD_NAMES);
+ json_object_object_add(header_ir, "validationBits", validation_bits);
- //Total length of the record (including headers) in bytes.
- json_object_object_add(header_ir, "recordLength", json_object_new_uint64(header->RecordLength));
+ //Total length of the record (including headers) in bytes.
+ json_object_object_add(header_ir, "recordLength",
+ json_object_new_uint64(header->RecordLength));
- //If a timestamp exists according to validation bits, then add it.
- if (header->ValidationBits & 0b10)
- {
- char timestamp_string[TIMESTAMP_LENGTH];
- timestamp_to_string(timestamp_string, &header->TimeStamp);
-
- json_object_object_add(header_ir, "timestamp", json_object_new_string(timestamp_string));
- json_object_object_add(header_ir, "timestampIsPrecise", json_object_new_boolean(header->TimeStamp.Flag));
- }
+ //If a timestamp exists according to validation bits, then add it.
+ if (header->ValidationBits & 0b10) {
+ char timestamp_string[TIMESTAMP_LENGTH];
+ timestamp_to_string(timestamp_string, &header->TimeStamp);
- //If a platform ID exists according to the validation bits, then add it.
- if (header->ValidationBits & 0b1)
- {
- char platform_string[GUID_STRING_LENGTH];
- guid_to_string(platform_string, &header->PlatformID);
- json_object_object_add(header_ir, "platformID", json_object_new_string(platform_string));
- }
+ json_object_object_add(
+ header_ir, "timestamp",
+ json_object_new_string(timestamp_string));
+ json_object_object_add(
+ header_ir, "timestampIsPrecise",
+ json_object_new_boolean(header->TimeStamp.Flag));
+ }
- //If a partition ID exists according to the validation bits, then add it.
- if (header->ValidationBits & 0b100)
- {
- char partition_string[GUID_STRING_LENGTH];
- guid_to_string(partition_string, &header->PartitionID);
- json_object_object_add(header_ir, "partitionID", json_object_new_string(partition_string));
- }
+ //If a platform ID exists according to the validation bits, then add it.
+ if (header->ValidationBits & 0b1) {
+ char platform_string[GUID_STRING_LENGTH];
+ guid_to_string(platform_string, &header->PlatformID);
+ json_object_object_add(header_ir, "platformID",
+ json_object_new_string(platform_string));
+ }
- //Creator ID of the header.
- char creator_string[GUID_STRING_LENGTH];
- guid_to_string(creator_string, &header->CreatorID);
- json_object_object_add(header_ir, "creatorID", json_object_new_string(creator_string));
+ //If a partition ID exists according to the validation bits, then add it.
+ if (header->ValidationBits & 0b100) {
+ char partition_string[GUID_STRING_LENGTH];
+ guid_to_string(partition_string, &header->PartitionID);
+ json_object_object_add(
+ header_ir, "partitionID",
+ json_object_new_string(partition_string));
+ }
- //Notification type for the header. Some defined types are available.
- json_object* notification_type = json_object_new_object();
- char notification_type_string[GUID_STRING_LENGTH];
- guid_to_string(notification_type_string, &header->NotificationType);
- json_object_object_add(notification_type, "guid", json_object_new_string(notification_type_string));
-
- //Add the human readable notification type if possible.
- char* notification_type_readable = "Unknown";
- if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCmcGuid))
- notification_type_readable = "CMC";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeCpeGuid))
- notification_type_readable = "CPE";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeMceGuid))
- notification_type_readable = "MCE";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePcieGuid))
- notification_type_readable = "PCIe";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeInitGuid))
- notification_type_readable = "INIT";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeNmiGuid))
- notification_type_readable = "NMI";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeBootGuid))
- notification_type_readable = "Boot";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeDmarGuid))
- notification_type_readable = "DMAr";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeaGuid))
- notification_type_readable = "SEA";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypeSeiGuid))
- notification_type_readable = "SEI";
- else if (guid_equal(&header->NotificationType, &gEfiEventNotificationTypePeiGuid))
- notification_type_readable = "PEI";
- 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);
+ //Creator ID of the header.
+ char creator_string[GUID_STRING_LENGTH];
+ guid_to_string(creator_string, &header->CreatorID);
+ json_object_object_add(header_ir, "creatorID",
+ json_object_new_string(creator_string));
- //The record ID for this record, unique on a given system.
- json_object_object_add(header_ir, "recordID", json_object_new_uint64(header->RecordID));
+ //Notification type for the header. Some defined types are available.
+ json_object *notification_type = json_object_new_object();
+ char notification_type_string[GUID_STRING_LENGTH];
+ guid_to_string(notification_type_string, &header->NotificationType);
+ json_object_object_add(
+ notification_type, "guid",
+ json_object_new_string(notification_type_string));
- //Flag for the record, and a human readable form.
- 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);
+ //Add the human readable notification type if possible.
+ char *notification_type_readable = "Unknown";
+ if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypeCmcGuid))
+ notification_type_readable = "CMC";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypeCpeGuid))
+ notification_type_readable = "CPE";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypeMceGuid))
+ notification_type_readable = "MCE";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypePcieGuid))
+ notification_type_readable = "PCIe";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypeInitGuid))
+ notification_type_readable = "INIT";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypeNmiGuid))
+ notification_type_readable = "NMI";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypeBootGuid))
+ notification_type_readable = "Boot";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypeDmarGuid))
+ notification_type_readable = "DMAr";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypeSeaGuid))
+ notification_type_readable = "SEA";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypeSeiGuid))
+ notification_type_readable = "SEI";
+ else if (guid_equal(&header->NotificationType,
+ &gEfiEventNotificationTypePeiGuid))
+ notification_type_readable = "PEI";
+ 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);
- //Persistence information. Outside the scope of specification, so just a uint32 here.
- json_object_object_add(header_ir, "persistenceInfo", json_object_new_uint64(header->PersistenceInfo));
- return header_ir;
+ //The record ID for this record, unique on a given system.
+ 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 = 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.
+ json_object_object_add(header_ir, "persistenceInfo",
+ json_object_new_uint64(header->PersistenceInfo));
+ return header_ir;
}
//Converts the given EFI section descriptor into JSON IR format.
-json_object* cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR* section_descriptor)
+json_object *
+cper_section_descriptor_to_ir(EFI_ERROR_SECTION_DESCRIPTOR *section_descriptor)
{
- json_object* section_descriptor_ir = json_object_new_object();
+ json_object *section_descriptor_ir = json_object_new_object();
- //The offset of the section from the base of the record header, length.
- json_object_object_add(section_descriptor_ir, "sectionOffset", json_object_new_uint64(section_descriptor->SectionOffset));
- json_object_object_add(section_descriptor_ir, "sectionLength", json_object_new_uint64(section_descriptor->SectionLength));
+ //The offset of the section from the base of the record header, length.
+ json_object_object_add(
+ section_descriptor_ir, "sectionOffset",
+ json_object_new_uint64(section_descriptor->SectionOffset));
+ json_object_object_add(
+ section_descriptor_ir, "sectionLength",
+ json_object_new_uint64(section_descriptor->SectionLength));
- //Revision.
- json_object_object_add(section_descriptor_ir, "revision", revision_to_ir(section_descriptor->Revision));
+ //Revision.
+ json_object_object_add(section_descriptor_ir, "revision",
+ revision_to_ir(section_descriptor->Revision));
- //Validation bits.
- json_object* validation_bits = bitfield_to_ir(section_descriptor->SecValidMask, 2, CPER_SECTION_DESCRIPTOR_VALID_BITFIELD_NAMES);
- json_object_object_add(section_descriptor_ir, "validationBits", validation_bits);
+ //Validation bits.
+ json_object *validation_bits =
+ bitfield_to_ir(section_descriptor->SecValidMask, 2,
+ CPER_SECTION_DESCRIPTOR_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_descriptor_ir, "validationBits",
+ validation_bits);
- //Flag bits.
- json_object* flags = bitfield_to_ir(section_descriptor->SectionFlags, 8, CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES);
- json_object_object_add(section_descriptor_ir, "flags", flags);
+ //Flag bits.
+ json_object *flags =
+ bitfield_to_ir(section_descriptor->SectionFlags, 8,
+ CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES);
+ json_object_object_add(section_descriptor_ir, "flags", flags);
- //Section type (GUID).
- json_object* section_type = json_object_new_object();
- char section_type_string[GUID_STRING_LENGTH];
- guid_to_string(section_type_string, §ion_descriptor->SectionType);
- json_object_object_add(section_type, "data", json_object_new_string(section_type_string));
+ //Section type (GUID).
+ json_object *section_type = json_object_new_object();
+ char section_type_string[GUID_STRING_LENGTH];
+ guid_to_string(section_type_string, §ion_descriptor->SectionType);
+ json_object_object_add(section_type, "data",
+ json_object_new_string(section_type_string));
- //Readable section type, if possible.
- char* section_type_readable = "Unknown";
- if (guid_equal(§ion_descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
- section_type_readable = "Processor Generic";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
- section_type_readable = "IA32/X64";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid))
- section_type_readable = "IPF";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid))
- section_type_readable = "ARM";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid)
- || guid_equal(§ion_descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid))
- section_type_readable = "Platform Memory";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiPcieErrorSectionGuid))
- section_type_readable = "PCIe";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiFirmwareErrorSectionGuid))
- section_type_readable = "Firmware Error Record Reference";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiPciBusErrorSectionGuid))
- section_type_readable = "PCI/PCI-X Bus";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiPciDevErrorSectionGuid))
- section_type_readable = "PCI Component/Device";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid))
- section_type_readable = "DMAr Generic";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
- section_type_readable = "Intel VT for Directed I/O specific DMAr section";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid))
- section_type_readable = "IOMMU specific DMAr section";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
- section_type_readable = "CCIX PER Log Error";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
- section_type_readable = "CXL Protocol Error";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid))
- section_type_readable = "CXL General Media Component Error";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid))
- section_type_readable = "CXL DRAM Component Error";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid))
- section_type_readable = "CXL Physical Switch Component Error";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid))
- section_type_readable = "CXL Virtual Switch Component Error";
- else if (guid_equal(§ion_descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid))
- section_type_readable = "CXL MLD Port Component Error";
+ //Readable section type, if possible.
+ char *section_type_readable = "Unknown";
+ if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiProcessorGenericErrorSectionGuid))
+ section_type_readable = "Processor Generic";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiIa32X64ProcessorErrorSectionGuid))
+ section_type_readable = "IA32/X64";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiIpfProcessorErrorSectionGuid))
+ section_type_readable = "IPF";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiArmProcessorErrorSectionGuid))
+ section_type_readable = "ARM";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiPlatformMemoryErrorSectionGuid) ||
+ guid_equal(§ion_descriptor->SectionType,
+ &gEfiPlatformMemoryError2SectionGuid))
+ section_type_readable = "Platform Memory";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiPcieErrorSectionGuid))
+ section_type_readable = "PCIe";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiFirmwareErrorSectionGuid))
+ section_type_readable = "Firmware Error Record Reference";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiPciBusErrorSectionGuid))
+ section_type_readable = "PCI/PCI-X Bus";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiPciDevErrorSectionGuid))
+ section_type_readable = "PCI Component/Device";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiDMArGenericErrorSectionGuid))
+ section_type_readable = "DMAr Generic";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiDirectedIoDMArErrorSectionGuid))
+ section_type_readable =
+ "Intel VT for Directed I/O specific DMAr section";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiIommuDMArErrorSectionGuid))
+ section_type_readable = "IOMMU specific DMAr section";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiCcixPerLogErrorSectionGuid))
+ section_type_readable = "CCIX PER Log Error";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiCxlProtocolErrorSectionGuid))
+ section_type_readable = "CXL Protocol Error";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiCxlGeneralMediaErrorSectionGuid))
+ section_type_readable = "CXL General Media Component Error";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiCxlDramEventErrorSectionGuid))
+ section_type_readable = "CXL DRAM Component Error";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiCxlPhysicalSwitchErrorSectionGuid))
+ section_type_readable = "CXL Physical Switch Component Error";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiCxlVirtualSwitchErrorSectionGuid))
+ section_type_readable = "CXL Virtual Switch Component Error";
+ else if (guid_equal(§ion_descriptor->SectionType,
+ &gEfiCxlMldPortErrorSectionGuid))
+ section_type_readable = "CXL MLD Port Component Error";
- json_object_object_add(section_type, "type", json_object_new_string(section_type_readable));
- json_object_object_add(section_descriptor_ir, "sectionType", section_type);
+ json_object_object_add(section_type, "type",
+ json_object_new_string(section_type_readable));
+ json_object_object_add(section_descriptor_ir, "sectionType",
+ section_type);
- //If validation bits indicate it exists, add FRU ID.
- if (section_descriptor->SecValidMask & 0b1)
- {
- char fru_id_string[GUID_STRING_LENGTH];
- guid_to_string(fru_id_string, §ion_descriptor->FruId);
- json_object_object_add(section_descriptor_ir, "fruID", json_object_new_string(fru_id_string));
- }
+ //If validation bits indicate it exists, add FRU ID.
+ if (section_descriptor->SecValidMask & 0b1) {
+ char fru_id_string[GUID_STRING_LENGTH];
+ guid_to_string(fru_id_string, §ion_descriptor->FruId);
+ json_object_object_add(section_descriptor_ir, "fruID",
+ json_object_new_string(fru_id_string));
+ }
- //If validation bits indicate it exists, add FRU text.
- if ((section_descriptor->SecValidMask & 0b10) >> 1)
- json_object_object_add(section_descriptor_ir, "fruText", json_object_new_string(section_descriptor->FruString));
+ //If validation bits indicate it exists, add FRU text.
+ if ((section_descriptor->SecValidMask & 0b10) >> 1)
+ json_object_object_add(
+ section_descriptor_ir, "fruText",
+ json_object_new_string(section_descriptor->FruString));
- //Section severity.
- json_object* section_severity = json_object_new_object();
- json_object_object_add(section_severity, "code", json_object_new_uint64(section_descriptor->Severity));
- json_object_object_add(section_severity, "name", json_object_new_string(severity_to_string(section_descriptor->Severity)));
- json_object_object_add(section_descriptor_ir, "severity", section_severity);
+ //Section severity.
+ json_object *section_severity = json_object_new_object();
+ json_object_object_add(
+ section_severity, "code",
+ json_object_new_uint64(section_descriptor->Severity));
+ json_object_object_add(section_severity, "name",
+ json_object_new_string(severity_to_string(
+ section_descriptor->Severity)));
+ json_object_object_add(section_descriptor_ir, "severity",
+ section_severity);
- return section_descriptor_ir;
+ return section_descriptor_ir;
}
-
//Converts the section described by a single given section descriptor.
-json_object* cper_section_to_ir(FILE* handle, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *cper_section_to_ir(FILE *handle,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- //Save our current position in the stream.
- long position = ftell(handle);
+ //Save our current position in the stream.
+ long position = ftell(handle);
- //Read section as described by the section descriptor.
- fseek(handle, descriptor->SectionOffset, SEEK_SET);
- void* section = malloc(descriptor->SectionLength);
- if (fread(section, descriptor->SectionLength, 1, handle) != 1)
- {
- printf("Section read failed: Could not read %d bytes from global offset %d.\n",
- descriptor->SectionLength,
- descriptor->SectionOffset);
- free(section);
- return NULL;
- }
+ //Read section as described by the section descriptor.
+ fseek(handle, descriptor->SectionOffset, SEEK_SET);
+ void *section = malloc(descriptor->SectionLength);
+ if (fread(section, descriptor->SectionLength, 1, handle) != 1) {
+ printf("Section read failed: Could not read %d bytes from global offset %d.\n",
+ descriptor->SectionLength, descriptor->SectionOffset);
+ free(section);
+ return NULL;
+ }
- //Seek back to our original position.
- fseek(handle, position, SEEK_SET);
+ //Seek back to our original position.
+ fseek(handle, position, SEEK_SET);
- //Parse section to IR based on GUID.
- json_object* result = NULL;
- if (guid_equal(&descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid))
- result = cper_section_generic_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
- result = cper_section_ia32x64_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid))
- result = cper_section_ipf_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid))
- result = cper_section_arm_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid))
- result = cper_section_platform_memory_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid))
- result = cper_section_platform_memory2_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiPcieErrorSectionGuid))
- result = cper_section_pcie_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid))
- result = cper_section_firmware_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid))
- result = cper_section_pci_bus_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid))
- result = cper_section_pci_dev_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid))
- result = cper_section_dmar_generic_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
- result = cper_section_dmar_vtd_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid))
- result = cper_section_dmar_iommu_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid))
- result = cper_section_ccix_per_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid))
- result = cper_section_cxl_protocol_to_ir(section, descriptor);
- else if (guid_equal(&descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid)
- || guid_equal(&descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid)
- || guid_equal(&descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid)
- || guid_equal(&descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid)
- || guid_equal(&descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid))
- {
- result = cper_section_cxl_component_to_ir(section, descriptor);
- }
- else
- {
- //Failed read, unknown GUID.
- //Output the data as formatted base64.
- result = json_object_new_object();
- char* encoded = b64_encode((unsigned char*)section, descriptor->SectionLength);
- json_object_object_add(result, "data", json_object_new_string(encoded));
- free(encoded);
- }
+ //Parse section to IR based on GUID.
+ json_object *result = NULL;
+ if (guid_equal(&descriptor->SectionType,
+ &gEfiProcessorGenericErrorSectionGuid))
+ result = cper_section_generic_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiIa32X64ProcessorErrorSectionGuid))
+ result = cper_section_ia32x64_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiIpfProcessorErrorSectionGuid))
+ result = cper_section_ipf_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiArmProcessorErrorSectionGuid))
+ result = cper_section_arm_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiPlatformMemoryErrorSectionGuid))
+ result =
+ cper_section_platform_memory_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiPlatformMemoryError2SectionGuid))
+ result = cper_section_platform_memory2_to_ir(section,
+ descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiPcieErrorSectionGuid))
+ result = cper_section_pcie_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiFirmwareErrorSectionGuid))
+ result = cper_section_firmware_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiPciBusErrorSectionGuid))
+ result = cper_section_pci_bus_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiPciDevErrorSectionGuid))
+ result = cper_section_pci_dev_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiDMArGenericErrorSectionGuid))
+ result = cper_section_dmar_generic_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiDirectedIoDMArErrorSectionGuid))
+ result = cper_section_dmar_vtd_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiIommuDMArErrorSectionGuid))
+ result = cper_section_dmar_iommu_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiCcixPerLogErrorSectionGuid))
+ result = cper_section_ccix_per_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiCxlProtocolErrorSectionGuid))
+ result = cper_section_cxl_protocol_to_ir(section, descriptor);
+ else if (guid_equal(&descriptor->SectionType,
+ &gEfiCxlGeneralMediaErrorSectionGuid) ||
+ guid_equal(&descriptor->SectionType,
+ &gEfiCxlDramEventErrorSectionGuid) ||
+ guid_equal(&descriptor->SectionType,
+ &gEfiCxlPhysicalSwitchErrorSectionGuid) ||
+ guid_equal(&descriptor->SectionType,
+ &gEfiCxlVirtualSwitchErrorSectionGuid) ||
+ guid_equal(&descriptor->SectionType,
+ &gEfiCxlMldPortErrorSectionGuid)) {
+ result = cper_section_cxl_component_to_ir(section, descriptor);
+ } else {
+ //Failed read, unknown GUID.
+ //Output the data as formatted base64.
+ result = json_object_new_object();
+ char *encoded = b64_encode((unsigned char *)section,
+ descriptor->SectionLength);
+ json_object_object_add(result, "data",
+ json_object_new_string(encoded));
+ free(encoded);
+ }
- //Free section memory, return result.
- free(section);
- return result;
+ //Free section memory, return result.
+ free(section);
+ return result;
}
\ No newline at end of file
diff --git a/cper-utils.c b/cper-utils.c
index 0eadf10..519349f 100644
--- a/cper-utils.c
+++ b/cper-utils.c
@@ -10,288 +10,301 @@
#include "cper-utils.h"
//The available severity types for CPER.
-const char* CPER_SEVERITY_TYPES[4] = {"Recoverable", "Fatal", "Corrected", "Informational"};
+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 *
+cper_generic_error_status_to_ir(EFI_GENERIC_ERROR_STATUS *error_status)
{
- json_object* error_status_ir = json_object_new_object();
+ 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)"));
+ //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, "overflowDroppedLogs", json_object_new_boolean(error_status->OverflowNotLogged));
-
- return error_status_ir;
+ //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, "overflowDroppedLogs",
+ json_object_new_boolean(error_status->OverflowNotLogged));
+
+ return error_status_ir;
}
//Converts the given CPER-JSON generic error status into a CPER structure.
-void ir_generic_error_status_to_cper(json_object* error_status, EFI_GENERIC_ERROR_STATUS* error_status_cper)
+void ir_generic_error_status_to_cper(
+ json_object *error_status, EFI_GENERIC_ERROR_STATUS *error_status_cper)
{
- error_status_cper->Type = readable_pair_to_integer(json_object_object_get(error_status, "errorType"));
- error_status_cper->AddressSignal = json_object_get_boolean(json_object_object_get(error_status, "addressSignal"));
- error_status_cper->ControlSignal = json_object_get_boolean(json_object_object_get(error_status, "controlSignal"));
- error_status_cper->DataSignal = json_object_get_boolean(json_object_object_get(error_status, "dataSignal"));
- error_status_cper->DetectedByResponder = json_object_get_boolean(json_object_object_get(error_status, "detectedByResponder"));
- error_status_cper->DetectedByRequester = json_object_get_boolean(json_object_object_get(error_status, "detectedByRequester"));
- error_status_cper->FirstError = json_object_get_boolean(json_object_object_get(error_status, "firstError"));
- error_status_cper->OverflowNotLogged = json_object_get_boolean(json_object_object_get(error_status, "overflowDroppedLogs"));
+ error_status_cper->Type = readable_pair_to_integer(
+ json_object_object_get(error_status, "errorType"));
+ error_status_cper->AddressSignal = json_object_get_boolean(
+ json_object_object_get(error_status, "addressSignal"));
+ error_status_cper->ControlSignal = json_object_get_boolean(
+ json_object_object_get(error_status, "controlSignal"));
+ error_status_cper->DataSignal = json_object_get_boolean(
+ json_object_object_get(error_status, "dataSignal"));
+ error_status_cper->DetectedByResponder = json_object_get_boolean(
+ json_object_object_get(error_status, "detectedByResponder"));
+ error_status_cper->DetectedByRequester = json_object_get_boolean(
+ json_object_object_get(error_status, "detectedByRequester"));
+ error_status_cper->FirstError = json_object_get_boolean(
+ json_object_object_get(error_status, "firstError"));
+ error_status_cper->OverflowNotLogged = json_object_get_boolean(
+ json_object_object_get(error_status, "overflowDroppedLogs"));
}
//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 *uniform_struct64_to_ir(UINT64 *start, int len, const char *names[])
{
- json_object* result = json_object_new_object();
+ json_object *result = json_object_new_object();
- UINT64* cur = start;
- for (int i=0; i<len; i++)
- {
- json_object_object_add(result, names[i], json_object_new_uint64(*cur));
- cur++;
- }
+ UINT64 *cur = start;
+ for (int i = 0; i < len; i++) {
+ json_object_object_add(result, names[i],
+ json_object_new_uint64(*cur));
+ cur++;
+ }
- return result;
+ return result;
}
//Converts a single uniform struct of UINT32s into intermediate JSON IR format, given names for each field in byte order.
-json_object* uniform_struct_to_ir(UINT32* start, int len, const char* names[])
+json_object *uniform_struct_to_ir(UINT32 *start, int len, const char *names[])
{
- json_object* result = json_object_new_object();
+ json_object *result = json_object_new_object();
- UINT32* cur = start;
- for (int i=0; i<len; i++)
- {
- json_object_object_add(result, names[i], json_object_new_uint64(*cur));
- cur++;
- }
+ UINT32 *cur = start;
+ for (int i = 0; i < len; i++) {
+ json_object_object_add(result, names[i],
+ json_object_new_uint64(*cur));
+ cur++;
+ }
- return result;
+ return result;
}
//Converts a single object containing UINT32s into a uniform struct.
-void ir_to_uniform_struct64(json_object* ir, UINT64* start, int len, const char* names[])
+void ir_to_uniform_struct64(json_object *ir, UINT64 *start, int len,
+ const char *names[])
{
- UINT64* cur = start;
- for (int i=0; i<len; i++)
- {
- *cur = json_object_get_uint64(json_object_object_get(ir, names[i]));
- cur++;
- }
+ UINT64 *cur = start;
+ for (int i = 0; i < len; i++) {
+ *cur = json_object_get_uint64(
+ json_object_object_get(ir, names[i]));
+ cur++;
+ }
}
//Converts a single object containing UINT32s into a uniform struct.
-void ir_to_uniform_struct(json_object* ir, UINT32* start, int len, const char* names[])
+void ir_to_uniform_struct(json_object *ir, UINT32 *start, int len,
+ const char *names[])
{
- UINT32* cur = start;
- for (int i=0; i<len; i++)
- {
- *cur = (UINT32)json_object_get_uint64(json_object_object_get(ir, names[i]));
- cur++;
- }
+ UINT32 *cur = start;
+ for (int i = 0; i < len; i++) {
+ *cur = (UINT32)json_object_get_uint64(
+ json_object_object_get(ir, names[i]));
+ cur++;
+ }
}
//Converts a single integer value to an object containing a value, and a readable name if possible.
-json_object* integer_to_readable_pair(UINT64 value, int len, int keys[], const char* values[], const char* default_value)
+json_object *integer_to_readable_pair(UINT64 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_uint64(value));
+ json_object *result = json_object_new_object();
+ json_object_object_add(result, "value", json_object_new_uint64(value));
- //Search for human readable name, add.
- const char* name = default_value;
- for (int i=0; i<len; i++)
- {
- if (keys[i] == value)
- name = values[i];
- }
+ //Search for human readable name, add.
+ const 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;
+ json_object_object_add(result, "name", json_object_new_string(name));
+ return result;
}
//Converts a single integer value to an object containing a value, readable name and description if possible.
-json_object* integer_to_readable_pair_with_desc(int value, int len, int keys[], const char* values[],
- const char* descriptions[], const char* default_value)
+json_object *integer_to_readable_pair_with_desc(int value, int len, int keys[],
+ const char *values[],
+ const char *descriptions[],
+ const char *default_value)
{
- json_object* result = json_object_new_object();
- json_object_object_add(result, "value", json_object_new_int(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.
- const char* name = default_value;
- for (int i=0; i<len; i++)
- {
- if (keys[i] == value)
- {
- name = values[i];
- json_object_object_add(result, "description", json_object_new_string(descriptions[i]));
- }
- }
+ //Search for human readable name, add.
+ const char *name = default_value;
+ for (int i = 0; i < len; i++) {
+ if (keys[i] == value) {
+ name = values[i];
+ json_object_object_add(
+ result, "description",
+ json_object_new_string(descriptions[i]));
+ }
+ }
- json_object_object_add(result, "name", json_object_new_string(name));
- return result;
+ json_object_object_add(result, "name", json_object_new_string(name));
+ return result;
}
//Returns a single UINT64 value from the given readable pair object.
//Assumes the integer value is held in the "value" field.
-UINT64 readable_pair_to_integer(json_object* pair)
+UINT64 readable_pair_to_integer(json_object *pair)
{
- return json_object_get_uint64(json_object_object_get(pair, "value"));
+ return json_object_get_uint64(json_object_object_get(pair, "value"));
}
//Converts the given 64 bit bitfield to IR, assuming bit 0 starts on the left.
-json_object* bitfield_to_ir(UINT64 bitfield, int num_fields, const char* names[])
+json_object *bitfield_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 >> i) & 0b1));
- }
+ 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 >> i) &
+ 0b1));
+ }
- return result;
+ return result;
}
//Converts the given IR bitfield into a standard UINT64 bitfield, with fields beginning from bit 0.
-UINT64 ir_to_bitfield(json_object* ir, int num_fields, const char* names[])
+UINT64 ir_to_bitfield(json_object *ir, int num_fields, const char *names[])
{
- UINT64 result = 0x0;
- for (int i=0; i<num_fields; i++)
- {
- if (json_object_get_boolean(json_object_object_get(ir, names[i])))
- result |= (0x1 << i);
- }
+ UINT64 result = 0x0;
+ for (int i = 0; i < num_fields; i++) {
+ if (json_object_get_boolean(
+ json_object_object_get(ir, names[i])))
+ result |= (0x1 << i);
+ }
- return result;
+ 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 *uint64_array_to_ir_array(UINT64 *array, int len)
{
- json_object* array_ir = json_object_new_array();
- for (int i=0; i<len; i++)
- json_object_array_add(array_ir, json_object_new_uint64(array[i]));
- return array_ir;
+ json_object *array_ir = json_object_new_array();
+ for (int i = 0; i < len; i++)
+ json_object_array_add(array_ir,
+ json_object_new_uint64(array[i]));
+ return array_ir;
}
//Converts a single UINT16 revision number into JSON IR representation.
-json_object* revision_to_ir(UINT16 revision)
+json_object *revision_to_ir(UINT16 revision)
{
- json_object* revision_info = json_object_new_object();
- json_object_object_add(revision_info, "major", json_object_new_int(revision >> 8));
- json_object_object_add(revision_info, "minor", json_object_new_int(revision & 0xFF));
- return revision_info;
+ json_object *revision_info = json_object_new_object();
+ json_object_object_add(revision_info, "major",
+ json_object_new_int(revision >> 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(UINT32 severity)
+const char *severity_to_string(UINT32 severity)
{
- return severity < 4 ? CPER_SEVERITY_TYPES[severity] : "Unknown";
+ return severity < 4 ? CPER_SEVERITY_TYPES[severity] : "Unknown";
}
//Converts a single EFI timestamp to string, at the given output.
//Output must be at least TIMESTAMP_LENGTH bytes long.
-void timestamp_to_string(char* out, EFI_ERROR_TIME_STAMP* timestamp)
+void timestamp_to_string(char *out, EFI_ERROR_TIME_STAMP *timestamp)
{
- sprintf(out, "%02hhu%02hhu-%02hhu-%02hhuT%02hhu:%02hhu:%02hhu.000",
- bcd_to_int(timestamp->Century) % 100, //Cannot go to three digits.
- bcd_to_int(timestamp->Year) % 100, //Cannot go to three digits.
- bcd_to_int(timestamp->Month),
- bcd_to_int(timestamp->Day),
- bcd_to_int(timestamp->Hours),
- bcd_to_int(timestamp->Minutes),
- bcd_to_int(timestamp->Seconds));
+ sprintf(out, "%02hhu%02hhu-%02hhu-%02hhuT%02hhu:%02hhu:%02hhu.000",
+ bcd_to_int(timestamp->Century) %
+ 100, //Cannot go to three digits.
+ bcd_to_int(timestamp->Year) % 100, //Cannot go to three digits.
+ bcd_to_int(timestamp->Month), bcd_to_int(timestamp->Day),
+ bcd_to_int(timestamp->Hours), bcd_to_int(timestamp->Minutes),
+ bcd_to_int(timestamp->Seconds));
}
//Converts a single timestamp string to an EFI timestamp.
-void string_to_timestamp(EFI_ERROR_TIME_STAMP* out, const char* timestamp)
+void string_to_timestamp(EFI_ERROR_TIME_STAMP *out, const char *timestamp)
{
- //Ignore invalid timestamps.
- if (timestamp == NULL)
- return;
+ //Ignore invalid timestamps.
+ if (timestamp == NULL)
+ return;
- sscanf(timestamp, "%2hhu%2hhu-%hhu-%hhuT%hhu:%hhu:%hhu.000",
- &out->Century,
- &out->Year,
- &out->Month,
- &out->Day,
- &out->Hours,
- &out->Minutes,
- &out->Seconds);
+ sscanf(timestamp, "%2hhu%2hhu-%hhu-%hhuT%hhu:%hhu:%hhu.000",
+ &out->Century, &out->Year, &out->Month, &out->Day, &out->Hours,
+ &out->Minutes, &out->Seconds);
- //Convert back to BCD.
- out->Century = int_to_bcd(out->Century);
- out->Year = int_to_bcd(out->Year);
- out->Month = int_to_bcd(out->Month);
- out->Day = int_to_bcd(out->Day);
- out->Hours = int_to_bcd(out->Hours);
- out->Minutes = int_to_bcd(out->Minutes);
- out->Seconds = int_to_bcd(out->Seconds);
+ //Convert back to BCD.
+ out->Century = int_to_bcd(out->Century);
+ out->Year = int_to_bcd(out->Year);
+ out->Month = int_to_bcd(out->Month);
+ out->Day = int_to_bcd(out->Day);
+ out->Hours = int_to_bcd(out->Hours);
+ out->Minutes = int_to_bcd(out->Minutes);
+ out->Seconds = int_to_bcd(out->Seconds);
}
//Helper function to convert an EDK EFI GUID into a string for intermediate use.
-void guid_to_string(char* out, EFI_GUID* guid)
+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]);
+ 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]);
}
//Helper function to convert a string into an EDK EFI GUID.
-void string_to_guid(EFI_GUID* out, const char* guid)
+void string_to_guid(EFI_GUID *out, const char *guid)
{
- //Ignore invalid GUIDs.
- if (guid == NULL)
- return;
+ //Ignore invalid GUIDs.
+ if (guid == NULL)
+ return;
- sscanf(guid, "%08x-%04hx-%04hx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
- &out->Data1,
- &out->Data2,
- &out->Data3,
- out->Data4,
- out->Data4 + 1,
- out->Data4 + 2,
- out->Data4 + 3,
- out->Data4 + 4,
- out->Data4 + 5,
- out->Data4 + 6,
- out->Data4 + 7);
+ sscanf(guid,
+ "%08x-%04hx-%04hx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
+ &out->Data1, &out->Data2, &out->Data3, out->Data4,
+ out->Data4 + 1, out->Data4 + 2, out->Data4 + 3, out->Data4 + 4,
+ out->Data4 + 5, out->Data4 + 6, out->Data4 + 7);
}
//Returns one if two EFI GUIDs are equal, zero otherwise.
-int guid_equal(EFI_GUID* a, EFI_GUID* b)
+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 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;
- }
+ //Check Data4 array for equality.
+ for (int i = 0; i < 8; i++) {
+ if (a->Data4[i] != b->Data4[i])
+ return 0;
+ }
- return 1;
+ return 1;
}
\ No newline at end of file
diff --git a/generator/cper-generate-cli.c b/generator/cper-generate-cli.c
index 0b17efe..7afc2aa 100644
--- a/generator/cper-generate-cli.c
+++ b/generator/cper-generate-cli.c
@@ -11,60 +11,57 @@
void print_help();
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
{
- //If help requested, print help.
- if (argc == 2 && strcmp(argv[1], "--help") == 0)
- {
- print_help();
- return 0;
- }
+ //If help requested, print help.
+ if (argc == 2 && strcmp(argv[1], "--help") == 0) {
+ print_help();
+ return 0;
+ }
- //Ensure the minimum number of arguments.
- if (argc < 5)
- {
- printf("Insufficient number of arguments. See 'cper-generate --help' for command information.\n");
- return -1;
- }
+ //Ensure the minimum number of arguments.
+ if (argc < 5) {
+ printf("Insufficient number of arguments. See 'cper-generate --help' for command information.\n");
+ return -1;
+ }
- //Open a file handle to write output.
- FILE* cper_file = fopen(argv[2], "w");
- if (cper_file == NULL)
- {
- printf("Could not get a handle for output file '%s', file handle returned null.\n", argv[2]);
- return -1;
- }
+ //Open a file handle to write output.
+ FILE *cper_file = fopen(argv[2], "w");
+ if (cper_file == NULL) {
+ printf("Could not get a handle for output file '%s', file handle returned null.\n",
+ argv[2]);
+ return -1;
+ }
- //Generate the record. Type names start from argv[4].
- UINT16 num_sections = argc - 4;
- generate_cper_record(argv + 4, num_sections, cper_file);
- fclose(cper_file);
+ //Generate the record. Type names start from argv[4].
+ UINT16 num_sections = argc - 4;
+ generate_cper_record(argv + 4, num_sections, cper_file);
+ fclose(cper_file);
}
-
//Prints command help for this CPER generator.
void print_help()
{
- printf(":: --out cper.file --sections section1 [section2 section3 ...]\n");
- printf("\tGenerates a psuedo-random CPER file with the provided section types and outputs to the given file name.\n");
- printf("\tValid section type names are the following:\n");
- printf("\t\t- generic\n");
- printf("\t\t- ia32x64\n");
- printf("\t\t- ipf\n");
- printf("\t\t- arm\n");
- printf("\t\t- memory\n");
- printf("\t\t- memory2\n");
- printf("\t\t- pcie\n");
- printf("\t\t- firmware\n");
- printf("\t\t- pcibus\n");
- printf("\t\t- pcidev\n");
- printf("\t\t- dmargeneric\n");
- printf("\t\t- dmarvtd\n");
- printf("\t\t- dmariommu\n");
- printf("\t\t- ccixper\n");
- printf("\t\t- cxlprotocol\n");
- printf("\t\t- cxlcomponent\n");
- printf("\t\t- unknown\n");
- printf("\n:: --help\n");
- printf("\tDisplays help information to the console.\n");
+ printf(":: --out cper.file --sections section1 [section2 section3 ...]\n");
+ printf("\tGenerates a psuedo-random CPER file with the provided section types and outputs to the given file name.\n");
+ printf("\tValid section type names are the following:\n");
+ printf("\t\t- generic\n");
+ printf("\t\t- ia32x64\n");
+ printf("\t\t- ipf\n");
+ printf("\t\t- arm\n");
+ printf("\t\t- memory\n");
+ printf("\t\t- memory2\n");
+ printf("\t\t- pcie\n");
+ printf("\t\t- firmware\n");
+ printf("\t\t- pcibus\n");
+ printf("\t\t- pcidev\n");
+ printf("\t\t- dmargeneric\n");
+ printf("\t\t- dmarvtd\n");
+ printf("\t\t- dmariommu\n");
+ printf("\t\t- ccixper\n");
+ printf("\t\t- cxlprotocol\n");
+ printf("\t\t- cxlcomponent\n");
+ printf("\t\t- unknown\n");
+ printf("\n:: --help\n");
+ printf("\tDisplays help information to the console.\n");
}
\ No newline at end of file
diff --git a/generator/cper-generate.c b/generator/cper-generate.c
index 7e7cc40..b1389b5 100644
--- a/generator/cper-generate.c
+++ b/generator/cper-generate.c
@@ -12,225 +12,254 @@
#include "sections/gen-sections.h"
#include "cper-generate.h"
-EFI_ERROR_SECTION_DESCRIPTOR* generate_section_descriptor(char* type, size_t* lengths, int index, int num_sections);
-size_t generate_section(void** location, char* type);
+EFI_ERROR_SECTION_DESCRIPTOR *generate_section_descriptor(char *type,
+ size_t *lengths,
+ int index,
+ int num_sections);
+size_t generate_section(void **location, char *type);
//Generates a CPER record with the given section types, outputting to the given stream.
-void generate_cper_record(char** types, UINT16 num_sections, FILE* out)
+void generate_cper_record(char **types, UINT16 num_sections, FILE *out)
{
- //Initialise randomiser.
- init_random();
+ //Initialise randomiser.
+ init_random();
- //Generate the sections.
- void* sections[num_sections];
- size_t section_lengths[num_sections];
- for (int i=0; i<num_sections; i++)
- {
- section_lengths[i] = generate_section(sections + i, types[i]);
- if (section_lengths[i] == 0)
- {
- //Error encountered, exit.
- printf("Error encountered generating section %d of type '%s', length returned zero.\n", i+1, types[i]);
- return;
- }
- }
+ //Generate the sections.
+ void *sections[num_sections];
+ size_t section_lengths[num_sections];
+ for (int i = 0; i < num_sections; i++) {
+ section_lengths[i] = generate_section(sections + i, types[i]);
+ if (section_lengths[i] == 0) {
+ //Error encountered, exit.
+ printf("Error encountered generating section %d of type '%s', length returned zero.\n",
+ i + 1, types[i]);
+ return;
+ }
+ }
- //Generate the header given the number of sections.
- EFI_COMMON_ERROR_RECORD_HEADER* header =
- (EFI_COMMON_ERROR_RECORD_HEADER*)calloc(1, sizeof(EFI_COMMON_ERROR_RECORD_HEADER));
- header->SignatureStart = 0x52455043; //CPER
- header->SectionCount = num_sections;
- header->SignatureEnd = 0xFFFFFFFF;
- header->Flags = 4; //HW_ERROR_FLAGS_SIMULATED
- header->RecordID = (UINT64)rand();
- header->ErrorSeverity = rand() % 4;
+ //Generate the header given the number of sections.
+ EFI_COMMON_ERROR_RECORD_HEADER *header =
+ (EFI_COMMON_ERROR_RECORD_HEADER *)calloc(
+ 1, sizeof(EFI_COMMON_ERROR_RECORD_HEADER));
+ header->SignatureStart = 0x52455043; //CPER
+ header->SectionCount = num_sections;
+ header->SignatureEnd = 0xFFFFFFFF;
+ header->Flags = 4; //HW_ERROR_FLAGS_SIMULATED
+ header->RecordID = (UINT64)rand();
+ header->ErrorSeverity = rand() % 4;
- //Generate a valid timestamp.
- header->TimeStamp.Century = int_to_bcd(rand() % 100);
- header->TimeStamp.Year = int_to_bcd(rand() % 100);
- header->TimeStamp.Month = int_to_bcd(rand() % 12 + 1);
- header->TimeStamp.Day = int_to_bcd(rand() % 31 + 1);
- header->TimeStamp.Hours = int_to_bcd(rand() % 24 + 1);
- header->TimeStamp.Seconds = int_to_bcd(rand() % 60);
+ //Generate a valid timestamp.
+ header->TimeStamp.Century = int_to_bcd(rand() % 100);
+ header->TimeStamp.Year = int_to_bcd(rand() % 100);
+ header->TimeStamp.Month = int_to_bcd(rand() % 12 + 1);
+ header->TimeStamp.Day = int_to_bcd(rand() % 31 + 1);
+ header->TimeStamp.Hours = int_to_bcd(rand() % 24 + 1);
+ header->TimeStamp.Seconds = int_to_bcd(rand() % 60);
- //Turn all validation bits on.
- header->ValidationBits = 0b11;
+ //Turn all validation bits on.
+ header->ValidationBits = 0b11;
- //Generate the section descriptors given the number of sections.
- EFI_ERROR_SECTION_DESCRIPTOR* section_descriptors[num_sections];
- for (int i=0; i<num_sections; i++)
- section_descriptors[i] = generate_section_descriptor(types[i], section_lengths, i, num_sections);
+ //Generate the section descriptors given the number of sections.
+ EFI_ERROR_SECTION_DESCRIPTOR *section_descriptors[num_sections];
+ for (int i = 0; i < num_sections; i++)
+ section_descriptors[i] = generate_section_descriptor(
+ types[i], section_lengths, i, num_sections);
- //Calculate total length of structure, set in header.
- size_t total_len = sizeof(EFI_COMMON_ERROR_RECORD_HEADER);
- for (int i=0; i<num_sections; i++)
- total_len += section_lengths[i];
- total_len += num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR);
- header->RecordLength = (UINT32)total_len;
+ //Calculate total length of structure, set in header.
+ size_t total_len = sizeof(EFI_COMMON_ERROR_RECORD_HEADER);
+ for (int i = 0; i < num_sections; i++)
+ total_len += section_lengths[i];
+ total_len += num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR);
+ header->RecordLength = (UINT32)total_len;
- //Write to stream in order, free all resources.
- fwrite(header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, out);
- fflush(out);
- free(header);
- for (int i=0; i<num_sections; i++)
- {
- fwrite(section_descriptors[i], sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, out);
- fflush(out);
- free(section_descriptors[i]);
- }
- for (int i=0; i<num_sections; i++)
- {
- fwrite(sections[i], section_lengths[i], 1, out);
- fflush(out);
- free(sections[i]);
- }
+ //Write to stream in order, free all resources.
+ fwrite(header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, out);
+ fflush(out);
+ free(header);
+ for (int i = 0; i < num_sections; i++) {
+ fwrite(section_descriptors[i],
+ sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, out);
+ fflush(out);
+ free(section_descriptors[i]);
+ }
+ for (int i = 0; i < num_sections; i++) {
+ fwrite(sections[i], section_lengths[i], 1, out);
+ fflush(out);
+ free(sections[i]);
+ }
}
//Generates a single section descriptor for a section with the given properties.
-EFI_ERROR_SECTION_DESCRIPTOR* generate_section_descriptor(char* type, size_t* lengths, int index, int num_sections)
+EFI_ERROR_SECTION_DESCRIPTOR *generate_section_descriptor(char *type,
+ size_t *lengths,
+ int index,
+ int num_sections)
{
- EFI_ERROR_SECTION_DESCRIPTOR* descriptor =
- (EFI_ERROR_SECTION_DESCRIPTOR*)generate_random_bytes(sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor =
+ (EFI_ERROR_SECTION_DESCRIPTOR *)generate_random_bytes(
+ sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
- //Set reserved bits to zero.
- descriptor->Resv1 = 0;
- descriptor->SectionFlags &= 0xFF;
+ //Set reserved bits to zero.
+ descriptor->Resv1 = 0;
+ descriptor->SectionFlags &= 0xFF;
- //Validation bits all set to 'on'.
- descriptor->SecValidMask = 0b11;
+ //Validation bits all set to 'on'.
+ descriptor->SecValidMask = 0b11;
- //Set severity.
- descriptor->Severity = rand() % 4;
+ //Set severity.
+ descriptor->Severity = rand() % 4;
- //Set length, offset from base record.
- descriptor->SectionLength = (UINT32)lengths[index];
- descriptor->SectionOffset = sizeof(EFI_COMMON_ERROR_RECORD_HEADER)
- + (num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
- for (int i=0; i<index; i++)
- descriptor->SectionOffset += lengths[i];
-
- //Ensure the FRU text is not null terminated early.
- for (int i=0; i<20; i++)
- {
- if (descriptor->FruString[i] == 0x0)
- descriptor->FruString[i] = rand() % 127 + 1;
+ //Set length, offset from base record.
+ descriptor->SectionLength = (UINT32)lengths[index];
+ descriptor->SectionOffset =
+ sizeof(EFI_COMMON_ERROR_RECORD_HEADER) +
+ (num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
+ for (int i = 0; i < index; i++)
+ descriptor->SectionOffset += lengths[i];
- //Null terminate last byte.
- if (i == 19)
- descriptor->FruString[i] = 0x0;
- }
+ //Ensure the FRU text is not null terminated early.
+ for (int i = 0; i < 20; i++) {
+ if (descriptor->FruString[i] == 0x0)
+ descriptor->FruString[i] = rand() % 127 + 1;
- //Set section type GUID based on type name.
- if (strcmp(type, "generic") == 0)
- memcpy(&descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "ia32x64") == 0)
- memcpy(&descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "ipf") == 0)
- memcpy(&descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "arm") == 0)
- memcpy(&descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "memory") == 0)
- memcpy(&descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "memory2") == 0)
- memcpy(&descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "pcie") == 0)
- memcpy(&descriptor->SectionType, &gEfiPcieErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "firmware") == 0)
- memcpy(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "pcibus") == 0)
- memcpy(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "pcidev") == 0)
- memcpy(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "dmargeneric") == 0)
- memcpy(&descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "dmarvtd") == 0)
- memcpy(&descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "dmariommu") == 0)
- memcpy(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "ccixper") == 0)
- memcpy(&descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "cxlprotocol") == 0)
- memcpy(&descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "cxlcomponent") == 0)
- {
- //Choose between the different CXL component type GUIDs.
- int componentType = rand() % 5;
- switch (componentType)
- {
- case 0:
- memcpy(&descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid, sizeof(EFI_GUID));
- break;
- case 1:
- memcpy(&descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid, sizeof(EFI_GUID));
- break;
- case 2:
- memcpy(&descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid, sizeof(EFI_GUID));
- break;
- case 3:
- memcpy(&descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid, sizeof(EFI_GUID));
- break;
- default:
- memcpy(&descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid, sizeof(EFI_GUID));
- break;
- }
- }
- else if (strcmp(type, "unknown") != 0)
- {
- //Undefined section, show error.
- printf("Undefined section type '%s' provided. See 'cper-generate --help' for command information.\n", type);
- return 0;
- }
+ //Null terminate last byte.
+ if (i == 19)
+ descriptor->FruString[i] = 0x0;
+ }
- return descriptor;
+ //Set section type GUID based on type name.
+ if (strcmp(type, "generic") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiProcessorGenericErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "ia32x64") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiIa32X64ProcessorErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "ipf") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiIpfProcessorErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "arm") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiArmProcessorErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "memory") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiPlatformMemoryErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "memory2") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiPlatformMemoryError2SectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "pcie") == 0)
+ memcpy(&descriptor->SectionType, &gEfiPcieErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "firmware") == 0)
+ memcpy(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "pcibus") == 0)
+ memcpy(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "pcidev") == 0)
+ memcpy(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "dmargeneric") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiDMArGenericErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "dmarvtd") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiDirectedIoDMArErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "dmariommu") == 0)
+ memcpy(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "ccixper") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiCcixPerLogErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "cxlprotocol") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlProtocolErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "cxlcomponent") == 0) {
+ //Choose between the different CXL component type GUIDs.
+ int componentType = rand() % 5;
+ switch (componentType) {
+ case 0:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlGeneralMediaErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ case 1:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlDramEventErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ case 2:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlPhysicalSwitchErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ case 3:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlVirtualSwitchErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ default:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlMldPortErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ }
+ } else if (strcmp(type, "unknown") != 0) {
+ //Undefined section, show error.
+ printf("Undefined section type '%s' provided. See 'cper-generate --help' for command information.\n",
+ type);
+ return 0;
+ }
+
+ return descriptor;
}
//Generates a single CPER section given the string type.
-size_t generate_section(void** location, char* type)
+size_t generate_section(void **location, char *type)
{
- //The length of the section.
- size_t length = 0;
+ //The length of the section.
+ size_t length = 0;
- //Switch on the type, generate accordingly.
- if (strcmp(type, "generic") == 0)
- length = generate_section_generic(location);
- else if (strcmp(type, "ia32x64") == 0)
- length = generate_section_ia32x64(location);
- // else if (strcmp(type, "ipf") == 0)
- // length = generate_section_ipf(location);
- else if (strcmp(type, "arm") == 0)
- length = generate_section_arm(location);
- else if (strcmp(type, "memory") == 0)
- length = generate_section_memory(location);
- else if (strcmp(type, "memory2") == 0)
- length = generate_section_memory2(location);
- else if (strcmp(type, "pcie") == 0)
- length = generate_section_pcie(location);
- else if (strcmp(type, "firmware") == 0)
- length = generate_section_firmware(location);
- else if (strcmp(type, "pcibus") == 0)
- length = generate_section_pci_bus(location);
- else if (strcmp(type, "pcidev") == 0)
- length = generate_section_pci_dev(location);
- else if (strcmp(type, "dmargeneric") == 0)
- length = generate_section_dmar_generic(location);
- else if (strcmp(type, "dmarvtd") == 0)
- length = generate_section_dmar_vtd(location);
- else if (strcmp(type, "dmariommu") == 0)
- length = generate_section_dmar_iommu(location);
- else if (strcmp(type, "ccixper") == 0)
- length = generate_section_ccix_per(location);
- else if (strcmp(type, "cxlprotocol") == 0)
- length = generate_section_cxl_protocol(location);
- else if (strcmp(type, "cxlcomponent") == 0)
- length = generate_section_cxl_component(location);
- else if (strcmp(type, "unknown") == 0)
- length = generate_random_section(location, rand() % 256);
- else
- {
- //Undefined section, show error.
- printf("Undefined section type '%s' given to generate. See 'cper-generate --help' for command information.\n", type);
- return 0;
- }
+ //Switch on the type, generate accordingly.
+ if (strcmp(type, "generic") == 0)
+ length = generate_section_generic(location);
+ else if (strcmp(type, "ia32x64") == 0)
+ length = generate_section_ia32x64(location);
+ // else if (strcmp(type, "ipf") == 0)
+ // length = generate_section_ipf(location);
+ else if (strcmp(type, "arm") == 0)
+ length = generate_section_arm(location);
+ else if (strcmp(type, "memory") == 0)
+ length = generate_section_memory(location);
+ else if (strcmp(type, "memory2") == 0)
+ length = generate_section_memory2(location);
+ else if (strcmp(type, "pcie") == 0)
+ length = generate_section_pcie(location);
+ else if (strcmp(type, "firmware") == 0)
+ length = generate_section_firmware(location);
+ else if (strcmp(type, "pcibus") == 0)
+ length = generate_section_pci_bus(location);
+ else if (strcmp(type, "pcidev") == 0)
+ length = generate_section_pci_dev(location);
+ else if (strcmp(type, "dmargeneric") == 0)
+ length = generate_section_dmar_generic(location);
+ else if (strcmp(type, "dmarvtd") == 0)
+ length = generate_section_dmar_vtd(location);
+ else if (strcmp(type, "dmariommu") == 0)
+ length = generate_section_dmar_iommu(location);
+ else if (strcmp(type, "ccixper") == 0)
+ length = generate_section_ccix_per(location);
+ else if (strcmp(type, "cxlprotocol") == 0)
+ length = generate_section_cxl_protocol(location);
+ else if (strcmp(type, "cxlcomponent") == 0)
+ length = generate_section_cxl_component(location);
+ else if (strcmp(type, "unknown") == 0)
+ length = generate_random_section(location, rand() % 256);
+ else {
+ //Undefined section, show error.
+ printf("Undefined section type '%s' given to generate. See 'cper-generate --help' for command information.\n",
+ type);
+ return 0;
+ }
- return length;
+ return length;
}
\ No newline at end of file
diff --git a/generator/gen-utils.c b/generator/gen-utils.c
index 1ab318f..bce904a 100644
--- a/generator/gen-utils.c
+++ b/generator/gen-utils.c
@@ -10,36 +10,38 @@
//Generates a random section of the given byte size, saving the result to the given location.
//Returns the length of the section as passed in.
-size_t generate_random_section(void** location, size_t size)
+size_t generate_random_section(void **location, size_t size)
{
- *location = generate_random_bytes(size);
- return size;
+ *location = generate_random_bytes(size);
+ return size;
}
//Generates a random byte allocation of the given size.
-UINT8* generate_random_bytes(size_t size)
+UINT8 *generate_random_bytes(size_t size)
{
- UINT8* bytes = malloc(size);
- for (size_t i = 0; i < size; i++)
- bytes[i] = rand();
- return bytes;
+ UINT8 *bytes = malloc(size);
+ for (size_t i = 0; i < size; i++)
+ bytes[i] = rand();
+ return bytes;
}
//Creates a valid common CPER error section, given the start of the error section.
//Clears reserved bits.
-void create_valid_error_section(UINT8* start)
+void create_valid_error_section(UINT8 *start)
{
- //Fix reserved bits.
- UINT64* error_section = (UINT64*)start;
- *error_section &= ~0xFF; //Reserved bits 0-7.
- *error_section &= 0x7FFFFF; //Reserved bits 23-63
+ //Fix reserved bits.
+ UINT64 *error_section = (UINT64 *)start;
+ *error_section &= ~0xFF; //Reserved bits 0-7.
+ *error_section &= 0x7FFFFF; //Reserved bits 23-63
- //Ensure error type has a valid value.
- *(start + 1) = CPER_ERROR_TYPES_KEYS[rand() % (sizeof(CPER_ERROR_TYPES_KEYS) / sizeof(int))];
+ //Ensure error type has a valid value.
+ *(start + 1) =
+ CPER_ERROR_TYPES_KEYS[rand() % (sizeof(CPER_ERROR_TYPES_KEYS) /
+ sizeof(int))];
}
//Initializes the random seed for rand() using the current time.
void init_random()
{
- srand((unsigned int)time(NULL));
+ srand((unsigned int)time(NULL));
}
\ No newline at end of file
diff --git a/ir-parse.c b/ir-parse.c
index 82904b5..437dd82 100644
--- a/ir-parse.c
+++ b/ir-parse.c
@@ -28,188 +28,252 @@
#include "sections/cper-section-cxl-component.h"
//Private pre-declarations.
-void ir_header_to_cper(json_object* header_ir, EFI_COMMON_ERROR_RECORD_HEADER* header);
-void ir_section_descriptor_to_cper(json_object* section_descriptor_ir, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
+void ir_header_to_cper(json_object *header_ir,
+ EFI_COMMON_ERROR_RECORD_HEADER *header);
+void ir_section_descriptor_to_cper(json_object *section_descriptor_ir,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor);
//Converts the given JSON IR CPER representation into CPER binary format, piped to the provided file stream.
//This function performs no validation of the IR against the CPER-JSON specification. To ensure a safe call,
-//use validate_schema() from json-schema.h before attempting to call this function.
-void ir_to_cper(json_object* ir, FILE* out)
+//use validate_schema() from json-schema.h before attempting to call this function.
+void ir_to_cper(json_object *ir, FILE *out)
{
- //Create the CPER header.
- EFI_COMMON_ERROR_RECORD_HEADER* header = (EFI_COMMON_ERROR_RECORD_HEADER*)calloc(1, sizeof(EFI_COMMON_ERROR_RECORD_HEADER));
- ir_header_to_cper(json_object_object_get(ir, "header"), header);
- fwrite(header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, out);
- fflush(out);
+ //Create the CPER header.
+ EFI_COMMON_ERROR_RECORD_HEADER *header =
+ (EFI_COMMON_ERROR_RECORD_HEADER *)calloc(
+ 1, sizeof(EFI_COMMON_ERROR_RECORD_HEADER));
+ ir_header_to_cper(json_object_object_get(ir, "header"), header);
+ fwrite(header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, out);
+ fflush(out);
- //Create the CPER section descriptors.
- json_object* section_descriptors = json_object_object_get(ir, "sectionDescriptors");
- int amt_descriptors = json_object_array_length(section_descriptors);
- EFI_ERROR_SECTION_DESCRIPTOR* descriptors[amt_descriptors];
- for (int i=0; i<amt_descriptors; i++)
- {
- descriptors[i] = (EFI_ERROR_SECTION_DESCRIPTOR*)calloc(1, sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
- ir_section_descriptor_to_cper(json_object_array_get_idx(section_descriptors, i), descriptors[i]);
- fwrite(descriptors[i], sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, out);
- fflush(out);
- }
-
- //Run through each section in turn.
- json_object* sections = json_object_object_get(ir, "sections");
- int amt_sections = json_object_array_length(sections);
- for (int i=0; i<amt_sections; i++)
- {
- //Get the section itself from the IR.
- json_object* section = json_object_array_get_idx(sections, i);
+ //Create the CPER section descriptors.
+ json_object *section_descriptors =
+ json_object_object_get(ir, "sectionDescriptors");
+ int amt_descriptors = json_object_array_length(section_descriptors);
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptors[amt_descriptors];
+ for (int i = 0; i < amt_descriptors; i++) {
+ descriptors[i] = (EFI_ERROR_SECTION_DESCRIPTOR *)calloc(
+ 1, sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
+ ir_section_descriptor_to_cper(
+ json_object_array_get_idx(section_descriptors, i),
+ descriptors[i]);
+ fwrite(descriptors[i], sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1,
+ out);
+ fflush(out);
+ }
- //Find the correct section type, and parse.
- if (guid_equal(&descriptors[i]->SectionType, &gEfiProcessorGenericErrorSectionGuid))
- ir_section_generic_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
- ir_section_ia32x64_to_cper(section, out);
- // else if (guid_equal(&descriptors[i]->SectionType, &gEfiIpfProcessorErrorSectionGuid))
- // ir_section_ipf_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiArmProcessorErrorSectionGuid))
- ir_section_arm_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPlatformMemoryErrorSectionGuid))
- ir_section_memory_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPlatformMemoryError2SectionGuid))
- ir_section_memory2_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPcieErrorSectionGuid))
- ir_section_pcie_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiFirmwareErrorSectionGuid))
- ir_section_firmware_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPciBusErrorSectionGuid))
- ir_section_pci_bus_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPciDevErrorSectionGuid))
- ir_section_pci_dev_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiDMArGenericErrorSectionGuid))
- ir_section_dmar_generic_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
- ir_section_dmar_vtd_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiIommuDMArErrorSectionGuid))
- ir_section_dmar_iommu_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiCcixPerLogErrorSectionGuid))
- ir_section_ccix_per_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiCxlProtocolErrorSectionGuid))
- ir_section_cxl_protocol_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid)
- || guid_equal(&descriptors[i]->SectionType, &gEfiCxlDramEventErrorSectionGuid)
- || guid_equal(&descriptors[i]->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid)
- || guid_equal(&descriptors[i]->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid)
- || guid_equal(&descriptors[i]->SectionType, &gEfiCxlMldPortErrorSectionGuid))
- {
- ir_section_cxl_component_to_cper(section, out);
- }
- else
- {
- //Unknown GUID, so read as a base64 unknown section.
- json_object* encoded = json_object_object_get(section, "data");
- UINT8* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- fwrite(decoded, descriptors[i]->SectionLength, 1, out);
- fflush(out);
- free(decoded);
- }
- }
+ //Run through each section in turn.
+ json_object *sections = json_object_object_get(ir, "sections");
+ int amt_sections = json_object_array_length(sections);
+ for (int i = 0; i < amt_sections; i++) {
+ //Get the section itself from the IR.
+ json_object *section = json_object_array_get_idx(sections, i);
- //Free all remaining resources.
- free(header);
- for (int i=0; i<amt_descriptors; i++)
- free(descriptors[i]);
+ //Find the correct section type, and parse.
+ if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiProcessorGenericErrorSectionGuid))
+ ir_section_generic_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiIa32X64ProcessorErrorSectionGuid))
+ ir_section_ia32x64_to_cper(section, out);
+ // else if (guid_equal(&descriptors[i]->SectionType, &gEfiIpfProcessorErrorSectionGuid))
+ // ir_section_ipf_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiArmProcessorErrorSectionGuid))
+ ir_section_arm_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPlatformMemoryErrorSectionGuid))
+ ir_section_memory_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPlatformMemoryError2SectionGuid))
+ ir_section_memory2_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPcieErrorSectionGuid))
+ ir_section_pcie_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiFirmwareErrorSectionGuid))
+ ir_section_firmware_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPciBusErrorSectionGuid))
+ ir_section_pci_bus_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPciDevErrorSectionGuid))
+ ir_section_pci_dev_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiDMArGenericErrorSectionGuid))
+ ir_section_dmar_generic_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiDirectedIoDMArErrorSectionGuid))
+ ir_section_dmar_vtd_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiIommuDMArErrorSectionGuid))
+ ir_section_dmar_iommu_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiCcixPerLogErrorSectionGuid))
+ ir_section_ccix_per_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlProtocolErrorSectionGuid))
+ ir_section_cxl_protocol_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlGeneralMediaErrorSectionGuid) ||
+ guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlDramEventErrorSectionGuid) ||
+ guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlPhysicalSwitchErrorSectionGuid) ||
+ guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlVirtualSwitchErrorSectionGuid) ||
+ guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlMldPortErrorSectionGuid)) {
+ ir_section_cxl_component_to_cper(section, out);
+ } else {
+ //Unknown GUID, so read as a base64 unknown section.
+ json_object *encoded =
+ json_object_object_get(section, "data");
+ UINT8 *decoded =
+ b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ fwrite(decoded, descriptors[i]->SectionLength, 1, out);
+ fflush(out);
+ free(decoded);
+ }
+ }
+
+ //Free all remaining resources.
+ free(header);
+ for (int i = 0; i < amt_descriptors; i++)
+ free(descriptors[i]);
}
//Converts a CPER-JSON IR header to a CPER header structure.
-void ir_header_to_cper(json_object* header_ir, EFI_COMMON_ERROR_RECORD_HEADER* header)
+void ir_header_to_cper(json_object *header_ir,
+ EFI_COMMON_ERROR_RECORD_HEADER *header)
{
- header->SignatureStart = 0x52455043; //CPER
+ header->SignatureStart = 0x52455043; //CPER
- //Revision.
- json_object* revision = json_object_object_get(header_ir, "revision");
- int minor = json_object_get_int(json_object_object_get(revision, "minor"));
- int major = json_object_get_int(json_object_object_get(revision, "major"));
- header->Revision = minor + (major << 8);
+ //Revision.
+ json_object *revision = json_object_object_get(header_ir, "revision");
+ int minor =
+ json_object_get_int(json_object_object_get(revision, "minor"));
+ int major =
+ json_object_get_int(json_object_object_get(revision, "major"));
+ header->Revision = minor + (major << 8);
- header->SignatureEnd = 0xFFFFFFFF;
+ header->SignatureEnd = 0xFFFFFFFF;
- //Section count.
- int section_count = json_object_get_int(json_object_object_get(header_ir, "sectionCount"));
- header->SectionCount = (UINT16)section_count;
+ //Section count.
+ int section_count = json_object_get_int(
+ json_object_object_get(header_ir, "sectionCount"));
+ header->SectionCount = (UINT16)section_count;
- //Error severity.
- json_object* severity = json_object_object_get(header_ir, "severity");
- header->ErrorSeverity = (UINT32)json_object_get_uint64(json_object_object_get(severity, "code"));
+ //Error severity.
+ json_object *severity = json_object_object_get(header_ir, "severity");
+ header->ErrorSeverity = (UINT32)json_object_get_uint64(
+ json_object_object_get(severity, "code"));
- //Validation bits.
- header->ValidationBits = ir_to_bitfield(json_object_object_get(header_ir, "validationBits"),
- 3, CPER_HEADER_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ header->ValidationBits = ir_to_bitfield(
+ json_object_object_get(header_ir, "validationBits"), 3,
+ CPER_HEADER_VALID_BITFIELD_NAMES);
- //Record length.
- header->RecordLength = (UINT32)json_object_get_uint64(json_object_object_get(header_ir, "recordLength"));
+ //Record length.
+ header->RecordLength = (UINT32)json_object_get_uint64(
+ json_object_object_get(header_ir, "recordLength"));
- //Timestamp, if present.
- json_object* timestamp = json_object_object_get(header_ir, "timestamp");
- if (timestamp != NULL)
- {
- string_to_timestamp(&header->TimeStamp, json_object_get_string(timestamp));
- header->TimeStamp.Flag = json_object_get_boolean(json_object_object_get(header_ir, "timestampIsPrecise"));
- }
+ //Timestamp, if present.
+ json_object *timestamp = json_object_object_get(header_ir, "timestamp");
+ if (timestamp != NULL) {
+ string_to_timestamp(&header->TimeStamp,
+ json_object_get_string(timestamp));
+ header->TimeStamp.Flag = json_object_get_boolean(
+ json_object_object_get(header_ir,
+ "timestampIsPrecise"));
+ }
- //Various GUIDs.
- json_object* platform_id = json_object_object_get(header_ir, "platformID");
- json_object* partition_id = json_object_object_get(header_ir, "partitionID");
- if (platform_id != NULL)
- string_to_guid(&header->PlatformID, json_object_get_string(platform_id));
- if (partition_id != NULL)
- string_to_guid(&header->PartitionID, json_object_get_string(partition_id));
- string_to_guid(&header->CreatorID, json_object_get_string(json_object_object_get(header_ir, "creatorID")));
+ //Various GUIDs.
+ json_object *platform_id =
+ json_object_object_get(header_ir, "platformID");
+ json_object *partition_id =
+ json_object_object_get(header_ir, "partitionID");
+ if (platform_id != NULL)
+ string_to_guid(&header->PlatformID,
+ json_object_get_string(platform_id));
+ if (partition_id != NULL)
+ string_to_guid(&header->PartitionID,
+ json_object_get_string(partition_id));
+ string_to_guid(&header->CreatorID,
+ json_object_get_string(
+ json_object_object_get(header_ir, "creatorID")));
- //Notification type.
- json_object* notification_type = json_object_object_get(header_ir, "notificationType");
- string_to_guid(&header->NotificationType, json_object_get_string(json_object_object_get(notification_type, "guid")));
+ //Notification type.
+ json_object *notification_type =
+ json_object_object_get(header_ir, "notificationType");
+ string_to_guid(&header->NotificationType,
+ json_object_get_string(json_object_object_get(
+ notification_type, "guid")));
- //Record ID, persistence info.
- header->RecordID = json_object_get_uint64(json_object_object_get(header_ir, "recordID"));
- header->PersistenceInfo = json_object_get_uint64(json_object_object_get(header_ir, "persistenceInfo"));
+ //Record ID, persistence info.
+ header->RecordID = json_object_get_uint64(
+ json_object_object_get(header_ir, "recordID"));
+ header->PersistenceInfo = json_object_get_uint64(
+ json_object_object_get(header_ir, "persistenceInfo"));
- //Flags.
- json_object* flags = json_object_object_get(header_ir, "flags");
- header->Flags = (UINT32)json_object_get_uint64(json_object_object_get(flags, "value"));
+ //Flags.
+ json_object *flags = json_object_object_get(header_ir, "flags");
+ header->Flags = (UINT32)json_object_get_uint64(
+ json_object_object_get(flags, "value"));
}
//Converts a single CPER-JSON IR section descriptor into a CPER structure.
-void ir_section_descriptor_to_cper(json_object* section_descriptor_ir, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+void ir_section_descriptor_to_cper(json_object *section_descriptor_ir,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- //Section offset, length.
- descriptor->SectionOffset = (UINT32)json_object_get_uint64(json_object_object_get(section_descriptor_ir, "sectionOffset"));
- descriptor->SectionLength = (UINT32)json_object_get_uint64(json_object_object_get(section_descriptor_ir, "sectionLength"));
+ //Section offset, length.
+ descriptor->SectionOffset = (UINT32)json_object_get_uint64(
+ json_object_object_get(section_descriptor_ir, "sectionOffset"));
+ descriptor->SectionLength = (UINT32)json_object_get_uint64(
+ json_object_object_get(section_descriptor_ir, "sectionLength"));
- //Revision.
- json_object* revision = json_object_object_get(section_descriptor_ir, "revision");
- int minor = json_object_get_int(json_object_object_get(revision, "minor"));
- int major = json_object_get_int(json_object_object_get(revision, "major"));
- descriptor->Revision = minor + (major << 8);
+ //Revision.
+ json_object *revision =
+ json_object_object_get(section_descriptor_ir, "revision");
+ int minor =
+ json_object_get_int(json_object_object_get(revision, "minor"));
+ int major =
+ json_object_get_int(json_object_object_get(revision, "major"));
+ descriptor->Revision = minor + (major << 8);
- //Validation bits, flags.
- descriptor->SecValidMask = ir_to_bitfield(json_object_object_get(section_descriptor_ir, "validationBits"),
- 2, CPER_SECTION_DESCRIPTOR_VALID_BITFIELD_NAMES);
- descriptor->SectionFlags = ir_to_bitfield(json_object_object_get(section_descriptor_ir, "flags"),
- 8, CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES);
+ //Validation bits, flags.
+ descriptor->SecValidMask = ir_to_bitfield(
+ json_object_object_get(section_descriptor_ir, "validationBits"),
+ 2, CPER_SECTION_DESCRIPTOR_VALID_BITFIELD_NAMES);
+ descriptor->SectionFlags = ir_to_bitfield(
+ json_object_object_get(section_descriptor_ir, "flags"), 8,
+ CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES);
- //Section type.
- json_object* section_type = json_object_object_get(section_descriptor_ir, "sectionType");
- string_to_guid(&descriptor->SectionType, json_object_get_string(json_object_object_get(section_type, "data")));
+ //Section type.
+ json_object *section_type =
+ json_object_object_get(section_descriptor_ir, "sectionType");
+ string_to_guid(&descriptor->SectionType,
+ json_object_get_string(
+ json_object_object_get(section_type, "data")));
- //FRU ID, if present.
- json_object* fru_id = json_object_object_get(section_descriptor_ir, "fruID");
- if (fru_id != NULL)
- string_to_guid(&descriptor->FruId, json_object_get_string(fru_id));
+ //FRU ID, if present.
+ json_object *fru_id =
+ json_object_object_get(section_descriptor_ir, "fruID");
+ if (fru_id != NULL)
+ string_to_guid(&descriptor->FruId,
+ json_object_get_string(fru_id));
- //Severity code.
- json_object* severity = json_object_object_get(section_descriptor_ir, "severity");
- descriptor->Severity = (UINT32)json_object_get_uint64(json_object_object_get(severity, "code"));
+ //Severity code.
+ json_object *severity =
+ json_object_object_get(section_descriptor_ir, "severity");
+ descriptor->Severity = (UINT32)json_object_get_uint64(
+ json_object_object_get(severity, "code"));
- //FRU text, if present.
- json_object* fru_text = json_object_object_get(section_descriptor_ir, "fruText");
- if (fru_text != NULL)
- strncpy(descriptor->FruString, json_object_get_string(fru_text), 20);
+ //FRU text, if present.
+ json_object *fru_text =
+ json_object_object_get(section_descriptor_ir, "fruText");
+ if (fru_text != NULL)
+ strncpy(descriptor->FruString, json_object_get_string(fru_text),
+ 20);
}
\ No newline at end of file
diff --git a/json-schema.c b/json-schema.c
index 4762dff..88cc03c 100644
--- a/json-schema.c
+++ b/json-schema.c
@@ -19,350 +19,420 @@
int json_validator_debug = 0;
//Private pre-definitions.
-int validate_field(const char* name, json_object* schema, json_object* object, char* error_message);
-int validate_integer(const char* field_name, json_object* schema, json_object* object, char* error_message);
-int validate_string(const char* field_name, json_object* schema, json_object* object, char* error_message);
-int validate_object(const char* field_name, json_object* schema, json_object* object, char* error_message);
-int validate_array(const char* field_name, json_object* schema, json_object* object, char* error_message);
-void log_validator_error(char* error_message, const char* format, ...);
-void log_validator_debug(const char* format, ...);
-void log_validator_msg(const char* format, va_list args);
+int validate_field(const char *name, json_object *schema, json_object *object,
+ char *error_message);
+int validate_integer(const char *field_name, json_object *schema,
+ json_object *object, char *error_message);
+int validate_string(const char *field_name, json_object *schema,
+ json_object *object, char *error_message);
+int validate_object(const char *field_name, json_object *schema,
+ json_object *object, char *error_message);
+int validate_array(const char *field_name, json_object *schema,
+ json_object *object, char *error_message);
+void log_validator_error(char *error_message, const char *format, ...);
+void log_validator_debug(const char *format, ...);
+void log_validator_msg(const char *format, va_list args);
//Validates a single JSON object against a provided schema file, returning 1 on success and 0 on failure to validate.
//Error message space must be allocated prior to call.
-int validate_schema_from_file(const char* schema_file, json_object* object, char* error_message)
+int validate_schema_from_file(const char *schema_file, json_object *object,
+ char *error_message)
{
- //Load schema IR from file.
- json_object* schema_ir = json_object_from_file(schema_file);
- if (schema_ir == NULL)
- {
- log_validator_error(error_message, "Failed to load schema from file '%s'.", schema_file);
- return 0;
- }
+ //Load schema IR from file.
+ json_object *schema_ir = json_object_from_file(schema_file);
+ if (schema_ir == NULL) {
+ log_validator_error(error_message,
+ "Failed to load schema from file '%s'.",
+ schema_file);
+ return 0;
+ }
- //Get the directory of the file.
- char* schema_file_copy = malloc(strlen(schema_file) + 1);
- strcpy(schema_file_copy, schema_file);
- char* schema_dir = dirname(schema_file_copy);
+ //Get the directory of the file.
+ char *schema_file_copy = malloc(strlen(schema_file) + 1);
+ strcpy(schema_file_copy, schema_file);
+ char *schema_dir = dirname(schema_file_copy);
- int result = validate_schema(schema_ir, schema_dir, object, error_message);
+ int result =
+ validate_schema(schema_ir, schema_dir, object, error_message);
- //Free memory from directory call.
- free(schema_file_copy);
+ //Free memory from directory call.
+ free(schema_file_copy);
- return result;
+ return result;
}
//Validates a single JSON object against a provided schema, returning 1 on success and 0 on failure to validate.
//Error message space must be allocated prior to call.
//If the schema does not include any other sub-schemas using "$ref", then leaving schema_directory as NULL is valid.
-int validate_schema(json_object* schema, char* schema_directory, json_object* object, char* error_message)
+int validate_schema(json_object *schema, char *schema_directory,
+ json_object *object, char *error_message)
{
- //Check that the schema version is the same as this validator.
- json_object* schema_ver = json_object_object_get(schema, "$schema");
- if (schema_ver == NULL || strcmp(json_object_get_string(schema_ver), JSON_SCHEMA_VERSION))
- {
- log_validator_error(error_message, "Provided schema is not of the same version that is referenced by this validator, or is not a schema.");
- return 0;
- }
+ //Check that the schema version is the same as this validator.
+ json_object *schema_ver = json_object_object_get(schema, "$schema");
+ if (schema_ver == NULL ||
+ strcmp(json_object_get_string(schema_ver), JSON_SCHEMA_VERSION)) {
+ log_validator_error(
+ error_message,
+ "Provided schema is not of the same version that is referenced by this validator, or is not a schema.");
+ return 0;
+ }
- //Change current directory into the schema directory.
- char* original_cwd = malloc(PATH_MAX);
- if (getcwd(original_cwd, PATH_MAX) == NULL)
- {
- log_validator_error(error_message, "Failed fetching the current directory.");
- return 0;
- }
- if (chdir(schema_directory))
- {
- log_validator_error(error_message, "Failed to chdir into schema directory.");
- return 0;
- }
+ //Change current directory into the schema directory.
+ char *original_cwd = malloc(PATH_MAX);
+ if (getcwd(original_cwd, PATH_MAX) == NULL) {
+ log_validator_error(error_message,
+ "Failed fetching the current directory.");
+ return 0;
+ }
+ if (chdir(schema_directory)) {
+ log_validator_error(error_message,
+ "Failed to chdir into schema directory.");
+ return 0;
+ }
- //Parse the top level structure appropriately.
- int result = validate_field("parent", schema, object, error_message);
+ //Parse the top level structure appropriately.
+ int result = validate_field("parent", schema, object, error_message);
- //Change back to original CWD.
- chdir(original_cwd);
- free(original_cwd);
+ //Change back to original CWD.
+ chdir(original_cwd);
+ free(original_cwd);
- if (result)
- log_validator_debug("Successfully validated the provided object against schema.");
- return result;
+ if (result)
+ log_validator_debug(
+ "Successfully validated the provided object against schema.");
+ return result;
}
//Validates a single JSON field given a schema/object.
//Returns -1 on fatal/error failure, 0 on validation failure, and 1 on validation.
-int validate_field(const char* field_name, json_object* schema, json_object* object, char* error_message)
+int validate_field(const char *field_name, json_object *schema,
+ json_object *object, char *error_message)
{
- log_validator_debug("Validating field '%s'...", field_name);
+ log_validator_debug("Validating field '%s'...", field_name);
- //If there is a "$ref" field, attempt to load the referenced schema.
- json_object* ref_schema = json_object_object_get(schema, "$ref");
- if (ref_schema != NULL && json_object_get_type(ref_schema) == json_type_string)
- {
- log_validator_debug("$ref schema detected for field '%s'.", field_name);
+ //If there is a "$ref" field, attempt to load the referenced schema.
+ json_object *ref_schema = json_object_object_get(schema, "$ref");
+ if (ref_schema != NULL &&
+ json_object_get_type(ref_schema) == json_type_string) {
+ log_validator_debug("$ref schema detected for field '%s'.",
+ field_name);
- //Attempt to load. If loading fails, report error.
- const char* ref_path = json_object_get_string(ref_schema);
- schema = json_object_from_file(ref_path);
- if (schema == NULL)
- {
- log_validator_error(error_message, "Failed to open referenced schema file '%s'.", ref_path);
- return -1;
- }
+ //Attempt to load. If loading fails, report error.
+ const char *ref_path = json_object_get_string(ref_schema);
+ schema = json_object_from_file(ref_path);
+ if (schema == NULL) {
+ log_validator_error(
+ error_message,
+ "Failed to open referenced schema file '%s'.",
+ ref_path);
+ return -1;
+ }
- log_validator_debug("loaded schema path '%s' for field '%s'.", ref_path, field_name);
- }
+ log_validator_debug("loaded schema path '%s' for field '%s'.",
+ ref_path, field_name);
+ }
- //Get the schema field type.
- json_object* desired_field_type = json_object_object_get(schema, "type");
- if (desired_field_type == NULL || !json_object_is_type(desired_field_type, json_type_string))
- {
- log_validator_error(error_message, "Desired field type not provided within schema/is not a string for field '%s' (schema violation).", field_name);
- return -1;
- }
+ //Get the schema field type.
+ json_object *desired_field_type =
+ json_object_object_get(schema, "type");
+ if (desired_field_type == NULL ||
+ !json_object_is_type(desired_field_type, json_type_string)) {
+ log_validator_error(
+ error_message,
+ "Desired field type not provided within schema/is not a string for field '%s' (schema violation).",
+ field_name);
+ return -1;
+ }
- //Check the field types are actually equal.
- const char* desired_field_type_str = json_object_get_string(desired_field_type);
- if (!(
- (!strcmp(desired_field_type_str, "object") && json_object_is_type(object, json_type_object))
- || (!strcmp(desired_field_type_str, "array") && json_object_is_type(object, json_type_array))
- || (!strcmp(desired_field_type_str, "integer") && json_object_is_type(object, json_type_int))
- || (!strcmp(desired_field_type_str, "string") && json_object_is_type(object, json_type_string))
- || (!strcmp(desired_field_type_str, "boolean") && json_object_is_type(object, json_type_boolean))
- || (!strcmp(desired_field_type_str, "double") && json_object_is_type(object, json_type_double))
- ))
- {
- log_validator_error(error_message, "Field type match failed for field '%s'.", field_name);
- return 0;
- }
+ //Check the field types are actually equal.
+ const char *desired_field_type_str =
+ json_object_get_string(desired_field_type);
+ if (!((!strcmp(desired_field_type_str, "object") &&
+ json_object_is_type(object, json_type_object)) ||
+ (!strcmp(desired_field_type_str, "array") &&
+ json_object_is_type(object, json_type_array)) ||
+ (!strcmp(desired_field_type_str, "integer") &&
+ json_object_is_type(object, json_type_int)) ||
+ (!strcmp(desired_field_type_str, "string") &&
+ json_object_is_type(object, json_type_string)) ||
+ (!strcmp(desired_field_type_str, "boolean") &&
+ json_object_is_type(object, json_type_boolean)) ||
+ (!strcmp(desired_field_type_str, "double") &&
+ json_object_is_type(object, json_type_double)))) {
+ log_validator_error(error_message,
+ "Field type match failed for field '%s'.",
+ field_name);
+ return 0;
+ }
- //If the schema contains a "oneOf" array, we need to validate the field against each of the
- //possible options in turn.
- json_object* one_of = json_object_object_get(schema, "oneOf");
- if (one_of != NULL && json_object_get_type(one_of) == json_type_array)
- {
- log_validator_debug("oneOf options detected for field '%s'.", field_name);
+ //If the schema contains a "oneOf" array, we need to validate the field against each of the
+ //possible options in turn.
+ json_object *one_of = json_object_object_get(schema, "oneOf");
+ if (one_of != NULL && json_object_get_type(one_of) == json_type_array) {
+ log_validator_debug("oneOf options detected for field '%s'.",
+ field_name);
- int len = json_object_array_length(one_of);
- int validated = 0;
- for (int i=0; i<len; i++)
- {
- //If the "oneOf" member isn't an object, warn on schema violation.
- json_object* one_of_option = json_object_array_get_idx(one_of, i);
- if (one_of_option == NULL || json_object_get_type(one_of_option) != json_type_object)
- {
- log_validator_debug("Schema Warning: 'oneOf' member for field '%s' is not an object, schema violation.", field_name);
- continue;
- }
+ int len = json_object_array_length(one_of);
+ int validated = 0;
+ for (int i = 0; i < len; i++) {
+ //If the "oneOf" member isn't an object, warn on schema violation.
+ json_object *one_of_option =
+ json_object_array_get_idx(one_of, i);
+ if (one_of_option == NULL ||
+ json_object_get_type(one_of_option) !=
+ json_type_object) {
+ log_validator_debug(
+ "Schema Warning: 'oneOf' member for field '%s' is not an object, schema violation.",
+ field_name);
+ continue;
+ }
- //Validate field with schema.
- validated = validate_field(field_name, one_of_option, object, error_message);
- if (validated == -1)
- return -1;
- if (validated)
- break;
- }
+ //Validate field with schema.
+ validated = validate_field(field_name, one_of_option,
+ object, error_message);
+ if (validated == -1)
+ return -1;
+ if (validated)
+ break;
+ }
- //Return if failed all checks.
- if (!validated)
- {
- log_validator_error(error_message, "No schema object structures matched provided object for field '%s'.", field_name);
- return 0;
- }
- }
+ //Return if failed all checks.
+ if (!validated) {
+ log_validator_error(
+ error_message,
+ "No schema object structures matched provided object for field '%s'.",
+ field_name);
+ return 0;
+ }
+ }
- //Switch and validate each type in turn.
- switch (json_object_get_type(object))
- {
- case json_type_int:
- return validate_integer(field_name, schema, object, error_message);
- case json_type_string:
- return validate_string(field_name, schema, object, error_message);
- case json_type_object:
- return validate_object(field_name, schema, object, error_message);
- case json_type_array:
- return validate_array(field_name, schema, object, error_message);
+ //Switch and validate each type in turn.
+ switch (json_object_get_type(object)) {
+ case json_type_int:
+ return validate_integer(field_name, schema, object,
+ error_message);
+ case json_type_string:
+ return validate_string(field_name, schema, object,
+ error_message);
+ case json_type_object:
+ return validate_object(field_name, schema, object,
+ error_message);
+ case json_type_array:
+ return validate_array(field_name, schema, object,
+ error_message);
- //We don't perform extra validation on this type.
- default:
- log_validator_debug("validation passed for '%s' (no extra validation).", field_name);
- return 1;
- }
+ //We don't perform extra validation on this type.
+ default:
+ log_validator_debug(
+ "validation passed for '%s' (no extra validation).",
+ field_name);
+ return 1;
+ }
}
//Validates a single integer value according to the given specification.
-int validate_integer(const char* field_name, json_object* schema, json_object* object, char* error_message)
+int validate_integer(const char *field_name, json_object *schema,
+ json_object *object, char *error_message)
{
- //Is there a minimum/maximum specified? If so, check those.
- //Validate minimum.
- json_object* min_value = json_object_object_get(schema, "minimum");
- if (min_value != NULL && json_object_is_type(min_value, json_type_int))
- {
- int min_value_int = json_object_get_int(min_value);
- if (json_object_get_uint64(object) < min_value_int)
- {
- log_validator_error(error_message, "Failed to validate integer field '%s'. Value was below minimum of %d.", field_name, min_value_int);
- return 0;
- }
- }
+ //Is there a minimum/maximum specified? If so, check those.
+ //Validate minimum.
+ json_object *min_value = json_object_object_get(schema, "minimum");
+ if (min_value != NULL &&
+ json_object_is_type(min_value, json_type_int)) {
+ int min_value_int = json_object_get_int(min_value);
+ if (json_object_get_uint64(object) < min_value_int) {
+ log_validator_error(
+ error_message,
+ "Failed to validate integer field '%s'. Value was below minimum of %d.",
+ field_name, min_value_int);
+ return 0;
+ }
+ }
- //Validate maximum.
- json_object* max_value = json_object_object_get(schema, "maximum");
- if (max_value != NULL && json_object_is_type(max_value, json_type_int))
- {
- int max_value_int = json_object_get_int(max_value);
- if (json_object_get_uint64(object) > max_value_int)
- {
- log_validator_error(error_message, "Failed to validate integer field '%s'. Value was above maximum of %d.", field_name, max_value_int);
- return 0;
- }
- }
+ //Validate maximum.
+ json_object *max_value = json_object_object_get(schema, "maximum");
+ if (max_value != NULL &&
+ json_object_is_type(max_value, json_type_int)) {
+ int max_value_int = json_object_get_int(max_value);
+ if (json_object_get_uint64(object) > max_value_int) {
+ log_validator_error(
+ error_message,
+ "Failed to validate integer field '%s'. Value was above maximum of %d.",
+ field_name, max_value_int);
+ return 0;
+ }
+ }
- return 1;
+ return 1;
}
//Validates a single string value according to the given specification.
-int validate_string(const char* field_name, json_object* schema, json_object* object, char* error_message)
+int validate_string(const char *field_name, json_object *schema,
+ json_object *object, char *error_message)
{
- //todo: if there is a "pattern" field, verify the string with RegEx.
- return 1;
+ //todo: if there is a "pattern" field, verify the string with RegEx.
+ return 1;
}
//Validates a single object value according to the given specification.
-int validate_object(const char* field_name, json_object* schema, json_object* object, char* error_message)
+int validate_object(const char *field_name, json_object *schema,
+ json_object *object, char *error_message)
{
- //Are there a set of "required" fields? If so, check they all exist.
- json_object* required_fields = json_object_object_get(schema, "required");
- if (required_fields != NULL && json_object_get_type(required_fields) == json_type_array)
- {
- log_validator_debug("Required fields found for '%s', matching...", field_name);
+ //Are there a set of "required" fields? If so, check they all exist.
+ json_object *required_fields =
+ json_object_object_get(schema, "required");
+ if (required_fields != NULL &&
+ json_object_get_type(required_fields) == json_type_array) {
+ log_validator_debug(
+ "Required fields found for '%s', matching...",
+ field_name);
- int len = json_object_array_length(required_fields);
- for (int i=0; i<len; i++)
- {
- //Get the required field from schema.
- json_object* required_field = json_object_array_get_idx(required_fields, i);
- if (json_object_get_type(required_field) != json_type_string)
- {
- log_validator_error(error_message, "Required field for object '%s' is not a string (schema violation).", field_name);
- return 0;
- }
+ int len = json_object_array_length(required_fields);
+ for (int i = 0; i < len; i++) {
+ //Get the required field from schema.
+ json_object *required_field =
+ json_object_array_get_idx(required_fields, i);
+ if (json_object_get_type(required_field) !=
+ json_type_string) {
+ log_validator_error(
+ error_message,
+ "Required field for object '%s' is not a string (schema violation).",
+ field_name);
+ return 0;
+ }
- //Does it exist in the object?
- const char* required_field_str = json_object_get_string(required_field);
- if (json_object_object_get(object, required_field_str) == NULL)
- {
- log_validator_error(error_message, "Required field '%s' was not present in object '%s'.", required_field_str, field_name);
- return 0;
- }
- }
- }
+ //Does it exist in the object?
+ const char *required_field_str =
+ json_object_get_string(required_field);
+ if (json_object_object_get(
+ object, required_field_str) == NULL) {
+ log_validator_error(
+ error_message,
+ "Required field '%s' was not present in object '%s'.",
+ required_field_str, field_name);
+ return 0;
+ }
+ }
+ }
- //Get additional properties value in advance.
- json_object* additional_properties = json_object_object_get(schema, "additionalProperties");
- int additional_properties_allowed = 0;
- if (additional_properties != NULL && json_object_get_type(additional_properties) == json_type_boolean)
- additional_properties_allowed = json_object_get_boolean(additional_properties);
+ //Get additional properties value in advance.
+ json_object *additional_properties =
+ json_object_object_get(schema, "additionalProperties");
+ int additional_properties_allowed = 0;
+ if (additional_properties != NULL &&
+ json_object_get_type(additional_properties) == json_type_boolean)
+ additional_properties_allowed =
+ json_object_get_boolean(additional_properties);
- //Run through the "properties" object and validate each of those in turn.
- json_object* properties = json_object_object_get(schema, "properties");
- if (properties != NULL && json_object_get_type(properties) == json_type_object)
- {
- json_object_object_foreach(properties, key, value) {
+ //Run through the "properties" object and validate each of those in turn.
+ json_object *properties = json_object_object_get(schema, "properties");
+ if (properties != NULL &&
+ json_object_get_type(properties) == json_type_object) {
+ json_object_object_foreach(properties, key, value)
+ {
+ //If the given property name does not exist on the target object, ignore and continue next.
+ json_object *object_prop =
+ json_object_object_get(object, key);
+ if (object_prop == NULL)
+ continue;
- //If the given property name does not exist on the target object, ignore and continue next.
- json_object* object_prop = json_object_object_get(object, key);
- if (object_prop == NULL)
- continue;
+ //Validate against the schema.
+ if (!validate_field(key, value, object_prop,
+ error_message))
+ return 0;
+ }
- //Validate against the schema.
- if (!validate_field(key, value, object_prop, error_message))
- return 0;
- }
+ //If additional properties are banned, validate that no additional properties exist.
+ if (!additional_properties_allowed) {
+ json_object_object_foreach(object, key, value)
+ {
+ //If the given property name does not exist on the schema object, fail validation.
+ json_object *schema_prop =
+ json_object_object_get(properties, key);
+ if (schema_prop == NULL) {
+ log_validator_error(
+ error_message,
+ "Invalid additional property '%s' detected on field '%s'.",
+ key, field_name);
+ return 0;
+ }
+ }
+ }
+ }
- //If additional properties are banned, validate that no additional properties exist.
- if (!additional_properties_allowed)
- {
- json_object_object_foreach(object, key, value) {
-
- //If the given property name does not exist on the schema object, fail validation.
- json_object* schema_prop = json_object_object_get(properties, key);
- if (schema_prop == NULL)
- {
- log_validator_error(error_message, "Invalid additional property '%s' detected on field '%s'.", key, field_name);
- return 0;
- }
- }
- }
- }
-
- return 1;
+ return 1;
}
//Validates a single array value according to the given specification.
-int validate_array(const char* field_name, json_object* schema, json_object* object, char* error_message)
+int validate_array(const char *field_name, json_object *schema,
+ json_object *object, char *error_message)
{
- //Iterate all items in the array, and validate according to the "items" schema.
- json_object* items_schema = json_object_object_get(schema, "items");
- if (items_schema != NULL && json_object_get_type(items_schema) == json_type_object)
- {
- int array_len = json_object_array_length(object);
- for (int i=0; i<array_len; i++)
- {
- if (!validate_field(field_name, items_schema, json_object_array_get_idx(object, i), error_message))
- return 0;
- }
- }
+ //Iterate all items in the array, and validate according to the "items" schema.
+ json_object *items_schema = json_object_object_get(schema, "items");
+ if (items_schema != NULL &&
+ json_object_get_type(items_schema) == json_type_object) {
+ int array_len = json_object_array_length(object);
+ for (int i = 0; i < array_len; i++) {
+ if (!validate_field(field_name, items_schema,
+ json_object_array_get_idx(object,
+ i),
+ error_message))
+ return 0;
+ }
+ }
- return 1;
+ return 1;
}
//Enables/disables debugging globally for the JSON validator.
-void validate_schema_debug_enable() { json_validator_debug = 1; }
-void validate_schema_debug_disable() { json_validator_debug = 0; }
+void validate_schema_debug_enable()
+{
+ json_validator_debug = 1;
+}
+void validate_schema_debug_disable()
+{
+ json_validator_debug = 0;
+}
//Logs an error message to the given error message location and (optionally) provides debug output.
-void log_validator_error(char* error_message, const char* format, ...)
+void log_validator_error(char *error_message, const char *format, ...)
{
- va_list args;
+ va_list args;
- //Log error to error out.
- va_start(args, format);
- vsnprintf(error_message, JSON_ERROR_MSG_MAX_LEN, format, args);
- va_end(args);
-
- //Debug message if necessary.
- va_start(args, format);
- log_validator_msg(format, args);
- va_end(args);
+ //Log error to error out.
+ va_start(args, format);
+ vsnprintf(error_message, JSON_ERROR_MSG_MAX_LEN, format, args);
+ va_end(args);
+
+ //Debug message if necessary.
+ va_start(args, format);
+ log_validator_msg(format, args);
+ va_end(args);
}
//Logs a debug message to stdout, if validator debug is enabled.
-void log_validator_debug(const char* format, ...)
+void log_validator_debug(const char *format, ...)
{
- va_list args;
- va_start(args, format);
- log_validator_msg(format, args);
- va_end(args);
+ va_list args;
+ va_start(args, format);
+ log_validator_msg(format, args);
+ va_end(args);
}
//Logs a single validator debug/error message.
-void log_validator_msg(const char* format, va_list args)
+void log_validator_msg(const char *format, va_list args)
{
- //Print debug output if debug is on.
- if (json_validator_debug)
- {
- //Make new format string for error.
- const char* header = "json_validator: ";
- char* new_format = malloc(strlen(header) + strlen(format) + 2);
- strcpy(new_format, header);
- strcat(new_format, format);
- strcat(new_format, "\n");
+ //Print debug output if debug is on.
+ if (json_validator_debug) {
+ //Make new format string for error.
+ const char *header = "json_validator: ";
+ char *new_format = malloc(strlen(header) + strlen(format) + 2);
+ strcpy(new_format, header);
+ strcat(new_format, format);
+ strcat(new_format, "\n");
- //Print & free format.
- vfprintf(stdout, new_format, args);
- free(new_format);
- }
+ //Print & free format.
+ vfprintf(stdout, new_format, args);
+ free(new_format);
+ }
}
\ No newline at end of file
diff --git a/sections/cper-section-arm.c b/sections/cper-section-arm.c
index 73e63ed..cdafd34 100644
--- a/sections/cper-section-arm.c
+++ b/sections/cper-section-arm.c
@@ -13,686 +13,887 @@
#include "cper-section-arm.h"
//Private pre-definitions.
-json_object* cper_arm_error_info_to_ir(EFI_ARM_ERROR_INFORMATION_ENTRY* error_info);
-json_object* cper_arm_processor_context_to_ir(EFI_ARM_CONTEXT_INFORMATION_HEADER* header, void** cur_pos);
-json_object* cper_arm_cache_tlb_error_to_ir(EFI_ARM_CACHE_ERROR_STRUCTURE* cache_tlb_error, EFI_ARM_ERROR_INFORMATION_ENTRY* error_info);
-json_object* cper_arm_bus_error_to_ir(EFI_ARM_BUS_ERROR_STRUCTURE* bus_error);
-json_object* cper_arm_misc_register_array_to_ir(EFI_ARM_MISC_CONTEXT_REGISTER* misc_register);
-void ir_arm_error_info_to_cper(json_object* error_info, FILE* out);
-void ir_arm_context_info_to_cper(json_object* context_info, FILE* out);
-void ir_arm_error_cache_tlb_info_to_cper(json_object* error_information, EFI_ARM_CACHE_ERROR_STRUCTURE* error_info_cper);
-void ir_arm_error_bus_info_to_cper(json_object* error_information, EFI_ARM_BUS_ERROR_STRUCTURE* error_info_cper);
-void ir_arm_aarch32_gpr_to_cper(json_object* registers, FILE* out);
-void ir_arm_aarch32_el1_to_cper(json_object* registers, FILE* out);
-void ir_arm_aarch32_el2_to_cper(json_object* registers, FILE* out);
-void ir_arm_aarch32_secure_to_cper(json_object* registers, FILE* out);
-void ir_arm_aarch64_gpr_to_cper(json_object* registers, FILE* out);
-void ir_arm_aarch64_el1_to_cper(json_object* registers, FILE* out);
-void ir_arm_aarch64_el2_to_cper(json_object* registers, FILE* out);
-void ir_arm_aarch64_el3_to_cper(json_object* registers, FILE* out);
-void ir_arm_misc_registers_to_cper(json_object* registers, FILE* out);
-void ir_arm_unknown_register_to_cper(json_object* registers, EFI_ARM_CONTEXT_INFORMATION_HEADER* header, FILE* out);
+json_object *
+cper_arm_error_info_to_ir(EFI_ARM_ERROR_INFORMATION_ENTRY *error_info);
+json_object *
+cper_arm_processor_context_to_ir(EFI_ARM_CONTEXT_INFORMATION_HEADER *header,
+ void **cur_pos);
+json_object *
+cper_arm_cache_tlb_error_to_ir(EFI_ARM_CACHE_ERROR_STRUCTURE *cache_tlb_error,
+ EFI_ARM_ERROR_INFORMATION_ENTRY *error_info);
+json_object *cper_arm_bus_error_to_ir(EFI_ARM_BUS_ERROR_STRUCTURE *bus_error);
+json_object *cper_arm_misc_register_array_to_ir(
+ EFI_ARM_MISC_CONTEXT_REGISTER *misc_register);
+void ir_arm_error_info_to_cper(json_object *error_info, FILE *out);
+void ir_arm_context_info_to_cper(json_object *context_info, FILE *out);
+void ir_arm_error_cache_tlb_info_to_cper(
+ json_object *error_information,
+ EFI_ARM_CACHE_ERROR_STRUCTURE *error_info_cper);
+void ir_arm_error_bus_info_to_cper(json_object *error_information,
+ EFI_ARM_BUS_ERROR_STRUCTURE *error_info_cper);
+void ir_arm_aarch32_gpr_to_cper(json_object *registers, FILE *out);
+void ir_arm_aarch32_el1_to_cper(json_object *registers, FILE *out);
+void ir_arm_aarch32_el2_to_cper(json_object *registers, FILE *out);
+void ir_arm_aarch32_secure_to_cper(json_object *registers, FILE *out);
+void ir_arm_aarch64_gpr_to_cper(json_object *registers, FILE *out);
+void ir_arm_aarch64_el1_to_cper(json_object *registers, FILE *out);
+void ir_arm_aarch64_el2_to_cper(json_object *registers, FILE *out);
+void ir_arm_aarch64_el3_to_cper(json_object *registers, FILE *out);
+void ir_arm_misc_registers_to_cper(json_object *registers, FILE *out);
+void ir_arm_unknown_register_to_cper(json_object *registers,
+ EFI_ARM_CONTEXT_INFORMATION_HEADER *header,
+ FILE *out);
//Converts the given processor-generic CPER section into JSON IR.
-json_object* cper_section_arm_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *cper_section_arm_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_ARM_ERROR_RECORD* record = (EFI_ARM_ERROR_RECORD*)section;
- json_object* section_ir = json_object_new_object();
-
- //Validation bits.
- json_object* validation = bitfield_to_ir(record->ValidFields, 4, ARM_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ EFI_ARM_ERROR_RECORD *record = (EFI_ARM_ERROR_RECORD *)section;
+ json_object *section_ir = json_object_new_object();
- //Number of error info and context info structures, and length.
- json_object_object_add(section_ir, "errorInfoNum", json_object_new_int(record->ErrInfoNum));
- json_object_object_add(section_ir, "contextInfoNum", json_object_new_int(record->ContextInfoNum));
- json_object_object_add(section_ir, "sectionLength", json_object_new_uint64(record->SectionLength));
+ //Validation bits.
+ json_object *validation = bitfield_to_ir(
+ record->ValidFields, 4, ARM_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_ir, "validationBits", validation);
- //Error affinity.
- json_object* error_affinity = json_object_new_object();
- json_object_object_add(error_affinity, "value", json_object_new_int(record->ErrorAffinityLevel));
- json_object_object_add(error_affinity, "type",
- json_object_new_string(record->ErrorAffinityLevel < 4 ? "Vendor Defined" : "Reserved"));
- json_object_object_add(section_ir, "errorAffinity", error_affinity);
+ //Number of error info and context info structures, and length.
+ json_object_object_add(section_ir, "errorInfoNum",
+ json_object_new_int(record->ErrInfoNum));
+ json_object_object_add(section_ir, "contextInfoNum",
+ json_object_new_int(record->ContextInfoNum));
+ json_object_object_add(section_ir, "sectionLength",
+ json_object_new_uint64(record->SectionLength));
- //Processor ID (MPIDR_EL1) and chip ID (MIDR_EL1).
- json_object_object_add(section_ir, "mpidrEl1", json_object_new_uint64(record->MPIDR_EL1));
- json_object_object_add(section_ir, "midrEl1", json_object_new_uint64(record->MIDR_EL1));
+ //Error affinity.
+ json_object *error_affinity = json_object_new_object();
+ json_object_object_add(error_affinity, "value",
+ json_object_new_int(record->ErrorAffinityLevel));
+ json_object_object_add(
+ error_affinity, "type",
+ json_object_new_string(record->ErrorAffinityLevel < 4 ?
+ "Vendor Defined" :
+ "Reserved"));
+ json_object_object_add(section_ir, "errorAffinity", error_affinity);
- //Whether the processor is running, and the state of it if so.
- json_object_object_add(section_ir, "running", json_object_new_boolean(record->RunningState & 0b1));
- if (!(record->RunningState >> 31))
- {
- //Bit 32 of running state is on, so PSCI state information is included.
- //This can't be made human readable, as it is unknown whether this will be the pre-PSCI 1.0 format
- //or the newer Extended StateID format.
- json_object_object_add(section_ir, "psciState", json_object_new_uint64(record->PsciState));
- }
+ //Processor ID (MPIDR_EL1) and chip ID (MIDR_EL1).
+ json_object_object_add(section_ir, "mpidrEl1",
+ json_object_new_uint64(record->MPIDR_EL1));
+ json_object_object_add(section_ir, "midrEl1",
+ json_object_new_uint64(record->MIDR_EL1));
- //Processor error structures.
- json_object* error_info_array = json_object_new_array();
- EFI_ARM_ERROR_INFORMATION_ENTRY* cur_error = (EFI_ARM_ERROR_INFORMATION_ENTRY*)(record + 1);
- for (int i=0; i<record->ErrInfoNum; i++)
- {
- json_object_array_add(error_info_array, cper_arm_error_info_to_ir(cur_error));
- cur_error++;
- }
- json_object_object_add(section_ir, "errorInfo", error_info_array);
+ //Whether the processor is running, and the state of it if so.
+ json_object_object_add(section_ir, "running",
+ json_object_new_boolean(record->RunningState &
+ 0b1));
+ if (!(record->RunningState >> 31)) {
+ //Bit 32 of running state is on, so PSCI state information is included.
+ //This can't be made human readable, as it is unknown whether this will be the pre-PSCI 1.0 format
+ //or the newer Extended StateID format.
+ json_object_object_add(
+ section_ir, "psciState",
+ json_object_new_uint64(record->PsciState));
+ }
- //Processor context structures.
- //The current position is moved within the processing, as it is a dynamic size structure.
- void* cur_pos = (void*)cur_error;
- json_object* context_info_array = json_object_new_array();
- for (int i=0; i<record->ContextInfoNum; i++)
- {
- EFI_ARM_CONTEXT_INFORMATION_HEADER* header = (EFI_ARM_CONTEXT_INFORMATION_HEADER*)cur_pos;
- json_object* processor_context = cper_arm_processor_context_to_ir(header, &cur_pos);
- json_object_array_add(context_info_array, processor_context);
- }
- json_object_object_add(section_ir, "contextInfo", context_info_array);
+ //Processor error structures.
+ json_object *error_info_array = json_object_new_array();
+ EFI_ARM_ERROR_INFORMATION_ENTRY *cur_error =
+ (EFI_ARM_ERROR_INFORMATION_ENTRY *)(record + 1);
+ for (int i = 0; i < record->ErrInfoNum; i++) {
+ json_object_array_add(error_info_array,
+ cper_arm_error_info_to_ir(cur_error));
+ cur_error++;
+ }
+ json_object_object_add(section_ir, "errorInfo", error_info_array);
- //Is there any vendor-specific information following?
- if (cur_pos < section + record->SectionLength)
- {
- json_object* vendor_specific = json_object_new_object();
- char* encoded = b64_encode((unsigned char*)cur_pos, section + record->SectionLength - cur_pos);
- json_object_object_add(vendor_specific, "data", json_object_new_string(encoded));
- free(encoded);
+ //Processor context structures.
+ //The current position is moved within the processing, as it is a dynamic size structure.
+ void *cur_pos = (void *)cur_error;
+ json_object *context_info_array = json_object_new_array();
+ for (int i = 0; i < record->ContextInfoNum; i++) {
+ EFI_ARM_CONTEXT_INFORMATION_HEADER *header =
+ (EFI_ARM_CONTEXT_INFORMATION_HEADER *)cur_pos;
+ json_object *processor_context =
+ cper_arm_processor_context_to_ir(header, &cur_pos);
+ json_object_array_add(context_info_array, processor_context);
+ }
+ json_object_object_add(section_ir, "contextInfo", context_info_array);
- json_object_object_add(section_ir, "vendorSpecificInfo", vendor_specific);
- }
+ //Is there any vendor-specific information following?
+ if (cur_pos < section + record->SectionLength) {
+ json_object *vendor_specific = json_object_new_object();
+ char *encoded =
+ b64_encode((unsigned char *)cur_pos,
+ section + record->SectionLength - cur_pos);
+ json_object_object_add(vendor_specific, "data",
+ json_object_new_string(encoded));
+ free(encoded);
- return section_ir;
+ json_object_object_add(section_ir, "vendorSpecificInfo",
+ vendor_specific);
+ }
+
+ return section_ir;
}
//Converts a single ARM Process Error Information structure into JSON IR.
-json_object* cper_arm_error_info_to_ir(EFI_ARM_ERROR_INFORMATION_ENTRY* error_info)
+json_object *
+cper_arm_error_info_to_ir(EFI_ARM_ERROR_INFORMATION_ENTRY *error_info)
{
- json_object* error_info_ir = json_object_new_object();
+ json_object *error_info_ir = json_object_new_object();
- //Version, length.
- json_object_object_add(error_info_ir, "version", json_object_new_int(error_info->Version));
- json_object_object_add(error_info_ir, "length", json_object_new_int(error_info->Length));
+ //Version, length.
+ json_object_object_add(error_info_ir, "version",
+ json_object_new_int(error_info->Version));
+ json_object_object_add(error_info_ir, "length",
+ json_object_new_int(error_info->Length));
- //Validation bitfield.
- json_object* validation = bitfield_to_ir(error_info->ValidationBits, 5, ARM_ERROR_INFO_ENTRY_VALID_BITFIELD_NAMES);
- json_object_object_add(error_info_ir, "validationBits", validation);
+ //Validation bitfield.
+ json_object *validation =
+ bitfield_to_ir(error_info->ValidationBits, 5,
+ ARM_ERROR_INFO_ENTRY_VALID_BITFIELD_NAMES);
+ json_object_object_add(error_info_ir, "validationBits", validation);
- //The type of error information in this log.
- json_object* error_type = integer_to_readable_pair(error_info->Type, 4,
- ARM_ERROR_INFO_ENTRY_INFO_TYPES_KEYS,
- ARM_ERROR_INFO_ENTRY_INFO_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(error_info_ir, "errorType", error_type);
+ //The type of error information in this log.
+ json_object *error_type = integer_to_readable_pair(
+ error_info->Type, 4, ARM_ERROR_INFO_ENTRY_INFO_TYPES_KEYS,
+ ARM_ERROR_INFO_ENTRY_INFO_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(error_info_ir, "errorType", error_type);
- //Multiple error count.
- json_object* multiple_error = json_object_new_object();
- json_object_object_add(multiple_error, "value", json_object_new_int(error_info->MultipleError));
- json_object_object_add(multiple_error, "type",
- json_object_new_string(error_info->MultipleError < 1 ? "Single Error" : "Multiple Errors"));
- json_object_object_add(error_info_ir, "multipleError", multiple_error);
+ //Multiple error count.
+ json_object *multiple_error = json_object_new_object();
+ json_object_object_add(multiple_error, "value",
+ json_object_new_int(error_info->MultipleError));
+ json_object_object_add(
+ multiple_error, "type",
+ json_object_new_string(error_info->MultipleError < 1 ?
+ "Single Error" :
+ "Multiple Errors"));
+ json_object_object_add(error_info_ir, "multipleError", multiple_error);
- //Flags.
- json_object* flags = bitfield_to_ir(error_info->Flags, 4, ARM_ERROR_INFO_ENTRY_FLAGS_NAMES);
- json_object_object_add(error_info_ir, "flags", flags);
+ //Flags.
+ json_object *flags = bitfield_to_ir(error_info->Flags, 4,
+ ARM_ERROR_INFO_ENTRY_FLAGS_NAMES);
+ json_object_object_add(error_info_ir, "flags", flags);
- //Error information, split by type.
- json_object* error_subinfo = NULL;
- switch (error_info->Type)
- {
- case ARM_ERROR_INFORMATION_TYPE_CACHE: //Cache
- case ARM_ERROR_INFORMATION_TYPE_TLB: //TLB
- error_subinfo = cper_arm_cache_tlb_error_to_ir((EFI_ARM_CACHE_ERROR_STRUCTURE*)&error_info->ErrorInformation, error_info);
- break;
- case ARM_ERROR_INFORMATION_TYPE_BUS: //Bus
- error_subinfo = cper_arm_bus_error_to_ir((EFI_ARM_BUS_ERROR_STRUCTURE*)&error_info->ErrorInformation);
- break;
+ //Error information, split by type.
+ json_object *error_subinfo = NULL;
+ switch (error_info->Type) {
+ case ARM_ERROR_INFORMATION_TYPE_CACHE: //Cache
+ case ARM_ERROR_INFORMATION_TYPE_TLB: //TLB
+ error_subinfo = cper_arm_cache_tlb_error_to_ir(
+ (EFI_ARM_CACHE_ERROR_STRUCTURE *)&error_info
+ ->ErrorInformation,
+ error_info);
+ break;
+ case ARM_ERROR_INFORMATION_TYPE_BUS: //Bus
+ error_subinfo = cper_arm_bus_error_to_ir(
+ (EFI_ARM_BUS_ERROR_STRUCTURE *)&error_info
+ ->ErrorInformation);
+ break;
- default:
- //Unknown/microarch, so can't be made readable. Simply dump as a uint64 data object.
- error_subinfo = json_object_new_object();
- json_object_object_add(error_subinfo, "data", json_object_new_uint64(*((UINT64*)&error_info->ErrorInformation)));
- break;
- }
- json_object_object_add(error_info_ir, "errorInformation", error_subinfo);
+ default:
+ //Unknown/microarch, so can't be made readable. Simply dump as a uint64 data object.
+ error_subinfo = json_object_new_object();
+ json_object_object_add(
+ error_subinfo, "data",
+ json_object_new_uint64(
+ *((UINT64 *)&error_info->ErrorInformation)));
+ break;
+ }
+ json_object_object_add(error_info_ir, "errorInformation",
+ error_subinfo);
- //Virtual fault address, physical fault address.
- json_object_object_add(error_info_ir, "virtualFaultAddress", json_object_new_uint64(error_info->VirtualFaultAddress));
- json_object_object_add(error_info_ir, "physicalFaultAddress", json_object_new_uint64(error_info->PhysicalFaultAddress));
-
- return error_info_ir;
+ //Virtual fault address, physical fault address.
+ json_object_object_add(
+ error_info_ir, "virtualFaultAddress",
+ json_object_new_uint64(error_info->VirtualFaultAddress));
+ json_object_object_add(
+ error_info_ir, "physicalFaultAddress",
+ json_object_new_uint64(error_info->PhysicalFaultAddress));
+
+ return error_info_ir;
}
//Converts a single ARM cache/TLB error information structure into JSON IR format.
-json_object* cper_arm_cache_tlb_error_to_ir(EFI_ARM_CACHE_ERROR_STRUCTURE* cache_tlb_error, EFI_ARM_ERROR_INFORMATION_ENTRY* error_info)
+json_object *
+cper_arm_cache_tlb_error_to_ir(EFI_ARM_CACHE_ERROR_STRUCTURE *cache_tlb_error,
+ EFI_ARM_ERROR_INFORMATION_ENTRY *error_info)
{
- json_object* cache_tlb_error_ir = json_object_new_object();
+ json_object *cache_tlb_error_ir = json_object_new_object();
- //Validation bitfield.
- json_object* validation = bitfield_to_ir(cache_tlb_error->ValidationBits, 7, ARM_CACHE_TLB_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(cache_tlb_error_ir, "validationBits", validation);
+ //Validation bitfield.
+ json_object *validation =
+ bitfield_to_ir(cache_tlb_error->ValidationBits, 7,
+ ARM_CACHE_TLB_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(cache_tlb_error_ir, "validationBits",
+ validation);
- //Transaction type.
- json_object* transaction_type = integer_to_readable_pair(cache_tlb_error->TransactionType, 3,
- ARM_ERROR_TRANSACTION_TYPES_KEYS,
- ARM_ERROR_TRANSACTION_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(cache_tlb_error_ir, "transactionType", transaction_type);
+ //Transaction type.
+ json_object *transaction_type = integer_to_readable_pair(
+ cache_tlb_error->TransactionType, 3,
+ ARM_ERROR_TRANSACTION_TYPES_KEYS,
+ ARM_ERROR_TRANSACTION_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(cache_tlb_error_ir, "transactionType",
+ transaction_type);
- //Operation.
- json_object* operation;
- if (error_info->Type == 0)
- {
- //Cache operation.
- operation = integer_to_readable_pair(cache_tlb_error->Operation, 11,
- ARM_CACHE_BUS_OPERATION_TYPES_KEYS,
- ARM_CACHE_BUS_OPERATION_TYPES_VALUES,
- "Unknown (Reserved)");
- }
- else
- {
- //TLB operation.
- operation = integer_to_readable_pair(cache_tlb_error->Operation, 9,
- ARM_TLB_OPERATION_TYPES_KEYS,
- ARM_TLB_OPERATION_TYPES_VALUES,
- "Unknown (Reserved)");
- }
- json_object_object_add(cache_tlb_error_ir, "operation", operation);
+ //Operation.
+ json_object *operation;
+ if (error_info->Type == 0) {
+ //Cache operation.
+ operation = integer_to_readable_pair(
+ cache_tlb_error->Operation, 11,
+ ARM_CACHE_BUS_OPERATION_TYPES_KEYS,
+ ARM_CACHE_BUS_OPERATION_TYPES_VALUES,
+ "Unknown (Reserved)");
+ } else {
+ //TLB operation.
+ operation = integer_to_readable_pair(
+ cache_tlb_error->Operation, 9,
+ ARM_TLB_OPERATION_TYPES_KEYS,
+ ARM_TLB_OPERATION_TYPES_VALUES, "Unknown (Reserved)");
+ }
+ json_object_object_add(cache_tlb_error_ir, "operation", operation);
- //Miscellaneous remaining fields.
- json_object_object_add(cache_tlb_error_ir, "level", json_object_new_int(cache_tlb_error->Level));
- json_object_object_add(cache_tlb_error_ir, "processorContextCorrupt", json_object_new_boolean(cache_tlb_error->ProcessorContextCorrupt));
- json_object_object_add(cache_tlb_error_ir, "corrected", json_object_new_boolean(cache_tlb_error->Corrected));
- json_object_object_add(cache_tlb_error_ir, "precisePC", json_object_new_boolean(cache_tlb_error->PrecisePC));
- json_object_object_add(cache_tlb_error_ir, "restartablePC", json_object_new_boolean(cache_tlb_error->RestartablePC));
- return cache_tlb_error_ir;
+ //Miscellaneous remaining fields.
+ json_object_object_add(cache_tlb_error_ir, "level",
+ json_object_new_int(cache_tlb_error->Level));
+ json_object_object_add(
+ cache_tlb_error_ir, "processorContextCorrupt",
+ json_object_new_boolean(
+ cache_tlb_error->ProcessorContextCorrupt));
+ json_object_object_add(
+ cache_tlb_error_ir, "corrected",
+ json_object_new_boolean(cache_tlb_error->Corrected));
+ json_object_object_add(
+ cache_tlb_error_ir, "precisePC",
+ json_object_new_boolean(cache_tlb_error->PrecisePC));
+ json_object_object_add(
+ cache_tlb_error_ir, "restartablePC",
+ json_object_new_boolean(cache_tlb_error->RestartablePC));
+ return cache_tlb_error_ir;
}
//Converts a single ARM bus error information structure into JSON IR format.
-json_object* cper_arm_bus_error_to_ir(EFI_ARM_BUS_ERROR_STRUCTURE* bus_error)
+json_object *cper_arm_bus_error_to_ir(EFI_ARM_BUS_ERROR_STRUCTURE *bus_error)
{
- json_object* bus_error_ir = json_object_new_object();
+ json_object *bus_error_ir = json_object_new_object();
- //Validation bits.
- json_object* validation = bitfield_to_ir(bus_error->ValidationBits, 12, ARM_BUS_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(bus_error_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation =
+ bitfield_to_ir(bus_error->ValidationBits, 12,
+ ARM_BUS_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(bus_error_ir, "validationBits", validation);
- //Transaction type.
- json_object* transaction_type = integer_to_readable_pair(bus_error->TransactionType, 3,
- ARM_ERROR_TRANSACTION_TYPES_KEYS,
- ARM_ERROR_TRANSACTION_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(bus_error_ir, "transactionType", transaction_type);
+ //Transaction type.
+ json_object *transaction_type = integer_to_readable_pair(
+ bus_error->TransactionType, 3, ARM_ERROR_TRANSACTION_TYPES_KEYS,
+ ARM_ERROR_TRANSACTION_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(bus_error_ir, "transactionType",
+ transaction_type);
- //Operation.
- json_object* operation = integer_to_readable_pair(bus_error->Operation, 7,
- ARM_CACHE_BUS_OPERATION_TYPES_KEYS,
- ARM_CACHE_BUS_OPERATION_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(bus_error_ir, "operation", operation);
+ //Operation.
+ json_object *operation = integer_to_readable_pair(
+ bus_error->Operation, 7, ARM_CACHE_BUS_OPERATION_TYPES_KEYS,
+ ARM_CACHE_BUS_OPERATION_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(bus_error_ir, "operation", operation);
- //Affinity level of bus error, + miscellaneous fields.
- json_object_object_add(bus_error_ir, "level", json_object_new_int(bus_error->Level));
- json_object_object_add(bus_error_ir, "processorContextCorrupt", json_object_new_boolean(bus_error->ProcessorContextCorrupt));
- json_object_object_add(bus_error_ir, "corrected", json_object_new_boolean(bus_error->Corrected));
- json_object_object_add(bus_error_ir, "precisePC", json_object_new_boolean(bus_error->PrecisePC));
- json_object_object_add(bus_error_ir, "restartablePC", json_object_new_boolean(bus_error->RestartablePC));
- json_object_object_add(bus_error_ir, "timedOut", json_object_new_boolean(bus_error->TimeOut));
+ //Affinity level of bus error, + miscellaneous fields.
+ json_object_object_add(bus_error_ir, "level",
+ json_object_new_int(bus_error->Level));
+ json_object_object_add(
+ bus_error_ir, "processorContextCorrupt",
+ json_object_new_boolean(bus_error->ProcessorContextCorrupt));
+ json_object_object_add(bus_error_ir, "corrected",
+ json_object_new_boolean(bus_error->Corrected));
+ json_object_object_add(bus_error_ir, "precisePC",
+ json_object_new_boolean(bus_error->PrecisePC));
+ json_object_object_add(
+ bus_error_ir, "restartablePC",
+ json_object_new_boolean(bus_error->RestartablePC));
+ json_object_object_add(bus_error_ir, "timedOut",
+ json_object_new_boolean(bus_error->TimeOut));
- //Participation type.
- json_object* participation_type = integer_to_readable_pair(bus_error->ParticipationType, 4,
- ARM_BUS_PARTICIPATION_TYPES_KEYS,
- ARM_BUS_PARTICIPATION_TYPES_VALUES,
- "Unknown");
- json_object_object_add(bus_error_ir, "participationType", participation_type);
+ //Participation type.
+ json_object *participation_type = integer_to_readable_pair(
+ bus_error->ParticipationType, 4,
+ ARM_BUS_PARTICIPATION_TYPES_KEYS,
+ ARM_BUS_PARTICIPATION_TYPES_VALUES, "Unknown");
+ json_object_object_add(bus_error_ir, "participationType",
+ participation_type);
- //Address space.
- json_object* address_space = integer_to_readable_pair(bus_error->AddressSpace, 3,
- ARM_BUS_ADDRESS_SPACE_TYPES_KEYS,
- ARM_BUS_ADDRESS_SPACE_TYPES_VALUES,
- "Unknown");
- json_object_object_add(bus_error_ir, "addressSpace", address_space);
+ //Address space.
+ json_object *address_space = integer_to_readable_pair(
+ bus_error->AddressSpace, 3, ARM_BUS_ADDRESS_SPACE_TYPES_KEYS,
+ ARM_BUS_ADDRESS_SPACE_TYPES_VALUES, "Unknown");
+ json_object_object_add(bus_error_ir, "addressSpace", address_space);
- //Memory access attributes.
- //todo: find the specification of these in the ARM ARM
- json_object_object_add(bus_error_ir, "memoryAttributes", json_object_new_int(bus_error->MemoryAddressAttributes));
+ //Memory access attributes.
+ //todo: find the specification of these in the ARM ARM
+ json_object_object_add(
+ bus_error_ir, "memoryAttributes",
+ json_object_new_int(bus_error->MemoryAddressAttributes));
- //Access Mode
- json_object* access_mode = json_object_new_object();
- json_object_object_add(access_mode, "value", json_object_new_int(bus_error->AccessMode));
- json_object_object_add(access_mode, "name", json_object_new_string(bus_error->AccessMode == 0 ? "Secure" : "Normal"));
- json_object_object_add(bus_error_ir, "accessMode", access_mode);
+ //Access Mode
+ json_object *access_mode = json_object_new_object();
+ json_object_object_add(access_mode, "value",
+ json_object_new_int(bus_error->AccessMode));
+ json_object_object_add(
+ access_mode, "name",
+ json_object_new_string(bus_error->AccessMode == 0 ? "Secure" :
+ "Normal"));
+ json_object_object_add(bus_error_ir, "accessMode", access_mode);
- return bus_error_ir;
+ return bus_error_ir;
}
//Converts a single ARM processor context block into JSON IR.
-json_object* cper_arm_processor_context_to_ir(EFI_ARM_CONTEXT_INFORMATION_HEADER* header, void** cur_pos)
+json_object *
+cper_arm_processor_context_to_ir(EFI_ARM_CONTEXT_INFORMATION_HEADER *header,
+ void **cur_pos)
{
- json_object* context_ir = json_object_new_object();
+ json_object *context_ir = json_object_new_object();
- //Version.
- json_object_object_add(context_ir, "version", json_object_new_int(header->Version));
+ //Version.
+ json_object_object_add(context_ir, "version",
+ json_object_new_int(header->Version));
- //Add the context type.
- json_object* context_type = integer_to_readable_pair(header->RegisterContextType, 9,
- ARM_PROCESSOR_INFO_REGISTER_CONTEXT_TYPES_KEYS,
- ARM_PROCESSOR_INFO_REGISTER_CONTEXT_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(context_ir, "registerContextType", context_type);
+ //Add the context type.
+ json_object *context_type = integer_to_readable_pair(
+ header->RegisterContextType, 9,
+ ARM_PROCESSOR_INFO_REGISTER_CONTEXT_TYPES_KEYS,
+ ARM_PROCESSOR_INFO_REGISTER_CONTEXT_TYPES_VALUES,
+ "Unknown (Reserved)");
+ json_object_object_add(context_ir, "registerContextType", context_type);
- //Register array size (bytes).
- json_object_object_add(context_ir, "registerArraySize", json_object_new_uint64(header->RegisterArraySize));
+ //Register array size (bytes).
+ json_object_object_add(
+ context_ir, "registerArraySize",
+ json_object_new_uint64(header->RegisterArraySize));
- //The register array itself.
- *cur_pos = (void*)(header + 1);
- json_object* register_array = NULL;
- switch (header->RegisterContextType)
- {
- case EFI_ARM_CONTEXT_TYPE_AARCH32_GPR:
- register_array = uniform_struct_to_ir((UINT32*)cur_pos,
- sizeof(EFI_ARM_V8_AARCH32_GPR) / sizeof(UINT32), ARM_AARCH32_GPR_NAMES);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH32_EL1:
- register_array = uniform_struct_to_ir((UINT32*)cur_pos,
- sizeof(EFI_ARM_AARCH32_EL1_CONTEXT_REGISTERS) / sizeof(UINT32), ARM_AARCH32_EL1_REGISTER_NAMES);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH32_EL2:
- register_array = uniform_struct_to_ir((UINT32*)cur_pos,
- sizeof(EFI_ARM_AARCH32_EL2_CONTEXT_REGISTERS) / sizeof(UINT32), ARM_AARCH32_EL2_REGISTER_NAMES);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH32_SECURE:
- register_array = uniform_struct_to_ir((UINT32*)cur_pos,
- sizeof(EFI_ARM_AARCH32_SECURE_CONTEXT_REGISTERS) / sizeof(UINT32), ARM_AARCH32_SECURE_REGISTER_NAMES);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH64_GPR:
- register_array = uniform_struct64_to_ir((UINT64*)cur_pos,
- sizeof(EFI_ARM_V8_AARCH64_GPR) / sizeof(UINT64), ARM_AARCH64_GPR_NAMES);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH64_EL1:
- register_array = uniform_struct64_to_ir((UINT64*)cur_pos,
- sizeof(EFI_ARM_AARCH64_EL1_CONTEXT_REGISTERS) / sizeof(UINT64), ARM_AARCH64_EL1_REGISTER_NAMES);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH64_EL2:
- register_array = uniform_struct64_to_ir((UINT64*)cur_pos,
- sizeof(EFI_ARM_AARCH64_EL2_CONTEXT_REGISTERS) / sizeof(UINT64), ARM_AARCH64_EL2_REGISTER_NAMES);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH64_EL3:
- register_array = uniform_struct64_to_ir((UINT64*)cur_pos,
- sizeof(EFI_ARM_AARCH64_EL3_CONTEXT_REGISTERS) / sizeof(UINT64), ARM_AARCH64_EL3_REGISTER_NAMES);
- break;
- case EFI_ARM_CONTEXT_TYPE_MISC:
- register_array = cper_arm_misc_register_array_to_ir((EFI_ARM_MISC_CONTEXT_REGISTER*)cur_pos);
- break;
- default:
- //Unknown register array type, add as base64 data instead.
- register_array = json_object_new_object();
- char* encoded = b64_encode((unsigned char*)cur_pos, header->RegisterArraySize);
- json_object_object_add(register_array, "data", json_object_new_string(encoded));
- free(encoded);
- break;
- }
- json_object_object_add(context_ir, "registerArray", register_array);
+ //The register array itself.
+ *cur_pos = (void *)(header + 1);
+ json_object *register_array = NULL;
+ switch (header->RegisterContextType) {
+ case EFI_ARM_CONTEXT_TYPE_AARCH32_GPR:
+ register_array = uniform_struct_to_ir(
+ (UINT32 *)cur_pos,
+ sizeof(EFI_ARM_V8_AARCH32_GPR) / sizeof(UINT32),
+ ARM_AARCH32_GPR_NAMES);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH32_EL1:
+ register_array = uniform_struct_to_ir(
+ (UINT32 *)cur_pos,
+ sizeof(EFI_ARM_AARCH32_EL1_CONTEXT_REGISTERS) /
+ sizeof(UINT32),
+ ARM_AARCH32_EL1_REGISTER_NAMES);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH32_EL2:
+ register_array = uniform_struct_to_ir(
+ (UINT32 *)cur_pos,
+ sizeof(EFI_ARM_AARCH32_EL2_CONTEXT_REGISTERS) /
+ sizeof(UINT32),
+ ARM_AARCH32_EL2_REGISTER_NAMES);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH32_SECURE:
+ register_array = uniform_struct_to_ir(
+ (UINT32 *)cur_pos,
+ sizeof(EFI_ARM_AARCH32_SECURE_CONTEXT_REGISTERS) /
+ sizeof(UINT32),
+ ARM_AARCH32_SECURE_REGISTER_NAMES);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH64_GPR:
+ register_array = uniform_struct64_to_ir(
+ (UINT64 *)cur_pos,
+ sizeof(EFI_ARM_V8_AARCH64_GPR) / sizeof(UINT64),
+ ARM_AARCH64_GPR_NAMES);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH64_EL1:
+ register_array = uniform_struct64_to_ir(
+ (UINT64 *)cur_pos,
+ sizeof(EFI_ARM_AARCH64_EL1_CONTEXT_REGISTERS) /
+ sizeof(UINT64),
+ ARM_AARCH64_EL1_REGISTER_NAMES);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH64_EL2:
+ register_array = uniform_struct64_to_ir(
+ (UINT64 *)cur_pos,
+ sizeof(EFI_ARM_AARCH64_EL2_CONTEXT_REGISTERS) /
+ sizeof(UINT64),
+ ARM_AARCH64_EL2_REGISTER_NAMES);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH64_EL3:
+ register_array = uniform_struct64_to_ir(
+ (UINT64 *)cur_pos,
+ sizeof(EFI_ARM_AARCH64_EL3_CONTEXT_REGISTERS) /
+ sizeof(UINT64),
+ ARM_AARCH64_EL3_REGISTER_NAMES);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_MISC:
+ register_array = cper_arm_misc_register_array_to_ir(
+ (EFI_ARM_MISC_CONTEXT_REGISTER *)cur_pos);
+ break;
+ default:
+ //Unknown register array type, add as base64 data instead.
+ register_array = json_object_new_object();
+ char *encoded = b64_encode((unsigned char *)cur_pos,
+ header->RegisterArraySize);
+ json_object_object_add(register_array, "data",
+ json_object_new_string(encoded));
+ free(encoded);
+ break;
+ }
+ json_object_object_add(context_ir, "registerArray", register_array);
- //Set the current position to after the processor context structure.
- *cur_pos = (UINT8*)(*cur_pos) + header->RegisterArraySize;
+ //Set the current position to after the processor context structure.
+ *cur_pos = (UINT8 *)(*cur_pos) + header->RegisterArraySize;
- return context_ir;
+ return context_ir;
}
//Converts a single CPER ARM miscellaneous register array to JSON IR format.
-json_object* cper_arm_misc_register_array_to_ir(EFI_ARM_MISC_CONTEXT_REGISTER* misc_register)
+json_object *
+cper_arm_misc_register_array_to_ir(EFI_ARM_MISC_CONTEXT_REGISTER *misc_register)
{
- json_object* register_array = json_object_new_object();
- json_object* mrs_encoding = json_object_new_object();
- json_object_object_add(mrs_encoding, "op2", json_object_new_uint64(misc_register->MrsOp2));
- json_object_object_add(mrs_encoding, "crm", json_object_new_uint64(misc_register->MrsCrm));
- json_object_object_add(mrs_encoding, "crn", json_object_new_uint64(misc_register->MrsCrn));
- json_object_object_add(mrs_encoding, "op1", json_object_new_uint64(misc_register->MrsOp1));
- json_object_object_add(mrs_encoding, "o0", json_object_new_uint64(misc_register->MrsO0));
- json_object_object_add(register_array, "mrsEncoding", mrs_encoding);
- json_object_object_add(register_array, "value", json_object_new_uint64(misc_register->Value));
+ json_object *register_array = json_object_new_object();
+ json_object *mrs_encoding = json_object_new_object();
+ json_object_object_add(mrs_encoding, "op2",
+ json_object_new_uint64(misc_register->MrsOp2));
+ json_object_object_add(mrs_encoding, "crm",
+ json_object_new_uint64(misc_register->MrsCrm));
+ json_object_object_add(mrs_encoding, "crn",
+ json_object_new_uint64(misc_register->MrsCrn));
+ json_object_object_add(mrs_encoding, "op1",
+ json_object_new_uint64(misc_register->MrsOp1));
+ json_object_object_add(mrs_encoding, "o0",
+ json_object_new_uint64(misc_register->MrsO0));
+ json_object_object_add(register_array, "mrsEncoding", mrs_encoding);
+ json_object_object_add(register_array, "value",
+ json_object_new_uint64(misc_register->Value));
- return register_array;
+ return register_array;
}
//Converts a single CPER-JSON ARM error section into CPER binary, outputting to the given stream.
-void ir_section_arm_to_cper(json_object* section, FILE* out)
+void ir_section_arm_to_cper(json_object *section, FILE *out)
{
- EFI_ARM_ERROR_RECORD* section_cper = (EFI_ARM_ERROR_RECORD*)calloc(1, sizeof(EFI_ARM_ERROR_RECORD));
- long starting_stream_pos = ftell(out);
+ EFI_ARM_ERROR_RECORD *section_cper =
+ (EFI_ARM_ERROR_RECORD *)calloc(1, sizeof(EFI_ARM_ERROR_RECORD));
+ long starting_stream_pos = ftell(out);
- //Validation bits.
- section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 4, ARM_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ section_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 4,
+ ARM_ERROR_VALID_BITFIELD_NAMES);
- //Count of error/context info structures.
- section_cper->ErrInfoNum = json_object_get_int(json_object_object_get(section, "errorInfoNum"));
- section_cper->ContextInfoNum = json_object_get_int(json_object_object_get(section, "contextInfoNum"));
+ //Count of error/context info structures.
+ section_cper->ErrInfoNum = json_object_get_int(
+ json_object_object_get(section, "errorInfoNum"));
+ section_cper->ContextInfoNum = json_object_get_int(
+ json_object_object_get(section, "contextInfoNum"));
- //Miscellaneous raw value fields.
- section_cper->SectionLength = json_object_get_uint64(json_object_object_get(section, "sectionLength"));
- section_cper->ErrorAffinityLevel = readable_pair_to_integer(json_object_object_get(section, "errorAffinity"));
- section_cper->MPIDR_EL1 = json_object_get_uint64(json_object_object_get(section, "mpidrEl1"));
- section_cper->MIDR_EL1 = json_object_get_uint64(json_object_object_get(section, "midrEl1"));
- section_cper->RunningState = json_object_get_boolean(json_object_object_get(section, "running"));
+ //Miscellaneous raw value fields.
+ section_cper->SectionLength = json_object_get_uint64(
+ json_object_object_get(section, "sectionLength"));
+ section_cper->ErrorAffinityLevel = readable_pair_to_integer(
+ json_object_object_get(section, "errorAffinity"));
+ section_cper->MPIDR_EL1 = json_object_get_uint64(
+ json_object_object_get(section, "mpidrEl1"));
+ section_cper->MIDR_EL1 = json_object_get_uint64(
+ json_object_object_get(section, "midrEl1"));
+ section_cper->RunningState = json_object_get_boolean(
+ json_object_object_get(section, "running"));
- //Optional PSCI state.
- json_object* psci_state = json_object_object_get(section, "psciState");
- if (psci_state != NULL)
- section_cper->PsciState = json_object_get_uint64(psci_state);
+ //Optional PSCI state.
+ json_object *psci_state = json_object_object_get(section, "psciState");
+ if (psci_state != NULL)
+ section_cper->PsciState = json_object_get_uint64(psci_state);
- //Flush header to stream.
- fwrite(section_cper, sizeof(EFI_ARM_ERROR_RECORD), 1, out);
- fflush(out);
+ //Flush header to stream.
+ fwrite(section_cper, sizeof(EFI_ARM_ERROR_RECORD), 1, out);
+ fflush(out);
- //Error info structure array.
- json_object* error_info = json_object_object_get(section, "errorInfo");
- for (int i=0; i<section_cper->ErrInfoNum; i++)
- ir_arm_error_info_to_cper(json_object_array_get_idx(error_info, i), out);
+ //Error info structure array.
+ json_object *error_info = json_object_object_get(section, "errorInfo");
+ for (int i = 0; i < section_cper->ErrInfoNum; i++)
+ ir_arm_error_info_to_cper(
+ json_object_array_get_idx(error_info, i), out);
- //Context info structure array.
- json_object* context_info = json_object_object_get(section, "contextInfo");
- for (int i=0; i<section_cper->ContextInfoNum; i++)
- ir_arm_context_info_to_cper(json_object_array_get_idx(context_info, i), out);
+ //Context info structure array.
+ json_object *context_info =
+ json_object_object_get(section, "contextInfo");
+ for (int i = 0; i < section_cper->ContextInfoNum; i++)
+ ir_arm_context_info_to_cper(
+ json_object_array_get_idx(context_info, i), out);
- //Vendor specific error info.
- json_object* vendor_specific_info = json_object_object_get(section, "vendorSpecificInfo");
- if (vendor_specific_info != NULL)
- {
- json_object* vendor_info_string = json_object_object_get(vendor_specific_info, "data");
- int vendor_specific_len = json_object_get_string_len(vendor_info_string);
- UINT8* decoded = b64_decode(json_object_get_string(vendor_info_string), vendor_specific_len);
+ //Vendor specific error info.
+ json_object *vendor_specific_info =
+ json_object_object_get(section, "vendorSpecificInfo");
+ if (vendor_specific_info != NULL) {
+ json_object *vendor_info_string =
+ json_object_object_get(vendor_specific_info, "data");
+ int vendor_specific_len =
+ json_object_get_string_len(vendor_info_string);
+ UINT8 *decoded =
+ b64_decode(json_object_get_string(vendor_info_string),
+ vendor_specific_len);
- //Write out to file.
- long cur_stream_pos = ftell(out);
- fwrite(decoded, starting_stream_pos + section_cper->SectionLength - cur_stream_pos, 1, out);
- fflush(out);
- free(decoded);
- }
+ //Write out to file.
+ long cur_stream_pos = ftell(out);
+ fwrite(decoded,
+ starting_stream_pos + section_cper->SectionLength -
+ cur_stream_pos,
+ 1, out);
+ fflush(out);
+ free(decoded);
+ }
- //Free remaining resources.
- free(section_cper);
+ //Free remaining resources.
+ free(section_cper);
}
//Converts a single ARM error information structure into CPER binary, outputting to the given stream.
-void ir_arm_error_info_to_cper(json_object* error_info, FILE* out)
+void ir_arm_error_info_to_cper(json_object *error_info, FILE *out)
{
- EFI_ARM_ERROR_INFORMATION_ENTRY error_info_cper;
+ EFI_ARM_ERROR_INFORMATION_ENTRY error_info_cper;
- //Version, length.
- error_info_cper.Version = json_object_get_int(json_object_object_get(error_info, "version"));
- error_info_cper.Length = json_object_get_int(json_object_object_get(error_info, "length"));
+ //Version, length.
+ error_info_cper.Version = json_object_get_int(
+ json_object_object_get(error_info, "version"));
+ error_info_cper.Length = json_object_get_int(
+ json_object_object_get(error_info, "length"));
- //Validation bits.
- error_info_cper.ValidationBits = ir_to_bitfield(json_object_object_get(error_info, "validationBits"),
- 5, ARM_ERROR_INFO_ENTRY_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ error_info_cper.ValidationBits = ir_to_bitfield(
+ json_object_object_get(error_info, "validationBits"), 5,
+ ARM_ERROR_INFO_ENTRY_VALID_BITFIELD_NAMES);
- //Type, multiple error.
- error_info_cper.Type = (UINT8)readable_pair_to_integer(json_object_object_get(error_info, "type"));
- error_info_cper.MultipleError = (UINT16)readable_pair_to_integer(json_object_object_get(error_info, "multipleError"));
+ //Type, multiple error.
+ error_info_cper.Type = (UINT8)readable_pair_to_integer(
+ json_object_object_get(error_info, "type"));
+ error_info_cper.MultipleError = (UINT16)readable_pair_to_integer(
+ json_object_object_get(error_info, "multipleError"));
- //Flags object.
- error_info_cper.Flags = (UINT8)ir_to_bitfield(json_object_object_get(error_info, "flags"),
- 4, ARM_ERROR_INFO_ENTRY_FLAGS_NAMES);
+ //Flags object.
+ error_info_cper.Flags = (UINT8)ir_to_bitfield(
+ json_object_object_get(error_info, "flags"), 4,
+ ARM_ERROR_INFO_ENTRY_FLAGS_NAMES);
- //Error information.
- json_object* error_info_information = json_object_object_get(error_info, "errorInformation");
- switch (error_info_cper.Type)
- {
- case ARM_ERROR_INFORMATION_TYPE_CACHE:
- case ARM_ERROR_INFORMATION_TYPE_TLB:
- ir_arm_error_cache_tlb_info_to_cper(error_info_information, &error_info_cper.ErrorInformation.CacheError);
- break;
+ //Error information.
+ json_object *error_info_information =
+ json_object_object_get(error_info, "errorInformation");
+ switch (error_info_cper.Type) {
+ case ARM_ERROR_INFORMATION_TYPE_CACHE:
+ case ARM_ERROR_INFORMATION_TYPE_TLB:
+ ir_arm_error_cache_tlb_info_to_cper(
+ error_info_information,
+ &error_info_cper.ErrorInformation.CacheError);
+ break;
- case ARM_ERROR_INFORMATION_TYPE_BUS:
- ir_arm_error_bus_info_to_cper(error_info_information, &error_info_cper.ErrorInformation.BusError);
- break;
+ case ARM_ERROR_INFORMATION_TYPE_BUS:
+ ir_arm_error_bus_info_to_cper(
+ error_info_information,
+ &error_info_cper.ErrorInformation.BusError);
+ break;
- default:
- //Unknown error information type.
- *((UINT64*)&error_info_cper.ErrorInformation) =
- json_object_get_uint64(json_object_object_get(error_info_information, "data"));
- break;
- }
+ default:
+ //Unknown error information type.
+ *((UINT64 *)&error_info_cper.ErrorInformation) =
+ json_object_get_uint64(json_object_object_get(
+ error_info_information, "data"));
+ break;
+ }
- //Virtual/physical fault address.
- error_info_cper.VirtualFaultAddress = json_object_get_uint64(json_object_object_get(error_info, "virtualFaultAddress"));
- error_info_cper.PhysicalFaultAddress = json_object_get_uint64(json_object_object_get(error_info, "physicalFaultAddress"));
+ //Virtual/physical fault address.
+ error_info_cper.VirtualFaultAddress = json_object_get_uint64(
+ json_object_object_get(error_info, "virtualFaultAddress"));
+ error_info_cper.PhysicalFaultAddress = json_object_get_uint64(
+ json_object_object_get(error_info, "physicalFaultAddress"));
- //Write out to stream.
- fwrite(&error_info_cper, sizeof(EFI_ARM_ERROR_INFORMATION_ENTRY), 1, out);
- fflush(out);
+ //Write out to stream.
+ fwrite(&error_info_cper, sizeof(EFI_ARM_ERROR_INFORMATION_ENTRY), 1,
+ out);
+ fflush(out);
}
//Converts a single ARM cache/TLB error information structure into a CPER structure.
-void ir_arm_error_cache_tlb_info_to_cper(json_object* error_information, EFI_ARM_CACHE_ERROR_STRUCTURE* error_info_cper)
+void ir_arm_error_cache_tlb_info_to_cper(
+ json_object *error_information,
+ EFI_ARM_CACHE_ERROR_STRUCTURE *error_info_cper)
{
- //Validation bits.
- error_info_cper->ValidationBits = ir_to_bitfield(json_object_object_get(error_information, "validationBits"),
- 7, ARM_CACHE_TLB_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ error_info_cper->ValidationBits = ir_to_bitfield(
+ json_object_object_get(error_information, "validationBits"), 7,
+ ARM_CACHE_TLB_ERROR_VALID_BITFIELD_NAMES);
- //Miscellaneous value fields.
- error_info_cper->TransactionType = readable_pair_to_integer(json_object_object_get(error_information, "transactionType"));
- error_info_cper->Operation = readable_pair_to_integer(json_object_object_get(error_information, "operation"));
- error_info_cper->Level = json_object_get_uint64(json_object_object_get(error_information, "level"));
- error_info_cper->ProcessorContextCorrupt =
- json_object_get_boolean(json_object_object_get(error_information, "processorContextCorrupt"));
- error_info_cper->Corrected = json_object_get_boolean(json_object_object_get(error_information, "corrected"));
- error_info_cper->PrecisePC = json_object_get_boolean(json_object_object_get(error_information, "precisePC"));
- error_info_cper->RestartablePC = json_object_get_boolean(json_object_object_get(error_information, "restartablePC"));
- error_info_cper->Reserved = 0;
+ //Miscellaneous value fields.
+ error_info_cper->TransactionType = readable_pair_to_integer(
+ json_object_object_get(error_information, "transactionType"));
+ error_info_cper->Operation = readable_pair_to_integer(
+ json_object_object_get(error_information, "operation"));
+ error_info_cper->Level = json_object_get_uint64(
+ json_object_object_get(error_information, "level"));
+ error_info_cper->ProcessorContextCorrupt = json_object_get_boolean(
+ json_object_object_get(error_information,
+ "processorContextCorrupt"));
+ error_info_cper->Corrected = json_object_get_boolean(
+ json_object_object_get(error_information, "corrected"));
+ error_info_cper->PrecisePC = json_object_get_boolean(
+ json_object_object_get(error_information, "precisePC"));
+ error_info_cper->RestartablePC = json_object_get_boolean(
+ json_object_object_get(error_information, "restartablePC"));
+ error_info_cper->Reserved = 0;
}
//Converts a single ARM bus error information structure into a CPER structure.
-void ir_arm_error_bus_info_to_cper(json_object* error_information, EFI_ARM_BUS_ERROR_STRUCTURE* error_info_cper)
+void ir_arm_error_bus_info_to_cper(json_object *error_information,
+ EFI_ARM_BUS_ERROR_STRUCTURE *error_info_cper)
{
- //Validation bits.
- error_info_cper->ValidationBits = ir_to_bitfield(json_object_object_get(error_information, "validationBits"),
- 7, ARM_BUS_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ error_info_cper->ValidationBits = ir_to_bitfield(
+ json_object_object_get(error_information, "validationBits"), 7,
+ ARM_BUS_ERROR_VALID_BITFIELD_NAMES);
- //Miscellaneous value fields.
- error_info_cper->TransactionType = readable_pair_to_integer(json_object_object_get(error_information, "transactionType"));
- error_info_cper->Operation = readable_pair_to_integer(json_object_object_get(error_information, "operation"));
- error_info_cper->Level = json_object_get_uint64(json_object_object_get(error_information, "level"));
- error_info_cper->ProcessorContextCorrupt =
- json_object_get_boolean(json_object_object_get(error_information, "processorContextCorrupt"));
- error_info_cper->Corrected = json_object_get_boolean(json_object_object_get(error_information, "corrected"));
- error_info_cper->PrecisePC = json_object_get_boolean(json_object_object_get(error_information, "precisePC"));
- error_info_cper->RestartablePC = json_object_get_boolean(json_object_object_get(error_information, "restartablePC"));
- error_info_cper->ParticipationType =
- readable_pair_to_integer(json_object_object_get(error_information, "participationType"));
- error_info_cper->AddressSpace = readable_pair_to_integer(json_object_object_get(error_information, "addressSpace"));
- error_info_cper->AccessMode = readable_pair_to_integer(json_object_object_get(error_information, "accessMode"));
- error_info_cper->MemoryAddressAttributes = json_object_get_uint64(json_object_object_get(error_information, "memoryAttributes"));
- error_info_cper->Reserved = 0;
+ //Miscellaneous value fields.
+ error_info_cper->TransactionType = readable_pair_to_integer(
+ json_object_object_get(error_information, "transactionType"));
+ error_info_cper->Operation = readable_pair_to_integer(
+ json_object_object_get(error_information, "operation"));
+ error_info_cper->Level = json_object_get_uint64(
+ json_object_object_get(error_information, "level"));
+ error_info_cper->ProcessorContextCorrupt = json_object_get_boolean(
+ json_object_object_get(error_information,
+ "processorContextCorrupt"));
+ error_info_cper->Corrected = json_object_get_boolean(
+ json_object_object_get(error_information, "corrected"));
+ error_info_cper->PrecisePC = json_object_get_boolean(
+ json_object_object_get(error_information, "precisePC"));
+ error_info_cper->RestartablePC = json_object_get_boolean(
+ json_object_object_get(error_information, "restartablePC"));
+ error_info_cper->ParticipationType = readable_pair_to_integer(
+ json_object_object_get(error_information, "participationType"));
+ error_info_cper->AddressSpace = readable_pair_to_integer(
+ json_object_object_get(error_information, "addressSpace"));
+ error_info_cper->AccessMode = readable_pair_to_integer(
+ json_object_object_get(error_information, "accessMode"));
+ error_info_cper->MemoryAddressAttributes = json_object_get_uint64(
+ json_object_object_get(error_information, "memoryAttributes"));
+ error_info_cper->Reserved = 0;
}
//Converts a single ARM context information structure into CPER binary, outputting to the given stream.
-void ir_arm_context_info_to_cper(json_object* context_info, FILE* out)
+void ir_arm_context_info_to_cper(json_object *context_info, FILE *out)
{
- EFI_ARM_CONTEXT_INFORMATION_HEADER info_header;
+ EFI_ARM_CONTEXT_INFORMATION_HEADER info_header;
- //Version, array size, context type.
- info_header.Version = json_object_get_int(json_object_object_get(context_info, "version"));
- info_header.RegisterArraySize = json_object_get_int(json_object_object_get(context_info, "registerArraySize"));
- info_header.RegisterContextType = readable_pair_to_integer(json_object_object_get(context_info, "registerContextType"));
+ //Version, array size, context type.
+ info_header.Version = json_object_get_int(
+ json_object_object_get(context_info, "version"));
+ info_header.RegisterArraySize = json_object_get_int(
+ json_object_object_get(context_info, "registerArraySize"));
+ info_header.RegisterContextType = readable_pair_to_integer(
+ json_object_object_get(context_info, "registerContextType"));
- //Flush to stream, write the register array itself.
- fwrite(&info_header, sizeof(EFI_ARM_CONTEXT_INFORMATION_HEADER), 1, out);
- fflush(out);
+ //Flush to stream, write the register array itself.
+ fwrite(&info_header, sizeof(EFI_ARM_CONTEXT_INFORMATION_HEADER), 1,
+ out);
+ fflush(out);
- json_object* register_array = json_object_object_get(context_info, "registerArray");
- switch (info_header.RegisterContextType)
- {
- case EFI_ARM_CONTEXT_TYPE_AARCH32_GPR:
- ir_arm_aarch32_gpr_to_cper(register_array, out);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH32_EL1:
- ir_arm_aarch32_el1_to_cper(register_array, out);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH32_EL2:
- ir_arm_aarch32_el2_to_cper(register_array, out);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH32_SECURE:
- ir_arm_aarch32_secure_to_cper(register_array, out);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH64_GPR:
- ir_arm_aarch64_gpr_to_cper(register_array, out);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH64_EL1:
- ir_arm_aarch64_el1_to_cper(register_array, out);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH64_EL2:
- ir_arm_aarch64_el2_to_cper(register_array, out);
- break;
- case EFI_ARM_CONTEXT_TYPE_AARCH64_EL3:
- ir_arm_aarch64_el3_to_cper(register_array, out);
- break;
- case EFI_ARM_CONTEXT_TYPE_MISC:
- ir_arm_misc_registers_to_cper(register_array, out);
- break;
- default:
- //Unknown register structure.
- ir_arm_unknown_register_to_cper(register_array, &info_header, out);
- break;
- }
+ json_object *register_array =
+ json_object_object_get(context_info, "registerArray");
+ switch (info_header.RegisterContextType) {
+ case EFI_ARM_CONTEXT_TYPE_AARCH32_GPR:
+ ir_arm_aarch32_gpr_to_cper(register_array, out);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH32_EL1:
+ ir_arm_aarch32_el1_to_cper(register_array, out);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH32_EL2:
+ ir_arm_aarch32_el2_to_cper(register_array, out);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH32_SECURE:
+ ir_arm_aarch32_secure_to_cper(register_array, out);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH64_GPR:
+ ir_arm_aarch64_gpr_to_cper(register_array, out);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH64_EL1:
+ ir_arm_aarch64_el1_to_cper(register_array, out);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH64_EL2:
+ ir_arm_aarch64_el2_to_cper(register_array, out);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_AARCH64_EL3:
+ ir_arm_aarch64_el3_to_cper(register_array, out);
+ break;
+ case EFI_ARM_CONTEXT_TYPE_MISC:
+ ir_arm_misc_registers_to_cper(register_array, out);
+ break;
+ default:
+ //Unknown register structure.
+ ir_arm_unknown_register_to_cper(register_array, &info_header,
+ out);
+ break;
+ }
}
//Converts a single AARCH32 GPR CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_aarch32_gpr_to_cper(json_object* registers, FILE* out)
+void ir_arm_aarch32_gpr_to_cper(json_object *registers, FILE *out)
{
- //Get uniform register array.
- EFI_ARM_V8_AARCH32_GPR reg_array;
- ir_to_uniform_struct(registers, (UINT32*)®_array,
- sizeof(EFI_ARM_V8_AARCH32_GPR) / sizeof(UINT32), ARM_AARCH32_GPR_NAMES);
+ //Get uniform register array.
+ EFI_ARM_V8_AARCH32_GPR reg_array;
+ ir_to_uniform_struct(registers, (UINT32 *)®_array,
+ sizeof(EFI_ARM_V8_AARCH32_GPR) / sizeof(UINT32),
+ ARM_AARCH32_GPR_NAMES);
- //Flush to stream.
- fwrite(®_array, sizeof(reg_array), 1, out);
- fflush(out);
+ //Flush to stream.
+ fwrite(®_array, sizeof(reg_array), 1, out);
+ fflush(out);
}
//Converts a single AARCH32 EL1 register set CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_aarch32_el1_to_cper(json_object* registers, FILE* out)
+void ir_arm_aarch32_el1_to_cper(json_object *registers, FILE *out)
{
- //Get uniform register array.
- EFI_ARM_AARCH32_EL1_CONTEXT_REGISTERS reg_array;
- ir_to_uniform_struct(registers, (UINT32*)®_array,
- sizeof(EFI_ARM_AARCH32_EL1_CONTEXT_REGISTERS) / sizeof(UINT32), ARM_AARCH32_EL1_REGISTER_NAMES);
+ //Get uniform register array.
+ EFI_ARM_AARCH32_EL1_CONTEXT_REGISTERS reg_array;
+ ir_to_uniform_struct(registers, (UINT32 *)®_array,
+ sizeof(EFI_ARM_AARCH32_EL1_CONTEXT_REGISTERS) /
+ sizeof(UINT32),
+ ARM_AARCH32_EL1_REGISTER_NAMES);
- //Flush to stream.
- fwrite(®_array, sizeof(reg_array), 1, out);
- fflush(out);
+ //Flush to stream.
+ fwrite(®_array, sizeof(reg_array), 1, out);
+ fflush(out);
}
//Converts a single AARCH32 EL2 register set CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_aarch32_el2_to_cper(json_object* registers, FILE* out)
+void ir_arm_aarch32_el2_to_cper(json_object *registers, FILE *out)
{
- //Get uniform register array.
- EFI_ARM_AARCH32_EL2_CONTEXT_REGISTERS reg_array;
- ir_to_uniform_struct(registers, (UINT32*)®_array,
- sizeof(EFI_ARM_AARCH32_EL2_CONTEXT_REGISTERS) / sizeof(UINT32), ARM_AARCH32_EL2_REGISTER_NAMES);
+ //Get uniform register array.
+ EFI_ARM_AARCH32_EL2_CONTEXT_REGISTERS reg_array;
+ ir_to_uniform_struct(registers, (UINT32 *)®_array,
+ sizeof(EFI_ARM_AARCH32_EL2_CONTEXT_REGISTERS) /
+ sizeof(UINT32),
+ ARM_AARCH32_EL2_REGISTER_NAMES);
- //Flush to stream.
- fwrite(®_array, sizeof(reg_array), 1, out);
- fflush(out);
+ //Flush to stream.
+ fwrite(®_array, sizeof(reg_array), 1, out);
+ fflush(out);
}
//Converts a single AARCH32 secure register set CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_aarch32_secure_to_cper(json_object* registers, FILE* out)
+void ir_arm_aarch32_secure_to_cper(json_object *registers, FILE *out)
{
- //Get uniform register array.
- EFI_ARM_AARCH32_SECURE_CONTEXT_REGISTERS reg_array;
- ir_to_uniform_struct(registers, (UINT32*)®_array,
- sizeof(EFI_ARM_AARCH32_SECURE_CONTEXT_REGISTERS) / sizeof(UINT32), ARM_AARCH32_SECURE_REGISTER_NAMES);
+ //Get uniform register array.
+ EFI_ARM_AARCH32_SECURE_CONTEXT_REGISTERS reg_array;
+ ir_to_uniform_struct(registers, (UINT32 *)®_array,
+ sizeof(EFI_ARM_AARCH32_SECURE_CONTEXT_REGISTERS) /
+ sizeof(UINT32),
+ ARM_AARCH32_SECURE_REGISTER_NAMES);
- //Flush to stream.
- fwrite(®_array, sizeof(reg_array), 1, out);
- fflush(out);
+ //Flush to stream.
+ fwrite(®_array, sizeof(reg_array), 1, out);
+ fflush(out);
}
//Converts a single AARCH64 GPR CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_aarch64_gpr_to_cper(json_object* registers, FILE* out)
+void ir_arm_aarch64_gpr_to_cper(json_object *registers, FILE *out)
{
- //Get uniform register array.
- EFI_ARM_V8_AARCH64_GPR reg_array;
- ir_to_uniform_struct64(registers, (UINT64*)®_array,
- sizeof(EFI_ARM_V8_AARCH64_GPR) / sizeof(UINT64), ARM_AARCH64_GPR_NAMES);
+ //Get uniform register array.
+ EFI_ARM_V8_AARCH64_GPR reg_array;
+ ir_to_uniform_struct64(registers, (UINT64 *)®_array,
+ sizeof(EFI_ARM_V8_AARCH64_GPR) / sizeof(UINT64),
+ ARM_AARCH64_GPR_NAMES);
- //Flush to stream.
- fwrite(®_array, sizeof(reg_array), 1, out);
- fflush(out);
+ //Flush to stream.
+ fwrite(®_array, sizeof(reg_array), 1, out);
+ fflush(out);
}
//Converts a single AARCH64 EL1 register set CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_aarch64_el1_to_cper(json_object* registers, FILE* out)
+void ir_arm_aarch64_el1_to_cper(json_object *registers, FILE *out)
{
- //Get uniform register array.
- EFI_ARM_AARCH64_EL1_CONTEXT_REGISTERS reg_array;
- ir_to_uniform_struct64(registers, (UINT64*)®_array,
- sizeof(EFI_ARM_AARCH64_EL1_CONTEXT_REGISTERS) / sizeof(UINT64), ARM_AARCH64_EL1_REGISTER_NAMES);
+ //Get uniform register array.
+ EFI_ARM_AARCH64_EL1_CONTEXT_REGISTERS reg_array;
+ ir_to_uniform_struct64(registers, (UINT64 *)®_array,
+ sizeof(EFI_ARM_AARCH64_EL1_CONTEXT_REGISTERS) /
+ sizeof(UINT64),
+ ARM_AARCH64_EL1_REGISTER_NAMES);
- //Flush to stream.
- fwrite(®_array, sizeof(reg_array), 1, out);
- fflush(out);
+ //Flush to stream.
+ fwrite(®_array, sizeof(reg_array), 1, out);
+ fflush(out);
}
//Converts a single AARCH64 EL2 register set CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_aarch64_el2_to_cper(json_object* registers, FILE* out)
+void ir_arm_aarch64_el2_to_cper(json_object *registers, FILE *out)
{
- //Get uniform register array.
- EFI_ARM_AARCH64_EL2_CONTEXT_REGISTERS reg_array;
- ir_to_uniform_struct64(registers, (UINT64*)®_array,
- sizeof(EFI_ARM_AARCH64_EL2_CONTEXT_REGISTERS) / sizeof(UINT64), ARM_AARCH64_EL2_REGISTER_NAMES);
+ //Get uniform register array.
+ EFI_ARM_AARCH64_EL2_CONTEXT_REGISTERS reg_array;
+ ir_to_uniform_struct64(registers, (UINT64 *)®_array,
+ sizeof(EFI_ARM_AARCH64_EL2_CONTEXT_REGISTERS) /
+ sizeof(UINT64),
+ ARM_AARCH64_EL2_REGISTER_NAMES);
- //Flush to stream.
- fwrite(®_array, sizeof(reg_array), 1, out);
- fflush(out);
+ //Flush to stream.
+ fwrite(®_array, sizeof(reg_array), 1, out);
+ fflush(out);
}
//Converts a single AARCH64 EL3 register set CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_aarch64_el3_to_cper(json_object* registers, FILE* out)
+void ir_arm_aarch64_el3_to_cper(json_object *registers, FILE *out)
{
- //Get uniform register array.
- EFI_ARM_AARCH64_EL3_CONTEXT_REGISTERS reg_array;
- ir_to_uniform_struct64(registers, (UINT64*)®_array,
- sizeof(EFI_ARM_AARCH64_EL3_CONTEXT_REGISTERS) / sizeof(UINT64), ARM_AARCH64_EL3_REGISTER_NAMES);
+ //Get uniform register array.
+ EFI_ARM_AARCH64_EL3_CONTEXT_REGISTERS reg_array;
+ ir_to_uniform_struct64(registers, (UINT64 *)®_array,
+ sizeof(EFI_ARM_AARCH64_EL3_CONTEXT_REGISTERS) /
+ sizeof(UINT64),
+ ARM_AARCH64_EL3_REGISTER_NAMES);
- //Flush to stream.
- fwrite(®_array, sizeof(reg_array), 1, out);
- fflush(out);
+ //Flush to stream.
+ fwrite(®_array, sizeof(reg_array), 1, out);
+ fflush(out);
}
//Converts a single ARM miscellaneous register set CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_misc_registers_to_cper(json_object* registers, FILE* out)
+void ir_arm_misc_registers_to_cper(json_object *registers, FILE *out)
{
- EFI_ARM_MISC_CONTEXT_REGISTER reg_array;
+ EFI_ARM_MISC_CONTEXT_REGISTER reg_array;
- //MRS encoding information.
- json_object* mrs_encoding = json_object_object_get(registers, "mrsEncoding");
- reg_array.MrsOp2 = json_object_get_uint64(json_object_object_get(mrs_encoding, "op2"));
- reg_array.MrsCrm = json_object_get_uint64(json_object_object_get(mrs_encoding, "crm"));
- reg_array.MrsCrn = json_object_get_uint64(json_object_object_get(mrs_encoding, "crn"));
- reg_array.MrsOp1 = json_object_get_uint64(json_object_object_get(mrs_encoding, "op1"));
- reg_array.MrsO0 = json_object_get_uint64(json_object_object_get(mrs_encoding, "o0"));
+ //MRS encoding information.
+ json_object *mrs_encoding =
+ json_object_object_get(registers, "mrsEncoding");
+ reg_array.MrsOp2 = json_object_get_uint64(
+ json_object_object_get(mrs_encoding, "op2"));
+ reg_array.MrsCrm = json_object_get_uint64(
+ json_object_object_get(mrs_encoding, "crm"));
+ reg_array.MrsCrn = json_object_get_uint64(
+ json_object_object_get(mrs_encoding, "crn"));
+ reg_array.MrsOp1 = json_object_get_uint64(
+ json_object_object_get(mrs_encoding, "op1"));
+ reg_array.MrsO0 = json_object_get_uint64(
+ json_object_object_get(mrs_encoding, "o0"));
- //Actual register value.
- reg_array.Value = json_object_get_uint64(json_object_object_get(registers, "value"));
+ //Actual register value.
+ reg_array.Value = json_object_get_uint64(
+ json_object_object_get(registers, "value"));
- //Flush to stream.
- fwrite(®_array, sizeof(reg_array), 1, out);
- fflush(out);
+ //Flush to stream.
+ fwrite(®_array, sizeof(reg_array), 1, out);
+ fflush(out);
}
//Converts a single ARM unknown register CPER-JSON object to CPER binary, outputting to the given stream.
-void ir_arm_unknown_register_to_cper(json_object* registers, EFI_ARM_CONTEXT_INFORMATION_HEADER* header, FILE* out)
+void ir_arm_unknown_register_to_cper(json_object *registers,
+ EFI_ARM_CONTEXT_INFORMATION_HEADER *header,
+ FILE *out)
{
- //Get base64 represented data.
- json_object* encoded = json_object_object_get(registers, "data");
- UINT8* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
+ //Get base64 represented data.
+ json_object *encoded = json_object_object_get(registers, "data");
+ UINT8 *decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
- //Flush out to stream.
- fwrite(&decoded, header->RegisterArraySize, 1, out);
- fflush(out);
- free(decoded);
+ //Flush out to stream.
+ fwrite(&decoded, header->RegisterArraySize, 1, out);
+ fflush(out);
+ free(decoded);
}
\ No newline at end of file
diff --git a/sections/cper-section-ccix-per.c b/sections/cper-section-ccix-per.c
index d295017..5beebea 100644
--- a/sections/cper-section-ccix-per.c
+++ b/sections/cper-section-ccix-per.c
@@ -13,64 +13,77 @@
#include "cper-section-ccix-per.h"
//Converts a single CCIX PER log CPER section into JSON IR.
-json_object* cper_section_ccix_per_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_ccix_per_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_CCIX_PER_LOG_DATA* ccix_error = (EFI_CCIX_PER_LOG_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_CCIX_PER_LOG_DATA *ccix_error = (EFI_CCIX_PER_LOG_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Length (bytes) for the entire structure.
- json_object_object_add(section_ir, "length", json_object_new_uint64(ccix_error->Length));
+ //Length (bytes) for the entire structure.
+ json_object_object_add(section_ir, "length",
+ json_object_new_uint64(ccix_error->Length));
- //Validation bits.
- json_object* validation = bitfield_to_ir(ccix_error->ValidBits, 3, CCIX_PER_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation = bitfield_to_ir(
+ ccix_error->ValidBits, 3, CCIX_PER_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_ir, "validationBits", validation);
- //CCIX source/port IDs.
- json_object_object_add(section_ir, "ccixSourceID", json_object_new_int(ccix_error->CcixSourceId));
- json_object_object_add(section_ir, "ccixPortID", json_object_new_int(ccix_error->CcixPortId));
-
- //CCIX PER Log.
- //This is formatted as described in Section 7.3.2 of CCIX Base Specification (Rev 1.0).
- unsigned char* cur_pos = (unsigned char*)(ccix_error + 1);
- int remaining_length = ccix_error->Length - sizeof(EFI_CCIX_PER_LOG_DATA);
- if (remaining_length > 0)
- {
- char* encoded = b64_encode(cur_pos, remaining_length);
- json_object_object_add(section_ir, "ccixPERLog", json_object_new_string(encoded));
- free(encoded);
- }
+ //CCIX source/port IDs.
+ json_object_object_add(section_ir, "ccixSourceID",
+ json_object_new_int(ccix_error->CcixSourceId));
+ json_object_object_add(section_ir, "ccixPortID",
+ json_object_new_int(ccix_error->CcixPortId));
- return section_ir;
+ //CCIX PER Log.
+ //This is formatted as described in Section 7.3.2 of CCIX Base Specification (Rev 1.0).
+ unsigned char *cur_pos = (unsigned char *)(ccix_error + 1);
+ int remaining_length =
+ ccix_error->Length - sizeof(EFI_CCIX_PER_LOG_DATA);
+ if (remaining_length > 0) {
+ char *encoded = b64_encode(cur_pos, remaining_length);
+ json_object_object_add(section_ir, "ccixPERLog",
+ json_object_new_string(encoded));
+ free(encoded);
+ }
+
+ return section_ir;
}
//Converts a single CCIX PER CPER-JSON section into CPER binary, outputting to the given stream.
-void ir_section_ccix_per_to_cper(json_object* section, FILE* out)
+void ir_section_ccix_per_to_cper(json_object *section, FILE *out)
{
- EFI_CCIX_PER_LOG_DATA* section_cper =
- (EFI_CCIX_PER_LOG_DATA*)calloc(1, sizeof(EFI_CCIX_PER_LOG_DATA));
+ EFI_CCIX_PER_LOG_DATA *section_cper = (EFI_CCIX_PER_LOG_DATA *)calloc(
+ 1, sizeof(EFI_CCIX_PER_LOG_DATA));
- //Length.
- section_cper->Length = json_object_get_uint64(json_object_object_get(section, "length"));
+ //Length.
+ section_cper->Length = json_object_get_uint64(
+ json_object_object_get(section, "length"));
- //Validation bits.
- section_cper->ValidBits = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 3, CCIX_PER_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ section_cper->ValidBits = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 3,
+ CCIX_PER_ERROR_VALID_BITFIELD_NAMES);
- //CCIX source/port IDs.
- section_cper->CcixSourceId = (UINT8)json_object_get_int(json_object_object_get(section, "ccixSourceID"));
- section_cper->CcixPortId = (UINT8)json_object_get_int(json_object_object_get(section, "ccixPortID"));
-
- //Write header out to stream.
- fwrite(section_cper, sizeof(EFI_CCIX_PER_LOG_DATA), 1, out);
- fflush(out);
+ //CCIX source/port IDs.
+ section_cper->CcixSourceId = (UINT8)json_object_get_int(
+ json_object_object_get(section, "ccixSourceID"));
+ section_cper->CcixPortId = (UINT8)json_object_get_int(
+ json_object_object_get(section, "ccixPortID"));
- //Write CCIX PER log itself to stream.
- json_object* encoded = json_object_object_get(section, "ccixPERLog");
- UINT8* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- fwrite(decoded, section_cper->Length - sizeof(EFI_CCIX_PER_LOG_DATA), 1, out);
- fflush(out);
+ //Write header out to stream.
+ fwrite(section_cper, sizeof(EFI_CCIX_PER_LOG_DATA), 1, out);
+ fflush(out);
- //Free resources.
- free(decoded);
- free(section_cper);
+ //Write CCIX PER log itself to stream.
+ json_object *encoded = json_object_object_get(section, "ccixPERLog");
+ UINT8 *decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ fwrite(decoded, section_cper->Length - sizeof(EFI_CCIX_PER_LOG_DATA), 1,
+ out);
+ fflush(out);
+
+ //Free resources.
+ free(decoded);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-cxl-component.c b/sections/cper-section-cxl-component.c
index 15454a2..a4a8dec 100644
--- a/sections/cper-section-cxl-component.c
+++ b/sections/cper-section-cxl-component.c
@@ -12,91 +12,122 @@
#include "cper-section-cxl-component.h"
//Converts a single CXL component error CPER section into JSON IR.
-json_object* cper_section_cxl_component_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_cxl_component_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_CXL_COMPONENT_EVENT_HEADER* cxl_error = (EFI_CXL_COMPONENT_EVENT_HEADER*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_CXL_COMPONENT_EVENT_HEADER *cxl_error =
+ (EFI_CXL_COMPONENT_EVENT_HEADER *)section;
+ json_object *section_ir = json_object_new_object();
- //Length (bytes) for the entire structure.
- json_object_object_add(section_ir, "length", json_object_new_uint64(cxl_error->Length));
-
- //Validation bits.
- json_object* validation = bitfield_to_ir(cxl_error->ValidBits, 3, CXL_COMPONENT_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ //Length (bytes) for the entire structure.
+ json_object_object_add(section_ir, "length",
+ json_object_new_uint64(cxl_error->Length));
- //Device ID.
- json_object* device_id = json_object_new_object();
- json_object_object_add(device_id, "vendorID", json_object_new_int(cxl_error->DeviceId.VendorId));
- json_object_object_add(device_id, "deviceID", json_object_new_int(cxl_error->DeviceId.DeviceId));
- json_object_object_add(device_id, "functionNumber", json_object_new_int(cxl_error->DeviceId.FunctionNumber));
- json_object_object_add(device_id, "deviceNumber", json_object_new_int(cxl_error->DeviceId.DeviceNumber));
- json_object_object_add(device_id, "busNumber", json_object_new_int(cxl_error->DeviceId.BusNumber));
- json_object_object_add(device_id, "segmentNumber", json_object_new_int(cxl_error->DeviceId.SegmentNumber));
- json_object_object_add(device_id, "slotNumber", json_object_new_int(cxl_error->DeviceId.SlotNumber));
- json_object_object_add(section_ir, "deviceID", device_id);
+ //Validation bits.
+ json_object *validation =
+ bitfield_to_ir(cxl_error->ValidBits, 3,
+ CXL_COMPONENT_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_ir, "validationBits", validation);
- //Device serial.
- json_object_object_add(section_ir, "deviceSerial", json_object_new_uint64(cxl_error->DeviceSerial));
+ //Device ID.
+ json_object *device_id = json_object_new_object();
+ json_object_object_add(
+ device_id, "vendorID",
+ json_object_new_int(cxl_error->DeviceId.VendorId));
+ json_object_object_add(
+ device_id, "deviceID",
+ json_object_new_int(cxl_error->DeviceId.DeviceId));
+ json_object_object_add(
+ device_id, "functionNumber",
+ json_object_new_int(cxl_error->DeviceId.FunctionNumber));
+ json_object_object_add(
+ device_id, "deviceNumber",
+ json_object_new_int(cxl_error->DeviceId.DeviceNumber));
+ json_object_object_add(
+ device_id, "busNumber",
+ json_object_new_int(cxl_error->DeviceId.BusNumber));
+ json_object_object_add(
+ device_id, "segmentNumber",
+ json_object_new_int(cxl_error->DeviceId.SegmentNumber));
+ json_object_object_add(
+ device_id, "slotNumber",
+ json_object_new_int(cxl_error->DeviceId.SlotNumber));
+ json_object_object_add(section_ir, "deviceID", device_id);
- //The specification for this is defined within the CXL Specification Section 8.2.9.1.
- unsigned char* cur_pos = (unsigned char*)(cxl_error + 1);
- int remaining_len = cxl_error->Length - sizeof(cxl_error);
- if (remaining_len > 0)
- {
- json_object* event_log = json_object_new_object();
- char* encoded = b64_encode(cur_pos, remaining_len);
- json_object_object_add(event_log, "data", json_object_new_string(encoded));
- free(encoded);
- json_object_object_add(section_ir, "cxlComponentEventLog", event_log);
- }
+ //Device serial.
+ json_object_object_add(section_ir, "deviceSerial",
+ json_object_new_uint64(cxl_error->DeviceSerial));
- return section_ir;
+ //The specification for this is defined within the CXL Specification Section 8.2.9.1.
+ unsigned char *cur_pos = (unsigned char *)(cxl_error + 1);
+ int remaining_len = cxl_error->Length - sizeof(cxl_error);
+ if (remaining_len > 0) {
+ json_object *event_log = json_object_new_object();
+ char *encoded = b64_encode(cur_pos, remaining_len);
+ json_object_object_add(event_log, "data",
+ json_object_new_string(encoded));
+ free(encoded);
+ json_object_object_add(section_ir, "cxlComponentEventLog",
+ event_log);
+ }
+
+ return section_ir;
}
//Converts a single given CXL Component CPER-JSON section into CPER binary, outputting to the
//given stream.
-void ir_section_cxl_component_to_cper(json_object* section, FILE* out)
+void ir_section_cxl_component_to_cper(json_object *section, FILE *out)
{
- EFI_CXL_COMPONENT_EVENT_HEADER* section_cper =
- (EFI_CXL_COMPONENT_EVENT_HEADER*)calloc(1, sizeof(EFI_CXL_COMPONENT_EVENT_HEADER));
+ EFI_CXL_COMPONENT_EVENT_HEADER *section_cper =
+ (EFI_CXL_COMPONENT_EVENT_HEADER *)calloc(
+ 1, sizeof(EFI_CXL_COMPONENT_EVENT_HEADER));
- //Length of the structure.
- section_cper->Length = json_object_get_uint64(json_object_object_get(section, "length"));
+ //Length of the structure.
+ section_cper->Length = json_object_get_uint64(
+ json_object_object_get(section, "length"));
- //Validation bits.
- section_cper->ValidBits = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 3, CXL_COMPONENT_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ section_cper->ValidBits = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 3,
+ CXL_COMPONENT_ERROR_VALID_BITFIELD_NAMES);
- //Device ID information.
- json_object* device_id = json_object_object_get(section, "deviceID");
- section_cper->DeviceId.VendorId = json_object_get_uint64(json_object_object_get(device_id, "vendorID"));
- section_cper->DeviceId.DeviceId = json_object_get_uint64(json_object_object_get(device_id, "deviceID"));
- section_cper->DeviceId.FunctionNumber =
- json_object_get_uint64(json_object_object_get(device_id, "functionNumber"));
- section_cper->DeviceId.DeviceNumber =
- json_object_get_uint64(json_object_object_get(device_id, "deviceNumber"));
- section_cper->DeviceId.BusNumber =
- json_object_get_uint64(json_object_object_get(device_id, "busNumber"));
- section_cper->DeviceId.SegmentNumber =
- json_object_get_uint64(json_object_object_get(device_id, "segmentNumber"));
- section_cper->DeviceId.SlotNumber =
- json_object_get_uint64(json_object_object_get(device_id, "slotNumber"));
+ //Device ID information.
+ json_object *device_id = json_object_object_get(section, "deviceID");
+ section_cper->DeviceId.VendorId = json_object_get_uint64(
+ json_object_object_get(device_id, "vendorID"));
+ section_cper->DeviceId.DeviceId = json_object_get_uint64(
+ json_object_object_get(device_id, "deviceID"));
+ section_cper->DeviceId.FunctionNumber = json_object_get_uint64(
+ json_object_object_get(device_id, "functionNumber"));
+ section_cper->DeviceId.DeviceNumber = json_object_get_uint64(
+ json_object_object_get(device_id, "deviceNumber"));
+ section_cper->DeviceId.BusNumber = json_object_get_uint64(
+ json_object_object_get(device_id, "busNumber"));
+ section_cper->DeviceId.SegmentNumber = json_object_get_uint64(
+ json_object_object_get(device_id, "segmentNumber"));
+ section_cper->DeviceId.SlotNumber = json_object_get_uint64(
+ json_object_object_get(device_id, "slotNumber"));
- //Device serial number.
- section_cper->DeviceSerial = json_object_get_uint64(json_object_object_get(section, "deviceSerial"));
+ //Device serial number.
+ section_cper->DeviceSerial = json_object_get_uint64(
+ json_object_object_get(section, "deviceSerial"));
- //Write header out to stream.
- fwrite(section_cper, sizeof(EFI_CXL_COMPONENT_EVENT_HEADER), 1, out);
- fflush(out);
+ //Write header out to stream.
+ fwrite(section_cper, sizeof(EFI_CXL_COMPONENT_EVENT_HEADER), 1, out);
+ fflush(out);
- //CXL component event log, decoded from base64.
- json_object* event_log = json_object_object_get(section, "cxlComponentEventLog");
- json_object* encoded = json_object_object_get(event_log, "data");
- int log_length = section_cper->Length - sizeof(EFI_CXL_COMPONENT_EVENT_HEADER);
- char* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- fwrite(decoded, log_length, 1, out);
- fflush(out);
- free(decoded);
+ //CXL component event log, decoded from base64.
+ json_object *event_log =
+ json_object_object_get(section, "cxlComponentEventLog");
+ json_object *encoded = json_object_object_get(event_log, "data");
+ int log_length =
+ section_cper->Length - sizeof(EFI_CXL_COMPONENT_EVENT_HEADER);
+ char *decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ fwrite(decoded, log_length, 1, out);
+ fflush(out);
+ free(decoded);
- free(section_cper);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-cxl-protocol.c b/sections/cper-section-cxl-protocol.c
index b3334a3..43c9dd0 100644
--- a/sections/cper-section-cxl-protocol.c
+++ b/sections/cper-section-cxl-protocol.c
@@ -13,172 +13,231 @@
#include "cper-section-cxl-protocol.h"
//Converts a single CXL protocol error CPER section into JSON IR.
-json_object* cper_section_cxl_protocol_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_cxl_protocol_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_CXL_PROTOCOL_ERROR_DATA* cxl_protocol_error = (EFI_CXL_PROTOCOL_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_CXL_PROTOCOL_ERROR_DATA *cxl_protocol_error =
+ (EFI_CXL_PROTOCOL_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Validation bits.
- json_object* validation = bitfield_to_ir(cxl_protocol_error->ValidBits, 7, CXL_PROTOCOL_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation =
+ bitfield_to_ir(cxl_protocol_error->ValidBits, 7,
+ CXL_PROTOCOL_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_ir, "validationBits", validation);
- //Type of detecting agent.
- json_object* agent_type = integer_to_readable_pair(cxl_protocol_error->CxlAgentType, 2,
- CXL_PROTOCOL_ERROR_AGENT_TYPES_KEYS,
- CXL_PROTOCOL_ERROR_AGENT_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(section_ir, "agentType", agent_type);
+ //Type of detecting agent.
+ json_object *agent_type = integer_to_readable_pair(
+ cxl_protocol_error->CxlAgentType, 2,
+ CXL_PROTOCOL_ERROR_AGENT_TYPES_KEYS,
+ CXL_PROTOCOL_ERROR_AGENT_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(section_ir, "agentType", agent_type);
- //CXL agent address, depending on the agent type.
- json_object* agent_address = json_object_new_object();
- if (cxl_protocol_error->CxlAgentType == CXL_PROTOCOL_ERROR_DEVICE_AGENT)
- {
- //Address is a CXL1.1 device agent.
- json_object_object_add(agent_address, "functionNumber",
- json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.DeviceAddress.FunctionNumber));
- json_object_object_add(agent_address, "deviceNumber",
- json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.DeviceAddress.DeviceNumber));
- json_object_object_add(agent_address, "busNumber",
- json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.DeviceAddress.BusNumber));
- json_object_object_add(agent_address, "segmentNumber",
- json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.DeviceAddress.SegmentNumber));
- }
- else if (cxl_protocol_error->CxlAgentType == CXL_PROTOCOL_ERROR_HOST_DOWNSTREAM_PORT_AGENT)
- {
- //Address is a CXL port RCRB base address.
- json_object_object_add(agent_address, "value",
- json_object_new_uint64(cxl_protocol_error->CxlAgentAddress.PortRcrbBaseAddress));
- }
- json_object_object_add(section_ir, "cxlAgentAddress", agent_address);
+ //CXL agent address, depending on the agent type.
+ json_object *agent_address = json_object_new_object();
+ if (cxl_protocol_error->CxlAgentType ==
+ CXL_PROTOCOL_ERROR_DEVICE_AGENT) {
+ //Address is a CXL1.1 device agent.
+ json_object_object_add(
+ agent_address, "functionNumber",
+ json_object_new_uint64(
+ cxl_protocol_error->CxlAgentAddress
+ .DeviceAddress.FunctionNumber));
+ json_object_object_add(
+ agent_address, "deviceNumber",
+ json_object_new_uint64(
+ cxl_protocol_error->CxlAgentAddress
+ .DeviceAddress.DeviceNumber));
+ json_object_object_add(
+ agent_address, "busNumber",
+ json_object_new_uint64(
+ cxl_protocol_error->CxlAgentAddress
+ .DeviceAddress.BusNumber));
+ json_object_object_add(
+ agent_address, "segmentNumber",
+ json_object_new_uint64(
+ cxl_protocol_error->CxlAgentAddress
+ .DeviceAddress.SegmentNumber));
+ } else if (cxl_protocol_error->CxlAgentType ==
+ CXL_PROTOCOL_ERROR_HOST_DOWNSTREAM_PORT_AGENT) {
+ //Address is a CXL port RCRB base address.
+ json_object_object_add(
+ agent_address, "value",
+ json_object_new_uint64(
+ cxl_protocol_error->CxlAgentAddress
+ .PortRcrbBaseAddress));
+ }
+ json_object_object_add(section_ir, "cxlAgentAddress", agent_address);
- //Device ID.
- json_object* device_id = json_object_new_object();
- json_object_object_add(device_id, "vendorID",
- json_object_new_uint64(cxl_protocol_error->DeviceId.VendorId));
- json_object_object_add(device_id, "deviceID",
- json_object_new_uint64(cxl_protocol_error->DeviceId.DeviceId));
- json_object_object_add(device_id, "subsystemVendorID",
- json_object_new_uint64(cxl_protocol_error->DeviceId.SubsystemVendorId));
- json_object_object_add(device_id, "subsystemDeviceID",
- json_object_new_uint64(cxl_protocol_error->DeviceId.SubsystemDeviceId));
- json_object_object_add(device_id, "classCode",
- json_object_new_uint64(cxl_protocol_error->DeviceId.ClassCode));
- json_object_object_add(device_id, "slotNumber",
- json_object_new_uint64(cxl_protocol_error->DeviceId.SlotNumber));
- json_object_object_add(section_ir, "deviceID", device_id);
+ //Device ID.
+ json_object *device_id = json_object_new_object();
+ json_object_object_add(
+ device_id, "vendorID",
+ json_object_new_uint64(cxl_protocol_error->DeviceId.VendorId));
+ json_object_object_add(
+ device_id, "deviceID",
+ json_object_new_uint64(cxl_protocol_error->DeviceId.DeviceId));
+ json_object_object_add(
+ device_id, "subsystemVendorID",
+ json_object_new_uint64(
+ cxl_protocol_error->DeviceId.SubsystemVendorId));
+ json_object_object_add(
+ device_id, "subsystemDeviceID",
+ json_object_new_uint64(
+ cxl_protocol_error->DeviceId.SubsystemDeviceId));
+ json_object_object_add(
+ device_id, "classCode",
+ json_object_new_uint64(cxl_protocol_error->DeviceId.ClassCode));
+ json_object_object_add(
+ device_id, "slotNumber",
+ json_object_new_uint64(
+ cxl_protocol_error->DeviceId.SlotNumber));
+ json_object_object_add(section_ir, "deviceID", device_id);
- //Device serial & capability structure (if CXL 1.1 device).
- if (cxl_protocol_error->CxlAgentType == CXL_PROTOCOL_ERROR_DEVICE_AGENT)
- {
- json_object_object_add(section_ir, "deviceSerial", json_object_new_uint64(cxl_protocol_error->DeviceSerial));
+ //Device serial & capability structure (if CXL 1.1 device).
+ if (cxl_protocol_error->CxlAgentType ==
+ CXL_PROTOCOL_ERROR_DEVICE_AGENT) {
+ json_object_object_add(
+ section_ir, "deviceSerial",
+ json_object_new_uint64(
+ cxl_protocol_error->DeviceSerial));
- //The PCIe capability structure provided here could either be PCIe 1.1 Capability Structure
- //(36-byte, padded to 60 bytes) or PCIe 2.0 Capability Structure (60-byte). There does not seem
- //to be a way to differentiate these, so this is left as a b64 dump.
- char* encoded = b64_encode(cxl_protocol_error->CapabilityStructure.PcieCap, 60);
- json_object_object_add(section_ir, "capabilityStructure", json_object_new_string(encoded));
- free(encoded);
- }
+ //The PCIe capability structure provided here could either be PCIe 1.1 Capability Structure
+ //(36-byte, padded to 60 bytes) or PCIe 2.0 Capability Structure (60-byte). There does not seem
+ //to be a way to differentiate these, so this is left as a b64 dump.
+ char *encoded = b64_encode(
+ cxl_protocol_error->CapabilityStructure.PcieCap, 60);
+ json_object_object_add(section_ir, "capabilityStructure",
+ json_object_new_string(encoded));
+ free(encoded);
+ }
- //CXL DVSEC & error log length.
- json_object_object_add(section_ir, "dvsecLength", json_object_new_int(cxl_protocol_error->CxlDvsecLength));
- json_object_object_add(section_ir, "errorLogLength", json_object_new_int(cxl_protocol_error->CxlErrorLogLength));
+ //CXL DVSEC & error log length.
+ json_object_object_add(
+ section_ir, "dvsecLength",
+ json_object_new_int(cxl_protocol_error->CxlDvsecLength));
+ json_object_object_add(
+ section_ir, "errorLogLength",
+ json_object_new_int(cxl_protocol_error->CxlErrorLogLength));
- //CXL DVSEC
- //For CXL 1.1 devices, this is the "CXL DVSEC For Flex Bus Device" structure as in CXL 1.1 spec.
- //For CXL 1.1 host downstream ports, this is the "CXL DVSEC For Flex Bus Port" structure as in CXL 1.1 spec.
- unsigned char* cur_pos = (unsigned char*)(cxl_protocol_error + 1);
- char* encoded = b64_encode(cur_pos, cxl_protocol_error->CxlDvsecLength);
- json_object_object_add(section_ir, "cxlDVSEC", json_object_new_string(encoded));
- free(encoded);
- cur_pos += cxl_protocol_error->CxlDvsecLength;
+ //CXL DVSEC
+ //For CXL 1.1 devices, this is the "CXL DVSEC For Flex Bus Device" structure as in CXL 1.1 spec.
+ //For CXL 1.1 host downstream ports, this is the "CXL DVSEC For Flex Bus Port" structure as in CXL 1.1 spec.
+ unsigned char *cur_pos = (unsigned char *)(cxl_protocol_error + 1);
+ char *encoded = b64_encode(cur_pos, cxl_protocol_error->CxlDvsecLength);
+ json_object_object_add(section_ir, "cxlDVSEC",
+ json_object_new_string(encoded));
+ free(encoded);
+ cur_pos += cxl_protocol_error->CxlDvsecLength;
- //CXL Error Log
- //This is the "CXL RAS Capability Structure" as in CXL 1.1 spec.
- encoded = b64_encode(cur_pos, cxl_protocol_error->CxlErrorLogLength);
- json_object_object_add(section_ir, "cxlErrorLog", json_object_new_string(encoded));
- free(encoded);
-
- return section_ir;
+ //CXL Error Log
+ //This is the "CXL RAS Capability Structure" as in CXL 1.1 spec.
+ encoded = b64_encode(cur_pos, cxl_protocol_error->CxlErrorLogLength);
+ json_object_object_add(section_ir, "cxlErrorLog",
+ json_object_new_string(encoded));
+ free(encoded);
+
+ return section_ir;
}
//Converts a single CXL protocol CPER-JSON section into CPER binary, outputting to the given stream.
-void ir_section_cxl_protocol_to_cper(json_object* section, FILE* out)
+void ir_section_cxl_protocol_to_cper(json_object *section, FILE *out)
{
- EFI_CXL_PROTOCOL_ERROR_DATA* section_cper =
- (EFI_CXL_PROTOCOL_ERROR_DATA*)calloc(1, sizeof(EFI_CXL_PROTOCOL_ERROR_DATA));
-
- //Validation bits.
- section_cper->ValidBits = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 7, CXL_PROTOCOL_ERROR_VALID_BITFIELD_NAMES);
+ EFI_CXL_PROTOCOL_ERROR_DATA *section_cper =
+ (EFI_CXL_PROTOCOL_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_CXL_PROTOCOL_ERROR_DATA));
- //Detecting agent type.
- section_cper->CxlAgentType = readable_pair_to_integer(json_object_object_get(section, "agentType"));
+ //Validation bits.
+ section_cper->ValidBits = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 7,
+ CXL_PROTOCOL_ERROR_VALID_BITFIELD_NAMES);
- //Based on the agent type, set the address.
- json_object* address = json_object_object_get(section, "cxlAgentAddress");
- if (section_cper->CxlAgentType == CXL_PROTOCOL_ERROR_DEVICE_AGENT)
- {
- //Address is split by function, device, bus & segment.
- UINT64 function = json_object_get_uint64(json_object_object_get(address, "functionNumber"));
- UINT64 device = json_object_get_uint64(json_object_object_get(address, "deviceNumber"));
- UINT64 bus = json_object_get_uint64(json_object_object_get(address, "busNumber"));
- UINT64 segment = json_object_get_uint64(json_object_object_get(address, "segmentNumber"));
- section_cper->CxlAgentAddress.DeviceAddress.FunctionNumber = function;
- section_cper->CxlAgentAddress.DeviceAddress.DeviceNumber = device;
- section_cper->CxlAgentAddress.DeviceAddress.BusNumber = bus;
- section_cper->CxlAgentAddress.DeviceAddress.SegmentNumber = segment;
- }
- else if (section_cper->CxlAgentType == CXL_PROTOCOL_ERROR_HOST_DOWNSTREAM_PORT_AGENT)
- {
- //Plain RCRB base address.
- section_cper->CxlAgentAddress.PortRcrbBaseAddress =
- json_object_get_uint64(json_object_object_get(address, "value"));
- }
+ //Detecting agent type.
+ section_cper->CxlAgentType = readable_pair_to_integer(
+ json_object_object_get(section, "agentType"));
- //Device ID information.
- json_object* device_id = json_object_object_get(section, "deviceID");
- section_cper->DeviceId.VendorId = json_object_get_uint64(json_object_object_get(device_id, "vendorID"));
- section_cper->DeviceId.DeviceId = json_object_get_uint64(json_object_object_get(device_id, "deviceID"));
- section_cper->DeviceId.SubsystemVendorId =
- json_object_get_uint64(json_object_object_get(device_id, "subsystemVendorID"));
- section_cper->DeviceId.SubsystemDeviceId =
- json_object_get_uint64(json_object_object_get(device_id, "subsystemDeviceID"));
- section_cper->DeviceId.ClassCode = json_object_get_uint64(json_object_object_get(device_id, "classCode"));
- section_cper->DeviceId.SlotNumber = json_object_get_uint64(json_object_object_get(device_id, "slotNumber"));
+ //Based on the agent type, set the address.
+ json_object *address =
+ json_object_object_get(section, "cxlAgentAddress");
+ if (section_cper->CxlAgentType == CXL_PROTOCOL_ERROR_DEVICE_AGENT) {
+ //Address is split by function, device, bus & segment.
+ UINT64 function = json_object_get_uint64(
+ json_object_object_get(address, "functionNumber"));
+ UINT64 device = json_object_get_uint64(
+ json_object_object_get(address, "deviceNumber"));
+ UINT64 bus = json_object_get_uint64(
+ json_object_object_get(address, "busNumber"));
+ UINT64 segment = json_object_get_uint64(
+ json_object_object_get(address, "segmentNumber"));
+ section_cper->CxlAgentAddress.DeviceAddress.FunctionNumber =
+ function;
+ section_cper->CxlAgentAddress.DeviceAddress.DeviceNumber =
+ device;
+ section_cper->CxlAgentAddress.DeviceAddress.BusNumber = bus;
+ section_cper->CxlAgentAddress.DeviceAddress.SegmentNumber =
+ segment;
+ } else if (section_cper->CxlAgentType ==
+ CXL_PROTOCOL_ERROR_HOST_DOWNSTREAM_PORT_AGENT) {
+ //Plain RCRB base address.
+ section_cper->CxlAgentAddress.PortRcrbBaseAddress =
+ json_object_get_uint64(
+ json_object_object_get(address, "value"));
+ }
- //If CXL 1.1 device, the serial number & PCI capability structure.
- if (section_cper->CxlAgentType == CXL_PROTOCOL_ERROR_DEVICE_AGENT)
- {
- section_cper->DeviceSerial = json_object_get_uint64(json_object_object_get(section, "deviceSerial"));
+ //Device ID information.
+ json_object *device_id = json_object_object_get(section, "deviceID");
+ section_cper->DeviceId.VendorId = json_object_get_uint64(
+ json_object_object_get(device_id, "vendorID"));
+ section_cper->DeviceId.DeviceId = json_object_get_uint64(
+ json_object_object_get(device_id, "deviceID"));
+ section_cper->DeviceId.SubsystemVendorId = json_object_get_uint64(
+ json_object_object_get(device_id, "subsystemVendorID"));
+ section_cper->DeviceId.SubsystemDeviceId = json_object_get_uint64(
+ json_object_object_get(device_id, "subsystemDeviceID"));
+ section_cper->DeviceId.ClassCode = json_object_get_uint64(
+ json_object_object_get(device_id, "classCode"));
+ section_cper->DeviceId.SlotNumber = json_object_get_uint64(
+ json_object_object_get(device_id, "slotNumber"));
- json_object* encoded = json_object_object_get(section, "capabilityStructure");
- char* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- memcpy(section_cper->CapabilityStructure.PcieCap, decoded, 60);
- free(decoded);
- }
+ //If CXL 1.1 device, the serial number & PCI capability structure.
+ if (section_cper->CxlAgentType == CXL_PROTOCOL_ERROR_DEVICE_AGENT) {
+ section_cper->DeviceSerial = json_object_get_uint64(
+ json_object_object_get(section, "deviceSerial"));
- //DVSEC length & error log length.
- section_cper->CxlDvsecLength = (UINT16)json_object_get_int(json_object_object_get(section, "dvsecLength"));
- section_cper->CxlErrorLogLength = (UINT16)json_object_get_int(json_object_object_get(section, "errorLogLength"));
+ json_object *encoded =
+ json_object_object_get(section, "capabilityStructure");
+ char *decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ memcpy(section_cper->CapabilityStructure.PcieCap, decoded, 60);
+ free(decoded);
+ }
- //Write header to stream.
- fwrite(section_cper, sizeof(EFI_CXL_PROTOCOL_ERROR_DATA), 1, out);
- fflush(out);
+ //DVSEC length & error log length.
+ section_cper->CxlDvsecLength = (UINT16)json_object_get_int(
+ json_object_object_get(section, "dvsecLength"));
+ section_cper->CxlErrorLogLength = (UINT16)json_object_get_int(
+ json_object_object_get(section, "errorLogLength"));
- //DVSEC out to stream.
- json_object* encoded = json_object_object_get(section, "cxlDVSEC");
- char* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- fwrite(decoded, section_cper->CxlDvsecLength, 1, out);
- fflush(out);
- free(decoded);
+ //Write header to stream.
+ fwrite(section_cper, sizeof(EFI_CXL_PROTOCOL_ERROR_DATA), 1, out);
+ fflush(out);
- //Error log out to stream.
- encoded = json_object_object_get(section, "cxlErrorLog");
- decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- fwrite(decoded, section_cper->CxlErrorLogLength, 1, out);
- fflush(out);
- free(decoded);
+ //DVSEC out to stream.
+ json_object *encoded = json_object_object_get(section, "cxlDVSEC");
+ char *decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ fwrite(decoded, section_cper->CxlDvsecLength, 1, out);
+ fflush(out);
+ free(decoded);
- free(section_cper);
+ //Error log out to stream.
+ encoded = json_object_object_get(section, "cxlErrorLog");
+ decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ fwrite(decoded, section_cper->CxlErrorLogLength, 1, out);
+ fflush(out);
+ free(decoded);
+
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-dmar-generic.c b/sections/cper-section-dmar-generic.c
index faeefa8..420dd8d 100644
--- a/sections/cper-section-dmar-generic.c
+++ b/sections/cper-section-dmar-generic.c
@@ -11,67 +11,84 @@
#include "cper-section-dmar-generic.h"
//Converts a single generic DMAr CPER section into JSON IR.
-json_object* cper_section_dmar_generic_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_dmar_generic_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_DMAR_GENERIC_ERROR_DATA* firmware_error = (EFI_DMAR_GENERIC_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_DMAR_GENERIC_ERROR_DATA *firmware_error =
+ (EFI_DMAR_GENERIC_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Requester ID, segment.
- json_object_object_add(section_ir, "requesterID", json_object_new_int(firmware_error->RequesterId));
- json_object_object_add(section_ir, "segmentNumber", json_object_new_int(firmware_error->SegmentNumber));
+ //Requester ID, segment.
+ json_object_object_add(
+ section_ir, "requesterID",
+ json_object_new_int(firmware_error->RequesterId));
+ json_object_object_add(
+ section_ir, "segmentNumber",
+ json_object_new_int(firmware_error->SegmentNumber));
- //Fault reason.
- json_object* fault_reason = integer_to_readable_pair_with_desc(firmware_error->FaultReason, 11,
- DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_KEYS,
- DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_VALUES,
- DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_DESCRIPTIONS,
- "Unknown (Reserved)");
- json_object_object_add(section_ir, "faultReason", fault_reason);
+ //Fault reason.
+ json_object *fault_reason = integer_to_readable_pair_with_desc(
+ firmware_error->FaultReason, 11,
+ DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_KEYS,
+ DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_VALUES,
+ DMAR_GENERIC_ERROR_FAULT_REASON_TYPES_DESCRIPTIONS,
+ "Unknown (Reserved)");
+ json_object_object_add(section_ir, "faultReason", fault_reason);
- //Access type.
- json_object* access_type = integer_to_readable_pair(firmware_error->AccessType, 2,
- DMAR_GENERIC_ERROR_ACCESS_TYPES_KEYS,
- DMAR_GENERIC_ERROR_ACCESS_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(section_ir, "accessType", access_type);
+ //Access type.
+ json_object *access_type = integer_to_readable_pair(
+ firmware_error->AccessType, 2,
+ DMAR_GENERIC_ERROR_ACCESS_TYPES_KEYS,
+ DMAR_GENERIC_ERROR_ACCESS_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(section_ir, "accessType", access_type);
- //Address type.
- json_object* address_type = integer_to_readable_pair(firmware_error->AddressType, 2,
- DMAR_GENERIC_ERROR_ADDRESS_TYPES_KEYS,
- DMAR_GENERIC_ERROR_ADDRESS_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(section_ir, "addressType", address_type);
+ //Address type.
+ json_object *address_type = integer_to_readable_pair(
+ firmware_error->AddressType, 2,
+ DMAR_GENERIC_ERROR_ADDRESS_TYPES_KEYS,
+ DMAR_GENERIC_ERROR_ADDRESS_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(section_ir, "addressType", address_type);
- //Architecture type.
- json_object* arch_type = integer_to_readable_pair(firmware_error->ArchType, 2,
- DMAR_GENERIC_ERROR_ARCH_TYPES_KEYS,
- DMAR_GENERIC_ERROR_ARCH_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(section_ir, "architectureType", arch_type);
+ //Architecture type.
+ json_object *arch_type = integer_to_readable_pair(
+ firmware_error->ArchType, 2, DMAR_GENERIC_ERROR_ARCH_TYPES_KEYS,
+ DMAR_GENERIC_ERROR_ARCH_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(section_ir, "architectureType", arch_type);
- //Device address.
- json_object_object_add(section_ir, "deviceAddress", json_object_new_uint64(firmware_error->DeviceAddr));
-
- return section_ir;
+ //Device address.
+ json_object_object_add(
+ section_ir, "deviceAddress",
+ json_object_new_uint64(firmware_error->DeviceAddr));
+
+ return section_ir;
}
//Converts a single generic DMAR CPER-JSON section into CPER binary, outputting to the given stream.
-void ir_section_dmar_generic_to_cper(json_object* section, FILE* out)
+void ir_section_dmar_generic_to_cper(json_object *section, FILE *out)
{
- EFI_DMAR_GENERIC_ERROR_DATA* section_cper =
- (EFI_DMAR_GENERIC_ERROR_DATA*)calloc(1, sizeof(EFI_DMAR_GENERIC_ERROR_DATA));
+ EFI_DMAR_GENERIC_ERROR_DATA *section_cper =
+ (EFI_DMAR_GENERIC_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_DMAR_GENERIC_ERROR_DATA));
- //Record fields.
- section_cper->RequesterId = (UINT16)json_object_get_int(json_object_object_get(section, "requesterID"));
- section_cper->SegmentNumber = (UINT16)json_object_get_int(json_object_object_get(section, "segmentNumber"));
- section_cper->FaultReason = (UINT8)readable_pair_to_integer(json_object_object_get(section, "faultReason"));
- section_cper->AccessType = (UINT8)readable_pair_to_integer(json_object_object_get(section, "accessType"));
- section_cper->AddressType = (UINT8)readable_pair_to_integer(json_object_object_get(section, "addressType"));
- section_cper->ArchType = (UINT8)readable_pair_to_integer(json_object_object_get(section, "architectureType"));
- section_cper->DeviceAddr = json_object_get_uint64(json_object_object_get(section, "deviceAddress"));
+ //Record fields.
+ section_cper->RequesterId = (UINT16)json_object_get_int(
+ json_object_object_get(section, "requesterID"));
+ section_cper->SegmentNumber = (UINT16)json_object_get_int(
+ json_object_object_get(section, "segmentNumber"));
+ section_cper->FaultReason = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "faultReason"));
+ section_cper->AccessType = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "accessType"));
+ section_cper->AddressType = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "addressType"));
+ section_cper->ArchType = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "architectureType"));
+ section_cper->DeviceAddr = json_object_get_uint64(
+ json_object_object_get(section, "deviceAddress"));
- //Write to stream, free resources.
- fwrite(section_cper, sizeof(EFI_DMAR_GENERIC_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //Write to stream, free resources.
+ fwrite(section_cper, sizeof(EFI_DMAR_GENERIC_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-dmar-iommu.c b/sections/cper-section-dmar-iommu.c
index 2861053..0c8df4a 100644
--- a/sections/cper-section-dmar-iommu.c
+++ b/sections/cper-section-dmar-iommu.c
@@ -13,73 +13,101 @@
#include "cper-section-dmar-iommu.h"
//Converts a single IOMMU specific DMAr CPER section into JSON IR.
-json_object* cper_section_dmar_iommu_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_dmar_iommu_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_IOMMU_DMAR_ERROR_DATA* iommu_error = (EFI_IOMMU_DMAR_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_IOMMU_DMAR_ERROR_DATA *iommu_error =
+ (EFI_IOMMU_DMAR_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Revision.
- json_object_object_add(section_ir, "revision", json_object_new_int(iommu_error->Revision));
+ //Revision.
+ json_object_object_add(section_ir, "revision",
+ json_object_new_int(iommu_error->Revision));
- //IOMMU registers.
- json_object_object_add(section_ir, "controlRegister", json_object_new_uint64(iommu_error->Control));
- json_object_object_add(section_ir, "statusRegister", json_object_new_uint64(iommu_error->Status));
+ //IOMMU registers.
+ json_object_object_add(section_ir, "controlRegister",
+ json_object_new_uint64(iommu_error->Control));
+ json_object_object_add(section_ir, "statusRegister",
+ json_object_new_uint64(iommu_error->Status));
- //IOMMU event log entry.
- //The format of these entries differ widely by the type of error.
- char* encoded = b64_encode((unsigned char*)iommu_error->EventLogEntry, 16);
- json_object_object_add(section_ir, "eventLogEntry", json_object_new_string(encoded));
- free(encoded);
+ //IOMMU event log entry.
+ //The format of these entries differ widely by the type of error.
+ char *encoded =
+ b64_encode((unsigned char *)iommu_error->EventLogEntry, 16);
+ json_object_object_add(section_ir, "eventLogEntry",
+ json_object_new_string(encoded));
+ free(encoded);
- //Device table entry (as base64).
- encoded = b64_encode((unsigned char*)iommu_error->DeviceTableEntry, 32);
- json_object_object_add(section_ir, "deviceTableEntry", json_object_new_string(encoded));
- free(encoded);
+ //Device table entry (as base64).
+ encoded =
+ b64_encode((unsigned char *)iommu_error->DeviceTableEntry, 32);
+ json_object_object_add(section_ir, "deviceTableEntry",
+ json_object_new_string(encoded));
+ free(encoded);
- //Page table entries.
- json_object_object_add(section_ir, "pageTableEntry_Level6", json_object_new_uint64(iommu_error->PteL6));
- json_object_object_add(section_ir, "pageTableEntry_Level5", json_object_new_uint64(iommu_error->PteL5));
- json_object_object_add(section_ir, "pageTableEntry_Level4", json_object_new_uint64(iommu_error->PteL4));
- json_object_object_add(section_ir, "pageTableEntry_Level3", json_object_new_uint64(iommu_error->PteL3));
- json_object_object_add(section_ir, "pageTableEntry_Level2", json_object_new_uint64(iommu_error->PteL2));
- json_object_object_add(section_ir, "pageTableEntry_Level1", json_object_new_uint64(iommu_error->PteL1));
+ //Page table entries.
+ json_object_object_add(section_ir, "pageTableEntry_Level6",
+ json_object_new_uint64(iommu_error->PteL6));
+ json_object_object_add(section_ir, "pageTableEntry_Level5",
+ json_object_new_uint64(iommu_error->PteL5));
+ json_object_object_add(section_ir, "pageTableEntry_Level4",
+ json_object_new_uint64(iommu_error->PteL4));
+ json_object_object_add(section_ir, "pageTableEntry_Level3",
+ json_object_new_uint64(iommu_error->PteL3));
+ json_object_object_add(section_ir, "pageTableEntry_Level2",
+ json_object_new_uint64(iommu_error->PteL2));
+ json_object_object_add(section_ir, "pageTableEntry_Level1",
+ json_object_new_uint64(iommu_error->PteL1));
- return section_ir;
+ return section_ir;
}
//Converts a single DMAR IOMMU CPER-JSON section into CPER binary, outputting to the given stream.
-void ir_section_dmar_iommu_to_cper(json_object* section, FILE* out)
+void ir_section_dmar_iommu_to_cper(json_object *section, FILE *out)
{
- EFI_IOMMU_DMAR_ERROR_DATA* section_cper =
- (EFI_IOMMU_DMAR_ERROR_DATA*)calloc(1, sizeof(EFI_IOMMU_DMAR_ERROR_DATA));
+ EFI_IOMMU_DMAR_ERROR_DATA *section_cper =
+ (EFI_IOMMU_DMAR_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_IOMMU_DMAR_ERROR_DATA));
- //Revision, registers.
- section_cper->Revision = (UINT8)json_object_get_int(json_object_object_get(section, "revision"));
- section_cper->Control = json_object_get_uint64(json_object_object_get(section, "controlRegister"));
- section_cper->Status = json_object_get_uint64(json_object_object_get(section, "statusRegister"));
+ //Revision, registers.
+ section_cper->Revision = (UINT8)json_object_get_int(
+ json_object_object_get(section, "revision"));
+ section_cper->Control = json_object_get_uint64(
+ json_object_object_get(section, "controlRegister"));
+ section_cper->Status = json_object_get_uint64(
+ json_object_object_get(section, "statusRegister"));
- //IOMMU event log entry.
- json_object* encoded = json_object_object_get(section, "eventLogEntry");
- UINT8* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- memcpy(section_cper->EventLogEntry, decoded, 16);
- free(decoded);
+ //IOMMU event log entry.
+ json_object *encoded = json_object_object_get(section, "eventLogEntry");
+ UINT8 *decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ memcpy(section_cper->EventLogEntry, decoded, 16);
+ free(decoded);
- //Device table entry.
- encoded = json_object_object_get(section, "deviceTableEntry");
- decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- memcpy(section_cper->DeviceTableEntry, decoded, 32);
- free(decoded);
+ //Device table entry.
+ encoded = json_object_object_get(section, "deviceTableEntry");
+ decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ memcpy(section_cper->DeviceTableEntry, decoded, 32);
+ free(decoded);
- //Page table entries.
- section_cper->PteL1 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level1"));
- section_cper->PteL2 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level2"));
- section_cper->PteL3 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level3"));
- section_cper->PteL4 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level4"));
- section_cper->PteL5 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level5"));
- section_cper->PteL6 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level6"));
+ //Page table entries.
+ section_cper->PteL1 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level1"));
+ section_cper->PteL2 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level2"));
+ section_cper->PteL3 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level3"));
+ section_cper->PteL4 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level4"));
+ section_cper->PteL5 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level5"));
+ section_cper->PteL6 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level6"));
- //Write to stream, free resources.
- fwrite(section_cper, sizeof(EFI_IOMMU_DMAR_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //Write to stream, free resources.
+ fwrite(section_cper, sizeof(EFI_IOMMU_DMAR_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-dmar-vtd.c b/sections/cper-section-dmar-vtd.c
index cfaace7..73fb2fc 100644
--- a/sections/cper-section-dmar-vtd.c
+++ b/sections/cper-section-dmar-vtd.c
@@ -13,133 +13,188 @@
#include "cper-section-dmar-vtd.h"
//Converts a single VT-d specific DMAr CPER section into JSON IR.
-json_object* cper_section_dmar_vtd_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_dmar_vtd_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_DIRECTED_IO_DMAR_ERROR_DATA* vtd_error = (EFI_DIRECTED_IO_DMAR_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_DIRECTED_IO_DMAR_ERROR_DATA *vtd_error =
+ (EFI_DIRECTED_IO_DMAR_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Version, revision and OEM ID, as defined in the VT-d architecture.
- UINT64 oem_id = 0;
- for (int i=0; i<6; i++)
- oem_id |= (UINT64)vtd_error->OemId[i] << (i * 8);
- json_object_object_add(section_ir, "version", json_object_new_int(vtd_error->Version));
- json_object_object_add(section_ir, "revision", json_object_new_int(vtd_error->Revision));
- json_object_object_add(section_ir, "oemID", json_object_new_uint64(oem_id));
+ //Version, revision and OEM ID, as defined in the VT-d architecture.
+ UINT64 oem_id = 0;
+ for (int i = 0; i < 6; i++)
+ oem_id |= (UINT64)vtd_error->OemId[i] << (i * 8);
+ json_object_object_add(section_ir, "version",
+ json_object_new_int(vtd_error->Version));
+ json_object_object_add(section_ir, "revision",
+ json_object_new_int(vtd_error->Revision));
+ json_object_object_add(section_ir, "oemID",
+ json_object_new_uint64(oem_id));
- //Registers.
- json_object_object_add(section_ir, "capabilityRegister", json_object_new_uint64(vtd_error->Capability));
- json_object_object_add(section_ir, "extendedCapabilityRegister", json_object_new_uint64(vtd_error->CapabilityEx));
- json_object_object_add(section_ir, "globalCommandRegister", json_object_new_uint64(vtd_error->GlobalCommand));
- json_object_object_add(section_ir, "globalStatusRegister", json_object_new_uint64(vtd_error->GlobalStatus));
- json_object_object_add(section_ir, "faultStatusRegister", json_object_new_uint64(vtd_error->FaultStatus));
+ //Registers.
+ json_object_object_add(section_ir, "capabilityRegister",
+ json_object_new_uint64(vtd_error->Capability));
+ json_object_object_add(section_ir, "extendedCapabilityRegister",
+ json_object_new_uint64(vtd_error->CapabilityEx));
+ json_object_object_add(
+ section_ir, "globalCommandRegister",
+ json_object_new_uint64(vtd_error->GlobalCommand));
+ json_object_object_add(section_ir, "globalStatusRegister",
+ json_object_new_uint64(vtd_error->GlobalStatus));
+ json_object_object_add(section_ir, "faultStatusRegister",
+ json_object_new_uint64(vtd_error->FaultStatus));
- //Fault record basic fields.
- json_object* fault_record_ir = json_object_new_object();
- EFI_VTD_FAULT_RECORD* fault_record = (EFI_VTD_FAULT_RECORD*)vtd_error->FaultRecord;
- json_object_object_add(fault_record_ir, "faultInformation", json_object_new_uint64(fault_record->FaultInformation));
- json_object_object_add(fault_record_ir, "sourceIdentifier", json_object_new_uint64(fault_record->SourceIdentifier));
- json_object_object_add(fault_record_ir, "privelegeModeRequested",
- json_object_new_boolean(fault_record->PrivelegeModeRequested));
- json_object_object_add(fault_record_ir, "executePermissionRequested",
- json_object_new_boolean(fault_record->ExecutePermissionRequested));
- json_object_object_add(fault_record_ir, "pasidPresent", json_object_new_boolean(fault_record->PasidPresent));
- json_object_object_add(fault_record_ir, "faultReason", json_object_new_uint64(fault_record->FaultReason));
- json_object_object_add(fault_record_ir, "pasidValue", json_object_new_uint64(fault_record->PasidValue));
- json_object_object_add(fault_record_ir, "addressType", json_object_new_uint64(fault_record->AddressType));
+ //Fault record basic fields.
+ json_object *fault_record_ir = json_object_new_object();
+ EFI_VTD_FAULT_RECORD *fault_record =
+ (EFI_VTD_FAULT_RECORD *)vtd_error->FaultRecord;
+ json_object_object_add(
+ fault_record_ir, "faultInformation",
+ json_object_new_uint64(fault_record->FaultInformation));
+ json_object_object_add(
+ fault_record_ir, "sourceIdentifier",
+ json_object_new_uint64(fault_record->SourceIdentifier));
+ json_object_object_add(
+ fault_record_ir, "privelegeModeRequested",
+ json_object_new_boolean(fault_record->PrivelegeModeRequested));
+ json_object_object_add(
+ fault_record_ir, "executePermissionRequested",
+ json_object_new_boolean(
+ fault_record->ExecutePermissionRequested));
+ json_object_object_add(
+ fault_record_ir, "pasidPresent",
+ json_object_new_boolean(fault_record->PasidPresent));
+ json_object_object_add(
+ fault_record_ir, "faultReason",
+ json_object_new_uint64(fault_record->FaultReason));
+ json_object_object_add(
+ fault_record_ir, "pasidValue",
+ json_object_new_uint64(fault_record->PasidValue));
+ json_object_object_add(
+ fault_record_ir, "addressType",
+ json_object_new_uint64(fault_record->AddressType));
- //Fault record type.
- json_object* fault_record_type = integer_to_readable_pair(fault_record->Type, 2,
- VTD_FAULT_RECORD_TYPES_KEYS,
- VTD_FAULT_RECORD_TYPES_VALUES,
- "Unknown");
- json_object_object_add(fault_record_ir, "type", fault_record_type);
- json_object_object_add(section_ir, "faultRecord", fault_record_ir);
+ //Fault record type.
+ json_object *fault_record_type = integer_to_readable_pair(
+ fault_record->Type, 2, VTD_FAULT_RECORD_TYPES_KEYS,
+ VTD_FAULT_RECORD_TYPES_VALUES, "Unknown");
+ json_object_object_add(fault_record_ir, "type", fault_record_type);
+ json_object_object_add(section_ir, "faultRecord", fault_record_ir);
- //Root entry.
- char* encoded = b64_encode((unsigned char*)vtd_error->RootEntry, 16);
- json_object_object_add(section_ir, "rootEntry", json_object_new_string(encoded));
- free(encoded);
+ //Root entry.
+ char *encoded = b64_encode((unsigned char *)vtd_error->RootEntry, 16);
+ json_object_object_add(section_ir, "rootEntry",
+ json_object_new_string(encoded));
+ free(encoded);
- //Context entry.
- encoded = b64_encode((unsigned char*)vtd_error->ContextEntry, 16);
- json_object_object_add(section_ir, "contextEntry", json_object_new_string(encoded));
- free(encoded);
+ //Context entry.
+ encoded = b64_encode((unsigned char *)vtd_error->ContextEntry, 16);
+ json_object_object_add(section_ir, "contextEntry",
+ json_object_new_string(encoded));
+ free(encoded);
- //PTE entry for all page levels.
- json_object_object_add(section_ir, "pageTableEntry_Level6", json_object_new_uint64(vtd_error->PteL6));
- json_object_object_add(section_ir, "pageTableEntry_Level5", json_object_new_uint64(vtd_error->PteL5));
- json_object_object_add(section_ir, "pageTableEntry_Level4", json_object_new_uint64(vtd_error->PteL4));
- json_object_object_add(section_ir, "pageTableEntry_Level3", json_object_new_uint64(vtd_error->PteL3));
- json_object_object_add(section_ir, "pageTableEntry_Level2", json_object_new_uint64(vtd_error->PteL2));
- json_object_object_add(section_ir, "pageTableEntry_Level1", json_object_new_uint64(vtd_error->PteL1));
+ //PTE entry for all page levels.
+ json_object_object_add(section_ir, "pageTableEntry_Level6",
+ json_object_new_uint64(vtd_error->PteL6));
+ json_object_object_add(section_ir, "pageTableEntry_Level5",
+ json_object_new_uint64(vtd_error->PteL5));
+ json_object_object_add(section_ir, "pageTableEntry_Level4",
+ json_object_new_uint64(vtd_error->PteL4));
+ json_object_object_add(section_ir, "pageTableEntry_Level3",
+ json_object_new_uint64(vtd_error->PteL3));
+ json_object_object_add(section_ir, "pageTableEntry_Level2",
+ json_object_new_uint64(vtd_error->PteL2));
+ json_object_object_add(section_ir, "pageTableEntry_Level1",
+ json_object_new_uint64(vtd_error->PteL1));
- return section_ir;
+ return section_ir;
}
//Converts a single VT-d DMAR CPER-JSON segment into CPER binary, outputting to the given stream.
-void ir_section_dmar_vtd_to_cper(json_object* section, FILE* out)
+void ir_section_dmar_vtd_to_cper(json_object *section, FILE *out)
{
- EFI_DIRECTED_IO_DMAR_ERROR_DATA* section_cper =
- (EFI_DIRECTED_IO_DMAR_ERROR_DATA*)calloc(1, sizeof(EFI_DIRECTED_IO_DMAR_ERROR_DATA));
+ EFI_DIRECTED_IO_DMAR_ERROR_DATA *section_cper =
+ (EFI_DIRECTED_IO_DMAR_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_DIRECTED_IO_DMAR_ERROR_DATA));
- //OEM ID.
- UINT64 oem_id = json_object_get_uint64(json_object_object_get(section, "oemID"));
- for (int i=0; i<6; i++)
- section_cper->OemId[i] = (oem_id >> (i * 8)) & 0xFF;
+ //OEM ID.
+ UINT64 oem_id = json_object_get_uint64(
+ json_object_object_get(section, "oemID"));
+ for (int i = 0; i < 6; i++)
+ section_cper->OemId[i] = (oem_id >> (i * 8)) & 0xFF;
- //Registers & basic numeric fields.
- section_cper->Version = (UINT8)json_object_get_int(json_object_object_get(section, "version"));
- section_cper->Revision = (UINT8)json_object_get_int(json_object_object_get(section, "revision"));
- section_cper->Capability = json_object_get_uint64(json_object_object_get(section, "capabilityRegister"));
- section_cper->CapabilityEx = json_object_get_uint64(json_object_object_get(section, "extendedCapabilityRegister"));
- section_cper->GlobalCommand = json_object_get_uint64(json_object_object_get(section, "globalCommandRegister"));
- section_cper->GlobalStatus = json_object_get_uint64(json_object_object_get(section, "globalStatusRegister"));
- section_cper->FaultStatus = json_object_get_uint64(json_object_object_get(section, "faultStatusRegister"));
+ //Registers & basic numeric fields.
+ section_cper->Version = (UINT8)json_object_get_int(
+ json_object_object_get(section, "version"));
+ section_cper->Revision = (UINT8)json_object_get_int(
+ json_object_object_get(section, "revision"));
+ section_cper->Capability = json_object_get_uint64(
+ json_object_object_get(section, "capabilityRegister"));
+ section_cper->CapabilityEx = json_object_get_uint64(
+ json_object_object_get(section, "extendedCapabilityRegister"));
+ section_cper->GlobalCommand = json_object_get_uint64(
+ json_object_object_get(section, "globalCommandRegister"));
+ section_cper->GlobalStatus = json_object_get_uint64(
+ json_object_object_get(section, "globalStatusRegister"));
+ section_cper->FaultStatus = json_object_get_uint64(
+ json_object_object_get(section, "faultStatusRegister"));
- //Fault record.
- json_object* fault_record = json_object_object_get(section, "faultRecord");
- EFI_VTD_FAULT_RECORD* fault_record_cper = (EFI_VTD_FAULT_RECORD*)section_cper->FaultRecord;
- fault_record_cper->FaultInformation =
- json_object_get_uint64(json_object_object_get(fault_record, "faultInformation"));
- fault_record_cper->SourceIdentifier =
- json_object_get_uint64(json_object_object_get(fault_record, "sourceIdentifier"));
- fault_record_cper->PrivelegeModeRequested =
- json_object_get_boolean(json_object_object_get(fault_record, "privelegeModeRequested"));
- fault_record_cper->ExecutePermissionRequested =
- json_object_get_boolean(json_object_object_get(fault_record, "executePermissionRequested"));
- fault_record_cper->PasidPresent =
- json_object_get_boolean(json_object_object_get(fault_record, "pasidPresent"));
- fault_record_cper->FaultReason =
- json_object_get_uint64(json_object_object_get(fault_record, "faultReason"));
- fault_record_cper->PasidValue =
- json_object_get_uint64(json_object_object_get(fault_record, "pasidValue"));
- fault_record_cper->AddressType =
- json_object_get_uint64(json_object_object_get(fault_record, "addressType"));
- fault_record_cper->Type =
- readable_pair_to_integer(json_object_object_get(fault_record, "type"));
-
- //Root entry.
- json_object* encoded = json_object_object_get(section, "rootEntry");
- UINT8* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- memcpy(section_cper->RootEntry, decoded, 16);
- free(decoded);
+ //Fault record.
+ json_object *fault_record =
+ json_object_object_get(section, "faultRecord");
+ EFI_VTD_FAULT_RECORD *fault_record_cper =
+ (EFI_VTD_FAULT_RECORD *)section_cper->FaultRecord;
+ fault_record_cper->FaultInformation = json_object_get_uint64(
+ json_object_object_get(fault_record, "faultInformation"));
+ fault_record_cper->SourceIdentifier = json_object_get_uint64(
+ json_object_object_get(fault_record, "sourceIdentifier"));
+ fault_record_cper->PrivelegeModeRequested = json_object_get_boolean(
+ json_object_object_get(fault_record, "privelegeModeRequested"));
+ fault_record_cper->ExecutePermissionRequested = json_object_get_boolean(
+ json_object_object_get(fault_record,
+ "executePermissionRequested"));
+ fault_record_cper->PasidPresent = json_object_get_boolean(
+ json_object_object_get(fault_record, "pasidPresent"));
+ fault_record_cper->FaultReason = json_object_get_uint64(
+ json_object_object_get(fault_record, "faultReason"));
+ fault_record_cper->PasidValue = json_object_get_uint64(
+ json_object_object_get(fault_record, "pasidValue"));
+ fault_record_cper->AddressType = json_object_get_uint64(
+ json_object_object_get(fault_record, "addressType"));
+ fault_record_cper->Type = readable_pair_to_integer(
+ json_object_object_get(fault_record, "type"));
- //Context entry.
- encoded = json_object_object_get(section, "contextEntry");
- decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- memcpy(section_cper->ContextEntry, decoded, 16);
- free(decoded);
+ //Root entry.
+ json_object *encoded = json_object_object_get(section, "rootEntry");
+ UINT8 *decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ memcpy(section_cper->RootEntry, decoded, 16);
+ free(decoded);
- //Page table entries.
- section_cper->PteL1 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level1"));
- section_cper->PteL2 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level2"));
- section_cper->PteL3 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level3"));
- section_cper->PteL4 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level4"));
- section_cper->PteL5 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level5"));
- section_cper->PteL6 = json_object_get_uint64(json_object_object_get(section, "pageTableEntry_Level6"));
+ //Context entry.
+ encoded = json_object_object_get(section, "contextEntry");
+ decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ memcpy(section_cper->ContextEntry, decoded, 16);
+ free(decoded);
- //Write to stream, free resources.
- fwrite(section_cper, sizeof(EFI_DIRECTED_IO_DMAR_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //Page table entries.
+ section_cper->PteL1 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level1"));
+ section_cper->PteL2 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level2"));
+ section_cper->PteL3 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level3"));
+ section_cper->PteL4 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level4"));
+ section_cper->PteL5 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level5"));
+ section_cper->PteL6 = json_object_get_uint64(
+ json_object_object_get(section, "pageTableEntry_Level6"));
+
+ //Write to stream, free resources.
+ fwrite(section_cper, sizeof(EFI_DIRECTED_IO_DMAR_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-firmware.c b/sections/cper-section-firmware.c
index 5e17e90..a3c3002 100644
--- a/sections/cper-section-firmware.c
+++ b/sections/cper-section-firmware.c
@@ -11,45 +11,56 @@
#include "cper-section-firmware.h"
//Converts a single firmware CPER section into JSON IR.
-json_object* cper_section_firmware_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_firmware_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_FIRMWARE_ERROR_DATA* firmware_error = (EFI_FIRMWARE_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_FIRMWARE_ERROR_DATA *firmware_error =
+ (EFI_FIRMWARE_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Record type.
- json_object* record_type = integer_to_readable_pair(firmware_error->ErrorType, 3,
- FIRMWARE_ERROR_RECORD_TYPES_KEYS,
- FIRMWARE_ERROR_RECORD_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(section_ir, "errorRecordType", record_type);
+ //Record type.
+ json_object *record_type = integer_to_readable_pair(
+ firmware_error->ErrorType, 3, FIRMWARE_ERROR_RECORD_TYPES_KEYS,
+ FIRMWARE_ERROR_RECORD_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(section_ir, "errorRecordType", record_type);
- //Revision, record identifier.
- json_object_object_add(section_ir, "revision", json_object_new_int(firmware_error->Revision));
- json_object_object_add(section_ir, "recordID", json_object_new_uint64(firmware_error->RecordId));
-
- //Record GUID.
- char record_id_guid[GUID_STRING_LENGTH];
- guid_to_string(record_id_guid, &firmware_error->RecordIdGuid);
- json_object_object_add(section_ir, "recordIDGUID", json_object_new_string(record_id_guid));
+ //Revision, record identifier.
+ json_object_object_add(section_ir, "revision",
+ json_object_new_int(firmware_error->Revision));
+ json_object_object_add(
+ section_ir, "recordID",
+ json_object_new_uint64(firmware_error->RecordId));
- return section_ir;
+ //Record GUID.
+ char record_id_guid[GUID_STRING_LENGTH];
+ guid_to_string(record_id_guid, &firmware_error->RecordIdGuid);
+ json_object_object_add(section_ir, "recordIDGUID",
+ json_object_new_string(record_id_guid));
+
+ return section_ir;
}
//Converts a single firmware CPER-JSON section into CPER binary, outputting to the given stream.
-void ir_section_firmware_to_cper(json_object* section, FILE* out)
+void ir_section_firmware_to_cper(json_object *section, FILE *out)
{
- EFI_FIRMWARE_ERROR_DATA* section_cper =
- (EFI_FIRMWARE_ERROR_DATA*)calloc(1, sizeof(EFI_FIRMWARE_ERROR_DATA));
+ EFI_FIRMWARE_ERROR_DATA *section_cper =
+ (EFI_FIRMWARE_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_FIRMWARE_ERROR_DATA));
- //Record fields.
- section_cper->ErrorType = readable_pair_to_integer(json_object_object_get(section, "errorRecordType"));
- section_cper->Revision = json_object_get_int(json_object_object_get(section, "revision"));
- section_cper->RecordId = json_object_get_uint64(json_object_object_get(section, "recordID"));
- string_to_guid(§ion_cper->RecordIdGuid,
- json_object_get_string(json_object_object_get(section, "recordIDGUID")));
+ //Record fields.
+ section_cper->ErrorType = readable_pair_to_integer(
+ json_object_object_get(section, "errorRecordType"));
+ section_cper->Revision = json_object_get_int(
+ json_object_object_get(section, "revision"));
+ section_cper->RecordId = json_object_get_uint64(
+ json_object_object_get(section, "recordID"));
+ string_to_guid(§ion_cper->RecordIdGuid,
+ json_object_get_string(json_object_object_get(
+ section, "recordIDGUID")));
- //Write to stream, free resources.
- fwrite(section_cper, sizeof(EFI_FIRMWARE_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //Write to stream, free resources.
+ fwrite(section_cper, sizeof(EFI_FIRMWARE_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-generic.c b/sections/cper-section-generic.c
index c82730b..f689945 100644
--- a/sections/cper-section-generic.c
+++ b/sections/cper-section-generic.c
@@ -13,106 +13,142 @@
#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)
+json_object *
+cper_section_generic_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_PROCESSOR_GENERIC_ERROR_DATA* section_generic = (EFI_PROCESSOR_GENERIC_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ 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 = bitfield_to_ir(section_generic->ValidFields, 13, GENERIC_VALIDATION_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation =
+ bitfield_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.
- 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 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 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);
+ //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);
+ //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 = bitfield_to_ir(section_generic->Flags, 4, GENERIC_FLAGS_BITFIELD_NAMES);
- json_object_object_add(section_ir, "flags", flags);
+ //Flags, additional information about the error.
+ json_object *flags = bitfield_to_ir(section_generic->Flags, 4,
+ GENERIC_FLAGS_BITFIELD_NAMES);
+ 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));
+ //The level of the error.
+ json_object_object_add(section_ir, "level",
+ json_object_new_int(section_generic->Level));
- //CPU version information.
- json_object_object_add(section_ir, "cpuVersionInfo", json_object_new_uint64(section_generic->VersionInfo));
+ //CPU version information.
+ json_object_object_add(
+ section_ir, "cpuVersionInfo",
+ json_object_new_uint64(section_generic->VersionInfo));
- //CPU brand string. May not exist if on ARM.
- json_object_object_add(section_ir, "cpuBrandString", json_object_new_string(section_generic->BrandString));
+ //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));
+ //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;
+ return section_ir;
}
//Converts the given CPER-JSON processor-generic error section into CPER binary,
//outputting to the provided stream.
-void ir_section_generic_to_cper(json_object* section, FILE* out)
+void ir_section_generic_to_cper(json_object *section, FILE *out)
{
- EFI_PROCESSOR_GENERIC_ERROR_DATA* section_cper =
- (EFI_PROCESSOR_GENERIC_ERROR_DATA*)calloc(1, sizeof(EFI_PROCESSOR_GENERIC_ERROR_DATA));
+ EFI_PROCESSOR_GENERIC_ERROR_DATA *section_cper =
+ (EFI_PROCESSOR_GENERIC_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_PROCESSOR_GENERIC_ERROR_DATA));
- //Validation bits.
- section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 13, GENERIC_VALIDATION_BITFIELD_NAMES);
-
- //Various name/value pair fields.
- section_cper->Type = (UINT8)readable_pair_to_integer(json_object_object_get(section, "processorType"));
- section_cper->Isa = (UINT8)readable_pair_to_integer(json_object_object_get(section, "processorISA"));
- section_cper->ErrorType = (UINT8)readable_pair_to_integer(json_object_object_get(section, "errorType"));
- section_cper->Operation = (UINT8)readable_pair_to_integer(json_object_object_get(section, "operation"));
+ //Validation bits.
+ section_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 13,
+ GENERIC_VALIDATION_BITFIELD_NAMES);
- //Flags.
- section_cper->Flags = (UINT8)ir_to_bitfield(json_object_object_get(section, "flags"), 4, GENERIC_FLAGS_BITFIELD_NAMES);
+ //Various name/value pair fields.
+ section_cper->Type = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "processorType"));
+ section_cper->Isa = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "processorISA"));
+ section_cper->ErrorType = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "errorType"));
+ section_cper->Operation = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "operation"));
- //Various numeric/string fields.
- section_cper->Level = (UINT8)json_object_get_int(json_object_object_get(section, "level"));
- section_cper->VersionInfo = json_object_get_uint64(json_object_object_get(section, "cpuVersionInfo"));
- section_cper->ApicId = json_object_get_uint64(json_object_object_get(section, "processorID"));
- section_cper->TargetAddr = json_object_get_uint64(json_object_object_get(section, "targetAddress"));
- section_cper->RequestorId = json_object_get_uint64(json_object_object_get(section, "requestorID"));
- section_cper->ResponderId = json_object_get_uint64(json_object_object_get(section, "responderID"));
- section_cper->InstructionIP = json_object_get_uint64(json_object_object_get(section, "instructionIP"));
+ //Flags.
+ section_cper->Flags =
+ (UINT8)ir_to_bitfield(json_object_object_get(section, "flags"),
+ 4, GENERIC_FLAGS_BITFIELD_NAMES);
- //CPU brand string.
- const char* brand_string = json_object_get_string(json_object_object_get(section, "cpuBrandString"));
- if (brand_string != NULL)
- strncpy(section_cper->BrandString, brand_string, 127);
+ //Various numeric/string fields.
+ section_cper->Level = (UINT8)json_object_get_int(
+ json_object_object_get(section, "level"));
+ section_cper->VersionInfo = json_object_get_uint64(
+ json_object_object_get(section, "cpuVersionInfo"));
+ section_cper->ApicId = json_object_get_uint64(
+ json_object_object_get(section, "processorID"));
+ section_cper->TargetAddr = json_object_get_uint64(
+ json_object_object_get(section, "targetAddress"));
+ section_cper->RequestorId = json_object_get_uint64(
+ json_object_object_get(section, "requestorID"));
+ section_cper->ResponderId = json_object_get_uint64(
+ json_object_object_get(section, "responderID"));
+ section_cper->InstructionIP = json_object_get_uint64(
+ json_object_object_get(section, "instructionIP"));
- //Write & flush out to file, free memory.
- fwrite(section_cper, sizeof(EFI_PROCESSOR_GENERIC_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //CPU brand string.
+ const char *brand_string = json_object_get_string(
+ json_object_object_get(section, "cpuBrandString"));
+ if (brand_string != NULL)
+ strncpy(section_cper->BrandString, brand_string, 127);
+
+ //Write & flush out to file, free memory.
+ fwrite(section_cper, sizeof(EFI_PROCESSOR_GENERIC_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-ia32x64.c b/sections/cper-section-ia32x64.c
index a2f806a..35c5a2e 100644
--- a/sections/cper-section-ia32x64.c
+++ b/sections/cper-section-ia32x64.c
@@ -13,360 +13,523 @@
#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);
-void ir_ia32x64_error_info_to_cper(json_object* error_info, FILE* out);
-void ir_ia32x64_context_info_to_cper(json_object* context_info, FILE* out);
-void ir_ia32x64_cache_tlb_check_error_to_cper(json_object* check_info, EFI_IA32_X64_CACHE_CHECK_INFO* check_info_cper);
-void ir_ia32x64_bus_check_error_to_cper(json_object* check_info, EFI_IA32_X64_BUS_CHECK_INFO* check_info_cper);
-void ir_ia32x64_ms_check_error_to_cper(json_object* check_info, EFI_IA32_X64_MS_CHECK_INFO* check_info_cper);
-void ir_ia32x64_ia32_registers_to_cper(json_object* registers, FILE* out);
-void ir_ia32x64_x64_registers_to_cper(json_object* registers, FILE* out);
+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);
+void ir_ia32x64_error_info_to_cper(json_object *error_info, FILE *out);
+void ir_ia32x64_context_info_to_cper(json_object *context_info, FILE *out);
+void ir_ia32x64_cache_tlb_check_error_to_cper(
+ json_object *check_info,
+ EFI_IA32_X64_CACHE_CHECK_INFO *check_info_cper);
+void ir_ia32x64_bus_check_error_to_cper(
+ json_object *check_info, EFI_IA32_X64_BUS_CHECK_INFO *check_info_cper);
+void ir_ia32x64_ms_check_error_to_cper(
+ json_object *check_info, EFI_IA32_X64_MS_CHECK_INFO *check_info_cper);
+void ir_ia32x64_ia32_registers_to_cper(json_object *registers, FILE *out);
+void ir_ia32x64_x64_registers_to_cper(json_object *registers, FILE *out);
//////////////////
/// CPER TO IR ///
//////////////////
//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)
+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();
+ EFI_IA32_X64_PROCESSOR_ERROR_RECORD *record =
+ (EFI_IA32_X64_PROCESSOR_ERROR_RECORD *)section;
+ json_object *record_ir = json_object_new_object();
- //Validation bits.
- json_object* validationBits = json_object_new_object();
- json_object_object_add(validationBits, "localAPICIDValid", json_object_new_boolean(record->ValidFields & 0b1));
- json_object_object_add(validationBits, "cpuIDInfoValid", json_object_new_boolean((record->ValidFields >> 1) & 0b1));
- int processor_error_info_num = (record->ValidFields >> 2) & 0b111111;
- json_object_object_add(validationBits, "processorErrorInfoNum", json_object_new_int(processor_error_info_num));
- int processor_context_info_num = (record->ValidFields >> 8) & 0b111111;
- json_object_object_add(validationBits, "processorContextInfoNum", json_object_new_int(processor_context_info_num));
- json_object_object_add(record_ir, "validationBits", validationBits);
+ //Validation bits.
+ json_object *validationBits = json_object_new_object();
+ json_object_object_add(validationBits, "localAPICIDValid",
+ json_object_new_boolean(record->ValidFields &
+ 0b1));
+ json_object_object_add(
+ validationBits, "cpuIDInfoValid",
+ json_object_new_boolean((record->ValidFields >> 1) & 0b1));
+ int processor_error_info_num = (record->ValidFields >> 2) & 0b111111;
+ json_object_object_add(validationBits, "processorErrorInfoNum",
+ json_object_new_int(processor_error_info_num));
+ int processor_context_info_num = (record->ValidFields >> 8) & 0b111111;
+ json_object_object_add(validationBits, "processorContextInfoNum",
+ json_object_new_int(processor_context_info_num));
+ json_object_object_add(record_ir, "validationBits", validationBits);
- //APIC ID.
- json_object_object_add(record_ir, "localAPICID", json_object_new_uint64(record->ApicId));
+ //APIC ID.
+ json_object_object_add(record_ir, "localAPICID",
+ json_object_new_uint64(record->ApicId));
- //CPUID information.
- json_object* cpuid_info_ir = json_object_new_object();
- EFI_IA32_X64_CPU_ID* cpuid_info = (EFI_IA32_X64_CPU_ID*)record->CpuIdInfo;
- json_object_object_add(cpuid_info_ir, "eax", json_object_new_uint64(cpuid_info->Eax));
- json_object_object_add(cpuid_info_ir, "ebx", json_object_new_uint64(cpuid_info->Ebx));
- json_object_object_add(cpuid_info_ir, "ecx", json_object_new_uint64(cpuid_info->Ecx));
- json_object_object_add(cpuid_info_ir, "edx", json_object_new_uint64(cpuid_info->Edx));
- json_object_object_add(record_ir, "cpuidInfo", cpuid_info_ir);
+ //CPUID information.
+ json_object *cpuid_info_ir = json_object_new_object();
+ EFI_IA32_X64_CPU_ID *cpuid_info =
+ (EFI_IA32_X64_CPU_ID *)record->CpuIdInfo;
+ json_object_object_add(cpuid_info_ir, "eax",
+ json_object_new_uint64(cpuid_info->Eax));
+ json_object_object_add(cpuid_info_ir, "ebx",
+ json_object_new_uint64(cpuid_info->Ebx));
+ json_object_object_add(cpuid_info_ir, "ecx",
+ json_object_new_uint64(cpuid_info->Ecx));
+ json_object_object_add(cpuid_info_ir, "edx",
+ json_object_new_uint64(cpuid_info->Edx));
+ json_object_object_add(record_ir, "cpuidInfo", cpuid_info_ir);
- //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 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;
- void* cur_pos = (void*)current_context_info;
- 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, &cur_pos));
- current_context_info = (EFI_IA32_X64_PROCESSOR_CONTEXT_INFO*)cur_pos;
- //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);
+ //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;
+ void *cur_pos = (void *)current_context_info;
+ 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, &cur_pos));
+ current_context_info =
+ (EFI_IA32_X64_PROCESSOR_CONTEXT_INFO *)cur_pos;
+ //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;
+ 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 *cper_ia32x64_processor_error_info_to_ir(
+ EFI_IA32_X64_PROCESS_ERROR_INFO *error_info)
{
- json_object* error_info_ir = json_object_new_object();
+ 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));
+ //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 = bitfield_to_ir(error_info->ValidFields, 5, IA32X64_PROCESSOR_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(error_info_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation =
+ bitfield_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* check_information = NULL;
- if (guid_equal(&error_info->ErrorType, &gEfiIa32x64ErrorTypeCacheCheckGuid)
- || guid_equal(&error_info->ErrorType, &gEfiIa32x64ErrorTypeTlbCheckGuid))
- {
- check_information = cper_ia32x64_cache_tlb_check_to_ir((EFI_IA32_X64_CACHE_CHECK_INFO*)&error_info->CheckInfo);
- }
- else if (guid_equal(&error_info->ErrorType, &gEfiIa32x64ErrorTypeBusCheckGuid))
- {
- check_information = cper_ia32x64_bus_check_to_ir((EFI_IA32_X64_BUS_CHECK_INFO*)&error_info->CheckInfo);
- }
- else if (guid_equal(&error_info->ErrorType, &gEfiIa32x64ErrorTypeMsCheckGuid))
- {
- check_information = cper_ia32x64_ms_check_to_ir((EFI_IA32_X64_MS_CHECK_INFO*)&error_info->CheckInfo);
- }
- else
- {
- //Unknown check information.
- printf("WARN: Invalid/unknown check information GUID found in IA32/x64 CPER section. Ignoring.\n");
- }
- json_object_object_add(error_info_ir, "checkInfo", check_information);
+ //Add the check information on a per-structure basis.
+ //Cache and TLB check information are identical, so can be equated.
+ json_object *check_information = NULL;
+ if (guid_equal(&error_info->ErrorType,
+ &gEfiIa32x64ErrorTypeCacheCheckGuid) ||
+ guid_equal(&error_info->ErrorType,
+ &gEfiIa32x64ErrorTypeTlbCheckGuid)) {
+ check_information = cper_ia32x64_cache_tlb_check_to_ir(
+ (EFI_IA32_X64_CACHE_CHECK_INFO *)&error_info->CheckInfo);
+ } else if (guid_equal(&error_info->ErrorType,
+ &gEfiIa32x64ErrorTypeBusCheckGuid)) {
+ check_information = cper_ia32x64_bus_check_to_ir(
+ (EFI_IA32_X64_BUS_CHECK_INFO *)&error_info->CheckInfo);
+ } else if (guid_equal(&error_info->ErrorType,
+ &gEfiIa32x64ErrorTypeMsCheckGuid)) {
+ check_information = cper_ia32x64_ms_check_to_ir(
+ (EFI_IA32_X64_MS_CHECK_INFO *)&error_info->CheckInfo);
+ } else {
+ //Unknown check information.
+ printf("WARN: Invalid/unknown check information GUID found in IA32/x64 CPER section. Ignoring.\n");
+ }
+ json_object_object_add(error_info_ir, "checkInfo", check_information);
- //Target, requestor, and responder identifiers.
- json_object_object_add(error_info_ir, "targetAddressID", json_object_new_uint64(error_info->TargetId));
- json_object_object_add(error_info_ir, "requestorID", json_object_new_uint64(error_info->RequestorId));
- json_object_object_add(error_info_ir, "responderID", json_object_new_uint64(error_info->ResponderId));
- json_object_object_add(error_info_ir, "instructionPointer", json_object_new_uint64(error_info->InstructionIP));
+ //Target, requestor, and responder identifiers.
+ json_object_object_add(error_info_ir, "targetAddressID",
+ json_object_new_uint64(error_info->TargetId));
+ json_object_object_add(error_info_ir, "requestorID",
+ json_object_new_uint64(error_info->RequestorId));
+ json_object_object_add(error_info_ir, "responderID",
+ 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;
+ 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 *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();
+ 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);
+ //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);
+ //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);
+ //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));
+ //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));
+ //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;
+ 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();
+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);
+ //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);
+ //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);
+ //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));
+ //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));
+ //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);
+ //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;
+ //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 *cper_ia32x64_ms_check_to_ir(EFI_IA32_X64_MS_CHECK_INFO *ms_check)
{
- json_object* ms_check_ir = json_object_new_object();
+ json_object *ms_check_ir = json_object_new_object();
- //Validation bits.
- json_object* validation = bitfield_to_ir(ms_check->ValidFields, 6, IA32X64_CHECK_INFO_MS_CHECK_VALID_BITFIELD_NAMES);
- json_object_object_add(ms_check_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation = bitfield_to_ir(
+ ms_check->ValidFields, 6,
+ IA32X64_CHECK_INFO_MS_CHECK_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));
+ //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);
- return ms_check_ir;
+ //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 *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();
+ 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 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 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 == EFI_REG_CONTEXT_TYPE_IA32)
- {
- 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 == EFI_REG_CONTEXT_TYPE_X64)
- {
- 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 dump as base64 and shift the head to the next item.
- *cur_pos = (void*)(context_info + 1);
+ //Register array.
+ json_object *register_array = NULL;
+ if (context_info->RegisterType == EFI_REG_CONTEXT_TYPE_IA32) {
+ 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 == EFI_REG_CONTEXT_TYPE_X64) {
+ 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 dump as base64 and shift the head to the next item.
+ *cur_pos = (void *)(context_info + 1);
- char* encoded = b64_encode((unsigned char*)*cur_pos, context_info->ArraySize);
- register_array = json_object_new_object();
- json_object_object_add(register_array, "data", json_object_new_string(encoded));
- free(encoded);
+ char *encoded = b64_encode((unsigned char *)*cur_pos,
+ context_info->ArraySize);
+ register_array = json_object_new_object();
+ json_object_object_add(register_array, "data",
+ json_object_new_string(encoded));
+ free(encoded);
- *cur_pos = (void*)(((char*)*cur_pos) + context_info->ArraySize);
- }
- json_object_object_add(context_info_ir, "registerArray", register_array);
+ *cur_pos =
+ (void *)(((char *)*cur_pos) + context_info->ArraySize);
+ }
+ json_object_object_add(context_info_ir, "registerArray",
+ register_array);
- return context_info_ir;
+ 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 *
+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_uint64(registers->Eax));
- json_object_object_add(ia32_registers, "ebx", json_object_new_uint64(registers->Ebx));
- json_object_object_add(ia32_registers, "ecx", json_object_new_uint64(registers->Ecx));
- json_object_object_add(ia32_registers, "edx", json_object_new_uint64(registers->Edx));
- json_object_object_add(ia32_registers, "esi", json_object_new_uint64(registers->Esi));
- json_object_object_add(ia32_registers, "edi", json_object_new_uint64(registers->Edi));
- json_object_object_add(ia32_registers, "ebp", json_object_new_uint64(registers->Ebp));
- json_object_object_add(ia32_registers, "esp", json_object_new_uint64(registers->Esp));
- json_object_object_add(ia32_registers, "cs", json_object_new_uint64(registers->Cs));
- json_object_object_add(ia32_registers, "ds", json_object_new_uint64(registers->Ds));
- json_object_object_add(ia32_registers, "ss", json_object_new_uint64(registers->Ss));
- json_object_object_add(ia32_registers, "es", json_object_new_uint64(registers->Es));
- json_object_object_add(ia32_registers, "fs", json_object_new_uint64(registers->Fs));
- json_object_object_add(ia32_registers, "gs", json_object_new_uint64(registers->Gs));
- json_object_object_add(ia32_registers, "eflags", json_object_new_uint64(registers->Eflags));
- json_object_object_add(ia32_registers, "eip", json_object_new_uint64(registers->Eip));
- json_object_object_add(ia32_registers, "cr0", json_object_new_uint64(registers->Cr0));
- json_object_object_add(ia32_registers, "cr1", json_object_new_uint64(registers->Cr1));
- json_object_object_add(ia32_registers, "cr2", json_object_new_uint64(registers->Cr2));
- json_object_object_add(ia32_registers, "cr3", json_object_new_uint64(registers->Cr3));
- json_object_object_add(ia32_registers, "cr4", json_object_new_uint64(registers->Cr4));
- json_object_object_add(ia32_registers, "gdtr", json_object_new_uint64(registers->Gdtr[0] + ((UINT64)registers->Gdtr[1] << 32)));
- json_object_object_add(ia32_registers, "idtr", json_object_new_uint64(registers->Idtr[0] + ((UINT64)registers->Idtr[1] << 32)));
- json_object_object_add(ia32_registers, "ldtr", json_object_new_uint64(registers->Ldtr));
- json_object_object_add(ia32_registers, "tr", json_object_new_uint64(registers->Tr));
+ json_object *ia32_registers = json_object_new_object();
+ json_object_object_add(ia32_registers, "eax",
+ json_object_new_uint64(registers->Eax));
+ json_object_object_add(ia32_registers, "ebx",
+ json_object_new_uint64(registers->Ebx));
+ json_object_object_add(ia32_registers, "ecx",
+ json_object_new_uint64(registers->Ecx));
+ json_object_object_add(ia32_registers, "edx",
+ json_object_new_uint64(registers->Edx));
+ json_object_object_add(ia32_registers, "esi",
+ json_object_new_uint64(registers->Esi));
+ json_object_object_add(ia32_registers, "edi",
+ json_object_new_uint64(registers->Edi));
+ json_object_object_add(ia32_registers, "ebp",
+ json_object_new_uint64(registers->Ebp));
+ json_object_object_add(ia32_registers, "esp",
+ json_object_new_uint64(registers->Esp));
+ json_object_object_add(ia32_registers, "cs",
+ json_object_new_uint64(registers->Cs));
+ json_object_object_add(ia32_registers, "ds",
+ json_object_new_uint64(registers->Ds));
+ json_object_object_add(ia32_registers, "ss",
+ json_object_new_uint64(registers->Ss));
+ json_object_object_add(ia32_registers, "es",
+ json_object_new_uint64(registers->Es));
+ json_object_object_add(ia32_registers, "fs",
+ json_object_new_uint64(registers->Fs));
+ json_object_object_add(ia32_registers, "gs",
+ json_object_new_uint64(registers->Gs));
+ json_object_object_add(ia32_registers, "eflags",
+ json_object_new_uint64(registers->Eflags));
+ json_object_object_add(ia32_registers, "eip",
+ json_object_new_uint64(registers->Eip));
+ json_object_object_add(ia32_registers, "cr0",
+ json_object_new_uint64(registers->Cr0));
+ json_object_object_add(ia32_registers, "cr1",
+ json_object_new_uint64(registers->Cr1));
+ json_object_object_add(ia32_registers, "cr2",
+ json_object_new_uint64(registers->Cr2));
+ json_object_object_add(ia32_registers, "cr3",
+ json_object_new_uint64(registers->Cr3));
+ json_object_object_add(ia32_registers, "cr4",
+ json_object_new_uint64(registers->Cr4));
+ json_object_object_add(
+ ia32_registers, "gdtr",
+ json_object_new_uint64(registers->Gdtr[0] +
+ ((UINT64)registers->Gdtr[1] << 32)));
+ json_object_object_add(
+ ia32_registers, "idtr",
+ json_object_new_uint64(registers->Idtr[0] +
+ ((UINT64)registers->Idtr[1] << 32)));
+ json_object_object_add(ia32_registers, "ldtr",
+ json_object_new_uint64(registers->Ldtr));
+ json_object_object_add(ia32_registers, "tr",
+ json_object_new_uint64(registers->Tr));
- return ia32_registers;
+ 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 *
+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));
- json_object_object_add(x64_registers, "cr8", json_object_new_uint64(registers->Cr8));
- 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));
+ 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));
+ json_object_object_add(x64_registers, "cr8",
+ json_object_new_uint64(registers->Cr8));
+ 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;
+ return x64_registers;
}
//////////////////
@@ -374,273 +537,415 @@
//////////////////
//Converts a single IA32/x64 CPER-JSON section into CPER binary, outputting to the provided stream.
-void ir_section_ia32x64_to_cper(json_object* section, FILE* out)
+void ir_section_ia32x64_to_cper(json_object *section, FILE *out)
{
- EFI_IA32_X64_PROCESSOR_ERROR_RECORD* section_cper =
- (EFI_IA32_X64_PROCESSOR_ERROR_RECORD*)calloc(1, sizeof(EFI_IA32_X64_PROCESSOR_ERROR_RECORD));
+ EFI_IA32_X64_PROCESSOR_ERROR_RECORD *section_cper =
+ (EFI_IA32_X64_PROCESSOR_ERROR_RECORD *)calloc(
+ 1, sizeof(EFI_IA32_X64_PROCESSOR_ERROR_RECORD));
- //Validation bits.
- json_object* validation = json_object_object_get(section, "validationBits");
- section_cper->ValidFields = 0x0;
- section_cper->ValidFields |= json_object_get_boolean(json_object_object_get(validation, "localAPICIDValid"));
- section_cper->ValidFields |= json_object_get_boolean(json_object_object_get(validation, "cpuIDInfoValid")) << 1;
- int proc_error_info_num = json_object_get_int(json_object_object_get(validation, "processorErrorInfoNum")) & 0b111111;
- int proc_ctx_info_num = json_object_get_int(json_object_object_get(validation, "processorContextInfoNum")) & 0b111111;
- section_cper->ValidFields |= proc_error_info_num << 2;
- section_cper->ValidFields |= proc_ctx_info_num << 8;
+ //Validation bits.
+ json_object *validation =
+ json_object_object_get(section, "validationBits");
+ section_cper->ValidFields = 0x0;
+ section_cper->ValidFields |= json_object_get_boolean(
+ json_object_object_get(validation, "localAPICIDValid"));
+ section_cper->ValidFields |=
+ json_object_get_boolean(
+ json_object_object_get(validation, "cpuIDInfoValid"))
+ << 1;
+ int proc_error_info_num =
+ json_object_get_int(json_object_object_get(
+ validation, "processorErrorInfoNum")) &
+ 0b111111;
+ int proc_ctx_info_num =
+ json_object_get_int(json_object_object_get(
+ validation, "processorContextInfoNum")) &
+ 0b111111;
+ section_cper->ValidFields |= proc_error_info_num << 2;
+ section_cper->ValidFields |= proc_ctx_info_num << 8;
- //Local APIC ID.
- section_cper->ApicId = json_object_get_uint64(json_object_object_get(section, "localAPICID"));
-
- //CPUID info.
- json_object* cpuid_info = json_object_object_get(section, "cpuidInfo");
- EFI_IA32_X64_CPU_ID* cpuid_info_cper = (EFI_IA32_X64_CPU_ID*)section_cper->CpuIdInfo;
- cpuid_info_cper->Eax = json_object_get_uint64(json_object_object_get(cpuid_info, "eax"));
- cpuid_info_cper->Ebx = json_object_get_uint64(json_object_object_get(cpuid_info, "ebx"));
- cpuid_info_cper->Ecx = json_object_get_uint64(json_object_object_get(cpuid_info, "ecx"));
- cpuid_info_cper->Edx = json_object_get_uint64(json_object_object_get(cpuid_info, "edx"));
+ //Local APIC ID.
+ section_cper->ApicId = json_object_get_uint64(
+ json_object_object_get(section, "localAPICID"));
- //Flush the header to file before dealing w/ info sections.
- fwrite(section_cper, sizeof(EFI_IA32_X64_PROCESSOR_ERROR_RECORD), 1, out);
- fflush(out);
- free(section_cper);
+ //CPUID info.
+ json_object *cpuid_info = json_object_object_get(section, "cpuidInfo");
+ EFI_IA32_X64_CPU_ID *cpuid_info_cper =
+ (EFI_IA32_X64_CPU_ID *)section_cper->CpuIdInfo;
+ cpuid_info_cper->Eax = json_object_get_uint64(
+ json_object_object_get(cpuid_info, "eax"));
+ cpuid_info_cper->Ebx = json_object_get_uint64(
+ json_object_object_get(cpuid_info, "ebx"));
+ cpuid_info_cper->Ecx = json_object_get_uint64(
+ json_object_object_get(cpuid_info, "ecx"));
+ cpuid_info_cper->Edx = json_object_get_uint64(
+ json_object_object_get(cpuid_info, "edx"));
- //Iterate and deal with sections.
- json_object* error_info = json_object_object_get(section, "processorErrorInfo");
- json_object* context_info = json_object_object_get(section, "processorContextInfo");
- for (int i=0; i<proc_error_info_num; i++)
- ir_ia32x64_error_info_to_cper(json_object_array_get_idx(error_info, i), out);
- for (int i=0; i<proc_ctx_info_num; i++)
- ir_ia32x64_context_info_to_cper(json_object_array_get_idx(context_info, i), out);
+ //Flush the header to file before dealing w/ info sections.
+ fwrite(section_cper, sizeof(EFI_IA32_X64_PROCESSOR_ERROR_RECORD), 1,
+ out);
+ fflush(out);
+ free(section_cper);
+
+ //Iterate and deal with sections.
+ json_object *error_info =
+ json_object_object_get(section, "processorErrorInfo");
+ json_object *context_info =
+ json_object_object_get(section, "processorContextInfo");
+ for (int i = 0; i < proc_error_info_num; i++)
+ ir_ia32x64_error_info_to_cper(
+ json_object_array_get_idx(error_info, i), out);
+ for (int i = 0; i < proc_ctx_info_num; i++)
+ ir_ia32x64_context_info_to_cper(
+ json_object_array_get_idx(context_info, i), out);
}
//Converts a single CPER-JSON IA32/x64 error information structure into CPER binary, outputting to the
//provided stream.
-void ir_ia32x64_error_info_to_cper(json_object* error_info, FILE* out)
+void ir_ia32x64_error_info_to_cper(json_object *error_info, FILE *out)
{
- EFI_IA32_X64_PROCESS_ERROR_INFO* error_info_cper =
- (EFI_IA32_X64_PROCESS_ERROR_INFO*)calloc(1, sizeof(EFI_IA32_X64_PROCESS_ERROR_INFO));
+ EFI_IA32_X64_PROCESS_ERROR_INFO *error_info_cper =
+ (EFI_IA32_X64_PROCESS_ERROR_INFO *)calloc(
+ 1, sizeof(EFI_IA32_X64_PROCESS_ERROR_INFO));
- //Error structure type.
- string_to_guid(&error_info_cper->ErrorType, json_object_get_string(json_object_object_get(error_info, "type")));
+ //Error structure type.
+ string_to_guid(&error_info_cper->ErrorType,
+ json_object_get_string(
+ json_object_object_get(error_info, "type")));
- //Validation bits.
- error_info_cper->ValidFields = ir_to_bitfield(json_object_object_get(error_info, "validationBits"),
- 5, IA32X64_PROCESSOR_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ error_info_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(error_info, "validationBits"), 5,
+ IA32X64_PROCESSOR_ERROR_VALID_BITFIELD_NAMES);
- //Check information, parsed based on the error type.
- json_object* check_info = json_object_object_get(error_info, "checkInfo");
- if (guid_equal(&error_info_cper->ErrorType, &gEfiIa32x64ErrorTypeCacheCheckGuid)
- || guid_equal(&error_info_cper->ErrorType, &gEfiIa32x64ErrorTypeTlbCheckGuid))
- {
- ir_ia32x64_cache_tlb_check_error_to_cper(check_info, (EFI_IA32_X64_CACHE_CHECK_INFO*)&error_info_cper->CheckInfo);
- }
- else if (guid_equal(&error_info_cper->ErrorType, &gEfiIa32x64ErrorTypeBusCheckGuid))
- ir_ia32x64_bus_check_error_to_cper(check_info, (EFI_IA32_X64_BUS_CHECK_INFO*)&error_info_cper->CheckInfo);
- else if (guid_equal(&error_info_cper->ErrorType, &gEfiIa32x64ErrorTypeMsCheckGuid))
- ir_ia32x64_ms_check_error_to_cper(check_info, (EFI_IA32_X64_MS_CHECK_INFO*)&error_info_cper->CheckInfo);
+ //Check information, parsed based on the error type.
+ json_object *check_info =
+ json_object_object_get(error_info, "checkInfo");
+ if (guid_equal(&error_info_cper->ErrorType,
+ &gEfiIa32x64ErrorTypeCacheCheckGuid) ||
+ guid_equal(&error_info_cper->ErrorType,
+ &gEfiIa32x64ErrorTypeTlbCheckGuid)) {
+ ir_ia32x64_cache_tlb_check_error_to_cper(
+ check_info,
+ (EFI_IA32_X64_CACHE_CHECK_INFO *)&error_info_cper
+ ->CheckInfo);
+ } else if (guid_equal(&error_info_cper->ErrorType,
+ &gEfiIa32x64ErrorTypeBusCheckGuid))
+ ir_ia32x64_bus_check_error_to_cper(
+ check_info,
+ (EFI_IA32_X64_BUS_CHECK_INFO *)&error_info_cper
+ ->CheckInfo);
+ else if (guid_equal(&error_info_cper->ErrorType,
+ &gEfiIa32x64ErrorTypeMsCheckGuid))
+ ir_ia32x64_ms_check_error_to_cper(
+ check_info,
+ (EFI_IA32_X64_MS_CHECK_INFO *)&error_info_cper
+ ->CheckInfo);
- //Miscellaneous numeric fields.
- error_info_cper->TargetId = json_object_get_uint64(json_object_object_get(error_info, "targetAddressID"));
- error_info_cper->RequestorId = json_object_get_uint64(json_object_object_get(error_info, "requestorID"));
- error_info_cper->ResponderId = json_object_get_uint64(json_object_object_get(error_info, "responderID"));
- error_info_cper->InstructionIP = json_object_get_uint64(json_object_object_get(error_info, "instructionPointer"));
+ //Miscellaneous numeric fields.
+ error_info_cper->TargetId = json_object_get_uint64(
+ json_object_object_get(error_info, "targetAddressID"));
+ error_info_cper->RequestorId = json_object_get_uint64(
+ json_object_object_get(error_info, "requestorID"));
+ error_info_cper->ResponderId = json_object_get_uint64(
+ json_object_object_get(error_info, "responderID"));
+ error_info_cper->InstructionIP = json_object_get_uint64(
+ json_object_object_get(error_info, "instructionPointer"));
- //Write out to stream, then free resources.
- fwrite(error_info_cper, sizeof(EFI_IA32_X64_PROCESS_ERROR_INFO), 1, out);
- fflush(out);
- free(error_info_cper);
+ //Write out to stream, then free resources.
+ fwrite(error_info_cper, sizeof(EFI_IA32_X64_PROCESS_ERROR_INFO), 1,
+ out);
+ fflush(out);
+ free(error_info_cper);
}
//Converts a single CPER-JSON IA32/x64 cache/TLB check error info structure to CPER binary.
-void ir_ia32x64_cache_tlb_check_error_to_cper(json_object* check_info, EFI_IA32_X64_CACHE_CHECK_INFO* check_info_cper)
+void ir_ia32x64_cache_tlb_check_error_to_cper(
+ json_object *check_info, EFI_IA32_X64_CACHE_CHECK_INFO *check_info_cper)
{
- //Validation bits.
- check_info_cper->ValidFields = ir_to_bitfield(json_object_object_get(check_info, "validationBits"),
- 8, IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ check_info_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(check_info, "validationBits"), 8,
+ IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES);
- //Transaction type, operation.
- check_info_cper->TransactionType = readable_pair_to_integer(json_object_object_get(check_info, "transactionType"));
- check_info_cper->Operation = readable_pair_to_integer(json_object_object_get(check_info, "operation"));
+ //Transaction type, operation.
+ check_info_cper->TransactionType = readable_pair_to_integer(
+ json_object_object_get(check_info, "transactionType"));
+ check_info_cper->Operation = readable_pair_to_integer(
+ json_object_object_get(check_info, "operation"));
- //Miscellaneous raw value fields.
- check_info_cper->Level = json_object_get_uint64(json_object_object_get(check_info, "level"));
- check_info_cper->ContextCorrupt = json_object_get_boolean(json_object_object_get(check_info, "processorContextCorrupt"));
- check_info_cper->ErrorUncorrected = json_object_get_boolean(json_object_object_get(check_info, "uncorrected"));
- check_info_cper->PreciseIp = json_object_get_boolean(json_object_object_get(check_info, "preciseIP"));
- check_info_cper->RestartableIp = json_object_get_boolean(json_object_object_get(check_info, "restartableIP"));
- check_info_cper->Overflow = json_object_get_boolean(json_object_object_get(check_info, "overflow"));
+ //Miscellaneous raw value fields.
+ check_info_cper->Level = json_object_get_uint64(
+ json_object_object_get(check_info, "level"));
+ check_info_cper->ContextCorrupt = json_object_get_boolean(
+ json_object_object_get(check_info, "processorContextCorrupt"));
+ check_info_cper->ErrorUncorrected = json_object_get_boolean(
+ json_object_object_get(check_info, "uncorrected"));
+ check_info_cper->PreciseIp = json_object_get_boolean(
+ json_object_object_get(check_info, "preciseIP"));
+ check_info_cper->RestartableIp = json_object_get_boolean(
+ json_object_object_get(check_info, "restartableIP"));
+ check_info_cper->Overflow = json_object_get_boolean(
+ json_object_object_get(check_info, "overflow"));
}
//Converts a single CPER-JSON IA32/x64 bus error info structure to CPER binary.
-void ir_ia32x64_bus_check_error_to_cper(json_object* check_info, EFI_IA32_X64_BUS_CHECK_INFO* check_info_cper)
+void ir_ia32x64_bus_check_error_to_cper(
+ json_object *check_info, EFI_IA32_X64_BUS_CHECK_INFO *check_info_cper)
{
- //Validation bits.
- check_info_cper->ValidFields = ir_to_bitfield(json_object_object_get(check_info, "validationBits"),
- 11, IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ check_info_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(check_info, "validationBits"), 11,
+ IA32X64_CHECK_INFO_VALID_BITFIELD_NAMES);
- //Readable pair fields.
- check_info_cper->TransactionType = readable_pair_to_integer(json_object_object_get(check_info, "transactionType"));
- check_info_cper->Operation = readable_pair_to_integer(json_object_object_get(check_info, "operation"));
- check_info_cper->ParticipationType = readable_pair_to_integer(json_object_object_get(check_info, "participationType"));
- check_info_cper->AddressSpace = readable_pair_to_integer(json_object_object_get(check_info, "addressSpace"));
+ //Readable pair fields.
+ check_info_cper->TransactionType = readable_pair_to_integer(
+ json_object_object_get(check_info, "transactionType"));
+ check_info_cper->Operation = readable_pair_to_integer(
+ json_object_object_get(check_info, "operation"));
+ check_info_cper->ParticipationType = readable_pair_to_integer(
+ json_object_object_get(check_info, "participationType"));
+ check_info_cper->AddressSpace = readable_pair_to_integer(
+ json_object_object_get(check_info, "addressSpace"));
- //Miscellaneous raw value fields.
- check_info_cper->Level = json_object_get_uint64(json_object_object_get(check_info, "level"));
- check_info_cper->ContextCorrupt = json_object_get_boolean(json_object_object_get(check_info, "processorContextCorrupt"));
- check_info_cper->ErrorUncorrected = json_object_get_boolean(json_object_object_get(check_info, "uncorrected"));
- check_info_cper->PreciseIp = json_object_get_boolean(json_object_object_get(check_info, "preciseIP"));
- check_info_cper->RestartableIp = json_object_get_boolean(json_object_object_get(check_info, "restartableIP"));
- check_info_cper->Overflow = json_object_get_boolean(json_object_object_get(check_info, "overflow"));
- check_info_cper->TimeOut = json_object_get_boolean(json_object_object_get(check_info, "timedOut"));
+ //Miscellaneous raw value fields.
+ check_info_cper->Level = json_object_get_uint64(
+ json_object_object_get(check_info, "level"));
+ check_info_cper->ContextCorrupt = json_object_get_boolean(
+ json_object_object_get(check_info, "processorContextCorrupt"));
+ check_info_cper->ErrorUncorrected = json_object_get_boolean(
+ json_object_object_get(check_info, "uncorrected"));
+ check_info_cper->PreciseIp = json_object_get_boolean(
+ json_object_object_get(check_info, "preciseIP"));
+ check_info_cper->RestartableIp = json_object_get_boolean(
+ json_object_object_get(check_info, "restartableIP"));
+ check_info_cper->Overflow = json_object_get_boolean(
+ json_object_object_get(check_info, "overflow"));
+ check_info_cper->TimeOut = json_object_get_boolean(
+ json_object_object_get(check_info, "timedOut"));
}
//Converts a single CPER-JSON IA32/x64 MS error info structure to CPER binary.
-void ir_ia32x64_ms_check_error_to_cper(json_object* check_info, EFI_IA32_X64_MS_CHECK_INFO* check_info_cper)
+void ir_ia32x64_ms_check_error_to_cper(
+ json_object *check_info, EFI_IA32_X64_MS_CHECK_INFO *check_info_cper)
{
- //Validation bits.
- check_info_cper->ValidFields = ir_to_bitfield(json_object_object_get(check_info, "validationBits"),
- 6, IA32X64_CHECK_INFO_MS_CHECK_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ check_info_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(check_info, "validationBits"), 6,
+ IA32X64_CHECK_INFO_MS_CHECK_VALID_BITFIELD_NAMES);
- //Type of MS check error.
- check_info_cper->ErrorType = readable_pair_to_integer(json_object_object_get(check_info, "errorType"));
+ //Type of MS check error.
+ check_info_cper->ErrorType = readable_pair_to_integer(
+ json_object_object_get(check_info, "errorType"));
- //Miscellaneous raw value fields.
- check_info_cper->ContextCorrupt = json_object_get_boolean(json_object_object_get(check_info, "processorContextCorrupt"));
- check_info_cper->ErrorUncorrected = json_object_get_boolean(json_object_object_get(check_info, "uncorrected"));
- check_info_cper->PreciseIp = json_object_get_boolean(json_object_object_get(check_info, "preciseIP"));
- check_info_cper->RestartableIp = json_object_get_boolean(json_object_object_get(check_info, "restartableIP"));
- check_info_cper->Overflow = json_object_get_boolean(json_object_object_get(check_info, "overflow"));
+ //Miscellaneous raw value fields.
+ check_info_cper->ContextCorrupt = json_object_get_boolean(
+ json_object_object_get(check_info, "processorContextCorrupt"));
+ check_info_cper->ErrorUncorrected = json_object_get_boolean(
+ json_object_object_get(check_info, "uncorrected"));
+ check_info_cper->PreciseIp = json_object_get_boolean(
+ json_object_object_get(check_info, "preciseIP"));
+ check_info_cper->RestartableIp = json_object_get_boolean(
+ json_object_object_get(check_info, "restartableIP"));
+ check_info_cper->Overflow = json_object_get_boolean(
+ json_object_object_get(check_info, "overflow"));
}
//Converts a single CPER-JSON IA32/x64 context information structure into CPER binary, outputting to the
//provided stream.
-void ir_ia32x64_context_info_to_cper(json_object* context_info, FILE* out)
+void ir_ia32x64_context_info_to_cper(json_object *context_info, FILE *out)
{
- EFI_IA32_X64_PROCESSOR_CONTEXT_INFO* context_info_cper =
- (EFI_IA32_X64_PROCESSOR_CONTEXT_INFO*)calloc(1, sizeof(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO));
+ EFI_IA32_X64_PROCESSOR_CONTEXT_INFO *context_info_cper =
+ (EFI_IA32_X64_PROCESSOR_CONTEXT_INFO *)calloc(
+ 1, sizeof(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO));
- //Register context type.
- context_info_cper->RegisterType = (UINT16)readable_pair_to_integer(json_object_object_get(context_info, "registerContextType"));
+ //Register context type.
+ context_info_cper->RegisterType = (UINT16)readable_pair_to_integer(
+ json_object_object_get(context_info, "registerContextType"));
- //Miscellaneous numeric fields.
- context_info_cper->ArraySize = (UINT16)json_object_get_uint64(json_object_object_get(context_info, "registerArraySize"));
- context_info_cper->MsrAddress = (UINT32)json_object_get_uint64(json_object_object_get(context_info, "msrAddress"));
- context_info_cper->MmRegisterAddress = json_object_get_uint64(json_object_object_get(context_info, "mmRegisterAddress"));
+ //Miscellaneous numeric fields.
+ context_info_cper->ArraySize = (UINT16)json_object_get_uint64(
+ json_object_object_get(context_info, "registerArraySize"));
+ context_info_cper->MsrAddress = (UINT32)json_object_get_uint64(
+ json_object_object_get(context_info, "msrAddress"));
+ context_info_cper->MmRegisterAddress = json_object_get_uint64(
+ json_object_object_get(context_info, "mmRegisterAddress"));
- //Flush header to stream.
- fwrite(context_info_cper, sizeof(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO), 1, out);
- fflush(out);
+ //Flush header to stream.
+ fwrite(context_info_cper, sizeof(EFI_IA32_X64_PROCESSOR_CONTEXT_INFO),
+ 1, out);
+ fflush(out);
- //Handle the register array, depending on type provided.
- json_object* register_array = json_object_object_get(context_info, "registerArray");
- if (context_info_cper->RegisterType == EFI_REG_CONTEXT_TYPE_IA32)
- {
- ir_ia32x64_ia32_registers_to_cper(register_array, out);
- }
- else if (context_info_cper->RegisterType == EFI_REG_CONTEXT_TYPE_X64)
- {
- ir_ia32x64_x64_registers_to_cper(register_array, out);
- }
- else
- {
- //Unknown/structure is not defined.
- json_object* encoded = json_object_object_get(register_array, "data");
- char* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- fwrite(decoded, context_info_cper->ArraySize, 1, out);
- fflush(out);
- }
+ //Handle the register array, depending on type provided.
+ json_object *register_array =
+ json_object_object_get(context_info, "registerArray");
+ if (context_info_cper->RegisterType == EFI_REG_CONTEXT_TYPE_IA32) {
+ ir_ia32x64_ia32_registers_to_cper(register_array, out);
+ } else if (context_info_cper->RegisterType ==
+ EFI_REG_CONTEXT_TYPE_X64) {
+ ir_ia32x64_x64_registers_to_cper(register_array, out);
+ } else {
+ //Unknown/structure is not defined.
+ json_object *encoded =
+ json_object_object_get(register_array, "data");
+ char *decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ fwrite(decoded, context_info_cper->ArraySize, 1, out);
+ fflush(out);
+ }
- //Free remaining resources.
- free(context_info_cper);
+ //Free remaining resources.
+ free(context_info_cper);
}
//Converts a single CPER-JSON IA32 register array into CPER binary, outputting to the given stream.
-void ir_ia32x64_ia32_registers_to_cper(json_object* registers, FILE* out)
+void ir_ia32x64_ia32_registers_to_cper(json_object *registers, FILE *out)
{
- EFI_CONTEXT_IA32_REGISTER_STATE register_state;
- register_state.Eax = (UINT32)json_object_get_uint64(json_object_object_get(registers, "eax"));
- register_state.Ebx = (UINT32)json_object_get_uint64(json_object_object_get(registers, "ebx"));
- register_state.Ecx = (UINT32)json_object_get_uint64(json_object_object_get(registers, "ecx"));
- register_state.Edx = (UINT32)json_object_get_uint64(json_object_object_get(registers, "edx"));
- register_state.Esi = (UINT32)json_object_get_uint64(json_object_object_get(registers, "esi"));
- register_state.Edi = (UINT32)json_object_get_uint64(json_object_object_get(registers, "edi"));
- register_state.Ebp = (UINT32)json_object_get_uint64(json_object_object_get(registers, "ebp"));
- register_state.Esp = (UINT32)json_object_get_uint64(json_object_object_get(registers, "esp"));
- register_state.Cs = (UINT16)json_object_get_uint64(json_object_object_get(registers, "cs"));
- register_state.Ds = (UINT32)json_object_get_uint64(json_object_object_get(registers, "ds"));
- register_state.Ss = (UINT16)json_object_get_uint64(json_object_object_get(registers, "ss"));
- register_state.Es = (UINT16)json_object_get_uint64(json_object_object_get(registers, "es"));
- register_state.Fs = (UINT16)json_object_get_uint64(json_object_object_get(registers, "fs"));
- register_state.Gs = (UINT16)json_object_get_uint64(json_object_object_get(registers, "gs"));
- register_state.Eflags = (UINT32)json_object_get_uint64(json_object_object_get(registers, "eflags"));
- register_state.Eip = (UINT32)json_object_get_uint64(json_object_object_get(registers, "eip"));
- register_state.Cr0 = (UINT32)json_object_get_uint64(json_object_object_get(registers, "cr0"));
- register_state.Cr1 = (UINT32)json_object_get_uint64(json_object_object_get(registers, "cr1"));
- register_state.Cr2 = (UINT32)json_object_get_uint64(json_object_object_get(registers, "cr2"));
- register_state.Cr3 = (UINT32)json_object_get_uint64(json_object_object_get(registers, "cr3"));
- register_state.Cr4 = (UINT32)json_object_get_uint64(json_object_object_get(registers, "cr4"));
+ EFI_CONTEXT_IA32_REGISTER_STATE register_state;
+ register_state.Eax = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "eax"));
+ register_state.Ebx = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "ebx"));
+ register_state.Ecx = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "ecx"));
+ register_state.Edx = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "edx"));
+ register_state.Esi = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "esi"));
+ register_state.Edi = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "edi"));
+ register_state.Ebp = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "ebp"));
+ register_state.Esp = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "esp"));
+ register_state.Cs = (UINT16)json_object_get_uint64(
+ json_object_object_get(registers, "cs"));
+ register_state.Ds = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "ds"));
+ register_state.Ss = (UINT16)json_object_get_uint64(
+ json_object_object_get(registers, "ss"));
+ register_state.Es = (UINT16)json_object_get_uint64(
+ json_object_object_get(registers, "es"));
+ register_state.Fs = (UINT16)json_object_get_uint64(
+ json_object_object_get(registers, "fs"));
+ register_state.Gs = (UINT16)json_object_get_uint64(
+ json_object_object_get(registers, "gs"));
+ register_state.Eflags = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "eflags"));
+ register_state.Eip = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "eip"));
+ register_state.Cr0 = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "cr0"));
+ register_state.Cr1 = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "cr1"));
+ register_state.Cr2 = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "cr2"));
+ register_state.Cr3 = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "cr3"));
+ register_state.Cr4 = (UINT32)json_object_get_uint64(
+ json_object_object_get(registers, "cr4"));
- //64-bit registers are split into two 32-bit parts.
- UINT64 gdtr = json_object_get_uint64(json_object_object_get(registers, "gdtr"));
- register_state.Gdtr[0] = gdtr & 0xFFFFFFFF;
- register_state.Gdtr[1] = gdtr >> 32;
- UINT64 idtr = json_object_get_uint64(json_object_object_get(registers, "idtr"));
- register_state.Idtr[0] = idtr & 0xFFFFFFFF;
- register_state.Idtr[1] = idtr >> 32;
+ //64-bit registers are split into two 32-bit parts.
+ UINT64 gdtr = json_object_get_uint64(
+ json_object_object_get(registers, "gdtr"));
+ register_state.Gdtr[0] = gdtr & 0xFFFFFFFF;
+ register_state.Gdtr[1] = gdtr >> 32;
+ UINT64 idtr = json_object_get_uint64(
+ json_object_object_get(registers, "idtr"));
+ register_state.Idtr[0] = idtr & 0xFFFFFFFF;
+ register_state.Idtr[1] = idtr >> 32;
- //16-bit registers.
- register_state.Ldtr = (UINT16)json_object_get_uint64(json_object_object_get(registers, "ldtr"));
- register_state.Tr = (UINT16)json_object_get_uint64(json_object_object_get(registers, "tr"));
+ //16-bit registers.
+ register_state.Ldtr = (UINT16)json_object_get_uint64(
+ json_object_object_get(registers, "ldtr"));
+ register_state.Tr = (UINT16)json_object_get_uint64(
+ json_object_object_get(registers, "tr"));
- //Write out to stream.
- fwrite(®ister_state, sizeof(EFI_CONTEXT_IA32_REGISTER_STATE), 1, out);
- fflush(out);
+ //Write out to stream.
+ fwrite(®ister_state, sizeof(EFI_CONTEXT_IA32_REGISTER_STATE), 1,
+ out);
+ fflush(out);
}
//Converts a single CPER-JSON x64 register array into CPER binary, outputting to the given stream.
-void ir_ia32x64_x64_registers_to_cper(json_object* registers, FILE* out)
+void ir_ia32x64_x64_registers_to_cper(json_object *registers, FILE *out)
{
- EFI_CONTEXT_X64_REGISTER_STATE register_state;
- register_state.Rax = json_object_get_uint64(json_object_object_get(registers, "rax"));
- register_state.Rbx = json_object_get_uint64(json_object_object_get(registers, "rbx"));
- register_state.Rcx = json_object_get_uint64(json_object_object_get(registers, "rcx"));
- register_state.Rdx = json_object_get_uint64(json_object_object_get(registers, "rdx"));
- register_state.Rsi = json_object_get_uint64(json_object_object_get(registers, "rsi"));
- register_state.Rdi = json_object_get_uint64(json_object_object_get(registers, "rdi"));
- register_state.Rbp = json_object_get_uint64(json_object_object_get(registers, "rbp"));
- register_state.Rsp = json_object_get_uint64(json_object_object_get(registers, "rsp"));
- register_state.R8 = json_object_get_uint64(json_object_object_get(registers, "r8"));
- register_state.R9 = json_object_get_uint64(json_object_object_get(registers, "r9"));
- register_state.R10 = json_object_get_uint64(json_object_object_get(registers, "r10"));
- register_state.R11 = json_object_get_uint64(json_object_object_get(registers, "r11"));
- register_state.R12 = json_object_get_uint64(json_object_object_get(registers, "r12"));
- register_state.R13 = json_object_get_uint64(json_object_object_get(registers, "r13"));
- register_state.R14 = json_object_get_uint64(json_object_object_get(registers, "r14"));
- register_state.R15 = json_object_get_uint64(json_object_object_get(registers, "r15"));
- register_state.Cs = (UINT16)json_object_get_int(json_object_object_get(registers, "cs"));
- register_state.Ds = (UINT16)json_object_get_int(json_object_object_get(registers, "ds"));
- register_state.Ss = (UINT16)json_object_get_int(json_object_object_get(registers, "ss"));
- register_state.Es = (UINT16)json_object_get_int(json_object_object_get(registers, "es"));
- register_state.Fs = (UINT16)json_object_get_int(json_object_object_get(registers, "fs"));
- register_state.Gs = (UINT16)json_object_get_int(json_object_object_get(registers, "gs"));
- register_state.Resv1 = 0;
- register_state.Rflags = json_object_get_uint64(json_object_object_get(registers, "rflags"));
- register_state.Rip = json_object_get_uint64(json_object_object_get(registers, "eip"));
- register_state.Cr0 = json_object_get_uint64(json_object_object_get(registers, "cr0"));
- register_state.Cr1 = json_object_get_uint64(json_object_object_get(registers, "cr1"));
- register_state.Cr2 = json_object_get_uint64(json_object_object_get(registers, "cr2"));
- register_state.Cr3 = json_object_get_uint64(json_object_object_get(registers, "cr3"));
- register_state.Cr4 = json_object_get_uint64(json_object_object_get(registers, "cr4"));
- register_state.Cr8 = json_object_get_uint64(json_object_object_get(registers, "cr8"));
- register_state.Gdtr[0] = json_object_get_uint64(json_object_object_get(registers, "gdtr_0"));
- register_state.Gdtr[1] = json_object_get_uint64(json_object_object_get(registers, "gdtr_1"));
- register_state.Idtr[0] = json_object_get_uint64(json_object_object_get(registers, "idtr_0"));
- register_state.Idtr[1] = json_object_get_uint64(json_object_object_get(registers, "idtr_1"));
- register_state.Ldtr = (UINT16)json_object_get_int(json_object_object_get(registers, "ldtr"));
- register_state.Tr = (UINT16)json_object_get_int(json_object_object_get(registers, "tr"));
+ EFI_CONTEXT_X64_REGISTER_STATE register_state;
+ register_state.Rax = json_object_get_uint64(
+ json_object_object_get(registers, "rax"));
+ register_state.Rbx = json_object_get_uint64(
+ json_object_object_get(registers, "rbx"));
+ register_state.Rcx = json_object_get_uint64(
+ json_object_object_get(registers, "rcx"));
+ register_state.Rdx = json_object_get_uint64(
+ json_object_object_get(registers, "rdx"));
+ register_state.Rsi = json_object_get_uint64(
+ json_object_object_get(registers, "rsi"));
+ register_state.Rdi = json_object_get_uint64(
+ json_object_object_get(registers, "rdi"));
+ register_state.Rbp = json_object_get_uint64(
+ json_object_object_get(registers, "rbp"));
+ register_state.Rsp = json_object_get_uint64(
+ json_object_object_get(registers, "rsp"));
+ register_state.R8 =
+ json_object_get_uint64(json_object_object_get(registers, "r8"));
+ register_state.R9 =
+ json_object_get_uint64(json_object_object_get(registers, "r9"));
+ register_state.R10 = json_object_get_uint64(
+ json_object_object_get(registers, "r10"));
+ register_state.R11 = json_object_get_uint64(
+ json_object_object_get(registers, "r11"));
+ register_state.R12 = json_object_get_uint64(
+ json_object_object_get(registers, "r12"));
+ register_state.R13 = json_object_get_uint64(
+ json_object_object_get(registers, "r13"));
+ register_state.R14 = json_object_get_uint64(
+ json_object_object_get(registers, "r14"));
+ register_state.R15 = json_object_get_uint64(
+ json_object_object_get(registers, "r15"));
+ register_state.Cs = (UINT16)json_object_get_int(
+ json_object_object_get(registers, "cs"));
+ register_state.Ds = (UINT16)json_object_get_int(
+ json_object_object_get(registers, "ds"));
+ register_state.Ss = (UINT16)json_object_get_int(
+ json_object_object_get(registers, "ss"));
+ register_state.Es = (UINT16)json_object_get_int(
+ json_object_object_get(registers, "es"));
+ register_state.Fs = (UINT16)json_object_get_int(
+ json_object_object_get(registers, "fs"));
+ register_state.Gs = (UINT16)json_object_get_int(
+ json_object_object_get(registers, "gs"));
+ register_state.Resv1 = 0;
+ register_state.Rflags = json_object_get_uint64(
+ json_object_object_get(registers, "rflags"));
+ register_state.Rip = json_object_get_uint64(
+ json_object_object_get(registers, "eip"));
+ register_state.Cr0 = json_object_get_uint64(
+ json_object_object_get(registers, "cr0"));
+ register_state.Cr1 = json_object_get_uint64(
+ json_object_object_get(registers, "cr1"));
+ register_state.Cr2 = json_object_get_uint64(
+ json_object_object_get(registers, "cr2"));
+ register_state.Cr3 = json_object_get_uint64(
+ json_object_object_get(registers, "cr3"));
+ register_state.Cr4 = json_object_get_uint64(
+ json_object_object_get(registers, "cr4"));
+ register_state.Cr8 = json_object_get_uint64(
+ json_object_object_get(registers, "cr8"));
+ register_state.Gdtr[0] = json_object_get_uint64(
+ json_object_object_get(registers, "gdtr_0"));
+ register_state.Gdtr[1] = json_object_get_uint64(
+ json_object_object_get(registers, "gdtr_1"));
+ register_state.Idtr[0] = json_object_get_uint64(
+ json_object_object_get(registers, "idtr_0"));
+ register_state.Idtr[1] = json_object_get_uint64(
+ json_object_object_get(registers, "idtr_1"));
+ register_state.Ldtr = (UINT16)json_object_get_int(
+ json_object_object_get(registers, "ldtr"));
+ register_state.Tr = (UINT16)json_object_get_int(
+ json_object_object_get(registers, "tr"));
- //Write out to stream.
- fwrite(®ister_state, sizeof(EFI_CONTEXT_X64_REGISTER_STATE), 1, out);
- fflush(out);
+ //Write out to stream.
+ fwrite(®ister_state, sizeof(EFI_CONTEXT_X64_REGISTER_STATE), 1, out);
+ fflush(out);
}
\ No newline at end of file
diff --git a/sections/cper-section-ipf.c b/sections/cper-section-ipf.c
index 0c065cc..b014d5d 100644
--- a/sections/cper-section-ipf.c
+++ b/sections/cper-section-ipf.c
@@ -10,99 +10,159 @@
#include "../cper-utils.h"
#include "cper-section-ipf.h"
-json_object* cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO** cur_error, int num_to_read);
-json_object* cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO* mod_error);
+json_object *cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO **cur_error,
+ int num_to_read);
+json_object *cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO *mod_error);
//Converts a single Intel IPF error CPER section into JSON IR.
-json_object* cper_section_ipf_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *cper_section_ipf_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_IPF_ERROR_INFO_HEADER* ipf_error = (EFI_IPF_ERROR_INFO_HEADER*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_IPF_ERROR_INFO_HEADER *ipf_error =
+ (EFI_IPF_ERROR_INFO_HEADER *)section;
+ json_object *section_ir = json_object_new_object();
- //Validation bits.
- json_object* validation = json_object_new_object();
- json_object_object_add(validation, "errorMapValid", json_object_new_boolean(ipf_error->ValidBits.ProcErrorMapValid));
- json_object_object_add(validation, "stateParameterValid", json_object_new_boolean(ipf_error->ValidBits.ProcErrorMapValid));
- json_object_object_add(validation, "crLIDValid", json_object_new_boolean(ipf_error->ValidBits.ProcCrLidValid));
- json_object_object_add(validation, "psiStaticStructValid", json_object_new_boolean(ipf_error->ValidBits.PsiStaticStructValid));
- json_object_object_add(validation, "cpuInfoValid", json_object_new_boolean(ipf_error->ValidBits.CpuIdInfoValid));
- json_object_object_add(section_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation = json_object_new_object();
+ json_object_object_add(validation, "errorMapValid",
+ json_object_new_boolean(
+ ipf_error->ValidBits.ProcErrorMapValid));
+ json_object_object_add(validation, "stateParameterValid",
+ json_object_new_boolean(
+ ipf_error->ValidBits.ProcErrorMapValid));
+ json_object_object_add(
+ validation, "crLIDValid",
+ json_object_new_boolean(ipf_error->ValidBits.ProcCrLidValid));
+ json_object_object_add(
+ validation, "psiStaticStructValid",
+ json_object_new_boolean(
+ ipf_error->ValidBits.PsiStaticStructValid));
+ json_object_object_add(
+ validation, "cpuInfoValid",
+ json_object_new_boolean(ipf_error->ValidBits.CpuIdInfoValid));
+ json_object_object_add(section_ir, "validationBits", validation);
- //Numbers of various variable length segments.
- json_object_object_add(section_ir, "cacheCheckNum", json_object_new_uint64(ipf_error->ValidBits.CacheCheckNum));
- json_object_object_add(section_ir, "tlbCheckNum", json_object_new_uint64(ipf_error->ValidBits.TlbCheckNum));
- json_object_object_add(section_ir, "busCheckNum", json_object_new_uint64(ipf_error->ValidBits.BusCheckNum));
- json_object_object_add(section_ir, "regFileCheckNum", json_object_new_uint64(ipf_error->ValidBits.RegFileCheckNum));
- json_object_object_add(section_ir, "msCheckNum", json_object_new_uint64(ipf_error->ValidBits.MsCheckNum));
+ //Numbers of various variable length segments.
+ json_object_object_add(
+ section_ir, "cacheCheckNum",
+ json_object_new_uint64(ipf_error->ValidBits.CacheCheckNum));
+ json_object_object_add(
+ section_ir, "tlbCheckNum",
+ json_object_new_uint64(ipf_error->ValidBits.TlbCheckNum));
+ json_object_object_add(
+ section_ir, "busCheckNum",
+ json_object_new_uint64(ipf_error->ValidBits.BusCheckNum));
+ json_object_object_add(
+ section_ir, "regFileCheckNum",
+ json_object_new_uint64(ipf_error->ValidBits.RegFileCheckNum));
+ json_object_object_add(
+ section_ir, "msCheckNum",
+ json_object_new_uint64(ipf_error->ValidBits.MsCheckNum));
- //Process error map, state params/CR LID.
- json_object_object_add(section_ir, "procErrorMap", json_object_new_uint64(ipf_error->ProcErrorMap));
- json_object_object_add(section_ir, "procStateParameter", json_object_new_uint64(ipf_error->ProcStateParameter));
- json_object_object_add(section_ir, "procCRLID", json_object_new_uint64(ipf_error->ProcCrLid));
+ //Process error map, state params/CR LID.
+ json_object_object_add(section_ir, "procErrorMap",
+ json_object_new_uint64(ipf_error->ProcErrorMap));
+ json_object_object_add(
+ section_ir, "procStateParameter",
+ json_object_new_uint64(ipf_error->ProcStateParameter));
+ json_object_object_add(section_ir, "procCRLID",
+ json_object_new_uint64(ipf_error->ProcCrLid));
- //Read cache, TLB, bus, register file, MS errors.
- EFI_IPF_MOD_ERROR_INFO* cur_error = (EFI_IPF_MOD_ERROR_INFO*)(ipf_error + 1);
- json_object_object_add(section_ir, "cacheErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.CacheCheckNum));
- json_object_object_add(section_ir, "tlbErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.TlbCheckNum));
- json_object_object_add(section_ir, "busErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.BusCheckNum));
- json_object_object_add(section_ir, "regFileErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.RegFileCheckNum));
- json_object_object_add(section_ir, "msErrors", cper_ipf_mod_error_read_array(&cur_error, ipf_error->ValidBits.MsCheckNum));
-
- //CPU ID information.
- EFI_IPF_CPU_INFO* cpu_info = (EFI_IPF_CPU_INFO*)cur_error;
- //stretch: find out how this is represented
+ //Read cache, TLB, bus, register file, MS errors.
+ EFI_IPF_MOD_ERROR_INFO *cur_error =
+ (EFI_IPF_MOD_ERROR_INFO *)(ipf_error + 1);
+ json_object_object_add(section_ir, "cacheErrors",
+ cper_ipf_mod_error_read_array(
+ &cur_error,
+ ipf_error->ValidBits.CacheCheckNum));
+ json_object_object_add(section_ir, "tlbErrors",
+ cper_ipf_mod_error_read_array(
+ &cur_error,
+ ipf_error->ValidBits.TlbCheckNum));
+ json_object_object_add(section_ir, "busErrors",
+ cper_ipf_mod_error_read_array(
+ &cur_error,
+ ipf_error->ValidBits.BusCheckNum));
+ json_object_object_add(section_ir, "regFileErrors",
+ cper_ipf_mod_error_read_array(
+ &cur_error,
+ ipf_error->ValidBits.RegFileCheckNum));
+ json_object_object_add(
+ section_ir, "msErrors",
+ cper_ipf_mod_error_read_array(&cur_error,
+ ipf_error->ValidBits.MsCheckNum));
- //Processor static information.
- EFI_IPF_PSI_STATIC* psi_static = (EFI_IPF_PSI_STATIC*)(cpu_info + 1);
- json_object* psi_static_ir = json_object_new_object();
-
- //PSI validation bits.
- json_object* psi_validation = bitfield_to_ir(psi_static->ValidBits, 6, IPF_PSI_STATIC_INFO_VALID_BITFIELD_NAMES);
- json_object_object_add(psi_static_ir, "validationBits", psi_validation);
+ //CPU ID information.
+ EFI_IPF_CPU_INFO *cpu_info = (EFI_IPF_CPU_INFO *)cur_error;
+ //stretch: find out how this is represented
- //PSI minimal state save info.
- //stretch: structure min save state area as in Intel Itanium Architecture Software Developer's Manual.
+ //Processor static information.
+ EFI_IPF_PSI_STATIC *psi_static = (EFI_IPF_PSI_STATIC *)(cpu_info + 1);
+ json_object *psi_static_ir = json_object_new_object();
- //BRs, CRs, ARs, RRs, FRs.
- json_object_object_add(psi_static_ir, "brs", uint64_array_to_ir_array(psi_static->Brs, 8));
- json_object_object_add(psi_static_ir, "crs", uint64_array_to_ir_array(psi_static->Crs, 128));
- json_object_object_add(psi_static_ir, "ars", uint64_array_to_ir_array(psi_static->Ars, 128));
- json_object_object_add(psi_static_ir, "rrs", uint64_array_to_ir_array(psi_static->Rrs, 8));
- json_object_object_add(psi_static_ir, "frs", uint64_array_to_ir_array(psi_static->Frs, 256));
- json_object_object_add(section_ir, "psiStaticInfo", psi_static_ir);
+ //PSI validation bits.
+ json_object *psi_validation =
+ bitfield_to_ir(psi_static->ValidBits, 6,
+ IPF_PSI_STATIC_INFO_VALID_BITFIELD_NAMES);
+ json_object_object_add(psi_static_ir, "validationBits", psi_validation);
- return section_ir;
+ //PSI minimal state save info.
+ //stretch: structure min save state area as in Intel Itanium Architecture Software Developer's Manual.
+
+ //BRs, CRs, ARs, RRs, FRs.
+ json_object_object_add(psi_static_ir, "brs",
+ uint64_array_to_ir_array(psi_static->Brs, 8));
+ json_object_object_add(psi_static_ir, "crs",
+ uint64_array_to_ir_array(psi_static->Crs, 128));
+ json_object_object_add(psi_static_ir, "ars",
+ uint64_array_to_ir_array(psi_static->Ars, 128));
+ json_object_object_add(psi_static_ir, "rrs",
+ uint64_array_to_ir_array(psi_static->Rrs, 8));
+ json_object_object_add(psi_static_ir, "frs",
+ uint64_array_to_ir_array(psi_static->Frs, 256));
+ json_object_object_add(section_ir, "psiStaticInfo", psi_static_ir);
+
+ return section_ir;
}
//Reads a continuous stream of CPER IPF mod errors beginning from the given pointer, for n entries.
//Returns an array containing all read entries as JSON IR.
-json_object* cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO** cur_error, int num_to_read)
+json_object *cper_ipf_mod_error_read_array(EFI_IPF_MOD_ERROR_INFO **cur_error,
+ int num_to_read)
{
- json_object* error_array = json_object_new_array();
- for (int i=0; i<num_to_read; i++)
- {
- json_object_array_add(error_array, cper_ipf_mod_error_to_ir(*cur_error));
- *cur_error = *cur_error + 1;
- }
+ json_object *error_array = json_object_new_array();
+ for (int i = 0; i < num_to_read; i++) {
+ json_object_array_add(error_array,
+ cper_ipf_mod_error_to_ir(*cur_error));
+ *cur_error = *cur_error + 1;
+ }
- return error_array;
+ return error_array;
}
//Converts a single CPER IPF mod error info structure into JSON IR.
-json_object* cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO* mod_error)
+json_object *cper_ipf_mod_error_to_ir(EFI_IPF_MOD_ERROR_INFO *mod_error)
{
- json_object* mod_error_ir = json_object_new_object();
-
- //Validation bits.
- json_object* validation = bitfield_to_ir(mod_error->ValidBits, 5, IPF_MOD_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(mod_error_ir, "validationBits", validation);
+ json_object *mod_error_ir = json_object_new_object();
- //Numeric fields.
- json_object_object_add(mod_error_ir, "modCheckInfo", json_object_new_uint64(mod_error->ModCheckInfo));
- json_object_object_add(mod_error_ir, "modTargetID", json_object_new_uint64(mod_error->ModTargetId));
- json_object_object_add(mod_error_ir, "modRequestorID", json_object_new_uint64(mod_error->ModRequestorId));
- json_object_object_add(mod_error_ir, "modResponderID", json_object_new_uint64(mod_error->ModResponderId));
- json_object_object_add(mod_error_ir, "modPreciseIP", json_object_new_uint64(mod_error->ModPreciseIp));
+ //Validation bits.
+ json_object *validation = bitfield_to_ir(
+ mod_error->ValidBits, 5, IPF_MOD_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(mod_error_ir, "validationBits", validation);
- return mod_error_ir;
+ //Numeric fields.
+ json_object_object_add(mod_error_ir, "modCheckInfo",
+ json_object_new_uint64(mod_error->ModCheckInfo));
+ json_object_object_add(mod_error_ir, "modTargetID",
+ json_object_new_uint64(mod_error->ModTargetId));
+ json_object_object_add(
+ mod_error_ir, "modRequestorID",
+ json_object_new_uint64(mod_error->ModRequestorId));
+ json_object_object_add(
+ mod_error_ir, "modResponderID",
+ json_object_new_uint64(mod_error->ModResponderId));
+ json_object_object_add(mod_error_ir, "modPreciseIP",
+ json_object_new_uint64(mod_error->ModPreciseIp));
+
+ return mod_error_ir;
}
\ No newline at end of file
diff --git a/sections/cper-section-memory.c b/sections/cper-section-memory.c
index 8cd7f0b..af507fd 100644
--- a/sections/cper-section-memory.c
+++ b/sections/cper-section-memory.c
@@ -11,240 +11,363 @@
#include "cper-section-memory.h"
//Converts a single memory error CPER section into JSON IR.
-json_object* cper_section_platform_memory_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_platform_memory_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_PLATFORM_MEMORY_ERROR_DATA* memory_error = (EFI_PLATFORM_MEMORY_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_PLATFORM_MEMORY_ERROR_DATA *memory_error =
+ (EFI_PLATFORM_MEMORY_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Validation bitfield.
- json_object* validation = bitfield_to_ir(memory_error->ValidFields, 22, MEMORY_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ //Validation bitfield.
+ json_object *validation =
+ bitfield_to_ir(memory_error->ValidFields, 22,
+ MEMORY_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_ir, "validationBits", validation);
- //Error status.
- json_object* error_status = cper_generic_error_status_to_ir(&memory_error->ErrorStatus);
- json_object_object_add(section_ir, "errorStatus", error_status);
+ //Error status.
+ json_object *error_status =
+ cper_generic_error_status_to_ir(&memory_error->ErrorStatus);
+ json_object_object_add(section_ir, "errorStatus", error_status);
- //Bank.
- json_object* bank = json_object_new_object();
- if ((memory_error->ValidFields >> 5) & 0x1)
- {
- //Entire bank address mode.
- json_object_object_add(bank, "value", json_object_new_uint64(memory_error->Bank));
- }
- else
- {
- //Address/group address mode.
- json_object_object_add(bank, "address", json_object_new_uint64(memory_error->Bank & 0xFF));
- json_object_object_add(bank, "group", json_object_new_uint64(memory_error->Bank >> 8));
- }
- json_object_object_add(section_ir, "bank", bank);
+ //Bank.
+ json_object *bank = json_object_new_object();
+ if ((memory_error->ValidFields >> 5) & 0x1) {
+ //Entire bank address mode.
+ json_object_object_add(
+ bank, "value",
+ json_object_new_uint64(memory_error->Bank));
+ } else {
+ //Address/group address mode.
+ json_object_object_add(
+ bank, "address",
+ json_object_new_uint64(memory_error->Bank & 0xFF));
+ json_object_object_add(
+ bank, "group",
+ json_object_new_uint64(memory_error->Bank >> 8));
+ }
+ json_object_object_add(section_ir, "bank", bank);
- //Memory error type.
- json_object* memory_error_type = integer_to_readable_pair(memory_error->ErrorType, 16,
- MEMORY_ERROR_TYPES_KEYS,
- MEMORY_ERROR_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(section_ir, "memoryErrorType", memory_error_type);
+ //Memory error type.
+ json_object *memory_error_type = integer_to_readable_pair(
+ memory_error->ErrorType, 16, MEMORY_ERROR_TYPES_KEYS,
+ MEMORY_ERROR_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(section_ir, "memoryErrorType",
+ memory_error_type);
- //"Extended" row/column indication field + misc.
- json_object* extended = json_object_new_object();
- json_object_object_add(extended, "rowBit16", json_object_new_boolean(memory_error->Extended & 0b1));
- json_object_object_add(extended, "rowBit17", json_object_new_boolean((memory_error->Extended >> 1) & 0b1));
- json_object_object_add(extended, "chipIdentification", json_object_new_int(memory_error->Extended >> 5));
- json_object_object_add(section_ir, "extended", extended);
+ //"Extended" row/column indication field + misc.
+ json_object *extended = json_object_new_object();
+ json_object_object_add(extended, "rowBit16",
+ json_object_new_boolean(memory_error->Extended &
+ 0b1));
+ json_object_object_add(
+ extended, "rowBit17",
+ json_object_new_boolean((memory_error->Extended >> 1) & 0b1));
+ json_object_object_add(extended, "chipIdentification",
+ json_object_new_int(memory_error->Extended >>
+ 5));
+ json_object_object_add(section_ir, "extended", extended);
- //Miscellaneous numeric fields.
- json_object_object_add(section_ir, "physicalAddress", json_object_new_uint64(memory_error->PhysicalAddress));
- json_object_object_add(section_ir, "physicalAddressMask", json_object_new_uint64(memory_error->PhysicalAddressMask));
- json_object_object_add(section_ir, "node", json_object_new_uint64(memory_error->Node));
- json_object_object_add(section_ir, "card", json_object_new_uint64(memory_error->Card));
- json_object_object_add(section_ir, "moduleRank", json_object_new_uint64(memory_error->ModuleRank));
- json_object_object_add(section_ir, "device", json_object_new_uint64(memory_error->Device));
- json_object_object_add(section_ir, "row", json_object_new_uint64(memory_error->Row));
- json_object_object_add(section_ir, "column", json_object_new_uint64(memory_error->Column));
- json_object_object_add(section_ir, "bitPosition", json_object_new_uint64(memory_error->BitPosition));
- json_object_object_add(section_ir, "requestorID", json_object_new_uint64(memory_error->RequestorId));
- json_object_object_add(section_ir, "responderID", json_object_new_uint64(memory_error->ResponderId));
- json_object_object_add(section_ir, "targetID", json_object_new_uint64(memory_error->TargetId));
- json_object_object_add(section_ir, "rankNumber", json_object_new_uint64(memory_error->RankNum));
- json_object_object_add(section_ir, "cardSmbiosHandle", json_object_new_uint64(memory_error->CardHandle));
- json_object_object_add(section_ir, "moduleSmbiosHandle", json_object_new_uint64(memory_error->ModuleHandle));
+ //Miscellaneous numeric fields.
+ json_object_object_add(
+ section_ir, "physicalAddress",
+ json_object_new_uint64(memory_error->PhysicalAddress));
+ json_object_object_add(
+ section_ir, "physicalAddressMask",
+ json_object_new_uint64(memory_error->PhysicalAddressMask));
+ json_object_object_add(section_ir, "node",
+ json_object_new_uint64(memory_error->Node));
+ json_object_object_add(section_ir, "card",
+ json_object_new_uint64(memory_error->Card));
+ json_object_object_add(
+ section_ir, "moduleRank",
+ json_object_new_uint64(memory_error->ModuleRank));
+ json_object_object_add(section_ir, "device",
+ json_object_new_uint64(memory_error->Device));
+ json_object_object_add(section_ir, "row",
+ json_object_new_uint64(memory_error->Row));
+ json_object_object_add(section_ir, "column",
+ json_object_new_uint64(memory_error->Column));
+ json_object_object_add(
+ section_ir, "bitPosition",
+ json_object_new_uint64(memory_error->BitPosition));
+ json_object_object_add(
+ section_ir, "requestorID",
+ json_object_new_uint64(memory_error->RequestorId));
+ json_object_object_add(
+ section_ir, "responderID",
+ json_object_new_uint64(memory_error->ResponderId));
+ json_object_object_add(section_ir, "targetID",
+ json_object_new_uint64(memory_error->TargetId));
+ json_object_object_add(section_ir, "rankNumber",
+ json_object_new_uint64(memory_error->RankNum));
+ json_object_object_add(
+ section_ir, "cardSmbiosHandle",
+ json_object_new_uint64(memory_error->CardHandle));
+ json_object_object_add(
+ section_ir, "moduleSmbiosHandle",
+ json_object_new_uint64(memory_error->ModuleHandle));
- return section_ir;
+ return section_ir;
}
//Converts a single memory error 2 CPER section into JSON IR.
-json_object* cper_section_platform_memory2_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_platform_memory2_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_PLATFORM_MEMORY2_ERROR_DATA* memory_error = (EFI_PLATFORM_MEMORY2_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_PLATFORM_MEMORY2_ERROR_DATA *memory_error =
+ (EFI_PLATFORM_MEMORY2_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Validation bits.
- json_object* validation = bitfield_to_ir(memory_error->ValidFields, 22, MEMORY_ERROR_2_VALID_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation =
+ bitfield_to_ir(memory_error->ValidFields, 22,
+ MEMORY_ERROR_2_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_ir, "validationBits", validation);
- //Error status.
- json_object* error_status = cper_generic_error_status_to_ir(&memory_error->ErrorStatus);
- json_object_object_add(section_ir, "errorStatus", error_status);
+ //Error status.
+ json_object *error_status =
+ cper_generic_error_status_to_ir(&memory_error->ErrorStatus);
+ json_object_object_add(section_ir, "errorStatus", error_status);
- //Bank.
- json_object* bank = json_object_new_object();
- if ((memory_error->ValidFields >> 5) & 0x1)
- {
- //Entire bank address mode.
- json_object_object_add(bank, "value", json_object_new_uint64(memory_error->Bank));
- }
- else
- {
- //Address/group address mode.
- json_object_object_add(bank, "address", json_object_new_uint64(memory_error->Bank & 0xFF));
- json_object_object_add(bank, "group", json_object_new_uint64(memory_error->Bank >> 8));
- }
- json_object_object_add(section_ir, "bank", bank);
+ //Bank.
+ json_object *bank = json_object_new_object();
+ if ((memory_error->ValidFields >> 5) & 0x1) {
+ //Entire bank address mode.
+ json_object_object_add(
+ bank, "value",
+ json_object_new_uint64(memory_error->Bank));
+ } else {
+ //Address/group address mode.
+ json_object_object_add(
+ bank, "address",
+ json_object_new_uint64(memory_error->Bank & 0xFF));
+ json_object_object_add(
+ bank, "group",
+ json_object_new_uint64(memory_error->Bank >> 8));
+ }
+ json_object_object_add(section_ir, "bank", bank);
- //Memory error type.
- json_object* memory_error_type = integer_to_readable_pair(memory_error->MemErrorType, 16,
- MEMORY_ERROR_TYPES_KEYS,
- MEMORY_ERROR_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(section_ir, "memoryErrorType", memory_error_type);
+ //Memory error type.
+ json_object *memory_error_type = integer_to_readable_pair(
+ memory_error->MemErrorType, 16, MEMORY_ERROR_TYPES_KEYS,
+ MEMORY_ERROR_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(section_ir, "memoryErrorType",
+ memory_error_type);
- //Status.
- json_object* status = json_object_new_object();
- json_object_object_add(status, "value", json_object_new_int(memory_error->Status));
- json_object_object_add(status, "state", json_object_new_string(memory_error->Status & 0b1 == 0 ? "Corrected" : "Uncorrected"));
- json_object_object_add(section_ir, "status", status);
+ //Status.
+ json_object *status = json_object_new_object();
+ json_object_object_add(status, "value",
+ json_object_new_int(memory_error->Status));
+ json_object_object_add(status, "state",
+ json_object_new_string(memory_error->Status &
+ 0b1 == 0 ?
+ "Corrected" :
+ "Uncorrected"));
+ json_object_object_add(section_ir, "status", status);
- //Miscellaneous numeric fields.
- json_object_object_add(section_ir, "physicalAddress", json_object_new_uint64(memory_error->PhysicalAddress));
- json_object_object_add(section_ir, "physicalAddressMask", json_object_new_uint64(memory_error->PhysicalAddressMask));
- json_object_object_add(section_ir, "node", json_object_new_uint64(memory_error->Node));
- json_object_object_add(section_ir, "card", json_object_new_uint64(memory_error->Card));
- json_object_object_add(section_ir, "module", json_object_new_uint64(memory_error->Module));
- json_object_object_add(section_ir, "device", json_object_new_uint64(memory_error->Device));
- json_object_object_add(section_ir, "row", json_object_new_uint64(memory_error->Row));
- json_object_object_add(section_ir, "column", json_object_new_uint64(memory_error->Column));
- json_object_object_add(section_ir, "rank", json_object_new_uint64(memory_error->Rank));
- json_object_object_add(section_ir, "bitPosition", json_object_new_uint64(memory_error->BitPosition));
- json_object_object_add(section_ir, "chipID", json_object_new_uint64(memory_error->ChipId));
- json_object_object_add(section_ir, "requestorID", json_object_new_uint64(memory_error->RequestorId));
- json_object_object_add(section_ir, "responderID", json_object_new_uint64(memory_error->ResponderId));
- json_object_object_add(section_ir, "targetID", json_object_new_uint64(memory_error->TargetId));
- json_object_object_add(section_ir, "cardSmbiosHandle", json_object_new_uint64(memory_error->CardHandle));
- json_object_object_add(section_ir, "moduleSmbiosHandle", json_object_new_uint64(memory_error->ModuleHandle));
-
- return section_ir;
+ //Miscellaneous numeric fields.
+ json_object_object_add(
+ section_ir, "physicalAddress",
+ json_object_new_uint64(memory_error->PhysicalAddress));
+ json_object_object_add(
+ section_ir, "physicalAddressMask",
+ json_object_new_uint64(memory_error->PhysicalAddressMask));
+ json_object_object_add(section_ir, "node",
+ json_object_new_uint64(memory_error->Node));
+ json_object_object_add(section_ir, "card",
+ json_object_new_uint64(memory_error->Card));
+ json_object_object_add(section_ir, "module",
+ json_object_new_uint64(memory_error->Module));
+ json_object_object_add(section_ir, "device",
+ json_object_new_uint64(memory_error->Device));
+ json_object_object_add(section_ir, "row",
+ json_object_new_uint64(memory_error->Row));
+ json_object_object_add(section_ir, "column",
+ json_object_new_uint64(memory_error->Column));
+ json_object_object_add(section_ir, "rank",
+ json_object_new_uint64(memory_error->Rank));
+ json_object_object_add(
+ section_ir, "bitPosition",
+ json_object_new_uint64(memory_error->BitPosition));
+ json_object_object_add(section_ir, "chipID",
+ json_object_new_uint64(memory_error->ChipId));
+ json_object_object_add(
+ section_ir, "requestorID",
+ json_object_new_uint64(memory_error->RequestorId));
+ json_object_object_add(
+ section_ir, "responderID",
+ json_object_new_uint64(memory_error->ResponderId));
+ json_object_object_add(section_ir, "targetID",
+ json_object_new_uint64(memory_error->TargetId));
+ json_object_object_add(
+ section_ir, "cardSmbiosHandle",
+ json_object_new_uint64(memory_error->CardHandle));
+ json_object_object_add(
+ section_ir, "moduleSmbiosHandle",
+ json_object_new_uint64(memory_error->ModuleHandle));
+
+ return section_ir;
}
//Converts a single Memory Error IR section into CPER binary, outputting to the provided stream.
-void ir_section_memory_to_cper(json_object* section, FILE* out)
+void ir_section_memory_to_cper(json_object *section, FILE *out)
{
- EFI_PLATFORM_MEMORY_ERROR_DATA* section_cper =
- (EFI_PLATFORM_MEMORY_ERROR_DATA*)calloc(1, sizeof(EFI_PLATFORM_MEMORY_ERROR_DATA));
+ EFI_PLATFORM_MEMORY_ERROR_DATA *section_cper =
+ (EFI_PLATFORM_MEMORY_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_PLATFORM_MEMORY_ERROR_DATA));
- //Validation bits.
- section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 22, MEMORY_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ section_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 22,
+ MEMORY_ERROR_VALID_BITFIELD_NAMES);
- //Error status.
- ir_generic_error_status_to_cper(json_object_object_get(section, "errorStatus"), §ion_cper->ErrorStatus);
+ //Error status.
+ ir_generic_error_status_to_cper(json_object_object_get(section,
+ "errorStatus"),
+ §ion_cper->ErrorStatus);
- //Bank.
- json_object* bank = json_object_object_get(section, "bank");
- if ((section_cper->ValidFields >> 5) & 0x1)
- {
- //Bank just uses simple address.
- section_cper->Bank = (UINT16)json_object_get_uint64(json_object_object_get(bank, "value"));
- }
- else
- {
- //Bank uses address/group style address.
- UINT16 address = (UINT8)json_object_get_uint64(json_object_object_get(bank, "address"));
- UINT16 group = (UINT8)json_object_get_uint64(json_object_object_get(bank, "group"));
- section_cper->Bank = address + (group << 8);
- }
+ //Bank.
+ json_object *bank = json_object_object_get(section, "bank");
+ if ((section_cper->ValidFields >> 5) & 0x1) {
+ //Bank just uses simple address.
+ section_cper->Bank = (UINT16)json_object_get_uint64(
+ json_object_object_get(bank, "value"));
+ } else {
+ //Bank uses address/group style address.
+ UINT16 address = (UINT8)json_object_get_uint64(
+ json_object_object_get(bank, "address"));
+ UINT16 group = (UINT8)json_object_get_uint64(
+ json_object_object_get(bank, "group"));
+ section_cper->Bank = address + (group << 8);
+ }
- //"Extended" field.
- json_object* extended = json_object_object_get(section, "extended");
- section_cper->Extended = 0;
- section_cper->Extended |= json_object_get_boolean(json_object_object_get(extended, "rowBit16"));
- section_cper->Extended |= json_object_get_boolean(json_object_object_get(extended, "rowBit17")) << 1;
- section_cper->Extended |= json_object_get_int(json_object_object_get(extended, "chipIdentification")) << 5;
+ //"Extended" field.
+ json_object *extended = json_object_object_get(section, "extended");
+ section_cper->Extended = 0;
+ section_cper->Extended |= json_object_get_boolean(
+ json_object_object_get(extended, "rowBit16"));
+ section_cper->Extended |=
+ json_object_get_boolean(
+ json_object_object_get(extended, "rowBit17"))
+ << 1;
+ section_cper->Extended |= json_object_get_int(json_object_object_get(
+ extended, "chipIdentification"))
+ << 5;
- //Miscellaneous value fields.
- section_cper->ErrorType = (UINT8)readable_pair_to_integer(json_object_object_get(section, "memoryErrorType"));
- section_cper->PhysicalAddress = json_object_get_uint64(json_object_object_get(section, "physicalAddress"));
- section_cper->PhysicalAddressMask = json_object_get_uint64(json_object_object_get(section, "physicalAddressMask"));
- section_cper->Node = (UINT16)json_object_get_uint64(json_object_object_get(section, "node"));
- section_cper->Card = (UINT16)json_object_get_uint64(json_object_object_get(section, "card"));
- section_cper->ModuleRank = (UINT16)json_object_get_uint64(json_object_object_get(section, "moduleRank"));
- section_cper->Device = (UINT16)json_object_get_uint64(json_object_object_get(section, "device"));
- section_cper->Row = (UINT16)json_object_get_uint64(json_object_object_get(section, "row"));
- section_cper->Column = (UINT16)json_object_get_uint64(json_object_object_get(section, "column"));
- section_cper->BitPosition = (UINT16)json_object_get_uint64(json_object_object_get(section, "bitPosition"));
- section_cper->RequestorId = json_object_get_uint64(json_object_object_get(section, "requestorID"));
- section_cper->ResponderId = json_object_get_uint64(json_object_object_get(section, "responderID"));
- section_cper->TargetId = json_object_get_uint64(json_object_object_get(section, "targetID"));
- section_cper->RankNum = (UINT16)json_object_get_uint64(json_object_object_get(section, "rankNumber"));
- section_cper->CardHandle = (UINT16)json_object_get_uint64(json_object_object_get(section, "cardSmbiosHandle"));
- section_cper->ModuleHandle = (UINT16)json_object_get_uint64(json_object_object_get(section, "moduleSmbiosHandle"));
+ //Miscellaneous value fields.
+ section_cper->ErrorType = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "memoryErrorType"));
+ section_cper->PhysicalAddress = json_object_get_uint64(
+ json_object_object_get(section, "physicalAddress"));
+ section_cper->PhysicalAddressMask = json_object_get_uint64(
+ json_object_object_get(section, "physicalAddressMask"));
+ section_cper->Node = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "node"));
+ section_cper->Card = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "card"));
+ section_cper->ModuleRank = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "moduleRank"));
+ section_cper->Device = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "device"));
+ section_cper->Row = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "row"));
+ section_cper->Column = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "column"));
+ section_cper->BitPosition = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "bitPosition"));
+ section_cper->RequestorId = json_object_get_uint64(
+ json_object_object_get(section, "requestorID"));
+ section_cper->ResponderId = json_object_get_uint64(
+ json_object_object_get(section, "responderID"));
+ section_cper->TargetId = json_object_get_uint64(
+ json_object_object_get(section, "targetID"));
+ section_cper->RankNum = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "rankNumber"));
+ section_cper->CardHandle = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "cardSmbiosHandle"));
+ section_cper->ModuleHandle = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "moduleSmbiosHandle"));
- //Write to stream, free up resources.
- fwrite(section_cper, sizeof(EFI_PLATFORM_MEMORY_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //Write to stream, free up resources.
+ fwrite(section_cper, sizeof(EFI_PLATFORM_MEMORY_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
}
//Converts a single Memory Error 2 IR section into CPER binary, outputting to the provided stream.
-void ir_section_memory2_to_cper(json_object* section, FILE* out)
+void ir_section_memory2_to_cper(json_object *section, FILE *out)
{
- EFI_PLATFORM_MEMORY2_ERROR_DATA* section_cper =
- (EFI_PLATFORM_MEMORY2_ERROR_DATA*)calloc(1, sizeof(EFI_PLATFORM_MEMORY2_ERROR_DATA));
+ EFI_PLATFORM_MEMORY2_ERROR_DATA *section_cper =
+ (EFI_PLATFORM_MEMORY2_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_PLATFORM_MEMORY2_ERROR_DATA));
- //Validation bits.
- section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 22, MEMORY_ERROR_2_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ section_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 22,
+ MEMORY_ERROR_2_VALID_BITFIELD_NAMES);
- //Error status.
- ir_generic_error_status_to_cper(json_object_object_get(section, "errorStatus"), §ion_cper->ErrorStatus);
+ //Error status.
+ ir_generic_error_status_to_cper(json_object_object_get(section,
+ "errorStatus"),
+ §ion_cper->ErrorStatus);
- //Bank.
- json_object* bank = json_object_object_get(section, "bank");
- if ((section_cper->ValidFields >> 5) & 0x1)
- {
- //Bank just uses simple address.
- section_cper->Bank = (UINT16)json_object_get_uint64(json_object_object_get(bank, "value"));
- }
- else
- {
- //Bank uses address/group style address.
- UINT16 address = (UINT8)json_object_get_uint64(json_object_object_get(bank, "address"));
- UINT16 group = (UINT8)json_object_get_uint64(json_object_object_get(bank, "group"));
- section_cper->Bank = address + (group << 8);
- }
+ //Bank.
+ json_object *bank = json_object_object_get(section, "bank");
+ if ((section_cper->ValidFields >> 5) & 0x1) {
+ //Bank just uses simple address.
+ section_cper->Bank = (UINT16)json_object_get_uint64(
+ json_object_object_get(bank, "value"));
+ } else {
+ //Bank uses address/group style address.
+ UINT16 address = (UINT8)json_object_get_uint64(
+ json_object_object_get(bank, "address"));
+ UINT16 group = (UINT8)json_object_get_uint64(
+ json_object_object_get(bank, "group"));
+ section_cper->Bank = address + (group << 8);
+ }
- //Miscellaneous value fields.
- section_cper->MemErrorType = readable_pair_to_integer(json_object_object_get(section, "memoryErrorType"));
- section_cper->Status = (UINT8)readable_pair_to_integer(json_object_object_get(section, "status"));
- section_cper->PhysicalAddress = json_object_get_uint64(json_object_object_get(section, "physicalAddress"));
- section_cper->PhysicalAddressMask = json_object_get_uint64(json_object_object_get(section, "physicalAddressMask"));
- section_cper->Node = (UINT16)json_object_get_uint64(json_object_object_get(section, "node"));
- section_cper->Card = (UINT16)json_object_get_uint64(json_object_object_get(section, "card"));
- section_cper->Module = (UINT32)json_object_get_uint64(json_object_object_get(section, "module"));
- section_cper->Device = (UINT32)json_object_get_uint64(json_object_object_get(section, "device"));
- section_cper->Row = (UINT32)json_object_get_uint64(json_object_object_get(section, "row"));
- section_cper->Column = (UINT32)json_object_get_uint64(json_object_object_get(section, "column"));
- section_cper->Rank = (UINT32)json_object_get_uint64(json_object_object_get(section, "rank"));
- section_cper->BitPosition = (UINT32)json_object_get_uint64(json_object_object_get(section, "bitPosition"));
- section_cper->ChipId = (UINT8)json_object_get_uint64(json_object_object_get(section, "chipID"));
- section_cper->RequestorId = json_object_get_uint64(json_object_object_get(section, "requestorID"));
- section_cper->ResponderId = json_object_get_uint64(json_object_object_get(section, "responderID"));
- section_cper->TargetId = json_object_get_uint64(json_object_object_get(section, "targetID"));
- section_cper->CardHandle = (UINT32)json_object_get_uint64(json_object_object_get(section, "cardSmbiosHandle"));
- section_cper->ModuleHandle = (UINT32)json_object_get_uint64(json_object_object_get(section, "moduleSmbiosHandle"));
+ //Miscellaneous value fields.
+ section_cper->MemErrorType = readable_pair_to_integer(
+ json_object_object_get(section, "memoryErrorType"));
+ section_cper->Status = (UINT8)readable_pair_to_integer(
+ json_object_object_get(section, "status"));
+ section_cper->PhysicalAddress = json_object_get_uint64(
+ json_object_object_get(section, "physicalAddress"));
+ section_cper->PhysicalAddressMask = json_object_get_uint64(
+ json_object_object_get(section, "physicalAddressMask"));
+ section_cper->Node = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "node"));
+ section_cper->Card = (UINT16)json_object_get_uint64(
+ json_object_object_get(section, "card"));
+ section_cper->Module = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "module"));
+ section_cper->Device = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "device"));
+ section_cper->Row = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "row"));
+ section_cper->Column = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "column"));
+ section_cper->Rank = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "rank"));
+ section_cper->BitPosition = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "bitPosition"));
+ section_cper->ChipId = (UINT8)json_object_get_uint64(
+ json_object_object_get(section, "chipID"));
+ section_cper->RequestorId = json_object_get_uint64(
+ json_object_object_get(section, "requestorID"));
+ section_cper->ResponderId = json_object_get_uint64(
+ json_object_object_get(section, "responderID"));
+ section_cper->TargetId = json_object_get_uint64(
+ json_object_object_get(section, "targetID"));
+ section_cper->CardHandle = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "cardSmbiosHandle"));
+ section_cper->ModuleHandle = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "moduleSmbiosHandle"));
- //Write to stream, free up resources.
- fwrite(section_cper, sizeof(EFI_PLATFORM_MEMORY2_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //Write to stream, free up resources.
+ fwrite(section_cper, sizeof(EFI_PLATFORM_MEMORY2_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-pci-bus.c b/sections/cper-section-pci-bus.c
index 0065192..106af1c 100644
--- a/sections/cper-section-pci-bus.c
+++ b/sections/cper-section-pci-bus.c
@@ -12,77 +12,105 @@
#include "cper-section-pci-bus.h"
//Converts a single PCI/PCI-X bus CPER section into JSON IR.
-json_object* cper_section_pci_bus_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_pci_bus_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_PCI_PCIX_BUS_ERROR_DATA* bus_error = (EFI_PCI_PCIX_BUS_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_PCI_PCIX_BUS_ERROR_DATA *bus_error =
+ (EFI_PCI_PCIX_BUS_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Validation bits.
- json_object* validation = bitfield_to_ir(bus_error->ValidFields, 9, PCI_BUS_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation = bitfield_to_ir(
+ bus_error->ValidFields, 9, PCI_BUS_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_ir, "validationBits", validation);
- //Error status.
- json_object* error_status = cper_generic_error_status_to_ir(&bus_error->ErrorStatus);
- json_object_object_add(section_ir, "errorStatus", error_status);
+ //Error status.
+ json_object *error_status =
+ cper_generic_error_status_to_ir(&bus_error->ErrorStatus);
+ json_object_object_add(section_ir, "errorStatus", error_status);
- //PCI bus error type.
- json_object* error_type = integer_to_readable_pair(bus_error->Type, 8,
- PCI_BUS_ERROR_TYPES_KEYS,
- PCI_BUS_ERROR_TYPES_VALUES,
- "Unknown (Reserved)");
- json_object_object_add(section_ir, "errorType", error_type);
+ //PCI bus error type.
+ json_object *error_type = integer_to_readable_pair(
+ bus_error->Type, 8, PCI_BUS_ERROR_TYPES_KEYS,
+ PCI_BUS_ERROR_TYPES_VALUES, "Unknown (Reserved)");
+ json_object_object_add(section_ir, "errorType", error_type);
- //Bus ID.
- json_object* bus_id = json_object_new_object();
- json_object_object_add(bus_id, "busNumber", json_object_new_int(bus_error->BusId & 0xFF));
- json_object_object_add(bus_id, "segmentNumber", json_object_new_int(bus_error->BusId >> 8));
- json_object_object_add(section_ir, "busID", bus_id);
+ //Bus ID.
+ json_object *bus_id = json_object_new_object();
+ json_object_object_add(bus_id, "busNumber",
+ json_object_new_int(bus_error->BusId & 0xFF));
+ json_object_object_add(bus_id, "segmentNumber",
+ json_object_new_int(bus_error->BusId >> 8));
+ json_object_object_add(section_ir, "busID", bus_id);
- //Miscellaneous numeric fields.
- UINT8 command_type = (bus_error->BusCommand >> 56) & 0b1; //Byte 7, bit 0.
- json_object_object_add(section_ir, "busAddress", json_object_new_uint64(bus_error->BusAddress));
- json_object_object_add(section_ir, "busData", json_object_new_uint64(bus_error->BusData));
- json_object_object_add(section_ir, "busCommandType", json_object_new_string(command_type == 0 ? "PCI" : "PCI-X"));
- json_object_object_add(section_ir, "busRequestorID", json_object_new_uint64(bus_error->RequestorId));
- json_object_object_add(section_ir, "busCompleterID", json_object_new_uint64(bus_error->ResponderId));
- json_object_object_add(section_ir, "targetID", json_object_new_uint64(bus_error->TargetId));
+ //Miscellaneous numeric fields.
+ UINT8 command_type = (bus_error->BusCommand >> 56) &
+ 0b1; //Byte 7, bit 0.
+ json_object_object_add(section_ir, "busAddress",
+ json_object_new_uint64(bus_error->BusAddress));
+ json_object_object_add(section_ir, "busData",
+ json_object_new_uint64(bus_error->BusData));
+ json_object_object_add(
+ section_ir, "busCommandType",
+ json_object_new_string(command_type == 0 ? "PCI" : "PCI-X"));
+ json_object_object_add(section_ir, "busRequestorID",
+ json_object_new_uint64(bus_error->RequestorId));
+ json_object_object_add(section_ir, "busCompleterID",
+ json_object_new_uint64(bus_error->ResponderId));
+ json_object_object_add(section_ir, "targetID",
+ json_object_new_uint64(bus_error->TargetId));
- return section_ir;
+ return section_ir;
}
//Converts a single provided PCI/PCI-X bus CPER-JSON section into CPER binary, outputting to the
//provided stream.
-void ir_section_pci_bus_to_cper(json_object* section, FILE* out)
+void ir_section_pci_bus_to_cper(json_object *section, FILE *out)
{
- EFI_PCI_PCIX_BUS_ERROR_DATA* section_cper =
- (EFI_PCI_PCIX_BUS_ERROR_DATA*)calloc(1, sizeof(EFI_PCI_PCIX_BUS_ERROR_DATA));
+ EFI_PCI_PCIX_BUS_ERROR_DATA *section_cper =
+ (EFI_PCI_PCIX_BUS_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_PCI_PCIX_BUS_ERROR_DATA));
- //Validation bits.
- section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 9, PCI_BUS_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ section_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 9,
+ PCI_BUS_ERROR_VALID_BITFIELD_NAMES);
- //Error status.
- ir_generic_error_status_to_cper(json_object_object_get(section, "errorStatus"), §ion_cper->ErrorStatus);
+ //Error status.
+ ir_generic_error_status_to_cper(json_object_object_get(section,
+ "errorStatus"),
+ §ion_cper->ErrorStatus);
- //Bus ID.
- json_object* bus_id = json_object_object_get(section, "busID");
- UINT16 bus_number = (UINT8)json_object_get_int(json_object_object_get(bus_id, "busNumber"));
- UINT16 segment_number = (UINT8)json_object_get_int(json_object_object_get(bus_id, "segmentNumber"));
- section_cper->BusId = bus_number + (segment_number << 8);
+ //Bus ID.
+ json_object *bus_id = json_object_object_get(section, "busID");
+ UINT16 bus_number = (UINT8)json_object_get_int(
+ json_object_object_get(bus_id, "busNumber"));
+ UINT16 segment_number = (UINT8)json_object_get_int(
+ json_object_object_get(bus_id, "segmentNumber"));
+ section_cper->BusId = bus_number + (segment_number << 8);
- //Remaining fields.
- UINT64 pcix_command = (UINT64)0x1 << 56;
- const char* bus_command = json_object_get_string(json_object_object_get(section, "busCommandType"));
- section_cper->Type = (UINT16)readable_pair_to_integer(json_object_object_get(section, "errorType"));
- section_cper->BusAddress = json_object_get_uint64(json_object_object_get(section, "busAddress"));
- section_cper->BusData = json_object_get_uint64(json_object_object_get(section, "busData"));
- section_cper->BusCommand = strcmp(bus_command, "PCI") == 0 ? 0 : pcix_command;
- section_cper->RequestorId = json_object_get_uint64(json_object_object_get(section, "busRequestorID"));
- section_cper->ResponderId = json_object_get_uint64(json_object_object_get(section, "busCompleterID"));
- section_cper->TargetId = json_object_get_uint64(json_object_object_get(section, "targetID"));
+ //Remaining fields.
+ UINT64 pcix_command = (UINT64)0x1 << 56;
+ const char *bus_command = json_object_get_string(
+ json_object_object_get(section, "busCommandType"));
+ section_cper->Type = (UINT16)readable_pair_to_integer(
+ json_object_object_get(section, "errorType"));
+ section_cper->BusAddress = json_object_get_uint64(
+ json_object_object_get(section, "busAddress"));
+ section_cper->BusData = json_object_get_uint64(
+ json_object_object_get(section, "busData"));
+ section_cper->BusCommand =
+ strcmp(bus_command, "PCI") == 0 ? 0 : pcix_command;
+ section_cper->RequestorId = json_object_get_uint64(
+ json_object_object_get(section, "busRequestorID"));
+ section_cper->ResponderId = json_object_get_uint64(
+ json_object_object_get(section, "busCompleterID"));
+ section_cper->TargetId = json_object_get_uint64(
+ json_object_object_get(section, "targetID"));
- //Write to stream, free resources.
- fwrite(section_cper, sizeof(EFI_PCI_PCIX_BUS_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //Write to stream, free resources.
+ fwrite(section_cper, sizeof(EFI_PCI_PCIX_BUS_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/sections/cper-section-pci-dev.c b/sections/cper-section-pci-dev.c
index cae0c2b..55b547b 100644
--- a/sections/cper-section-pci-dev.c
+++ b/sections/cper-section-pci-dev.c
@@ -11,102 +11,142 @@
#include "cper-section-pci-dev.h"
//Converts a single PCI/PCI-X device CPER section into JSON IR.
-json_object* cper_section_pci_dev_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *
+cper_section_pci_dev_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_PCI_PCIX_DEVICE_ERROR_DATA* dev_error = (EFI_PCI_PCIX_DEVICE_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_PCI_PCIX_DEVICE_ERROR_DATA *dev_error =
+ (EFI_PCI_PCIX_DEVICE_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Validation bits.
- json_object* validation = bitfield_to_ir(dev_error->ValidFields, 5, PCI_DEV_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation = bitfield_to_ir(
+ dev_error->ValidFields, 5, PCI_DEV_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_ir, "validationBits", validation);
- //Error status.
- json_object* error_status = cper_generic_error_status_to_ir(&dev_error->ErrorStatus);
- json_object_object_add(section_ir, "errorStatus", error_status);
+ //Error status.
+ json_object *error_status =
+ cper_generic_error_status_to_ir(&dev_error->ErrorStatus);
+ json_object_object_add(section_ir, "errorStatus", error_status);
- //ID information.
- json_object* id_info = json_object_new_object();
- json_object_object_add(id_info, "vendorID", json_object_new_uint64(dev_error->IdInfo.VendorId));
- json_object_object_add(id_info, "deviceID", json_object_new_uint64(dev_error->IdInfo.DeviceId));
- json_object_object_add(id_info, "classCode", json_object_new_uint64(dev_error->IdInfo.ClassCode));
- json_object_object_add(id_info, "functionNumber", json_object_new_uint64(dev_error->IdInfo.FunctionNumber));
- json_object_object_add(id_info, "deviceNumber", json_object_new_uint64(dev_error->IdInfo.DeviceNumber));
- json_object_object_add(id_info, "busNumber", json_object_new_uint64(dev_error->IdInfo.BusNumber));
- json_object_object_add(id_info, "segmentNumber", json_object_new_uint64(dev_error->IdInfo.SegmentNumber));
- json_object_object_add(section_ir, "idInfo", id_info);
+ //ID information.
+ json_object *id_info = json_object_new_object();
+ json_object_object_add(
+ id_info, "vendorID",
+ json_object_new_uint64(dev_error->IdInfo.VendorId));
+ json_object_object_add(
+ id_info, "deviceID",
+ json_object_new_uint64(dev_error->IdInfo.DeviceId));
+ json_object_object_add(
+ id_info, "classCode",
+ json_object_new_uint64(dev_error->IdInfo.ClassCode));
+ json_object_object_add(
+ id_info, "functionNumber",
+ json_object_new_uint64(dev_error->IdInfo.FunctionNumber));
+ json_object_object_add(
+ id_info, "deviceNumber",
+ json_object_new_uint64(dev_error->IdInfo.DeviceNumber));
+ json_object_object_add(
+ id_info, "busNumber",
+ json_object_new_uint64(dev_error->IdInfo.BusNumber));
+ json_object_object_add(
+ id_info, "segmentNumber",
+ json_object_new_uint64(dev_error->IdInfo.SegmentNumber));
+ json_object_object_add(section_ir, "idInfo", id_info);
- //Number of following register data pairs.
- json_object_object_add(section_ir, "memoryNumber", json_object_new_uint64(dev_error->MemoryNumber));
- json_object_object_add(section_ir, "ioNumber", json_object_new_uint64(dev_error->IoNumber));
- int num_data_pairs = dev_error->MemoryNumber + dev_error->IoNumber;
+ //Number of following register data pairs.
+ json_object_object_add(section_ir, "memoryNumber",
+ json_object_new_uint64(dev_error->MemoryNumber));
+ json_object_object_add(section_ir, "ioNumber",
+ json_object_new_uint64(dev_error->IoNumber));
+ int num_data_pairs = dev_error->MemoryNumber + dev_error->IoNumber;
- //Register pairs, described by the numeric fields.
- //The actual "pairs" of address and data aren't necessarily 8 bytes long, so can't assume the contents.
- //Hence the naming "firstHalf" and "secondHalf" rather than "address" and "data".
- json_object* register_data_pair_array = json_object_new_array();
- UINT64* cur_pos = (UINT64*)(dev_error + 1);
- for (int i=0; i<num_data_pairs; i++)
- {
- //Save current pair to array.
- json_object* register_data_pair = json_object_new_object();
- json_object_object_add(register_data_pair, "firstHalf", json_object_new_uint64(*cur_pos));
- json_object_object_add(register_data_pair, "secondHalf", json_object_new_uint64(*(cur_pos + 1)));
- json_object_array_add(register_data_pair_array, register_data_pair);
+ //Register pairs, described by the numeric fields.
+ //The actual "pairs" of address and data aren't necessarily 8 bytes long, so can't assume the contents.
+ //Hence the naming "firstHalf" and "secondHalf" rather than "address" and "data".
+ json_object *register_data_pair_array = json_object_new_array();
+ UINT64 *cur_pos = (UINT64 *)(dev_error + 1);
+ for (int i = 0; i < num_data_pairs; i++) {
+ //Save current pair to array.
+ json_object *register_data_pair = json_object_new_object();
+ json_object_object_add(register_data_pair, "firstHalf",
+ json_object_new_uint64(*cur_pos));
+ json_object_object_add(register_data_pair, "secondHalf",
+ json_object_new_uint64(*(cur_pos + 1)));
+ json_object_array_add(register_data_pair_array,
+ register_data_pair);
- //Move to next pair.
- cur_pos += 2;
- }
- json_object_object_add(section_ir, "registerDataPairs", register_data_pair_array);
+ //Move to next pair.
+ cur_pos += 2;
+ }
+ json_object_object_add(section_ir, "registerDataPairs",
+ register_data_pair_array);
- return section_ir;
+ return section_ir;
}
-void ir_section_pci_dev_to_cper(json_object* section, FILE* out)
+void ir_section_pci_dev_to_cper(json_object *section, FILE *out)
{
- EFI_PCI_PCIX_DEVICE_ERROR_DATA* section_cper =
- (EFI_PCI_PCIX_DEVICE_ERROR_DATA*)calloc(1, sizeof(EFI_PCI_PCIX_DEVICE_ERROR_DATA));
+ EFI_PCI_PCIX_DEVICE_ERROR_DATA *section_cper =
+ (EFI_PCI_PCIX_DEVICE_ERROR_DATA *)calloc(
+ 1, sizeof(EFI_PCI_PCIX_DEVICE_ERROR_DATA));
- //Validation bits.
- section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 5, PCI_DEV_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ section_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 5,
+ PCI_DEV_ERROR_VALID_BITFIELD_NAMES);
- //Error status.
- ir_generic_error_status_to_cper(json_object_object_get(section, "errorStatus"), §ion_cper->ErrorStatus);
+ //Error status.
+ ir_generic_error_status_to_cper(json_object_object_get(section,
+ "errorStatus"),
+ §ion_cper->ErrorStatus);
- //Device ID information.
- json_object* id_info = json_object_object_get(section, "idInfo");
- section_cper->IdInfo.VendorId = json_object_get_uint64(json_object_object_get(id_info, "vendorID"));
- section_cper->IdInfo.DeviceId = json_object_get_uint64(json_object_object_get(id_info, "deviceID"));
- section_cper->IdInfo.ClassCode = json_object_get_uint64(json_object_object_get(id_info, "classCode"));
- section_cper->IdInfo.FunctionNumber = json_object_get_uint64(json_object_object_get(id_info, "functionNumber"));
- section_cper->IdInfo.DeviceNumber = json_object_get_uint64(json_object_object_get(id_info, "deviceNumber"));
- section_cper->IdInfo.BusNumber = json_object_get_uint64(json_object_object_get(id_info, "busNumber"));
- section_cper->IdInfo.SegmentNumber = json_object_get_uint64(json_object_object_get(id_info, "segmentNumber"));
+ //Device ID information.
+ json_object *id_info = json_object_object_get(section, "idInfo");
+ section_cper->IdInfo.VendorId = json_object_get_uint64(
+ json_object_object_get(id_info, "vendorID"));
+ section_cper->IdInfo.DeviceId = json_object_get_uint64(
+ json_object_object_get(id_info, "deviceID"));
+ section_cper->IdInfo.ClassCode = json_object_get_uint64(
+ json_object_object_get(id_info, "classCode"));
+ section_cper->IdInfo.FunctionNumber = json_object_get_uint64(
+ json_object_object_get(id_info, "functionNumber"));
+ section_cper->IdInfo.DeviceNumber = json_object_get_uint64(
+ json_object_object_get(id_info, "deviceNumber"));
+ section_cper->IdInfo.BusNumber = json_object_get_uint64(
+ json_object_object_get(id_info, "busNumber"));
+ section_cper->IdInfo.SegmentNumber = json_object_get_uint64(
+ json_object_object_get(id_info, "segmentNumber"));
- //Amount of following data pairs.
- section_cper->MemoryNumber = (UINT32)json_object_get_uint64(json_object_object_get(section, "memoryNumber"));
- section_cper->IoNumber = (UINT32)json_object_get_uint64(json_object_object_get(section, "ioNumber"));
+ //Amount of following data pairs.
+ section_cper->MemoryNumber = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "memoryNumber"));
+ section_cper->IoNumber = (UINT32)json_object_get_uint64(
+ json_object_object_get(section, "ioNumber"));
- //Write header out to stream, free it.
- fwrite(section_cper, sizeof(EFI_PCI_PCIX_DEVICE_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //Write header out to stream, free it.
+ fwrite(section_cper, sizeof(EFI_PCI_PCIX_DEVICE_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
- //Begin writing register pairs.
- json_object* register_pairs = json_object_object_get(section, "registerDataPairs");
- int num_pairs = json_object_array_length(register_pairs);
- for (int i=0; i<num_pairs; i++)
- {
- //Get the pair array item out.
- json_object* register_pair = json_object_array_get_idx(register_pairs, i);
+ //Begin writing register pairs.
+ json_object *register_pairs =
+ json_object_object_get(section, "registerDataPairs");
+ int num_pairs = json_object_array_length(register_pairs);
+ for (int i = 0; i < num_pairs; i++) {
+ //Get the pair array item out.
+ json_object *register_pair =
+ json_object_array_get_idx(register_pairs, i);
- //Create the pair array.
- UINT64 pair[2];
- pair[0] = json_object_get_uint64(json_object_object_get(register_pair, "firstHalf"));
- pair[1] = json_object_get_uint64(json_object_object_get(register_pair, "secondHalf"));
+ //Create the pair array.
+ UINT64 pair[2];
+ pair[0] = json_object_get_uint64(
+ json_object_object_get(register_pair, "firstHalf"));
+ pair[1] = json_object_get_uint64(
+ json_object_object_get(register_pair, "secondHalf"));
- //Push to stream.
- fwrite(pair, sizeof(UINT64), 2, out);
- fflush(out);
- }
+ //Push to stream.
+ fwrite(pair, sizeof(UINT64), 2, out);
+ fflush(out);
+ }
}
\ No newline at end of file
diff --git a/sections/cper-section-pcie.c b/sections/cper-section-pcie.c
index d5a7729..5b49fa2 100644
--- a/sections/cper-section-pcie.c
+++ b/sections/cper-section-pcie.c
@@ -13,150 +13,204 @@
#include "cper-section-pcie.h"
//Converts a single PCIe CPER section into JSON IR.
-json_object* cper_section_pcie_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+json_object *cper_section_pcie_to_ir(void *section,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- EFI_PCIE_ERROR_DATA* pcie_error = (EFI_PCIE_ERROR_DATA*)section;
- json_object* section_ir = json_object_new_object();
+ EFI_PCIE_ERROR_DATA *pcie_error = (EFI_PCIE_ERROR_DATA *)section;
+ json_object *section_ir = json_object_new_object();
- //Validation bits.
- json_object* validation = bitfield_to_ir(pcie_error->ValidFields, 8, PCIE_ERROR_VALID_BITFIELD_NAMES);
- json_object_object_add(section_ir, "validationBits", validation);
+ //Validation bits.
+ json_object *validation = bitfield_to_ir(
+ pcie_error->ValidFields, 8, PCIE_ERROR_VALID_BITFIELD_NAMES);
+ json_object_object_add(section_ir, "validationBits", validation);
- //Port type.
- json_object* port_type = integer_to_readable_pair(pcie_error->PortType, 9,
- PCIE_ERROR_PORT_TYPES_KEYS,
- PCIE_ERROR_PORT_TYPES_VALUES,
- "Unknown");
- json_object_object_add(section_ir, "portType", port_type);
+ //Port type.
+ json_object *port_type = integer_to_readable_pair(
+ pcie_error->PortType, 9, PCIE_ERROR_PORT_TYPES_KEYS,
+ PCIE_ERROR_PORT_TYPES_VALUES, "Unknown");
+ json_object_object_add(section_ir, "portType", port_type);
- //Version, provided each half in BCD.
- json_object* version = json_object_new_object();
- json_object_object_add(version, "minor", json_object_new_int(bcd_to_int(pcie_error->Version & 0xFF)));
- json_object_object_add(version, "major", json_object_new_int(bcd_to_int(pcie_error->Version >> 8)));
- json_object_object_add(section_ir, "version", version);
+ //Version, provided each half in BCD.
+ json_object *version = json_object_new_object();
+ json_object_object_add(
+ version, "minor",
+ json_object_new_int(bcd_to_int(pcie_error->Version & 0xFF)));
+ json_object_object_add(
+ version, "major",
+ json_object_new_int(bcd_to_int(pcie_error->Version >> 8)));
+ json_object_object_add(section_ir, "version", version);
- //Command & status.
- json_object* command_status = json_object_new_object();
- json_object_object_add(command_status, "commandRegister", json_object_new_uint64(pcie_error->CommandStatus & 0xFFFF));
- json_object_object_add(command_status, "statusRegister", json_object_new_uint64(pcie_error->CommandStatus >> 16));
- json_object_object_add(section_ir, "commandStatus", command_status);
+ //Command & status.
+ json_object *command_status = json_object_new_object();
+ json_object_object_add(
+ command_status, "commandRegister",
+ json_object_new_uint64(pcie_error->CommandStatus & 0xFFFF));
+ json_object_object_add(
+ command_status, "statusRegister",
+ json_object_new_uint64(pcie_error->CommandStatus >> 16));
+ json_object_object_add(section_ir, "commandStatus", command_status);
- //PCIe Device ID.
- json_object* device_id = json_object_new_object();
- UINT64 class_id = (pcie_error->DevBridge.ClassCode[0] << 16) +
- (pcie_error->DevBridge.ClassCode[1] << 8) +
- pcie_error->DevBridge.ClassCode[2];
- json_object_object_add(device_id, "vendorID", json_object_new_uint64(pcie_error->DevBridge.VendorId));
- json_object_object_add(device_id, "deviceID", json_object_new_uint64(pcie_error->DevBridge.DeviceId));
- json_object_object_add(device_id, "classCode", json_object_new_uint64(class_id));
- json_object_object_add(device_id, "functionNumber", json_object_new_uint64(pcie_error->DevBridge.Function));
- json_object_object_add(device_id, "deviceNumber", json_object_new_uint64(pcie_error->DevBridge.Device));
- json_object_object_add(device_id, "segmentNumber", json_object_new_uint64(pcie_error->DevBridge.Segment));
- json_object_object_add(device_id, "primaryOrDeviceBusNumber", json_object_new_uint64(pcie_error->DevBridge.PrimaryOrDeviceBus));
- json_object_object_add(device_id, "secondaryBusNumber", json_object_new_uint64(pcie_error->DevBridge.SecondaryBus));
- json_object_object_add(device_id, "slotNumber", json_object_new_uint64(pcie_error->DevBridge.Slot.Number));
- json_object_object_add(section_ir, "deviceID", device_id);
+ //PCIe Device ID.
+ json_object *device_id = json_object_new_object();
+ UINT64 class_id = (pcie_error->DevBridge.ClassCode[0] << 16) +
+ (pcie_error->DevBridge.ClassCode[1] << 8) +
+ pcie_error->DevBridge.ClassCode[2];
+ json_object_object_add(
+ device_id, "vendorID",
+ json_object_new_uint64(pcie_error->DevBridge.VendorId));
+ json_object_object_add(
+ device_id, "deviceID",
+ json_object_new_uint64(pcie_error->DevBridge.DeviceId));
+ json_object_object_add(device_id, "classCode",
+ json_object_new_uint64(class_id));
+ json_object_object_add(
+ device_id, "functionNumber",
+ json_object_new_uint64(pcie_error->DevBridge.Function));
+ json_object_object_add(
+ device_id, "deviceNumber",
+ json_object_new_uint64(pcie_error->DevBridge.Device));
+ json_object_object_add(
+ device_id, "segmentNumber",
+ json_object_new_uint64(pcie_error->DevBridge.Segment));
+ json_object_object_add(
+ device_id, "primaryOrDeviceBusNumber",
+ json_object_new_uint64(
+ pcie_error->DevBridge.PrimaryOrDeviceBus));
+ json_object_object_add(
+ device_id, "secondaryBusNumber",
+ json_object_new_uint64(pcie_error->DevBridge.SecondaryBus));
+ json_object_object_add(
+ device_id, "slotNumber",
+ json_object_new_uint64(pcie_error->DevBridge.Slot.Number));
+ json_object_object_add(section_ir, "deviceID", device_id);
- //Device serial number.
- json_object_object_add(section_ir, "deviceSerialNumber", json_object_new_uint64(pcie_error->SerialNo));
+ //Device serial number.
+ json_object_object_add(section_ir, "deviceSerialNumber",
+ json_object_new_uint64(pcie_error->SerialNo));
- //Bridge control status.
- json_object* bridge_control_status = json_object_new_object();
- json_object_object_add(bridge_control_status, "secondaryStatusRegister",
- json_object_new_uint64(pcie_error->BridgeControlStatus & 0xFFFF));
- json_object_object_add(bridge_control_status, "controlRegister",
- json_object_new_uint64(pcie_error->BridgeControlStatus >> 16));
- json_object_object_add(section_ir, "bridgeControlStatus", bridge_control_status);
+ //Bridge control status.
+ json_object *bridge_control_status = json_object_new_object();
+ json_object_object_add(
+ bridge_control_status, "secondaryStatusRegister",
+ json_object_new_uint64(pcie_error->BridgeControlStatus &
+ 0xFFFF));
+ json_object_object_add(
+ bridge_control_status, "controlRegister",
+ json_object_new_uint64(pcie_error->BridgeControlStatus >> 16));
+ json_object_object_add(section_ir, "bridgeControlStatus",
+ bridge_control_status);
- //Capability structure.
- //The PCIe capability structure provided here could either be PCIe 1.1 Capability Structure
- //(36-byte, padded to 60 bytes) or PCIe 2.0 Capability Structure (60-byte). There does not seem
- //to be a way to differentiate these, so this is left as a b64 dump.
- char* encoded = b64_encode((unsigned char*)pcie_error->Capability.PcieCap, 60);
- json_object* capability = json_object_new_object();
- json_object_object_add(capability, "data", json_object_new_string(encoded));
- free(encoded);
- json_object_object_add(section_ir, "capabilityStructure", capability);
+ //Capability structure.
+ //The PCIe capability structure provided here could either be PCIe 1.1 Capability Structure
+ //(36-byte, padded to 60 bytes) or PCIe 2.0 Capability Structure (60-byte). There does not seem
+ //to be a way to differentiate these, so this is left as a b64 dump.
+ char *encoded =
+ b64_encode((unsigned char *)pcie_error->Capability.PcieCap, 60);
+ json_object *capability = json_object_new_object();
+ json_object_object_add(capability, "data",
+ json_object_new_string(encoded));
+ free(encoded);
+ json_object_object_add(section_ir, "capabilityStructure", capability);
- //AER information.
- json_object* aer_capability_ir = json_object_new_object();
- encoded = b64_encode((unsigned char*)pcie_error->AerInfo.PcieAer, 96);
- json_object_object_add(aer_capability_ir, "data", json_object_new_string(encoded));
- free(encoded);
- json_object_object_add(section_ir, "aerInfo", aer_capability_ir);
- return section_ir;
+ //AER information.
+ json_object *aer_capability_ir = json_object_new_object();
+ encoded = b64_encode((unsigned char *)pcie_error->AerInfo.PcieAer, 96);
+ json_object_object_add(aer_capability_ir, "data",
+ json_object_new_string(encoded));
+ free(encoded);
+ json_object_object_add(section_ir, "aerInfo", aer_capability_ir);
+ return section_ir;
}
//Converts a single CPER-JSON PCIe section into CPER binary, outputting to the given stream.
-void ir_section_pcie_to_cper(json_object* section, FILE* out)
+void ir_section_pcie_to_cper(json_object *section, FILE *out)
{
- EFI_PCIE_ERROR_DATA* section_cper = (EFI_PCIE_ERROR_DATA*)calloc(1, sizeof(EFI_PCIE_ERROR_DATA));
+ EFI_PCIE_ERROR_DATA *section_cper =
+ (EFI_PCIE_ERROR_DATA *)calloc(1, sizeof(EFI_PCIE_ERROR_DATA));
- //Validation bits.
- section_cper->ValidFields = ir_to_bitfield(json_object_object_get(section, "validationBits"),
- 8, PCIE_ERROR_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ section_cper->ValidFields = ir_to_bitfield(
+ json_object_object_get(section, "validationBits"), 8,
+ PCIE_ERROR_VALID_BITFIELD_NAMES);
- //Version.
- json_object* version = json_object_object_get(section, "version");
- UINT32 minor = int_to_bcd(json_object_get_int(json_object_object_get(version, "minor")));
- UINT32 major = int_to_bcd(json_object_get_int(json_object_object_get(version, "major")));
- section_cper->Version = minor + (major << 8);
+ //Version.
+ json_object *version = json_object_object_get(section, "version");
+ UINT32 minor = int_to_bcd(
+ json_object_get_int(json_object_object_get(version, "minor")));
+ UINT32 major = int_to_bcd(
+ json_object_get_int(json_object_object_get(version, "major")));
+ section_cper->Version = minor + (major << 8);
- //Command/status registers.
- json_object* command_status = json_object_object_get(section, "commandStatus");
- UINT32 command = (UINT16)json_object_get_uint64(json_object_object_get(command_status, "commandRegister"));
- UINT32 status = (UINT16)json_object_get_uint64(json_object_object_get(command_status, "statusRegister"));
- section_cper->CommandStatus = command + (status << 16);
+ //Command/status registers.
+ json_object *command_status =
+ json_object_object_get(section, "commandStatus");
+ UINT32 command = (UINT16)json_object_get_uint64(
+ json_object_object_get(command_status, "commandRegister"));
+ UINT32 status = (UINT16)json_object_get_uint64(
+ json_object_object_get(command_status, "statusRegister"));
+ section_cper->CommandStatus = command + (status << 16);
- //Device ID.
- json_object* device_id = json_object_object_get(section, "deviceID");
- UINT64 class_id = json_object_get_uint64(json_object_object_get(device_id, "classCode"));
- section_cper->DevBridge.VendorId =
- (UINT16)json_object_get_uint64(json_object_object_get(device_id, "vendorID"));
- section_cper->DevBridge.DeviceId =
- (UINT16)json_object_get_uint64(json_object_object_get(device_id, "deviceID"));
- section_cper->DevBridge.ClassCode[0] = class_id >> 16;
- section_cper->DevBridge.ClassCode[1] = (class_id >> 8) & 0xFF;
- section_cper->DevBridge.ClassCode[2] = class_id & 0xFF;
- section_cper->DevBridge.Function =
- (UINT8)json_object_get_uint64(json_object_object_get(device_id, "functionNumber"));
- section_cper->DevBridge.Device =
- (UINT8)json_object_get_uint64(json_object_object_get(device_id, "deviceNumber"));
- section_cper->DevBridge.Segment =
- (UINT16)json_object_get_uint64(json_object_object_get(device_id, "segmentNumber"));
- section_cper->DevBridge.PrimaryOrDeviceBus =
- (UINT8)json_object_get_uint64(json_object_object_get(device_id, "primaryOrDeviceBusNumber"));
- section_cper->DevBridge.SecondaryBus =
- (UINT8)json_object_get_uint64(json_object_object_get(device_id, "secondaryBusNumber"));
- section_cper->DevBridge.Slot.Number =
- (UINT16)json_object_get_uint64(json_object_object_get(device_id, "slotNumber"));
+ //Device ID.
+ json_object *device_id = json_object_object_get(section, "deviceID");
+ UINT64 class_id = json_object_get_uint64(
+ json_object_object_get(device_id, "classCode"));
+ section_cper->DevBridge.VendorId = (UINT16)json_object_get_uint64(
+ json_object_object_get(device_id, "vendorID"));
+ section_cper->DevBridge.DeviceId = (UINT16)json_object_get_uint64(
+ json_object_object_get(device_id, "deviceID"));
+ section_cper->DevBridge.ClassCode[0] = class_id >> 16;
+ section_cper->DevBridge.ClassCode[1] = (class_id >> 8) & 0xFF;
+ section_cper->DevBridge.ClassCode[2] = class_id & 0xFF;
+ section_cper->DevBridge.Function = (UINT8)json_object_get_uint64(
+ json_object_object_get(device_id, "functionNumber"));
+ section_cper->DevBridge.Device = (UINT8)json_object_get_uint64(
+ json_object_object_get(device_id, "deviceNumber"));
+ section_cper->DevBridge.Segment = (UINT16)json_object_get_uint64(
+ json_object_object_get(device_id, "segmentNumber"));
+ section_cper->DevBridge.PrimaryOrDeviceBus =
+ (UINT8)json_object_get_uint64(json_object_object_get(
+ device_id, "primaryOrDeviceBusNumber"));
+ section_cper->DevBridge.SecondaryBus = (UINT8)json_object_get_uint64(
+ json_object_object_get(device_id, "secondaryBusNumber"));
+ section_cper->DevBridge.Slot.Number = (UINT16)json_object_get_uint64(
+ json_object_object_get(device_id, "slotNumber"));
- //Bridge/control status.
- json_object* bridge_control = json_object_object_get(section, "bridgeControlStatus");
- UINT32 bridge_status = (UINT16)json_object_get_uint64(json_object_object_get(bridge_control, "secondaryStatusRegister"));
- UINT32 control_status = (UINT16)json_object_get_uint64(json_object_object_get(bridge_control, "controlRegister"));
- section_cper->BridgeControlStatus = bridge_status + (control_status << 16);
+ //Bridge/control status.
+ json_object *bridge_control =
+ json_object_object_get(section, "bridgeControlStatus");
+ UINT32 bridge_status = (UINT16)json_object_get_uint64(
+ json_object_object_get(bridge_control,
+ "secondaryStatusRegister"));
+ UINT32 control_status = (UINT16)json_object_get_uint64(
+ json_object_object_get(bridge_control, "controlRegister"));
+ section_cper->BridgeControlStatus =
+ bridge_status + (control_status << 16);
- //Capability structure.
- json_object* capability = json_object_object_get(section, "capabilityStructure");
- json_object* encoded = json_object_object_get(capability, "data");
- UINT8* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- memcpy(section_cper->Capability.PcieCap, decoded, 60);
- free(decoded);
+ //Capability structure.
+ json_object *capability =
+ json_object_object_get(section, "capabilityStructure");
+ json_object *encoded = json_object_object_get(capability, "data");
+ UINT8 *decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ memcpy(section_cper->Capability.PcieCap, decoded, 60);
+ free(decoded);
- //AER capability structure.
- json_object* aer_info = json_object_object_get(section, "aerInfo");
- encoded = json_object_object_get(aer_info, "data");
- decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- memcpy(section_cper->AerInfo.PcieAer, decoded, 96);
- free(decoded);
+ //AER capability structure.
+ json_object *aer_info = json_object_object_get(section, "aerInfo");
+ encoded = json_object_object_get(aer_info, "data");
+ decoded = b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ memcpy(section_cper->AerInfo.PcieAer, decoded, 96);
+ free(decoded);
- //Miscellaneous value fields.
- section_cper->PortType = (UINT32)readable_pair_to_integer(json_object_object_get(section, "portType"));
- section_cper->SerialNo = json_object_get_uint64(json_object_object_get(section, "deviceSerialNumber"));
+ //Miscellaneous value fields.
+ section_cper->PortType = (UINT32)readable_pair_to_integer(
+ json_object_object_get(section, "portType"));
+ section_cper->SerialNo = json_object_get_uint64(
+ json_object_object_get(section, "deviceSerialNumber"));
- //Write out to stream, free resources.
- fwrite(section_cper, sizeof(EFI_PCIE_ERROR_DATA), 1, out);
- fflush(out);
- free(section_cper);
+ //Write out to stream, free resources.
+ fwrite(section_cper, sizeof(EFI_PCIE_ERROR_DATA), 1, out);
+ fflush(out);
+ free(section_cper);
}
\ No newline at end of file
diff --git a/tests/ir-tests.cpp b/tests/ir-tests.cpp
index 6ca44a3..86ec021 100644
--- a/tests/ir-tests.cpp
+++ b/tests/ir-tests.cpp
@@ -18,68 +18,74 @@
*/
//Tests a single randomly generated CPER section of the given type to ensure CPER-JSON IR validity.
-void single_section_ir_test(const char* section_name)
+void single_section_ir_test(const char *section_name)
{
- //Generate CPER record for the given type.
- char* buf;
- size_t size;
- FILE* record = generate_record_memstream(§ion_name, 1, &buf, &size);
+ //Generate CPER record for the given type.
+ char *buf;
+ size_t size;
+ FILE *record = generate_record_memstream(§ion_name, 1, &buf, &size);
- //Convert to IR, free resources.
- json_object* ir = cper_to_ir(record);
- fclose(record);
- free(buf);
+ //Convert to IR, free resources.
+ json_object *ir = cper_to_ir(record);
+ fclose(record);
+ free(buf);
- //Validate against schema.
- char error_message[JSON_ERROR_MSG_MAX_LEN] = {0};
- int valid = validate_schema_from_file("./specification/cper-json.json", ir, error_message);
- ASSERT_TRUE(valid) << error_message;
+ //Validate against schema.
+ char error_message[JSON_ERROR_MSG_MAX_LEN] = { 0 };
+ int valid = validate_schema_from_file("./specification/cper-json.json",
+ ir, error_message);
+ ASSERT_TRUE(valid) << error_message;
}
//Checks for binary round-trip equality for a given randomly generated CPER record.
-void single_section_binary_test(const char* section_name)
+void single_section_binary_test(const char *section_name)
{
- //Generate CPER record for the given type.
- char* buf;
- size_t size;
- FILE* record = generate_record_memstream(§ion_name, 1, &buf, &size);
+ //Generate CPER record for the given type.
+ char *buf;
+ size_t size;
+ FILE *record = generate_record_memstream(§ion_name, 1, &buf, &size);
- //Convert to IR, then back to binary, getting a stream out.
- json_object* ir = cper_to_ir(record);
- char* cper_buf;
- size_t cper_buf_size;
- FILE* stream = open_memstream(&cper_buf, &cper_buf_size);
- ir_to_cper(ir, stream);
- size_t cper_len = ftell(stream);
- fclose(stream);
+ //Convert to IR, then back to binary, getting a stream out.
+ json_object *ir = cper_to_ir(record);
+ char *cper_buf;
+ size_t cper_buf_size;
+ FILE *stream = open_memstream(&cper_buf, &cper_buf_size);
+ ir_to_cper(ir, stream);
+ size_t cper_len = ftell(stream);
+ fclose(stream);
- //Validate the two are identical.
- ASSERT_GE(size, cper_len);
- ASSERT_EQ(memcmp(buf, cper_buf, cper_len), 0) << "Binary output was not identical to input.";
-
- //Free everything up.
- fclose(record);
- free(buf);
- free(cper_buf);
+ //Validate the two are identical.
+ ASSERT_GE(size, cper_len);
+ ASSERT_EQ(memcmp(buf, cper_buf, cper_len), 0)
+ << "Binary output was not identical to input.";
+
+ //Free everything up.
+ fclose(record);
+ free(buf);
+ free(cper_buf);
}
/*
* Single section tests.
*/
//Generic processor tests.
-TEST(GenericProcessorTests, IRValid) {
- single_section_ir_test("generic");
+TEST(GenericProcessorTests, IRValid)
+{
+ single_section_ir_test("generic");
}
-TEST(GenericProcessorTests, BinaryEqual) {
- single_section_binary_test("generic");
+TEST(GenericProcessorTests, BinaryEqual)
+{
+ single_section_binary_test("generic");
}
//IA32/x64 tests.
-TEST(IA32x64Tests, IRValid) {
- single_section_ir_test("ia32x64");
+TEST(IA32x64Tests, IRValid)
+{
+ single_section_ir_test("ia32x64");
}
-TEST(IA32x64Tests, BinaryEqual) {
- single_section_binary_test("ia32x64");
+TEST(IA32x64Tests, BinaryEqual)
+{
+ single_section_binary_test("ia32x64");
}
// TEST(IPFTests, IRValid) {
@@ -87,120 +93,148 @@
// }
//ARM tests.
-TEST(ArmTests, IRValid) {
- single_section_ir_test("arm");
+TEST(ArmTests, IRValid)
+{
+ single_section_ir_test("arm");
}
-TEST(ArmTests, BinaryEqual) {
- single_section_binary_test("arm");
+TEST(ArmTests, BinaryEqual)
+{
+ single_section_binary_test("arm");
}
//Memory tests.
-TEST(MemoryTests, IRValid) {
- single_section_ir_test("memory");
+TEST(MemoryTests, IRValid)
+{
+ single_section_ir_test("memory");
}
-TEST(MemoryTests, BinaryEqual) {
- single_section_binary_test("memory");
+TEST(MemoryTests, BinaryEqual)
+{
+ single_section_binary_test("memory");
}
//Memory 2 tests.
-TEST(Memory2Tests, IRValid) {
- single_section_ir_test("memory2");
+TEST(Memory2Tests, IRValid)
+{
+ single_section_ir_test("memory2");
}
-TEST(Memory2Tests, BinaryEqual) {
- single_section_binary_test("memory2");
+TEST(Memory2Tests, BinaryEqual)
+{
+ single_section_binary_test("memory2");
}
//PCIe tests.
-TEST(PCIeTests, IRValid) {
- single_section_ir_test("pcie");
+TEST(PCIeTests, IRValid)
+{
+ single_section_ir_test("pcie");
}
-TEST(PCIeTests, BinaryEqual) {
- single_section_binary_test("pcie");
+TEST(PCIeTests, BinaryEqual)
+{
+ single_section_binary_test("pcie");
}
//Firmware tests.
-TEST(FirmwareTests, IRValid) {
- single_section_ir_test("firmware");
+TEST(FirmwareTests, IRValid)
+{
+ single_section_ir_test("firmware");
}
-TEST(FirmwareTests, BinaryEqual) {
- single_section_binary_test("firmware");
+TEST(FirmwareTests, BinaryEqual)
+{
+ single_section_binary_test("firmware");
}
//PCI Bus tests.
-TEST(PCIBusTests, IRValid) {
- single_section_ir_test("pcibus");
+TEST(PCIBusTests, IRValid)
+{
+ single_section_ir_test("pcibus");
}
-TEST(PCIBusTests, BinaryEqual) {
- single_section_binary_test("pcibus");
+TEST(PCIBusTests, BinaryEqual)
+{
+ single_section_binary_test("pcibus");
}
//PCI Device tests.
-TEST(PCIDevTests, IRValid) {
- single_section_ir_test("pcidev");
+TEST(PCIDevTests, IRValid)
+{
+ single_section_ir_test("pcidev");
}
-TEST(PCIDevTests, BinaryEqual) {
- single_section_binary_test("pcidev");
+TEST(PCIDevTests, BinaryEqual)
+{
+ single_section_binary_test("pcidev");
}
//Generic DMAr tests.
-TEST(DMArGenericTests, IRValid) {
- single_section_ir_test("dmargeneric");
+TEST(DMArGenericTests, IRValid)
+{
+ single_section_ir_test("dmargeneric");
}
-TEST(DMArGenericTests, BinaryEqual) {
- single_section_binary_test("dmargeneric");
+TEST(DMArGenericTests, BinaryEqual)
+{
+ single_section_binary_test("dmargeneric");
}
//VT-d DMAr tests.
-TEST(DMArVtdTests, IRValid) {
- single_section_ir_test("dmarvtd");
+TEST(DMArVtdTests, IRValid)
+{
+ single_section_ir_test("dmarvtd");
}
-TEST(DMArVtdTests, BinaryEqual) {
- single_section_binary_test("dmarvtd");
+TEST(DMArVtdTests, BinaryEqual)
+{
+ single_section_binary_test("dmarvtd");
}
//IOMMU DMAr tests.
-TEST(DMArIOMMUTests, IRValid) {
- single_section_ir_test("dmariommu");
+TEST(DMArIOMMUTests, IRValid)
+{
+ single_section_ir_test("dmariommu");
}
-TEST(DMArIOMMUTests, BinaryEqual) {
- single_section_binary_test("dmariommu");
+TEST(DMArIOMMUTests, BinaryEqual)
+{
+ single_section_binary_test("dmariommu");
}
//CCIX PER tests.
-TEST(CCIXPERTests, IRValid) {
- single_section_ir_test("ccixper");
+TEST(CCIXPERTests, IRValid)
+{
+ single_section_ir_test("ccixper");
}
-TEST(CCIXPERTests, BinaryEqual) {
- single_section_binary_test("ccixper");
+TEST(CCIXPERTests, BinaryEqual)
+{
+ single_section_binary_test("ccixper");
}
//CXL Protocol tests.
-TEST(CXLProtocolTests, IRValid) {
- single_section_ir_test("cxlprotocol");
+TEST(CXLProtocolTests, IRValid)
+{
+ single_section_ir_test("cxlprotocol");
}
-TEST(CXLProtocolTests, BinaryEqual) {
- single_section_binary_test("cxlprotocol");
+TEST(CXLProtocolTests, BinaryEqual)
+{
+ single_section_binary_test("cxlprotocol");
}
//CXL Component tests.
-TEST(CXLComponentTests, IRValid) {
- single_section_ir_test("cxlcomponent");
+TEST(CXLComponentTests, IRValid)
+{
+ single_section_ir_test("cxlcomponent");
}
-TEST(CXLComponentTests, BinaryEqual) {
- single_section_binary_test("cxlcomponent");
+TEST(CXLComponentTests, BinaryEqual)
+{
+ single_section_binary_test("cxlcomponent");
}
//Unknown section tests.
-TEST(UnknownSectionTests, IRValid) {
- single_section_ir_test("unknown");
+TEST(UnknownSectionTests, IRValid)
+{
+ single_section_ir_test("unknown");
}
-TEST(UnknownSectionTests, BinaryEqual) {
- single_section_binary_test("unknown");
+TEST(UnknownSectionTests, BinaryEqual)
+{
+ single_section_binary_test("unknown");
}
//Entrypoint for the testing program.
int main()
{
- testing::InitGoogleTest();
- return RUN_ALL_TESTS();
+ testing::InitGoogleTest();
+ return RUN_ALL_TESTS();
}
\ No newline at end of file
diff --git a/tests/test-utils.cpp b/tests/test-utils.cpp
index 0d4cabf..b7e263a 100644
--- a/tests/test-utils.cpp
+++ b/tests/test-utils.cpp
@@ -13,15 +13,16 @@
}
//Returns a ready-for-use memory stream containing a CPER record with the given sections inside.
-FILE* generate_record_memstream(const char** types, UINT16 num_types, char** buf, size_t* buf_size)
+FILE *generate_record_memstream(const char **types, UINT16 num_types,
+ char **buf, size_t *buf_size)
{
- //Open a memory stream.
- FILE* stream = open_memstream(buf, buf_size);
+ //Open a memory stream.
+ FILE *stream = open_memstream(buf, buf_size);
- //Generate a section to the stream, close & return.
- generate_cper_record((char**)types, num_types, stream);
- fclose(stream);
+ //Generate a section to the stream, close & return.
+ generate_cper_record((char **)types, num_types, stream);
+ fclose(stream);
- //Return fmemopen() buffer for reading.
- return fmemopen(*buf, *buf_size, "r");
+ //Return fmemopen() buffer for reading.
+ return fmemopen(*buf, *buf_size, "r");
}
\ No newline at end of file