From a48737de123e304866212f5382d6fa4174d496a0 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sat, 31 Jan 2015 20:49:38 -0600 Subject: [PATCH] Fixed a nasty bug that dropped symbols that shouldn't have been. This stemmed from the fact that EQUR symbols somehow made it on to the symbol declaration list. If such symbol was later .equrundef'd, it would find it's way back onto the the sdecl list *twice*, with the result that any symbols that came after it would be summarily discarded into the ether. Really, really bad mojo. --- direct.c | 35 +++++------------------------------ expr.c | 3 +-- procln.c | 12 +++++------- riscasm.c | 12 +++++++----- rmac.c | 2 +- sect.c | 40 +++++++++++++++++++++++----------------- symbol.c | 48 +++++++++++++++++++----------------------------- symbol.h | 2 +- version.h | 2 +- 9 files changed, 63 insertions(+), 93 deletions(-) diff --git a/direct.c b/direct.c index e7a23bd..5cdac4c 100644 --- a/direct.c +++ b/direct.c @@ -136,7 +136,6 @@ int d_print(void) switch(*tok) { case STRING: -// sprintf(prntstr, "%s", (char *)tok[1]); sprintf(prntstr, "%s", string[tok[1]]); printf("%s", prntstr); @@ -203,7 +202,6 @@ int d_print(void) } printf("\n"); -// println("\n"); return 0; @@ -229,12 +227,10 @@ int d_ccundef(void) if (*tok != SYMBOL) { -// error(syntax_error); error("syntax error; expected symbol"); return ERROR; } -// ccname = lookup((char *)tok[1], LABEL, 0); ccname = lookup(string[tok[1]], LABEL, 0); // Make sure symbol is a valid ccdef @@ -407,7 +403,6 @@ int d_even(void) { unsigned skip = (rgpu || rdsp ? orgaddr : sloc) & 0x01; -// if (sloc & 1) if (skip) { if ((scattr & SBSS) == 0) @@ -581,23 +576,15 @@ int d_include(void) char buf[128]; char buf1[128]; - if (*tok == STRING) // Leave strings ALONE -#if 0 - fn = (char *)*++tok; -#else + if (*tok == STRING) // Leave strings ALONE fn = string[*++tok]; -#endif - else if (*tok == SYMBOL) // Try to append ".s" to symbols + 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: @@ -1114,7 +1101,6 @@ int d_comm(void) if (*tok != SYMBOL) return error("missing symbol"); -// p = (char *)tok[1]; p = string[tok[1]]; tok += 2; @@ -1273,18 +1259,10 @@ int d_cargs(void) { if (*tok == SYMBOL) { -// p = (char *)tok[1]; p = string[tok[1]]; -#if 0 - if (*p == '.') - env = curenv; // Label is local - else - env = 0; // Label is global -#else // Set env to either local (dot prefixed) or global scope env = (*p == '.' ? curenv : 0); -#endif symbol = lookup(p, LABEL, env); if (symbol == NULL) @@ -1296,8 +1274,7 @@ int d_cargs(void) return errors("multiply-defined label '%s'", p); // Put symbol in "order of definition" list - if (!(symbol->sattr & SDECLLIST)) - AddToSymbolOrderList(symbol); + AddToSymbolDeclarationList(symbol); symbol->sattr |= (ABS | DEFINED | EQUATED); symbol->svalue = eval; @@ -1322,7 +1299,6 @@ int d_cargs(void) if (reglist(&rlist) < 0) return 0; -// for(i=0; i++<16; rlist>>=1) for(i=0; i<16; i++, rlist>>=1) { if (rlist & 1) @@ -1414,8 +1390,7 @@ int d_cstruct(void) return errors("multiply-defined label '%s'", symbolName); // Put symbol in "order of definition" list - if (!(symbol->sattr & SDECLLIST)) - AddToSymbolOrderList(symbol); + AddToSymbolDeclarationList(symbol); tok += 2; diff --git a/expr.c b/expr.c index 5c7fc87..deeea40 100644 --- a/expr.c +++ b/expr.c @@ -360,7 +360,7 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) j = (*p == '.' ? curenv : 0); symbol = lookup(p, LABEL, j); #if 0 -printf("eval: Looking up symbol [=%08X]\n", symbol); +printf("eval: Looking up symbol (%s) [=%08X]\n", p, symbol); if (symbol) printf(" attr=%04X, attre=%08X, val=%i, name=%s\n", symbol->sattr, symbol->sattre, symbol->svalue, symbol->sname); #endif @@ -416,7 +416,6 @@ thrown away right here. What the hell is it for? */ if (symbol->sattre & EQUATEDREG) *a_value &= 0x1F; - *a_attr = (WORD)(symbol->sattr & ~GLOBAL); if ((symbol->sattr & (GLOBAL | DEFINED)) == GLOBAL && a_esym != NULL) diff --git a/procln.c b/procln.c index d849b00..44b94d6 100644 --- a/procln.c +++ b/procln.c @@ -371,7 +371,7 @@ normal: { //REALLY? sy->sattre |= ~UNDEF_EQUR; sy->sattre &= ~UNDEF_EQUR; - sy->svalue = 0; + sy->svalue = 0; } else if ((equtyp == CCDEF) && (sy->sattre & UNDEF_CC)) { @@ -386,9 +386,8 @@ normal: } } - // Put symbol in "order of definition" list - if (!(sy->sattr & SDECLLIST)) - AddToSymbolOrderList(sy); + // Put symbol in "order of definition" list if it's not already there + AddToSymbolDeclarationList(sy); // Parse value to equate symbol to; // o .equr @@ -694,9 +693,8 @@ int HandleLabel(char * label, int labelType) else if (symbol->sattr & DEFINED) return errors("multiply-defined label '%s'", label); - // Put symbol in "order of definition" list - if (!(symbol->sattr & SDECLLIST)) - AddToSymbolOrderList(symbol); + // Put symbol in "order of definition" list if it's not already in it + AddToSymbolDeclarationList(symbol); if (orgactive) { diff --git a/riscasm.c b/riscasm.c index b4a06d7..d2d594b 100644 --- a/riscasm.c +++ b/riscasm.c @@ -224,7 +224,8 @@ int GenerateRISCCode(int state) break; // Single operand instructions (Rd) - // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S, UNPACK + // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S, + // UNPACK case RI_ONE: reg2 = GetRegister(FU_REGTWO); at_eol(); @@ -232,8 +233,8 @@ int GenerateRISCCode(int state) break; // Two operand instructions (Rs,Rd) - // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT, MMULT, - // MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR + // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT, + // MMULT, MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR case RI_TWO: if (parm == 37) altbankok = 1; // MOVEFA @@ -258,7 +259,8 @@ int GenerateRISCCode(int state) case RI_NUM_31: // Numeric operand (n,Rd) where n = 1..32 - // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ, RORQ + // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ, + // RORQ case RI_NUM_32: switch (type) { @@ -348,7 +350,7 @@ int GenerateRISCCode(int state) { if (eattr & TDB) //{ -//printf("risca: Doing rmark for RI_MOVEI (tdb=$%X)...\n", eattr & TDB); +//printf("RISCASM: Doing rmark for RI_MOVEI (tdb=$%X)...\n", eattr & TDB); rmark(cursect, sloc + 2, (eattr & TDB), (MLONG | MMOVEI), NULL); //} } diff --git a/rmac.c b/rmac.c index b2b2610..3f5a9b5 100644 --- a/rmac.c +++ b/rmac.c @@ -150,7 +150,7 @@ void DisplayHelp(void) void DisplayVersion(void) { printf("\nReboot's Macro Assembler for Atari Jaguar\n" - "Copyright (C) 199x Landon Dyer, 2011 Reboot\n" + "Copyright (C) 199x Landon Dyer, 2011-2015 Reboot\n" "V%01i.%01i.%01i %s (%s)\n\n", MAJOR, MINOR, PATCH, __DATE__, PLATFORM); } diff --git a/sect.c b/sect.c index 1ff54b4..80acece 100644 --- a/sect.c +++ b/sect.c @@ -80,10 +80,10 @@ void InitSection(void) MakeSection(i, 0); // Construct default sections, make TEXT the current section - MakeSection(ABS, SUSED | SABS | SBSS); // ABS - MakeSection(TEXT, SUSED | TEXT ); // TEXT - MakeSection(DATA, SUSED | DATA ); // DATA - MakeSection(BSS, SUSED | BSS | SBSS); // BSS + MakeSection(ABS, SUSED | SABS | SBSS); // ABS + MakeSection(TEXT, SUSED | TEXT ); // TEXT + MakeSection(DATA, SUSED | DATA ); // DATA + MakeSection(BSS, SUSED | BSS | SBSS); // BSS // MakeSection(M6502, SUSED | TEXT ); // 6502 code section // Switch to TEXT for starters @@ -287,18 +287,21 @@ int AddFixup(WORD attr, LONG loc, TOKEN * fexpr) // NYAN ! if ((attr & FUMASKRISC) == FU_JR) { +//printf("AddFixup: ((attr & FUMASKRISC) == FU_JR)\n"); // i = 18; // i = FIXUP_BASE_SIZE + (sizeof(LONG) * 2); i = FIXUP_BASE_SIZE + sizeof(SYM *) + sizeof(LONG); } else { +//printf("AddFixup: ((attr & FUMASKRISC) == FU_JR) ELSE\n"); // i = 14; i = FIXUP_BASE_SIZE + sizeof(SYM *); } } else { +//printf("AddFixup: !SYMBOL\n"); attr |= FU_EXPR; for(len=0; fexpr[len]!=ENDEXPR; len++) @@ -312,7 +315,7 @@ int AddFixup(WORD attr, LONG loc, TOKEN * fexpr) i = FIXUP_BASE_SIZE + sizeof(WORD) + (len * sizeof(TOKEN)); } - // Maybe alloc another fixup chunk for this one to fit in + // Alloc another fixup chunk for this one to fit in if necessary if ((fchalloc - fchsize) < i) { p = §[cursect]; @@ -360,6 +363,7 @@ int AddFixup(WORD attr, LONG loc, TOKEN * fexpr) { // *fchptr.lp++ = (LONG)fexpr[1]; *fchptr.sy++ = symbolPtr[fexpr[1]]; +//printf("AddFixup: adding symbol (%s) [%08X]\n", symbolPtr[fexpr[1]]->sname, symbolPtr[fexpr[1]]->sattr); } // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN ! @@ -402,17 +406,17 @@ int ResolveAllFixups(void) // int ResolveFixups(int sno) { - PTR fup; // Current fixup - WORD * fuend; // End of last fixup (in this chunk) - WORD w; // Fixup word (type+modes+flags) - char * locp; // Location to fix (in cached chunk) - LONG loc; // Location to fixup - VALUE eval; // Expression value - WORD eattr; // Expression attrib - SYM * esym; // External symbol involved in expr - SYM * sy; // (Temp) pointer to a symbol - WORD i; // (Temp) word - WORD tdb; // eattr & TDB + PTR fup; // Current fixup + WORD * fuend; // End of last fixup (in this chunk) + WORD w; // Fixup word (type+modes+flags) + char * locp; // Location to fix (in cached chunk) + LONG loc; // Location to fixup + VALUE eval; // Expression value + WORD eattr; // Expression attrib + SYM * esym; // External symbol involved in expr + SYM * sy; // (Temp) pointer to a symbol + WORD i; // (Temp) word + WORD tdb; // eattr & TDB LONG oaddr; int reg2; WORD flags; @@ -502,6 +506,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } if ((eattr & (GLOBAL | DEFINED)) == GLOBAL) esym = sy; +printf("DoFixups: found symbol (%s) [%08X]\n", sy->sname, sy->sattr); } tdb = (WORD)(eattr & TDB); @@ -895,7 +900,8 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } break; default: - interror(4); // Bad fixup type + // Bad fixup type--this should *never* happen! + interror(4); // NOTREACHED } continue; diff --git a/symbol.c b/symbol.c index 2edf9fd..71e7bf5 100644 --- a/symbol.c +++ b/symbol.c @@ -170,20 +170,23 @@ SYM * lookup(char * name, int type, int envno) // // Put symbol on "order-of-declaration" list of symbols // -//void sym_decl(SYM * symbol) -void AddToSymbolOrderList(SYM * symbol) +void AddToSymbolDeclarationList(SYM * symbol) { - if (symbol->sattr & SDECLLIST) - return; // Already on list + // Don't add if already on list, or it's an equated register/CC + if ((symbol->sattr & SDECLLIST) + || (symbol->sattre & (EQUATEDREG | UNDEF_EQUR | EQUATEDCC | UNDEF_CC))) + return; - symbol->sattr |= SDECLLIST; // Mark "already on list" + // Mark as "on .sdecl list" + symbol->sattr |= SDECLLIST; if (sdecl == NULL) - sdecl = symbol; // First on decl-list + sdecl = symbol; // First on decl-list else - sdecltail->sdecl = symbol; // Add to end of list + sdecltail->sdecl = symbol; // Add to end of list - symbol->sdecl = NULL; // Fix up list's tail + // Fix up list's tail + symbol->sdecl = NULL; sdecltail = symbol; } @@ -238,33 +241,18 @@ int sy_assign(char * buf, char *(* constr)()) // Append all symbols not appearing on the .sdecl list to the end of // the .sdecl list for(sy=sorder; sy!=NULL; sy=sy->sorder) - { - // Essentially the same as 'sym_decl()' above: - if (sy->sattr & SDECLLIST) - continue; // Already on list - - sy->sattr |= SDECLLIST; // Mark "on the list" - - if (sdecl == NULL) - sdecl = sy; // First on decl-list - else - sdecltail->sdecl = sy; // Add to end of list - - sy->sdecl = NULL; // Fix up list's tail - sdecltail = sy; - } + AddToSymbolDeclarationList(sy); } // Run through all symbols (now on the .sdecl list) and assign numbers to // them. We also pick which symbols should be global or not here. for(sy=sdecl; sy!=NULL; sy=sy->sdecl) { - if (sy->sattre & UNDEF_EQUR) - continue; // Don't want undefined on our list + // Don't want register/CC or undefined on our list +//these should already be rejected above... +// if (sy->sattre & (EQUATEDREG | UNDEF_EQUR | EQUATEDCC | UNDEF_CC))) +// continue; - if (sy->sattre & UNDEF_CC) - continue; - // Export or import external references, and export COMMON blocks. if ((sy->stype == LABEL) && ((sy->sattr & (GLOBAL | DEFINED)) == (GLOBAL | DEFINED) @@ -283,7 +271,9 @@ int sy_assign(char * buf, char *(* constr)()) && (!as68_flag || *sy->sname != 'L')) { sy->senv = (WORD)scount++; - if (buf != NULL) buf = (*constr)(buf, sy, 0); + + if (buf != NULL) + buf = (*constr)(buf, sy, 0); } } diff --git a/symbol.h b/symbol.h index 767799e..73a2dca 100644 --- a/symbol.h +++ b/symbol.h @@ -44,7 +44,7 @@ extern char subttl[]; SYM * lookup(char *, int, int); void InitSymbolTable(void); SYM * NewSymbol(char *, int, int); -void AddToSymbolOrderList(SYM *); +void AddToSymbolDeclarationList(SYM *); void ForceUndefinedSymbolsGlobal(void); int symtable(void); int sy_assign(char *, char *(*)()); diff --git a/version.h b/version.h index 58f9dba..1e4e7ae 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 3 // Minor version number -#define PATCH 2 // Patch release number +#define PATCH 3 // Patch release number #endif // __VERSION_H__ -- 2.37.2