From patchwork Mon Aug 23 19:55:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 501558 Delivered-To: patch@linaro.org Received: by 2002:a02:6f15:0:0:0:0:0 with SMTP id x21csp2495124jab; Mon, 23 Aug 2021 13:03:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy5KW+TLHWomY29P505gXpPKViOm904vx6R5J5qFmJQdDCkp3RfbS6F3pqLinRjtgyLOOH X-Received: by 2002:a17:906:7b53:: with SMTP id n19mr37152786ejo.14.1629748989424; Mon, 23 Aug 2021 13:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629748989; cv=none; d=google.com; s=arc-20160816; b=pg3O6xZjGF0De4k4bVgjtGG5fB2yCvXFt8rhwl0aYHSsfN0Dt3D9VUPNxtdjal8AuJ k8zmCwzDWQXxT/hLWKRHLUK687hLB/uIwTo4XAg+Mg9Nyg5VREpYrZZgoTBltYBvwqMA t/fk8qKzNbvbDPaPtkCZPX20amD+W6IB5Jr0cVpHoFoSypHbut4VT4Lf6zeniMbyZVCg d/H+CQ64I7wB6n0EDTpMnOrFxO1aV5+6bgFHwcABR6I+JL634f9/AWskGyzudV1mfOlP pKMdsgYN2Tcfehb5DupzLTzRb+dlWiZZUElvIsFQBC0tMldpF35aqmUORbBRlJK7l0un snDA== 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=EhRoz6fDTgou8i0y2EDLKe/oSBMrCIVBe4MhM6xpgpk=; b=GAlEq00+NsQy8WzdamOqPo4nMeGAD1mBZi/ts2/jZis/8sbvxNeOv7m9UmDZfe7ttx flz0YQF/HvN9If9HM5sh0WP9GkUqDUwRXnLAe2IZS5o3d8rk91dJAAv9QW+XsHtiq5XF QX6i1fZIExJdDZ1J2D4V2qKptbbWrIcTgcB/alj4RkXcw6KKQBLuJMD/DZntIfkGuSHX YV+3gG7gE2I7syohIiptuNVoHkhY6JwEVreUUW6lVPFDBsFILpXxK+ylMIB8U8NCwavO 0Z1Gq5HGOJUvtk8of13vse1VjL08U4zAv8JknqvUnlik0LoAkO+6rvQTd6grJgWYt6Cu qYmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wvHOffyq; 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 j5si11582609ejm.413.2021.08.23.13.03.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Aug 2021 13:03:09 -0700 (PDT) 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=wvHOffyq; 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]:37514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIGA0-0004Ue-GJ for patch@linaro.org; Mon, 23 Aug 2021 16:03:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIG2z-0006WV-KV for qemu-devel@nongnu.org; Mon, 23 Aug 2021 15:55:53 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:35454) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mIG2p-0003Ae-Sp for qemu-devel@nongnu.org; Mon, 23 Aug 2021 15:55:53 -0400 Received: by mail-pj1-x102e.google.com with SMTP id mw10-20020a17090b4d0a00b0017b59213831so252133pjb.0 for ; Mon, 23 Aug 2021 12:55:43 -0700 (PDT) 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=EhRoz6fDTgou8i0y2EDLKe/oSBMrCIVBe4MhM6xpgpk=; b=wvHOffyqOEJJ3rSbqJJv1OJXc+GjEJylJjy7pWDGrVGyn8m1T3JOkytWlFBh8yfSL7 mH9XFyT/WcQXrtdk5c1BlbkvJ+He5EUZGv5f+oz7vRvFbM4pLXZM4PfrVJSe70nJ4Iil JKh/O7xniWA+lze7JTa1hoE3kcuxmfO418RZDqak1/UNCI6XoUkEQDW0r1ZYDKlDiSmh vShaMRUV+vDPk/5eDl6Yl4Gc2RCKEOZFHEaqeXYR+TY6J3UqwEkb/sEvQcduVAg+Fw76 G26O2PUPJ+90Df65wc9Cc8PKnvsnh+0lcqenYpo/i86ikwOoieXPMzKOLCvwXwI8n6n+ Xazw== 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=EhRoz6fDTgou8i0y2EDLKe/oSBMrCIVBe4MhM6xpgpk=; b=B3H6qvAwbGcE3JjSXCIGxK0qcmPQuGUaV0iu04kEHmJ43CCUSMS7SviJobMFCno1SK 2XEcSIAkbjzgaTUZ9vPR/nCwel9CzOCKh72P9fILpu6fpA2m+n4Tp/wnHr+cr0Cmtx8r CQckWqE2FcOw8IvS9n5qbizguqwnkIjy1zMEr9/q4QiyvPMvSrbE2jnqAlr7M1FGx9Pz qM139NT+GLVXd1/QtRrr18Hqtmp1ETitnDyb6CWp6t7qztDsCMYmqIjTGRd7idnOV2PN 47AExtYerGvNhD/AHOL5Fmyjr6GaZIiH5f0QIBUZ79FzwdaGk+Lm9NprDMhl7xzokdAx /cqA== X-Gm-Message-State: AOAM532jl+AOOkBc0akwqvWTnw44UE7YNobAhrKZ18G/9iO+HpKrRaZB OdPkrVmDH+zX1S+gxZQ5xihhRSi4YAVZdQ== X-Received: by 2002:a17:90a:5b0f:: with SMTP id o15mr228963pji.97.1629748542532; Mon, 23 Aug 2021 12:55:42 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id v15sm16685078pff.105.2021.08.23.12.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 12:55:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 16/24] target/riscv: Fix rmw_sip, rmw_vsip, rmw_hsip vs write-only operation Date: Mon, 23 Aug 2021 12:55:21 -0700 Message-Id: <20210823195529.560295-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210823195529.560295-1-richard.henderson@linaro.org> References: <20210823195529.560295-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) 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: alistair.francis@wdc.com, bin.meng@windriver.com, qemu-riscv@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We distinguish write-only by passing ret_value as NULL. Signed-off-by: Richard Henderson --- target/riscv/csr.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) -- 2.25.1 Reviewed-by: Bin Meng Reviewed-by: Alistair Francis diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 9a4ed18ac5..d900f96dc1 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -937,9 +937,12 @@ static RISCVException rmw_vsip(CPURISCVState *env, int csrno, /* Shift the S bits to their VS bit location in mip */ int ret = rmw_mip(env, 0, ret_value, new_value << 1, (write_mask << 1) & vsip_writable_mask & env->hideleg); - *ret_value &= VS_MODE_INTERRUPTS; - /* Shift the VS bits to their S bit location in vsip */ - *ret_value >>= 1; + + if (ret_value) { + *ret_value &= VS_MODE_INTERRUPTS; + /* Shift the VS bits to their S bit location in vsip */ + *ret_value >>= 1; + } return ret; } @@ -956,7 +959,9 @@ static RISCVException rmw_sip(CPURISCVState *env, int csrno, write_mask & env->mideleg & sip_writable_mask); } - *ret_value &= env->mideleg; + if (ret_value) { + *ret_value &= env->mideleg; + } return ret; } @@ -1072,8 +1077,9 @@ static RISCVException rmw_hvip(CPURISCVState *env, int csrno, int ret = rmw_mip(env, 0, ret_value, new_value, write_mask & hvip_writable_mask); - *ret_value &= hvip_writable_mask; - + if (ret_value) { + *ret_value &= hvip_writable_mask; + } return ret; } @@ -1084,8 +1090,9 @@ static RISCVException rmw_hip(CPURISCVState *env, int csrno, int ret = rmw_mip(env, 0, ret_value, new_value, write_mask & hip_writable_mask); - *ret_value &= hip_writable_mask; - + if (ret_value) { + *ret_value &= hip_writable_mask; + } return ret; }