OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [sim/] [d10v/] [gencode.c] - Blame information for rev 865

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.