All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Yanfeng Liu <yfliu2008@qq.com>
Cc: qemu-riscv@nongnu.org,  qemu-devel@nongnu.org,  alistair.francis@wdc.com
Subject: Re: [PATCH v2] riscv/gdb: add virt mode debug interface
Date: Thu, 28 Nov 2024 14:21:33 +0000	[thread overview]
Message-ID: <8734jbh21e.fsf@draig.linaro.org> (raw)
In-Reply-To: <tencent_B52B1EB0A504D6F690B6E6F3FD3AC9BCDC09@qq.com> (Yanfeng Liu's message of "Thu, 28 Nov 2024 15:21:27 +0800")

Yanfeng Liu <yfliu2008@qq.com> writes:

> This adds `virt` virtual register on debug interface so that users
> can access current virtualization mode for debugging purposes.
>
> Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
> ---
>  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 @@
>  <!DOCTYPE feature SYSTEM "gdb-target.dtd">
>  <feature name="org.gnu.gdb.riscv.virtual">
>    <reg name="priv" bitsize="32"/>
> +  <reg name="virt" bitsize="32"/>
>  </feature>
> 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 @@
>  <!DOCTYPE feature SYSTEM "gdb-target.dtd">
>  <feature name="org.gnu.gdb.riscv.virtual">
>    <reg name="priv" bitsize="64"/>
> +  <reg name="virt" bitsize="64"/>
>  </feature>

I assume these are mirrored in gdb not a QEMU only extension?

> 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 *mem_buf, int n)
>  
>  static int riscv_gdb_get_virtual(CPUState *cs, GByteArray *buf, int n)
>  {
> -    if (n == 0) {
> +    if (n >= 0 && n <= 1) {
>  #ifdef CONFIG_USER_ONLY
>          return gdb_get_regl(buf, 0);
>  #else
>          RISCVCPU *cpu = RISCV_CPU(cs);
>          CPURISCVState *env = &cpu->env;
>  
> -        return gdb_get_regl(buf, env->priv);
> +        return gdb_get_regl(buf, n ? env->virt_enabled : env->priv);

The range checking of n and ternary op are a bit magical here. Whats
wrong with a good old fashioned switch/case statement?

>  #endif
>      }
>      return 0;
> @@ -221,14 +221,20 @@ static int riscv_gdb_get_virtual(CPUState *cs, GByteArray *buf, int n)
>  
>  static int riscv_gdb_set_virtual(CPUState *cs, uint8_t *mem_buf, int n)
>  {
> -    if (n == 0) {
> +    if (n >= 0 && n <= 1) {
>  #ifndef CONFIG_USER_ONLY
>          RISCVCPU *cpu = RISCV_CPU(cs);
>          CPURISCVState *env = &cpu->env;
>  
> -        env->priv = ldtul_p(mem_buf) & 0x3;
> -        if (env->priv == PRV_RESERVED) {
> -            env->priv = PRV_S;
> +        if (n == 0) {
> +            env->priv = ldtul_p(mem_buf) & 0x3;
> +            if (env->priv == PRV_RESERVED) {
> +                env->priv = PRV_S;
> +            }
> +        } else {
> +            if (env->priv != PRV_M) {
> +                env->virt_enabled = ldtul_p(mem_buf) & 0x1;
> +            }

ditto here.

>          }
>  #endif
>          return sizeof(target_ulong);

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2024-11-28 14:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-28  7:21 [PATCH v2] riscv/gdb: add virt mode debug interface Yanfeng Liu
2024-11-28 14:21 ` Alex Bennée [this message]
2024-11-28 18:01   ` Richard Henderson
2024-11-29  2:11   ` Yanfeng
2024-11-29  9:59     ` Alex Bennée
2024-11-30  0:14       ` Yanfeng Liu
2024-12-04 16:03         ` Mario Fleischmann
2024-12-05  1:29           ` Yanfeng Liu
2024-12-05  8:10             ` Alex Bennée
2024-12-05  9:15               ` Yanfeng Liu
2024-12-16  5:33                 ` Alistair Francis
2024-12-18  0:49                   ` Yanfeng Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8734jbh21e.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=yfliu2008@qq.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.