Skip to contentSkip to conversation

Fixes for target/m68k

PATCH Superseded Laurent Vivier 3 participants 14 messages Jan 13, 2017

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fixes for target/m68k

This is a series of fixes for target/m68k found:
- with RISU (bit operation with immediate)
- while debugging package build under chroot
(gen_flush_flags() and CAS address modes)
- while I was working on the softmmu mode
(CAS alignment and SP address modes)

v2:
- Don't align stack access on coldfire.

Laurent Vivier (5):
target-m68k: fix bit operation with immediate value
target-m68k: fix gen_flush_flags()
target-m68k: manage pre-dec et post-inc in CAS
target-m68k: CAS doesn't need aligned access
target-m68k: increment/decrement with SP

 target/m68k/translate.c | 40 +++++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/5 target-m68k: fix bit operation with immediate value

M680x0 bit operations with an immediate value use 9 bits of the 16bit value, while coldfire ones use only 8 bits.

---
 target/m68k/translate.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
target/m68k/translate.c +10 -3
index 5f7357e..410f56a 100644
@@ -1801,9 +1801,16 @@ DISAS_INSN(bitop_im)
     op = (insn >> 6) & 3;
 
     bitnum = read_im16(env, s);
-    if (bitnum & 0xff00) {
-        disas_undef(env, s, insn);
-        return;
+    if (m68k_feature(s->env, M68K_FEATURE_M68000)) {
+        if (bitnum & 0xfe00) {
+            disas_undef(env, s, insn);
+            return;
+        }
+    } else {
+        if (bitnum & 0xff00) {
+            disas_undef(env, s, insn);
+            return;
+        }
     }
 
     SRC_EA(env, src1, opsize, 0, op ? &addr: NULL);
Signature · 1 line
2.7.4
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/5] target-m68k: fix bit operation with immediate value

Quoted 2 lines · Laurent Vivier

M680x0 bit operations with an immediate value use 9 bits of the 16bit value, while coldfire ones use only 8 bits.

I don't see that in the reference manual. Where do you get this from?

r~

#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/5] target-m68k: fix bit operation with immediate value

Quoted 5 lines · Richard Henderson
Quoted 2 lines · Laurent Vivier

M680x0 bit operations with an immediate value use 9 bits of the 16bit value, while coldfire ones use only 8 bits.

I don't see that in the reference manual. Where do you get this from?

See "BSET Instruction Format:BIT NUMBER STATIC, SPECIFIED AS IMMEDIATE DATA", p. 4.58 of "M68000 FAMILY PROGRAMMER’S REFERENCE MANUAL", "BIT NUMBER" is bits 0 to 8 of extended word.

See "Test a Bit and Set", p. 4-22 of "ColdFire Family Programmer’s Reference Manual, Rev. 3" (link given by Thomas), "Bit Number" is bits 0 to 7 of extended word.

I've found the problem with RISU.

Thanks,
Laurent

Reviewed-by
#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/5] target-m68k: fix bit operation with immediate value

Quoted 3 lines · Laurent Vivier

See "BSET Instruction Format:BIT NUMBER STATIC, SPECIFIED AS IMMEDIATE DATA", p. 4.58 of "M68000 FAMILY PROGRAMMER’S REFERENCE MANUAL", "BIT NUMBER" is bits 0 to 8 of extended word.

Oops, yep. I misread that.

r~

#5 lore raw

PATCH v2 2/5 target-m68k: fix gen_flush_flags()

In reply to Laurent Vivier

gen_flush_flags() is setting unconditionally cc_op_synced to 1 and s->cc_op to CC_OP_FLAGS, whereas env->cc_op can be set to something else by a previous tcg fragment.

We fix that by not setting cc_op_synced to 1 (except for gen_helper_flush_flags() that updates env->cc_op)

FIX: https://github.com/vivier/qemu-m68k/issues/19

---
 target/m68k/translate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/m68k/translate.c +2 -1
index 410f56a..0e97900 100644
@@ -595,18 +595,19 @@ static void gen_flush_flags(DisasContext *s)
 
     case CC_OP_DYNAMIC:
         gen_helper_flush_flags(cpu_env, QREG_CC_OP);
+        s->cc_op_synced = 1;
         break;
 
     default:
         t0 = tcg_const_i32(s->cc_op);
         gen_helper_flush_flags(cpu_env, t0);
         tcg_temp_free(t0);
+        s->cc_op_synced = 1;
         break;
     }
 
     /* Note that flush_flags also assigned to env->cc_op.  */
     s->cc_op = CC_OP_FLAGS;
-    s->cc_op_synced = 1;
 }
 
 static inline TCGv gen_extend(TCGv val, int opsize, int sign)
Signature · 1 line
2.7.4
Reviewed-by on v2 2/5
#6 lore raw

Re: [Qemu-devel] [PATCH v2 2/5] target-m68k: fix gen_flush_flags()

Quoted 7 lines · Laurent Vivier

gen_flush_flags() is setting unconditionally cc_op_synced to 1 and s->cc_op to CC_OP_FLAGS, whereas env->cc_op can be set to something else by a previous tcg fragment.

We fix that by not setting cc_op_synced to 1 (except for gen_helper_flush_flags() that updates env->cc_op)

Quoted 6 lines

FIX: https://github.com/vivier/qemu-m68k/issues/19

---
 target/m68k/translate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

r~

#7 lore raw

PATCH v2 3/5 target-m68k: manage pre-dec et post-inc in CAS

In reply to Laurent Vivier

In these cases we must update the address register after the operation.

---
 target/m68k/translate.c | 9 +++++++++
 1 file changed, 9 insertions(+)
