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