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