From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-s390x@nongnu.org, "Michael Rolnik" <mrolnik@gmail.com>,
"BALATON Zoltan" <balaton@eik.bme.hu>,
"Gihun Nam" <gihun.nam@outlook.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 6/7] hw/avr/atmega: Fix wrong initial value of stack pointer
Date: Tue, 28 Nov 2023 14:37:39 +0100 [thread overview]
Message-ID: <20231128133740.64525-7-philmd@linaro.org> (raw)
In-Reply-To: <20231128133740.64525-1-philmd@linaro.org>
From: Gihun Nam <gihun.nam@outlook.com>
The current implementation initializes the stack pointer of AVR devices
to 0. Although older AVR devices used to be like that, newer ones set
it to RAMEND.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1525
Signed-off-by: Gihun Nam <gihun.nam@outlook.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <PH0P222MB0010877445B594724D40C924DEBDA@PH0P222MB0010.NAMP222.PROD.OUTLOOK.COM>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/avr/cpu.h | 3 +++
hw/avr/atmega.c | 4 ++++
target/avr/cpu.c | 10 +++++++++-
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/target/avr/cpu.h b/target/avr/cpu.h
index 8a17862737..7960c5c57a 100644
--- a/target/avr/cpu.h
+++ b/target/avr/cpu.h
@@ -145,6 +145,9 @@ struct ArchCPU {
CPUState parent_obj;
CPUAVRState env;
+
+ /* Initial value of stack pointer */
+ uint32_t init_sp;
};
/**
diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c
index a34803e642..31c8992d75 100644
--- a/hw/avr/atmega.c
+++ b/hw/avr/atmega.c
@@ -233,6 +233,10 @@ static void atmega_realize(DeviceState *dev, Error **errp)
/* CPU */
object_initialize_child(OBJECT(dev), "cpu", &s->cpu, mc->cpu_type);
+
+ object_property_set_uint(OBJECT(&s->cpu), "init-sp",
+ mc->io_size + mc->sram_size - 1, &error_abort);
+
qdev_realize(DEVICE(&s->cpu), NULL, &error_abort);
cpudev = DEVICE(&s->cpu);
diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index 44de1e18d1..999c010ded 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -25,6 +25,7 @@
#include "cpu.h"
#include "disas/dis-asm.h"
#include "tcg/debug-assert.h"
+#include "hw/qdev-properties.h"
static void avr_cpu_set_pc(CPUState *cs, vaddr value)
{
@@ -95,7 +96,7 @@ static void avr_cpu_reset_hold(Object *obj)
env->rampY = 0;
env->rampZ = 0;
env->eind = 0;
- env->sp = 0;
+ env->sp = cpu->init_sp;
env->skip = 0;
@@ -152,6 +153,11 @@ static void avr_cpu_initfn(Object *obj)
sizeof(cpu->env.intsrc) * 8);
}
+static Property avr_cpu_properties[] = {
+ DEFINE_PROP_UINT32("init-sp", AVRCPU, init_sp, 0),
+ DEFINE_PROP_END_OF_LIST()
+};
+
static ObjectClass *avr_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
@@ -228,6 +234,8 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
device_class_set_parent_realize(dc, avr_cpu_realizefn, &mcc->parent_realize);
+ device_class_set_props(dc, avr_cpu_properties);
+
resettable_class_set_parent_phases(rc, NULL, avr_cpu_reset_hold, NULL,
&mcc->parent_phases);
--
2.41.0
next prev parent reply other threads:[~2023-11-28 13:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 13:37 [PULL 0/7] Misc fixes for 2023-11-28 Philippe Mathieu-Daudé
2023-11-28 13:37 ` [PULL 1/7] target/hexagon/idef-parser/prepare: use env to invoke bash Philippe Mathieu-Daudé
2023-11-28 13:37 ` [PULL 2/7] hw/isa/vt82c686: Bring back via_isa_set_irq() Philippe Mathieu-Daudé
2023-11-28 13:37 ` [PULL 3/7] hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts Philippe Mathieu-Daudé
2023-11-28 13:37 ` [PULL 4/7] hw/isa/vt82c686: Route PIRQ inputs using via_isa_set_irq() Philippe Mathieu-Daudé
2023-11-28 13:37 ` [PULL 5/7] hw/audio/via-ac97: Route interrupts " Philippe Mathieu-Daudé
2023-11-28 13:37 ` Philippe Mathieu-Daudé [this message]
2023-11-28 13:37 ` [PULL 7/7] docs/s390: Fix wrong command example in s390-cpu-topology.rst Philippe Mathieu-Daudé
2023-11-28 23:14 ` [PULL 0/7] Misc fixes for 2023-11-28 Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231128133740.64525-7-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=balaton@eik.bme.hu \
--cc=gihun.nam@outlook.com \
--cc=mrolnik@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).