Skip to contentSkip to conversation

target/avr: Few fixes

PATCH In review Philippe Mathieu-Daudé 3 participants 14 messages Jul 7, 2020 – Jul 10, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover target/avr: Few fixes

Since v1:
- added missing 'Fix store instructions display order'

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é (4):
target/avr/cpu: Drop tlb_flush() in avr_cpu_reset() target/avr/cpu: Fix $PC displayed address target/avr/disas: Fix store instructions display order target/avr/translate: Fix SBRC/SBRS instructions

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

PATCH v2 1/4 target/avr/cpu: 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 v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] target/avr/cpu: Drop tlb_flush() in avr_cpu_reset()

Am Tue, 7 Jul 2020 09:00:18 +0200
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 20 lines

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
Quoted 1 line

*info)

#4 lore raw

PATCH v2 2/4 target/avr/cpu: 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 v2 2/4
#5 lore raw

Re: [PATCH v2 2/4] target/avr/cpu: Fix $PC displayed address

Am Tue, 7 Jul 2020 09:00:19 +0200
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 14 lines

$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 · line 157

Quoted 8 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);
     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);
Reviewed-by on v2 2/4
#6 lore raw

Re: [PATCH v2 2/4] target/avr/cpu: Fix $PC displayed address

In reply to Philippe Mathieu-Daudé
Quoted 8 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(-)

r~

#7 lore raw

PATCH v2 3/4 target/avr/disas: Fix store instructions display order

In reply to Philippe Mathieu-Daudé

While LOAD instructions use the target register as first argument, STORE instructions use it as second argument:

LD Rd, X // Rd <- (X)

ST Y, Rd // (Y) <- Rr

---
 target/avr/disas.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
target/avr/disas.c +10 -10
index 23bd9919ed..7fa6e8711b 100644
@@ -196,16 +196,16 @@ INSN(LDZ2,   "r%d, Z+", a->rd)
 INSN(LDZ3,   "r%d, -Z", a->rd)
 INSN(LDDY,   "r%d, Y+%d", a->rd, a->imm)
 INSN(LDDZ,   "r%d, Z+%d", a->rd, a->imm)
-INSN(STS,    "r%d, %d", a->rd, a->imm)
-INSN(STX1,   "r%d, X", a->rr)
-INSN(STX2,   "r%d, X+", a->rr)
-INSN(STX3,   "r%d, -X", a->rr)
-INSN(STY2,   "r%d, Y+", a->rd)
-INSN(STY3,   "r%d, -Y", a->rd)
-INSN(STZ2,   "r%d, Z+", a->rd)
-INSN(STZ3,   "r%d, -Z", a->rd)
-INSN(STDY,   "r%d, Y+%d", a->rd, a->imm)
-INSN(STDZ,   "r%d, Z+%d", a->rd, a->imm)
+INSN(STS,    "%d, r%d", a->imm, a->rd)
+INSN(STX1,   "X, r%d", a->rr)
+INSN(STX2,   "X+, r%d", a->rr)
+INSN(STX3,   "-X, r%d", a->rr)
+INSN(STY2,   "Y+, r%d", a->rd)
+INSN(STY3,   "-Y, r%d", a->rd)
+INSN(STZ2,   "Z+, r%d", a->rd)
+INSN(STZ3,   "-Z, r%d", a->rd)
+INSN(STDY,   "Y+%d, r%d", a->imm, a->rd)
+INSN(STDZ,   "Z+%d, r%d", a->imm, a->rd)
 INSN(LPM1,   "")
 INSN(LPM2,   "r%d, Z", a->rd)
 INSN(LPMX,   "r%d, Z+", a->rd)
Signature · 1 line
2.21.3
Reviewed-by on v2 3/4
#8 lore raw

Re: [PATCH v2 3/4] target/avr/disas: Fix store instructions display order

Quoted 5 lines · Philippe Mathieu-Daudé

While LOAD instructions use the target register as first argument, STORE instructions use it as second argument:

LD Rd, X // Rd <- (X)

Quoted 7 lines

ST Y, Rd // (Y) <- Rr

---
 target/avr/disas.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

r~

#9 lore raw

