Home | History | Annotate | Line # | Download | only in d10v
      1  1.1  christos #include <stdio.h>
      2  1.1  christos #include <ctype.h>
      3  1.1  christos #include <limits.h>
      4  1.5  christos #include <string.h>
      5  1.1  christos #include "ansidecl.h"
      6  1.1  christos #include "opcode/d10v.h"
      7  1.1  christos 
      8  1.1  christos static void write_header (void);
      9  1.1  christos static void write_opcodes (void);
     10  1.1  christos static void write_template (void);
     11  1.1  christos 
     12  1.1  christos int
     13  1.5  christos main (int argc, char *argv[])
     14  1.1  christos {
     15  1.1  christos   if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
     16  1.1  christos     write_header();
     17  1.1  christos   else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
     18  1.1  christos     write_template ();
     19  1.1  christos   else
     20  1.1  christos     write_opcodes();
     21  1.1  christos   return 0;
     22  1.1  christos }
     23  1.1  christos 
     24  1.1  christos 
     25  1.1  christos static void
     26  1.5  christos write_header (void)
     27  1.1  christos {
     28  1.1  christos   struct d10v_opcode *opcode;
     29  1.1  christos 
     30  1.1  christos   for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
     31  1.1  christos     if (opcode->format != OPCODE_FAKE)
     32  1.6  christos       printf ("void OP_%lX (SIM_DESC, SIM_CPU *);\t\t/* %s */\n", opcode->opcode, opcode->name);
     33  1.1  christos }
     34  1.1  christos 
     35  1.1  christos 
     36  1.1  christos /* write_template creates a file all required functions, ready */
     37  1.1  christos /* to be filled out */
     38  1.1  christos 
     39  1.1  christos static void
     40  1.5  christos write_template (void)
     41  1.1  christos {
     42  1.1  christos   struct d10v_opcode *opcode;
     43  1.1  christos   int i,j;
     44  1.1  christos 
     45  1.8  christos   printf ("#include \"d10v-sim.h\"\n");
     46  1.1  christos   printf ("#include \"simops.h\"\n");
     47  1.1  christos 
     48  1.1  christos   for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
     49  1.1  christos     {
     50  1.1  christos       if (opcode->format != OPCODE_FAKE)
     51  1.1  christos 	{
     52  1.5  christos 	  printf("/* %s */\nvoid\nOP_%lX ()\n{\n", opcode->name, opcode->opcode);
     53  1.1  christos 
     54  1.1  christos 	  /* count operands */
     55  1.1  christos 	  j = 0;
     56  1.1  christos 	  for (i=0;i<6;i++)
     57  1.1  christos 	    {
     58  1.1  christos 	      int flags = d10v_operands[opcode->operands[i]].flags;
     59  1.1  christos 	      if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
     60  1.1  christos 		j++;
     61  1.1  christos 	    }
     62  1.1  christos 	  switch (j)
     63  1.1  christos 	    {
     64  1.1  christos 	    case 0:
     65  1.1  christos 	      printf ("printf(\"   %s\\n\");\n",opcode->name);
     66  1.1  christos 	      break;
     67  1.1  christos 	    case 1:
     68  1.1  christos 	      printf ("printf(\"   %s\\t%%x\\n\",OP[0]);\n",opcode->name);
     69  1.1  christos 	      break;
     70  1.1  christos 	    case 2:
     71  1.1  christos 	      printf ("printf(\"   %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",opcode->name);
     72  1.1  christos 	      break;
     73  1.1  christos 	    case 3:
     74  1.1  christos 	      printf ("printf(\"   %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",opcode->name);
     75  1.1  christos 	      break;
     76  1.1  christos 	    default:
     77  1.1  christos 	      fprintf (stderr,"Too many operands: %d\n",j);
     78  1.1  christos 	    }
     79  1.1  christos 	  printf ("}\n\n");
     80  1.1  christos 	}
     81  1.1  christos     }
     82  1.1  christos }
     83  1.1  christos 
     84  1.1  christos 
     85  1.1  christos long Opcodes[512];
     86  1.1  christos static int curop=0;
     87  1.1  christos 
     88  1.5  christos static void
     89  1.1  christos check_opcodes( long op)
     90  1.1  christos {
     91  1.1  christos   int i;
     92  1.1  christos 
     93  1.1  christos   for (i=0;i<curop;i++)
     94  1.1  christos     if (Opcodes[i] == op)
     95  1.5  christos       fprintf(stderr,"DUPLICATE OPCODES: %lx\n", op);
     96  1.1  christos }
     97  1.1  christos 
     98  1.1  christos static void
     99  1.5  christos write_opcodes (void)
    100  1.1  christos {
    101  1.1  christos   struct d10v_opcode *opcode;
    102  1.1  christos   int i, j;
    103  1.1  christos 
    104  1.1  christos   /* write out opcode table */
    105  1.6  christos   printf ("#include \"sim-main.h\"\n");
    106  1.8  christos   printf ("#include \"d10v-sim.h\"\n");
    107  1.1  christos   printf ("#include \"simops.h\"\n\n");
    108  1.1  christos   printf ("struct simops Simops[] = {\n");
    109  1.1  christos 
    110  1.1  christos   for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
    111  1.1  christos     {
    112  1.1  christos       if (opcode->format != OPCODE_FAKE)
    113  1.1  christos 	{
    114  1.5  christos 	  printf ("  { %ld,%d,%ld,%d,%d,%d,%d,OP_%lX,", opcode->opcode,
    115  1.1  christos 		  (opcode->format & LONG_OPCODE) ? 1 : 0, opcode->mask, opcode->format,
    116  1.1  christos 		  opcode->cycles, opcode->unit, opcode->exec_type, opcode->opcode);
    117  1.1  christos 
    118  1.1  christos 	  /* REMOVE ME */
    119  1.1  christos 	  check_opcodes (opcode->opcode);
    120  1.1  christos 	  Opcodes[curop++] = opcode->opcode;
    121  1.1  christos 
    122  1.1  christos 	  j = 0;
    123  1.1  christos 	  for (i=0;i<6;i++)
    124  1.1  christos 	    {
    125  1.1  christos 	      int flags = d10v_operands[opcode->operands[i]].flags;
    126  1.1  christos 	      if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
    127  1.1  christos 		j++;
    128  1.1  christos 	    }
    129  1.1  christos 	  printf ("%d,",j);
    130  1.1  christos 
    131  1.1  christos 	  j = 0;
    132  1.1  christos 	  for (i=0;i<6;i++)
    133  1.1  christos 	    {
    134  1.1  christos 	      int flags = d10v_operands[opcode->operands[i]].flags;
    135  1.1  christos 	      int shift = d10v_operands[opcode->operands[i]].shift;
    136  1.1  christos 	      if ((flags & OPERAND_REG) || (flags & OPERAND_NUM)|| (flags & OPERAND_ADDR))
    137  1.1  christos 		{
    138  1.1  christos 		  if (j == 0)
    139  1.1  christos 		    printf ("{");
    140  1.1  christos 		  else
    141  1.1  christos 		    printf (", ");
    142  1.1  christos 		  if ((flags & OPERAND_REG) && (opcode->format == LONG_L))
    143  1.1  christos 		    shift += 15;
    144  1.1  christos 		  printf ("%d,%d,%d",shift,d10v_operands[opcode->operands[i]].bits,flags);
    145  1.1  christos 		  j = 1;
    146  1.1  christos 		}
    147  1.1  christos 	    }
    148  1.1  christos 	  if (j)
    149  1.1  christos 	    printf ("}");
    150  1.1  christos 	  printf ("},\n");
    151  1.1  christos 	}
    152  1.1  christos     }
    153  1.6  christos   printf ("{ 0,0,0,0,0,0,0,(void (*)())0,0,{0,0,0}},\n};\n");
    154  1.1  christos }
    155