diff options
Diffstat (limited to 'sim/mn10300/gencode.c')
-rw-r--r-- | sim/mn10300/gencode.c | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/sim/mn10300/gencode.c b/sim/mn10300/gencode.c new file mode 100644 index 0000000..d2f5e3b --- /dev/null +++ b/sim/mn10300/gencode.c @@ -0,0 +1,143 @@ +#include "mn10300_sim.h" + +static void write_header PARAMS ((void)); +static void write_opcodes PARAMS ((void)); +static void write_template PARAMS ((void)); + +long Opcodes[512]; +static int curop=0; + +int +main (argc, argv) + int argc; + char *argv[]; +{ + 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 +write_header () +{ + struct mn10300_opcode *opcode; + + for (opcode = (struct mn10300_opcode *)mn10300_opcodes; opcode->name; opcode++) + printf("void OP_%X PARAMS ((void));\t\t/* %s */\n", + opcode->opcode, opcode->name); +} + + +/* write_template creates a file all required functions, ready */ +/* to be filled out */ + +static void +write_template () +{ + struct mn10300_opcode *opcode; + int i,j; + + printf ("#include \"mn10300_sim.h\"\n"); + printf ("#include \"simops.h\"\n"); + + for (opcode = (struct mn10300_opcode *)mn10300_opcodes; opcode->name; opcode++) + { + printf("/* %s */\nvoid\nOP_%X ()\n{\n", opcode->name, opcode->opcode); + + /* count operands */ + j = 0; + for (i = 0; i < 6; i++) + { + int flags = mn10300_operands[opcode->operands[i]].flags; + + if (flags) + 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"); + } +} + +static void +write_opcodes () +{ + struct mn10300_opcode *opcode; + int i, j; + int numops; + + /* write out opcode table */ + printf ("#include \"mn10300_sim.h\"\n"); + printf ("#include \"simops.h\"\n\n"); + printf ("struct simops Simops[] = {\n"); + + for (opcode = (struct mn10300_opcode *)mn10300_opcodes; opcode->name; opcode++) + { + printf (" { 0x%x,0x%x,OP_%X,", + opcode->opcode, opcode->mask, opcode->opcode); + + Opcodes[curop++] = opcode->opcode; + + /* count operands */ + j = 0; + for (i = 0; i < 6; i++) + { + int flags = mn10300_operands[opcode->operands[i]].flags; + + if (flags) + j++; + } + printf ("%d,{",j); + + j = 0; + numops = 0; + for (i = 0; i < 6; i++) + { + int flags = mn10300_operands[opcode->operands[i]].flags; + int shift = mn10300_operands[opcode->operands[i]].shift; + + if (flags) + { + if (j) + printf (", "); + printf ("%d,%d,%d", shift, + mn10300_operands[opcode->operands[i]].bits,flags); + j = 1; + numops++; + } + } + + switch (numops) + { + case 0: + printf ("0,0,0"); + case 1: + printf (",0,0,0"); + } + + printf ("}},\n"); + } + printf ("{ 0,0,NULL,0,{0,0,0,0,0,0}},\n};\n"); +} |