qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Subject: Re: [PATCH] target/avr: Use vaddr type for $PC jumps
Date: Thu, 9 Oct 2025 14:42:36 -0700	[thread overview]
Message-ID: <3460610b-5c1a-4189-8f0a-fd04897effb5@linaro.org> (raw)
In-Reply-To: <20251009200525.33987-1-philmd@linaro.org>

On 10/9/25 13:05, Philippe Mathieu-Daudé wrote:
> translator_use_goto_tb() expects a vaddr type since commit
> b1c09220b4c ("accel/tcg: Replace target_ulong with vaddr in
> translator*()").
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/avr/translate.c | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/target/avr/translate.c b/target/avr/translate.c
> index 804b0b21dbd..20191055861 100644
> --- a/target/avr/translate.c
> +++ b/target/avr/translate.c
> @@ -87,7 +87,7 @@ struct DisasContext {
>       CPUAVRState *env;
>       CPUState *cs;
>   
> -    target_long npc;
> +    vaddr npc;

Ah, here's where proper typing might have saved us a bug.

npc is not a virtual (or physical) address in the normal sense, it is a *word* address 
(i.e. byte address / 2).

So I think you should just use uint32_t here.

>       uint32_t opcode;
>   
>       /* Routine used to access memory */
> @@ -981,7 +981,7 @@ static void gen_pop_ret(DisasContext *ctx, TCGv ret)
>       }
>   }
>   
> -static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
> +static void gen_goto_tb(DisasContext *ctx, int n, vaddr dest)
>   {
>       const TranslationBlock *tb = ctx->base.tb;
>   
> @@ -1004,7 +1004,7 @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
>    */
>   static bool trans_RJMP(DisasContext *ctx, arg_RJMP *a)
>   {
> -    int dst = ctx->npc + a->imm;
> +    vaddr dst = ctx->npc + a->imm;

And here...

>   
>       gen_goto_tb(ctx, 0, dst);

... and therefore also in the gen_goto_tb argument.

The bug can thus be said to be within gen_goto_tb, where we don't convert from word 
address to byte address.



r~


  reply	other threads:[~2025-10-09 21:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-09 20:05 [PATCH] target/avr: Use vaddr type for $PC jumps Philippe Mathieu-Daudé
2025-10-09 21:42 ` Richard Henderson [this message]
2025-10-10  2:56   ` Philippe Mathieu-Daudé
2025-10-10  4:30     ` Richard Henderson

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=3460610b-5c1a-4189-8f0a-fd04897effb5@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).