target/m68k/translate.c +9 -0
index 0e97900..23e2b06 100644
@@ -1963,6 +1963,15 @@ DISAS_INSN(cas)
     gen_partset_reg(opsize, DREG(ext, 0), load);
 
     tcg_temp_free(load);
+
+    switch (extract32(insn, 3, 3)) {
+    case 3: /* Indirect postincrement.  */
+        tcg_gen_addi_i32(AREG(insn, 0), addr, opsize_bytes(opsize));
+        break;
+    case 4: /* Indirect predecrememnt.  */
+        tcg_gen_mov_i32(AREG(insn, 0), addr);
+        break;
+    }
 }
 
 DISAS_INSN(cas2w)
Signature · 1 line
2.7.4
#9 lore raw

PATCH v2 4/5 target-m68k: CAS doesn't need aligned access

In reply to Laurent Vivier
---
 target/m68k/translate.c | 1 -
 1 file changed, 1 deletion(-)
target/m68k/translate.c +0 -1
index 23e2b06..cf5d8dd 100644
@@ -1934,7 +1934,6 @@ DISAS_INSN(cas)
     default:
         g_assert_not_reached();
     }
-    opc |= MO_ALIGN;
 
     ext = read_im16(env, s);
 
Signature · 1 line
2.7.4
#11 lore raw

PATCH v2 5/5 target-m68k: increment/decrement with SP

In reply to Laurent Vivier

On 680x0 family only.

Address Register indirect With postincrement:

When using the stack pointer (A7) with byte size data, the register is incremented by two.

Address Register indirect With predecrement:

When using the stack pointer (A7) with byte size data, the register is decremented by two.

---
 target/m68k/translate.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
target/m68k/translate.c +12 -2
index cf5d8dd..727c189 100644
@@ -725,7 +725,12 @@ static TCGv gen_lea_mode(CPUM68KState *env, DisasContext *s,
         }
         reg = get_areg(s, reg0);
         tmp = tcg_temp_new();
-        tcg_gen_subi_i32(tmp, reg, opsize_bytes(opsize));
+        if (reg0 == 7 && opsize == OS_BYTE &&
+            m68k_feature(s->env, M68K_FEATURE_M68000)) {
+            tcg_gen_subi_i32(tmp, reg, 2);
+        } else {
+            tcg_gen_subi_i32(tmp, reg, opsize_bytes(opsize));
+        }
         return tmp;
     case 5: /* Indirect displacement.  */
         reg = get_areg(s, reg0);
@@ -801,7 +806,12 @@ static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0,
         result = gen_ldst(s, opsize, reg, val, what);
         if (what == EA_STORE || !addrp) {
             TCGv tmp = tcg_temp_new();
-            tcg_gen_addi_i32(tmp, reg, opsize_bytes(opsize));
+            if (reg0 == 7 && opsize == OS_BYTE &&
+                m68k_feature(s->env, M68K_FEATURE_M68000)) {
+                tcg_gen_subi_i32(tmp, reg, 2);
+            } else {
+                tcg_gen_addi_i32(tmp, reg, opsize_bytes(opsize));
+            }
             delay_set_areg(s, reg0, tmp, true);
         }
         return result;
Signature · 1 line
2.7.4
Reviewed-by on v2 5/5
#12 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] target-m68k: increment/decrement with SP

Quoted 40 lines · Laurent Vivier

On 680x0 family only.

Address Register indirect With postincrement:

When using the stack pointer (A7) with byte size data, the register is incremented by two.

Address Register indirect With predecrement:

When using the stack pointer (A7) with byte size data, the register is decremented by two.

---
 target/m68k/translate.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
target/m68k/translate.c +6 -1
index cf5d8dd..727c189 100644
@@ -725,7 +725,12 @@ static TCGv gen_lea_mode(CPUM68KState *env, DisasContext *s,
         }
         reg = get_areg(s, reg0);
         tmp = tcg_temp_new();
-        tcg_gen_subi_i32(tmp, reg, opsize_bytes(opsize));
+        if (reg0 == 7 && opsize == OS_BYTE &&
+            m68k_feature(s->env, M68K_FEATURE_M68000)) {
+            tcg_gen_subi_i32(tmp, reg, 2);
+        } else {
+            tcg_gen_subi_i32(tmp, reg, opsize_bytes(opsize));
+        }
         return tmp;
     case 5: /* Indirect displacement.  */
         reg = get_areg(s, reg0);
@@ -801,7 +806,12 @@ static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0,
         result = gen_ldst(s, opsize, reg, val, what);
         if (what == EA_STORE || !addrp) {
             TCGv tmp = tcg_temp_new();

target/m68k/translate.c static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0, · line 817

Quoted 10 lines
target/m68k/translate.c +6 -1
-            tcg_gen_addi_i32(tmp, reg, opsize_bytes(opsize));
+            if (reg0 == 7 && opsize == OS_BYTE &&
+                m68k_feature(s->env, M68K_FEATURE_M68000)) {
+                tcg_gen_subi_i32(tmp, reg, 2);
+            } else {
+                tcg_gen_addi_i32(tmp, reg, opsize_bytes(opsize));
+            }
             delay_set_areg(s, reg0, tmp, true);
         }
         return result;
#13 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] target-m68k: increment/decrement with SP

In reply to Laurent Vivier

target/m68k/translate.c static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0, · line 814

Quoted 6 lines · Laurent Vivier
target/m68k/translate.c +6 -0
+            if (reg0 == 7 && opsize == OS_BYTE &&
+                m68k_feature(s->env, M68K_FEATURE_M68000)) {
+                tcg_gen_subi_i32(tmp, reg, 2);
+            } else {
+                tcg_gen_addi_i32(tmp, reg, opsize_bytes(opsize));
+            }

post-increment add.

r~