Skip to contentSkip to conversation

target/avr: Few fixes

PATCH Superseded Philippe Mathieu-Daudé 2 participants 7 messages Jul 7, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover target/avr: Few fixes

Few fixes on top of the AVR merger series Thomas sent yesterday:

https://www.mail-archive.com/[email protected]/msg720089.html
Based-on: <[email protected]>

Philippe Mathieu-Daudé (3):
target/avr: Drop tlb_flush() in avr_cpu_reset()
target/avr: Fix $PC displayed address
target/avr: Fix SBRC/SBRS instructions

 target/avr/cpu.c       | 4 +---
 target/avr/translate.c | 4 ++--
 2 files changed, 3 insertions(+), 5 deletions(-)
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/3 target/avr: Drop tlb_flush() in avr_cpu_reset()

Since commit 1f5c00cfdb tlb_flush() is called from cpu_common_reset().

---
 target/avr/cpu.c | 2 --
 1 file changed, 2 deletions(-)
target/avr/cpu.c +0 -2
index 4e4dd4f6aa..50fb1c378b 100644
@@ -78,8 +78,6 @@ static void avr_cpu_reset(DeviceState *ds)
     env->skip = 0;
 
     memset(env->r, 0, sizeof(env->r));
-
-    tlb_flush(cs);
 }
 
 static void avr_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
Signature · 1 line
2.21.3
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] target/avr: Drop tlb_flush() in avr_cpu_reset()

Quoted 3 lines · Philippe Mathieu-Daudé

Since commit 1f5c00cfdb tlb_flush() is called from cpu_common_reset().

Quoted 17 lines
---
 target/avr/cpu.c | 2 --
 1 file changed, 2 deletions(-)
target/avr/cpu.c +0 -2
index 4e4dd4f6aa..50fb1c378b 100644
@@ -78,8 +78,6 @@ static void avr_cpu_reset(DeviceState *ds)
     env->skip = 0;
 
     memset(env->r, 0, sizeof(env->r));
-
-    tlb_flush(cs);
 }
 
 static void avr_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
Signature · 1 line
Alex Bennée
#3 lore raw

PATCH 2/3 target/avr: Fix $PC displayed address

In reply to Philippe Mathieu-Daudé

$PC is 16-bit wide. Other registers display addresses on a byte granularity.
To have a coherent ouput, display $PC using byte granularity too.

---
 target/avr/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/avr/cpu.c +1 -1
index 50fb1c378b..9be464991f 100644
@@ -151,7 +151,7 @@ static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     int i;
 
     qemu_fprintf(f, "\n");
-    qemu_fprintf(f, "PC:    %06x\n", env->pc_w);
+    qemu_fprintf(f, "PC:    %06x\n", env->pc_w * 2);
     qemu_fprintf(f, "SP:      %04x\n", env->sp);
     qemu_fprintf(f, "rampD:     %02x\n", env->rampD >> 16);
     qemu_fprintf(f, "rampX:     %02x\n", env->rampX >> 16);
Signature · 1 line
2.21.3
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] target/avr: Fix $PC displayed address

Quoted 14 lines · Philippe Mathieu-Daudé

$PC is 16-bit wide. Other registers display addresses on a byte granularity.
To have a coherent ouput, display $PC using byte granularity too.

---
 target/avr/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/avr/cpu.c +0 -0
index 50fb1c378b..9be464991f 100644

target/avr/cpu.c static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 154

Quoted 5 lines
target/avr/cpu.c +1 -1
@@ -151,7 +151,7 @@ static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     int i;
 
     qemu_fprintf(f, "\n");
-    qemu_fprintf(f, "PC:    %06x\n", env->pc_w);
+    qemu_fprintf(f, "PC:    %06x\n", env->pc_w * 2);

OK this was confusing until I grepped around the code and found the comment in set pc:

    cpu->env.pc_w = value / 2; /* internally PC points to words */

so it makes sense I guess but I didn't pick it up from the name. Maybe worth adding the comment in CPUAVRstate?

Anyway:

Quoted 3 lines
target/avr/cpu.c +0 -0
     qemu_fprintf(f, "SP:      %04x\n", env->sp);
     qemu_fprintf(f, "rampD:     %02x\n", env->rampD >> 16);
     qemu_fprintf(f, "rampX:     %02x\n", env->rampX >> 16);
Signature · 1 line
Alex Bennée
#5 lore raw

RFC PATCH 3/3 target/avr: Fix SBRC/SBRS instructions

In reply to Philippe Mathieu-Daudé

SBRC/SBRS instructions seem to be inverted.

---
 target/avr/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/avr/translate.c +2 -2
index fe03e676df..2f77fe3ba7 100644
@@ -1385,7 +1385,7 @@ static bool trans_SBRC(DisasContext *ctx, arg_SBRC *a)
 {
     TCGv Rr = cpu_r[a->rr];
 
-    ctx->skip_cond = TCG_COND_EQ;
+    ctx->skip_cond = TCG_COND_NE;
     ctx->skip_var0 = tcg_temp_new();
     ctx->free_skip_var0 = true;
 
@@ -1401,7 +1401,7 @@ static bool trans_SBRS(DisasContext *ctx, arg_SBRS *a)
 {
     TCGv Rr = cpu_r[a->rr];
 
-    ctx->skip_cond = TCG_COND_NE;
+    ctx->skip_cond = TCG_COND_EQ;
     ctx->skip_var0 = tcg_temp_new();
     ctx->free_skip_var0 = true;
 
Signature · 1 line
2.21.3
#6 lore raw

Re: [RFC PATCH 3/3] target/avr: Fix SBRC/SBRS instructions

Quoted 1 line · Philippe Mathieu-Daudé

SBRC/SBRS instructions seem to be inverted.

I'm having trouble following exactly how the skip logic is meant to work. Intuitively I would expect a skip if clear to be TCG_COND_EQ because that is true if bit & mask is compared to 0 but it's not clear that what happens.

It would be easier if we actually had some instruction tests. I see gcc-avr is a thing.

Quoted 27 lines
---
 target/avr/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/avr/translate.c +2 -2
index fe03e676df..2f77fe3ba7 100644
@@ -1385,7 +1385,7 @@ static bool trans_SBRC(DisasContext *ctx, arg_SBRC *a)
 {
     TCGv Rr = cpu_r[a->rr];
 
-    ctx->skip_cond = TCG_COND_EQ;
+    ctx->skip_cond = TCG_COND_NE;
     ctx->skip_var0 = tcg_temp_new();
     ctx->free_skip_var0 = true;
 
@@ -1401,7 +1401,7 @@ static bool trans_SBRS(DisasContext *ctx, arg_SBRS *a)
 {
     TCGv Rr = cpu_r[a->rr];
 
-    ctx->skip_cond = TCG_COND_NE;
+    ctx->skip_cond = TCG_COND_EQ;
     ctx->skip_var0 = tcg_temp_new();
     ctx->free_skip_var0 = true;
Signature · 1 line
Alex Bennée