From: Shamus Hammons Date: Sat, 17 May 2014 20:56:15 +0000 (-0500) Subject: Fixed word reversed fixup problem. X-Git-Tag: 1.3.0~1 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=commitdiff_plain;h=062214e62031c26d372edc2e68473ebb64f6a506 Fixed word reversed fixup problem. For some reason, there was code in several places that marked fixups/symbols as belonging to a RISC section when it was clearly not the case. As a result, it caused serious problems by reversing words in 68K sections just because a symbol had been seen in a MOVEI # statement in a RISC section. Probably not the last nasty surprise in this pile of spaghetti. :-/ --- diff --git a/.gitignore b/.gitignore index 033e720..5cb2947 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ bugs/ bugs1/ bugs2/ bugs3/ +bugs4/ +bugs5/ +*.zip +features/ diff --git a/debug.c b/debug.c index cb12e3d..5062b8f 100644 --- a/debug.c +++ b/debug.c @@ -115,7 +115,6 @@ int fudump(CHUNK * ch) } else { -// printf("`%s' ;\n", (*p.sy)->sname); printf("`%s' ;", (*p.sy)->sname); p.sy++; } diff --git a/direct.c b/direct.c index 67a6ffd..efec94a 100644 --- a/direct.c +++ b/direct.c @@ -258,10 +258,7 @@ int d_equrundef(void) // Check that we are in a RISC section if (!rgpu && !rdsp) - { - error(".equrundef/.regundef must be defined in .gpu/.dsp section"); - return ERROR; - } + return error(".equrundef/.regundef must be defined in .gpu/.dsp section"); while (*tok != EOL) { @@ -271,14 +268,9 @@ int d_equrundef(void) // Check we are dealing with a symbol if (*tok != SYMBOL) - { -// error(syntax_error); - error("syntax error; expected symbol"); - return ERROR; - } + return error("syntax error; expected symbol"); // Lookup and undef if equated register -// regname = lookup((char *)tok[1], LABEL, 0); regname = lookup(string[tok[1]], LABEL, 0); if (regname && (regname->sattre & EQUATEDREG)) @@ -524,7 +516,7 @@ int d_qphrase(void) { if ((scattr & SBSS) == 0) { - savsect(); + SaveSection(); chcheck(val); for(i=0; isvalue = 0; sy->sattr = GLOBAL; +//printf("glob1: Making global symbol: attr=%04X, eattr=%08X, %s\n", sy->sattr, sy->sattre, sy->sname); } else sy->sattr |= GLOBAL; @@ -747,14 +736,14 @@ int d_abs(void) { VALUE eval; - savsect(); + SaveSection(); if (*tok == EOL) eval = 0; else if (abs_expr(&eval) != OK) return 0; - switchsect(ABS); + SwitchSection(ABS); sloc = eval; return 0; } @@ -771,8 +760,8 @@ int d_text(void) if (cursect != TEXT) { - savsect(); - switchsect(TEXT); + SaveSection(); + SwitchSection(TEXT); } return 0; @@ -786,8 +775,8 @@ int d_data(void) if (cursect != DATA) { - savsect(); - switchsect(DATA); + SaveSection(); + SwitchSection(DATA); } return 0; @@ -801,8 +790,8 @@ int d_bss(void) if (cursect != BSS) { - savsect(); - switchsect(BSS); + SaveSection(); + SwitchSection(BSS); } return 0; @@ -911,7 +900,7 @@ int d_dc(WORD siz) case SIZB: if (!defined) { - fixup(FU_BYTE | FU_SEXT, sloc, exprbuf); + AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf); D_byte(0); } else @@ -930,7 +919,7 @@ int d_dc(WORD siz) case SIZN: if (!defined) { - fixup(FU_WORD | FU_SEXT, sloc, exprbuf); + AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf); D_word(0); } else @@ -950,9 +939,9 @@ int d_dc(WORD siz) if (!defined) { if (movei) - fixup(FU_LONG | FU_MOVEI, sloc, exprbuf); + AddFixup(FU_LONG | FU_MOVEI, sloc, exprbuf); else - fixup(FU_LONG, sloc, exprbuf); + AddFixup(FU_LONG, sloc, exprbuf); D_long(0); } @@ -1098,7 +1087,7 @@ int dep_block(VALUE count, WORD siz, VALUE eval, WORD eattr, TOKEN * exprbuf) case SIZB: if (!defined) { - fixup(FU_BYTE | FU_SEXT, sloc, exprbuf); + AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf); D_byte(0); } else @@ -1117,7 +1106,7 @@ int dep_block(VALUE count, WORD siz, VALUE eval, WORD eattr, TOKEN * exprbuf) case SIZN: if (!defined) { - fixup(FU_WORD | FU_SEXT, sloc, exprbuf); + AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf); D_word(0); } else @@ -1136,7 +1125,7 @@ int dep_block(VALUE count, WORD siz, VALUE eval, WORD eattr, TOKEN * exprbuf) case SIZL: if (!defined) { - fixup(FU_LONG, sloc, exprbuf); + AddFixup(FU_LONG, sloc, exprbuf); D_long(0); } else @@ -1229,8 +1218,8 @@ int d_68000(void) // Switching from gpu/dsp sections should reset any ORG'd Address orgactive = 0; orgwarning = 0; - savsect(); - switchsect(TEXT); + SaveSection(); + SwitchSection(TEXT); return 0; } @@ -1348,7 +1337,7 @@ int d_cargs(void) // Put symbol in "order of definition" list if (!(symbol->sattr & SDECLLIST)) - sym_decl(symbol); + AddToSymbolOrderList(symbol); symbol->sattr |= (ABS | DEFINED | EQUATED); symbol->svalue = eval; @@ -1466,7 +1455,7 @@ int d_cstruct(void) // Put symbol in "order of definition" list if (!(symbol->sattr & SDECLLIST)) - sym_decl(symbol); + AddToSymbolOrderList(symbol); tok += 2; diff --git a/eagen0.c b/eagen0.c index c69ac88..c3feb2c 100644 --- a/eagen0.c +++ b/eagen0.c @@ -19,7 +19,8 @@ int eaNgen(WORD siz) switch (amN) { - case DREG: // "Do nothing" - they're in the opword + // "Do nothing" - they're in the opword + case DREG: case AREG: case AIND: case APOSTINC: @@ -28,10 +29,13 @@ int eaNgen(WORD siz) case AM_CCR: case AM_SR: case AM_NONE: - break; // This is a performance hit, though - case ADISP: // expr(An) + // This is a performance hit, though + break; + case ADISP: + // expr(An) if (w) - { // Just deposit it + { + // Just deposit it if (tdb) rmark(cursect, sloc, tdb, MWORD, NULL); @@ -41,15 +45,17 @@ int eaNgen(WORD siz) D_word(v); } else - { // Arrange for fixup later on - fixup(FU_WORD|FU_SEXT, sloc, aNexpr); + { + // Arrange for fixup later on + AddFixup(FU_WORD|FU_SEXT, sloc, aNexpr); D_word(0); } break; case PCDISP: if (w) - { // Just deposit it + { + // Just deposit it if ((aNexattr & TDB) == cursect) v -= (VALUE)sloc; else if ((aNexattr & TDB) != ABS) @@ -61,19 +67,23 @@ int eaNgen(WORD siz) D_word(v); } else - { // Arrange for fixup later on - fixup(FU_WORD|FU_SEXT|FU_PCREL, sloc, aNexpr); + { + // Arrange for fixup later on + AddFixup(FU_WORD|FU_SEXT|FU_PCREL, sloc, aNexpr); D_word(0); } break; case AINDEXED: - w = (WORD)((aNixreg << 12) | aNixsiz); // Compute ixreg and size+scale + // Compute ixreg and size+scale + w = (WORD)((aNixreg << 12) | aNixsiz); if (aNexattr & DEFINED) - { // Deposit a byte... + { + // Deposit a byte... if (tdb) - return error(abs_error); // Can't mark bytes + // Can't mark bytes + return error(abs_error); if (v + 0x80 >= 0x180) return error(range_error); @@ -82,17 +92,20 @@ int eaNgen(WORD siz) D_word(w); } else - { // Fixup the byte later - fixup(FU_BYTE|FU_SEXT, sloc+1, aNexpr); + { + // Fixup the byte later + AddFixup(FU_BYTE|FU_SEXT, sloc+1, aNexpr); D_word(w); } break; case PCINDEXED: - w = (WORD)((aNixreg << 12) | aNixsiz); // Compute ixreg and size+scale + // Compute ixreg and size+scale + w = (WORD)((aNixreg << 12) | aNixsiz); if (aNexattr & DEFINED) - { // Deposit a byte... + { + // Deposit a byte... if ((aNexattr & TDB) == cursect) v -= (VALUE)sloc; else if ((aNexattr & TDB) != ABS) @@ -105,8 +118,9 @@ int eaNgen(WORD siz) D_word(w); } else - { // Fixup the byte later - fixup(FU_WBYTE|FU_SEXT|FU_PCREL, sloc, aNexpr); + { + // Fixup the byte later + AddFixup(FU_WBYTE|FU_SEXT|FU_PCREL, sloc, aNexpr); D_word(w); } @@ -127,7 +141,7 @@ int eaNgen(WORD siz) } else { - fixup(FU_BYTE|FU_SEXT, sloc+1, aNexpr); + AddFixup(FU_BYTE|FU_SEXT, sloc+1, aNexpr); D_word(0); } @@ -146,7 +160,7 @@ int eaNgen(WORD siz) } else { - fixup(FU_WORD|FU_SEXT, sloc, aNexpr); + AddFixup(FU_WORD|FU_SEXT, sloc, aNexpr); D_word(0); } @@ -161,13 +175,14 @@ int eaNgen(WORD siz) } else { - fixup(FU_LONG, sloc, aNexpr); + AddFixup(FU_LONG, sloc, aNexpr); D_long(0); } break; default: - interror(1); // IMMED size problem + // IMMED size problem + interror(1); } break; @@ -184,7 +199,7 @@ int eaNgen(WORD siz) } else { - fixup(FU_WORD|FU_SEXT, sloc, aNexpr); + AddFixup(FU_WORD|FU_SEXT, sloc, aNexpr); D_word(0); } @@ -199,7 +214,7 @@ int eaNgen(WORD siz) } else { - fixup(FU_LONG, sloc, aNexpr); + AddFixup(FU_LONG, sloc, aNexpr); D_long(0); } @@ -212,7 +227,8 @@ int eaNgen(WORD siz) case PCMPRE: return error("unsupported 68020 addressing mode"); default: - interror(3); // Bad addressing mode in ea gen + // Bad addressing mode in ea gen + interror(3); } return OK; @@ -226,3 +242,4 @@ int eaNgen(WORD siz) #undef aNexpr #undef aNixreg #undef aNixsiz + diff --git a/expr.c b/expr.c index f582408..6373114 100644 --- a/expr.c +++ b/expr.c @@ -20,7 +20,7 @@ #define DEF_KW // Declare keyword values #include "kwtab.h" // Incl generated keyword tables & defs -static char tokenClass[128]; // Generated table of token classes +static char tokenClass[128]; // Generated table of token classes static VALUE evstk[EVSTACKSIZE]; // Evaluator value stack static WORD evattr[EVSTACKSIZE]; // Evaluator attribute stack @@ -364,6 +364,11 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym) p = string[tok[1]]; j = (*p == '.' ? curenv : 0); symbol = lookup(p, LABEL, j); +#if 0 +printf("eval: Looking up symbol [=%08X]\n", symbol); +if (symbol) + printf(" attr=%04X, attre=%08X, val=%i, name=%s\n", symbol->sattr, symbol->sattre, symbol->svalue, symbol->sname); +#endif if (symbol == NULL) symbol = NewSymbol(p, LABEL, j); diff --git a/expr.h b/expr.h index 148157f..ad83d28 100644 --- a/expr.h +++ b/expr.h @@ -12,23 +12,23 @@ #include "rmac.h" // Tunable definitions -#define STKSIZE 64 // Size of expression stacks -#define EVSTACKSIZE 64 // Expression evaluator stack size +#define STKSIZE 64 // Size of expression stacks +#define EVSTACKSIZE 64 // Expression evaluator stack size // Token classes in order of precedence -#define END 0 // End/beginning of input -#define ID 1 // Symbol or constant -#define OPAR 2 // ( -#define CPAR 3 // ) -#define SUNARY 4 // Special unary (^^defined, etc.) -#define UNARY 5 // Unary class: ! ~ - -#define MULT 6 // Multiplicative class: * / % -#define ADD 7 // Additive class: + - -#define SHIFT 8 // Shift class: << >> -#define REL 9 // Relational class: <= >= < > <> = != -#define AND 10 // Bitwise and: & -#define XOR 11 // Bitwise xor: ^ -#define OR 12 // Bitwise or: | +#define END 0 // End/beginning of input +#define ID 1 // Symbol or constant +#define OPAR 2 // ( +#define CPAR 3 // ) +#define SUNARY 4 // Special unary (^^defined, etc.) +#define UNARY 5 // Unary class: ! ~ - +#define MULT 6 // Multiplicative class: * / % +#define ADD 7 // Additive class: + - +#define SHIFT 8 // Shift class: << >> +#define REL 9 // Relational class: <= >= < > <> = != +#define AND 10 // Bitwise and: & +#define XOR 11 // Bitwise xor: ^ +#define OR 12 // Bitwise or: | // Prototypes void InitExpression(void); diff --git a/listing.c b/listing.c index 9dfddc5..5306913 100644 --- a/listing.c +++ b/listing.c @@ -306,7 +306,7 @@ void listeol(void) // deposited with dcb. The fix (kludge) is an extra variable which records // the fact that a 'ds.x' directive generated all the data, and it // shouldn't be listed - savsect(); // Update section variables + SaveSection(); // Update section variables if (lcursect == cursect && (sect[lcursect].scattr & SBSS) == 0 && lsloc != sloc && just_bss == 0) diff --git a/mach.c b/mach.c index 550db61..db45123 100644 --- a/mach.c +++ b/mach.c @@ -307,7 +307,7 @@ int m_shi(WORD inst, WORD siz) } else { - fixup(FU_QUICK, sloc, a0expr); + AddFixup(FU_QUICK, sloc, a0expr); D_word(inst); } @@ -372,7 +372,7 @@ int m_dbra(WORD inst, WORD siz) } else { - fixup(FU_WORD | FU_PCREL | FU_ISBRA, sloc, a1expr); + AddFixup(FU_WORD | FU_PCREL | FU_ISBRA, sloc, a1expr); D_word(0); } @@ -489,7 +489,7 @@ int m_moveq(WORD inst, WORD siz) // Arrange for future fixup if (!(a0exattr & DEFINED)) { - fixup(FU_BYTE | FU_SEXT, sloc + 1, a0expr); + AddFixup(FU_BYTE | FU_SEXT, sloc + 1, a0expr); a0exval = 0; } else if (a0exval + 0x100 >= 0x200) @@ -599,7 +599,7 @@ int m_br(WORD inst, WORD siz) if (siz == SIZB) { // .B - fixup(FU_BBRA | FU_PCREL | FU_SEXT, sloc, a0expr); + AddFixup(FU_BBRA | FU_PCREL | FU_SEXT, sloc, a0expr); D_word(inst); return 0; } @@ -607,7 +607,7 @@ int m_br(WORD inst, WORD siz) { // .W D_word(inst); - fixup(FU_WORD | FU_PCREL | FU_LBRA | FU_ISBRA, sloc, a0expr); + AddFixup(FU_WORD | FU_PCREL | FU_LBRA | FU_ISBRA, sloc, a0expr); D_word(0); } @@ -632,7 +632,7 @@ int m_addq(WORD inst, WORD siz) } else { - fixup(FU_QUICK, sloc, a0expr); + AddFixup(FU_QUICK, sloc, a0expr); D_word(inst); } diff --git a/mark.c b/mark.c index c33f450..3b3bd3a 100644 --- a/mark.c +++ b/mark.c @@ -54,8 +54,9 @@ int rmark(uint16_t from, uint32_t loc, uint16_t to, uint16_t size, SYM * symbol) { #ifdef DEBUG_IMAGE_MARKING printf("rmark: from=%i, loc=$%X, to=$%X, size=$%x, symbol=$%X\n", from, loc, to, size, symbol); +if (symbol) + printf(" symbol->stype=$%02X, sattr=$%04X, sattre=$%08X, svalue=%i, sname=%s\n", symbol->stype, symbol->sattr, symbol->sattre, symbol->svalue, symbol->sname); #endif -// uint16_t w; if ((mcalloc - mcused) < MIN_MARK_MEM) amark(); @@ -212,8 +213,12 @@ printf(" validsegment: raddr = $%08X\n", raddr); else rflag = 0x00000040; // Absolute fixup +// This flag tells the linker to WORD swap the LONG when doing the fixup. if (w & MMOVEI) +//{ +//printf("bsdmarkimg: ORing $01 to rflag (MMOVEI) [symbol=%s]...\n", symbol->sname); rflag |= 0x00000001; +//} } // Compute mark position in relocation information; @@ -231,8 +236,14 @@ printf(" validsegment: raddr = $%08X\n", raddr); rflag |= 0x00000010; // Set external reloc flag bit rflag |= (symbol->senv << 8); // Put symbol index in flags +// Looks like this is completely unnecessary (considering it does the wrong thing!) +#if 0 if (symbol->sattre & RISCSYM) +{ +printf("bsdmarkimg: ORing $01 to rflag (RISCSYM) [symbol=%s]...\n", symbol->sname); rflag |= 0x00000001; +} +#endif if (validsegment) { diff --git a/parmode.h b/parmode.h index 5ef768a..13805fd 100644 --- a/parmode.h +++ b/parmode.h @@ -224,21 +224,25 @@ return ERROR; if (*tok == DOTW) - { // expr.W + { + // expr.W tok++; AMn = ABSW; goto AnOK; } else if (*tok != '(') - { // expr[.L] + { + // expr[.L] AMn = ABSL; - // Defined, absolute values from $FFFF8000..$00007FFF get optimized to absolute short + // Defined, absolute values from $FFFF8000..$00007FFF get optimized + // to absolute short if ((AnEXATTR & (TDB|DEFINED)) == DEFINED && (AnEXVAL + 0x8000) < 0x10000) AMn = ABSW; + // Is .L forced here? if (*tok == DOTL) - { // force .L + { tok++; AMn = ABSL; } diff --git a/procln.c b/procln.c index 727b9db..b56b254 100644 --- a/procln.c +++ b/procln.c @@ -127,7 +127,6 @@ void Assemble(void) SYM * sy, * sy2; // Symbol (temp usage) char * opname = NULL; // Name of dirctve/mnemonic/macro int listflag; // 0: Don't call listeol() -// int as68mode = 0; // 1: Handle multiple labels WORD rmask; // Register list, for REG int registerbank; // RISC register bank int riscreg; // RISC register @@ -172,10 +171,9 @@ loop1: // Internal line processing loop if (*tok == EOL) // Restart loop if end-of-line goto loop; - // First token MUST be a symbol + // First token MUST be a symbol (Shamus: not sure why :-/) if (*tok != SYMBOL) { -// error(syntax_error); error("syntax error; expected symbol"); goto loop; } @@ -194,28 +192,19 @@ loop1: // Internal line processing loop if (j == ':' || j == DCOLON) { as68label: -// 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 - // Handle multiple labels; if there's another label, go process it, - // and come back at `as68label' above. - if (as68_flag) + // AS68 MODE: + // Looks like another label follows the previous one, so handle + // the previous one until there aren't any more + if (as68_flag && (*tok == SYMBOL && tok[2] == ':')) { -// as68mode = 0; - - // Looks like another label follows the previous one, so handle - // the previous one - if (*tok == SYMBOL && tok[2] == ':') - { -// as68mode = 1; -// goto do_label; - if (HandleLabel(label, labtyp) != 0) - goto loop; + if (HandleLabel(label, labtyp) != 0) + goto loop; - goto as68label; - } + goto as68label; } } @@ -226,19 +215,11 @@ as68label: // Next token MUST be a symbol if (*tok++ != SYMBOL) { -// error(syntax_error); error("syntax error; expected symbol"); goto loop; } -// 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 !!!" -#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: @@ -315,6 +296,7 @@ as68label: case MN_MACRO: // .macro --- macro definition if (!disabled) { + // Label on a macro definition is bad mojo... Warn the user if (label != NULL) warn(lab_ignored); @@ -326,7 +308,6 @@ as68label: case MN_ENDM: // .endm --- same as .exitm if (!disabled) { - // Label on a macro definition is bad mojo... Warn the user if (label != NULL) warn(lab_ignored); @@ -337,17 +318,12 @@ as68label: case MN_REPT: if (!disabled) { -#if 0 - if (label != NULL) - warn(lab_ignored); -#else // Handle labels on REPT directive lines... if (label) { if (HandleLabel(label, labtyp) != 0) goto loop; } -#endif defrept(); } @@ -369,14 +345,7 @@ normal: if (equate != NULL) { // Pick global or local symbol enviroment -#if 0 - j = 0; - - if (*equate == '.') - j = curenv; -#else j = (*equate == '.' ? curenv : 0); -#endif sy = lookup(equate, LABEL, j); if (sy == NULL) @@ -419,7 +388,7 @@ normal: // Put symbol in "order of definition" list if (!(sy->sattr & SDECLLIST)) - sym_decl(sy); + AddToSymbolOrderList(sy); // Parse value to equate symbol to; // o .equr @@ -445,7 +414,8 @@ checking to see if it's already been equated, issue a warning. // Check for register to equate to if ((*tok >= KW_R0) && (*tok <= KW_R31)) { - sy->sattre = EQUATEDREG | RISCSYM; // Mark as equated register +// sy->sattre = EQUATEDREG | RISCSYM; // Mark as equated register + sy->sattre = EQUATEDREG; // Mark as equated register riscreg = (*tok - KW_R0); //is there any reason to do this, since we're putting this in svalue? //i'm thinking, no. Let's test that out! :-D @@ -589,63 +559,9 @@ checking to see if it's already been equated, issue a warning. // Do labels if (label != NULL) { -do_label: -#if 0 - // Check for dot in front of label; means this is a local label if present - j = (*label == '.' ? curenv : 0); - sy = lookup(label, LABEL, j); - - if (sy == NULL) - { - sy = NewSymbol(label, LABEL, j); - sy->sattr = 0; - sy->sattre = RISCSYM; - } - else if (sy->sattr & DEFINED) - { - errors("multiply-defined label '%s'", label); - goto loop; - } - - // Put symbol in "order of definition" list - if (!(sy->sattr & SDECLLIST)) - sym_decl(sy); - - if (orgactive) - { - sy->svalue = orgaddr; - sy->sattr |= ABS | DEFINED | EQUATED; - } - else - { - sy->svalue = sloc; - sy->sattr |= DEFINED | cursect; - } - - lab_sym = sy; - - if (!j) - curenv++; - - // Make label global - if (labtyp == DCOLON) - { - if (j) - { - error(locgl_error); - goto loop; - } - - sy->sattr |= GLOBAL; - } -#else // Non-zero == error occurred if (HandleLabel(label, labtyp) != 0) goto loop; -#endif - // If we're in as68 mode, and there's another label, go back and handle it -// if (as68_flag && as68mode) -// goto as68label; } // Punt on EOL @@ -765,45 +681,46 @@ do_label: int HandleLabel(char * label, int labelType) { // Check for dot in front of label; means this is a local label if present - int j = (*label == '.' ? curenv : 0); - SYM * sy = lookup(label, LABEL, j); + int environment = (*label == '.' ? curenv : 0); + SYM * symbol = lookup(label, LABEL, environment); - if (sy == NULL) + if (symbol == NULL) { - sy = NewSymbol(label, LABEL, j); - sy->sattr = 0; - sy->sattre = RISCSYM; + symbol = NewSymbol(label, LABEL, environment); + symbol->sattr = 0; +// symbol->sattre = RISCSYM; + symbol->sattre = 0; } - else if (sy->sattr & DEFINED) + else if (symbol->sattr & DEFINED) return errors("multiply-defined label '%s'", label); // Put symbol in "order of definition" list - if (!(sy->sattr & SDECLLIST)) - sym_decl(sy); + if (!(symbol->sattr & SDECLLIST)) + AddToSymbolOrderList(symbol); if (orgactive) { - sy->svalue = orgaddr; - sy->sattr |= ABS | DEFINED | EQUATED; + symbol->svalue = orgaddr; + symbol->sattr |= ABS | DEFINED | EQUATED; } else { - sy->svalue = sloc; - sy->sattr |= DEFINED | cursect; + symbol->svalue = sloc; + symbol->sattr |= DEFINED | cursect; } - lab_sym = sy; + lab_sym = symbol; - if (!j) + if (0 == environment) curenv++; // Make label global if it has a double colon if (labelType == DCOLON) { - if (j) + if (environment != 0) return error(locgl_error); - sy->sattr |= GLOBAL; + symbol->sattr |= GLOBAL; } return 0; @@ -883,3 +800,4 @@ int d_endif (void) f_ifent = rif; return 0; } + diff --git a/riscasm.c b/riscasm.c index 2754600..e55a986 100644 --- a/riscasm.c +++ b/riscasm.c @@ -3,7 +3,7 @@ // RISCA.C - GPU/DSP Assembler // Copyright (C) 199x Landon Dyer, 2011 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 -// Source Utilised with the Kind Permission of Landon Dyer +// Source utilised with the kind permission of Landon Dyer // #include "riscasm.h" @@ -15,11 +15,11 @@ #include "mark.h" #include "amode.h" -#define DEF_MR // Declar keyword values -#include "risckw.h" // Incl generated risc keywords +#define DEF_MR // Declare keyword values +#include "risckw.h" // Incl. generated risc keywords #define DEF_KW // Declare keyword values -#include "kwtab.h" // Incl generated keyword tables & defs +#include "kwtab.h" // Incl. generated keyword tables & defs unsigned altbankok = 0; // Ok to use alternate register bank @@ -28,22 +28,22 @@ unsigned orgaddr = 0; // Org'd address unsigned orgwarning = 0; // Has an ORG warning been issued int lastOpcode = -1; // Last RISC opcode assembled -char reg_err[] = "missing register R0...R31"; +const char reg_err[] = "missing register R0...R31"; // Jaguar Jump Condition Names -char condname[MAXINTERNCC][5] = { +const char condname[MAXINTERNCC][5] = { "NZ", "Z", "NC", "NCNZ", "NCZ", "C", "CNZ", "CZ", "NN", "NNNZ", "NNZ", "N", "N_NZ", "N_Z", "T", "A", "NE", "EQ", "CC", "HS", "HI", "CS", "LO", "PL", "MI", "F" }; // Jaguar Jump Condition Numbers -char condnumber[] = { +const char condnumber[] = { 1, 2, 4, 5, 6, 8, 9, 10, 20, 21, 22, 24, 25, 26, 0, 0, 1, 2, 4, 4, 5, 8, 8, 20, 24, 31 }; -struct opcoderecord roptbl[] = { +const struct opcoderecord roptbl[] = { { MR_ADD, RI_TWO, 0 }, { MR_ADDC, RI_TWO, 1 }, { MR_ADDQ, RI_NUM_32, 2 }, @@ -110,7 +110,7 @@ struct opcoderecord roptbl[] = { // -// Convert a String to Uppercase +// Convert a string to uppercase // void strtoupper(char * s) { @@ -127,20 +127,20 @@ static inline int MalformedOpcode(int signal) { char buf[16]; sprintf(buf, "%02X", signal); - errors("Malformed opcode [internal $%s]", buf); - return ERROR; + return errors("Malformed opcode [internal $%s]", buf); } // -// Build RISC Instruction Word +// Build RISC instruction word // void BuildRISCIntructionWord(unsigned short opcode, int reg1, int reg2) { // Check for absolute address setting if (!orgwarning && !orgactive) { - warn("GPU/DSP code outside of absolute section"); +// warn("GPU/DSP code outside of absolute section"); + warn("RISC code generated with no origin defined"); orgwarning = 1; } @@ -150,7 +150,7 @@ void BuildRISCIntructionWord(unsigned short opcode, int reg1, int reg2) // -// Get a RISC Register +// Get a RISC register // int GetRegister(WORD rattr) { @@ -170,7 +170,7 @@ int GetRegister(WORD rattr) if (!(eattr & DEFINED)) { - fixup((WORD)(FU_WORD | rattr), sloc, r_expr); + AddFixup((WORD)(FU_WORD | rattr), sloc, r_expr); return 0; } @@ -179,13 +179,12 @@ int GetRegister(WORD rattr) return eval; // Otherwise, it's out of range & we flag an error - error(reg_err); - return ERROR; + return error(reg_err); } // -// Do RISC Code Generation +// Do RISC code generation // int GenerateRISCCode(int state) { @@ -213,10 +212,7 @@ int GenerateRISCCode(int state) // specific to only one of the RISC processors and ensure it is legal in // the current code section. If not then show error and return. if (((parm & GPUONLY) && rdsp) || ((parm & DSPONLY) && rgpu)) - { - error("Opcode is not valid in this code section"); - return ERROR; - } + return error("Opcode is not valid in this code section"); // Process RISC opcode switch (type) @@ -294,16 +290,13 @@ int GenerateRISCCode(int state) if (!(eattr & DEFINED)) { - fixup((WORD)(FU_WORD | attrflg), sloc, r_expr); + AddFixup((WORD)(FU_WORD | attrflg), sloc, r_expr); reg1 = 0; } else { if ((int)eval < reg1 || (int)eval > reg2) - { - error("constant out of range"); - return ERROR; - } + return error("constant out of range"); if (parm & SUB32) reg1 = 32 - eval; @@ -346,7 +339,7 @@ int GenerateRISCCode(int state) if (!(eattr & DEFINED)) { - fixup(FU_LONG | FU_MOVEI, sloc + 2, r_expr); + AddFixup(FU_LONG | FU_MOVEI, sloc + 2, r_expr); eval = 0; } else @@ -467,10 +460,7 @@ int GenerateRISCCode(int state) chcheck(4L); if (!(eattr & DEFINED)) - { - error("constant expected after '+'"); - return ERROR; - } + return error("constant expected after '+'"); reg1 = eval; @@ -483,10 +473,7 @@ int GenerateRISCCode(int state) else { if (reg1 < 1 || reg1 > 32) - { - error("constant in LOAD out of range"); - return ERROR; - } + return error("constant in LOAD out of range"); if (reg1 == 32) reg1 = 0; @@ -528,7 +515,6 @@ int GenerateRISCCode(int state) if (*tok == SYMBOL) { -// sy = lookup((char *)tok[1], LABEL, 0); sy = lookup(string[tok[1]], LABEL, 0); if (!sy) @@ -568,7 +554,6 @@ int GenerateRISCCode(int state) if (*tok == SYMBOL) { -// sy = lookup((char *)tok[1], LABEL, 0); sy = lookup(string[tok[1]], LABEL, 0); if (!sy) @@ -595,7 +580,7 @@ int GenerateRISCCode(int state) if (!(eattr & DEFINED)) { - fixup(FU_WORD | FU_REGTWO, sloc, r_expr); + AddFixup(FU_WORD | FU_REGTWO, sloc, r_expr); reg2 = 0; } else @@ -611,10 +596,7 @@ int GenerateRISCCode(int state) else { if (reg2 < 1 || reg2 > 32) - { - error("constant in STORE out of range"); - return ERROR; - } + return error("constant in STORE out of range"); if (reg2 == 32) reg2 = 0; @@ -731,10 +713,7 @@ int GenerateRISCCode(int state) val = ccsym->svalue; } else - { - error("unknown condition code"); - return ERROR; - } + return error("unknown condition code"); } tok += 2; @@ -753,10 +732,7 @@ int GenerateRISCCode(int state) } if (val < 0 || val > 31) - { - error("condition constant out of range"); - return ERROR; - } + return error("condition constant out of range"); // Store condition code reg1 = val; @@ -772,7 +748,7 @@ int GenerateRISCCode(int state) if (!(eattr & DEFINED)) { - fixup(FU_WORD | FU_JR, sloc, r_expr); + AddFixup(FU_WORD | FU_JR, sloc, r_expr); reg2 = 0; } else @@ -806,8 +782,7 @@ int GenerateRISCCode(int state) // Should never get here :-D default: - error("Unknown risc opcode type"); - return ERROR; + return error("Unknown RISC opcode type"); } lastOpcode = type; diff --git a/rmac.c b/rmac.c index c47adf2..4506a95 100644 --- a/rmac.c +++ b/rmac.c @@ -105,9 +105,9 @@ int kmatch(char * p, int * base, int * check, int * tab, int * accept) // void autoeven(int sect) { - switchsect(sect); + SwitchSection(sect); d_even(); - savsect(); + SaveSection(); } @@ -470,11 +470,11 @@ int process(int argc, char ** argv) // o determine name of object file: // - "foo.o" for linkable output; // - "foo.prg" for GEMDOS executable (-p flag). - savsect(); + SaveSection(); for(i=TEXT; i<=BSS; i<<=1) { - switchsect(i); + SwitchSection(i); switch(segpadsize) { @@ -485,7 +485,7 @@ int process(int argc, char ** argv) case 32: d_qphrase(); break; } - savsect(); + SaveSection(); } if (objfname == NULL) diff --git a/rmac.h b/rmac.h index 25f69f5..24da33d 100644 --- a/rmac.h +++ b/rmac.h @@ -165,7 +165,7 @@ PTR #define EQUATEDCC 0x0020 #define UNDEF_CC 0x0040 -#define RISCSYM 0x00010000 +//#define RISCSYM 0x00010000 // Globals, externals etc extern int verb_flag; @@ -183,7 +183,7 @@ extern int lsym_flag; extern int sbra_flag; extern int obj_format; extern int legacy_flag; -extern LONG amemtot; +//extern LONG amemtot; // Prototypes void init_sym(void); diff --git a/sect.c b/sect.c index fe630b1..d4277fc 100644 --- a/sect.c +++ b/sect.c @@ -19,8 +19,8 @@ // Function prototypes -void mksect(int, WORD); -void switchsect(int); +void MakeSection(int, WORD); +void SwitchSection(int); // Section descriptors SECT sect[NSECTS]; // All sections... @@ -77,23 +77,23 @@ void InitSection(void) // Cleanup all sections for(i=0; iscattr = attr; @@ -104,10 +104,10 @@ void mksect(int sno, WORD attr) // -// Switch to Another Section (Copy Section & Chunk Descriptors to Global Vars -// for Fast Access) +// Switch to another section (copy section & chunk descriptors to global vars +// for fast access) // -void switchsect(int sno) +void SwitchSection(int sno) { CHUNK * cp; // Chunk pointer cursect = sno; @@ -141,9 +141,9 @@ void switchsect(int sno) // -// Save Current Section +// Save current section // -void savsect(void) +void SaveSection(void) { SECT * p = §[cursect]; @@ -263,14 +263,14 @@ int chcheck(LONG amt) // // Arrange for a fixup on a location // -int fixup(WORD attr, LONG loc, TOKEN * fexpr) +int AddFixup(WORD attr, LONG loc, TOKEN * fexpr) { LONG i; LONG len = 0; CHUNK * cp; SECT * p; // Shamus: Expression lengths are voodoo ATM (variable "i"). Need to fix this. -#warning "!!! fixup() is filled with VOODOO !!!" +#warning "!!! AddFixup() is filled with VOODOO !!!" DEBUG printf("FIXUP@$%X: $%X\n", loc, attr); // Compute length of expression (could be faster); determine if it's the @@ -280,7 +280,7 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr) { // Just a single symbol // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN ! - if ((attr & 0x0F00) == FU_JR) + if ((attr & FUMASKRISC) == FU_JR) { // i = 18; // i = FIXUP_BASE_SIZE + (sizeof(LONG) * 2); @@ -358,7 +358,7 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr) } // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN ! - if ((attr & 0x0F00) == FU_JR) + if ((attr & FUMASKRISC) == FU_JR) { if (orgactive) *fchptr.lp++ = orgaddr; @@ -388,28 +388,6 @@ int ResolveAllFixups(void) DEBUG printf("Resolving DATA sections...\n"); ResolveFixups(DATA); -//No, no we don't. -#if 0 - // We need to do a final check of forward 'jump' destination addresses that - // are external - for(i=0; i 0) - ship_ln(buf); - - if (err_flag) - write(err_fd, buf, (LONG)strlen(buf)); - else - printf("%s\n", buf); - } - } -#endif - return 0; } @@ -444,9 +422,11 @@ int ResolveFixups(int sno) if (ch == NULL) return 0; - CHUNK * cch = sc->sfcode; // "cache" first chunk + // "Cache" first chunk + CHUNK * cch = sc->sfcode; - if (cch == NULL) // Can't fixup a sect with nothing in it + // Can't fixup a sect with nothing in it + if (cch == NULL) return 0; do @@ -481,7 +461,8 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } if (cch == NULL) { - interror(7); // Fixup (loc) out of range + // Fixup (loc) out of range + interror(7); // NOTREACHED } } @@ -522,14 +503,20 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } // If the expression is undefined and no external symbol is // involved, then it's an error. - if (!(eattr & DEFINED) && esym == NULL) + if (!(eattr & DEFINED) && (esym == NULL)) { error(undef_error); continue; } - if (((w & 0x0F00) == FU_MOVEI) && esym) +// It seems that this is completely unnecessary! +#if 0 + if (((w & FUMASKRISC) == FU_MOVEI) && esym) +//{ +//printf("DoFixups: Setting symbol attre to RISCSYM...\n"); esym->sattre |= RISCSYM; +//} +#endif // Do the fixup // @@ -625,7 +612,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } // 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)) + if ((w & FUMASKRISC) == FU_JR)// || ((w & 0x0F00) == FU_MJR)) { oaddr = *fup.lp++; @@ -685,7 +672,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } break; } - if ((w & 0x0F00) == FU_NUM15) + if ((w & FUMASKRISC) == FU_NUM15) { if (eval < -16 || eval > 15) { @@ -699,7 +686,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } break; } - if ((w & 0x0F00) == FU_NUM31) + if ((w & FUMASKRISC) == FU_NUM31) { if (eval < 0 || eval > 31) { @@ -713,7 +700,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } break; } - if ((w & 0x0F00) == FU_NUM32) + if ((w & FUMASKRISC) == FU_NUM32) { if (eval < 1 || eval > 32) { @@ -731,7 +718,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } break; } - if ((w & 0x0F00) == FU_REGONE) + if ((w & FUMASKRISC) == FU_REGONE) { if (eval < 0 || eval > 31) { @@ -745,7 +732,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } break; } - if ((w & 0x0F00) == FU_REGTWO) + if ((w & FUMASKRISC) == FU_REGTWO) { if (eval < 0 || eval > 31) { @@ -797,7 +784,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } // the long could be unaligned in the section buffer, so be careful // (again). case FU_LONG: - if ((w & 0x0F00) == FU_MOVEI) + if ((w & FUMASKRISC) == FU_MOVEI) { #if 0 address = loc + 4; @@ -851,6 +838,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); } } #endif + // Long constant in MOVEI # is word-swapped, so fix it here eval = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000); flags = (MLONG | MMOVEI); } diff --git a/sect.h b/sect.h index d86056d..8759eda 100644 --- a/sect.h +++ b/sect.h @@ -64,14 +64,15 @@ #define FU_PCREL 020 // Subtract PC first #define FU_EXPR 040 // Expression (not symbol) follows +#define FUMASKRISC 0x0F00 // Mask for RISC fixup cases #define FU_MOVEI 0x0100 #define FU_JR 0x0200 -//#define FU_MJR 0x0300 #define FU_REGONE 0x0400 #define FU_NUM15 0x0500 #define FU_NUM31 0x0600 #define FU_NUM32 0x0700 #define FU_REGTWO 0x0800 + #define FU_SUB32 0x1000 #define FU_ISBRA 0x2000 // Word forward fixup is a BRA or DBRA #define FU_LBRA 0x4000 // Long branch, for short branch detect @@ -120,10 +121,6 @@ MCHUNK { #define MCHEND 0x2000 // Indicates end of mark chunk #define MPCREL 0x1000 // Mark is PC-relative -//#define MAXFWDJUMPS 1024 // Maximum forward jumps to check -//extern unsigned fwdjump[MAXFWDJUMPS]; -//extern unsigned fwindex; - // Globals, external etc extern LONG sloc; extern WORD scattr; @@ -136,11 +133,11 @@ extern CHUNK * scode; // Prototypes void InitSection(void); -void switchsect(int); -void savsect(void); +void SwitchSection(int); +void SaveSection(void); int fixtest(int, LONG); int chcheck(LONG); -int fixup(WORD, LONG, TOKEN *); +int AddFixup(WORD, LONG, TOKEN *); int ResolveAllFixups(void); #endif // __SECT_H__ diff --git a/symbol.c b/symbol.c index f8d8424..d476121 100644 --- a/symbol.c +++ b/symbol.c @@ -91,7 +91,12 @@ SYM * NewSymbol(char * name, int type, int envno) symbol->stype = (BYTE)type; symbol->senv = (WORD)envno; symbol->sattr = 0; - symbol->sattre = (rgpu || rdsp ? RISCSYM : 0); +//we don't do this, it could be a forward reference! +// symbol->sattr = DEFINED; // We just defined it... + // This is a bad assumption. Not every symbol 1st seen in a RISC section is + // a RISC symbol! +// symbol->sattre = (rgpu || rdsp ? RISCSYM : 0); + symbol->sattre = 0; symbol->svalue = 0; symbol->sorder = NULL; symbol->uid = currentUID++; @@ -165,7 +170,8 @@ SYM * lookup(char * name, int type, int envno) // // Put symbol on "order-of-declaration" list of symbols // -void sym_decl(SYM * symbol) +//void sym_decl(SYM * symbol) +void AddToSymbolOrderList(SYM * symbol) { if (symbol->sattr & SDECLLIST) return; // Already on list diff --git a/symbol.h b/symbol.h index eaf9107..e183b43 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 sym_decl(SYM *); +void AddToSymbolOrderList(SYM *); int syg_fix(void); int symtable(void); int sy_assign(char *, char *(*)()); diff --git a/version.h b/version.h index 0302423..75e1c56 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 2 // Minor version number -#define PATCH 13 // Patch release number +#define PATCH 15 // Patch release number #endif // __VERSION_H__