ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/build68k.c
Revision: 1.7
Committed: 2012-03-30T01:25:46Z (12 years, 8 months ago) by asvitkine
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +14 -0 lines
Log Message:
Add GPLv2 notices to files from UAE Amiga Emulator, as retrieved from the
COPYING file of uae-0.8.29, retrieved from http://www.amigaemulator.org/
via uae-0.8.29.tar.bz2 (MD5 = 54abbabb5e8580b679c52de019141d61).

File Contents

# Content
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 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #include <assert.h>
24 #include <ctype.h>
25 #include <stdio.h>
26
27 #include "sysdeps.h"
28 #include "readcpu.h"
29
30 static FILE *tablef;
31 static int nextch = 0;
32
33 static void getnextch(void)
34 {
35 do {
36 nextch = fgetc(tablef);
37 if (nextch == '%') {
38 do {
39 nextch = fgetc(tablef);
40 } while (nextch != EOF && nextch != '\n');
41 }
42 } while (nextch != EOF && isspace(nextch));
43 }
44
45 static int nextchtohex(void)
46 {
47 switch (isupper (nextch) ? tolower (nextch) : nextch) {
48 case '0': return 0;
49 case '1': return 1;
50 case '2': return 2;
51 case '3': return 3;
52 case '4': return 4;
53 case '5': return 5;
54 case '6': return 6;
55 case '7': return 7;
56 case '8': return 8;
57 case '9': return 9;
58 case 'a': return 10;
59 case 'b': return 11;
60 case 'c': return 12;
61 case 'd': return 13;
62 case 'e': return 14;
63 case 'f': return 15;
64 default: abort();
65 }
66 }
67
68 int main(int argc, char **argv)
69 {
70 int no_insns = 0;
71
72 printf ("#include \"sysdeps.h\"\n");
73 printf ("#include \"readcpu.h\"\n");
74 printf ("struct instr_def defs68k[] = {\n");
75 #ifdef WIN32
76 tablef = fopen(argc > 1 ? argv[1] : "table68k","r");
77 if (tablef == NULL) {
78 fprintf(stderr, "table68k not found\n");
79 exit(1);
80 }
81 #else
82 tablef = stdin;
83 #endif
84 getnextch();
85 while (nextch != EOF) {
86 int cpulevel, plevel, sduse;
87 int i;
88
89 char patbits[16];
90 char opcstr[256];
91 int bitpos[16];
92 int flagset[5], flaguse[5];
93 char cflow;
94
95 unsigned int bitmask,bitpattern;
96 int n_variable;
97
98 n_variable = 0;
99 bitmask = bitpattern = 0;
100 memset (bitpos, 0, sizeof(bitpos));
101 for(i=0; i<16; i++) {
102 int currbit;
103 bitmask <<= 1;
104 bitpattern <<= 1;
105
106 switch (nextch) {
107 case '0': currbit = bit0; bitmask |= 1; break;
108 case '1': currbit = bit1; bitmask |= 1; bitpattern |= 1; break;
109 case 'c': currbit = bitc; break;
110 case 'C': currbit = bitC; break;
111 case 'f': currbit = bitf; break;
112 case 'i': currbit = biti; break;
113 case 'I': currbit = bitI; break;
114 case 'j': currbit = bitj; break;
115 case 'J': currbit = bitJ; break;
116 case 'k': currbit = bitk; break;
117 case 'K': currbit = bitK; break;
118 case 's': currbit = bits; break;
119 case 'S': currbit = bitS; break;
120 case 'd': currbit = bitd; break;
121 case 'D': currbit = bitD; break;
122 case 'r': currbit = bitr; break;
123 case 'R': currbit = bitR; break;
124 case 'z': currbit = bitz; break;
125 case 'E': currbit = bitE; break;
126 case 'p': currbit = bitp; break;
127 default: abort();
128 }
129 if (!(bitmask & 1)) {
130 bitpos[n_variable] = currbit;
131 n_variable++;
132 }
133
134 if (nextch == '0' || nextch == '1')
135 bitmask |= 1;
136 if (nextch == '1')
137 bitpattern |= 1;
138 patbits[i] = nextch;
139 getnextch();
140 }
141
142 while (isspace(nextch) || nextch == ':') /* Get CPU and privilege level */
143 getnextch();
144
145 switch (nextch) {
146 case '0': cpulevel = 0; break;
147 case '1': cpulevel = 1; break;
148 case '2': cpulevel = 2; break;
149 case '3': cpulevel = 3; break;
150 case '4': cpulevel = 4; break;
151 case '5': cpulevel = 5; break;
152 default: abort();
153 }
154 getnextch();
155
156 switch (nextch) {
157 case '0': plevel = 0; break;
158 case '1': plevel = 1; break;
159 case '2': plevel = 2; break;
160 case '3': plevel = 3; break;
161 default: abort();
162 }
163 getnextch();
164
165 while (isspace(nextch)) /* Get flag set information */
166 getnextch();
167
168 if (nextch != ':')
169 abort();
170
171 for(i = 0; i < 5; i++) {
172 getnextch();
173 switch(nextch){
174 case '-': flagset[i] = fa_unset; break;
175 case '0': flagset[i] = fa_zero; break;
176 case '1': flagset[i] = fa_one; break;
177 case 'x': flagset[i] = fa_dontcare; break;
178 case '?': flagset[i] = fa_unknown; break;
179 default: flagset[i] = fa_set; break;
180 }
181 }
182
183 getnextch();
184 while (isspace(nextch))
185 getnextch();
186
187 if (nextch != ':') /* Get flag used information */
188 abort();
189
190 for(i = 0; i < 5; i++) {
191 getnextch();
192 switch(nextch){
193 case '-': flaguse[i] = fu_unused; break;
194 case '?': flaguse[i] = fu_unknown; break;
195 default: flaguse[i] = fu_used; break;
196 }
197 }
198
199 getnextch();
200 while (isspace(nextch))
201 getnextch();
202
203 if (nextch != ':') /* Get control flow information */
204 abort();
205
206 cflow = 0;
207 for(i = 0; i < 2; i++) {
208 getnextch();
209 switch(nextch){
210 case '-': break;
211 case 'R': cflow |= fl_return; break;
212 case 'B': cflow |= fl_branch; break;
213 case 'J': cflow |= fl_jump; break;
214 case 'T': cflow |= fl_trap; break;
215 default: abort();
216 }
217 }
218
219 getnextch();
220 while (isspace(nextch))
221 getnextch();
222
223 if (nextch != ':') /* Get source/dest usage information */
224 abort();
225
226 getnextch();
227 sduse = nextchtohex() << 4;
228 getnextch();
229 sduse |= nextchtohex();
230
231 getnextch();
232 while (isspace(nextch))
233 getnextch();
234
235 if (nextch != ':')
236 abort();
237
238 fgets(opcstr, 250, tablef);
239 getnextch();
240 {
241 int j;
242 /* Remove superfluous spaces from the string */
243 char *opstrp = opcstr, *osendp;
244 int slen = 0;
245
246 while (isspace(*opstrp))
247 opstrp++;
248
249 osendp = opstrp;
250 while (*osendp) {
251 if (!isspace (*osendp))
252 slen = osendp - opstrp + 1;
253 osendp++;
254 }
255 opstrp[slen] = 0;
256
257 if (no_insns > 0)
258 printf(",\n");
259 no_insns++;
260 printf("{ %d, %d, {", bitpattern, n_variable);
261 for (j = 0; j < 16; j++) {
262 printf("%d", bitpos[j]);
263 if (j < 15)
264 printf(",");
265 }
266 printf ("}, %d, %d, %d, { ", bitmask, cpulevel, plevel);
267 for(i = 0; i < 5; i++) {
268 printf("{ %d, %d }%c ", flaguse[i], flagset[i], i == 4 ? ' ' : ',');
269 }
270 printf("}, %d, %d, \"%s\"}", cflow, sduse, opstrp);
271 }
272 }
273 printf("};\nint n_defs68k = %d;\n", no_insns);
274 fflush(stdout);
275 return 0;
276 }