target/mips/cpu: Move initialization of memory region to realize function
When introspecting the Loongson-3A4000 CPUs from the command line, QEMU currently crashes: $ ./qemu-system-mips64el -device Loongson-3A4000-mips64-cpu,help qemu-system-mips64el: ../../devel/qemu/system/physmem.c:1401: register_multipage: Assertion `num_pages' failed. Aborted (core dumped) Move the initialization of the memory regions to the realize function to fix this problem. Reported-by: Markus Armbruster <armbru@redhat.com> Message-ID: <87y0jxzdrk.fsf@pond.sub.org> Tested-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com> Message-ID: <20260311211629.118608-1-thuth@redhat.com>
Thomas Huth committed
Mar 11, 2026 at 22:16 UTC
0dcaa42694aa799cabb8db2fbd06ed1ce26d7b4c
1 file changed
+8
-8
target/mips/cpu.c
+8
-8
@@ -460,6 +460,14 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)
460
MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(dev);
461
Error *local_err = NULL;
462
463
+#ifndef CONFIG_USER_ONLY
464
+ if (mcc->cpu_def->lcsr_cpucfg2 & (1 << CPUCFG2_LCSRP)) {
465
+ memory_region_init_io(&env->iocsr.mr, OBJECT(cpu), NULL,
466
+ env, "iocsr", UINT64_MAX);
467
+ address_space_init(&env->iocsr.as, &env->iocsr.mr, "IOCSR");
468
+ }
469
+#endif
470
+
471
if (!clock_get(cpu->clock)) {
472
#ifndef CONFIG_USER_ONLY
473
if (!qtest_enabled()) {
@@ -504,14 +512,6 @@ static void mips_cpu_initfn(Object *obj)
512
cpu->count_div = clock_new(OBJECT(obj), "clk-div-count");
513
env->count_clock = clock_new(OBJECT(obj), "clk-count");
514
env->cpu_model = mcc->cpu_def;
507
-#ifndef CONFIG_USER_ONLY
508
- if (mcc->cpu_def->lcsr_cpucfg2 & (1 << CPUCFG2_LCSRP)) {
509
- memory_region_init_io(&env->iocsr.mr, OBJECT(cpu), NULL,
510
- env, "iocsr", UINT64_MAX);
511
- address_space_init(&env->iocsr.as,
512
- &env->iocsr.mr, "IOCSR");
513
- }
514
-#endif
515
}
516
517
static char *mips_cpu_type_name(const char *cpu_model)