ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/build68k.c
Revision: 1.1.1.1 (vendor branch)
Committed: 1999-10-03T14:16:26Z (25 years, 1 month ago) by cebix
Content type: text/plain
Branch: cebix
CVS Tags: release-0_7-2, snapshot-21101999, start
Changes since 1.1: +0 -0 lines
Log Message:
Imported sources

File Contents

# User Rev Content
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     default: abort();
135     }
136     getnextch();
137    
138     switch (nextch) {
139     case '0': plevel = 0; break;
140     case '1': plevel = 1; break;
141     case '2': plevel = 2; break;
142     case '3': plevel = 3; break;
143     default: abort();
144     }
145     getnextch();
146    
147     while (isspace(nextch)) /* Get flag set information */
148     getnextch();
149    
150     if (nextch != ':')
151     abort();
152    
153     for(i = 0; i < 5; i++) {
154     getnextch();
155     switch(nextch){
156     case '-': flagset[i] = fa_unset; break;
157     case '/': flagset[i] = fa_isjmp; break;
158     case '0': flagset[i] = fa_zero; break;
159     case '1': flagset[i] = fa_one; break;
160     case 'x': flagset[i] = fa_dontcare; break;
161     case '?': flagset[i] = fa_unknown; break;
162     default: flagset[i] = fa_set; break;
163     }
164     }
165    
166     getnextch();
167     while (isspace(nextch))
168     getnextch();
169    
170     if (nextch != ':') /* Get flag used information */
171     abort();
172    
173     for(i = 0; i < 5; i++) {
174     getnextch();
175     switch(nextch){
176     case '-': flaguse[i] = fu_unused; break;
177     case '/': flaguse[i] = fu_isjmp; break;
178     case '+': flaguse[i] = fu_maybecc; break;
179     case '?': flaguse[i] = fu_unknown; break;
180     default: flaguse[i] = fu_used; break;
181     }
182     }
183    
184     getnextch();
185     while (isspace(nextch))
186     getnextch();
187    
188     if (nextch != ':') /* Get source/dest usage information */
189     abort();
190    
191     getnextch();
192     sduse = nextchtohex() << 4;
193     getnextch();
194     sduse |= nextchtohex();
195    
196     getnextch();
197     while (isspace(nextch))
198     getnextch();
199    
200     if (nextch != ':')
201     abort();
202    
203     fgets(opcstr, 250, tablef);
204     getnextch();
205     {
206     int j;
207     /* Remove superfluous spaces from the string */
208     char *opstrp = opcstr, *osendp;
209     int slen = 0;
210    
211     while (isspace(*opstrp))
212     opstrp++;
213    
214     osendp = opstrp;
215     while (*osendp) {
216     if (!isspace (*osendp))
217     slen = osendp - opstrp + 1;
218     osendp++;
219     }
220     opstrp[slen] = 0;
221    
222     if (no_insns > 0)
223     printf(",\n");
224     no_insns++;
225     printf("{ %d, %d, {", bitpattern, n_variable);
226     for (j = 0; j < 16; j++) {
227     printf("%d", bitpos[j]);
228     if (j < 15)
229     printf(",");
230     }
231     printf ("}, %d, %d, %d, { ", bitmask, cpulevel, plevel);
232     for(i = 0; i < 5; i++) {
233     printf("{ %d, %d }%c ", flaguse[i], flagset[i], i == 4 ? ' ' : ',');
234     }
235     printf("}, %d, \"%s\"}", sduse, opstrp);
236     }
237     }
238     printf("};\nint n_defs68k = %d;\n", no_insns);
239     fclose(tablef);
240     return 0;
241     }