--- uae/src/build68k.c 2018/04/24 16:38:39 1.1 +++ uae/src/build68k.c 2018/04/24 17:02:04 1.1.1.6 @@ -1,4 +1,4 @@ -/* +/* * UAE - The Un*x Amiga Emulator * * Read 68000 CPU specs from file "table68k" and build table68k.c @@ -12,8 +12,6 @@ #include #include -#include "config.h" -#include "options.h" #include "readcpu.h" static FILE *tablef; @@ -26,9 +24,32 @@ static void getnextch(void) if (nextch == '%') { do { nextch = fgetc(tablef); - } while (nextch != EOF && nextch != '\n'); + } while (nextch != EOF && nextch != '\n'); } - } while (nextch != EOF && isspace(nextch)); + } while (nextch != EOF && isspace(nextch)); +} + +static int nextchtohex(void) +{ + switch (isupper (nextch) ? tolower (nextch) : nextch) { + case '0': return 0; + case '1': return 1; + case '2': return 2; + case '3': return 3; + case '4': return 4; + case '5': return 5; + case '6': return 6; + case '7': return 7; + case '8': return 8; + case '9': return 9; + case 'a': return 10; + case 'b': return 11; + case 'c': return 12; + case 'd': return 13; + case 'e': return 14; + case 'f': return 15; + default: abort(); + } } int main(int argc, char **argv) @@ -37,28 +58,30 @@ int main(int argc, char **argv) printf ("#include \"sysconfig.h\"\n"); printf ("#include \"sysdeps.h\"\n"); - printf ("#include \"config.h\"\n"); - printf ("#include \"options.h\"\n"); printf ("#include \"readcpu.h\"\n"); printf ("struct instr_def defs68k[] = {\n"); +#if 0 tablef = fopen("table68k","r"); if (tablef == NULL) { fprintf(stderr, "table68k not found\n"); exit(1); } +#else + tablef = stdin; +#endif getnextch(); while (nextch != EOF) { - int cpulevel, plevel; + int cpulevel, plevel, sduse; int i; - + char patbits[16]; char opcstr[256]; int bitpos[16]; int flagset[5], flaguse[5]; - - UWORD bitmask,bitpattern; + + unsigned int bitmask,bitpattern; int n_variable; - + n_variable = 0; bitmask = bitpattern = 0; memset (bitpos, 0, sizeof(bitpos)); @@ -66,7 +89,7 @@ int main(int argc, char **argv) int currbit; bitmask <<= 1; bitpattern <<= 1; - + switch (nextch) { case '0': currbit = bit0; bitmask |= 1; break; case '1': currbit = bit1; bitmask |= 1; bitpattern |= 1; break; @@ -86,32 +109,35 @@ int main(int argc, char **argv) case 'r': currbit = bitr; break; case 'R': currbit = bitR; break; case 'z': currbit = bitz; break; + case 'p': currbit = bitp; break; default: abort(); } if (!(bitmask & 1)) { bitpos[n_variable] = currbit; n_variable++; } - - if (nextch == '0' || nextch == '1') + + if (nextch == '0' || nextch == '1') bitmask |= 1; - if (nextch == '1') + if (nextch == '1') bitpattern |= 1; patbits[i] = nextch; getnextch(); } - + while (isspace(nextch) || nextch == ':') /* Get CPU and privilege level */ getnextch(); - + switch (nextch) { case '0': cpulevel = 0; break; case '1': cpulevel = 1; break; case '2': cpulevel = 2; break; + case '3': cpulevel = 3; break; + case '4': cpulevel = 4; break; default: abort(); } getnextch(); - + switch (nextch) { case '0': plevel = 0; break; case '1': plevel = 1; break; @@ -123,7 +149,7 @@ int main(int argc, char **argv) while (isspace(nextch)) /* Get flag set information */ getnextch(); - + if (nextch != ':') abort(); @@ -132,6 +158,7 @@ int main(int argc, char **argv) switch(nextch){ case '-': flagset[i] = fa_unset; break; case '/': flagset[i] = fa_isjmp; break; + case '+': flagset[i] = fa_isbranch; break; case '0': flagset[i] = fa_zero; break; case '1': flagset[i] = fa_one; break; case 'x': flagset[i] = fa_dontcare; break; @@ -139,11 +166,11 @@ int main(int argc, char **argv) default: flagset[i] = fa_set; break; } } - + getnextch(); while (isspace(nextch)) getnextch(); - + if (nextch != ':') /* Get flag used information */ abort(); @@ -157,17 +184,29 @@ int main(int argc, char **argv) default: flaguse[i] = fu_used; break; } } - + + getnextch(); + while (isspace(nextch)) + getnextch(); + + if (nextch != ':') /* Get source/dest usage information */ + abort(); + + getnextch(); + sduse = nextchtohex() << 4; + getnextch(); + sduse |= nextchtohex(); + getnextch(); while (isspace(nextch)) getnextch(); - + if (nextch != ':') abort(); fgets(opcstr, 250, tablef); getnextch(); - if (cpulevel <= CPU_LEVEL) { + { int j; /* Remove superfluous spaces from the string */ char *opstrp = opcstr, *osendp; @@ -175,7 +214,7 @@ int main(int argc, char **argv) while (isspace(*opstrp)) opstrp++; - + osendp = opstrp; while (*osendp) { if (!isspace (*osendp)) @@ -183,7 +222,7 @@ int main(int argc, char **argv) osendp++; } opstrp[slen] = 0; - + if (no_insns > 0) printf(",\n"); no_insns++; @@ -193,14 +232,13 @@ int main(int argc, char **argv) if (j < 15) printf(","); } - printf ("}, %d, %d, { ", bitmask, plevel); + printf ("}, %d, %d, %d, { ", bitmask, cpulevel, plevel); for(i = 0; i < 5; i++) { printf("{ %d, %d }%c ", flaguse[i], flagset[i], i == 4 ? ' ' : ','); } - printf("}, \"%s\"}", opstrp); + printf("}, %d, \"%s\"}", sduse, opstrp); } } printf("};\nint n_defs68k = %d;\n", no_insns); - fclose(tablef); return 0; }