On Sat, 15 Feb 2025 at 02:17, Keith Packard via <qemu-devel@nongnu.org> wrote:
>
> This ensure that the CPU gets reset every time QEMU resets.
>
> Signed-off-by: Keith Packard <kei...@keithp.com>
> ---
>  target/rx/cpu.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/target/rx/cpu.c b/target/rx/cpu.c
> index 37a6fdd569..04dd34b310 100644
> --- a/target/rx/cpu.c
> +++ b/target/rx/cpu.c
> @@ -27,6 +27,7 @@
>  #include "hw/loader.h"
>  #include "fpu/softfloat.h"
>  #include "tcg/debug-assert.h"
> +#include "system/reset.h"
>
>  static void rx_cpu_set_pc(CPUState *cs, vaddr value)
>  {
> @@ -129,6 +130,13 @@ static ObjectClass *rx_cpu_class_by_name(const char 
> *cpu_model)
>      return oc;
>  }
>
> +static void rx_cpu_reset(void *opaque)
> +{
> +    RXCPU *cpu = opaque;
> +
> +    cpu_reset(CPU(cpu));
> +}
> +
>  static void rx_cpu_realize(DeviceState *dev, Error **errp)
>  {
>      CPUState *cs = CPU(dev);
> @@ -142,9 +150,10 @@ static void rx_cpu_realize(DeviceState *dev, Error 
> **errp)
>      }
>
>      qemu_init_vcpu(cs);
> -    cpu_reset(cs);
>
>      rcc->parent_realize(dev, errp);
> +
> +    qemu_register_reset(rx_cpu_reset, RX_CPU(cs));
>  }

Reset of devices not plugged into buses (of which CPUs
are the most common kind) is a mess. But having them
call qemu_register_reset() themselves in their own
realize method isn't the usual workaround. Instead we
get the board code to do it (usually in the same function
that handles arranging to sort out the in-QEMU boot
loader, see eg hw/arm/boot.c).

thanks
-- PMM

Reply via email to