From nobody Thu Dec 26 20:29:40 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; dmarc=pass(p=quarantine dis=none) header.from=qq.com ARC-Seal: i=1; a=rsa-sha256; t=1732778885; cv=none; d=zohomail.com; s=zohoarc; b=izNT0jATuj5aJjfoZZM60pQfQC2zr+L1MznPta9tjxxv0X1SYZSmcHxxWsHlm/z/HI05Ko6bOSqZ9l8iz6n/BWmbvzYjTRfrP9EnYPyRha8tvDTIYtcH/HmLUIK8AmLDI6wCcseToo4+6ADzmBsUzBf8rAZMtvoT9hmL37Z5xtA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732778885; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Sz6/n21em2mOQ+wrKO+rxDoqrWHY7+lJTRf0i7BsglY=; b=QmxyVIwI5jhoH6wiTvbY2UOsFjI5B5v9+GSMmXuSP0YrzKNxCWza/lXbU5ULuf2hkufFnJ+c/QTAAMSrbFMTki4Mo9lpXlwJPiZgvmVG83WgfDPt4Wn26E+ssu+DX2V0G6uzbTO3qgY7oO7BgO/IAxkik4nGxfr9LvKBKz+/CQE= 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732778885700977.8916470373482; Wed, 27 Nov 2024 23:28:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGYve-0003CL-7j; Thu, 28 Nov 2024 02:27:10 -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 1tGYvX-0003BQ-27; Thu, 28 Nov 2024 02:27:04 -0500 Received: from out162-62-57-210.mail.qq.com ([162.62.57.210]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGYvL-0006Ms-PO; Thu, 28 Nov 2024 02:26:57 -0500 Received: from qq.com ([61.139.23.214]) by newxmesmtplogicsvrszb21-0.qq.com (NewEsmtp) with SMTP id 55D8A671; Thu, 28 Nov 2024 15:21:29 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1732778798; bh=Sz6/n21em2mOQ+wrKO+rxDoqrWHY7+lJTRf0i7BsglY=; h=From:To:Cc:Subject:Date; b=D6CDNyI9o+O9YzOpk83XnOeOrmIMGkPPFWusRbF1UT6Ov/zt/34bG3PqKxFnxhfnK g4gnJlTjUxENg0J+bfZkn27zdVQlqlPLb4mqIu65BDKfM4hbYXJ9PnY7P/mdD1CyfE P1ta3llC+MRKhfRwxhLSHJzdDIUC1nQZKB2rtpzo= X-QQ-mid: xmsmtpt1732778489t2o1igzzk Message-ID: X-QQ-XMAILINFO: MyIXMys/8kCtONX4BHXX+F9csqGMb/bilzJ9iKYVWZeOdep80M2VxqxgMJtdTu g8l9IHRfAl7YwFgo/ghM/CFuH3VXj3aePnz4JYZfBKss4wLBeubBoyn4T5Y7knIGtInibVYz+lwc bQEmv0hv0FAjfipKE1ZLw6jDPYnVzqMBCLb9tTAkKzwWDmTydTGGuEhPpy6Zxdun/fLkiIKI1bM0 gLCelErVTuyBe+Hp0ZP8pRJ2ub9q+RosRn21ETLj27jdRY147yl+5Telqe4E/3NOqlaynNqtXAM2 7vp/+7lWYzOM4csHDPM5RTXgXc+bUwjoeZD6gDQMsjLt5KHK52yKyDvD6YBF8Sa8PylCJG7whq1a zibXQ2K0LjyQiTAyyxdhU7wUu8hCAXlheuxlKBX8gM73iz4WiIiBbhtXyxMmAI9r9wnvGjp/6RxZ CTA4VCSVaPDvVfJG4EixDSBuTC9aX1gUniKLKyky2MH9lHBRV2aD+UqSPJf9cgW5MEnR/bCGvH3X cWZMXi5u0LtxfKKlHkRjNM96050YxznQ30UoE5Jnn4xuzgpel3Oiwms0TEKwHIViD4AA4bvSI3NC xEw7l2LskI2YB+AnlRL/BtDi0V/mENbDQDmKNfSklyi6Muel3Mk6u512uaS8GnyEQNzi2p4+tfiZ 12A4epxTI2znGSDVEx0+h3l32TThQnRJPqTnCfamZIufIwfnetW2QP8jKl5x57boBT739FlbabY7 mi3a2djplC7vrGOfdYrW1gsOji/tBLCsZAczLKgNGCvk4g5v1wq2veP8R9CchBD2cJeVtUsl1d90 Adop498P3MwPRzm33ZF2g68XI5Ss6CtVAX50QWYfEgHT4bR8zwTX/EWeJbTZRkk4fnRxz9KWNgDK HLTktaBY7z93kWB3a6nqR4i8Jj4ZxssOjYJvjeEsRplFsgqePSjZiGPDXU21kWQd6tVePo9tuG3U aYWjsLJBWFp0ZPQ1nZYP3bnuRhBFTK X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= From: Yanfeng Liu To: qemu-riscv@nongnu.org Cc: qemu-devel@nongnu.org, alistair.francis@wdc.com, Yanfeng Liu Subject: [PATCH v2] riscv/gdb: add virt mode debug interface Date: Thu, 28 Nov 2024 15:21:27 +0800 X-OQ-MSGID: <20241128072127.17246-1-yfliu2008@qq.com> X-Mailer: git-send-email 2.34.1 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=162.62.57.210; envelope-from=yfliu2008@qq.com; helo=out162-62-57-210.mail.qq.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HELO_DYNAMIC_IPADDR=1.951, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, RDNS_DYNAMIC=0.982, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @qq.com) X-ZM-MESSAGEID: 1732778887182019100 Content-Type: text/plain; charset="utf-8" This adds `virt` virtual register on debug interface so that users can access current virtualization mode for debugging purposes. Signed-off-by: Yanfeng Liu --- gdb-xml/riscv-32bit-virtual.xml | 1 + gdb-xml/riscv-64bit-virtual.xml | 1 + target/riscv/gdbstub.c | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gdb-xml/riscv-32bit-virtual.xml b/gdb-xml/riscv-32bit-virtual.= xml index 905f1c555d..d44b6ca2dc 100644 --- a/gdb-xml/riscv-32bit-virtual.xml +++ b/gdb-xml/riscv-32bit-virtual.xml @@ -8,4 +8,5 @@ + diff --git a/gdb-xml/riscv-64bit-virtual.xml b/gdb-xml/riscv-64bit-virtual.= xml index 62d86c237b..7c9b63d5b6 100644 --- a/gdb-xml/riscv-64bit-virtual.xml +++ b/gdb-xml/riscv-64bit-virtual.xml @@ -8,4 +8,5 @@ + diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index c07df972f1..7399003e04 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -206,14 +206,14 @@ static int riscv_gdb_set_csr(CPUState *cs, uint8_t *m= em_buf, int n) =20 static int riscv_gdb_get_virtual(CPUState *cs, GByteArray *buf, int n) { - if (n =3D=3D 0) { + if (n >=3D 0 && n <=3D 1) { #ifdef CONFIG_USER_ONLY return gdb_get_regl(buf, 0); #else RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; =20 - return gdb_get_regl(buf, env->priv); + return gdb_get_regl(buf, n ? env->virt_enabled : env->priv); #endif } return 0; @@ -221,14 +221,20 @@ static int riscv_gdb_get_virtual(CPUState *cs, GByteA= rray *buf, int n) =20 static int riscv_gdb_set_virtual(CPUState *cs, uint8_t *mem_buf, int n) { - if (n =3D=3D 0) { + if (n >=3D 0 && n <=3D 1) { #ifndef CONFIG_USER_ONLY RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; =20 - env->priv =3D ldtul_p(mem_buf) & 0x3; - if (env->priv =3D=3D PRV_RESERVED) { - env->priv =3D PRV_S; + if (n =3D=3D 0) { + env->priv =3D ldtul_p(mem_buf) & 0x3; + if (env->priv =3D=3D PRV_RESERVED) { + env->priv =3D PRV_S; + } + } else { + if (env->priv !=3D PRV_M) { + env->virt_enabled =3D ldtul_p(mem_buf) & 0x1; + } } #endif return sizeof(target_ulong); --=20 2.34.1