1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/* Simulation code for the CR16 processor.
Copyright (C) 2008-2015 Free Software Foundation, Inc.
Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com>
This file is part of GDB, the GNU debugger.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "config.h"
#include <stdio.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include "ansidecl.h"
#include "opcode/cr16.h"
static void write_header (void);
static void write_opcodes (void);
static void write_template (void);
int
main (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 (void)
{
int i = 0;
/* Start searching from end of instruction table. */
const inst *instruction = &cr16_instruction[NUMOPCODES - 1];
/* Loop over instruction table until a full match is found. */
for ( ; i < NUMOPCODES; i++)
printf("void OP_%lX_%X (void);\t\t/* %s */\n", cr16_instruction[i].match,
(32 - cr16_instruction[i].match_bits), cr16_instruction[i].mnemonic);
}
/* write_template creates a file all required functions,
ready to be filled out. */
static void
write_template (void)
{
int i = 0,j, k, flags;
printf ("#include \"cr16_sim.h\"\n");
printf ("#include \"simops.h\"\n\n");
for ( ; i < NUMOPCODES; i++)
{
if (cr16_instruction[i].size != 0)
{
printf("/* %s */\nvoid\nOP_%lX_%X ()\n{\n", cr16_instruction[i].mnemonic,
cr16_instruction[i].match, (32 - cr16_instruction[i].match_bits));
/* count operands. */
j = 0;
for (k=0;k<5;k++)
{
if (cr16_instruction[i].operands[k].op_type == dummy)
break;
else
j++;
}
switch (j)
{
case 0:
printf ("printf(\" %s\\n\");\n",cr16_instruction[i].mnemonic);
break;
case 1:
printf ("printf(\" %s\\t%%x\\n\",OP[0]);\n",cr16_instruction[i].mnemonic);
break;
case 2:
printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",cr16_instruction[i].mnemonic);
break;
case 3:
printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",cr16_instruction[i].mnemonic);
break;
default:
fprintf (stderr,"Too many operands: %d\n",j);
}
printf ("}\n\n");
}
}
}
long Opcodes[512];
static int curop=0;
#if 0
static void
check_opcodes( long op)
{
int i;
for (i=0;i<curop;i++)
if (Opcodes[i] == op)
fprintf(stderr,"DUPLICATE OPCODES: %lx\n", op);
}
#endif
static void
write_opcodes (void)
{
int i = 0, j = 0, k;
/* write out opcode table. */
printf ("#include \"cr16_sim.h\"\n");
printf ("#include \"simops.h\"\n\n");
printf ("struct simops Simops[] = {\n");
for (i = NUMOPCODES-1; i >= 0; --i)
{
if (cr16_instruction[i].size != 0)
{
printf (" { \"%s\", %u, %d, %ld, %u, \"OP_%lX_%X\", OP_%lX_%X, ",
cr16_instruction[i].mnemonic, cr16_instruction[i].size,
cr16_instruction[i].match_bits, cr16_instruction[i].match,
cr16_instruction[i].flags, ((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)),
(32 - cr16_instruction[i].match_bits),
((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)), (32 - cr16_instruction[i].match_bits));
j = 0;
for (k=0;k<5;k++)
{
if (cr16_instruction[i].operands[k].op_type == dummy)
break;
else
j++;
}
printf ("%d, ",j);
j = 0;
for (k=0;k<4;k++)
{
int optype = cr16_instruction[i].operands[k].op_type;
int shift = cr16_instruction[i].operands[k].shift;
if (j == 0)
printf ("{");
else
printf (", ");
printf ("{");
printf ("%d,%d",optype, shift);
printf ("}");
j = 1;
}
if (j)
printf ("}");
printf ("},\n");
}
}
printf (" { \"NULL\",1,8,0,0,\"OP_0_20\",OP_0_20,0,{{0,0},{0,0},{0,0},{0,0}}},\n};\n");
}
|