From nobody Tue Feb 10 13:18:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1610717082; cv=none; d=zohomail.com; s=zohoarc; b=CbZJ1hJ142utCNtB1jFJNqRqBb/KWzLyQQA3F8yVVBjl9LzcLLxnAV09BGR0anU1sp59DuavrObN8+cKr/uwEpuo6qOWC69G5a/HCs3iNpymg8e0g8FKvz7qUrzocp+G/GBlIrNhU1nW48hhgdRAiRIWztEZH2fRugV55KZtNlU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610717082; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kdUcvH/D3i7eMpyjSu9D9spoJoxmIAl4kuXpl0wBNfY=; b=JnCGXbijFxNAWcbLxxgisRQH5CwG4gBoCgc0UY5LljSzhuQWOaVRdpW+owt6jw+FmGZ/QEh9EV9FRDkZ3vIICbCSYxDRTHlNWrWcaajhP2ABn/H2ax5sAjnlLyGe0sG/zdYEWfrJFrz/799IHCKPdg6mKbXZWTxA0kfk49o9Nv0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610717082474418.76110872745153; Fri, 15 Jan 2021 05:24:42 -0800 (PST) Received: from localhost ([::1]:45568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0P5l-00089p-5B for importer@patchew.org; Fri, 15 Jan 2021 08:24:41 -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) 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) 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-Google-Smtp-Source: ABdhPJz4Hd+8yGzgd2WjjBFazDaQK/OSWI9St7RlXXvIqRiypY25ZKIxvwHJ61ZciPZGOebGSDi3uw== X-Received: by 2002:a1c:2c82:: with SMTP id s124mr8456613wms.81.1610716134533; Fri, 15 Jan 2021 05:08:54 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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=20Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e Message-Id: <20210107170717.2098982-5-keithp@keithp.com> Message-Id: <20210108224256.2321-16-alex.bennee@linaro.org> diff --git a/hw/semihosting/arm-compat-semi.c b/hw/semihosting/arm-compat-s= emi.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 { =20 static GArray *guestfd_array; =20 +#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 =3D int128_add(int128_make64(subregion->addr), + subregion->size); + Int128 addr128 =3D int128_make64(addr); + if (subregion->addr <=3D 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 =3D cs->env_ptr; const struct arm_boot_info *info =3D env->boot_info; - return info->loader_start; + target_ulong sp; + + if (info) { + return info->loader_start; + } + + if (is_a64(env)) { + sp =3D env->xregs[31]; + } else { + sp =3D env->regs[13]; + } + return common_semi_find_region_base(sp); } #endif =20 --=20 2.20.1