qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: schwab@linux-m68k.org, agraf@suse.de,
	Richard Henderson <rth@twiddle.net>,
	gerg@uclinux.org, Laurent Vivier <laurent@vivier.eu>
Subject: [Qemu-devel] [PATCH v2 2/3] target-m68k: implement 680x0 movem
Date: Wed,  2 Nov 2016 22:15:18 +0100	[thread overview]
Message-ID: <1478121319-31986-3-git-send-email-laurent@vivier.eu> (raw)
In-Reply-To: <1478121319-31986-1-git-send-email-laurent@vivier.eu>

680x0 movem can load/store words and long words
and can use more addressing modes.
Coldfire can only use long words with (Ax) and (d16,Ax)
addressing modes.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 target-m68k/translate.c | 96 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 79 insertions(+), 17 deletions(-)

diff --git a/target-m68k/translate.c b/target-m68k/translate.c
index 1cf88a4..93f1270 100644
--- a/target-m68k/translate.c
+++ b/target-m68k/translate.c
@@ -1667,14 +1667,25 @@ static void gen_push(DisasContext *s, TCGv val)
     tcg_gen_mov_i32(QREG_SP, tmp);
 }
 
+static TCGv mreg(int reg)
+{
+    if (reg < 8) {
+        /* Dx */
+        return cpu_dregs[reg];
+    }
+    /* Ax */
+    return cpu_aregs[reg & 7];
+}
+
 DISAS_INSN(movem)
 {
     TCGv addr;
     int i;
     uint16_t mask;
-    TCGv reg;
     TCGv tmp;
-    int is_load;
+    int is_load = (insn & 0x0400) != 0;
+    int opsize = (insn & 0x40) != 0 ? OS_LONG : OS_WORD;
+    TCGv incr;
 
     mask = read_im16(env, s);
     tmp = gen_lea(env, s, insn, OS_LONG);
@@ -1682,25 +1693,74 @@ DISAS_INSN(movem)
         gen_addr_fault(s);
         return;
     }
+
     addr = tcg_temp_new();
     tcg_gen_mov_i32(addr, tmp);
-    is_load = ((insn & 0x0400) != 0);
-    for (i = 0; i < 16; i++, mask >>= 1) {
-        if (mask & 1) {
-            if (i < 8)
-                reg = DREG(i, 0);
-            else
-                reg = AREG(i, 0);
-            if (is_load) {
-                tmp = gen_load(s, OS_LONG, addr, 0);
-                tcg_gen_mov_i32(reg, tmp);
-            } else {
-                gen_store(s, OS_LONG, addr, reg);
+    incr = tcg_const_i32(opsize_bytes(opsize));
+
+    if (is_load) {
+        /* memory to register */
+        TCGv r[16];
+        for (i = 0; i < 16; i++) {
+            if ((mask >> i) & 1) {
+                r[i] = gen_load(s, opsize, addr, 1);
+                tcg_gen_add_i32(addr, addr, incr);
+            }
+        }
+        for (i = 0; i < 16; i++, mask >>= 1) {
+            if (mask & 1) {
+                tcg_gen_mov_i32(mreg(i), r[i]);
+                tcg_temp_free(r[i]);
+            }
+        }
+        if ((insn & 070) == 030) {
+            /* movem (An)+,X */
+            tcg_gen_mov_i32(AREG(insn, 0), addr);
+        }
+
+    } else {
+        /* register to memory */
+
+        if ((insn & 070) == 040) {
+            /* movem X,-(An) */
+
+            for (i = 15; i >= 0; i--, mask >>= 1) {
+                if (mask & 1) {
+                    if ((insn & 7) + 8 == i &&
+                        m68k_feature(s->env, M68K_FEATURE_EXT_FULL)) {
+                        /* M68020+: if the addressing register is the
+                         * register moved to memory, the value written
+                         * is the initial value decremented by the size of
+                         * the operation
+                         * M68000/M68010: the value is the initial value
+                         */
+                        TCGv tmp = tcg_temp_new();
+                        tcg_gen_sub_i32(tmp, mreg(i), incr);
+                        gen_store(s, opsize, addr, tmp);
+                        tcg_temp_free(tmp);
+                    } else {
+                        gen_store(s, opsize, addr, mreg(i));
+                    }
+                    if (mask != 1) {
+                        tcg_gen_sub_i32(addr, addr, incr);
+                    }
+                }
+            }
+            tcg_gen_mov_i32(AREG(insn, 0), addr);
+        } else {
+            /* movem X,(An)+ is not allowed */
+
+            for (i = 0; i < 16; i++, mask >>= 1) {
+                if (mask & 1) {
+                    gen_store(s, opsize, addr, mreg(i));
+                    tcg_gen_add_i32(addr, addr, incr);
+                }
             }
-            if (mask != 1)
-                tcg_gen_addi_i32(addr, addr, 4);
         }
     }
+
+    tcg_temp_free(incr);
+    tcg_temp_free(addr);
 }
 
 DISAS_INSN(bitop_im)
@@ -3858,7 +3918,9 @@ void register_m68k_insns (CPUM68KState *env)
     BASE(pea,       4840, ffc0);
     BASE(swap,      4840, fff8);
     INSN(bkpt,      4848, fff8, BKPT);
-    BASE(movem,     48c0, fbc0);
+    INSN(movem,     48d0, fbf8, CF_ISA_A);
+    INSN(movem,     48e8, fbf8, CF_ISA_A);
+    INSN(movem,     4880, fb80, M68000);
     BASE(ext,       4880, fff8);
     BASE(ext,       48c0, fff8);
     BASE(ext,       49c0, fff8);
-- 
2.7.4

  parent reply	other threads:[~2016-11-02 21:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-02 21:15 [Qemu-devel] [PATCH v2 0/3] target-m68k: add movem, BCD and CAS instructions Laurent Vivier
2016-11-02 21:15 ` [Qemu-devel] [PATCH v2 1/3] target-m68k: add abcd/sbcd/nbcd Laurent Vivier
2016-11-03 16:16   ` Richard Henderson
2016-11-02 21:15 ` Laurent Vivier [this message]
2016-11-03 16:17   ` [Qemu-devel] [PATCH v2 2/3] target-m68k: implement 680x0 movem Richard Henderson
2016-11-03 19:47   ` Richard Henderson
2016-11-03 20:11     ` Laurent Vivier
2016-11-03 20:45       ` Richard Henderson
2016-11-03 20:47   ` Richard Henderson
2016-11-04  7:59     ` Laurent Vivier
2016-11-04 12:27       ` Richard Henderson
2016-11-02 21:15 ` [Qemu-devel] [PATCH v2 3/3] target-m68k: add cas/cas2 ops Laurent Vivier
2016-11-03 16:36   ` Richard Henderson
2016-11-03 18:03     ` Laurent Vivier
2016-11-03 19:20       ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478121319-31986-3-git-send-email-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=agraf@suse.de \
    --cc=gerg@uclinux.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).