target/mips/cpu: Move initialization of memory region to realize function
PATCH 1/1 target/mips/cpu: Move initialization of memory region to realize function
From: Thomas Huth <[email protected]>
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 <[email protected]>
Signed-off-by Thomas Huth <[email protected]>
--- target/mips/cpu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
target/mips/cpu.c +8 -8
@@ -460,6 +460,14 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)MIPSCPUClass *mcc =MIPS_CPU_GET_CLASS (dev);Error *local_err =NULL ; +#ifndef CONFIG_USER_ONLY +if (mcc->cpu_def->lcsr_cpucfg2 & (1 <<CPUCFG2_LCSRP )) { +memory_region_init_io (&env->iocsr.mr,OBJECT (cpu),NULL , + env,"iocsr" ,UINT64_MAX ); +address_space_init (&env->iocsr.as, &env->iocsr.mr,"IOCSR" ); + } +#endif +if (!clock_get (cpu->clock)) {#ifndef CONFIG_USER_ONLY if (!qtest_enabled ()) {
@@ -504,14 +512,6 @@ static void mips_cpu_initfn(Object *obj) cpu->count_div =clock_new (OBJECT (obj),"clk-div-count" ); env->count_clock =clock_new (OBJECT (obj),"clk-count" ); env->cpu_model = mcc->cpu_def; -#ifndef CONFIG_USER_ONLY -if (mcc->cpu_def->lcsr_cpucfg2 & (1 <<CPUCFG2_LCSRP )) { -memory_region_init_io (&env->iocsr.mr,OBJECT (cpu),NULL , - env,"iocsr" ,UINT64_MAX ); -address_space_init (&env->iocsr.as, - &env->iocsr.mr,"IOCSR" ); - } -#endif }static char *mips_cpu_type_name (const char *cpu_model)
Signature · 1 line
2.53.0
Quoted 10 lines · Thomas Huth
From: Thomas Huth <[email protected]>
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)
Quoted 5 lines
Move the initialization of the memory regions to the realize function to fix this problem.
Reported-by Markus Armbruster <[email protected]>Signed-off-by Thomas Huth <[email protected]>
See also my ramblings in reply to the related xtensa patch:
Subject: Re: [PATCH] target/xtensa/cpu: Move initialization of memory region to realize function
Date: Thu, 12 Mar 2026 08:51:43 +0100
Message-ID: <[email protected]>Quoted 28 lines
--- target/mips/cpu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)target/mips/cpu.c +8
-1@@ -460,6 +460,14 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)MIPSCPUClass *mcc =MIPS_CPU_GET_CLASS (dev);Error *local_err =NULL ; +#ifndef CONFIG_USER_ONLY +if (mcc->cpu_def->lcsr_cpucfg2 & (1 <<CPUCFG2_LCSRP )) { +memory_region_init_io (&env->iocsr.mr,OBJECT (cpu),NULL , + env,"iocsr" ,UINT64_MAX ); +address_space_init (&env->iocsr.as, &env->iocsr.mr,"IOCSR" ); + } +#endif +if (!clock_get (cpu->clock)) {#ifndef CONFIG_USER_ONLY if (!qtest_enabled ()) {@@ -504,14 +512,6 @@ static void mips_cpu_initfn(Object *obj) cpu->count_div =clock_new (OBJECT (obj),"clk-div-count" ); env->count_clock =clock_new (OBJECT (obj),"clk-count" ); env->cpu_model = mcc->cpu_def; -#ifndef CONFIG_USER_ONLY
target/mips/cpu.c static void mips_cpu_initfn(Object *obj) · line 517
Quoted 10 lines
target/mips/cpu.c +0
-7-if (mcc->cpu_def->lcsr_cpucfg2 & (1 <<CPUCFG2_LCSRP )) { -memory_region_init_io (&env->iocsr.mr,OBJECT (cpu),NULL , - env,"iocsr" ,UINT64_MAX ); -address_space_init (&env->iocsr.as, - &env->iocsr.mr,"IOCSR" ); - } -#endif }static char *mips_cpu_type_name (const char *cpu_model)
Tested-by Markus Armbruster <[email protected]>