On Sun, Nov 01, 2026 at 12:40:01AM +0800, Yonggang Luo wrote: > max-v8 was one TypeInfo whose instance initializer was chosen from the > selected target at registration. Register both initializers, and let > target_arm() and target_aarch64() select which type is available. > > Reviewed-by: Pierrick Bouvier <[email protected]> > Signed-off-by: Yonggang Luo <[email protected]> > --- > target/arm/cpu.c | 1 + > target/arm/cpu.h | 1 + > target/arm/tcg/cpu-max-v8.c | 16 ++++++++++++---- > 3 files changed, 14 insertions(+), 4 deletions(-) > > diff --git a/target/arm/cpu.c b/target/arm/cpu.c > index 510fc9eeb3b..6eb55242980 100644 > --- a/target/arm/cpu.c > +++ b/target/arm/cpu.c > @@ -2695,6 +2695,7 @@ void arm_cpu_register(const ARMCPUInfo *info) > .instance_init = arm_cpu_instance_init, > .class_init = info->class_init ?: cpu_register_class_init, > .class_data = info, > + .is_available = info->is_available, > }; > > type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name); > diff --git a/target/arm/cpu.h b/target/arm/cpu.h > index add993ef101..3240a8633ee 100644 > --- a/target/arm/cpu.h > +++ b/target/arm/cpu.h > @@ -1203,6 +1203,7 @@ typedef struct ARMCPUInfo { > const char *deprecation_note; > void (*initfn)(Object *obj); > void (*class_init)(ObjectClass *oc, const void *data); > + bool (*is_available)(void); > } ARMCPUInfo; > > /** > diff --git a/target/arm/tcg/cpu-max-v8.c b/target/arm/tcg/cpu-max-v8.c > index 65f851f2006..e819d07e6ce 100644 > --- a/target/arm/tcg/cpu-max-v8.c > +++ b/target/arm/tcg/cpu-max-v8.c > @@ -121,10 +121,18 @@ void aarch32_max_v8_tcg_initfn(Object *obj) > > static void cpu_max_v8_register_type(void) > { > - static const ARMCPUInfo max_v8[2] = { > - { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn }, > - { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn }, > + static const ARMCPUInfo max_v8_aarch32 = { > + .name = "max-v8", > + .initfn = aarch32_max_v8_tcg_initfn, > + .is_available = target_arm, > }; > - arm_cpu_register(&max_v8[target_aarch64()]); > + static const ARMCPUInfo max_v8_aarch64 = { > + .name = "max-v8", > + .initfn = aarch64_max_v8_tcg_initfn, > + .is_available = target_aarch64, > + }; > + > + arm_cpu_register(&max_v8_aarch32); > + arm_cpu_register(&max_v8_aarch64); > } > type_init(cpu_max_v8_register_type)
Conceptually these are two separate CPUs one 32-bit featureset and one 64-bit featureset, but both given the same name. The current code registers them only in the respective arm and aarch64 target binaries, but this CPU is an oddity overall. More generally the aarch64 emulator includes all the 32-bit CPUs that the arm emulator includes, and just adds extra 64-bit CPUs. IOW, excluding the 32-bit max-v8 CPU is a special case - if it were not for the clashing name, it would be included like all the other 32-bit CPUs. Thus rather than using is_available to continue to exclude it, we must instead resolve the naming problem, such that both models can be included concurrently. One approach to this is to consider the generic 'max-v8' name to be an alias, that is resolved to the underlying real CPU name 'max-v8-64' vs 'max-v8-32'. Allow the aliases to be ambiguous, and either the selected target_info() disambiguates aliases, or apps can use the canonical name instead of the alias. With regards, Daniel -- |: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
