[RFC PATCH 06/12] hw/m68k: just use reset_pc for virt platform

Alex Bennée posted 12 patches 1 month ago
Maintainers: Thomas Huth <huth@tuxfamily.org>, Laurent Vivier <laurent@vivier.eu>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Peter Maydell <peter.maydell@linaro.org>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Yoshinori Sato <yoshinori.sato@nifty.com>, Bastian Koppelmann <kbastian@rumtueddeln.de>
[RFC PATCH 06/12] hw/m68k: just use reset_pc for virt platform
Posted by Alex Bennée 1 month ago
We never actually set initial_stack so revert to the previous
behaviour and stash pc in the common env->reset_pc holding place.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 hw/m68k/virt.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index e67900c727d..6af74b7ba1d 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -87,21 +87,14 @@
 #define VIRT_VIRTIO_MMIO_BASE 0xff010000     /* MMIO: 0xff010000 - 0xff01ffff */
 #define VIRT_VIRTIO_IRQ_BASE  PIC_IRQ(2, 1)  /* PIC: 2, 3, 4, 5, IRQ: ALL */
 
-typedef struct {
-    M68kCPU *cpu;
-    hwaddr initial_pc;
-    hwaddr initial_stack;
-} ResetInfo;
-
 static void main_cpu_reset(void *opaque)
 {
-    ResetInfo *reset_info = opaque;
-    M68kCPU *cpu = reset_info->cpu;
+    M68kCPU *cpu = opaque;
     CPUState *cs = CPU(cpu);
 
     cpu_reset(cs);
-    cpu->env.aregs[7] = reset_info->initial_stack;
-    cpu->env.pc = reset_info->initial_pc;
+    cpu->env.aregs[7] = ldl_phys(cs->as, 0);
+    cpu->env.pc = cpu->env.reset_pc;
 }
 
 static void rerandomize_rng_seed(void *opaque)
@@ -129,8 +122,8 @@ static void virt_init(MachineState *machine)
     SysBusDevice *sysbus;
     hwaddr io_base;
     int i;
-    ResetInfo *reset_info;
     uint8_t rng_seed[32];
+    CPUM68KState *env;
 
     if (ram_size > 3399672 * KiB) {
         /*
@@ -142,13 +135,10 @@ static void virt_init(MachineState *machine)
         exit(1);
     }
 
-    reset_info = g_new0(ResetInfo, 1);
-
     /* init CPUs */
     cpu = M68K_CPU(cpu_create(machine->cpu_type));
-
-    reset_info->cpu = cpu;
-    qemu_register_reset(main_cpu_reset, reset_info);
+    qemu_register_reset(main_cpu_reset, cpu);
+    env = &cpu->env;
 
     /* RAM */
     memory_region_add_subregion(get_system_memory(), 0, machine->ram);
@@ -235,7 +225,7 @@ static void virt_init(MachineState *machine)
             error_report("could not load kernel '%s'", kernel_filename);
             exit(1);
         }
-        reset_info->initial_pc = elf_entry;
+        env->reset_pc = elf_entry;
         parameters_base = (high + 1) & ~1;
         param_ptr = param_blob;
 
-- 
2.47.3


Re: [RFC PATCH 06/12] hw/m68k: just use reset_pc for virt platform
Posted by Richard Henderson 4 weeks ago
On 1/9/26 01:34, Alex Bennée wrote:
> @@ -129,8 +122,8 @@ static void virt_init(MachineState *machine)
>       SysBusDevice *sysbus;
>       hwaddr io_base;
>       int i;
> -    ResetInfo *reset_info;
>       uint8_t rng_seed[32];
> +    CPUM68KState *env;
>   
>       if (ram_size > 3399672 * KiB) {
>           /*
> @@ -142,13 +135,10 @@ static void virt_init(MachineState *machine)
>           exit(1);
>       }
>   
> -    reset_info = g_new0(ResetInfo, 1);
> -
>       /* init CPUs */
>       cpu = M68K_CPU(cpu_create(machine->cpu_type));
> -
> -    reset_info->cpu = cpu;
> -    qemu_register_reset(main_cpu_reset, reset_info);
> +    qemu_register_reset(main_cpu_reset, cpu);
> +    env = &cpu->env;
>   
>       /* RAM */
>       memory_region_add_subregion(get_system_memory(), 0, machine->ram);
> @@ -235,7 +225,7 @@ static void virt_init(MachineState *machine)
>               error_report("could not load kernel '%s'", kernel_filename);
>               exit(1);
>           }
> -        reset_info->initial_pc = elf_entry;
> +        env->reset_pc = elf_entry;
>           parameters_base = (high + 1) & ~1;
>           param_ptr = param_blob;
>   

Why introduce env rather than use cpu->env like elsewhere in the function?

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

Re: [RFC PATCH 06/12] hw/m68k: just use reset_pc for virt platform
Posted by Thomas Huth 1 month ago
Am Thu,  8 Jan 2026 14:34:17 +0000
schrieb Alex Bennée <alex.bennee@linaro.org>:

> We never actually set initial_stack so revert to the previous
> behaviour and stash pc in the common env->reset_pc holding place.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  hw/m68k/virt.c | 24 +++++++-----------------
>  1 file changed, 7 insertions(+), 17 deletions(-)

Reviewed-by: Thomas Huth <huth@tuxfamily.org>