target/xtensa/cpu: Move initialization of memory region to realize function
When introspecting the xtensa CPUs from the command line, QEMU currently crashes: $ ./qemu-system-xtensa -device dc233c-xtensa-cpu,help qemu-system-xtensa: ../../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> Tested-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com> Message-ID: <20260311202503.107026-1-thuth@redhat.com>
Thomas Huth committed
Mar 11, 2026 at 21:25 UTC
7b743d01c32d618190861209c69522cae8ef3276
1 file changed
+8
-6
target/xtensa/cpu.c
+8
-6
@@ -244,6 +244,14 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp)
244
Error *local_err = NULL;
245
246
#ifndef CONFIG_USER_ONLY
247
+ CPUXtensaState *env = &XTENSA_CPU(dev)->env;
248
+
249
+ env->address_space_er = g_malloc(sizeof(*env->address_space_er));
250
+ env->system_er = g_malloc(sizeof(*env->system_er));
251
+ memory_region_init_io(env->system_er, OBJECT(dev), NULL, env, "er",
252
+ UINT64_C(0x100000000));
253
+ address_space_init(env->address_space_er, env->system_er, "ER");
254
+
255
xtensa_irq_init(&XTENSA_CPU(dev)->env);
256
#endif
257
@@ -269,12 +277,6 @@ static void xtensa_cpu_initfn(Object *obj)
277
env->config = xcc->config;
278
279
#ifndef CONFIG_USER_ONLY
272
- env->address_space_er = g_malloc(sizeof(*env->address_space_er));
273
- env->system_er = g_malloc(sizeof(*env->system_er));
274
- memory_region_init_io(env->system_er, obj, NULL, env, "er",
275
- UINT64_C(0x100000000));
276
- address_space_init(env->address_space_er, env->system_er, "ER");
277
-
280
cpu->clock = qdev_init_clock_in(DEVICE(obj), "clk-in", NULL, cpu, 0);
281
clock_set_hz(cpu->clock, env->config->clock_freq_khz * 1000);
282
#endif