On 2/6/25 10:26, Paolo Bonzini wrote:
Start putting all the CPU definitions in a struct. Later this will replace
instance_init functions with declarative code, for now just remove the
ugly cast of class_data.
...
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index ed9da692030..29cfae38b75 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -2955,7 +2955,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void
*data)
{
RISCVCPUClass *mcc = RISCV_CPU_CLASS(c);
- mcc->misa_mxl_max = (uint32_t)(uintptr_t)data;
+ mcc->misa_mxl_max = ((RISCVCPUDef *)data)->misa_mxl_max;
riscv_cpu_validate_misa_mxl(mcc);
}
@@ -3051,40 +3051,48 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename)
}
#endif
-#define DEFINE_DYNAMIC_CPU(type_name, misa_mxl_max, initfn) \
+#define DEFINE_DYNAMIC_CPU(type_name, misa_mxl_max_, initfn) \
{ \
.name = (type_name), \
.parent = TYPE_RISCV_DYNAMIC_CPU, \
.instance_init = (initfn), \
.class_init = riscv_cpu_class_init, \
- .class_data = (void *)(misa_mxl_max) \
+ .class_data = &((RISCVCPUDef) { \
+ .misa_mxl_max = (misa_mxl_max_), \
+ }), \
Drop the unnecessary ().
It would be nice if this were const, i.e.
.class_data = (void *) &(const RISCVCPUDef){
...
},
This will in fact create an anonymous object in .rodata.
We have other uses that do the extra casting away const,
e.g. armsse_variants in hw/arm/armsse.c. Although I suspect
*all* usage of .class_init can and should be with const data.
An unrelated cleanup, to be sure.
r~