From patchwork Fri Mar 10 22:09:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 661662 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:1b90:b0:222:2e2e:b2c3 with SMTP id e16csp15632lty; Fri, 10 Mar 2023 14:13:38 -0800 (PST) X-Google-Smtp-Source: AK7set8pVMAujTfOkC8oFkpCGSWa9547WdMAdY6Ei2KjlNy+2M+J+5l4sA8BSo4d2vLsA7CG0qYs X-Received: by 2002:a05:622a:1052:b0:3bf:c675:3b65 with SMTP id f18-20020a05622a105200b003bfc6753b65mr12249758qte.44.1678486418582; Fri, 10 Mar 2023 14:13:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678486418; cv=none; d=google.com; s=arc-20160816; b=NNlFW4rd+Jjz04qi9ilhd8/nV3ezpDYVQ2Tro1N6brDG5c9v6A+K4aSVm1tKTAVw4A 3wOkBlTrA8Q4mIOvj33LFwBRP37iFQzOZymvUaIVuatcgDakQ0iEXQ3U0rnb3GuTBqvQ u4qXOANFej8AOcU6UPoV0/Ob0BnCXRSK4dh+yIUv9BmxLugyF41z5aprGzSYROfKtySq ouLVYmSNu56fnNMdwf0DiApiMtuQkh0h715CH2qziNHAxFjn98WIG5kW0ZNAXHukTGeX ixhw0PvOWqCPmBPHqh8bAevUqT02G1KZSXF6cS3g4Fpso/jI45Cp+ePP6cCuH4GYQtsz fReA== 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=Qsbf2GEazYmgsexcLJx6OWoNuGdZN6X38YTEFOu0cQQES1412Wgz8DiJd0v2yB0Snz oDwMxgX3egGP3uVmR4iBw/xK4fkoMI+WZfPeEzxUhKV/e31cQmtFct3C6f+9bOfwtQji Jp5U58HbIDZhsqVBDM+rUor8HfqRevmorvw4+vVI1gmG/gEujo9NyxCHl36rCioOf92+ PB8NaN6bfx3D9RvyFSBuAFc8VMSMtlipDWm5H6a6lbO9+lKb7YnIfhvSqWio5McuUThX pGdxccjbdRX/AcurUFfx8RQ3eaTxlZDU5L37pGwvttUtg3zwbK8C4c7jchERLGB08T4g OSwQ== 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 t2-20020a37aa02000000b00743995aef85si314894qke.230.2023.03.10.14.13.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Mar 2023 14:13:38 -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 1pakvr-0008I9-62; Fri, 10 Mar 2023 17:09:47 -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 1pakvn-0008FR-QF for qemu-devel@nongnu.org; Fri, 10 Mar 2023 17:09:43 -0500 Received: from mout.kundenserver.de ([212.227.126.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pakvl-00033M-Ja for qemu-devel@nongnu.org; Fri, 10 Mar 2023 17:09:43 -0500 Received: from quad ([82.64.211.94]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N3KkM-1qZhEf117q-010L9g; Fri, 10 Mar 2023 23:09:39 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Laurent Vivier , Richard Henderson Subject: [PULL 21/28] linux-user/sparc: Handle getcc, setcc, getpsr traps Date: Fri, 10 Mar 2023 23:09:20 +0100 Message-Id: <20230310220927.326606-22-laurent@vivier.eu> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310220927.326606-1-laurent@vivier.eu> References: <20230310220927.326606-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:VHzsuxxPPKWyfOtCIGXTKlpnoif4oOTx6r8dnvKBJsoUhW/Xib1 iUBCnfxLEAB5zq2fxl8UrwrwRrHTsHO/eboCQ0wg/X5/MeHKYRPjqcDVfuqmGWFpw/95Hpa jVEFKrsGWnTh1KRRE2xItM2STRJb6pfzwBao/7pw8Selb7Twc3BUGKLk1MqaqKif3sdg3Zz qBbHwPoTUQ7oEgbECz8lw== UI-OutboundReport: notjunk:1;M01:P0:iP4dggLz/Ho=;RqsK83/RCo/DQMua3FTulhXvx0E IBDNR4R3l9x/iVB9CB5guzZzBjspHrNWvj0QgeimnHUekrpJDBGS15lbDrZ61PCobGP6qrXTN bDoM/lbVhzEho9DNgnZGc4bAZe1aqFQ1z/u/fxPEyL9gwOBHxNGJC+md6wdwoaQf4A+KuIaKU xzyqsl4Lc4JuEOOo+o4mxdvwgBpMkbVSmkLMfYA1LZxbHof4e/seUEEC09Hb0JXoaaO9CULfO bM+OPHsQBe6XfmH68plLb/55kzPAjRLDEeEBVZuKQip5U4/Kj7OTobazLtz6r2Nmx7mwx1BE5 Y0MrJQUI59OnRbekWerdPnW5SMkz3PlWRl3bzb64fU/W9fxzOBYq7Vp5XpeVaI2h583lxTSbl cqfH5mv0SkiYAS2LsZG2nzsL1qyShCHTYsP13UNXtOJR1nrXjcFCOfcNPRIaeo9UEdAWSFYp2 /4eRw2NnamAkkouV8PX+Zta7OSqENXI/VH4ZDBhmrD1i+hLeDZ//55UnEKTY1QWbjbxgfiVjk ee0tPBCjt5x35b8Ca2DsYJIxdOPkEznHH4XQu0MJXfipPlJ4C6PyGT7EdTGm0iCNbSw/t60UR qdwQuytc7iUuumNnFCqX6TZuoxVq7IqSm/gATRQ30YXMpmyoNYd+IfrQM8o/HwSoeEW0A0NC5 iLSBvUvuez1lCWaR9RsGaGWoflWG53Uj6NNOw6fjzA== Received-SPF: none client-ip=212.227.126.131; 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