Skip to contentSkip to conversation

Fixes for target/m68k

PATCH Superseded Laurent Vivier 2 participants 8 messages Jan 12, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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)

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 | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 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

PATCH 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
#3 lore raw

PATCH 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
#4 lore raw

PATCH 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
#5 lore raw

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

In reply to Laurent Vivier

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 | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
target/m68k/translate.c +8 -2
index cf5d8dd..c83d902 100644
@@ -725,7 +725,10 @@ 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));
+        tcg_gen_subi_i32(tmp, reg,
+                         reg0 == 7 && opsize == OS_BYTE
+                         ? 2
+                         : opsize_bytes(opsize));
         return tmp;
     case 5: /* Indirect displacement.  */
         reg = get_areg(s, reg0);
@@ -801,7 +804,10 @@ 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));
+            tcg_gen_addi_i32(tmp, reg,
+                             reg0 == 7 && opsize == OS_BYTE
+                             ? 2
+                             : opsize_bytes(opsize));
             delay_set_areg(s, reg0, tmp, true);
         }
         return result;
Signature · 1 line
2.7.4
#6 lore raw

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

Quoted 9 lines · Laurent Vivier

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.

I think this is only valid for the full 680x0 CPUs. According to
http://www.nxp.com/assets/documents/data/en/reference-manuals/CFPRM.pdf
the stack pointer behaves differently on ColdFire:

"2.2.5 Address Register Indirect with Predecrement Mode [...] Note that the stack pointer (A7) is treated just like the other address registers."

Thomas

#7 lore raw

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

Quoted 11 lines · Thomas Huth
Quoted 9 lines · Laurent Vivier

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.

Quoted 7 lines

I think this is only valid for the full 680x0 CPUs. According to
http://www.nxp.com/assets/documents/data/en/reference-manuals/CFPRM.pdf
the stack pointer behaves differently on ColdFire:

"2.2.5 Address Register Indirect with Predecrement Mode [...] Note that the stack pointer (A7) is treated just like the other address registers."

Yes, you're right. This is true only for 680x0:

"MOTOROLA M68000 FAMILY Programmer’s Reference Manual"

"2.2.5 Address Register Indirect with Predecrement Mode
...
If the address register is thestack pointer and the operand size is byte, the address is decremented by two to keep the stack pointer aligned to a word boundary."

Thank you, I will update this patch accordingly.

Laurent