From nobody Mon Feb 9 17:27:24 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; 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=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1617290595; cv=none; d=zohomail.com; s=zohoarc; b=mhkg8v9A5LQ240hKGH2unkuUOeiFPkcGy5rKMnoAmDzfrVLZgv3RJ6n9WJ0jkgS7fzK0D6hY11KBiiRmtFarIig5+fxCs1BoK8yIhPYdd3siTXd06Tcx3kfPnLvtBujaSo2jZ+7f1DPVQjmUav3jgIohNSiEU/Bl/gW03MHfUw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617290595; h=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=WQLodL5MMDL7uI+H7/QAqm84avWCN7yWWuCgQLuQ+nk=; b=TmJkKkyy8iz+qtFU7Ud9ftHaRrRZ+SWIsVZ/fuhzH7I7oGkGNtocZh+2WcGmKw+tuvtUbZDRg+QjDLv1/MNaIXLbTjXu3/ddU5XODHp9RqRlriChORms8oS/JMtx8XGLNXa5r2ngpYZGe3L/pSNVzD4b+aJvORFIwD+DLxB1yHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; 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 1617290595395127.76082548763566; Thu, 1 Apr 2021 08:23:15 -0700 (PDT) Received: from localhost ([::1]:44890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRzAA-0002fe-AM for importer@patchew.org; Thu, 01 Apr 2021 11:23:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz6z-0006zx-4U; Thu, 01 Apr 2021 11:19:57 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:23965) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz6x-0004jK-1X; Thu, 01 Apr 2021 11:19:56 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Apr 2021 23:19:30 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2021 08:01:10 -0700 Received: from unknown (HELO alistair-risc6-laptop.wdc.com) ([10.225.167.75]) by uls-op-cesaip01.wdc.com with ESMTP; 01 Apr 2021 08:19:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617290394; x=1648826394; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dqwAJfuA1e/RYG4bU1etDZREYvBWEd7y8YmBWf0vHrM=; b=a9BG5EFtb5SeLSpz70l5xsV35nwm+7JGIqWOZTigMKyFsHFHTC3QwMZL xrygj9FG1MrKRU81CQeDEY9/w71AJ5Uml7cPz+VI/IG/Cm7LOMIL+3Y2U LIFqypYMHo+ETms/TbVMq9WYpN6V71+i7fgbOzDhmQk9T/yBxwn1PZ1Sk HJvABIQxShKFKny+1HyrrZP9UKd+765NLD/3E4YSTH3pCbuaAxaqpWZ5L mBt4N5yqtyv/QEsvbbPXyIE5bEMKzmx43BjjLHqWJXmjXp7ktpzJO6rTG 9MtjJv787JGROlSdj85P1JwrWl1QybiTYUJ/cIezdx+9qqYTmGkl0B70o Q==; IronPort-SDR: 0VdhvplYewhVYIVskOg80y0Ze61/F3DDcphblMoXgzCMG0ALh4o7xJWhZ5W/UqUOUH+i+oL09C 7W09GYOnaBibOTh+SruvsSDeRi3zCDTbd7Tz/HlZpxuHvjxCke/1YjzAIXTKD7jhot2BLwzQO4 ZIJGs2T8CJzM1Hvl1lxU1t8etQ9hKw+so8Ll7fWSgL5HrhaC1owo6cl+r6XIIeZdEzXlVcPITG l3woWzFMvvp8MZuch83KGB1izLgLSQur45a1ZpvGR2HXLrP59Utnavcrt+OPIbVA5bgE6k4NZl 9Jw= X-IronPort-AV: E=Sophos;i="5.81,296,1610380800"; d="scan'208";a="163455429" IronPort-SDR: Y8iy4SEk2pBx2k24kfovtrDt80z/RtTkDtjur8lW4DxU+OjYUgxTYe8ZQYrJTKlFis+wbABt1K d0mUaWfW9mZ7gCjb1D8X1/ajLbQJeI6NON98BTojrJu5QXUNJw9CH9fvVCUUbfZKSTOGILbKzC pFXkVlRzsAtNPtXxvASHYJepzkPvIQ+cZOFZ0gy7Wmkjn8gmvyaiZg3ynJuKshvZ0j9kU9ate3 8sujqiqXSKGg+FDCksCCf7wCJScGVyVFCpk2GgMFrUTRY78UrdI9LlEqPTGKVZfLrtzGD6G/E8 eghBGKstEsPezysg+nwRXgEZ IronPort-SDR: VRFgSuaY0KF1+9VoJboOvT3CstsMtNDemuCkw4KvUm74Zp8fFkmhMaAvb/GA3SzHH7S9hgW3KU Db8y3zIJkSc8xd+QmWItHBz9Z3oGMAImJnOXBBpIx5c2Nhk5bdorT10mMVbingUBOdfsQhwdRB CdnO0jV/28nPlizF8yA6qO72dfzMEHBF9gS0vB0NBs0K+4kR6/22bhpx1aNmPO46CW6wthw5jG jYRH1JxxjlqCcdSTaGsX2JlZ7xo3z67BTlT3MDKksTDan0iekXfvBzwSKcgcyAOluZ97oMGuR+ XFU= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 2/5] target/riscv: Use the RISCVException enum for CSR predicates Date: Thu, 1 Apr 2021 11:17:39 -0400 Message-Id: <187261fa671c3a77cf5aa482adb2a558c02a7cad.1617290165.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: References: MIME-Version: 1.0 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=216.71.154.42; envelope-from=prvs=718ae7c5e=alistair.francis@wdc.com; helo=esa4.hgst.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_PASS=-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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Richard Henderson --- target/riscv/cpu.h | 3 +- target/riscv/csr.c | 80 +++++++++++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0a33d387ba..1291ddc381 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -473,7 +473,8 @@ static inline target_ulong riscv_csr_read(CPURISCVState= *env, int csrno) return val; } =20 -typedef int (*riscv_csr_predicate_fn)(CPURISCVState *env, int csrno); +typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env, + int csrno); typedef int (*riscv_csr_read_fn)(CPURISCVState *env, int csrno, target_ulong *ret_value); typedef int (*riscv_csr_write_fn)(CPURISCVState *env, int csrno, diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d2585395bf..5dc2aa9845 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -35,29 +35,29 @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations = *ops) } =20 /* Predicates */ -static int fs(CPURISCVState *env, int csrno) +static RISCVException fs(CPURISCVState *env, int csrno) { #if !defined(CONFIG_USER_ONLY) /* loose check condition for fcsr in vector extension */ if ((csrno =3D=3D CSR_FCSR) && (env->misa & RVV)) { - return 0; + return RISCV_EXCP_NONE; } if (!env->debugger && !riscv_cpu_fp_enabled(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } #endif - return 0; + return RISCV_EXCP_NONE; } =20 -static int vs(CPURISCVState *env, int csrno) +static RISCVException vs(CPURISCVState *env, int csrno) { if (env->misa & RVV) { - return 0; + return RISCV_EXCP_NONE; } - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 -static int ctr(CPURISCVState *env, int csrno) +static RISCVException ctr(CPURISCVState *env, int csrno) { #if !defined(CONFIG_USER_ONLY) CPUState *cs =3D env_cpu(env); @@ -65,7 +65,7 @@ static int ctr(CPURISCVState *env, int csrno) =20 if (!cpu->cfg.ext_counters) { /* The Counters extensions is not enabled */ - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 if (riscv_cpu_virt_enabled(env)) { @@ -73,25 +73,25 @@ static int ctr(CPURISCVState *env, int csrno) case CSR_CYCLE: if (!get_field(env->hcounteren, HCOUNTEREN_CY) && get_field(env->mcounteren, HCOUNTEREN_CY)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_TIME: if (!get_field(env->hcounteren, HCOUNTEREN_TM) && get_field(env->mcounteren, HCOUNTEREN_TM)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_INSTRET: if (!get_field(env->hcounteren, HCOUNTEREN_IR) && get_field(env->mcounteren, HCOUNTEREN_IR)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_HPMCOUNTER3...CSR_HPMCOUNTER31: if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3)= ) && get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3))= ) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; } @@ -100,93 +100,101 @@ static int ctr(CPURISCVState *env, int csrno) case CSR_CYCLEH: if (!get_field(env->hcounteren, HCOUNTEREN_CY) && get_field(env->mcounteren, HCOUNTEREN_CY)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_TIMEH: if (!get_field(env->hcounteren, HCOUNTEREN_TM) && get_field(env->mcounteren, HCOUNTEREN_TM)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_INSTRETH: if (!get_field(env->hcounteren, HCOUNTEREN_IR) && get_field(env->mcounteren, HCOUNTEREN_IR)) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; case CSR_HPMCOUNTER3H...CSR_HPMCOUNTER31H: if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNT= ER3H)) && get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTE= R3H))) { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; } } } #endif - return 0; + return RISCV_EXCP_NONE; } =20 -static int ctr32(CPURISCVState *env, int csrno) +static RISCVException ctr32(CPURISCVState *env, int csrno) { if (!riscv_cpu_is_32bit(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 return ctr(env, csrno); } =20 #if !defined(CONFIG_USER_ONLY) -static int any(CPURISCVState *env, int csrno) +static RISCVException any(CPURISCVState *env, int csrno) { - return 0; + return RISCV_EXCP_NONE; } =20 -static int any32(CPURISCVState *env, int csrno) +static RISCVException any32(CPURISCVState *env, int csrno) { if (!riscv_cpu_is_32bit(env)) { - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 return any(env, csrno); =20 } =20 -static int smode(CPURISCVState *env, int csrno) +static RISCVException smode(CPURISCVState *env, int csrno) { - return -!riscv_has_ext(env, RVS); + if (riscv_has_ext(env, RVS)) { + return RISCV_EXCP_NONE; + } + + return RISCV_EXCP_ILLEGAL_INST; } =20 -static int hmode(CPURISCVState *env, int csrno) +static RISCVException hmode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVS) && riscv_has_ext(env, RVH)) { /* Hypervisor extension is supported */ if ((env->priv =3D=3D PRV_S && !riscv_cpu_virt_enabled(env)) || env->priv =3D=3D PRV_M) { - return 0; + return RISCV_EXCP_NONE; } else { - return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } } =20 - return -RISCV_EXCP_ILLEGAL_INST; + return RISCV_EXCP_ILLEGAL_INST; } =20 -static int hmode32(CPURISCVState *env, int csrno) +static RISCVException hmode32(CPURISCVState *env, int csrno) { if (!riscv_cpu_is_32bit(env)) { - return 0; + return RISCV_EXCP_NONE; } =20 return hmode(env, csrno); =20 } =20 -static int pmp(CPURISCVState *env, int csrno) +static RISCVException pmp(CPURISCVState *env, int csrno) { - return -!riscv_feature(env, RISCV_FEATURE_PMP); + if (riscv_feature(env, RISCV_FEATURE_PMP)) { + return RISCV_EXCP_NONE; + } + + return RISCV_EXCP_ILLEGAL_INST; } #endif =20 @@ -1313,8 +1321,8 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target= _ulong *ret_value, return -RISCV_EXCP_ILLEGAL_INST; } ret =3D csr_ops[csrno].predicate(env, csrno); - if (ret < 0) { - return ret; + if (ret !=3D RISCV_EXCP_NONE) { + return -ret; } =20 /* execute combined read/write operation if it exists */ --=20 2.31.0