From: Shamus Hammons Date: Sat, 24 Nov 2012 19:48:52 +0000 (-0600) Subject: First working 64-bit version of RMAC X-Git-Tag: 1.3.0~33 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=commitdiff_plain;h=d16b8ea0ee65b2ad901ca6b0624c07e6e4930cc4 First working 64-bit version of RMAC There's still lots to do, like refactoring a bunch of stuff that's still basically wrong, but that's par for the course. There may be more things that need fixing (like the .rept function, for example). --- diff --git a/debug.c b/debug.c index e3f947a..6ce0065 100644 --- a/debug.c +++ b/debug.c @@ -7,11 +7,14 @@ // #include "debug.h" -#include "sect.h" #include "amode.h" +#include "direct.h" #include "mark.h" +#include "sect.h" +#include "token.h" + -static int siztab[4] = {3, 5, 9, 9}; +static int siztab[4] = { 3, 5, 9, 9 }; // @@ -40,8 +43,9 @@ TOKEN * printexpr(TOKEN * tp) switch ((int)*tp++) { case SYMBOL: - printf("`%s' ", ((SYM *)*tp)->sname); - ++tp; +// printf("`%s' ", ((SYM *)*tp)->sname); + printf("`%s' ", symbolPtr[*tp]->sname); + tp++; break; case CONST: printf("$%ux ", *tp++); @@ -94,7 +98,7 @@ int fudump(CHUNK * ch) p.cp = ch->chptr; ep = ch->chptr + ch->ch_size; - while(p.cp < ep) + while (p.cp < ep) { attr = *p.wp++; loc = *p.lp++; @@ -112,7 +116,7 @@ int fudump(CHUNK * ch) else { printf("`%s' ;\n", (*p.sy)->sname); - ++p.lp; + p.sy++; } } @@ -278,10 +282,12 @@ int dumptok(TOKEN * tk) printf("CONST=%ud", *tk++); break; case STRING: // STRING
- printf("STRING='%s'", (char *)*tk++); +// printf("STRING='%s'", (char *)*tk++); + printf("STRING='%s'", string[*tk++]); break; case SYMBOL: // SYMBOL
- printf("SYMBOL='%s'", (char *)*tk++); +// printf("SYMBOL='%s'", (char *)*tk++); + printf("SYMBOL='%s'", string[*tk++]); break; case EOL: // End of line printf("EOL"); @@ -329,7 +335,7 @@ int dump_everything(void) { int i; - for(i = 1; i < NSECTS; ++i) + for(i=1; isattre & EQUATEDCC)) @@ -296,7 +300,8 @@ int d_equrundef(void) } // Lookup and undef if equated register - regname = lookup((char *)tok[1], LABEL, 0); +// regname = lookup((char *)tok[1], LABEL, 0); + regname = lookup(string[tok[1]], LABEL, 0); if (regname && (regname->sattre & EQUATEDREG)) regname->sattre |= UNDEF_EQUR; @@ -334,7 +339,8 @@ int d_incbin(void) return ERROR; } - if ((j = open((char *)tok[1], _OPEN_INC)) >= 0) +// if ((j = open((char *)tok[1], _OPEN_INC)) >= 0) + if ((j = open(string[tok[1]], _OPEN_INC)) >= 0) { size = lseek(j, 0L, SEEK_END); chcheck(size); @@ -349,7 +355,8 @@ int d_incbin(void) } else { - errors("cannot open include binary file (%s)", (char *)tok[1]); +// errors("cannot open include binary file (%s)", (char *)tok[1]); + errors("cannot open include binary file (%s)", string[tok[1]]); return ERROR; } @@ -595,7 +602,11 @@ int symlist(int(* func)()) if (*tok != SYMBOL) return error(em); +#if 0 if ((*func)(tok[1]) != OK) +#else + if ((*func)(string[tok[1]]) != OK) +#endif break; tok += 2; @@ -624,15 +635,23 @@ int d_include(void) char buf[128]; char buf1[128]; - if (*tok == STRING) // Leave strings ALONE + if (*tok == STRING) // Leave strings ALONE +#if 0 fn = (char *)*++tok; +#else + fn = string[*++tok]; +#endif else if (*tok == SYMBOL) // Try to append ".s" to symbols { +#if 0 strcpy(buf, (char *)*++tok); +#else + strcpy(buf, string[*++tok]); +#endif fext(buf, ".s", 0); fn = &buf[0]; } - else // Punt if no STRING or SYMBOL + else // Punt if no STRING or SYMBOL return error("missing filename"); // Make sure the user didn't try anything like: @@ -640,15 +659,16 @@ int d_include(void) if (*++tok != EOL) return error("extra stuff after filename -- enclose it in quotes"); - // Attempt to open the include file in the current directory, then (if that failed) try list - // of include files passed in the enviroment string or by the "-d" option. + // Attempt to open the include file in the current directory, then (if that + // failed) try list of include files passed in the enviroment string or by + // the "-d" option. if ((j = open(fn, 0)) < 0) { for(i=0; nthpath("RMACPATH", i, buf1)!=0; ++i) { j = strlen(buf1); - if (j > 0 && buf1[j-1] != SLASHCHAR) // Append path char if necessary + if (j > 0 && buf1[j-1] != SLASHCHAR) // Append path char if necessary strcat(buf1, SLASHSTRING); strcat(buf1, fn); @@ -703,7 +723,7 @@ int globl1(char * p) if ((sy = lookup(p, LABEL, 0)) == NULL) { - sy = newsym(p, LABEL, 0); + sy = NewSymbol(p, LABEL, 0); sy->svalue = 0; sy->sattr = GLOBAL; } @@ -854,12 +874,13 @@ int d_dc(WORD siz) // dc.b 'string' [,] ... if (siz == SIZB && *tok == STRING && (tok[2] == ',' || tok[2] == EOL)) { - i = strlen((const char*)tok[1]); +// i = strlen((const char*)tok[1]); + i = strlen(string[tok[1]]); if ((challoc - ch_size) < i) chcheck(i); - for(p=(char *)tok[1]; *p!=EOS; ++p) + for(p=string[tok[1]]; *p!=EOS; ++p) D_byte(*p); tok += 2; @@ -1144,29 +1165,30 @@ int d_comm(void) if (*tok != SYMBOL) return error("missing symbol"); - p = (char *)tok[1]; +// p = (char *)tok[1]; + p = string[tok[1]]; tok += 2; - if (*p == '.') // Cannot .comm a local symbol + if (*p == '.') // Cannot .comm a local symbol return error(locgl_error); if ((sym = lookup(p, LABEL, 0)) == NULL) - sym = newsym(p, LABEL, 0); + sym = NewSymbol(p, LABEL, 0); else { if (sym->sattr & DEFINED) return error(".comm symbol already defined"); } - sym->sattr = GLOBAL|COMMON|BSS; + sym->sattr = GLOBAL | COMMON | BSS; if (*tok++ != ',') return error(comma_error); - if (abs_expr(&eval) != OK) // Parse size of common region + if (abs_expr(&eval) != OK) // Parse size of common region return 0; - sym->svalue = eval; // Install common symbol's size + sym->svalue = eval; // Install common symbol's size at_eol(); return 0; } @@ -1323,7 +1345,7 @@ int d_cargs(void) if (abs_expr(&eval) != OK) return 0; - if (*tok == ',') // Eat comma if it's there + if (*tok == ',') // Eat comma if it's there ++tok; } else @@ -1333,7 +1355,8 @@ int d_cargs(void) { if (*tok == SYMBOL) { - p = (char *)tok[1]; +// p = (char *)tok[1]; + p = string[tok[1]]; if (*p == '.') env = curenv; @@ -1344,7 +1367,7 @@ int d_cargs(void) if (sy == NULL) { - sy = newsym(p, LABEL, env); + sy = NewSymbol(p, LABEL, env); sy->sattr = 0; } else if (sy->sattr & DEFINED) diff --git a/direct.h b/direct.h index 24961c3..732a52e 100644 --- a/direct.h +++ b/direct.h @@ -13,6 +13,7 @@ // Globals, Externals etc extern TOKEN exprbuf[]; +extern SYM * symbolPtr[]; extern int (* dirtab[])(); // Prototypes diff --git a/error.c b/error.c index c73cec5..e17dcc7 100644 --- a/error.c +++ b/error.c @@ -69,7 +69,7 @@ void err_setup(void) // // Display Error Message // -int error(char * s) +int error(const char * s) { char buf[EBUFSIZ]; unsigned int length; @@ -88,7 +88,7 @@ int error(char * s) printf("%s", buf); taglist('E'); - ++errcnt; + errcnt++; return ERROR; } diff --git a/error.h b/error.h index 7754792..f0e9ed6 100644 --- a/error.h +++ b/error.h @@ -18,7 +18,7 @@ extern int errcnt; extern char * err_fname; // Prototypes -int error(char *); +int error(const char *); int errors(char *, char *); int fatal(char *); int warn(char *); diff --git a/expr.c b/expr.c index 84018bd..6e0bd18 100644 --- a/expr.c +++ b/expr.c @@ -7,14 +7,15 @@ // #include "expr.h" -#include "token.h" -#include "listing.h" +#include "direct.h" #include "error.h" -#include "procln.h" -#include "symbol.h" -#include "sect.h" +#include "listing.h" #include "mach.h" +#include "procln.h" #include "risca.h" +#include "sect.h" +#include "symbol.h" +#include "token.h" #define DEF_KW // Declare keyword values #include "kwtab.h" // Incl generated keyword tables & defs @@ -43,13 +44,13 @@ char itokcl[] = { 1 // (the end) }; -char missym_error[] = "missing symbol"; -char * str_error = "missing symbol or string"; +const char missym_error[] = "missing symbol"; +const char str_error[] = "missing symbol or string"; // Convert expression to postfix -static TOKEN * tk; // Deposit tokens here -SYM * lookup(); -SYM * newsym(); +static TOKEN * tk; // Deposit tokens here (this is really a + // pointer to exprbuf from direct.c) +static symbolNum; // Pointer to the entry in symbolPtr[] // @@ -71,11 +72,11 @@ static VALUE str_value(char * p) // void init_expr(void) { - int i; // Iterator - char * p; // Token pointer + int i; // Iterator + char * p; // Token pointer // Initialize token-class table - for(i=0; i<128; ++i) // Mark all entries END + for(i=0; i<128; ++i) // Mark all entries END tokcl[i] = END; for(i=0, p=itokcl; *p!=1; p++) @@ -85,6 +86,8 @@ void init_expr(void) else tokcl[(int)(*p)] = (char)i; } + + symbolNum = 0; } @@ -154,12 +157,20 @@ int expr1(void) if (*tok++ != SYMBOL) return error(missym_error); +#if 0 p = (char *)*tok++; +#else + p = string[*tok++]; +#endif +#if 0 if (lookup(p, MACRO, 0) == NULL) w = 0; else w = 1; +#else + w = (lookup(p, MACRO, 0) == NULL ? 0 : 1); +#endif *tk++ = CONST; *tk++ = (TOKEN)w; @@ -173,16 +184,24 @@ getsym: if (*tok++ != SYMBOL) return error(missym_error); +#if 0 p = (char *)*tok++; +#else + p = string[*tok++]; +#endif j = 0; if (*p == '.') j = curenv; +#if 0 if ((sy = lookup(p, LABEL, j)) != NULL && (sy->sattr & w)) w = 1; else w = 0; +#else + w = ((sy = lookup(p, LABEL, j)) != NULL && (sy->sattr & w) ? 1 : 0); +#endif *tk++ = CONST; *tk++ = (TOKEN)w; @@ -191,7 +210,11 @@ getsym: if (*tok != SYMBOL && *tok != STRING) return error(str_error); +#if 0 p = (char *)tok[1]; +#else + p = string[tok[1]]; +#endif tok +=2; if (*tok++ != ',') @@ -200,7 +223,11 @@ getsym: if (*tok != SYMBOL && *tok != STRING) return error(str_error); +#if 0 p2 = (char *)tok[1]; +#else + p = string[tok[1]]; +#endif tok += 2; w = (WORD)(!strcmp(p, p2)); @@ -232,7 +259,11 @@ int expr2(void) *tk++ = *tok++; break; case SYMBOL: +#if 0 p = (char *)*tok++; +#else + p = string[*tok++]; +#endif j = 0; if (*p == '.') @@ -241,7 +272,7 @@ int expr2(void) sy = lookup(p, LABEL, j); if (sy == NULL) - sy = newsym(p, LABEL, j); + sy = NewSymbol(p, LABEL, j); // Check register bank usage if (sy->sattre & EQUATEDREG) @@ -254,11 +285,21 @@ int expr2(void) } *tk++ = SYMBOL; +#if 0 *tk++ = (TOKEN)sy; +#else + *tk++ = symbolNum; + symbolPtr[symbolNum] = sy; + symbolNum++; +#endif break; case STRING: *tk++ = CONST; +#if 0 *tk++ = str_value((char *)*tok++); +#else + *tk++ = str_value(string[*tok++]); +#endif break; case '(': if (expr0() != OK) @@ -308,7 +349,8 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) char * p; int j; - tk = otk; + tk = otk; // Set token pointer to 'exprbuf' (direct.c) +// symbolNum = 0; // Set symbol number in symbolPtr[] to 0 // Optimize for single constant or single symbol. if ((tok[1] == EOL) @@ -356,7 +398,11 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) } else { +#if 0 p = (char *)tok[1]; +#else + p = string[tok[1]]; +#endif j = 0; if (*p == '.') @@ -365,7 +411,7 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) sy = lookup(p, LABEL, j); if (sy == NULL) - sy = newsym(p, LABEL, j); + sy = NewSymbol(p, LABEL, j); sy->sattr |= REFERENCED; @@ -380,7 +426,13 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) } *tk++ = SYMBOL; +#if 0 *tk++ = (TOKEN)sy; +#else + *tk++ = symbolNum; + symbolPtr[symbolNum] = sy; + symbolNum++; +#endif if (sy->sattr & DEFINED) *a_value = sy->svalue; @@ -392,7 +444,7 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) *a_attr = (WORD)(sy->sattr & ~GLOBAL); - if ((sy->sattr & (GLOBAL|DEFINED)) == GLOBAL && a_esym != NULL) + if ((sy->sattr & (GLOBAL | DEFINED)) == GLOBAL && a_esym != NULL) *a_esym = sy; } @@ -424,9 +476,9 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) SYM * esym; WORD sym_seg; - sval = evstk; // (Empty) initial stack + sval = evstk; // (Empty) initial stack sattr = evattr; - esym = NULL; // No external symbol involved + esym = NULL; // No external symbol involved sym_seg = 0; while (*tk != ENDEXPR) @@ -434,19 +486,21 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) switch ((int)*tk++) { case SYMBOL: - sy = (SYM *)*tk++; - sy->sattr |= REFERENCED; // Set "referenced" bit +// sy = (SYM *)*tk++; + sy = symbolPtr[*tk++]; + sy->sattr |= REFERENCED; // Set "referenced" bit if (!(sy->sattr & DEFINED)) { + // Reference to undefined symbol if (!(sy->sattr & GLOBAL)) - { // Reference to undefined symbol + { *a_attr = 0; *a_value = 0; return OK; } - if (esym != NULL) // Check for multiple externals + if (esym != NULL) // Check for multiple externals return error(seg_error); esym = sy; @@ -454,23 +508,23 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) if (sy->sattr & DEFINED) { - *++sval = sy->svalue; // Push symbol's value + *++sval = sy->svalue; // Push symbol's value } else { - *++sval = 0; // 0 for undefined symbols + *++sval = 0; // 0 for undefined symbols } - *++sattr = (WORD)(sy->sattr & ~GLOBAL); // Push attribs - sym_seg = (WORD)(sy->sattr & (TEXT|DATA|BSS)); + *++sattr = (WORD)(sy->sattr & ~GLOBAL); // Push attribs + sym_seg = (WORD)(sy->sattr & (TEXT | DATA | BSS)); break; case CONST: - *++sval = *tk++; // Push value - *++sattr = ABS|DEFINED; // Push simple attribs + *++sval = *tk++; // Push value + *++sattr = ABS | DEFINED; // Push simple attribs break; case ACONST: - *++sval = *tk++; // Push value - *++sattr = (WORD)*tk++; // Push attribs + *++sval = *tk++; // Push value + *++sattr = (WORD)*tk++; // Push attribs break; // Binary "+" and "-" matrix: @@ -485,58 +539,58 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) // [1] + : Error // - : ABS case '+': - --sval; // Pop value - --sattr; // Pop attrib - *sval += sval[1]; // Compute value + --sval; // Pop value + --sattr; // Pop attrib + *sval += sval[1]; // Compute value - if (!(*sattr & (TEXT|DATA|BSS))) + if (!(*sattr & (TEXT | DATA | BSS))) *sattr = sattr[1]; - else if (sattr[1] & (TEXT|DATA|BSS)) + else if (sattr[1] & (TEXT | DATA | BSS)) return error(seg_error); break; case '-': - --sval; // Pop value - --sattr; // Pop attrib - *sval -= sval[1]; // Compute value + --sval; // Pop value + --sattr; // Pop attrib + *sval -= sval[1]; // Compute value - attr = (WORD)(*sattr & (TEXT|DATA|BSS)); + attr = (WORD)(*sattr & (TEXT | DATA | BSS)); if (!attr) *sattr = sattr[1]; - else if (sattr[1] & (TEXT|DATA|BSS)) + else if (sattr[1] & (TEXT | DATA | BSS)) { if (!(attr & sattr[1])) return error(seg_error); else - *sattr &= ~(TEXT|DATA|BSS); + *sattr &= ~(TEXT | DATA | BSS); } break; - // Unary operators only work on ABS items + // Unary operators only work on ABS items case UNMINUS: - if (*sattr & (TEXT|DATA|BSS)) + if (*sattr & (TEXT | DATA | BSS)) error(seg_error); *sval = -(int)*sval; - *sattr = ABS|DEFINED; // Expr becomes absolute + *sattr = ABS | DEFINED; // Expr becomes absolute break; case '!': - if (*sattr & (TEXT|DATA|BSS)) + if (*sattr & (TEXT | DATA | BSS)) error(seg_error); *sval = !*sval; - *sattr = ABS|DEFINED; // Expr becomes absolute + *sattr = ABS | DEFINED; // Expr becomes absolute break; case '~': - if (*sattr & (TEXT|DATA|BSS)) + if (*sattr & (TEXT | DATA | BSS)) error(seg_error); *sval = ~*sval; - *sattr = ABS|DEFINED; // Expr becomes absolute + *sattr = ABS | DEFINED; // Expr becomes absolute break; - // Comparison operators must have two values that - // are in the same segment, but that's the only requirement. + // Comparison operators must have two values that + // are in the same segment, but that's the only requirement. case LE: --sattr; --sval; @@ -544,7 +598,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) if ((*sattr & TDB) != (sattr[1] & TDB)) error(seg_error); - *sattr = ABS|DEFINED; + *sattr = ABS | DEFINED; *sval = *sval <= sval[1]; break; case GE: @@ -554,7 +608,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) if ((*sattr & TDB) != (sattr[1] & TDB)) error(seg_error); - *sattr = ABS|DEFINED; + *sattr = ABS | DEFINED; *sval = *sval >= sval[1]; break; case '>': @@ -564,7 +618,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) if ((*sattr & TDB) != (sattr[1] & TDB)) error(seg_error); - *sattr = ABS|DEFINED; + *sattr = ABS | DEFINED; *sval = *sval > sval[1]; break; case '<': @@ -574,7 +628,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) if ((*sattr & TDB) != (sattr[1] & TDB)) error(seg_error); - *sattr = ABS|DEFINED; + *sattr = ABS | DEFINED; *sval = *sval < sval[1]; break; case NE: @@ -584,7 +638,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) if ((*sattr & TDB) != (sattr[1] & TDB)) error(seg_error); - *sattr = ABS|DEFINED; + *sattr = ABS | DEFINED; *sval = *sval != sval[1]; break; case '=': @@ -594,27 +648,27 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) if ((*sattr & TDB) != (sattr[1] & TDB)) error(seg_error); - *sattr = ABS|DEFINED; + *sattr = ABS | DEFINED; *sval = *sval == sval[1]; break; - // All other binary operators must have two ABS items - // to work with. They all produce an ABS value. + // All other binary operators must have two ABS items + // to work with. They all produce an ABS value. default: // GH - Removed for v1.0.15 as part of the fix for indexed loads. //if ((*sattr & (TEXT|DATA|BSS)) || (*--sattr & (TEXT|DATA|BSS))) //error(seg_error); - *sattr = ABS|DEFINED; // Expr becomes absolute + *sattr = ABS | DEFINED; // Expr becomes absolute switch ((int)tk[-1]) { case '*': --sval; - --sattr; // Pop attrib + --sattr; // Pop attrib *sval *= sval[1]; break; case '/': --sval; - --sattr; // Pop attrib + --sattr; // Pop attrib if (sval[1] == 0) return error("divide by zero"); @@ -623,7 +677,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) break; case '%': --sval; - --sattr; // Pop attrib + --sattr; // Pop attrib if (sval[1] == 0) return error("mod (%) by zero"); @@ -632,31 +686,31 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) break; case SHL: --sval; - --sattr; // Pop attrib + --sattr; // Pop attrib *sval <<= sval[1]; break; case SHR: --sval; - --sattr; // Pop attrib + --sattr; // Pop attrib *sval >>= sval[1]; break; case '&': --sval; - --sattr; // Pop attrib + --sattr; // Pop attrib *sval &= sval[1]; break; case '^': --sval; - --sattr; // Pop attrib + --sattr; // Pop attrib *sval ^= sval[1]; break; case '|': --sval; - --sattr; // Pop attrib + --sattr; // Pop attrib *sval |= sval[1]; break; default: - interror(5); // Bad operator in expression stream + interror(5); // Bad operator in expression stream } } } @@ -672,7 +726,7 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) // overiding the symbol segments and not being included :( //*a_attr = *sattr | sym_seg; // Copy value + attrib - *a_attr = *sattr; // Copy value + attrib + *a_attr = *sattr; // Copy value + attrib *a_value = *sval; return OK; diff --git a/listing.c b/listing.c index cea150b..82d2520 100644 --- a/listing.c +++ b/listing.c @@ -204,7 +204,7 @@ void taglist(char chr) // // Print a Line to the Listing File // -void println(char * ln) +void println(const char * ln) { unsigned int length; @@ -220,7 +220,7 @@ void println(char * ln) // // Ship Line `ln' Out; Do Page Breaks and Title Stuff // -void ship_ln(char * ln) +void ship_ln(const char * ln) { // If listing level is <= 0, then don't print anything if (listing <= 0) @@ -443,7 +443,8 @@ int d_subttl(void) if (*tok != STRING) return error("missing string"); - strcpy(subttl, (char *)tok[1]); +// strcpy(subttl, (char *)tok[1]); + strcpy(subttl, string[tok[1]]); tok += 2; @@ -464,7 +465,8 @@ int d_title(void) if (*tok != STRING) return error("missing string"); - strcpy(title, (char*)tok[1]); +// strcpy(title, (char*)tok[1]); + strcpy(title, string[tok[1]]); tok += 2; if (pageno > 1) diff --git a/listing.h b/listing.h index 7dd5761..f674ea6 100644 --- a/listing.h +++ b/listing.h @@ -31,9 +31,9 @@ extern LONG lsloc; // Prototypes void init_list(void); -void ship_ln(char *); +void ship_ln(const char *); void taglist(char); -void println(char *); +void println(const char *); void listeol(void); VALUE dos_date(void); VALUE dos_time(void); diff --git a/mach.c b/mach.c index fac29e3..47896a9 100644 --- a/mach.c +++ b/mach.c @@ -18,13 +18,13 @@ #include "kwtab.h" // Common error messages -char * range_error = "expression out of range"; -char * abs_error = "illegal absolute expression"; -char * seg_error = "bad (section) expression"; -char * rel_error = "illegal relative address"; -char * siz_error = "bad size specified"; -char * undef_error = "undefined expression"; -char * fwd_error = "forward or undefined expression"; +char range_error[] = "expression out of range"; +char abs_error[] = "illegal absolute expression"; +char seg_error[] = "bad (section) expression"; +char rel_error[] = "illegal relative address"; +char siz_error[] = "bad size specified"; +char undef_error[] = "undefined expression"; +char fwd_error[] = "forward or undefined expression"; extern int ea0gen(WORD); extern int ea1gen(WORD); @@ -445,9 +445,10 @@ int m_moveq(WORD inst, WORD siz) { siz = siz; + // Arrange for future fixup if (!(a0exattr & DEFINED)) - { // Arrange for future fixup - fixup(FU_BYTE|FU_SEXT, sloc+1, a0expr); + { + fixup(FU_BYTE | FU_SEXT, sloc + 1, a0expr); a0exval = 0; } else if (a0exval + 0x100 >= 0x200) diff --git a/mach.h b/mach.h index 65ea148..2240950 100644 --- a/mach.h +++ b/mach.h @@ -13,11 +13,11 @@ #include "amode.h" // Globals, Externals etc -extern char *seg_error; -extern char *undef_error; -extern char *rel_error; -extern char *range_error; -extern char *abs_error; +extern char seg_error[]; +extern char undef_error[]; +extern char rel_error[]; +extern char range_error[]; +extern char abs_error[]; extern MNTAB machtab[]; // Prototypes diff --git a/macro.c b/macro.c index 8731fb8..6c67bb6 100644 --- a/macro.c +++ b/macro.c @@ -7,22 +7,24 @@ // #include "macro.h" -#include "token.h" +#include "debug.h" +#include "direct.h" #include "error.h" #include "expr.h" #include "listing.h" -#include "symbol.h" #include "procln.h" -#include "direct.h" -#include "debug.h" +#include "symbol.h" +#include "token.h" LONG curuniq; // Current macro's unique number -TOKEN ** argp; // Free spot in argptrs[] +//TOKEN ** argp; // Free spot in argptrs[] int macnum; // Unique number for macro definition +TOKEN * argPtrs[128]; // 128 arguments ought to be enough for anyone +static int argp; static LONG macuniq; // Unique-per-macro number static SYM * curmac; // Macro currently being defined -static char ** curmln; // Previous macro line (or NULL) +//static char ** curmln; // Previous macro line (or NULL) static VALUE argno; // Formal argument count static LONG * firstrpt; // First .rept line @@ -37,22 +39,20 @@ void init_macro(void) { macuniq = 0; macnum = 1; - argp = NULL; +// argp = NULL; + argp = 0; ib_macro(); } // // Exit from a Macro; -// o pop any intervening include files and repeat blocks; -// o restore argument stack; -// o pop the macro. +// -- pop any intervening include files and repeat blocks; +// -- restore argument stack; +// -- pop the macro. // int exitmac(void) { - IMACRO * imacro; - TOKEN ** p; - // Pop intervening include files and .rept blocks while (cur_inobj != NULL && cur_inobj->in_type != SRC_IMACRO) fpop(); @@ -65,16 +65,14 @@ int exitmac(void) // o old unique number // ...and then pop the macro. - imacro = cur_inobj->inobj.imacro; + IMACRO * imacro = cur_inobj->inobj.imacro; curuniq = imacro->im_olduniq; - p = --argp; - argp = (TOKEN **)*argp; + /*TOKEN ** p = */argp--; +// argp = (TOKEN **)*argp; fpop(); - mjump_align = 0; - return 0; } @@ -87,8 +85,9 @@ int defmac2(char * argname) SYM * arg; if (lookup(argname, MACARG, (int)curmac->sattr) != NULL) - return(error("multiple formal argument definition")); - arg = newsym(argname, MACARG, (int)curmac->sattr); + return error("multiple formal argument definition"); + + arg = NewSymbol(argname, MACARG, (int)curmac->sattr); arg->svalue = argno++; return OK; @@ -98,39 +97,74 @@ int defmac2(char * argname) // // Add a line to a macro definition; also print lines to listing file (if // enabled). The last line of the macro (containing .endm) is not included in -// the macro. A label on that line will be lost. `endflg' is misleading here. -// It is -1 for all lines but the last one (.endm), when it is 0. +// the macro. A label on that line will be lost. +// notEndFlag is -1 for all lines but the last one (.endm), when it is 0. // -int defmac1(char * ln, int endflg) +int defmac1(char * ln, int notEndFlag) { PTR p; LONG len; if (list_flag) { - listeol(); // Flush previous source line - lstout('.'); // Mark macro definition with period + listeol(); // Flush previous source line + lstout('.'); // Mark macro definition with period } - if (endflg) + // This is just wrong, wrong, wrong. It makes up a weird kind of string with + // a pointer on front, and then uses a ** to manage them: This is a recipe + // for disaster. + // How to manage it then? + // Could use a linked list, like Landon uses everywhere else. +/* +How it works: +Allocate a space big enough for the string + NULL + pointer. +Set the pointer to NULL. +Copy the string to the space after the pointer. +If this is the 1st time through, set the SYM * "svalue" to the pointer. +If this is the 2nd time through, derefence the ** to point to the memory you just allocated. +Then, set the ** to the location of the memory you allocated for the next pass through. + +This is a really low level way to do a linked list, and by bypassing all the safety +features of the language. Seems like we can do better here. +*/ + if (notEndFlag) { +#if 0 len = strlen(ln) + 1 + sizeof(LONG); -// p.cp = amem(len); p.cp = malloc(len); *p.lp = 0; strcpy(p.cp + sizeof(LONG), ln); // Link line of text onto end of list if (curmln == NULL) - curmac->svalue = (VALUE)p.cp; + curmac->svalue = p.cp; else *curmln = p.cp; curmln = (char **)p.cp; - return 1; // Keep looking + return 1; // Keep looking +#else + if (curmac->lineList == NULL) + { + curmac->lineList = malloc(sizeof(struct LineList)); + curmac->lineList->next = NULL; + curmac->lineList->line = strdup(ln); + curmac->last = curmac->lineList; + } + else + { + curmac->last->next = malloc(sizeof(struct LineList)); + curmac->last->next->next = NULL; + curmac->last->next->line = strdup(ln); + curmac->last = curmac->last->next; + } + + return 1; // Keep looking +#endif } - else - return 0; // Stop looking at the end + + return 0; // Stop looking at the end } @@ -147,24 +181,22 @@ int defmac1(char * ln, int endflg) // `defmac1' adds lines of text to the macro definition // `defmac2' processes the formal arguments (and sticks them into the symbol table) // -int defmac(void) +int DefineMacro(void) { - char * p; - SYM * mac; - - // Setup entry in symbol table, make sure the macro isn't a duplicate entry, and that - // it doesn't override any processor mnemonic or assembler directive. + // Setup entry in symbol table, make sure the macro isn't a duplicate + // entry, and that it doesn't override any processor mnemonic or assembler + // directive. if (*tok++ != SYMBOL) return error("missing symbol"); - p = (char *)*tok++; + char * name = string[*tok++]; - if (lookup(p, MACRO, 0) != NULL) - return error("multiple macro definition"); + if (lookup(name, MACRO, 0) != NULL) + return error("duplicate macro definition"); - curmac = mac = newsym(p, MACRO, 0); - mac->svalue = 0; - mac->sattr = (WORD)(macnum++); + curmac = NewSymbol(name, MACRO, 0); + curmac->svalue = 0; + curmac->sattr = (WORD)(macnum++); // Parse and define formal arguments in symbol table if (*tok != EOL) @@ -176,7 +208,8 @@ int defmac(void) // Suck in the macro definition; we're looking for an ENDM symbol on a line // by itself to terminate the definition. - curmln = NULL; +// curmln = NULL; + curmac->lineList = NULL; lncatch(defmac1, "endm "); return 0; @@ -204,8 +237,10 @@ int defr1(char * ln, int kwno) return(0); goto addln; case 1: // .rept - ++rptlevel; + rptlevel++; default: +//MORE stupidity here... +#warning "!!! Casting (char *) as LONG !!!" addln: // Allocate length of line + 1('\0') + LONG len = strlen(ln) + 1 + sizeof(LONG); @@ -286,7 +321,7 @@ int lncatch(int (* lnfunc)(), char * dirlist) int k; if (lnfunc != NULL) - ++lnsave; // Tell tokenizer to keep lines + lnsave++; // Tell tokenizer to keep lines for(;;) { @@ -307,18 +342,26 @@ int lncatch(int (* lnfunc)(), char * dirlist) if ((tok[2] == ':' || tok[2] == DCOLON)) { if (tok[3] == SYMBOL) // label: symbol +#if 0 p = (char *)tok[4]; +#else + p = string[tok[4]]; +#endif } else { +#if 0 p = (char *)tok[1]; // symbol +#else + p = string[tok[1]]; // Symbol +#endif } } if (p != NULL) { if (*p == '.') // ignore leading '.'s - ++p; + p++; k = kwmatch(p, dirlist); } @@ -334,7 +377,7 @@ int lncatch(int (* lnfunc)(), char * dirlist) } if (lnfunc != NULL) - --lnsave; // Tell tokenizer to stop keeping lines + lnsave--; // Tell tokenizer to stop keeping lines return 0; } @@ -374,7 +417,7 @@ int kwmatch(char * kw, char * kwlist) ++kwlist; if (*kwlist== ' ') - ++kwlist; + kwlist++; } return -1; @@ -386,16 +429,14 @@ int kwmatch(char * kw, char * kwlist) // o parse, count and copy arguments // o push macro's string-stream // -int invokemac(SYM * mac, WORD siz) +int InvokeMacro(SYM * mac, WORD siz) { TOKEN * p = NULL; - IMACRO * imacro; - INOBJ * inobj; int dry_run; - WORD nargs; WORD arg_siz = 0; - TOKEN ** argptr = NULL; - TOKEN * beg_tok; +// TOKEN ** argptr = NULL; +//Doesn't need to be global! (or does it???) + argp = 0; if ((!strcmp(mac->sname, "mjump") || !strcmp(mac->sname, "mpad")) && !in_main) { @@ -403,20 +444,24 @@ int invokemac(SYM * mac, WORD siz) return ERROR; } - inobj = a_inobj(SRC_IMACRO); // Alloc and init IMACRO - imacro = inobj->inobj.imacro; + INOBJ * inobj = a_inobj(SRC_IMACRO); // Alloc and init IMACRO + IMACRO * imacro = inobj->inobj.imacro; imacro->im_siz = siz; - nargs = 0; - beg_tok = tok; // 'tok' comes from token.c + WORD nargs = 0; + TOKEN * beg_tok = tok; // 'tok' comes from token.c - for(dry_run=1;; --dry_run) + for(dry_run=1; ; dry_run--) { for(tok=beg_tok; *tok!=EOL;) { if (dry_run) nargs++; else +#if 0 *argptr++ = p; +#else + argPtrs[argp++] = p; +#endif // Keep going while tok isn't pointing at a comma or EOL while (*tok != ',' && *tok != EOL) @@ -468,12 +513,17 @@ int invokemac(SYM * mac, WORD siz) { if (nargs != 0) //Barfing here with memory corruption in glibc. TOKEN is defined as LONG, which is uint32_t -// p = (TOKEN *)malloc(arg_siz + 1); - p = (TOKEN *)malloc(arg_siz + sizeof(TOKEN)); + p = (TOKEN *)malloc(arg_siz); +// p = (TOKEN *)malloc(arg_siz + sizeof(TOKEN)); +// This construct is meant to deal with nested macros, so the simple minded way +// we deal with them now won't work. :-/ Have to think about how to fix. +#if 0 argptr = (TOKEN **)malloc((nargs + 1) * sizeof(LONG)); *argptr++ = (TOKEN *)argp; argp = argptr; +#else +#endif } else break; @@ -487,18 +537,10 @@ int invokemac(SYM * mac, WORD siz) // o bump `macuniq' counter and set 'curuniq' to it; imacro->im_nargs = nargs; imacro->im_macro = mac; - imacro->im_nextln = (TOKEN *)mac->svalue; +// imacro->im_nextln = (TOKEN *)mac->svalue; + imacro->im_nextln = mac->lineList; imacro->im_olduniq = curuniq; curuniq = macuniq++; -/*IMACRO { - IMACRO * im_link; // Pointer to ancient IMACROs - LONG * im_nextln; // Next line to include - WORD im_nargs; // # of arguments supplied on invocation - WORD im_siz; // Size suffix supplied on invocation - LONG im_olduniq; // Old value of 'macuniq' - SYM * im_macro; // Pointer to macro we're in - char im_lnbuf[LNSIZ]; // Line buffer -};*/ DEBUG { @@ -507,7 +549,8 @@ int invokemac(SYM * mac, WORD siz) for(nargs=0; nargsim_nargs; ++nargs) { printf("arg%d=", nargs); - dumptok(argp[imacro->im_nargs - nargs - 1]); +// dumptok(argp[imacro->im_nargs - nargs - 1]); + dumptok(argPtrs[imacro->im_nargs - nargs - 1]); } } @@ -520,40 +563,41 @@ int invokemac(SYM * mac, WORD siz) // void ib_macro(void) { - SYM * mac; - - curmac = mac = newsym("mjump", MACRO, 0); - mac->svalue = 0; - mac->sattr = (WORD)(macnum++); + curmac = NewSymbol("mjump", MACRO, 0); + curmac->svalue = 0; + curmac->sattr = (WORD)(macnum++); argno = 0; defmac2("cc"); defmac2("addr"); defmac2("jreg"); - curmln = NULL; - defmac1(" nop", -1); - defmac1(" movei #\\addr,\\jreg", -1); - defmac1(" jump \\cc,(\\jreg)", -1); - defmac1(" nop", -1); - defmac1(" nop", -1); - - curmac = mac = newsym("mjr", MACRO, 0); - mac->svalue = 0; - mac->sattr = (WORD)(macnum++); +// curmln = NULL; + curmac->lineList = NULL; + defmac1(" nop", -1); + defmac1(" movei #\\addr,\\jreg", -1); + defmac1(" jump \\cc,(\\jreg)", -1); + defmac1(" nop", -1); + defmac1(" nop", -1); + + curmac = NewSymbol("mjr", MACRO, 0); + curmac->svalue = 0; + curmac->sattr = (WORD)(macnum++); argno = 0; defmac2("cc"); defmac2("addr"); - curmln = NULL; - defmac1(" jr \\cc,\\addr", -1); - defmac1(" nop", -1); - defmac1(" nop", -1); - - curmac = mac = newsym("mpad", MACRO, 0); - mac->svalue = 0; - mac->sattr = (WORD)(macnum++); +// curmln = NULL; + curmac->lineList = NULL; + defmac1(" jr \\cc,\\addr", -1); + defmac1(" nop", -1); + defmac1(" nop", -1); + + curmac = NewSymbol("mpad", MACRO, 0); + curmac->svalue = 0; + curmac->sattr = (WORD)(macnum++); argno = 0; defmac2("size"); - curmln = NULL; - defmac1(" .rept (\\size/2)", -1); - defmac1(" nop", -1); - defmac1(" .endr", -1); +// curmln = NULL; + curmac->lineList = NULL; + defmac1(" .rept (\\size/2)", -1); + defmac1(" nop", -1); + defmac1(" .endr", -1); } diff --git a/macro.h b/macro.h index ea25b8b..2418c26 100644 --- a/macro.h +++ b/macro.h @@ -13,18 +13,18 @@ // Globals, externals etc extern LONG curuniq; -extern TOKEN ** argp; +//extern TOKEN ** argp; extern int mjump_align; +extern TOKEN * argPtrs[]; // Prototypes void init_macro(void); int exitmac(void); -int defmac(void); +int DefineMacro(void); int defrept(void); int lncatch(int (*)(), char *); int kwmatch(char *, char *); -int invokemac(SYM *, WORD); +int InvokeMacro(SYM *, WORD); void ib_macro(void); #endif // __MACRO_H__ - diff --git a/procln.c b/procln.c index edd2173..8127d73 100644 --- a/procln.c +++ b/procln.c @@ -178,7 +178,8 @@ loop1: // Internal line processing loop if (j == '=' || j == DEQUALS || j == SET || j == REG || j == EQUREG || j == CCDEF) { - equate = (char *)tok[1]; +// equate = (char *)tok[1]; + equate = string[tok[1]]; equtyp = j; tok += 3; goto normal; @@ -188,7 +189,8 @@ loop1: // Internal line processing loop if (j == ':' || j == DCOLON) { as68label: - label = (char *)tok[1]; // Get label name +// label = (char *)tok[1]; // Get label name + label = string[tok[1]]; // Get label name labtyp = tok[2]; // Get label type tok += 3; // Go to next line token @@ -218,8 +220,12 @@ as68label: // This is the problem here: On 64-bit platforms, this cuts the native pointer // in half. We need to figure out how to fix this. -#warning "!!! Bad pointer !!!" +//#warning "!!! Bad pointer !!!" +#if 0 opname = p = (char *)*tok++; // Store opcode name here +#else + opname = p = string[*tok++]; +#endif // Check to see if the SYMBOL is a keyword (a mnemonic or directive). // On output, `state' will have one of the values: @@ -299,7 +305,7 @@ as68label: if (label != NULL) warn(lab_ignored); - defmac(); + DefineMacro(); } goto loop; @@ -348,7 +354,7 @@ normal: if (sy == NULL) { - sy = newsym(equate, LABEL, j); + sy = NewSymbol(equate, LABEL, j); sy->sattr = 0; if (equtyp == DEQUALS) @@ -430,7 +436,8 @@ normal: // Checking for a register symbol else if (tok[0] == SYMBOL) { - sy2 = lookup((char *)tok[1], LABEL, j); +// sy2 = lookup((char *)tok[1], LABEL, j); + sy2 = lookup(string[tok[1]], LABEL, j); // Make sure symbol is a valid equreg if (!sy2 || !(sy2->sattre & EQUATEDREG)) @@ -467,7 +474,8 @@ normal: if (tok[0] == SYMBOL) { - sy2 = lookup((char *)tok[1], LABEL, j); +// sy2 = lookup((char *)tok[1], LABEL, j); + sy2 = lookup(string[tok[1]], LABEL, j); if (!sy2 || !(sy2->sattre & EQUATEDCC)) { @@ -488,7 +496,8 @@ normal: //equ a equr else if (*tok == SYMBOL) { - sy2 = lookup((char *)tok[1], LABEL, j); +// sy2 = lookup((char *)tok[1], LABEL, j); + sy2 = lookup(string[tok[1]], LABEL, j); if (sy2 && (sy2->sattre & EQUATEDREG)) { @@ -533,7 +542,7 @@ do_label: if (sy == NULL) { - sy = newsym(label, LABEL, j); + sy = NewSymbol(label, LABEL, j); sy->sattr = 0; sy->sattre = RISCSYM; } @@ -621,7 +630,7 @@ do_label: if (state < 0) { if ((sy = lookup(opname, MACRO, 0)) != NULL) - invokemac(sy, siz); + InvokeMacro(sy, siz); else errors("unknown op '%s'", opname); @@ -703,7 +712,6 @@ int d_if(void) // Alloc an IFENTRY if ((rif = f_ifent) == NULL) -// rif = (IFENT *)amem((LONG)sizeof(IFENT)); rif = (IFENT *)malloc(sizeof(IFENT)); else f_ifent = rif->if_prev; @@ -713,7 +721,8 @@ int d_if(void) if (!disabled) { - if (expr(exprbuf, &eval, &eattr, &esym) != OK) return 0; + if (expr(exprbuf, &eval, &eattr, &esym) != OK) + return 0; if ((eattr & DEFINED) == 0) return error(undef_error); diff --git a/risca.c b/risca.c index f1d2ed6..a7d50cc 100644 --- a/risca.c +++ b/risca.c @@ -15,20 +15,20 @@ #include "mark.h" #include "amode.h" -#define DEF_MR // Declar keyword values -#include "risckw.h" // Incl generated risc keywords +#define DEF_MR // Declar keyword values +#include "risckw.h" // Incl generated risc keywords -#define DEF_KW // Declare keyword values -#include "kwtab.h" // Incl generated keyword tables & defs +#define DEF_KW // Declare keyword values +#include "kwtab.h" // Incl generated keyword tables & defs -unsigned altbankok = 0; // Ok to use alternate register bank -unsigned orgactive = 0; // RISC org directive active -unsigned orgaddr = 0; // Org'd address -unsigned orgwarning = 0; // Has an ORG warning been issued +unsigned altbankok = 0; // Ok to use alternate register bank +unsigned orgactive = 0; // RISC org directive active +unsigned orgaddr = 0; // Org'd address +unsigned orgwarning = 0; // Has an ORG warning been issued int jpad = 0; -unsigned previousop = 0; // Used for NOP padding checks -unsigned currentop = 0; // Used for NOP padding checks -unsigned mjump_defined, mjump_dest; // mjump macro flags, values etc +unsigned previousop = 0; // Used for NOP padding checks +unsigned currentop = 0; // Used for NOP padding checks +unsigned mjump_defined, mjump_dest; // mjump macro flags, values etc char reg_err[] = "missing register R0...R31"; @@ -249,33 +249,33 @@ int getregister(WORD rattr) // int risccg(int state) { - unsigned short parm; // Opcode parameters - unsigned type; // Opcode type - int reg1; // Register 1 - int reg2; // Register 2 - int val = 0; // Constructed value + unsigned short parm; // Opcode parameters + unsigned type; // Opcode type + int reg1; // Register 1 + int reg2; // Register 2 + int val = 0; // Constructed value char scratch[80]; SYM * ccsym; SYM * sy; - int i; // Iterator + int i; // Iterator int t, c; WORD tdb; - unsigned locptr = 0; // Address location pointer - unsigned page_jump = 0; // Memory page jump flag - VALUE eval; // Expression value - WORD eattr; // Expression attributes - SYM * esym; // External symbol involved in expr. - TOKEN r_expr[EXPRSIZE]; // Expression token list - WORD defined; // Symbol defined flag + unsigned locptr = 0; // Address location pointer + unsigned page_jump = 0; // Memory page jump flag + VALUE eval; // Expression value + WORD eattr; // Expression attributes + SYM * esym; // External symbol involved in expr. + TOKEN r_expr[EXPRSIZE]; // Expression token list + WORD defined; // Symbol defined flag WORD attrflg; - int indexed; // Indexed register flag + int indexed; // Indexed register flag - parm = (WORD)(roptbl[state-3000].parm); // Get opcode parameter and type + parm = (WORD)(roptbl[state-3000].parm); // Get opcode parameter and type type = roptbl[state-3000].typ; - // Detect whether the opcode parmeter passed determines that the opcode is specific to only one - // of the RISC processors and ensure it is legal in the current code section. - // If not then error and return. + // Detect whether the opcode parmeter passed determines that the opcode is + // specific to only one of the RISC processors and ensure it is legal in + // the current code section. If not then error and return. if (((parm & GPUONLY) && rdsp) || ((parm & DSPONLY) && rgpu)) { error("opcode is not valid in this code section"); @@ -472,13 +472,16 @@ int risccg(int state) if (*tok != '(') goto malformed; - ++tok; + tok++; + if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok+1) != ')')) indexed = (*tok - KW_R0); if (*tok == SYMBOL) { - sy = lookup((char *)tok[1], LABEL, 0); +// sy = lookup((char *)tok[1], LABEL, 0); + sy = lookup(string[tok[1]], LABEL, 0); + if (!sy) { error(reg_err); @@ -518,7 +521,8 @@ int risccg(int state) if (*tok == SYMBOL) { - sy = lookup((char *)tok[1], LABEL, 0); +// sy = lookup((char *)tok[1], LABEL, 0); + sy = lookup(string[tok[1]], LABEL, 0); if (!sy) { @@ -615,7 +619,8 @@ int risccg(int state) if (*tok == SYMBOL) { - sy = lookup((char *)tok[1], LABEL, 0); +// sy = lookup((char *)tok[1], LABEL, 0); + sy = lookup(string[tok[1]], LABEL, 0); if (!sy) { @@ -656,7 +661,8 @@ int risccg(int state) if (*tok == SYMBOL) { - sy = lookup((char *)tok[1], LABEL, 0); +// sy = lookup((char *)tok[1], LABEL, 0); + sy = lookup(string[tok[1]], LABEL, 0); if (!sy) { @@ -795,7 +801,8 @@ int risccg(int state) for(i=0; isattre & EQUATEDCC) && !(ccsym->sattre & UNDEF_CC)) { diff --git a/rmac.c b/rmac.c index 56ff27f..eab2125 100644 --- a/rmac.c +++ b/rmac.c @@ -563,7 +563,7 @@ int process(int argc, char ** argv) in_main = 0; // Initialise modules - init_sym(); // Symbol table + InitSymbolTable(); // Symbol table init_token(); // Tokenizer init_procln(); // Line processor init_expr(); // Expression analyzer @@ -601,7 +601,7 @@ int process(int argc, char ** argv) if (sy == NULL) { - sy = newsym(argv[argno] + 2, LABEL, 0); + sy = NewSymbol(argv[argno] + 2, LABEL, 0); sy->svalue = 0; } @@ -793,8 +793,8 @@ int process(int argc, char ** argv) // (`lo68' format, extended (postfix) format....) // (2) generate the output file image and symbol table; // (3) generate relocation information from left-over fixups. - fixups(); // Do all fixups - stopmark(); // Stop mark tape-recorder + ResolveAllFixups(); // Do all fixups + stopmark(); // Stop mark tape-recorder if (errcnt == 0) { diff --git a/rmac.h b/rmac.h index f660a0d..ca43ea4 100644 --- a/rmac.h +++ b/rmac.h @@ -12,7 +12,6 @@ // // TARGET SPECIFIC BUILD SETTINGS // - #ifdef WIN32 #define PLATFORM "Win32" // Release platform - windows #define _OPEN_FLAGS _O_TRUNC|_O_CREAT|_O_BINARY|_O_RDWR @@ -60,7 +59,11 @@ #endif #endif +// +// Non-target specific stuff +// #include +#include "symbol.h" #define BYTE uint8_t #define WORD uint16_t @@ -113,21 +116,6 @@ #define MWC 1 // Mark Williams object format #define BSD 2 // BSD object format -// Symbols -#define SYM struct _sym -SYM -{ - SYM * snext; // * -> Next symbol on hash-chain - SYM * sorder; // * -> Next sym in order of refrence - SYM * sdecl; // * -> Next sym in order of declaration - BYTE stype; // Symbol type - WORD sattr; // Attribute bits - LONG sattre; // Extended attribute bits - WORD senv; // Enviroment number - LONG svalue; // Symbol value - char * sname; // * -> Symbol's print-name -}; - // Pointer type that can point to (almost) anything #define PTR union _ptr PTR diff --git a/sect.c b/sect.c index 89df4b4..53ba02b 100644 --- a/sect.c +++ b/sect.c @@ -7,14 +7,15 @@ // #include "sect.h" +#include "direct.h" #include "error.h" +#include "expr.h" +#include "listing.h" #include "mach.h" -#include "token.h" #include "mark.h" -#include "expr.h" -#include "symbol.h" #include "risca.h" -#include "listing.h" +#include "symbol.h" +#include "token.h" // Section descriptors SECT sect[NSECTS]; // All sections... @@ -86,19 +87,18 @@ void mksect(int sno, WORD attr) // void switchsect(int sno) { - SECT * p; // Section pointer - CHUNK * cp; // Chunk pointer - + CHUNK * cp; // Chunk pointer cursect = sno; - p = §[sno]; + SECT * p = §[sno]; - scattr = p->scattr; // Copy section vars + scattr = p->scattr; // Copy section vars sloc = p->sloc; scode = p->scode; sfix = p->sfix; + // Copy code chunk vars if ((cp = scode) != NULL) - { // Copy code chunk vars + { challoc = cp->challoc; ch_size = cp->ch_size; chptr = cp->chptr + ch_size; @@ -106,8 +106,9 @@ void switchsect(int sno) else challoc = ch_size = 0; + // Copy fixup chunk vars if ((cp = sfix) != NULL) - { // Copy fixup chunk vars + { fchalloc = cp->challoc; fchsize = cp->ch_size; fchptr.cp = cp->chptr + fchsize; @@ -140,20 +141,20 @@ void savsect(void) // void init_sect(void) { - int i; // Iterator + int i; // Cleanup all sections - for(i=0; ichnext) { fup.cp = (char *)ch->chptr; @@ -210,11 +212,9 @@ int fixtest(int sno, LONG loc) // int chcheck(LONG amt) { - CHUNK * cp; - SECT * p; - + // If in BSS section, no allocation required if (scattr & SBSS) - return 0; // If in BSS section, forget it + return 0; if (!amt) amt = CH_THRESHOLD; @@ -225,8 +225,8 @@ int chcheck(LONG amt) if (amt < CH_CODE_SIZE) amt = CH_CODE_SIZE; - p = §[cursect]; - cp = (CHUNK *)malloc(sizeof(CHUNK) + amt); + SECT * p = §[cursect]; + CHUNK * cp = malloc(sizeof(CHUNK) + amt); // First chunk in section if (scode == NULL) @@ -254,6 +254,9 @@ int chcheck(LONG amt) } +// This is really wrong. We need to make some proper structures here so we don't +// have to count sizes of objects, that's what the compiler's for! :-P +#define FIXUP_BASE_SIZE (sizeof(WORD) + sizeof(LONG) + sizeof(WORD) + sizeof(WORD)) // // Arrange for a fixup on a location // @@ -263,19 +266,25 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr) LONG len = 0; CHUNK * cp; SECT * p; + // Shamus: Expression lengths are voodoo ATM (varibale "i"). Need to fix this. + DEBUG printf("FIXUP@$%X: $%X\n", loc, attr); // Compute length of expression (could be faster); determine if it's the // single-symbol case; no expression if it's just a mark. This code assumes // 16 bit WORDs and 32 bit LONGs if (*fexpr == SYMBOL && fexpr[2] == ENDEXPR) { - if ((attr & 0x0F00) == FU_JR) // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN ! + // Just a single symbol + // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN ! + if ((attr & 0x0F00) == FU_JR) { - i = 18; // Just a single symbol +// i = 18; + i = FIXUP_BASE_SIZE + (sizeof(LONG) * 2); } else { - i = 14; +// i = 14; + i = FIXUP_BASE_SIZE + sizeof(SYM *); } } else @@ -289,23 +298,25 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr) } len++; // Add 1 for ENDEXPR - i = (len << 2) + 12; +// i = (len << 2) + 12; + i = FIXUP_BASE_SIZE + sizeof(WORD) + (len * sizeof(TOKEN)); } // Maybe alloc another fixup chunk for this one to fit in if ((fchalloc - fchsize) < i) { p = §[cursect]; -// cp = (CHUNK *)amem((long)(sizeof(CHUNK) + CH_FIXUP_SIZE)); cp = (CHUNK *)malloc(sizeof(CHUNK) + CH_FIXUP_SIZE); + // First fixup chunk in section if (sfix == NULL) - { // First fixup chunk in section + { cp->chprev = NULL; p->sffix = cp; } + // Add to other chunks else - { // Add to other chunks + { cp->chprev = sfix; sfix->chnext = cp; sfix->ch_size = fchsize; @@ -319,14 +330,15 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr) sfix = p->sfix = cp; } - // Record fixup type, fixup location, and the file number and line number the fixup is - // located at. + // Record fixup type, fixup location, and the file number and line number + // the fixup is located at. *fchptr.wp++ = attr; *fchptr.lp++ = loc; *fchptr.wp++ = cfileno; *fchptr.wp++ = (WORD)curlineno; - // Store postfix expression or pointer to a single symbol, or nothing for a mark. + // Store postfix expression or pointer to a single symbol, or nothing for a + // mark. if (attr & FU_EXPR) { *fchptr.wp++ = (WORD)len; @@ -336,10 +348,12 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr) } else { - *fchptr.lp++ = (LONG)fexpr[1]; +// *fchptr.lp++ = (LONG)fexpr[1]; + *fchptr.sy++ = symbolPtr[fexpr[1]]; } - if ((attr & 0x0F00) == FU_JR) // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN ! + // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN ! + if ((attr & 0x0F00) == FU_JR) { if (orgactive) *fchptr.lp++ = orgaddr; @@ -355,7 +369,7 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr) // // Resolve all Fixups // -int fixups(void) +int ResolveAllFixups(void) { unsigned i; char buf[EBUFSIZ]; @@ -364,10 +378,13 @@ int fixups(void) if (glob_flag) syg_fix(); - resfix(TEXT); - resfix(DATA); + DEBUG printf("Resolving TEXT sections...\n"); + ResolveFixups(TEXT); + DEBUG printf("Resolving DATA sections...\n"); + ResolveFixups(DATA); - // We need to do a final check of forward 'jump' destination addresses that are external + // We need to do a final check of forward 'jump' destination addresses that + // are external for(i=0; isffix; + SECT * sc = §[sno]; + CHUNK * ch = sc->sffix; if (ch == NULL) return 0; - cch = sc->sfcode; // "cache" first chunk + CHUNK * cch = sc->sfcode; // "cache" first chunk - if (cch == NULL) // Can't fixup a sect with nothing in it + if (cch == NULL) // Can't fixup a sect with nothing in it return 0; do { - fup.cp = ch->chptr; // fup -> start of chunk - fuend = (WORD *)(fup.cp + ch->ch_size); // fuend -> end of chunk + fup.cp = ch->chptr; // fup -> start of chunk + fuend = (WORD *)(fup.cp + ch->ch_size); // fuend -> end of chunk while (fup.wp < fuend) { @@ -441,9 +455,10 @@ int resfix(int sno) esym = NULL; - // Search for chunk containing location to fix up; compute a pointer to the location - // (in the chunk). Often we will find the fixup is in the "cached" chunk, so the - // linear-search is seldom executed. + // Search for chunk containing location to fix up; compute a + // pointer to the location (in the chunk). Often we will find the + // fixup is in the "cached" chunk, so the linear-search is seldom + // executed. if (loc < cch->chloc || loc >= (cch->chloc + cch->ch_size)) { for(cch=sc->sfcode; cch!=NULL; cch=cch->chnext) @@ -454,18 +469,18 @@ int resfix(int sno) if (cch == NULL) { - interror(7); // Fixup (loc) out of range + interror(7); // Fixup (loc) out of range // NOTREACHED } } locp = cch->chptr + (loc - cch->chloc); - eattr = 0; // Compute expression/symbol value and attribs + // Complex expression if (w & FU_EXPR) - { // Complex expression + { i = *fup.wp++; if (evexpr(fup.tk, &eval, &eattr, &esym) != OK) @@ -476,8 +491,9 @@ int resfix(int sno) fup.lp += i; } + // Simple symbol else - { // Simple symbol + { sy = *fup.sy++; eattr = sy->sattr; @@ -486,7 +502,7 @@ int resfix(int sno) else eval = 0; - if ((eattr & (GLOBAL|DEFINED)) == GLOBAL) + if ((eattr & (GLOBAL | DEFINED)) == GLOBAL) esym = sy; } @@ -505,14 +521,17 @@ int resfix(int sno) // Do the fixup // - // If a PC-relative fixup is undefined, its value is *not* subtracted from the location - // (that will happen in the linker when the external reference is resolved). + // If a PC-relative fixup is undefined, its value is *not* + // subtracted from the location (that will happen in the linker + // when the external reference is resolved). // - // MWC expects PC-relative things to have the LOC subtracted from the value, if the - // value is external (that is, undefined at this point). + // MWC expects PC-relative things to have the LOC subtracted from + // the value, if the value is external (that is, undefined at this + // point). // - // PC-relative fixups must be DEFINED and either in the same section (whereupon the - // subtraction takes place) or ABS (with no subtract). + // PC-relative fixups must be DEFINED and either in the same + // section (whereupon the subtraction takes place) or ABS (with no + // subtract). if (w & FU_PCREL) { if (eattr & DEFINED) @@ -591,7 +610,8 @@ int resfix(int sno) *locp = (char)eval; break; // Fixup WORD forward references; - // the word could be unaligned in the section buffer, so we have to be careful. + // the word could be unaligned in the section buffer, so we have to + // be careful. case FU_WORD: if (((w & 0x0F00) == FU_JR) || ((w & 0x0F00) == FU_MJR)) { @@ -608,7 +628,8 @@ int resfix(int sno) if ((w & 0x0F00) == FU_MJR) { - // Main code destination alignment checking here for forward declared labels + // Main code destination alignment checking here for + // forward declared labels address = (oaddr) ? oaddr : loc; if (((address >= 0xF03000) && (address < 0xF04000) @@ -624,7 +645,8 @@ int resfix(int sno) if (page_jump) { - // This jump is to a page outside of the current 256 byte page + // This jump is to a page outside of the + // current 256 byte page if (eval % 4) { warni("* \'jr\' at $%08X - destination address not aligned for long page jump, insert a \'nop\' before the destination address", address); @@ -762,7 +784,8 @@ int resfix(int sno) *locp = (char)eval; break; // Fixup LONG forward references; - // the long could be unaligned in the section buffer, so be careful (again). + // the long could be unaligned in the section buffer, so be careful + // (again). case FU_LONG: if ((w & 0x0F00) == FU_MOVEI) { diff --git a/sect.h b/sect.h index 735c794..7f09d6b 100644 --- a/sect.h +++ b/sect.h @@ -83,8 +83,8 @@ CHUNK { CHUNK * chnext; // Next, previous chunks in section CHUNK * chprev; LONG chloc; // Base addr of this chunk - LONG challoc; // #bytes allocated for chunk - LONG ch_size; // #bytes chunk actually uses + LONG challoc; // # bytes allocated for chunk + LONG ch_size; // # bytes chunk actually uses char * chptr; // Data for this chunk }; @@ -108,8 +108,8 @@ SECT { MCHUNK { MCHUNK * mcnext; // Next mark chunk PTR mcptr; // Vector of marks - LONG mcalloc; // #marks allocted to mark block - LONG mcused; // #marks used in block + LONG mcalloc; // # marks allocted to mark block + LONG mcused; // # marks used in block }; #define MWORD 0x0000 // Marked word @@ -141,7 +141,7 @@ void savsect(void); int fixtest(int, LONG); int chcheck(LONG); int fixup(WORD, LONG, TOKEN *); -int fixups(void); -int resfix(int); +int ResolveAllFixups(void); +//int ResolveFixups(int); #endif // __SECT_H__ diff --git a/symbol.c b/symbol.c index fbe84a5..0e3cac0 100644 --- a/symbol.c +++ b/symbol.c @@ -11,12 +11,15 @@ #include "procln.h" #include "error.h" -static SYM * sytab[NBUCKETS]; // User symbol-table header -int curenv; // Current enviroment number -SYM * sorder; // * -> Symbols, in order of reference -SYM * sordtail; // * -> Last symbol in sorder list -SYM * sdecl; // * -> Symbols, in order of declaration -SYM * sdecltail; // * -> Last symbol in sdecl list +// Macros +#define NBUCKETS 256 // Number of hash buckets (power of 2) + +static SYM * symbolTable[NBUCKETS]; // User symbol-table header +int curenv; // Current enviroment number +static SYM * sorder; // * -> Symbols, in order of reference +static SYM * sordtail; // * -> Last symbol in sorder list +static SYM * sdecl; // * -> Symbols, in order of declaration +static SYM * sdecltail; // * -> Last symbol in sdecl list // Tags for marking symbol spaces // a = absolute @@ -32,17 +35,17 @@ static char tdb_text[8] = { // // Initialize Symbol Table // -void init_sym(void) +void InitSymbolTable(void) { - int i; // Iterator + int i; // Iterator - for(i=0; isname = nstring(name); - sy->sname = strdup(name); + symbol->sname = strdup(name); // Fill-in the symbol - sy->stype = (BYTE)type; - sy->senv = (WORD)envno; - sy->sattr = 0; -#if 0 - if (rgpu || rdsp) - sy->sattre = RISCSYM; - else - sy->sattre = 0; -#else - sy->sattre = (rgpu || rdsp ? RISCSYM : 0); -#endif - sy->svalue = 0; + symbol->stype = (BYTE)type; + symbol->senv = (WORD)envno; + symbol->sattr = 0; + symbol->sattre = (rgpu || rdsp ? RISCSYM : 0); + symbol->svalue = 0; // Install symbol in symbol table - hash = syhash(name, envno); - sy->snext = sytab[hash]; - sytab[hash] = sy; + int hash = HashSymbol(name, envno); + symbol->snext = symbolTable[hash]; + symbolTable[hash] = symbol; // Append symbol to symbol-order list if (sorder == NULL) - sorder = sy; // Add first symbol + sorder = symbol; // Add first symbol else - sordtail->sorder = sy; // Or append to tail of list + sordtail->sorder = symbol; // Or append to tail of list - sy->sorder = NULL; - sordtail = sy; + symbol->sorder = NULL; + sordtail = symbol; - return sy; // Return pointer to symbol + return symbol; } @@ -130,7 +121,7 @@ SYM * lookup(char * name, int type, int envno) int k, sum; // Hash bucket calculation char * s; // String pointer - // Pick a hash-bucket (SAME algorithm as syhash()) + // Pick a hash-bucket (SAME algorithm as HashSymbol()) k = 0; s = name; @@ -142,24 +133,24 @@ SYM * lookup(char * name, int type, int envno) sum += *s++; } - sy = sytab[sum & (NBUCKETS-1)]; + sy = symbolTable[sum & (NBUCKETS-1)]; #else - SYM * sy = sytab[syhash(name, envno)]; + SYM * symbol = symbolTable[HashSymbol(name, envno)]; #endif // Do linear-search for symbol in bucket - while (sy != NULL) + while (symbol != NULL) { - if (sy->stype == type // Type, envno and name must match - && sy->senv == envno - && *name == *sy->sname // Fast check for first character - && !strcmp(name, sy->sname)) + if (symbol->stype == type // Type, envno and name must match + && symbol->senv == envno + && *name == *symbol->sname // Fast check for first character + && !strcmp(name, symbol->sname)) break; else - sy = sy->snext; + symbol = symbol->snext; } - return sy; // Return NULL or matching symbol + return symbol; // Return NULL or matching symbol } @@ -197,7 +188,7 @@ int syg_fix(void) for(sy=sorder; sy!=NULL; sy=sy->sorder) { if (sy->stype == LABEL && sy->senv == 0 - && ((sy->sattr & (REFERENCED|DEFINED)) == REFERENCED)) + && ((sy->sattr & (REFERENCED | DEFINED)) == REFERENCED)) sy->sattr |= GLOBAL; } @@ -267,8 +258,8 @@ int sy_assign(char * buf, char *(* constr)()) // Export or import external references, and export COMMON blocks. if ((sy->stype == LABEL) - && ((sy->sattr & (GLOBAL|DEFINED)) == (GLOBAL|DEFINED) - || (sy->sattr & (GLOBAL|REFERENCED)) == (GLOBAL|REFERENCED)) + && ((sy->sattr & (GLOBAL | DEFINED)) == (GLOBAL | DEFINED) + || (sy->sattr & (GLOBAL | REFERENCED)) == (GLOBAL | REFERENCED)) || (sy->sattr & COMMON)) { sy->senv = (WORD)scount++; @@ -279,7 +270,7 @@ int sy_assign(char * buf, char *(* constr)()) // Export vanilla labels (but don't make them global). An exception is // made for equates, which are not exported unless they are referenced. else if (sy->stype == LABEL && lsym_flag - && (sy->sattr & (DEFINED|REFERENCED)) != 0 + && (sy->sattr & (DEFINED | REFERENCED)) != 0 && (!as68_flag || *sy->sname != 'L')) { sy->senv = (WORD)scount++; @@ -325,7 +316,7 @@ int symtable(void) for(i=0; isnext; j = *p->sname; diff --git a/symbol.h b/symbol.h index 9f46ee3..9ce6b17 100644 --- a/symbol.h +++ b/symbol.h @@ -9,10 +9,31 @@ #ifndef __SYMBOL_H__ #define __SYMBOL_H__ -#include "rmac.h" +#include -// Macros -#define NBUCKETS 256 // Number of hash buckets (power of 2) +// Line lists +struct LineList +{ + struct LineList * next; + char * line; +}; + +// Symbols +#define SYM struct _sym +SYM +{ + SYM * snext; // * -> Next symbol on hash-chain + SYM * sorder; // * -> Next sym in order of reference + SYM * sdecl; // * -> Next sym in order of declaration + uint8_t stype; // Symbol type + uint16_t sattr; // Attribute bits + uint32_t sattre; // Extended attribute bits + uint16_t senv; // Enviroment number + uint32_t svalue; // Symbol value + char * sname; // * -> Symbol's print-name + struct LineList * lineList; // * -> Macro's linked list of lines + struct LineList * last; // * -> end of macro linked list +}; // Globals, externals etc extern int curenv; @@ -20,8 +41,8 @@ extern char subttl[]; // Prototypes SYM * lookup(char *, int, int); -void init_sym(void); -SYM * newsym(char *, int, int); +void InitSymbolTable(void); +SYM * NewSymbol(char *, int, int); void sym_decl(SYM *); int syg_fix(void); int symtable(void); diff --git a/token.c b/token.c index cd515a8..27a7f32 100644 --- a/token.c +++ b/token.c @@ -7,10 +7,10 @@ // #include "token.h" -#include "symbol.h" -#include "procln.h" -#include "macro.h" #include "error.h" +#include "macro.h" +#include "procln.h" +#include "symbol.h" #define DECL_KW // Declare keyword arrays #define DEF_KW // Declare keyword values @@ -210,30 +210,27 @@ INOBJ * a_inobj(int typ) // (the colon must be in the first column). These labels are stripped before // macro expansion takes place. // -int mexpand(char * src, char * dest, int destsiz) +int ExpandMacro(char * src, char * dest, int destsiz) { - char * s; - char * d = NULL; - char * dst; // Next dest slot - char * edst; // End+1 of dest buffer int i; int questmark; // \? for testing argument existence - TOKEN * tk; char mname[128]; // Assume max size of a formal arg name - int macnum; - SYM * arg; - IMACRO * imacro; char numbuf[20]; // Buffer for text of CONSTs + TOKEN * tk; + SYM * arg; - imacro = cur_inobj->inobj.imacro; - macnum = (int)(imacro->im_macro->sattr); + DEBUG { printf("EM: src=\"%s\"\n", src); } - destsiz--; - dst = dest; - edst = dest + destsiz; + IMACRO * imacro = cur_inobj->inobj.imacro; + int macnum = (int)(imacro->im_macro->sattr); + +// destsiz--; + char * dst = dest; // Next dest slot + char * edst = dest + destsiz - 1; // End + 1(?) of dest buffer // Check for (and skip over) any "label" on the line - s = src; + char * s = src; + char * d = NULL; if (*s == ':') { @@ -291,7 +288,7 @@ int mexpand(char * src, char * dest, int destsiz) copystr: d = numbuf; copy_d: - ++s; + s++; while (*d != EOS) { @@ -320,7 +317,7 @@ copy_d: // Get argument name: \name, \{name} d = mname; - // \foo + // \label if (*s != '{') { do @@ -329,7 +326,7 @@ copy_d: } while (chrtab[*s] & CTSYM); } - // \\{foo} + // \\{label} else { for(++s; *s != EOS && *s != '}';) @@ -338,14 +335,14 @@ copy_d: if (*s != '}') return error("missing '}'"); else - ++s; + s++; } *d = EOS; // Lookup the argument and copy its (string) value into the // destination string - DEBUG printf("mname='%s'\n", mname); + DEBUG printf("argument='%s'\n", mname); if ((arg = lookup(mname, MACARG, macnum)) == NULL) return errors("undefined argument: '%s'", mname); @@ -361,7 +358,8 @@ arg_num: tk = NULL; if (i < imacro->im_nargs) - tk = argp[i]; +// tk = argp[i]; + tk = argPtrs[i]; // \?arg yields: // 0 if the argument is empty or non-existant, @@ -378,7 +376,7 @@ arg_num: continue; } - if (tk != NULL) // arg# is in range, so expand it + if (tk != NULL) // arg # is in range, so expand it { while (*tk != EOL) { @@ -401,10 +399,12 @@ arg_num: switch ((int)*tk++) { case SYMBOL: - d = (char *)*tk++; +// d = (char *)*tk++; + d = string[*tk++]; break; case STRING: - d = (char *)*tk++; +// d = (char *)*tk++; + d = string[*tk++]; if (dst >= edst) goto overflow; @@ -532,20 +532,23 @@ char * getmln(void) unsigned source_addr; IMACRO * imacro = cur_inobj->inobj.imacro; - LONG * strp = imacro->im_nextln; +// LONG * strp = imacro->im_nextln; + struct LineList * strp = imacro->im_nextln; if (strp == NULL) // End-of-macro return NULL; - imacro->im_nextln = (LONG *)*strp; - mexpand((char *)(strp + 1), imacro->im_lnbuf, LNSIZ); +// imacro->im_nextln = (LONG *)*strp; + imacro->im_nextln = strp->next; +// ExpandMacro((char *)(strp + 1), imacro->im_lnbuf, LNSIZ); + ExpandMacro(strp->line, imacro->im_lnbuf, LNSIZ); if (!strcmp(imacro->im_macro->sname, "mjump") && !mjump_align) { // if we need to adjust the alignment of the jump source address to // meet the rules of gpu main execution we need to skip the first nop // of the macro. This is simpler than trying to insert nop's mid macro. - source_addr = (orgactive) ? orgaddr : sloc; + source_addr = (orgactive ? orgaddr : sloc); source_addr += 8; if (source_addr % 4) @@ -555,8 +558,10 @@ char * getmln(void) if (strp == NULL) return NULL; - imacro->im_nextln = (LONG *)*strp; - mexpand((char *)(strp + 1), imacro->im_lnbuf, LNSIZ); +// imacro->im_nextln = (LONG *)*strp; +// ExpandMacro((char *)(strp + 1), imacro->im_lnbuf, LNSIZ); + imacro->im_nextln = strp->next; + ExpandMacro(strp->line, imacro->im_lnbuf, LNSIZ); } mjump_align = 1; @@ -697,12 +702,10 @@ void init_token(void) // int fpop(void) { - INOBJ * inobj; IFILE * ifile; IMACRO * imacro; LONG * p, * p1; - - inobj = cur_inobj; + INOBJ * inobj = cur_inobj; if (inobj != NULL) { @@ -892,7 +895,7 @@ int tokln(void) *ln = ';'; else { - for(p=ln; *p!=EOS; ++p) + for(p=ln; *p!=EOS; p++) { if (*p == '*') { @@ -970,7 +973,7 @@ int tokln(void) if (c & STSYM) { - if (stuffnull) // Terminate old symbol + if (stuffnull) // Terminate old symbol from previous pass *nullspot = EOS; v = 0; // Assume no DOT attrib follows symbol @@ -1050,7 +1053,13 @@ int tokln(void) #warning //problem here: nullspot is a char * but TOKEN is a uint32_t. On a 64-bit system, //this will cause all kinds of mischief. +#if 0 *tk++ = (TOKEN)nullspot; +#else + string[stringNum] = nullspot; + *tk++ = stringNum; + stringNum++; +#endif } else { @@ -1061,7 +1070,7 @@ int tokln(void) if (v) // Record attribute token (if any) *tk++ = (TOKEN)v; - if (stuffnull) // Arrange for string termination + if (stuffnull) // Arrange for string termination on next pass nullspot = ln; continue; @@ -1096,7 +1105,13 @@ int tokln(void) #warning // More char * stuffing (8 bytes) into the space of 4 (TOKEN). // Need to figure out how to fix this crap. +#if 0 *tk++ = (TOKEN)ln; +#else + string[stringNum] = ln; + *tk++ = stringNum; + stringNum++; +#endif for(p=ln; *ln!=EOS && *ln!=c1;) { @@ -1434,35 +1449,43 @@ goteol: // be EOL. // //int d_goto(WORD siz) { -int d_goto(void) +//int d_goto(void) +int d_goto(WORD unused) { - char * sym; // Label to search for - LONG * defln; // Macro definition strings +// char * sym; // Label to search for +// LONG * defln; // Macro definition strings char * s1; // Temps for string comparison char * s2; - IMACRO * imacro; // Macro invocation block +// IMACRO * imacro; // Macro invocation block // Setup for the search if (*tok != SYMBOL) return error("missing label"); - sym = (char *)tok[1]; +// sym = (char *)tok[1]; + char * sym = string[tok[1]]; tok += 2; if (cur_inobj->in_type != SRC_IMACRO) return error("goto not in macro"); - imacro = cur_inobj->inobj.imacro; - defln = (LONG *)imacro->im_macro->svalue; + IMACRO * imacro = cur_inobj->inobj.imacro; +// defln = (LONG *)imacro->im_macro->svalue; + struct LineList * defln = imacro->im_macro->lineList; // Find the label, starting with the first line. - for(; defln!=NULL; defln=(LONG *)*defln) +// for(; defln!=NULL; defln=(LONG *)*defln) + for(; defln!=NULL; defln=defln->next) { - if (*(char *)(defln + 1) == ':') +// if (*(char *)(defln + 1) == ':') + if (defln->line[0] == ':') { // Compare names (sleazo string compare) + // This string compare is not right. Doesn't check for lengths. +#warning "!!! Bad string comparison !!!" s1 = sym; - s2 = (char *)(defln + 1) + 1; +// s2 = (char *)(defln + 1) + 1; + s2 = defln->line; while (*s1 == *s2) { @@ -1470,8 +1493,8 @@ int d_goto(void) break; else { - ++s1; - ++s2; + s1++; + s2++; } } @@ -1504,11 +1527,15 @@ void DumpTokenBuffer(void) else if (*t == ACONST) printf("[ACONST]"); else if (*t == STRING) - printf("[STRING]"); +// printf("[STRING]"); + { + t++; + printf("[STRING:\"%s\"]", string[*t]); + } else if (*t == SYMBOL) { t++; - printf("[SYMBOL:\"%s\"]", (char *)*t); + printf("[SYMBOL:\"%s\"]", string[*t]); } else if (*t == EOS) printf("[EOS]"); @@ -1558,13 +1585,15 @@ void DumpTokenBuffer(void) printf("[CR_DATE]"); else if (*t >= 0x20 && *t <= 0x2F) printf("[%c]", (char)*t); + else if (*t >= 0x3A && *t <= 0x3F) + printf("[%c]", (char)*t); else if (*t >= 0x80 && *t <= 0x87) printf("[D%u]", ((uint32_t)*t) - 0x80); else if (*t >= 0x88 && *t <= 0x8F) printf("[A%u]", ((uint32_t)*t) - 0x88); else -// printf("[%X:%c]", (uint32_t)*t, (char)*t); - printf("[%X]", (uint32_t)*t); + printf("[%X:%c]", (uint32_t)*t, (char)*t); +// printf("[%X]", (uint32_t)*t); } printf("[EOL]\n"); diff --git a/token.h b/token.h index 5ca5176..6bc1102 100644 --- a/token.h +++ b/token.h @@ -113,7 +113,8 @@ IFILE { // Information about a macro invocation IMACRO { IMACRO * im_link; // Pointer to ancient IMACROs - LONG * im_nextln; // Next line to include +// LONG * im_nextln; // Next line to include + struct LineList * im_nextln; // Next line to include WORD im_nargs; // # of arguments supplied on invocation WORD im_siz; // Size suffix supplied on invocation LONG im_olduniq; // Old value of 'macuniq' @@ -150,8 +151,8 @@ void init_token(void); void setfnum(WORD); int tokln(void); int fpop(void); -//int d_goto(WORD); -int d_goto(void); +int d_goto(WORD); +//int d_goto(void); INOBJ * a_inobj(int); void DumpTokenBuffer(void);