target/avr: Use vaddr type for $PC jumps
PATCH 1/1 target/avr: Use vaddr type for $PC jumps
translator_use_goto_tb() expects a vaddr type since commit b1c09220b4c ("accel/tcg: Replace target_ulong with vaddr in translator*()").
--- target/avr/translate.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
target/avr/translate.c +9 -9
@@ -87,7 +87,7 @@ struct DisasContext {CPUAVRState *env;CPUState *cs; -target_long npc; +vaddr npc;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;gen_goto_tb (ctx,0 , dst);
@@ -1072,8 +1072,8 @@ static bool trans_JMP(DisasContext *ctx, arg_JMP *a)*/ static bool trans_RCALL (DisasContext *ctx,arg_RCALL *a) { -int ret = ctx->npc; -int dst = ctx->npc + a->imm; +vaddr ret = ctx->npc; +vaddr dst = ctx->npc + a->imm;gen_push_ret (ctx, ret);gen_goto_tb (ctx,0 , dst);
@@ -1094,7 +1094,7 @@ static bool trans_ICALL(DisasContext *ctx, arg_ICALL *a)return true; } -int ret = ctx->npc; +vaddr ret = ctx->npc;gen_push_ret (ctx, ret);gen_jmp_z (ctx);
@@ -1136,8 +1136,8 @@ static bool trans_CALL(DisasContext *ctx, arg_CALL *a)return true; } -int Imm = a->imm; -int ret = ctx->npc; +vaddr Imm = a->imm; +vaddr ret = ctx->npc;gen_push_ret (ctx, ret);gen_goto_tb (ctx,0 , Imm);
@@ -2743,7 +2743,7 @@ static void avr_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) }if (ctx->base.is_jmp ==DISAS_NEXT ) { -target_ulong page_first = ctx->base.pc_first &TARGET_PAGE_MASK ; +vaddr page_first = ctx->base.pc_first &TARGET_PAGE_MASK ;if ((ctx->base.pc_next - page_first) >=TARGET_PAGE_SIZE -4 ) { ctx->base.is_jmp =DISAS_TOO_MANY ;
Signature · 1 line
2.51.0
Quoted 14 lines · Philippe Mathieu-Daudé
translator_use_goto_tb()expects a vaddr type since commitb1c09220b4c("accel/tcg: Replacetarget_ulongwith vaddr in translator*()").Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/avr/translate.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)target/avr/translate.c +0
-0
target/avr/translate.c struct DisasContext { · line 90
Quoted 5 lines
target/avr/translate.c +1
-1@@ -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.
Quoted 13 lines
target/avr/translate.c +1
-1uint32_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;
target/avr/translate.c static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) · line 1007
Quoted 5 lines
target/avr/translate.c +1
-1@@ -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...
target/avr/translate.c static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) · line 1008
Quoted 2 lines
target/avr/translate.c +0
-0gen_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~
Quoted 22 lines · Richard Henderson
Quoted 14 lines · Philippe Mathieu-Daudé
translator_use_goto_tb()expects a vaddr type since commitb1c09220b4c("accel/tcg: Replacetarget_ulongwith vaddr in translator*()").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/avr/translate.c| 18 +++++++++---------1 file changed, 9 insertions(+), 9 deletions(-)target/avr/translate.c +0
-0target/avr/translate.c struct DisasContext { · line 89
Quoted 4 lines
target/avr/translate.c +1
-1@@ -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.
Quoted 3 lines
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_there.
IIUC the field is 24-bit wide, OK.
Quoted 20 lines
Quoted 11 lines
target/avr/translate.c +1
-1uint32_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;target/avr/translate.c static void gen_goto_tb(DisasContext *ctx, int · line 1008
Quoted 6 lines
target/avr/translate.c +1
-1@@ -1004,7 +1004,7 @@ static void gen_goto_tb(DisasContext *ctx, intn, 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...
Quoted 5 lines
target/avr/translate.c static void gen_goto_tb(DisasContext *ctx, int · line 1009
Quoted 1 line
target/avr/translate.c +0
-0gen_goto_tb(ctx, 0, dst);... and therefore also in the
gen_goto_tbargument.The bug can thus be said to be within
gen_goto_tb, where we don't convert from word address to byte address.
Oh I see. Then avr_tr_insn_start() is also buggy?
Quoted 1 line · Philippe Mathieu-Daudé
Oh I see. Then
avr_tr_insn_start()is also buggy?
Good question. It depends on how we view things.
At least once upon a time, the values in insn_start were all private to the target. They were only consumed by restore_state_to_opc.
Over time there has been creep, where the first argument might be assumed to be the virtual address. E.g. plugins? But beyond that?
r~