On 3/25/25 08:40, Philippe Mathieu-Daudé wrote:
> "target/foo/cpu-qom.h" can not use any target specific definitions.
>
> Currently "target/mips/cpu-qom.h" defines TYPE_MIPS_CPU depending
> on the mips(32)/mips64 build type. This doesn't scale in a
> heterogeneous context where we need to access both types concurrently.
>
> In order to do that, introduce the new MIPS32_CPU / MIPS64_CPU types,
> both inheriting a common TYPE_MIPS_CPU base type.
>
> Keep the current CPU types registered in mips_register_cpudef_type()
> as 32 or 64-bit, but instead of depending on the binary built being
> targeting 32/64-bit, check whether the CPU is 64-bit by looking at
> the CPU_MIPS64 bit.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/mips/cpu-qom.h | 12 ++++++------
> target/mips/cpu.c | 11 ++++++++++-
> 2 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/target/mips/cpu-qom.h b/target/mips/cpu-qom.h
> index 0eea2a2598e..9acf647420c 100644
> --- a/target/mips/cpu-qom.h
> +++ b/target/mips/cpu-qom.h
> @@ -1,5 +1,5 @@
> /*
> - * QEMU MIPS CPU
> + * QEMU MIPS CPU QOM header (target agnostic)
> *
> * Copyright (c) 2012 SUSE LINUX Products GmbH
> *
> @@ -22,12 +22,12 @@
>
> #include "hw/core/cpu.h"
>
> -#ifdef TARGET_MIPS64
> -#define TYPE_MIPS_CPU "mips64-cpu"
> -#else
> -#define TYPE_MIPS_CPU "mips-cpu"
> -#endif
> +#define TYPE_MIPS32_CPU "mips32-cpu"
> +#define TYPE_MIPS64_CPU "mips64-cpu"
> +#define TYPE_MIPS_CPU "mips-cpu"
>
> +OBJECT_DECLARE_CPU_TYPE(MIPS32CPU, MIPSCPUClass, MIPS32_CPU)
> +OBJECT_DECLARE_CPU_TYPE(MIPS64CPU, MIPSCPUClass, MIPS64_CPU)
> OBJECT_DECLARE_CPU_TYPE(MIPSCPU, MIPSCPUClass, MIPS_CPU)
>
> #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
> index 097554fd8ae..5ed6b3402d3 100644
> --- a/target/mips/cpu.c
> +++ b/target/mips/cpu.c
> @@ -607,6 +607,14 @@ static const TypeInfo mips_cpu_types[] = {
> .abstract = true,
> .class_size = sizeof(MIPSCPUClass),
> .class_init = mips_cpu_class_init,
> + }, {
> + .name = TYPE_MIPS32_CPU,
> + .parent = TYPE_MIPS_CPU,
> + .abstract = true,
> + }, {
> + .name = TYPE_MIPS64_CPU,
> + .parent = TYPE_MIPS_CPU,
> + .abstract = true,
> }
> };
>
> @@ -623,7 +631,8 @@ static void mips_register_cpudef_type(const struct mips_def_t *def)
> char *typename = mips_cpu_type_name(def->name);
> TypeInfo ti = {
> .name = typename,
> - .parent = TYPE_MIPS_CPU,
> + .parent = def->insn_flags & CPU_MIPS64
> + ? TYPE_MIPS64_CPU : TYPE_MIPS32_CPU,
> .class_init = mips_cpu_cpudef_class_init,
> .class_data = (void *)def,
> };
I'm not sure we absolutely need to introduce a new common type
TYPE_MIPS_CPU.
If types don't share any common data, or have specific method applying
to them, I would just define 32/64 types without a common ancestor.
That said, if you prefer, or if needed, I'm ok with the patch as it is:
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>