From nobody Mon Feb 9 18:46:13 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=1615544830; cv=none; d=zohomail.com; s=zohoarc; b=Ru0YoQD42HYJjEN3nQC4uqQsrsydSg2T6F3FTQNy1+LLY0UEVip8R0Kp4xEMya6hPhmabL1/LLTnpexfGAPq24jE62n5ZFOzDfZGqjG0IerXiQcLOGyWTFwn0XDq8IOtUu6Y/CU9GwL7cQvVeZEiyUcQekl0DHFp8imN5iSTTQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615544830; 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=fUuSdxHLrrklPAPPgMtY5hAbAYZJd9t8CTN4SQZzksI=; b=amuqaGkHC8pjuCAsTB4VskPrnEWCfs09mCadnVAC1C2XpF465qMKzMm3spAhKSwSY374Qex/Vay31stOKWvEbzTCK4PI7D8gmMeB38DaPVrzUR6yFRvZrywgOwLHkChQfYYNmEXmuKQYgYx9bXPeuSLyNzf/+T5D17xyZTIrQ/8= 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 1615544829971875.6626696253504; Fri, 12 Mar 2021 02:27:09 -0800 (PST) Received: from localhost ([::1]:45668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lKf0e-0001mj-Jm for importer@patchew.org; Fri, 12 Mar 2021 05:27:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKeuU-00007S-4c for qemu-devel@nongnu.org; Fri, 12 Mar 2021 05:20:46 -0500 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]:40724) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lKeuK-0005FV-6d for qemu-devel@nongnu.org; Fri, 12 Mar 2021 05:20:45 -0500 Received: by mail-ej1-x62f.google.com with SMTP id ci14so52189283ejc.7 for ; Fri, 12 Mar 2021 02:20:35 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t15sm2730249edw.84.2021.03.12.02.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 02:20:30 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D5C3E1FF8C; Fri, 12 Mar 2021 10:20:29 +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=fUuSdxHLrrklPAPPgMtY5hAbAYZJd9t8CTN4SQZzksI=; b=IGY723lYV6BJ5ogec7fCbCfRC/Px7tE14Z3MOCI27I1eD/kmk8qrOGqEyam11P8Izf +7tbPBPls08zrzbu0E0qMDsXuuaNdoNkoCRmSQewh1ORX0v+iHnzHrXR3ci7Mis893tF 0JK3ahHZlVg+2+9PsA03g7Spnj3BJF1J5fXV5qszN7aEaWEUu9+pvmP/OsOL6L5p81Rk DoHYHrMypPAwInVuEs17+rTPly53YyDVjATIsUzuxOJzvWxH2CpIzeSuED4ML46trRUQ 5N+V+QR0pUCaxsADlwK8Eqc6rY/7ibQMrdNQUetGYYljiVy8FkdTDqfA1/Izsz/lr8xC VpqA== 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=fUuSdxHLrrklPAPPgMtY5hAbAYZJd9t8CTN4SQZzksI=; b=QtVDPI9bLQADAKx6OCSce8kDHVrAF0Mni6jzB566q6siQz9oCGu0zrC5C5SYhsHaDJ C10Th4j4oBSuPslge0laBihc/iiu8zFQRxH6kBFS67ujTpQ711VPFCAlq6y32y5Z4sEm mDZUTqYSLYI2bcb4OWfRWxJvF4COTGW0bSDAf0x4zoOPIKvDTp1IMNY2MzM65QFjBTO8 +2Lu/Y/vJxGJ38ml9j4IY2k+gFBpy0m2QP/X7z84GEzO8p9XmL/jCFFWOqc1WukfAAqb PyVNXQAtMoa2n8TrY/r1Mgi83KzeBh1oH9RGt4596WvZqEIUpSr4SJRYjWXO33Mkj+PZ 9Baw== X-Gm-Message-State: AOAM530zBX3p4Wp2ulA4F4h68T+eSd+aq3gF4ge1z0IA67Ye/vhTHkk7 0kDCAy53HhXwvqr6BgLzviwY7A== X-Google-Smtp-Source: ABdhPJyEci/JMY0YkWdM/vJVOy8PUeDew2CmH9VFdGIaN+YV4Y2YGYW1L7YnM2J1Vz9xPHLOULNmnA== X-Received: by 2002:a17:906:5d12:: with SMTP id g18mr7579546ejt.246.1615544434468; Fri, 12 Mar 2021 02:20:34 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 2/5] semihosting/arm-compat-semi: unify GET/SET_ARG helpers Date: Fri, 12 Mar 2021 10:20:26 +0000 Message-Id: <20210312102029.17017-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210312102029.17017-1-alex.bennee@linaro.org> References: <20210312102029.17017-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::62f; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62f.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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , keithp@keithp.com, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From the semihosting point of view what we want to know is the current mode of the processor. Unify this into a single helper and allow us to use the same GET/SET_ARG helpers for the rest of the code. Having the helper will also be useful later. Note: we aren't currently testing riscv32 due to missing toolchain for check-tcg tests. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Peter Maydell Reviewed-by: Keith Packard --- v3 - consistent #ifdeffery --- semihosting/arm-compat-semi.c | 56 ++++++++++++----------------------- 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 94950b6c56..0f0e129a7c 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -767,15 +767,28 @@ static const GuestFDFunctions guestfd_fns[] =3D { }, }; =20 -/* Read the input value from the argument block; fail the semihosting - * call if the memory read fails. +/* + * Read the input value from the argument block; fail the semihosting + * call if the memory read fails. Eventually we could use a generic + * CPUState helper function here. */ -#ifdef TARGET_ARM +static inline bool is_64bit_semihosting(CPUArchState *env) +{ +#if defined(TARGET_ARM) + return is_a64(env); +#elif defined(TARGET_RISCV) + return !riscv_cpu_is_32bit(env); +#else +#error un-handled architecture +#endif +} + + #define GET_ARG(n) do { \ - if (is_a64(env)) { \ + if (is_64bit_semihosting(env)) { \ if (get_user_u64(arg ## n, args + (n) * 8)) { \ errno =3D EFAULT; \ - return set_swi_errno(cs, -1); \ + return set_swi_errno(cs, -1); \ } \ } else { \ if (get_user_u32(arg ## n, args + (n) * 4)) { \ @@ -786,41 +799,10 @@ static const GuestFDFunctions guestfd_fns[] =3D { } while (0) =20 #define SET_ARG(n, val) \ - (is_a64(env) ? \ + (is_64bit_semihosting(env) ? \ put_user_u64(val, args + (n) * 8) : \ put_user_u32(val, args + (n) * 4)) -#endif =20 -#ifdef TARGET_RISCV - -/* - * get_user_ual is defined as get_user_u32 in softmmu-semi.h, - * we need a macro that fetches a target_ulong - */ -#define get_user_utl(arg, p) \ - ((sizeof(target_ulong) =3D=3D 8) ? \ - get_user_u64(arg, p) : \ - get_user_u32(arg, p)) - -/* - * put_user_ual is defined as put_user_u32 in softmmu-semi.h, - * we need a macro that stores a target_ulong - */ -#define put_user_utl(arg, p) \ - ((sizeof(target_ulong) =3D=3D 8) ? \ - put_user_u64(arg, p) : \ - put_user_u32(arg, p)) - -#define GET_ARG(n) do { \ - if (get_user_utl(arg ## n, args + (n) * sizeof(target_ulong))) { \ - errno =3D EFAULT; \ - return set_swi_errno(cs, -1); \ - } \ - } while (0) - -#define SET_ARG(n, val) \ - put_user_utl(val, args + (n) * sizeof(target_ulong)) -#endif =20 /* * Do a semihosting call. --=20 2.20.1