From patchwork Fri Apr 28 16:52:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 1775071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=TKBy0uYQ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q7JZv26NXz23v6 for ; Sat, 29 Apr 2023 02:53:26 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psRL1-0004Pi-N2; Fri, 28 Apr 2023 12:52:51 -0400 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 1psRKz-0004Nr-Oq for qemu-devel@nongnu.org; Fri, 28 Apr 2023 12:52:49 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1psRKs-0005tF-3f for qemu-devel@nongnu.org; Fri, 28 Apr 2023 12:52:49 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-38de3338abeso133717b6e.1 for ; Fri, 28 Apr 2023 09:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682700759; x=1685292759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FJg9Z757wkoktYD9WwpmRyspyW4Py5K0/MXLwUgCBlw=; b=TKBy0uYQj0FW5tqHBPhs0Tj8KeGxwDHHD6P0S5x3c6HyId32CM+qaLOaRWjl4MEc+M nzEJH3SdJw/PXHSINgfSm0rXaJiNUzKhm7QJ9DITLwsRkoZZc1110dZ0oIMyV95ABwX/ tflBSFQGPi1+lUcnpkmesZGxBYFsF5kAeKKW17PYSHKVuEOG2EOga5POfkj1t7iWHlhl 6jXBA3dpfFVVHu8Bm8SPW4VW/hvb2BwmCQco3wJJNnd+73xVVO9vgxNc+U9kxHvUJFjL FtockBCTahDZb1DNnbrrfSw1GjZzYqk6C/5baW3S7rxhkcocZybQ40rrW2Qae6u7JTQa NhxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682700759; x=1685292759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FJg9Z757wkoktYD9WwpmRyspyW4Py5K0/MXLwUgCBlw=; b=iqgmSsUphg0niVxU4ypDrLW5rHVDXTFRAi392pySw4FWlscOTlmhAaRkdsjH8F9gVV r1ld4L4C7Wo5eGfaLJH2H7UprJMOMueFaolIPjwN8T9wrKpDUxKq9LwYbVYBaU2Vi9d7 6BZStBxQyt+L7q0maGX9Ba+PvwoFiyQFnIymPX+kjTxpyjgoVxl1HopOjsaxLXetiuYr xBQttd41pSpOgJ8T6aXqXRUtpSZlSaVHu9ASIjrffH4N8/I2L/BuiRbqmkMoth+aolXV wFmrk9vAQa3B+B3XUnE2vZUxWn/Wsep/DEszQbGlxug4Xe8qCa2FVt7t65ZTZ1Nof0lq 7C4Q== X-Gm-Message-State: AC+VfDz2F+/ff4Jih8g6foTeWO8zVHECq9GRnz6Zjni4LDQHmHoIDcAq FX4OAikR7ZDlxccFinRm+bs4S9KGOnOBnQvCaVFhMQ== X-Google-Smtp-Source: ACHHUZ6nl3mJ3PtbmdY7Ypc9R0cIjqjdJZCOG8x3I4UI2scjGfNswL3Uxesx+mU+3fS6AhR/45naDw== X-Received: by 2002:aca:f01:0:b0:38c:398e:6afd with SMTP id 1-20020aca0f01000000b0038c398e6afdmr2585752oip.53.1682700757871; Fri, 28 Apr 2023 09:52:37 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id c10-20020a4a4f0a000000b005462a25c4f9sm9665764oob.9.2023.04.28.09.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 09:52:37 -0700 (PDT) From: Mayuresh Chitale To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, alistair.francis@wdc.com Cc: Mayuresh Chitale , Alistair Francis , Daniel Barboza , liweiwei@iscas.ac.cn, Richard Henderson Subject: [PATCH v3 1/4] target/riscv: smstateen check for fcsr Date: Fri, 28 Apr 2023 22:22:08 +0530 Message-Id: <20230428165212.2800669-2-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230428165212.2800669-1-mchitale@ventanamicro.com> References: <20230428165212.2800669-1-mchitale@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=mchitale@ventanamicro.com; helo=mail-oi1-x22b.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If smstateen is implemented and smtateen0.fcsr is clear and misa.F is off then the floating point operations must return illegal instruction exception or virtual instruction trap, if relevant. Signed-off-by: Mayuresh Chitale Reviewed-by: Weiwei Li --- target/riscv/csr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 4451bd1263..3f6b824bd2 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -82,6 +82,10 @@ static RISCVException fs(CPURISCVState *env, int csrno) !riscv_cpu_cfg(env)->ext_zfinx) { return RISCV_EXCP_ILLEGAL_INST; } + + if (!env->debugger && !riscv_cpu_fp_enabled(env)) { + return smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR); + } #endif return RISCV_EXCP_NONE; } @@ -2100,6 +2104,9 @@ static RISCVException write_mstateen0(CPURISCVState *env, int csrno, target_ulong new_val) { uint64_t wr_mask = SMSTATEEN_STATEEN | SMSTATEEN0_HSENVCFG; + if (!riscv_has_ext(env, RVF)) { + wr_mask |= SMSTATEEN0_FCSR; + } return write_mstateen(env, csrno, wr_mask, new_val); } @@ -2173,6 +2180,10 @@ static RISCVException write_hstateen0(CPURISCVState *env, int csrno, { uint64_t wr_mask = SMSTATEEN_STATEEN | SMSTATEEN0_HSENVCFG; + if (!riscv_has_ext(env, RVF)) { + wr_mask |= SMSTATEEN0_FCSR; + } + return write_hstateen(env, csrno, wr_mask, new_val); } @@ -2259,6 +2270,10 @@ static RISCVException write_sstateen0(CPURISCVState *env, int csrno, { uint64_t wr_mask = SMSTATEEN_STATEEN | SMSTATEEN0_HSENVCFG; + if (!riscv_has_ext(env, RVF)) { + wr_mask |= SMSTATEEN0_FCSR; + } + return write_sstateen(env, csrno, wr_mask, new_val); } From patchwork Fri Apr 28 16:52:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 1775070 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=fUWu8QJf; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q7JZs5qWkz23td for ; Sat, 29 Apr 2023 02:53:25 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psRL0-0004Oj-Ft; Fri, 28 Apr 2023 12:52:50 -0400 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 1psRKz-0004NW-C7 for qemu-devel@nongnu.org; Fri, 28 Apr 2023 12:52:49 -0400 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1psRKx-0005tj-HI for qemu-devel@nongnu.org; Fri, 28 Apr 2023 12:52:49 -0400 Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-546ef028d62so63427eaf.1 for ; Fri, 28 Apr 2023 09:52:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682700763; x=1685292763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dIN9zI/PgwinfXAkOsAE9d4fwBU5Aj9DW4c0RUdpk0Y=; b=fUWu8QJfduUx6k7BKTtLmXQvz/Nhxv6onW24okY9zmoiu2koC2ThrdDUguXQlyS0NU JVUWMFDr8EXT7Ys+i6PsbXsfdJCu1yNkTD0LMKvBscIXn5KRASu+tbmjU9WFYsHChCPE V3pMlgkqGEVPkGdsfHh6e7TBeYQoVlWFU/bq7v9aa7MPPpFiCIeFRiyFu+G4MB6wmGOa yIPSJFC+OlaElQYVaWpvIeg86pJjO4HI21PpxOcr89nk9ZLBVYgcJ7646VdPuUo5QqKM dGVSDLYoB+6N7Ifp10cdJx4noDZvXAJ6meS/E64MFRtyODLztNWG+FoVixYy/ZLiKqBv 05uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682700763; x=1685292763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dIN9zI/PgwinfXAkOsAE9d4fwBU5Aj9DW4c0RUdpk0Y=; b=IKA6F7dIW71bwYHnrSaUm24alZf8J8BnusuImpsocR8U3rJyuixrDu18J92Koc4PQQ 0vLpOh6DkXK+mVyZ2XNDbXqrvhoHd049ZHYi1dIeclLXDyKza5/VMF1kndrELrxJ0mah O7P+07wcXbGAkgUKGQlJKnPj4nPqLJdCeEBDbUQSMdGImVj0Xq06ukyfzR3Xc3JP+zaD OjxedQBv5jMHwCxmev0aAOhAiwZT68R2RNB/RmGx456UGCg3OTjMqvIRkF/o0LQNeXx5 Q3vYuhRmztgVxplRRi/NHz+oUK8GWPDQLz2akVVYRqJADuvJSApRZ+j2qTTZv5ZCyV+x 0CWw== X-Gm-Message-State: AC+VfDwhbDE+f2JjaJGsI2k6sobdknGxjLgxMX7gHsthA+6+OsGNk1oo APkW1qz8s+eWB1XIWIHGiTHWrvXbeYJnKqowc1eYgA== X-Google-Smtp-Source: ACHHUZ7C9QYCh0g0wGuGux0S1eBMjQZmjXAmvF8Qe69scnZudL/AnmC71D8LoatKbcYgg0T7x75DRQ== X-Received: by 2002:aca:674d:0:b0:38b:eb6b:315b with SMTP id b13-20020aca674d000000b0038beb6b315bmr2602348oiy.46.1682700763253; Fri, 28 Apr 2023 09:52:43 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id c10-20020a4a4f0a000000b005462a25c4f9sm9665764oob.9.2023.04.28.09.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 09:52:42 -0700 (PDT) From: Mayuresh Chitale To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, alistair.francis@wdc.com Cc: Mayuresh Chitale , Alistair Francis , Daniel Barboza , liweiwei@iscas.ac.cn, Richard Henderson Subject: [PATCH v3 2/4] target/riscv: Reuse tb->flags.FS Date: Fri, 28 Apr 2023 22:22:09 +0530 Message-Id: <20230428165212.2800669-3-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230428165212.2800669-1-mchitale@ventanamicro.com> References: <20230428165212.2800669-1-mchitale@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c35; envelope-from=mchitale@ventanamicro.com; helo=mail-oo1-xc35.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, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When misa.F is 0 tb->flags.FS field is unused and can be used to save the current state of smstateen0.FCSR check which is needed by the floating point translation routines. Signed-off-by: Mayuresh Chitale Reviewed-by: Weiwei Li --- target/riscv/cpu_helper.c | 9 +++++++++ target/riscv/translate.c | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index b68dcfe7b6..126ac221a0 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -119,6 +119,15 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS)); } + /* + * If misa.F is 0 then the FS field of the tb->flags can be used to pass + * the current state of the smstateen.FCSR bit which must be checked for + * in the floating point translation routines. + */ + if (!riscv_has_ext(env, RVF)) { + fs = (smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR) == RISCV_EXCP_NONE); + } + if (cpu->cfg.debug && !icount_enabled()) { flags = FIELD_DP32(flags, TB_FLAGS, ITRIGGER, env->itrigger_enabled); } diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 928da0d3f0..74f624aa62 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -78,6 +78,7 @@ typedef struct DisasContext { int frm; RISCVMXL ol; bool virt_inst_excp; + bool smstateen_fcsr_ok; bool virt_enabled; const RISCVCPUConfig *cfg_ptr; /* vector extension */ @@ -1155,7 +1156,11 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->pc_succ_insn = ctx->base.pc_first; ctx->priv = FIELD_EX32(tb_flags, TB_FLAGS, PRIV); ctx->mem_idx = FIELD_EX32(tb_flags, TB_FLAGS, MEM_IDX); - ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS); + if (has_ext(ctx, RVF)) { + ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS); + } else { + ctx->mstatus_fs = 0; + } ctx->mstatus_vs = FIELD_EX32(tb_flags, TB_FLAGS, VS); ctx->priv_ver = env->priv_ver; ctx->virt_enabled = FIELD_EX32(tb_flags, TB_FLAGS, VIRT_ENABLED); @@ -1178,6 +1183,11 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); ctx->zero = tcg_constant_tl(0); ctx->virt_inst_excp = false; + if (has_ext(ctx, RVF) || !cpu->cfg.ext_smstateen) { + ctx->smstateen_fcsr_ok = 1; + } else { + ctx->smstateen_fcsr_ok = FIELD_EX32(tb_flags, TB_FLAGS, FS); + } } static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) From patchwork Fri Apr 28 16:52:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 1775073 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=n+KCQ7Z1; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q7Jb75CRNz23td for ; Sat, 29 Apr 2023 02:53:39 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psRL9-0004Ss-7r; Fri, 28 Apr 2023 12:52:59 -0400 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 1psRL7-0004ST-RB for qemu-devel@nongnu.org; Fri, 28 Apr 2023 12:52:57 -0400 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1psRL5-0005uS-0C for qemu-devel@nongnu.org; Fri, 28 Apr 2023 12:52:57 -0400 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-547303fccefso67528eaf.3 for ; Fri, 28 Apr 2023 09:52:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682700771; x=1685292771; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W8xSQqNZwWMr4Yif3IiQuGJNixlUe2bQ/ExkAYT0s5g=; b=n+KCQ7Z1Ks+4927ICY48gWNPUYE56GEtwtGetZf1jVvO2eHQfrm/AnlWujBSZ8aMGV d4rwlFzrzxukBvt4IiXXAVURPm8hxvCLNj6g3gPtGqMPup8+1BjQ9oovLlsG9bcVCKqN oMtKDlaZ8+eSROvRMVH596VVwmsPcSX2Skmmfyur78JH7GmLECn2kzoq+6Ectqpb400U h4Cmw9tJAY2M3itL+ABhYQe2S/SfvvcFt4KsKPlWETbJ/l1dU7666UFWtOfNXbjE6if5 csNoeWMr00GsH9hm34pDkAkC4sYcv2+QLRRvw0UKpnJno4XyWVPw8OmVu79wl/EZFS99 ym/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682700771; x=1685292771; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W8xSQqNZwWMr4Yif3IiQuGJNixlUe2bQ/ExkAYT0s5g=; b=c0GzokkGU/5el78/to3YtYebAZ5+xcmKTUu97CTIseH85kURCnXuBD/YITamGKxhmg Zl5tYBYJDCyjpG/M+yUT/xAKOjgwEEoa1xp24uoIl/K7Ch6/Z0YLHB1j9SudVedkhHlu 2ATFoW8DZAVGUOgmOEzma7PE9GImjMT63OqmGcZBcv2Fexe9hGH4QvMxj9vjubSVPXdQ l0wfHvrXBzDXFinlOjZ6r6U6tla3uE1wd/51acqKPN1xfaJh97FSwz/yxY6C2OdEcu0N Qgw0bL7/GQLgDnMNxMgV7Sf1aFuv25+AD8fLMo58JC0bgrOr6nboSXUt9uPi2oenWWrc BKCA== X-Gm-Message-State: AC+VfDyPFpoUeKc0d0wogpI/ALDjbofsuwP5VtgzPjuurPDe5n9KBCPb 0xgTg3n+3D8ykbmL3MwtXwI+KBWG16AaUiwrvq8OgA== X-Google-Smtp-Source: ACHHUZ4JikU1Ef368MlsO3lAF5uPDfeufWor5dQoiLi4KNxjUXvyERJbZC3GE16EsL+6iM3iKx1jpw== X-Received: by 2002:aca:170c:0:b0:38e:285e:99ec with SMTP id j12-20020aca170c000000b0038e285e99ecmr2676710oii.4.1682700771223; Fri, 28 Apr 2023 09:52:51 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id c10-20020a4a4f0a000000b005462a25c4f9sm9665764oob.9.2023.04.28.09.52.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 09:52:50 -0700 (PDT) From: Mayuresh Chitale To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, alistair.francis@wdc.com Cc: Mayuresh Chitale , Alistair Francis , Daniel Barboza , liweiwei@iscas.ac.cn, Richard Henderson Subject: [PATCH v3 3/4] target/riscv: check smstateen fcsr flag Date: Fri, 28 Apr 2023 22:22:10 +0530 Message-Id: <20230428165212.2800669-4-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230428165212.2800669-1-mchitale@ventanamicro.com> References: <20230428165212.2800669-1-mchitale@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c30; envelope-from=mchitale@ventanamicro.com; helo=mail-oo1-xc30.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If misa.F and smstateen_fcsr_ok flag are clear then all the floating point instructions must generate an appropriate exception. Signed-off-by: Mayuresh Chitale --- target/riscv/insn_trans/trans_rvd.c.inc | 13 ++++++--- target/riscv/insn_trans/trans_rvf.c.inc | 24 ++++++++++++++--- target/riscv/insn_trans/trans_rvzfh.c.inc | 32 +++++++++++++++-------- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_trans/trans_rvd.c.inc index 2c51e01c40..d9e0cf116f 100644 --- a/target/riscv/insn_trans/trans_rvd.c.inc +++ b/target/riscv/insn_trans/trans_rvd.c.inc @@ -18,10 +18,15 @@ * this program. If not, see . */ -#define REQUIRE_ZDINX_OR_D(ctx) do { \ - if (!ctx->cfg_ptr->ext_zdinx) { \ - REQUIRE_EXT(ctx, RVD); \ - } \ +#define REQUIRE_ZDINX_OR_D(ctx) do { \ + if (!has_ext(ctx, RVD)) { \ + if (!ctx->cfg_ptr->ext_zdinx) { \ + return false; \ + } \ + if (!smstateen_fcsr_check(ctx)) { \ + return false; \ + } \ + } \ } while (0) #define REQUIRE_EVEN(ctx, reg) do { \ diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_trans/trans_rvf.c.inc index b2de4fcf3f..e4d9834237 100644 --- a/target/riscv/insn_trans/trans_rvf.c.inc +++ b/target/riscv/insn_trans/trans_rvf.c.inc @@ -24,10 +24,26 @@ return false; \ } while (0) -#define REQUIRE_ZFINX_OR_F(ctx) do {\ - if (!ctx->cfg_ptr->ext_zfinx) { \ - REQUIRE_EXT(ctx, RVF); \ - } \ +static inline bool smstateen_fcsr_check(DisasContext *ctx) +{ +#ifndef CONFIG_USER_ONLY + if (!ctx->smstateen_fcsr_ok) { + ctx->virt_inst_excp = ctx->virt_enabled; + return false; + } +#endif + return true; +} + +#define REQUIRE_ZFINX_OR_F(ctx) do { \ + if (!has_ext(ctx, RVF)) { \ + if (!ctx->cfg_ptr->ext_zfinx) { \ + return false; \ + } \ + if (!smstateen_fcsr_check(ctx)) { \ + return false; \ + } \ + } \ } while (0) #define REQUIRE_ZCF(ctx) do { \ diff --git a/target/riscv/insn_trans/trans_rvzfh.c.inc b/target/riscv/insn_trans/trans_rvzfh.c.inc index 74dde37ff7..e228ae28a5 100644 --- a/target/riscv/insn_trans/trans_rvzfh.c.inc +++ b/target/riscv/insn_trans/trans_rvzfh.c.inc @@ -16,28 +16,38 @@ * this program. If not, see . */ -#define REQUIRE_ZFH(ctx) do { \ +#define REQUIRE_ZFH(ctx) do { \ if (!ctx->cfg_ptr->ext_zfh) { \ - return false; \ - } \ -} while (0) - -#define REQUIRE_ZHINX_OR_ZFH(ctx) do { \ - if (!ctx->cfg_ptr->ext_zhinx && !ctx->cfg_ptr->ext_zfh) { \ return false; \ } \ } while (0) +#define REQUIRE_ZHINX_OR_ZFH(ctx) do { \ + if (!ctx->cfg_ptr->ext_zfh) { \ + if (!ctx->cfg_ptr->ext_zhinx) { \ + return false; \ + } \ + if (!smstateen_fcsr_check(ctx)) { \ + return false; \ + } \ + } \ +} while (0) + #define REQUIRE_ZFHMIN(ctx) do { \ if (!ctx->cfg_ptr->ext_zfhmin) { \ return false; \ } \ } while (0) -#define REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx) do { \ - if (!(ctx->cfg_ptr->ext_zfhmin || ctx->cfg_ptr->ext_zhinxmin)) { \ - return false; \ - } \ +#define REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx) do { \ + if (!ctx->cfg_ptr->ext_zfhmin) { \ + if (ctx->cfg_ptr->ext_zhinxmin) { \ + return false; \ + } \ + if (!smstateen_fcsr_check(ctx)) { \ + return false; \ + } \ + } \ } while (0) static bool trans_flh(DisasContext *ctx, arg_flh *a) From patchwork Fri Apr 28 16:52:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 1775074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=bsyrp98+; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q7JbP4JbCz23td for ; Sat, 29 Apr 2023 02:53:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psRLH-0004Vl-Ka; Fri, 28 Apr 2023 12:53:07 -0400 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 1psRLE-0004Uc-5T for qemu-devel@nongnu.org; Fri, 28 Apr 2023 12:53:04 -0400 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1psRLB-0005vl-Cd for qemu-devel@nongnu.org; Fri, 28 Apr 2023 12:53:03 -0400 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-1878f1ebf46so163449fac.1 for ; Fri, 28 Apr 2023 09:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682700777; x=1685292777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ry93EuiL339cXmTcSwW+O/TAemEHyYi1HmGB8rjIeQg=; b=bsyrp98+yhTnfMaIDEAlExYnTQSo2RL4D0dvGwrn+2En3F+e6Ce7fnDrRNXdaQomT9 YSiXMPd0ERzRhzRzwlWuL/Yu8NO6D3krQTB3hg11+hPidGNpAfmIGLtmVoZyFBDu0U+J xBgRE2e/WDTZ5QA7jOc+kqJazrdROxaNmAq43JdUP0AMfPrCWELCi5hqrjHhHjhjNiZA tEW/XmPLxHLGHMlorY9ro9S6/l4CthoWlBQX3KjXrELU8Y+otfmVGR2QYKF5QVd/a7QY AhyxKX6eylrnu6t1GRYcL+tDSKBCA4S2m+P2BoL49WrN19DdaMcsj5wYVxy6W4w1eDCD r/KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682700777; x=1685292777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ry93EuiL339cXmTcSwW+O/TAemEHyYi1HmGB8rjIeQg=; b=YYRkZGdOObJYfHi6uWmuKMgbQh/nKvqONlU2o2qRW47y3Dsh6G6rPKvWQaTpMoXQ2d oi7unldvi74UOu9OIp6mg7g6DPLef7XlO8Xvbb9C7GB2eKE423DOFSwPOlBEnCtAoKvK yZao95Bnt71+bbUnIhKAjepoAuV9Do3+U+CN8KXhqUNld6PbcUJlrKYlmWNM5ReZM+Xc juYQiNyxp7CIGMp2cAQiQKFvC6/5NCc8C9sdrgd9eGIg+9x/nSIbKRDl4jnMaYcFIkjO 2ln8y8xNBv6BFOXsR0O1A785hqLEYlqwaZqD2s+D1xyEiO9UhXaqtclxLOdy+T1G80qb Wz6g== X-Gm-Message-State: AC+VfDw5Yj9z78y1iUhpIccGP+vEYvUrvJfu1AZNlrP5BRRb3biT5zk5 wLZtOIl5vlzMP30TlVpM5qQZg2yGGoh0/W2Hj0ZAWQ== X-Google-Smtp-Source: ACHHUZ6DOCEJfRde9M0If+servyTmkcjRv0W6sTcCaXxTAj9yTKo32wf5sIm2jUPlRkAZSw4J4s3Nw== X-Received: by 2002:a05:6870:52c5:b0:184:1c47:853d with SMTP id p5-20020a05687052c500b001841c47853dmr3014755oak.35.1682700776977; Fri, 28 Apr 2023 09:52:56 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id c10-20020a4a4f0a000000b005462a25c4f9sm9665764oob.9.2023.04.28.09.52.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 09:52:56 -0700 (PDT) From: Mayuresh Chitale To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, alistair.francis@wdc.com Cc: Mayuresh Chitale , Alistair Francis , Daniel Barboza , liweiwei@iscas.ac.cn, Richard Henderson Subject: [PATCH v3 4/4] target/riscv: smstateen knobs Date: Fri, 28 Apr 2023 22:22:11 +0530 Message-Id: <20230428165212.2800669-5-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230428165212.2800669-1-mchitale@ventanamicro.com> References: <20230428165212.2800669-1-mchitale@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2b; envelope-from=mchitale@ventanamicro.com; helo=mail-oa1-x2b.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add knobs to allow users to enable smstateen and also export it via the ISA extension string. Signed-off-by: Mayuresh Chitale Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index befa64528f..9420cd670e 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -119,6 +119,7 @@ static const struct isa_ext_data isa_edata_arr[] = { ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx), ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), + ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), @@ -1498,8 +1499,8 @@ static Property riscv_cpu_extensions[] = { DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128), DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), + DEFINE_PROP_BOOL("smstateen", RISCVCPU, cfg.ext_smstateen, false), DEFINE_PROP_BOOL("svadu", RISCVCPU, cfg.ext_svadu, true), - DEFINE_PROP_BOOL("svinval", RISCVCPU, cfg.ext_svinval, false), DEFINE_PROP_BOOL("svnapot", RISCVCPU, cfg.ext_svnapot, false), DEFINE_PROP_BOOL("svpbmt", RISCVCPU, cfg.ext_svpbmt, false),