For now, we expect only one target to be available at runtime. This will change with the single-binary and we'll detect which one to use dynamically.
Signed-off-by: Pierrick Bouvier <[email protected]> --- include/qemu/target-info-qom.h | 2 ++ system/vl.c | 2 ++ target-info-qom.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/include/qemu/target-info-qom.h b/include/qemu/target-info-qom.h index db069db718a..9549465aa64 100644 --- a/include/qemu/target-info-qom.h +++ b/include/qemu/target-info-qom.h @@ -21,3 +21,5 @@ typedef struct TargetInfoQomClass { } TargetInfoQomClass; OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO) + +void target_info_qom_set_target(void); diff --git a/system/vl.c b/system/vl.c index b4a5ea6f857..96a03ff2ff7 100644 --- a/system/vl.c +++ b/system/vl.c @@ -28,6 +28,7 @@ #include "qemu/units.h" #include "qemu/module.h" #include "qemu/target-info.h" +#include "qemu/target-info-qom.h" #include "exec/cpu-common.h" #include "exec/page-vary.h" #include "hw/core/qdev-properties.h" @@ -2891,6 +2892,7 @@ void qemu_init(int argc, char **argv) module_init_info(qemu_modinfo); /* We need to initialize QOM first to detect target */ module_call_init(MODULE_INIT_QOM); + target_info_qom_set_target(); module_allow_arch(target_name()); diff --git a/target-info-qom.c b/target-info-qom.c index 5ce29f80301..748fdd5a8fb 100644 --- a/target-info-qom.c +++ b/target-info-qom.c @@ -32,3 +32,20 @@ static const TypeInfo target_info_types[] = { }; DEFINE_TYPES(target_info_types) + +static const TargetInfo *target_info_ptr; + +void target_info_qom_set_target(void) +{ + g_autoptr(GSList) targets = + object_class_get_list_by_name_prefix(TYPE_TARGET_INFO, false); + + size_t num_found = g_slist_length(targets); + if (num_found != 1) { + error_setg(&error_fatal, num_found == 0 ? + "no target-info is available" : + "more than one target-info is available"); + } + + target_info_ptr = TARGET_INFO_CLASS(targets->data)->target_info; +} -- 2.43.0