RFC PATCH v2 4/4 target/avr/translate: 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
#10 lore raw

Re: [RFC PATCH v2 4/4] target/avr/translate: Fix SBRC/SBRS instructions

target/avr/translate.c static bool trans_SBRC(DisasContext *ctx, arg_SBRC *a) · line 1390

Quoted 8 lines · Philippe Mathieu-Daudé
target/avr/translate.c +1 -1
@@ -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;

This is wrong. The next line is

Review static bool trans_SBRC(DisasContext *ctx, arg_SBRC *a) · line 1391

Quoted 1 line
(quoted diff) +0 -0
    tcg_gen_andi_tl(ctx->skip_var0, Rr, 1 << a->bit);

So we compute "var = R & bit", which should be zero for "Skip if Bit in Register Clear". Thus "var EQ 0" is the correct test.

target/avr/translate.c static bool trans_SBRS(DisasContext *ctx, arg_SBRS *a) · line 1406

Quoted 8 lines
target/avr/translate.c +1 -1
@@ -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;

Similarly this is "var NE 0".

r~

#11 lore raw

Re: [RFC PATCH v2 4/4] target/avr/translate: Fix SBRC/SBRS instructions

Quoted 12 lines · Richard Henderson

target/avr/translate.c static bool trans_SBRC(DisasContext *ctx, arg_SBRC *a) · line 1390

Quoted 8 lines · Philippe Mathieu-Daudé
target/avr/translate.c +1 -1
@@ -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;

This is wrong. The next line is

Quoted 4 lines

Review static bool trans_SBRC(DisasContext *ctx, arg_SBRC *a) · line 1391

Quoted 1 line
(quoted diff) +0 -0
    tcg_gen_andi_tl(ctx->skip_var0, Rr, 1 << a->bit);

So we compute "var = R & bit", which should be zero for "Skip if Bit in Register Clear". Thus "var EQ 0" is the correct test.

Thanks for verifying. If TCG is correct, then some hardware register might have a bit flipped.

I couldn't run Sarah's test suite on Fedora 30:

/usr/lib/gcc/avr/9.2.0/../../../../avr/bin/ld: cannot find crtatmega2560.o: No such file or directory /usr/lib/gcc/avr/9.2.0/../../../../avr/bin/ld: cannot find -lm /usr/lib/gcc/avr/9.2.0/../../../../avr/bin/ld: cannot find -lc /usr/lib/gcc/avr/9.2.0/../../../../avr/bin/ld: cannot find -latmega2560
collect2: error: ld returned 1 exit status

I'll try on some Debian based host.

Quoted 11 lines

target/avr/translate.c static bool trans_SBRS(DisasContext *ctx, arg_SBRS *a) · line 1406

Quoted 9 lines
target/avr/translate.c +1 -1
@@ -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;

Similarly this is "var NE 0".

#12 lore raw

Re: [RFC PATCH v2 4/4] target/avr/translate: Fix SBRC/SBRS instructions

Quoted 10 lines · Philippe Mathieu-Daudé

I couldn't run Sarah's test suite on Fedora 30:

/usr/lib/gcc/avr/9.2.0/../../../../avr/bin/ld: cannot find crtatmega2560.o: No such file or directory /usr/lib/gcc/avr/9.2.0/../../../../avr/bin/ld: cannot find -lm /usr/lib/gcc/avr/9.2.0/../../../../avr/bin/ld: cannot find -lc /usr/lib/gcc/avr/9.2.0/../../../../avr/bin/ld: cannot find -latmega2560
collect2: error: ld returned 1 exit status

I'll try on some Debian based host.

I believe the debian avr-libc package will have those, and should be pulled in by gcc-avr.

r~

#13 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Since v1:
- added missing 'Fix store instructions display order'

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]>

Quoted 5 lines

Philippe Mathieu-Daudé (4):
target/avr/cpu: Drop tlb_flush() in avr_cpu_reset() target/avr/cpu: Fix $PC displayed address target/avr/disas: Fix store instructions display order target/avr/translate: Fix SBRC/SBRS instructions

Thanks for the reviews, I am queuing the patches 1-3 and will send a pull request for the AVR port shortly.

Regards,

Phil.