1 |
cebix |
1.1 |
/* |
2 |
|
|
* UAE - The Un*x Amiga Emulator |
3 |
|
|
* |
4 |
|
|
* Read 68000 CPU specs from file "table68k" and build table68k.c |
5 |
|
|
* |
6 |
|
|
* Copyright 1995,1996 Bernd Schmidt |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
#include <assert.h> |
10 |
|
|
#include <ctype.h> |
11 |
|
|
#include <stdio.h> |
12 |
|
|
|
13 |
|
|
#include "sysdeps.h" |
14 |
|
|
#include "readcpu.h" |
15 |
|
|
|
16 |
|
|
static FILE *tablef; |
17 |
|
|
static int nextch = 0; |
18 |
|
|
|
19 |
|
|
static void getnextch(void) |
20 |
|
|
{ |
21 |
|
|
do { |
22 |
|
|
nextch = fgetc(tablef); |
23 |
|
|
if (nextch == '%') { |
24 |
|
|
do { |
25 |
|
|
nextch = fgetc(tablef); |
26 |
|
|
} while (nextch != EOF && nextch != '\n'); |
27 |
|
|
} |
28 |
|
|
} while (nextch != EOF && isspace(nextch)); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
static int nextchtohex(void) |
32 |
|
|
{ |
33 |
|
|
switch (isupper (nextch) ? tolower (nextch) : nextch) { |
34 |
|
|
case '0': return 0; |
35 |
|
|
case '1': return 1; |
36 |
|
|
case '2': return 2; |
37 |
|
|
case '3': return 3; |
38 |
|
|
case '4': return 4; |
39 |
|
|
case '5': return 5; |
40 |
|
|
case '6': return 6; |
41 |
|
|
case '7': return 7; |
42 |
|
|
case '8': return 8; |
43 |
|
|
case '9': return 9; |
44 |
|
|
case 'a': return 10; |
45 |
|
|
case 'b': return 11; |
46 |
|
|
case 'c': return 12; |
47 |
|
|
case 'd': return 13; |
48 |
|
|
case 'e': return 14; |
49 |
|
|
case 'f': return 15; |
50 |
|
|
default: abort(); |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
int main(int argc, char **argv) |
55 |
|
|
{ |
56 |
|
|
int no_insns = 0; |
57 |
|
|
|
58 |
|
|
printf ("#include \"sysdeps.h\"\n"); |
59 |
|
|
printf ("#include \"readcpu.h\"\n"); |
60 |
|
|
printf ("struct instr_def defs68k[] = {\n"); |
61 |
|
|
#if 0 |
62 |
|
|
tablef = fopen("table68k","r"); |
63 |
|
|
if (tablef == NULL) { |
64 |
|
|
fprintf(stderr, "table68k not found\n"); |
65 |
|
|
exit(1); |
66 |
|
|
} |
67 |
|
|
#else |
68 |
|
|
tablef = stdin; |
69 |
|
|
#endif |
70 |
|
|
getnextch(); |
71 |
|
|
while (nextch != EOF) { |
72 |
|
|
int cpulevel, plevel, sduse; |
73 |
|
|
int i; |
74 |
|
|
|
75 |
|
|
char patbits[16]; |
76 |
|
|
char opcstr[256]; |
77 |
|
|
int bitpos[16]; |
78 |
|
|
int flagset[5], flaguse[5]; |
79 |
|
|
|
80 |
|
|
unsigned int bitmask,bitpattern; |
81 |
|
|
int n_variable; |
82 |
|
|
|
83 |
|
|
n_variable = 0; |
84 |
|
|
bitmask = bitpattern = 0; |
85 |
|
|
memset (bitpos, 0, sizeof(bitpos)); |
86 |
|
|
for(i=0; i<16; i++) { |
87 |
|
|
int currbit; |
88 |
|
|
bitmask <<= 1; |
89 |
|
|
bitpattern <<= 1; |
90 |
|
|
|
91 |
|
|
switch (nextch) { |
92 |
|
|
case '0': currbit = bit0; bitmask |= 1; break; |
93 |
|
|
case '1': currbit = bit1; bitmask |= 1; bitpattern |= 1; break; |
94 |
|
|
case 'c': currbit = bitc; break; |
95 |
|
|
case 'C': currbit = bitC; break; |
96 |
|
|
case 'f': currbit = bitf; break; |
97 |
|
|
case 'i': currbit = biti; break; |
98 |
|
|
case 'I': currbit = bitI; break; |
99 |
|
|
case 'j': currbit = bitj; break; |
100 |
|
|
case 'J': currbit = bitJ; break; |
101 |
|
|
case 'k': currbit = bitk; break; |
102 |
|
|
case 'K': currbit = bitK; break; |
103 |
|
|
case 's': currbit = bits; break; |
104 |
|
|
case 'S': currbit = bitS; break; |
105 |
|
|
case 'd': currbit = bitd; break; |
106 |
|
|
case 'D': currbit = bitD; break; |
107 |
|
|
case 'r': currbit = bitr; break; |
108 |
|
|
case 'R': currbit = bitR; break; |
109 |
|
|
case 'z': currbit = bitz; break; |
110 |
|
|
default: abort(); |
111 |
|
|
} |
112 |
|
|
if (!(bitmask & 1)) { |
113 |
|
|
bitpos[n_variable] = currbit; |
114 |
|
|
n_variable++; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
if (nextch == '0' || nextch == '1') |
118 |
|
|
bitmask |= 1; |
119 |
|
|
if (nextch == '1') |
120 |
|
|
bitpattern |= 1; |
121 |
|
|
patbits[i] = nextch; |
122 |
|
|
getnextch(); |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
while (isspace(nextch) || nextch == ':') /* Get CPU and privilege level */ |
126 |
|
|
getnextch(); |
127 |
|
|
|
128 |
|
|
switch (nextch) { |
129 |
|
|
case '0': cpulevel = 0; break; |
130 |
|
|
case '1': cpulevel = 1; break; |
131 |
|
|
case '2': cpulevel = 2; break; |
132 |
|
|
case '3': cpulevel = 3; break; |
133 |
|
|
case '4': cpulevel = 4; break; |
134 |
cebix |
1.2 |
case '5': cpulevel = 5; break; |
135 |
cebix |
1.1 |
default: abort(); |
136 |
|
|
} |
137 |
|
|
getnextch(); |
138 |
|
|
|
139 |
|
|
switch (nextch) { |
140 |
|
|
case '0': plevel = 0; break; |
141 |
|
|
case '1': plevel = 1; break; |
142 |
|
|
case '2': plevel = 2; break; |
143 |
|
|
case '3': plevel = 3; break; |
144 |
|
|
default: abort(); |
145 |
|
|
} |
146 |
|
|
getnextch(); |
147 |
|
|
|
148 |
|
|
while (isspace(nextch)) /* Get flag set information */ |
149 |
|
|
getnextch(); |
150 |
|
|
|
151 |
|
|
if (nextch != ':') |
152 |
|
|
abort(); |
153 |
|
|
|
154 |
|
|
for(i = 0; i < 5; i++) { |
155 |
|
|
getnextch(); |
156 |
|
|
switch(nextch){ |
157 |
|
|
case '-': flagset[i] = fa_unset; break; |
158 |
|
|
case '/': flagset[i] = fa_isjmp; break; |
159 |
|
|
case '0': flagset[i] = fa_zero; break; |
160 |
|
|
case '1': flagset[i] = fa_one; break; |
161 |
|
|
case 'x': flagset[i] = fa_dontcare; break; |
162 |
|
|
case '?': flagset[i] = fa_unknown; break; |
163 |
|
|
default: flagset[i] = fa_set; break; |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
getnextch(); |
168 |
|
|
while (isspace(nextch)) |
169 |
|
|
getnextch(); |
170 |
|
|
|
171 |
|
|
if (nextch != ':') /* Get flag used information */ |
172 |
|
|
abort(); |
173 |
|
|
|
174 |
|
|
for(i = 0; i < 5; i++) { |
175 |
|
|
getnextch(); |
176 |
|
|
switch(nextch){ |
177 |
|
|
case '-': flaguse[i] = fu_unused; break; |
178 |
|
|
case '/': flaguse[i] = fu_isjmp; break; |
179 |
|
|
case '+': flaguse[i] = fu_maybecc; break; |
180 |
|
|
case '?': flaguse[i] = fu_unknown; break; |
181 |
|
|
default: flaguse[i] = fu_used; break; |
182 |
|
|
} |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
getnextch(); |
186 |
|
|
while (isspace(nextch)) |
187 |
|
|
getnextch(); |
188 |
|
|
|
189 |
|
|
if (nextch != ':') /* Get source/dest usage information */ |
190 |
|
|
abort(); |
191 |
|
|
|
192 |
|
|
getnextch(); |
193 |
|
|
sduse = nextchtohex() << 4; |
194 |
|
|
getnextch(); |
195 |
|
|
sduse |= nextchtohex(); |
196 |
|
|
|
197 |
|
|
getnextch(); |
198 |
|
|
while (isspace(nextch)) |
199 |
|
|
getnextch(); |
200 |
|
|
|
201 |
|
|
if (nextch != ':') |
202 |
|
|
abort(); |
203 |
|
|
|
204 |
|
|
fgets(opcstr, 250, tablef); |
205 |
|
|
getnextch(); |
206 |
|
|
{ |
207 |
|
|
int j; |
208 |
|
|
/* Remove superfluous spaces from the string */ |
209 |
|
|
char *opstrp = opcstr, *osendp; |
210 |
|
|
int slen = 0; |
211 |
|
|
|
212 |
|
|
while (isspace(*opstrp)) |
213 |
|
|
opstrp++; |
214 |
|
|
|
215 |
|
|
osendp = opstrp; |
216 |
|
|
while (*osendp) { |
217 |
|
|
if (!isspace (*osendp)) |
218 |
|
|
slen = osendp - opstrp + 1; |
219 |
|
|
osendp++; |
220 |
|
|
} |
221 |
|
|
opstrp[slen] = 0; |
222 |
|
|
|
223 |
|
|
if (no_insns > 0) |
224 |
|
|
printf(",\n"); |
225 |
|
|
no_insns++; |
226 |
|
|
printf("{ %d, %d, {", bitpattern, n_variable); |
227 |
|
|
for (j = 0; j < 16; j++) { |
228 |
|
|
printf("%d", bitpos[j]); |
229 |
|
|
if (j < 15) |
230 |
|
|
printf(","); |
231 |
|
|
} |
232 |
|
|
printf ("}, %d, %d, %d, { ", bitmask, cpulevel, plevel); |
233 |
|
|
for(i = 0; i < 5; i++) { |
234 |
|
|
printf("{ %d, %d }%c ", flaguse[i], flagset[i], i == 4 ? ' ' : ','); |
235 |
|
|
} |
236 |
|
|
printf("}, %d, \"%s\"}", sduse, opstrp); |
237 |
|
|
} |
238 |
|
|
} |
239 |
|
|
printf("};\nint n_defs68k = %d;\n", no_insns); |
240 |
|
|
return 0; |
241 |
|
|
} |