1999-04-16 09:35:26 +08:00
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
2015-03-30 13:38:59 +08:00
|
|
|
#include <string.h>
|
1999-04-16 09:35:26 +08:00
|
|
|
#include "ansidecl.h"
|
|
|
|
#include "opcode/d10v.h"
|
|
|
|
|
2014-01-05 12:43:21 +08:00
|
|
|
static void write_header (void);
|
|
|
|
static void write_opcodes (void);
|
|
|
|
static void write_template (void);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
int
|
2015-03-30 13:38:59 +08:00
|
|
|
main (int argc, char *argv[])
|
1999-04-16 09:35:26 +08:00
|
|
|
{
|
|
|
|
if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
|
|
|
|
write_header();
|
|
|
|
else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
|
|
|
|
write_template ();
|
|
|
|
else
|
|
|
|
write_opcodes();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2015-03-30 13:38:59 +08:00
|
|
|
write_header (void)
|
1999-04-16 09:35:26 +08:00
|
|
|
{
|
|
|
|
struct d10v_opcode *opcode;
|
|
|
|
|
|
|
|
for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
|
|
|
|
if (opcode->format != OPCODE_FAKE)
|
2015-11-15 18:57:42 +08:00
|
|
|
printf ("void OP_%lX (SIM_DESC, SIM_CPU *);\t\t/* %s */\n", opcode->opcode, opcode->name);
|
1999-04-16 09:35:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* write_template creates a file all required functions, ready */
|
|
|
|
/* to be filled out */
|
|
|
|
|
|
|
|
static void
|
2015-03-30 13:38:59 +08:00
|
|
|
write_template (void)
|
1999-04-16 09:35:26 +08:00
|
|
|
{
|
|
|
|
struct d10v_opcode *opcode;
|
|
|
|
int i,j;
|
|
|
|
|
2015-11-15 18:57:42 +08:00
|
|
|
printf ("#include \"sim-main.h\"\n");
|
1999-04-16 09:35:26 +08:00
|
|
|
printf ("#include \"simops.h\"\n");
|
|
|
|
|
|
|
|
for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
|
|
|
|
{
|
|
|
|
if (opcode->format != OPCODE_FAKE)
|
|
|
|
{
|
2015-03-30 13:38:59 +08:00
|
|
|
printf("/* %s */\nvoid\nOP_%lX ()\n{\n", opcode->name, opcode->opcode);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* count operands */
|
|
|
|
j = 0;
|
|
|
|
for (i=0;i<6;i++)
|
|
|
|
{
|
|
|
|
int flags = d10v_operands[opcode->operands[i]].flags;
|
|
|
|
if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
switch (j)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
printf ("printf(\" %s\\n\");\n",opcode->name);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
printf ("printf(\" %s\\t%%x\\n\",OP[0]);\n",opcode->name);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",opcode->name);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",opcode->name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf (stderr,"Too many operands: %d\n",j);
|
|
|
|
}
|
|
|
|
printf ("}\n\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long Opcodes[512];
|
|
|
|
static int curop=0;
|
|
|
|
|
2015-03-30 13:38:59 +08:00
|
|
|
static void
|
1999-04-16 09:35:26 +08:00
|
|
|
check_opcodes( long op)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0;i<curop;i++)
|
|
|
|
if (Opcodes[i] == op)
|
2015-03-30 13:38:59 +08:00
|
|
|
fprintf(stderr,"DUPLICATE OPCODES: %lx\n", op);
|
1999-04-16 09:35:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-03-30 13:38:59 +08:00
|
|
|
write_opcodes (void)
|
1999-04-16 09:35:26 +08:00
|
|
|
{
|
|
|
|
struct d10v_opcode *opcode;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/* write out opcode table */
|
2015-11-15 18:57:42 +08:00
|
|
|
printf ("#include \"sim-main.h\"\n");
|
1999-04-16 09:35:26 +08:00
|
|
|
printf ("#include \"simops.h\"\n\n");
|
|
|
|
printf ("struct simops Simops[] = {\n");
|
|
|
|
|
|
|
|
for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
|
|
|
|
{
|
|
|
|
if (opcode->format != OPCODE_FAKE)
|
|
|
|
{
|
2015-03-30 13:38:59 +08:00
|
|
|
printf (" { %ld,%d,%ld,%d,%d,%d,%d,OP_%lX,", opcode->opcode,
|
1999-04-16 09:35:26 +08:00
|
|
|
(opcode->format & LONG_OPCODE) ? 1 : 0, opcode->mask, opcode->format,
|
|
|
|
opcode->cycles, opcode->unit, opcode->exec_type, opcode->opcode);
|
|
|
|
|
|
|
|
/* REMOVE ME */
|
|
|
|
check_opcodes (opcode->opcode);
|
|
|
|
Opcodes[curop++] = opcode->opcode;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for (i=0;i<6;i++)
|
|
|
|
{
|
|
|
|
int flags = d10v_operands[opcode->operands[i]].flags;
|
|
|
|
if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
printf ("%d,",j);
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for (i=0;i<6;i++)
|
|
|
|
{
|
|
|
|
int flags = d10v_operands[opcode->operands[i]].flags;
|
|
|
|
int shift = d10v_operands[opcode->operands[i]].shift;
|
|
|
|
if ((flags & OPERAND_REG) || (flags & OPERAND_NUM)|| (flags & OPERAND_ADDR))
|
|
|
|
{
|
|
|
|
if (j == 0)
|
|
|
|
printf ("{");
|
|
|
|
else
|
|
|
|
printf (", ");
|
|
|
|
if ((flags & OPERAND_REG) && (opcode->format == LONG_L))
|
|
|
|
shift += 15;
|
|
|
|
printf ("%d,%d,%d",shift,d10v_operands[opcode->operands[i]].bits,flags);
|
|
|
|
j = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j)
|
|
|
|
printf ("}");
|
|
|
|
printf ("},\n");
|
|
|
|
}
|
|
|
|
}
|
2015-11-15 18:57:42 +08:00
|
|
|
printf ("{ 0,0,0,0,0,0,0,(void (*)())0,0,{0,0,0}},\n};\n");
|
1999-04-16 09:35:26 +08:00
|
|
|
}
|