From patchwork Wed Mar 8 13:28:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 660439 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp329162wrb; Wed, 8 Mar 2023 05:33:07 -0800 (PST) X-Google-Smtp-Source: AK7set/LClLGxpkimMKfSQEPHgEHkMJb8UGAutb+oGVUema8Rzt+ezg8/8vkjrD7yKAWV99VPPrJ X-Received: by 2002:ac8:5a46:0:b0:3bf:d9f3:debe with SMTP id o6-20020ac85a46000000b003bfd9f3debemr4757278qta.59.1678282387725; Wed, 08 Mar 2023 05:33:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678282387; cv=none; d=google.com; s=arc-20160816; b=cuUtNym7hVDNWwzPYHTRdG6CzYRvn1L/yihShQh+fwd7SznN4mfTdApdTCUhFcHUl0 Be0oN819qIzfFPyvJPUmKY8DrRjksY40tOKd8PqStM2Qn3w8zlz56Z8Ib3WWFkn2HCRs 26TgioJbFg3bE+IY2/hmUOAKhLAmvZoofhfZCdxIYFQoNFpnxOmXo3py8pKInQK8MNhq mrj8ED3PXUNk2aVNnCXYdROEG3PnDYBpprWgBKHE+GbVaIzq7hVBSeNhd72fyKkLRtYY C6gKhhGU7pB92Ubj2ujlgRbw2xdsvvFl/OP6cmtx1ibzABRm216Ke+5nQEx3zcXc3F+R eBKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:ui-outboundreport :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=UnGCq8YCsCj9GMBSfgLvkVJwtYKx+DeQUq5zh06tZGw=; b=AlCAToZS/YpQ6m84+BTfPZm1X9ZDfDhsIn25G2ih/5C73zo98scgzaOi487OBW8wzb YscE/Ti1fAxi/2sUIHFA7A8qGAxQWG4YFGRpyTv8p7pPyL9ElgGMbq3YpjqwzbOtnCqb 74+pkRpssf9BnxLW3euWW1GZLnNtwnnXExwd6pgLY3TQmw5HZRGbZ6buByzHt2pxOxKQ pdpiEXcja3Yp13QjWGcpEBsFnjiIV0KAgYo/+bMmYSATT4xQ/2gDr5v1mZzJw8AWIBBj BXkx39e7Sh01yo0uFRipbhF3S3TsW/grLf8VXx3FhiH5QfWCnLDC5czuTkYv1Ng972M7 ioqQ== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o3-20020a374103000000b00716641078e4si11154211qka.508.2023.03.08.05.33.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Mar 2023 05:33:07 -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; 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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZttO-0004Ii-Ij; Wed, 08 Mar 2023 08:31:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZtr5-0001ks-Dx for qemu-devel@nongnu.org; Wed, 08 Mar 2023 08:29:21 -0500 Received: from mout.kundenserver.de ([212.227.17.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZtr2-000683-OH for qemu-devel@nongnu.org; Wed, 08 Mar 2023 08:29:19 -0500 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MzyAy-1qWgyk2vbC-00x5iS; Wed, 08 Mar 2023 14:29:12 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier Subject: [PULL 21/28] linux-user/sparc: Handle getcc, setcc, getpsr traps Date: Wed, 8 Mar 2023 14:28:50 +0100 Message-Id: <20230308132857.161793-22-laurent@vivier.eu> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308132857.161793-1-laurent@vivier.eu> References: <20230308132857.161793-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:eHalJmY8rD8wOf1IC4sz+QHbX4m89J/lQVnkR+6/eBXHlq3zCKR sub+U5ODxaJBaVRAaOeYHKFzqdYqtjNyCAa/BWcxr2Gg7c3/URN4ewkKJh7cbtEhqrBNnrd vd0Kij7922yYycxxOisj/vH+RtNLb+eRQnmkt6qhOfEqV3hJwGzHV6Vfx4YAWxB3AiGuXN/ qjbEM4lczd1d26+PYOOGQ== UI-OutboundReport: notjunk:1;M01:P0:nwc34GiXmyw=;HBT6wV9vyfEdwANIOnFm7oCYbKz lirTj/z7xtqo+2gPWmnGziF2eMppa5bkKGp1hy4HBdhCGQDjsnOtc+LGCpE40T7AOJHAIApRp 9dzHhNtqsp7TNzEmHwXHZrcPz3UQ4EkAA5Wtl73eKPGXBD7mSbAhM5+d0DUd762VsRKOlh1HG c81+8w6+AxSWsX8sGr2LAenMSKX6Vk9ogwzv42a8CUqUtmggE1kbh38PErw8Jtiiy8Vk5g0xt 8qtX+6ad38JR3YdFF1lLbZAVOCzhrAVAZaWlOfBYVigZBP47+Pl4idvKQn2diUWxEpxO3TyTz WoDRZrCcRcSF2PGC49KDiuSAKgQTsAT0h6htcMNjodRqLbs2xy51KMt0sd+mSHCY59krqupR+ pFkf8k8WtbARW4A3oJQVsOoYzHzKVH9i5EK2Fj+dI8pjARBpX/OMhF32u2DKsqKT/0xsK2eoe iABAxLHcy+lkcpSfhNYlso2OVYsW0GFJe8pPUnA/nIIReMcGAj3/oAEAJ/iz5FCRvUjf2yYcx EiXxuPTnEDtf4a4KtwKEtrM+zClf6BKIVm4Qca38tgO3jtvN5BYWh0pZkzf5tYjfZRGwa8KKG 9m00X99fJ49pl6CZgchBxYmgFgiZl9tsCVFNwuIM4VOGZESToJZKOrsH3e7DsufFA2MfSFPW/ ANobOTGv+n0/pv6Zzv7Lg22XIvMtOOJtiH2U6FXQAw== Received-SPF: none client-ip=212.227.17.24; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson These are really only meaningful for sparc32, but they're still present for backward compatibility for sparc64. Signed-off-by: Richard Henderson Message-Id: <20230216054516.1267305-10-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/sparc/cpu_loop.c | 62 +++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c index e04c84286769..a3edb353f6fd 100644 --- a/linux-user/sparc/cpu_loop.c +++ b/linux-user/sparc/cpu_loop.c @@ -149,6 +149,51 @@ static void flush_windows(CPUSPARCState *env) #endif } +static void next_instruction(CPUSPARCState *env) +{ + env->pc = env->npc; + env->npc = env->npc + 4; +} + +static uint32_t do_getcc(CPUSPARCState *env) +{ +#ifdef TARGET_SPARC64 + return cpu_get_ccr(env) & 0xf; +#else + return extract32(cpu_get_psr(env), 20, 4); +#endif +} + +static void do_setcc(CPUSPARCState *env, uint32_t icc) +{ +#ifdef TARGET_SPARC64 + cpu_put_ccr(env, (cpu_get_ccr(env) & 0xf0) | (icc & 0xf)); +#else + cpu_put_psr(env, deposit32(cpu_get_psr(env), 20, 4, icc)); +#endif +} + +static uint32_t do_getpsr(CPUSPARCState *env) +{ +#ifdef TARGET_SPARC64 + const uint64_t TSTATE_CWP = 0x1f; + const uint64_t TSTATE_ICC = 0xfull << 32; + const uint64_t TSTATE_XCC = 0xfull << 36; + const uint32_t PSR_S = 0x00000080u; + const uint32_t PSR_V8PLUS = 0xff000000u; + uint64_t tstate = sparc64_tstate(env); + + /* See , tstate_to_psr. */ + return ((tstate & TSTATE_CWP) | + PSR_S | + ((tstate & TSTATE_ICC) >> 12) | + ((tstate & TSTATE_XCC) >> 20) | + PSR_V8PLUS); +#else + return (cpu_get_psr(env) & (PSR_ICC | PSR_CWP)) | PSR_S; +#endif +} + /* Avoid ifdefs below for the abi32 and abi64 paths. */ #ifdef TARGET_ABI32 #define TARGET_TT_SYSCALL (TT_TRAP + 0x10) /* t_linux */ @@ -218,9 +263,20 @@ void cpu_loop (CPUSPARCState *env) case TT_TRAP + 0x03: /* flush windows */ flush_windows(env); - /* next instruction */ - env->pc = env->npc; - env->npc = env->npc + 4; + next_instruction(env); + break; + + case TT_TRAP + 0x20: /* getcc */ + env->gregs[1] = do_getcc(env); + next_instruction(env); + break; + case TT_TRAP + 0x21: /* setcc */ + do_setcc(env, env->gregs[1]); + next_instruction(env); + break; + case TT_TRAP + 0x22: /* getpsr */ + env->gregs[1] = do_getpsr(env); + next_instruction(env); break; #ifdef TARGET_SPARC64