From patchwork Fri Jan 15 13:08:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 363628 Delivered-To: patch@linaro.org Received: by 2002:a02:ccad:0:0:0:0:0 with SMTP id t13csp288995jap; Fri, 15 Jan 2021 05:22:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxd0149ruQvh8xnijj3bFCDjSLKKEC1YkZqyQv2fvmKVZj1DgVevJ6b5mVfVpuSAkLhSQIN X-Received: by 2002:a25:ef46:: with SMTP id w6mr18017094ybm.458.1610716922933; Fri, 15 Jan 2021 05:22:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610716922; cv=none; d=google.com; s=arc-20160816; b=aioUaLhKmOUIDiQxW3fKfHFDLG3yyC1NY87TgCObDXwcvpGI0ZTwNmDhRuCKGfyswr 1f7A5dhpyAdbdjomBebebwEmLn2fH/3aRp8gT9koVuJXE7pWfiVJ42YXo8TeIzVGi9RV I26ApSrZBaSJUdkY7HWlNYExWJtkiBZm3hxFuLgtRDn56gy1zvUV0i3qLVX9xyYfp2XH u3JfcoC/ensXwEzmt7bjld/uCR3nue59pXsXnPrgZldMx61AaemmyQIEmAJ5PDhF9rf5 NzAK31jFO3QRvgMREP0AJ2CdiLHwdV6UQYbOhVVWZd7AtB/f9HjO9b8se+lRRrFN5oNy LO4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=kdUcvH/D3i7eMpyjSu9D9spoJoxmIAl4kuXpl0wBNfY=; b=hJJe9gBlTy7LFiC7tJLtE/QvUnQZtoj1EngDmpE3gmTlwbVpfoLnkPzPixZkRjnuxq 0BP6H4VvFGtGAuj2qmGYgkbVsdpUq+fDAdgXFK6cirwVO47EFXOS+YnomqFkv/ZUjoC+ 4QqEDqHYXvz8Aywr7QWP+hPAThVOvY6nsN2eSb+ITk9MkLjDxtbTrPxsy9RHwrJrDZ5J y9cltAOQER8oLH3UXevijPeCwMzAiyFkHgB+5v/KPvltCqeX30T1ouD7sQSl8sHD5sjT sS3CLyUUx5AbDOfSG06Ucjb41XrIT5pAwaaId6eTNa1OP3GqgCb7XIiAXmvGnnDVZii7 pCLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VPWGkmg2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b1si8323367ybq.405.2021.01.15.05.22.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Jan 2021 05:22:02 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VPWGkmg2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0P3C-0006Hy-CJ for patch@linaro.org; Fri, 15 Jan 2021 08:22:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0OqZ-0006LL-U8 for qemu-devel@nongnu.org; Fri, 15 Jan 2021 08:09:01 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:36448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l0OqW-0006cI-5F for qemu-devel@nongnu.org; Fri, 15 Jan 2021 08:08:59 -0500 Received: by mail-wm1-x330.google.com with SMTP id v184so3339317wma.1 for ; Fri, 15 Jan 2021 05:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kdUcvH/D3i7eMpyjSu9D9spoJoxmIAl4kuXpl0wBNfY=; b=VPWGkmg2YK+cJ50FQezrUKzECGeNO71bRKNcnFyrEQn/uURgTqBCfSr5GJQAGy9uKA TUYODv+feWflpZqfCYXkQf7rbuQLSac4W4zLX/qwUAfLNV0rRh6KBkbSGNfg5DySe3RI ePv4h1C25t5ITOdVYcW9XbivoXr9wSXRVdPAukICsATWoRQsdJ8KxBUrbrhnfU9EEXAo mYVmsoqPvtiMSgYKeNZAHNphYm8XYZBMs67s2mY8AXJGA9hgyaqnlzK7fmuDpUEmPuGR MYgFeObcrDlSR2aXwBNHYjzW1jI+jjnoajqx6Ut8FFl9iL39cZprfmcb/U/RVkynvJmE Y7uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kdUcvH/D3i7eMpyjSu9D9spoJoxmIAl4kuXpl0wBNfY=; b=JPxoK1myJdBv/NxcRSX5y3BUwHE101eQDGGp8NPrjcSYVwo13DIK6ZSIC/D6KQOEbU pZdTTZlVKMArEKsUkADdMjeI857VmXXJ+0+BzA/6k5Bs4TsfvV9yy0jq7b0ufC1qeQvn cr+IiuLEOnrF4RsRuQQYo/ooTOOrJMvIykriAgBEnOkia+lr5O2sWxUQhL7L6FkVc7Tz Ci42X6O3Xzrmbm2gP7PSqhcfSzc7TGpduTRJh3zDyAPb5FA+phE2YBBiRBWVtpKxnt5U 6CJGi5nqHcDVHxbjSlW+D51g+l5h9rU7M4FFfK3rMajFwtLrcHEt+rI+F4PQfbr1mt7x L+fg== X-Gm-Message-State: AOAM531fSVDw1xWgZ2vFNrBQx/gFHCEARymg3mKSq0FIDWVE8GT7jjLp UZSFq3l15zOHfQ46M2qLcF4weQ== X-Received: by 2002:a1c:2c82:: with SMTP id s124mr8456613wms.81.1610716134533; Fri, 15 Jan 2021 05:08:54 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id m14sm14328242wrh.94.2021.01.15.05.08.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 05:08:49 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 4CB3F1FFAF; Fri, 15 Jan 2021 13:08:34 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 25/30] semihosting: Support SYS_HEAPINFO when env->boot_info is not set Date: Fri, 15 Jan 2021 13:08:23 +0000 Message-Id: <20210115130828.23968-26-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210115130828.23968-1-alex.bennee@linaro.org> References: <20210115130828.23968-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Keith Packard , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Keith Packard env->boot_info is only set in some ARM startup paths, so we cannot rely on it to support the SYS_HEAPINFO semihosting function. When not available, fallback to finding a RAM memory region containing the current stack and use the base of that. Signed-off-by: Keith Packard Signed-off-by: Alex Bennée Message-Id: <20210107170717.2098982-5-keithp@keithp.com> Message-Id: <20210108224256.2321-16-alex.bennee@linaro.org> -- 2.20.1 diff --git a/hw/semihosting/arm-compat-semi.c b/hw/semihosting/arm-compat-semi.c index ac1271545e..293791f721 100644 --- a/hw/semihosting/arm-compat-semi.c +++ b/hw/semihosting/arm-compat-semi.c @@ -137,6 +137,36 @@ typedef struct GuestFD { static GArray *guestfd_array; +#ifndef CONFIG_USER_ONLY +#include "exec/address-spaces.h" +/* + * Find the base of a RAM region containing the specified address + */ +static inline hwaddr +common_semi_find_region_base(hwaddr addr) +{ + MemoryRegion *subregion; + + /* + * Find the chunk of R/W memory containing the address. This is + * used for the SYS_HEAPINFO semihosting call, which should + * probably be using information from the loaded application. + */ + QTAILQ_FOREACH(subregion, &get_system_memory()->subregions, + subregions_link) { + if (subregion->ram && !subregion->readonly) { + Int128 top128 = int128_add(int128_make64(subregion->addr), + subregion->size); + Int128 addr128 = int128_make64(addr); + if (subregion->addr <= addr && int128_lt(addr128, top128)) { + return subregion->addr; + } + } + } + return 0; +} +#endif + #ifdef TARGET_ARM static inline target_ulong common_semi_arg(CPUState *cs, int argno) @@ -175,7 +205,18 @@ common_semi_rambase(CPUState *cs) { CPUArchState *env = cs->env_ptr; const struct arm_boot_info *info = env->boot_info; - return info->loader_start; + target_ulong sp; + + if (info) { + return info->loader_start; + } + + if (is_a64(env)) { + sp = env->xregs[31]; + } else { + sp = env->regs[13]; + } + return common_semi_find_region_base(sp); } #endif