qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 14/24] target/arm: Make SYS_HEAPINFO work with RAM that doesn't start at 0
Date: Mon, 23 Nov 2020 11:43:05 +0000	[thread overview]
Message-ID: <20201123114315.13372-15-peter.maydell@linaro.org> (raw)
In-Reply-To: <20201123114315.13372-1-peter.maydell@linaro.org>

The semihosting SYS_HEAPINFO call is supposed to return an array
of four guest addresses:
 * base of heap memory
 * limit of heap memory
 * base of stack memory
 * limit of stack memory

Some semihosting programs (including those compiled to use the
'newlib' embedded C library) use this call to work out where they
should initialize themselves to.

QEMU's implementation when in system emulation mode is very
simplistic: we say that the heap starts halfway into RAM and
continues to the end of RAM, and the stack starts at the top of RAM
and works down to the bottom.  Unfortunately the code assumes that
the base address of RAM is at address 0, so on boards like 'virt'
where this is not true the addresses returned will all be wrong and
the guest application will usually crash.

Conveniently since all Arm boards call arm_load_kernel() we have the
base address of the main RAM block in the arm_boot_info struct which
is accessible via the CPU object.  Use this to return sensible values
from SYS_HEAPINFO.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Message-id: 20201119092346.32356-1-peter.maydell@linaro.org
---
 target/arm/arm-semi.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
index c1df664f7e5..c892e0e674e 100644
--- a/target/arm/arm-semi.c
+++ b/target/arm/arm-semi.c
@@ -36,6 +36,7 @@
 #else
 #include "exec/gdbstub.h"
 #include "qemu/cutils.h"
+#include "hw/arm/boot.h"
 #endif
 
 #define TARGET_SYS_OPEN        0x01
@@ -1014,6 +1015,9 @@ target_ulong do_arm_semihosting(CPUARMState *env)
             int i;
 #ifdef CONFIG_USER_ONLY
             TaskState *ts = cs->opaque;
+#else
+            const struct arm_boot_info *info = env->boot_info;
+            target_ulong rambase = info->loader_start;
 #endif
 
             GET_ARG(0);
@@ -1046,10 +1050,10 @@ target_ulong do_arm_semihosting(CPUARMState *env)
 #else
             limit = ram_size;
             /* TODO: Make this use the limit of the loaded application.  */
-            retvals[0] = limit / 2;
-            retvals[1] = limit;
-            retvals[2] = limit; /* Stack base */
-            retvals[3] = 0; /* Stack limit.  */
+            retvals[0] = rambase + limit / 2;
+            retvals[1] = rambase + limit;
+            retvals[2] = rambase + limit; /* Stack base */
+            retvals[3] = rambase; /* Stack limit.  */
 #endif
 
             for (i = 0; i < ARRAY_SIZE(retvals); i++) {
-- 
2.20.1



  parent reply	other threads:[~2020-11-23 11:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 11:42 [PULL 00/24] target-arm queue Peter Maydell
2020-11-23 11:42 ` [PULL 01/24] target/arm: fix stage 2 page-walks in 32-bit emulation Peter Maydell
2020-11-23 11:42 ` [PULL 02/24] hw/arm: Fix bad print format specifiers Peter Maydell
2020-11-23 11:42 ` [PULL 03/24] hw/intc: fix heap-buffer-overflow in rxicu_realize() Peter Maydell
2020-11-23 11:42 ` [PULL 04/24] MAINTAINERS: Cover system/arm/cpu-features.rst with ARM TCG CPUs Peter Maydell
2020-11-23 11:42 ` [PULL 05/24] MAINTAINERS: Cover system/arm/aspeed.rst with ASPEED BMC machines Peter Maydell
2020-11-23 11:42 ` [PULL 06/24] MAINTAINERS: Cover system/arm/nuvoton.rst with Nuvoton NPCM7xx Peter Maydell
2020-11-23 11:42 ` [PULL 07/24] MAINTAINERS: Fix system/arm/orangepi.rst path Peter Maydell
2020-11-23 11:42 ` [PULL 08/24] MAINTAINERS: Cover system/arm/sbsa.rst with SBSA-REF machine Peter Maydell
2020-11-23 11:43 ` [PULL 09/24] MAINTAINERS: Cover system/arm/sx1.rst with OMAP machines Peter Maydell
2020-11-23 11:43 ` [PULL 10/24] docs/system: Deprecate raspi2/raspi3 machine aliases Peter Maydell
2020-11-23 11:43 ` [PULL 11/24] docs/system/arm: Document the various raspi boards Peter Maydell
2020-11-23 11:43 ` [PULL 12/24] docs/system/arm: Document OpenPOWER Witherspoon BMC model Front LEDs Peter Maydell
2020-11-23 11:43 ` [PULL 13/24] docs/system/arm: Document the Sharp Zaurus SL-6000 Peter Maydell
2020-11-23 11:43 ` Peter Maydell [this message]
2020-11-23 11:43 ` [PULL 15/24] linux-user/arm: Deliver SIGTRAP for UDF patterns used as breakpoints Peter Maydell
2020-11-23 11:43 ` [PULL 16/24] docs: Move virtio-net-failover.rst into the system manual Peter Maydell
2020-11-23 11:43 ` [PULL 17/24] docs: Move cpu-hotplug.rst " Peter Maydell
2020-11-23 11:43 ` [PULL 18/24] docs: Move virtio-pmem.rst " Peter Maydell
2020-11-23 11:43 ` [PULL 19/24] docs/system/virtio-pmem.rst: Fix minor style issues Peter Maydell
2020-11-23 11:43 ` [PULL 20/24] docs: Split out 'pc' machine model docs into their own file Peter Maydell
2020-11-23 11:43 ` [PULL 21/24] docs: Move microvm.rst into the system manual Peter Maydell
2020-11-23 11:43 ` [PULL 22/24] docs: Move pr-manager.rst " Peter Maydell
2020-11-23 11:43 ` [PULL 23/24] docs: Split qemu-pr-helper documentation into tools manual Peter Maydell
2020-11-23 11:43 ` [PULL 24/24] docs/system/pr-manager.rst: Fix minor docs nits Peter Maydell
2020-11-23 17:03 ` [PULL 00/24] target-arm queue Peter Maydell

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=20201123114315.13372-15-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@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).