aboutsummaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
authorSteve Chamberlain <sac@cygnus>1993-01-03 22:19:42 +0000
committerSteve Chamberlain <sac@cygnus>1993-01-03 22:19:42 +0000
commit191395156c25bce7915660307c78708269ff6c0f (patch)
tree997093535ad84b69b1ea353ea1d6b6b1085229ae /sim
parent1188fbbf2762a9692c6f4756d2c8984c01c4fa23 (diff)
downloadgdb-191395156c25bce7915660307c78708269ff6c0f.zip
gdb-191395156c25bce7915660307c78708269ff6c0f.tar.gz
gdb-191395156c25bce7915660307c78708269ff6c0f.tar.bz2
* p1.c, p3.c, run.c, writecode.c: all used h8/300 opcodes in and
running
Diffstat (limited to 'sim')
-rw-r--r--sim/h8300/.Sanitize2
-rw-r--r--sim/h8300/ChangeLog5
-rw-r--r--sim/h8300/Makefile.in6
-rw-r--r--sim/h8300/p1.c228
-rw-r--r--sim/h8300/p3.c45
-rw-r--r--sim/h8300/run.c4
-rw-r--r--sim/h8300/writecode.c1472
7 files changed, 774 insertions, 988 deletions
diff --git a/sim/h8300/.Sanitize b/sim/h8300/.Sanitize
index 9fef135..7ba3633 100644
--- a/sim/h8300/.Sanitize
+++ b/sim/h8300/.Sanitize
@@ -32,6 +32,8 @@ Makefile.in
configure.in
writecode.c
run.c
+p1.c
+p3.c
Do-last:
diff --git a/sim/h8300/ChangeLog b/sim/h8300/ChangeLog
index 8462c6a..c028b42 100644
--- a/sim/h8300/ChangeLog
+++ b/sim/h8300/ChangeLog
@@ -1,3 +1,8 @@
+Sun Jan 3 14:15:07 1993 Steve Chamberlain (sac@thepub.cygnus.com)
+
+ * p1.c, p3.c, run.c, writecode.c: all used h8/300 opcodes in and
+ running
+
Tue Dec 22 13:56:48 1992 Steve Chamberlain (sac@thepub.cygnus.com)
* new
diff --git a/sim/h8300/Makefile.in b/sim/h8300/Makefile.in
index c768932..b84792d 100644
--- a/sim/h8300/Makefile.in
+++ b/sim/h8300/Makefile.in
@@ -53,8 +53,8 @@ BISON = bison
MAKEINFO = makeinfo
RANLIB = ranlib
-INCDIR = $(srcdir)/../include
-CSEARCH = -I. -I$(srcdir) -I$(INCDIR)
+INCDIR = $(srcdir)/../include
+CSEARCH = -I. -I$(srcdir) -I$(INCDIR) -I$(srcdir)/../bfd
DEP = mkdep
@@ -74,7 +74,7 @@ p2.c:writecode
writecode:writecode.o
writecode.o:writecode.c
- $(CC) -g -I$(INCDIR) -c writecode.c
+ $(CC) -g $(CSEARCH) -c writecode.c
diff --git a/sim/h8300/p1.c b/sim/h8300/p1.c
new file mode 100644
index 0000000..1193e9b
--- /dev/null
+++ b/sim/h8300/p1.c
@@ -0,0 +1,228 @@
+/* H8/300 simulator
+ Copyright 1992 Free Software Foundation, Inc.
+
+ Contributed by Cygnus Support.
+ Written by Steve Chamberlain (sac@cygnus.com).
+
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#define SET_WORD_MEM(x,y) {mem[x] = (y)>>8;mem[x+1] = y;}
+#define SET_BYTE_MEM(x,y) mem[x]=y
+
+#define WORD_MEM(x) ((mem[x]<<8) | (mem[x+1]))
+#define BYTE_MEM(x) mem[x]
+
+
+#define PC 9
+#define CCR 8
+
+struct state
+{
+ int cycles;
+ unsigned short int reg[10];
+ unsigned char *(bregp[16]);
+ unsigned char *(bregp_NNNNxxxx[256]);
+ unsigned char *(bregp_xxxxNNNN[256]);
+ unsigned short int *(wregp_xNNNxxxx[256]);
+ unsigned short int *(wregp_xxxxxNNN[256]);
+}
+
+saved_state;
+
+#define V (v!=0)
+#define C (c!=0)
+#define N (n!=0)
+#define Z (z!=0)
+
+#define SET_CCR(x) n = x & 0x8; v = x & 0x2; z = x & 0x4; c = x & 0x1;
+#define GET_CCR() ((N << 3) | (Z<<2) | (V<<1) | C)
+
+int exception;
+
+static unsigned char *mem;
+
+void
+control_c (sig, code, scp, addr)
+ int sig;
+ int code;
+ char *scp;
+ char *addr;
+{
+ exception = SIGINT;
+}
+
+void
+sim_store_register (reg, val)
+int reg;
+int val;
+{
+ saved_state.reg[reg] = val;
+}
+
+void
+sim_fetch_register (reg, buf)
+int reg;
+char *buf;
+{
+ buf[0] = saved_state.reg[reg] >> 8;
+ buf[1] = saved_state.reg[reg];
+}
+
+static union
+{
+ short int i;
+ struct
+ {
+ char low;
+ char high;
+ }
+
+ u;
+}
+
+littleendian;
+
+static void
+meminit ()
+{
+ if (!mem)
+ {
+ int tmp;
+
+ mem = calloc (1024, 64);
+ littleendian.i = 1;
+
+ /* initialze the array of pointers to byte registers */
+ for (tmp = 0; tmp < 8; tmp++)
+ {
+ if (littleendian.u.high)
+ {
+ saved_state.bregp[tmp] = (unsigned char *) (saved_state.reg + tmp);
+ saved_state.bregp[tmp + 8] = saved_state.bregp[tmp] + 1;
+ }
+ else
+ {
+ saved_state.bregp[tmp + 8] = (unsigned char *) (saved_state.reg + tmp);
+ saved_state.bregp[tmp] = saved_state.bregp[tmp + 8] + 1;
+ }
+ }
+
+ /* we keep two 256 sized pointers to byte regs, one for when we
+ want to look at the reg descibed by bits NNNNxxxx and one for
+ when we want to look at xxxxNNNN */
+ for (tmp = 0; tmp < 256; tmp++)
+ {
+ saved_state.bregp_NNNNxxxx[tmp] = saved_state.bregp[(tmp >> 4) & 0xf];
+ saved_state.bregp_xxxxNNNN[tmp] = saved_state.bregp[tmp & 0xf];
+ }
+ /* We keep two 256 sized pointers to word regs, one for regs in
+ xNNNxxxx and one for regs in xxxxxNNNN */
+ for (tmp = 0; tmp < 256; tmp++)
+ {
+ saved_state.wregp_xNNNxxxx[tmp] = &saved_state.reg[(tmp >> 4) & 0x7];
+ saved_state.wregp_xxxxxNNN[tmp] = &saved_state.reg[tmp & 0x7];
+ }
+
+ }
+}
+
+void
+sim_write (to, from, len)
+ int to;
+ char *from;
+ int len;
+{
+ meminit ();
+ memcpy (mem + to, from, len);
+}
+
+void
+sim_read (from, to, len)
+ int from;
+ char *to;
+
+ int len;
+{
+ meminit ();
+ memcpy (to, mem + from, len);
+}
+
+int
+sim_stop_signal ()
+{
+ return exception;
+}
+
+void
+sim_resume (step, sig)
+int step;
+int sig;
+{
+ int lval;
+ int tmp;
+ int b0;
+ int b1;
+ unsigned char **blow;
+ unsigned char **bhigh;
+ unsigned short **wlow;
+ unsigned short **whigh;
+ unsigned char *npc;
+ int rn;
+ unsigned short int *reg;
+ unsigned char **bregp;
+ void (*prev) ();
+ unsigned char *pc;
+
+ int srca;
+ int srcb;
+ int dst;
+ int cycles = saved_state.cycles;
+
+ int n;
+ int v;
+ int z;
+ int c;
+
+ SET_CCR (saved_state.reg[CCR]);
+ pc = saved_state.reg[PC] + mem;
+
+ reg = saved_state.reg;
+ bregp = saved_state.bregp;
+ blow = saved_state.bregp_xxxxNNNN;
+ bhigh = saved_state.bregp_NNNNxxxx;
+
+ wlow = saved_state.wregp_xxxxxNNN;
+ whigh = saved_state.wregp_xNNNxxxx;
+
+ prev = signal (SIGINT, control_c);
+ meminit();
+ if (step)
+ exception = SIGTRAP;
+ else
+ {
+ exception = sig;
+ }
+ do
+ {
+ dst = 0xfeedface;
+ b0 = pc[0];
+ b1 = pc[1];
+
+
diff --git a/sim/h8300/p3.c b/sim/h8300/p3.c
new file mode 100644
index 0000000..7d4d481
--- /dev/null
+++ b/sim/h8300/p3.c
@@ -0,0 +1,45 @@
+ movflags8:
+if (dst == 0xfeedface) abort();
+ n = dst & 0x80;
+ z = !(dst & 0xff);
+ v = 0;
+goto next;
+ movflags16:
+if (dst == 0xfeedface) abort();
+ n = dst & 0x8000;
+ z = !(dst & 0xffff);
+ v = 0;
+goto next;
+ aluflags8:
+if (dst == 0xfeedface) abort();
+ n = dst & 0x80;
+ z = !(dst & 0xff);
+ v = ((srca & 0x80) == (srcb & 0x80)) && ((srca & 0x80) != (dst & 0x80));
+ c = dst & 0x100;
+ goto next;
+ aluflags16:
+if (dst == 0xfeedface) abort();
+ n = dst & 0x8000;
+ z = !(dst & 0xffff);
+ v = ((srca & 0x8000) == (srcb & 0x8000)) && ((srca & 0x8000) != (dst & 0x8000));
+ c = dst & 0x10000;
+ goto next;
+ setflags:;
+SET_CCR(tmp);
+break;
+ logflags:
+ shiftflags:
+ v = 0;
+ incflags:
+if (dst == 0xfeedface) abort();
+ z = !(dst & 0xff);
+ n = dst & 0x80;
+goto next;
+ next: ;
+pc = npc;
+} while (!exception);
+
+saved_state.cycles = cycles;
+saved_state.reg[PC] = pc - mem;
+saved_state.reg[CCR] = GET_CCR();
+}
diff --git a/sim/h8300/run.c b/sim/h8300/run.c
index c42c8e7..1673227 100644
--- a/sim/h8300/run.c
+++ b/sim/h8300/run.c
@@ -57,7 +57,6 @@ char **av;
printf("run %s\n", name);
}
abfd = bfd_openr(name,"coff-h8300");
-
if (abfd) {
if (bfd_check_format(abfd, bfd_object))
@@ -71,7 +70,8 @@ char **av;
}
start_address = bfd_get_start_address(abfd);
- sim_store_register(start_address);
+ sim_store_register(
+ 9,start_address);
sim_resume(0,0);
return 0;
}
diff --git a/sim/h8300/writecode.c b/sim/h8300/writecode.c
index 77625cc..0f8408a 100644
--- a/sim/h8300/writecode.c
+++ b/sim/h8300/writecode.c
@@ -1,4 +1,4 @@
-/* BFD library support routines for the Hitachi H8/300 architecture.
+/* code generator for the Hitachi H8/300 architecture simulator.
Copyright (C) 1990-1991 Free Software Foundation, Inc.
Hacked by Steve Chamberlain of Cygnus Support.
@@ -18,8 +18,12 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include"bfd.h"
-#include"sysdep.h"
+/* This program reads the H8/300 opcode table and writes out
+ a large switch statement to understand the opcodes (with ifs if
+ there is more than one opcode per case) and code to do the stuff */
+
+#include "bfd.h"
+#include "sysdep.h"
#define DEFINE_TABLE
#define INSIM
@@ -30,13 +34,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#define PTWO 256
static struct h8_opcode *h8_opcodes_sorted[PTWO][MAXSAME];
-/* Run through the opcodes and sort them into order to make them easy
- to disassemble
- */
-
char *cs = "/*";
char *ce = "*/";
+/* How to get at nibble n from the instruction */
char *nibs[] =
{
"foo",
@@ -49,342 +50,103 @@ char *nibs[] =
"((pc[3])&0xf)",
0, 0};
-char *abs8[] =
-{
- "foo",
- "foo",
- "b1",
- "foo",
-};
+/* how to get at the 3 bit immediate in the instruction */
+char *imm3[] =
+{"foo",
+ "foo",
+ "((pc[1]>>4)&0x7)",
+ "foo",
+ "foo",
+ "foo",
+ "((pc[3]>>4)&0x7)"};
+
+/* How to get at a byte register from an index in the instruction at
+ nibble n */
+char *breg[] =
+{"foo",
+ "*(blow[b0])",
+ "*(bhigh[b1])",
+ "*(blow[b1])"};
+
+/* How to get at a word register from an index in the instruction at
+ nibble n */
+
+char *wreg[] =
+{"foo",
+ "*(wlow[b0])",
+ "*(whigh[b1])",
+ "*(wlow[b1])"};
#define sorted_key noperands
-char *abs16[] =
-{
- "foo",
- "foo",
- "foo",
- "foo",
- "(pc[2]<<8)|pc[3]",
- "foo",
- "foo",
- "foo",
-};
-char *empty="fake";
+/* sort the opcode table into h8_opcodes_sorted[0..255] */
+static void
init ()
{
unsigned int i;
struct h8_opcode *p;
for (p = h8_opcodes; p->name; p++)
- {
- int n1 = 0;
- int n2 = 0;
- int j;
- for (j = 0; p->data.nib[j] != E; j++)
- {
- if ((int)p->data.nib[j] == ABS16ORREL8SRC)
- p->data.nib[j] = ABS16SRC;
- if ((int)p->data.nib[j ] == ABS16OR8SRC)
- p->data.nib[j] = ABS16SRC;
- if ((int)p->data.nib[j] == ABS16OR8DST)
- p->data.nib[j] = ABS16DST;
- }
- /* Kill push and pop, they're duplicates */
- if (strcmp(p->name,"push")==0) {
- p->name = empty;
- }
- if (strcmp(p->name,"pop")==0) {
- p->name = empty;
- }
-
-
- if ((int) p->data.nib[0] < 16)
- {
- n1 = (int) p->data.nib[0];
- }
- else
- n1 = 0;
- if ((int) p->data.nib[1] < 16)
- {
- n2 = (int) p->data.nib[1];
- }
- else
- n2 = 0;
-#if 0
- if ((int) p->data.nib[2] < 16)
- {
- n3 = (int) p->data.nib[2];
- }
- else if ((int) p->data.nib[2] & B30)
- {
- n3 = 0;
- }
- else if ((int) p->data.nib[2] & B31)
- {
- n3 = 0x8;
- }
-
-
- if ((int) p->data.nib[3] < 16)
- {
- n4 = (int) p->data.nib[3];
- }
- else if ((int) p->data.nib[3] & B30)
- {
- n4 = 0;
- }
- else if ((int) p->data.nib[3] & B31)
- {
- n4 = 0x8;
- }
-#endif
- for (i = 0; i < MAXSAME; i++)
- {
- int j = /* ((n3 >> 3) * 512) + ((n4 >> 3) * 256) + */ n1 * 16 + n2;
-
- if (h8_opcodes_sorted[j][i] == (struct h8_opcode *) NULL)
- {
- h8_opcodes_sorted[j][i] = p;
- p->sorted_key = j;
- break;
- }
- }
-
- if (i == MAXSAME)
- abort ();
-
- /* Just make sure there are an even number of nibbles in it, and
- that the count is the same s the length */
- for (i = 0; p->data.nib[i] != E; i++)
- /*EMPTY*/ ;
- if (i & 1)
- abort ();
- p->length = i / 2;
- }
- for (i = 0; i < PTWO; i++)
- {
- if (h8_opcodes_sorted[i][0])
- p = h8_opcodes_sorted[i][0];
- else
- h8_opcodes_sorted[i][0] = p;
- }
-}
-
-unsigned int
-DEFUN (bfd_h8_disassemble, (addr, data, stream),
- bfd_vma addr AND
- CONST bfd_byte * data AND
- FILE * stream)
-{
- /* Find the first entry in the table for this opcode */
- CONST static char *regnames[] =
- {
- "r0h", "r1h", "r2h", "r3h", "r4h", "r5h", "r6h", "r7h",
- "r0l", "r1l", "r2l", "r3l", "r4l", "r5l", "r6l", "r7l"};
-
- int rs = 0;
- int rd = 0;
- int rdisp = 0;
- int abs = 0;
- struct h8_opcode **p = h8_opcodes_sorted[(unsigned) (data[0])];
- struct h8_opcode *q;
-
- /* Find the exact opcode/arg combo */
- while (*p)
{
- op_type *nib;
- unsigned int len = 0;
+ int n1 = 0;
+ int n2 = 0;
+ int j;
- q = *p++;
- nib = q->data.nib;
- while (*nib != E)
+ for (j = 0; p->data.nib[j] != E; j++)
+ {
+ if ((int) p->data.nib[j] == ABS16ORREL8SRC)
+ p->data.nib[j] = ABS16SRC;
+ if ((int) p->data.nib[j] == ABS16OR8SRC)
+ p->data.nib[j] = ABS16SRC;
+ if ((int) p->data.nib[j] == ABS16OR8DST)
+ p->data.nib[j] = ABS16DST;
+ }
+ if ((int) p->data.nib[0] < 16)
+ {
+ n1 = (int) p->data.nib[0];
+ }
+ else
+ n1 = 0;
+ if ((int) p->data.nib[1] < 16)
+ {
+ n2 = (int) p->data.nib[1];
+ }
+ else
+ n2 = 0;
+ for (i = 0; i < MAXSAME; i++)
{
- op_type looking_for = *nib;
- int thisnib = data[len >> 1];
+ int j = /* ((n3 >> 3) * 512) + ((n4 >> 3) * 256) + */ n1 * 16 + n2;
- thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib >> 4) & 0xf);
- if ((int) looking_for & (int) B31)
- {
- if (((int) thisnib & 0x8) == 0)
- goto fail;
- looking_for = (op_type) ((int) looking_for & ~(int) B31);
- }
- if ((int) looking_for & (int) B30)
- {
- if (((int) thisnib & 0x8) != 0)
- goto fail;
- looking_for = (op_type) ((int) looking_for & ~(int) B30);
- }
- switch (looking_for)
+ if (h8_opcodes_sorted[j][i] == (struct h8_opcode *) NULL)
{
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- if ((int) looking_for != thisnib)
- goto fail;
- break;
- case ABS16SRC:
- case ABS16OR8SRC:
- case ABS16ORREL8SRC:
- case ABS16DST:
- case ABS16OR8DST:
- case DISPSRC:
- case DISPDST:
- case IMM16:
- abs = (data[len >> 1]) * 256 + data[(len + 2) >> 1];
- len += 3;
- nib += 3;
- break;
- case DISPREG:
- rdisp = thisnib;
- break;
- case KBIT:
- abs = thisnib == 0x8 ? 2 : 1;
- break;
- case IMM8:
- case ABS8SRC:
- case ABS8DST:
- case MEMIND:
- case DISP8:
- abs = data[len >> 1];
- len++;
- nib++;
+ h8_opcodes_sorted[j][i] = p;
+ p->sorted_key = j;
break;
- case IMM3:
- abs = thisnib;
- break;
- case RS8:
- case RS16:
- case RSINC:
- case RSIND:
- rs = thisnib;
- break;
- case RD16:
- case RDDEC:
- case RD8:
- case RDIND:
- rd = thisnib;
- break;
- default:
- fprintf (stream, "Dont understand \n");
- goto found;
}
- len++;
- nib++;
}
- goto found;
- fail:
- ;
+ if (i == MAXSAME)
+ abort ();
+
+ /* Just make sure there are an even number of nibbles in it, and
+ that the count is the same s the length */
+ for (i = 0; p->data.nib[i] != E; i++)
+ /*EMPTY*/ ;
+ if (i & 1)
+ abort ();
+ p->length = i / 2;
+ }
+ for (i = 0; i < PTWO; i++)
+ {
+ if (h8_opcodes_sorted[i][0])
+ p = h8_opcodes_sorted[i][0];
+ else
+ h8_opcodes_sorted[i][0] = p;
}
- fprintf (stream, "%02x %02x .word\tH'%x,H'%x",
- data[0], data[1],
- data[0], data[1]);
- return 2;
-found:;
- {
- int i;
-
- for (i = 0; i < q->length; i++)
- {
- fprintf (stream, "%02x", data[i]);
- }
- for (; i < 6; i++)
- {
- fprintf (stream, " ");
- }
- }
- fprintf (stream, "%s\t", q->name);
- /* Now print out the args */
- {
- op_type *args = q->args.nib;
- int hadone = 0;
-
- while (*args != E)
- {
- if (hadone)
- fprintf (stream, ",");
- switch ((int) (*args) & ~((int) B30 | (int) B31))
- {
- case IMM16:
- case IMM8:
- case IMM3:
- fprintf (stream, "#0x%x", (unsigned) abs);
- break;
- case RD8:
- fprintf (stream, "%s", regnames[rd]);
- break;
- case RS8:
- fprintf (stream, "%s", regnames[rs]);
- break;
- case RD16:
- fprintf (stream, "r%d", rd & 0x7);
- break;
- case RS16:
- fprintf (stream, "r%d", rs & 0x7);
- break;
- case RSINC:
- fprintf (stream, "@r%d+", rs & 0x7);
- break;
- case RDDEC:
- fprintf (stream, "@-r%d", rd & 0x7);
- break;
- case RDIND:
- fprintf (stream, "@r%d", rd & 0x7);
- break;
- case RSIND:
- fprintf (stream, "@r%d", rs & 0x7);
- break;
- case ABS8SRC:
- case ABS16SRC:
- case ABS16OR8SRC:
- case ABS16ORREL8SRC:
- case ABS16OR8DST:
- case ABS16DST:
- case ABS8DST:
- fprintf (stream, "@0x%x", (unsigned) abs);
- break;
- case MEMIND:
- fprintf (stream, "@@%d (%x)", abs, abs);
- break;
- case DISP8:
- fprintf (stream, ".%s%d (%x)", (char) abs > 0 ? "+" : "", (char) abs,
- addr + (char) abs + 2);
- break;
- case DISPSRC:
- case DISPDST:
- fprintf (stream, "@(0x%x,r%d)", abs, rdisp & 0x7);
- break;
- case CCR:
- fprintf (stream, "ccr");
- break;
- case KBIT:
- fprintf (stream, "#%d", abs);
- break;
- default:
- abort ();
- }
- hadone = 1;
- args++;
- }
- }
- return q->length;
}
+/* either fetch srca&srcb or store dst */
+
void
decode (p, fetch, size)
struct h8_opcode *p;
@@ -395,399 +157,224 @@ decode (p, fetch, size)
char *ss = size == 8 ? "BYTE" : "WORD";
for (i = 0; p->data.nib[i] != E; i++)
- {
- switch (p->data.nib[i])
- {
- case RS8:
- if (fetch)
- printf ("srca = BYTE_REG(%s);\n", nibs[i]);
- break;
- case RS16 | B30:
- case RS16 | B31:
- case RS16:
- if (fetch)
- printf ("srca = WORD_REG(%s);\n", nibs[i]);
- break;
- case RD8:
- if (fetch)
- printf ("srcb = BYTE_REG(%s);\n", nibs[i]);
- else
- printf ("SET_BYTE_REG(%s,dst);\n", nibs[i]);
- break;
- case RD16 | B30:
- case RD16 | B31:
- case RD16:
- if (fetch)
- printf ("srcb = WORD_REG(%s);\n", nibs[i]);
- else
- printf ("SET_WORD_REG(%s,dst);\n", nibs[i]);
- break;
- case IMM8:
- if (fetch)
- printf ("srca = b1;\n", i);
- break;
- case RSINC:
- case RSINC | B30:
- case RSINC | B31:
-
- if (fetch)
- {
- printf("rn = %s &0x7;\n", nibs[i]);
- printf ("srca = %s_MEM(reg[rn]);\n", size == 8 ? "BYTE"
- : "WORD") ;
- printf("reg[rn]+=%d;\n", size/8);
- }
- break;
- case RSIND:
- case RSIND | B30:
- case RSIND | B31:
- if (fetch) {
- printf("lval = WORD_REG(%s);\n", nibs[i]);
- printf("srca = %s_MEM(lval);\n", ss);
- }
- break;
-
- case RDIND:
- case RDIND | B30:
- case RDIND | B31:
- if (fetch) {
- printf("rn = %s & 0x7;\n", nibs[i] );
- printf("lval = reg[rn];\n");
- printf("srcb = %s_MEM(lval);\n", size==8 ? "BYTE" : "WORD");
- }
- else
- {
- printf("SET_%s_MEM(lval,dst);\n",ss);
- }
- break;
-
- case MEMIND:
- if (fetch)
- {
- printf("lval = WORD_MEM(b1);\n");
- }
- break;
- case RDDEC:
- case RDDEC | B30:
- case RDDEC | B31:
- if (!fetch)
- {
- printf("rn = %s & 0x7;\n", nibs[i]);
- printf("reg[rn]-=%d;\n", size/8);
- printf ("SET_%s_MEM(reg[rn], dst);\n",
- size == 8 ? "BYTE" : "WORD");
- }
- break;
-
- case IMM16:
- if (fetch)
- printf ("srca =WORD_IMM;\n", i);
- break;
- case ABS8SRC:
- if (fetch) {
-
- printf("lval = (0xff00) + b1;\n");
- printf ("srca = BYTE_MEM(lval);\n");
- }
-
- break;
- case ABS8DST:
- if (fetch)
- {
- printf("lval = (0xff00) + b1;\n");
- printf ("srcb = BYTE_MEM(lval);\n");
- }
- else
- {
- printf ("SET_BYTE_MEM(lval,dst);\n");
- }
- break;
- case KBIT:
- if (fetch)
- printf ("srca = KBIT(%d);\n", i);
- break;
- case ABS16ORREL8SRC:
- case ABS16SRC:
- if (fetch)
- {
- printf("lval = ((pc[2] << 8) + pc[3]);\n");
- printf("srca = %s_MEM(lval);\n", size==8 ? "BYTE" : "WORD");
- }
- break;
- case DISPREG|B30:
- case DISPREG|B31:
- case DISPREG:
- printf("rn = %s & 0x7;\n", nibs[i]);
- break;
- case DISPSRC:
- if (fetch)
- {
- printf("lval = 0xffff&((pc[2] << 8) + pc[3] +reg[rn]);\n");
- printf("srca = %s_MEM(lval);\n", size == 8 ? "BYTE" : "WORD");
- }
- break;
- case DISPDST:
- if (fetch)
- {
- printf("lval = 0xffff&((pc[2] << 8) + pc[3] +reg[rn]);\n");
- printf("srcb = %s_MEM(lval);\n", size == 8 ? "BYTE" : "WORD");
- }
- else {
- printf("SET_%s_MEM(lval,dst);\n",ss);
- }
- break;
- case ABS16DST:
- if (fetch)
- {
- printf("lval = ((pc[2] << 8) + pc[3]);\n");
- printf("srcb = WORD_MEM(lval);\n");
- }
- else
- {
- printf ("SET_WORD_MEM(lval,dst);\n", i);
- }
- break;
- case IGNORE:
- break;
- case DISP8:
- printf(" /* DISP8 handled in opcode */\n");
- break;
- default:
- if (p->data.nib[i] > HexF)
- {
- printf("exception = SIGILL;\n");
- }
- }
- }
-}
-
-#define NNIBS 8
-
-typedef int keytype[NNIBS];
-struct key
-{
- keytype k;
- int nmatch;
-/* struct h8_opcode *match[200];*/
-};
-
-struct key keys[50];
-int nkeys;
-
-calckey (p, key)
-struct h8_opcode *p;
- keytype key;
-{
- int j;
-
- for (j = 0; (p->data.nib[j] != E); j++)
{
- if (p->data.nib[j] == RS8 || p->data.nib[j] == RD8)
- p->size = 8;
- if (p->size != 8)
- p->size=16;
- if (p->data.nib[j] > HexF)
- key[j] = p->data.nib[j];
- else
- key[j] = 0;
- }
- for (; j < NNIBS; j++)
- key[j] = 0;
-}
-
-lookup (key)
-keytype key;
-{
- int n;
-
- /* See if this key matches one already found */
- for (n = 0; n < nkeys; n++)
- {
- int i;
-
- for (i = 0; i < NNIBS; i++)
+ switch (p->data.nib[i])
{
- if ((keys[n].k[i]&0x3f) != (key[i]&0x3f))
- break;
- }
- if (i == NNIBS)
- break;
- }
- return n;
-}
-BADNEWS(x) {
-if (x == 0x7c) return 0;
-if (x == 0x7d) return 0;
-if (x == 0x7e) return 0;
-if (x == 0x7f) return 0;
-return 1;
-}
+ case RS8:
+ if (fetch)
+ printf ("srca = %s;\n", breg[i]);
+ break;
+ case RS16 | B30:
+ case RS16 | B31:
+ case RS16:
+ if (fetch)
+ printf ("srca = %s;\n", wreg[i]);
+ break;
+ case RD8:
+ if (fetch)
+ printf ("srcb = %s;\n", breg[i]);
+ else
+ printf ("%s = dst;\n", breg[i]);
+ break;
+ case RD16 | B30:
+ case RD16 | B31:
+ case RD16:
+ if (fetch)
+ printf ("srcb = %s;\n", wreg[i]);
+ else
+ printf ("%s =dst;\n", wreg[i]);
+ break;
+ case IMM8:
+ if (fetch)
+ printf ("srca = b1;\n");
+ break;
+ case RSINC:
+ case RSINC | B30:
+ case RSINC | B31:
-sortmodes ()
-{
- /* look through all the addressing modes, work out which ones are unique*/
- struct h8_opcode **p;
- keytype key;
+ if (fetch)
+ {
+ printf ("srca = %s_MEM(%s);\n", ss, wreg[i]);
+ printf ("%s+=%d;\n", wreg[i], size / 8);
+ }
+ break;
+ case RSIND:
+ case RSIND | B30:
+ case RSIND | B31:
+ if (fetch)
+ {
+ printf ("lval = %s;\n", wreg[i]);
+ printf ("srca = %s_MEM(lval);\n", ss);
+ }
+ break;
- int n;
- int i;
+ case RDIND:
+ case RDIND | B30:
+ case RDIND | B31:
+ if (fetch)
+ {
+ printf ("lval = %s;\n", wreg[i]);
+ printf ("srcb = %s_MEM(lval);\n", ss);
+ }
+ else
+ {
+ printf ("SET_%s_MEM(lval,dst);\n", ss);
+ }
+ break;
- memset (keys, 0, sizeof (keys));
+ case MEMIND:
+ if (fetch)
+ {
+ printf ("lval = ((pc[2]<<8)|pc[3]);\n");
+ }
+ break;
+ case RDDEC:
+ case RDDEC | B30:
+ case RDDEC | B31:
+ if (!fetch)
+ {
+ printf ("%s -=%d;\n", wreg[i], size / 8);
+ printf ("SET_%s_MEM(%s, dst);\n", ss, wreg[i]);
+ }
+ break;
+ case IMM3:
+ case IMM3 | B31:
+ case IMM3 | B30:
+ if (fetch)
+ printf ("srca = %s;\n", imm3[i]);
+ break;
+ case IMM16:
+ if (fetch)
+ printf ("srca =( pc[2] << 8) | pc[3];\n");
+ break;
+ case ABS8SRC:
+ if (fetch)
+ {
- for (i = 0; i < PTWO; i++)
- {
- p = h8_opcodes_sorted[i];
- while (*p)
- {
- int j;
- int a = 0;
+ printf ("lval = (0xff00) + b1;\n");
+ printf ("srca = BYTE_MEM(lval);\n");
+ }
-if (BADNEWS((*p)->sorted_key)) {
- calckey (*p, key);
- n = lookup (key);
- if (n == nkeys)
+ break;
+ case ABS8DST:
+ if (fetch)
{
- /* No hit, insert */
- memcpy (keys[n].k, key, sizeof (keys[n].k));
- nkeys++;
+ printf ("lval = (0xff00) + b1;\n");
+ printf ("srcb = BYTE_MEM(lval);\n");
+ }
+ else
+ {
+ printf ("SET_BYTE_MEM(lval,dst);\n");
+ }
+ break;
+ case KBIT:
+ if (fetch)
+ printf ("srca = ((b1&0x80)?2:1);\n");
+ break;
+ case ABS16ORREL8SRC:
+ case ABS16SRC:
+ if (fetch)
+ {
+ printf ("lval = ((pc[2] << 8) + pc[3]);\n");
+ printf ("srca = %s_MEM(lval);\n", size == 8 ? "BYTE" : "WORD");
+ }
+ break;
+ case DISPREG | B30:
+ case DISPREG | B31:
+ case DISPREG:
+ printf ("rn = %s & 0x7;\n", nibs[i]);
+ break;
+ case DISPSRC:
+ if (fetch)
+ {
+ printf ("lval = 0xffff&((pc[2] << 8) + pc[3] +reg[rn]);\n");
+ printf ("srca = %s_MEM(lval);\n", size == 8 ? "BYTE" : "WORD");
+ }
+ break;
+ case DISPDST:
+ if (fetch)
+ {
+ printf ("lval = 0xffff&((pc[2] << 8) + pc[3] +reg[rn]);\n");
+ printf ("srcb = %s_MEM(lval);\n", size == 8 ? "BYTE" : "WORD");
+ }
+ else
+ {
+ printf ("SET_%s_MEM(lval,dst);\n", ss);
+ }
+ break;
+ case ABS16DST:
+ if (fetch)
+ {
+ printf ("lval = ((pc[2] << 8) + pc[3]);\n");
+ printf ("srcb = %s_MEM(lval);\n", ss);
+ }
+ else
+ {
+ printf ("SET_%s_MEM(lval,dst);\n", ss);
+ }
+ break;
+ case IGNORE:
+ break;
+ case DISP8:
+ printf (" /* DISP8 handled in opcode */\n");
+ break;
+ default:
+ if (p->data.nib[i] > HexF)
+ {
+ printf ("exception = SIGILL;\n");
}
- /* Link in the p */
-#if 0
-/*e*/ keys[n].match[keys[n].nmatch++] = *p;
-#endif
- }
- (*p)->idx = n;
- p++;
}
}
-
-#if 0
- for (n = 0; n < nkeys; n++)
- {
- printf ("%d %d %d %d %d %d %d %d\n", keys[n][0], keys[n][1], keys[n][2], keys[n][3],
- keys[n][4], keys[n][5], keys[n][6], keys[n][7]);
-
- }
-#endif
-
-}
-void
-enop ()
-{
- printf ("%s Nop does nothing %s", cs, ce);
}
-void
+
+static void
esleep ()
{
printf ("exception = SIGSTOP;\n");
}
-rv (x)
-{
- printf ("v= 0;\n");
-}
-
-void
+static void
mov (p, s, sz)
struct h8_opcode *p;
char *s;
int sz;
{
- printf("dst = srca;\n");
-}
-
-tn (s)
-{
-/* printf ("n = dst & 0x%x;\n", s == 8 ? 0x80 : 0x8000);*/
-}
-
-tz (s)
-{
-/* printf ("z = ~(dst & 0x%x);\n", s == 8 ? 0xff : 0xffff);*/
-}
-
-tv (s)
-{
-/* printf ("v = (( (~(srca ^ srcb) & (srca ^ dst))) & (1<<%d));\n", s);*/
-}
-
-tc (s)
-{
- printf ("c = dst & 0x%x;\n", 1 << s);
-}
-
-log_flags (s)
-{
- tn (s);
- tz (s);
- rv (s);
-}
-
-alu_flags (s)
-{
- tn (s);
- tz (s);
- tv (s);
- tc (s);
-}
-
-void
-bclr (p)
- struct h8_opcode *p;
-{
- printf ("dst = srca & ~(1<<srcb);\n");
-}
-
-void
-biand (p)
- struct h8_opcode *p;
-{
- printf ("c =(C && ! ((srca >> srcb)&1));\n");
-}
-
-void
-bild (p)
- struct h8_opcode *p;
-{
- printf ("c = ( ! ((srca >> srcb)&1));\n");
+ printf ("dst = srca;\n");
}
-
-void
+static void
andc (p)
struct h8_opcode *p;
{
printf ("SET_CCR(GET_CCR() & srca);\n");
}
-void
+static void
addx (p)
struct h8_opcode *p;
{
printf ("dst = srca + srcb+ (c != 0);\n");
}
-void
+static void
subx (p)
struct h8_opcode *p;
{
printf ("dst = srcb - srca - (c != 0);\n");
}
-void
+static void
add (p, s, sz)
struct h8_opcode *p;
char *s;
int sz;
{
printf ("%s;\n", s);
- alu_flags (sz);
-
}
-void
+static void
adds (p, s)
struct h8_opcode *p;
char *s;
@@ -795,7 +382,7 @@ adds (p, s)
printf ("%s;\n", s);
}
-void
+static void
bra (p, a)
struct h8_opcode *p;
char *a;
@@ -803,47 +390,47 @@ bra (p, a)
printf ("if (%s) npc += (((char *)pc)[1]);\n", a);
}
-
-void
+static void
bsr (p, a)
struct h8_opcode *p;
char *a;
{
- printf("reg[7]-=2;\n");
- printf("tmp = reg[7];\n");
+ printf ("reg[7]-=2;\n");
+ printf ("tmp = reg[7];\n");
printf ("SET_WORD_MEM(tmp, npc-mem);\n");
printf ("npc += (((char *)pc)[1]);\n");
}
-void
+static void
cmp (p, a, s)
struct h8_opcode *p;
char *a;
int s;
{
- decode(p, 1, s);
-printf("srca = -srca;\n");
+ decode (p, 1, s);
+ printf ("srca = -srca;\n");
printf ("dst = srca + srcb;\n");
}
+static
void
jsr (p, a, s)
struct h8_opcode *p;
char *a;
int s;
{
- printf("if (b1 == 0xc4) {\n");
- printf("printf(\"%%c\", reg[2]);\n");
- printf("}\n");
- printf("else {\n");
- printf("reg[7]-=2;\n");
- printf("tmp = reg[7];\n");
+ printf ("if (b1 == 0xc4) {\n");
+ printf ("printf(\"%%c\", reg[2]);\n");
+ printf ("}\n");
+ printf ("else {\n");
+ printf ("reg[7]-=2;\n");
+ printf ("tmp = reg[7];\n");
printf ("SET_WORD_MEM(tmp, npc-mem);\n");
printf ("npc = lval + mem;\n");
- printf("}");
+ printf ("}");
}
-void
+static void
jmp (p, a, s)
struct h8_opcode *p;
char *a;
@@ -852,7 +439,7 @@ jmp (p, a, s)
printf ("npc = lval + mem;\n");
}
-void
+static void
rts (p, a, s)
struct h8_opcode *p;
char *a;
@@ -863,27 +450,27 @@ rts (p, a, s)
printf ("npc = mem + WORD_MEM(tmp);\n");
}
-void
+static void
setf (p, a, s)
struct h8_opcode *p;
char *a;
int s;
{
printf ("tmp = GET_CCR();\n");
- printf ("tmp %s= srca;\n",a);
+ printf ("tmp %s= srca;\n", a);
}
-void
+static void
bpt (p, a, s)
struct h8_opcode *p;
char *a;
int s;
{
printf ("exception = SIGTRAP;\n");
- printf( "npc = pc;\n");
+ printf ("npc = pc;\n");
}
-void
+static void
log (p, a, s)
struct h8_opcode *p;
char *a;
@@ -892,7 +479,7 @@ log (p, a, s)
printf ("dst = srcb %s srca;\n", a);
}
-void
+static void
ulog (p, a, s)
struct h8_opcode *p;
char *a;
@@ -901,102 +488,143 @@ ulog (p, a, s)
printf ("dst = %s srcb ;\n", a);
}
-void
-nop()
+static void
+nop ()
{
}
-void
-rotl()
+static void
+rotl ()
{
-printf("c = srcb & 0x80;\n");
-printf("dst = srcb << 1;\n");
-printf("if (c) dst|=1;\n");
+ printf ("c = srcb & 0x80;\n");
+ printf ("dst = srcb << 1;\n");
+ printf ("if (c) dst|=1;\n");
}
-void
-rotr()
+
+static void
+rotr ()
{
-printf("c = srcb & 1;\n");
-printf("dst = srcb >> 1;\n");
-printf("if (c) dst|=0x80;\n");
+ printf ("c = srcb & 1;\n");
+ printf ("dst = srcb >> 1;\n");
+ printf ("if (c) dst|=0x80;\n");
}
-void
-rotxl()
+static void
+rotxl ()
+{
+ printf ("tmp = srcb & 0x80;\n");
+ printf ("dst = srcb << 1;\n");
+ printf ("if (c) dst|=1;\n");
+ printf ("c = tmp;\n");
+}
+
+static void
+rotxr ()
+{
+ printf ("tmp = srcb & 1;\n");
+ printf ("dst = srcb >> 1;\n");
+ printf ("if (c) dst|=0x80;\n");
+ printf ("c = tmp;\n");
+}
+
+static void
+shal ()
{
-printf("tmp = srcb & 0x80;\n");
-printf("dst = srcb << 1;\n");
-printf("if (c) dst|=1;\n");
-printf("c = tmp;\n");
+ printf ("c = srcb&0x80;\n");
+ printf ("dst = srcb << 1;\n");
}
+
+static
void
-rotxr()
+shar ()
{
-printf("tmp = srcb & 1;\n");
-printf("dst = srcb >> 1;\n");
-printf("if (c) dst|=0x80;\n");
-printf("c = tmp;\n");
+ printf ("c = srcb&0x1;\n");
+ printf ("if (srcb&0x80) dst = (srcb>>1) | 0x80;\n");
+ printf ("else dst = (srcb>>1) &~ 0x80;\n");
}
+static
+void
+shll ()
+{
+ printf ("c = srcb&0x80;\n");
+ printf ("dst = srcb << 1;\n");
+}
+static
void
-shal()
+shlr ()
{
-printf("c = srcb&0x80;\n");
-printf("dst = srcb << 1;\n");
+ printf ("c = srcb&0x1;\n");
+ printf ("dst = (srcb>>1) &~ 0x80;\n");
}
+static
void
-shar()
+divxu ()
{
-printf("c = srcb&0x1;\n");
-printf("if (srcb&0x80) dst = (srcb>>1) | 0x80;\n");
-printf("else dst = (srcb>>1) &~ 0x80;\n");
+ printf ("srca = %s;\n", breg[2]);
+ printf ("srcb = %s;\n", wreg[3]);
+ printf ("n = srca & 0x80;\n");
+ printf ("z = !srca;\n");
+ printf ("if (srca) dst = srcb / srca;tmp = srcb %% srca;\n");
+ printf ("%s = (dst & 0xff) | (tmp << 8);\n", wreg[3]);
}
+static
void
-shll()
+mulxu ()
{
-printf("c = srcb&0x80;\n");
-printf("dst = srcb << 1;\n");
+ printf ("srca = %s;\n", breg[2]);
+ printf ("srcb = %s;\n", wreg[3]);
+
+ printf ("dst = (srcb&0xff) * srca;\n");
+ printf ("%s = dst;\n", wreg[3]);
}
+static
void
-shlr()
+inc ()
{
-printf("c = srcb&0x1;\n");
-printf("dst = (srcb>>1) &~ 0x80;\n");
+ printf ("dst = %s;\n", breg[3]);
+ printf ("v = (dst==0x7f);\n");
+ printf ("dst++;\n");
+ printf ("%s= dst;\n", breg[3]);
}
+static
void
-divxu()
+bit (p, a, s)
+ struct h8_opcode *p;
+ char *a;
+ int s;
{
- printf("srca = BYTE_REG(pc[1]>>4);\n");
- printf("srcb = WORD_REG(pc[1]&0x7);\n");
- printf("n = srca & 0x80\;\n");
- printf("z = !srca;\n");
- printf("if (srca) dst = srcb / srca;tmp = srcb %% srca;\n");
- printf("reg[pc[1]&0x7] = (dst & 0xff) | (tmp << 8);\n");
+ printf ("%s\n", a);
}
+
+static
void
-mulxu()
+dec ()
{
- printf("srca = BYTE_REG(pc[1]>>4);\n");
- printf("srcb = WORD_REG(pc[1]&0x7);\n");
- printf("dst = (srcb&0xff) * srca;\n");
- printf("reg[pc[1]&0x7] = dst;\n");
+ printf ("dst = %s;\n", breg[3]);
+ printf ("v = (dst==0x80);\n");
+ printf ("dst--;\n");
+ printf ("%s = dst;\n", breg[3]);
}
-char saf[]="goto setflags;";
+
+char saf[] = "goto setflags;";
char sf[] = "goto shiftflags;";
char af8[] = "goto aluflags8;";
char af16[] = "goto aluflags16;";
char lf[] = "goto logflags;";
-char mf8[]= "goto movflags8;";
-char mf16[]= "goto movflags16;";
+char icf[] = "goto incflags;";
+char mf8[] = "goto movflags8;";
+char mf16[] = "goto movflags16;";
char nx[] = "goto next;";
+
struct
{
-char *ftype;
+ char *ftype;
int decode;
char *name;
void (*func) ();
@@ -1005,71 +633,85 @@ char *ftype;
}
-
table [] =
{
- saf,1,"orc",setf,"|",0,
- saf,1,"xorc",setf,"^",0,
- saf,1,"andc",setf,"&",0,
- 0,1, "bild", bild, 0, 0,
- 0,1, "nop", nop, 0, 0,
- 0,1, "bclr", bclr, 0, 0,
- 0,1, "biand", biand, 0, 0,
- 0,1, "bra", bra, "1", 0,
- 0,1, "brn", bra, "0", 0,
- 0,1, "bf", bra, "0", 0,
- 0,1, "bhi", bra, "(C||Z)==0", 0,
- 0,1, "bls", bra, "(C||Z)==1", 0,
- 0,1, "bcs", bra, "C==1", 0,
- 0,1, "bcc", bra, "C==0", 0,
- 0,1, "bpl", bra, "N==0", 0,
- 0,1, "bmi", bra, "N==1", 0,
- 0,1, "bvs", bra, "V==1", 0,
- 0,1, "bvc", bra, "V==0", 0,
- 0,1, "bge", bra, "(N^V)==0", 0,
- 0,1, "bgt", bra, "(Z|(N^V))==0", 0,
- 0,1, "blt", bra, "(N^V)==1", 0,
- 0,1, "ble", bra, "(Z|(N^V))==1", 0,
- 0,1, "beq", bra, "Z==1", 0,
- 0,1, "bne", bra, "Z==0", 0,
- 0,1, "bsr", bsr, "", 0,
- 0,1, "jsr", jsr, 0, 0,
- 0,1, "jmp", jmp, 0, 0,
- 0,0, "rts", rts, 0, 0,
- 0,1, "andc", andc, 0, 0,
- 0,1, "nop", enop, 0, 0,
- sf,1, "shal",shal,0,0,
- sf,1, "shar",shar,0,0,
- sf,1, "shll",shll,0,0,
- sf,1, "shlr",shlr,0,0,
- sf,1, "rotxl",rotxl,0,0,
- sf,1, "rotxr",rotxr,0,0,
- sf,1, "rotl",rotl,0,0,
- sf,1, "rotr",rotr,0,0,
- lf,1, "xor", log, "^",0,
- lf,1, "and", log, "&",0,
- lf,1, "or", log, "|",0,
- lf,1,"not", ulog," ~",0,
- lf,1,"neg", ulog," - ",0,
- 0,1, "adds", adds, "dst = srca + srcb", 0,
- 0,1, "subs", adds, "srca = -srca; dst = srcb + srca", 0,
- af8,1, "add.b", add, "dst = srca + srcb", 8,
- af16,1, "add.w", add, "dst = srca + srcb", 16,
- af16,1, "sub.w", add, "srca = -srca; dst = srcb + srca", 16,
- af8,1, "sub.b", add, "srca = -srca; dst = srcb + srca", 8,
- af8,1, "addx", addx, 0, 8,
- af8,1, "subx", subx, 0, 8,
- af8,0, "cmp.b", cmp, 0, 8,
- af16,0, "cmp.w", cmp, 0, 16,
- 0,1, "sleep", esleep, 0, 0,
- 0,0, "bpt", bpt, 0, 8,
- nx,0, "divxu", divxu,0,0,
- nx,0, "mulxu", mulxu,0,0,
- mf8,1, "mov.b", mov, 0, 8,
- mf16,1, "mov.w", mov, 0, 16,
- 0, 0
- };
+ { nx, 1, "bld", bit, "dst = srcb; c = (srcb>>srca)&1;", 8 } ,
+ { nx, 1, "bild", bit, "dst = srcb; c = !((srcb>>srca)&1);", 8 } ,
+ { nx, 1, "band", bit, "dst = srcb; c = C &&((srcb>>srca)&1);", 8 } ,
+ { nx, 1, "biand", bit, "dst = srcb; c = C &&(!((srcb>>srca)&1));", 8 } ,
+ { nx, 1, "bior", bit, "dst = srcb; c = C ||(!((srcb>>srca)&1));", 8 } ,
+ { nx, 1, "bor", bit, "dst = srcb; c = C ||(((srcb>>srca)&1));", 8 } ,
+ { nx, 1, "bixor", bit, "dst = srcb; c = C ^(!((srcb>>srca)&1));", 8 } ,
+ { nx, 1, "bxor", bit, "dst = srcb; c = C ^(((srcb>>srca)&1));", 8 } ,
+ { nx, 1, "bnot", bit, "dst = srcb ^ (1<<srca);", 8 } ,
+ { nx, 1, "bclr", bit, "dst = srcb & ~(1<<srca);", 8 } ,
+ { nx, 1, "bset", bit, "dst = srcb | (1<<srca);", 8 } ,
+ { nx, 1, "bst", bit, "dst = (srcb & ~(1<<srca))| ((C)<<srca);", 8 } ,
+ { nx, 1, "bist", bit, "dst = (srcb & ~(1<<srca))| ((!C)<<srca);", 8 } ,
+ { nx, 1, "btst", bit, "dst = srcb; z = !((srcb>>srca)&1);", 8 } ,
+ { icf, 0, "dec", dec, 0, 0 } ,
+ { icf, 0, "inc", inc, 0, 0 } ,
+ { saf, 1, "orc", setf, "|", 0 } ,
+ { saf, 1, "xorc", setf, "^", 0 } ,
+ { saf, 1, "andc", setf, "&", 0 } ,
+ { nx, 1, "nop", nop, 0, 0 } ,
+ { nx, 1, "bra", bra, "1", 0 } ,
+ { nx, 1, "brn", bra, "0", 0 } ,
+ { nx, 1, "bhi", bra, "(C||Z)==0", 0 } ,
+ { nx, 1, "bls", bra, "(C||Z)==1", 0 } ,
+ { nx, 1, "bcs", bra, "C==1", 0 } ,
+ { nx, 1, "bcc", bra, "C==0", 0 } ,
+ { nx, 1, "bpl", bra, "N==0", 0 } ,
+ { nx, 1, "bmi", bra, "N==1", 0 } ,
+ { nx, 1, "bvs", bra, "V==1", 0 } ,
+ { nx, 1, "bvc", bra, "V==0", 0 } ,
+ { nx, 1, "bge", bra, "(N^V)==0", 0 } ,
+ { nx, 1, "bgt", bra, "(Z|(N^V))==0", 0 } ,
+ { nx, 1, "blt", bra, "(N^V)==1", 0 } ,
+ { nx, 1, "ble", bra, "(Z|(N^V))==1", 0 } ,
+ { nx, 1, "beq", bra, "Z==1", 0 } ,
+ { nx, 1, "bne", bra, "Z==0", 0 } ,
+ { nx, 1, "bsr", bsr, "", 0 } ,
+ { nx, 1, "jsr", jsr, 0, 0 } ,
+ { nx, 1, "jmp", jmp, 0, 0 } ,
+ { nx, 0, "rts", rts, 0, 0 } ,
+ { nx, 1, "andc", andc, 0, 0 } ,
+ { sf, 1, "shal", shal, 0, 0 } ,
+ { sf, 1, "shar", shar, 0, 0 } ,
+ { sf, 1, "shll", shll, 0, 0 } ,
+ { sf, 1, "shlr", shlr, 0, 0 } ,
+ { sf, 1, "rotxl", rotxl, 0, 0 } ,
+ { sf, 1, "rotxr", rotxr, 0, 0 } ,
+ { sf, 1, "rotl", rotl, 0, 0 } ,
+ { sf, 1, "rotr", rotr, 0, 0 } ,
+ { lf, 1, "xor", log, "^", 0 } ,
+ { lf, 1, "and", log, "&", 0 } ,
+ { lf, 1, "or", log, "|", 0 } ,
+ { lf, 1, "not", ulog, " ~", 0 } ,
+ { lf, 1, "neg", ulog, " - ", 0 } ,
+ { nx, 1, "adds", adds, "dst = srca + srcb", 0 } ,
+ { nx, 1, "subs", adds, "srca = -srca; dst = srcb + srca", 0 } ,
+ { af8, 1, "add.b", add, "dst = srca + srcb", 8 } ,
+ { af16, 1, "add.w", add, "dst = srca + srcb", 16 } ,
+ { af16, 1, "sub.w", add, "srca = -srca; dst = srcb + srca", 16 } ,
+ { af8, 1, "sub.b", add, "srca = -srca; dst = srcb + srca", 8 } ,
+ { af8, 1, "addx", addx, 0, 8 } ,
+ { af8, 1, "subx", subx, 0, 8 } ,
+ { af8, 0, "cmp.b", cmp, 0, 8 } ,
+ { af16, 0, "cmp.w", cmp, 0, 16 } ,
+ { nx, 1, "sleep", esleep, 0, 0 } ,
+ { nx, 0, "bpt", bpt, 0, 8 } ,
+ { nx, 0, "divxu", divxu, 0, 0 } ,
+ { nx, 0, "mulxu", mulxu, 0, 0 } ,
+ { mf8, 1, "mov.b", mov, 0, 8 } ,
+ { mf8, 1, "movtpe", mov, 0, 8 } ,
+ { mf8, 1, "movfpe", mov, 0, 8 } ,
+ { mf16, 1, "mov.w", mov, 0, 16 } ,
+ { 0 }
+};
+static
+void
edo (p)
struct h8_opcode *p;
{
@@ -1078,28 +720,34 @@ edo (p)
printf ("%s %s %s\n", cs, p->name, ce);
for (i = 0; table[i].name; i++)
- {
- if (strcmp (table[i].name, p->name) == 0)
{
- printf ("{\n");
- if (table[i].decode) decode(p, 1,p->size);
- printf ("cycles += %d;\n", p->time);
- printf ("npc = pc + %d;\n", p->length);
- table[i].func (p, table[i].arg, table[i].size);
- if (table[i].decode) decode(p, 0,p->size);
- if (table[i].ftype) printf(table[i].ftype);
- else printf ("goto next;\n");
- printf ("}\n");
- return;
+ if (strcmp (table[i].name, p->name) == 0)
+ {
+ printf ("{\n");
+ if (table[i].decode)
+ decode (p, 1, table[i].size);
+ printf ("cycles += %d;\n", p->time);
+ printf ("npc = pc + %d;\n", p->length);
+ table[i].func (p, table[i].arg, table[i].size);
+ if (table[i].decode)
+ decode (p, 0, table[i].size);
+ if (table[i].ftype)
+ printf (table[i].ftype);
+ else
+ printf ("goto next;\n");
+ printf ("}\n");
+ return;
+ }
}
- }
printf ("%s not found %s\n", cs, ce);
- printf("exception = SIGILL;\n");
+ printf ("exception = SIGILL;\n");
printf ("break;\n");
}
+static
int
owrite (i)
+ int i;
{
/* write if statements to select the right opcode */
struct h8_opcode **p;
@@ -1203,194 +851,52 @@ owrite (i)
return i;
}
-print_key (i)
+static
+void
+remove_dups ()
{
- int j;
+ struct h8_opcode *s;
+ struct h8_opcode *d;
- printf ("%s", cs);
- for (j = 0; j < 8; j++)
+ for (d = s = h8_opcodes; s->name; s++)
{
-/* printf ("(0x%02x ", keys[i].k[j]);*/
- if (keys[i].k[j] & B30)
- printf ("B30");
- else if (keys[i].k[j] & B31)
- printf ("B31");
- switch (keys[i].k[j])
+ int doit = 1;
+
+ if (strcmp (s->name, "push") == 0)
+ doit = 0;
+ if (strcmp (s->name, "bhs") == 0)
+ doit = 0;
+ if (strcmp (s->name, "blo") == 0)
+ doit = 0;
+ if (strcmp (s->name, "bt") == 0)
+ doit = 0;
+ if (strcmp (s->name, "bf") == 0)
+ doit = 0;
+ if (strcmp (s->name, "pop") == 0)
+ doit = 0;
+ if (doit)
{
- case KBIT:
- printf ("KBIT");
- break;
- case IMM3:
- printf ("IMM3");
- break;
- case RD8:
- printf ("RD8");
- break;
- case RD16:
- printf ("RD16");
- break;
- case RS8:
- printf ("RS8");
- break;
- case RS16:
- printf ("RS16");
- break;
- case IMM8:
- printf ("IMM8");
- break;
- case IMM16:
- printf ("IMM16");
- break;
- case CCR:
- printf ("CCR");
- break;
- case ABS8SRC:
- printf ("ABS8SRC");
- break;
- case ABS8DST:
- printf ("ABS8SDST");
- break;
- case DISP8:
- printf ("DISP8");
- break;
- case ABS16SRC:
- printf ("ABS16SRC");
- break;
- case ABS16OR8SRC:
- printf ("ABS16OR8SRC");
- break;
- case ABS16DST:
- printf ("ABS16SDST");
- break;
- case ABS16OR8DST:
- printf ("ABS16OR8SDST");
- break;
- case DISPSRC:
- printf ("DISPSRC");
- break;
- case DISPDST:
- printf ("DISPSDST");
- break;
- case DISPREG:
- printf ("DISPREG");
- break;
- case RDDEC:
- printf ("RDDEC");
- break;
- case RSINC:
- printf ("RSINC");
- break;
- case RDIND:
- printf ("RDIND");
- break;
- case RSIND:
- printf ("RSIND");
- break;
- case MEMIND:
- printf ("MEMIND");
- break;
- case ABS16ORREL8SRC:
- printf ("ABS16ORREL8SRC");
- break;
- case IGNORE:
- printf ("IGNORE");
- break;
- default:
- printf ("**");
- break;
+ *d++ = *s;
}
- printf (" ");
- }
- printf ("%s\n", ce);
-}
-
-dofetch (fetch)
-int fetch;
-{
- int i;
- int done_for[PTWO];
- memset (done_for, 0, sizeof (done_for));
- printf ("switch (b0) {\n");
- for (i = 0; i < nkeys; i++)
- {
- struct h8_opcode *p;
- struct h8_opcode *l = 0;
- int k;
-
- printf ("%s KEY %d %s\n", cs,i,ce);
- print_key (i);
-
- {
- int j;
-
- l = 0;
- for (p = h8_opcodes; p->name; p++)
- {
- int key[8];
-
- if (p->idx == i && p->name != empty)
- {
- l = p;
- if (done_for[p->sorted_key] != i + 1000)
- {
- done_for[p->sorted_key] = i + 1000;
- printf ("case 0x%03x:\n", p->sorted_key);
- printf("%s %s %s\n", cs, p->name, ce);
- }
- }
- }
- if (l)
- {
-
- decode (l, fetch, l->size);
- printf ("break;\n");
- }
- else
- printf (" /* NO */\n");
- }
- }
- printf ("}\n");
-}
-
-remove_dups()
-{
- struct h8_opcode *s;
- struct h8_opcode *d;
- for (d = s = h8_opcodes; s->name; s++)
- {
- int doit = 1;
- if (strcmp(s->name,"push") ==0) doit = 0;
- if (strcmp(s->name,"pop") ==0) doit = 0;
- if (doit)
- {
- *d++ = *s;
}
- }
*d++ = *s++;
}
+
+int
main ()
{
int i;
-remove_dups();
- init ();
- sortmodes ();
+ remove_dups ();
+ init ();
-#if 0
- printf("%s fetch the args %s\n", cs,ce);
- dofetch (1);
-#endif
- printf("%s do the operation %s\n", cs,ce);
+ printf ("%s do the operation %s\n", cs, ce);
printf ("switch (b0) \n{\n");
for (i = 0; i < PTWO; i++)
{
i = owrite (i);
}
printf ("}\n");
-#if 0
- printf("%s store the result %s\n", cs,ce);
- dofetch (0);
-#endif
return 0;
}