From nobody Sat Nov 23 18:43:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1731575748; cv=none; d=zohomail.com; s=zohoarc; b=MT1HbrBpAHvjMfu+BlqjmFb5x9Pqp8qi8OhFMLZo9KuUFTdGHonDmRfCN+FDJweKXTJnHciLnZ9+FhVW+9VFJMkMI+/u5UYkU4Y+Yh2/M39xdQw8cAw5npB8kMblmr8TZKzK+apSTdyjqTHanjEapEqqmrwJd0aZuupaNnhkIrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731575748; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=e5VCSEROfFnSITFRhmQ5Rm5Z+/eZKzb7VObh38bI74M=; b=GDVYse8noQ/1wjgA73fiZZNE9hYvJDvr3nT9i9HO6NHkIWjdzMfoIgchYU3FlcmyXuk7AKH43iZsbp6S8K/yTQuM5lf/gtv2lW96aDu5AFU2YQ1/BKm2NUz8D1OQU+baycA3xvH1V+x0NqM21bEODz2lr5DLD/EYvXQzIHJiXPM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731575748145559.6770517600916; Thu, 14 Nov 2024 01:15:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBVvp-000087-U0; Thu, 14 Nov 2024 04:14:29 -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 1tBVvL-0008L7-Gj for qemu-devel@nongnu.org; Thu, 14 Nov 2024 04:14:00 -0500 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBVvG-0007hm-GI for qemu-devel@nongnu.org; Thu, 14 Nov 2024 04:13:59 -0500 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-53da3545908so358642e87.1 for ; Thu, 14 Nov 2024 01:13:52 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3821ae313e3sm899050f8f.94.2024.11.14.01.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 01:13:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1731575631; x=1732180431; darn=nongnu.org; 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=e5VCSEROfFnSITFRhmQ5Rm5Z+/eZKzb7VObh38bI74M=; b=3C6HlX6w7ygZCpKvl1Q+a+cusabPmMNdqkmR2VOngn0d3QW4oMQt3uht8J1ncVspoo h4oe0nwXSCfr3NC7Q0bhe8pE3/Kh1RiIDBLAR9VtW0KuOvOp6gjly/jNPE/sWukyn3Y8 b7CGIsoQFWbT7TvKhfiDdIWGvEPsLT+DW8VBbIcdeprDCjxA+Xgkl6F6lkiJ5GoRY8NH /0vNwHN2EDt0NOaxM3iID30t3nsfnzFT7je9ox9ddUZI5Pm1SOYxn6UYvSLLcJP8AINR g867SwD6UGqK4ullj0qkDhU5VPv36j6o4JpSrJjj0nvOTSFBmnEfTZmMPgnE0EDf876U kZOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731575631; x=1732180431; 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=e5VCSEROfFnSITFRhmQ5Rm5Z+/eZKzb7VObh38bI74M=; b=eiYJpNnP+Cq+HIXqrlYWZkHHPkgtxnoOT5lYI5v0tBMFaTbViY1NPX9VXSAoNFjbnp Rr/anx7xWlRGg5hg+/JZNDZgjiJpepv4QsN7yPdIARfvGuOUTmTjtlrP7t9jvLrZixFw 46xOjH3LTOTNoDlYDIFWWboYLUk5z4bQpoISjGkSkpii+Vf6WjcWgc7OPDKjPYdjaEvZ NmxkCrjuRvt1JJI7bNPu9rQ4VFhJa8qWi8emz935RiQEjgP4vqr1H6P/hdRoKDPGCiRe FRhm5Inz6RcV4KrvB/nWGzYsIlcIOODUHYY7Yp0q7eNKiWGneFXlb7JJeB3qEg9uJ3Ad am3A== X-Forwarded-Encrypted: i=1; AJvYcCUwwUQ5lq/UYKGzQnGMeVWgx0ETpCV3CJ/ffkBAw2SwDXUUnvtPjjtdaMREqhbwD8M/jsfzuiyzQrBm@nongnu.org X-Gm-Message-State: AOJu0Yy4uzJ361mG0W76Mg76yKnS2Rik7qtnIgkW9wMTOYsR6kmxMw5Q aAn4oeVaxZyAKVqj2Z2hlrZULZA7Nx25bjNMJaCDV4zUnXurEDsBoW86YkPXWwQ= X-Google-Smtp-Source: AGHT+IF1OJfD8iGL+A6cQediE5Vks/yi+m1EhKBEvVOF7+doo9vYEKH0yxEhEaiQo1UrKP7M6X97Qg== X-Received: by 2002:a05:6512:3e02:b0:539:8fcd:510 with SMTP id 2adb3069b0e04-53da5c44f67mr632759e87.20.1731575631322; Thu, 14 Nov 2024 01:13:51 -0800 (PST) From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Bin Meng Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Ved Shanbhogue , Atish Patra , qemu-devel@nongnu.org Subject: [PATCH v5 7/9] target/riscv: Implement Smdbltrp sret, mret and mnret behavior Date: Thu, 14 Nov 2024 10:13:28 +0100 Message-ID: <20241114091332.108811-8-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241114091332.108811-1-cleger@rivosinc.com> References: <20241114091332.108811-1-cleger@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::12b; envelope-from=cleger@rivosinc.com; helo=mail-lf1-x12b.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1731575748507116600 When the Ssdbltrp extension is enabled, SSTATUS.MDT field is cleared when executing sret if executed in M-mode. When executing mret/mnret, SSTATUS.MDT is cleared. Signed-off-by: Cl=C3=A9ment L=C3=A9ger Reviewed-by: Alistair Francis --- target/riscv/op_helper.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index dabc74de39..e5e10f7162 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -299,6 +299,9 @@ target_ulong helper_sret(CPURISCVState *env) } mstatus =3D set_field(mstatus, MSTATUS_SDT, 0); } + if (riscv_cpu_cfg(env)->ext_smdbltrp && env->priv >=3D PRV_M) { + mstatus =3D set_field(mstatus, MSTATUS_MDT, 0); + } if (env->priv_ver >=3D PRIV_VERSION_1_12_0) { mstatus =3D set_field(mstatus, MSTATUS_MPRV, 0); } @@ -375,6 +378,9 @@ target_ulong helper_mret(CPURISCVState *env) if (riscv_cpu_cfg(env)->ext_ssdbltrp) { mstatus =3D ssdbltrp_mxret(env, mstatus, prev_priv, prev_virt); } + if (riscv_cpu_cfg(env)->ext_smdbltrp) { + mstatus =3D set_field(mstatus, MSTATUS_MDT, 0); + } if ((env->priv_ver >=3D PRIV_VERSION_1_12_0) && (prev_priv !=3D PRV_M)= ) { mstatus =3D set_field(mstatus, MSTATUS_MPRV, 0); } @@ -412,6 +418,12 @@ target_ulong helper_mnret(CPURISCVState *env) env->mstatus =3D ssdbltrp_mxret(env, env->mstatus, prev_priv, prev= _virt); } =20 + if (riscv_cpu_cfg(env)->ext_smdbltrp) { + if (prev_priv < PRV_M) { + env->mstatus =3D set_field(env->mstatus, MSTATUS_MDT, 0); + } + } + if (riscv_has_ext(env, RVH) && prev_virt) { riscv_cpu_swap_hypervisor_regs(env); } --=20 2.45.2