@@ -40,6 +40,7 @@ struct MIPSCPSState {
char *cpu_type;
bool cpu_is_bigendian;
+ MIPSCPU **cpus;
MemoryRegion container;
MIPSGCRState gcr;
MIPSGICState gic;
@@ -73,6 +73,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
return;
}
+ s->cpus = g_new(MIPSCPU *, s->num_vp);
for (int i = 0; i < s->num_vp; i++) {
MIPSCPU *cpu = MIPS_CPU(object_new(s->cpu_type));
CPUMIPSState *env = &cpu->env;
@@ -91,6 +92,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
if (!qdev_realize_and_unref(DEVICE(cpu), NULL, errp)) {
return;
}
+ s->cpus[i] = cpu;
/* Init internal devices */
cpu_mips_irq_init_cpu(cpu);
@@ -146,7 +148,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0));
/* Global Configuration Registers */
- gcr_base = MIPS_CPU(first_cpu)->env.CP0_CMGCRBase << 4;
+ gcr_base = s->cpus[0]->env.CP0_CMGCRBase << 4;
object_initialize_child(OBJECT(dev), "gcr", &s->gcr, TYPE_MIPS_GCR);
object_property_set_uint(OBJECT(&s->gcr), "num-vp", s->num_vp,
When a QOM object create children with object_new(), it is better to keep reference to them for further use. In particular, this allow to remove one global &first_cpu use. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/hw/mips/cps.h | 1 + hw/mips/cps.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)