X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=riscasm.c;h=2754600b2dabdcee7561eae01cb717e64c6cc4aa;hp=f2ffa4d34563edc781ffffcef605bd0e19b3a92d;hb=9df4696c6d38b7908dd83f95509fc14f2f7c799c;hpb=82307651be6db411532b317a5ebc6edd933eea8d diff --git a/riscasm.c b/riscasm.c index f2ffa4d..2754600 100644 --- a/riscasm.c +++ b/riscasm.c @@ -26,13 +26,14 @@ 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 lastOpcode = -1; // Last RISC opcode assembled char reg_err[] = "missing register R0...R31"; // Jaguar Jump Condition Names 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", + "N", "N_NZ", "N_Z", "T", "A", "NE", "EQ", "CC", "HS", "HI", "CS", "LO", "PL", "MI", "F" }; @@ -113,16 +114,8 @@ struct opcoderecord roptbl[] = { // void strtoupper(char * s) { -#if 0 - while (*s) - { - *s = (char)(toupper(*s)); - s++; - } -#else while (*s) *s++ &= 0xDF; -#endif } @@ -130,9 +123,11 @@ void strtoupper(char * s) // Function to return "malformed expression" error // This is done mainly to remove a bunch of GOTO statements in the parser // -static inline int MalformedOpcode(void) +static inline int MalformedOpcode(int signal) { - error("Malformed opcode"); + char buf[16]; + sprintf(buf, "%02X", signal); + errors("Malformed opcode [internal $%s]", buf); return ERROR; } @@ -166,7 +161,9 @@ int GetRegister(WORD rattr) // Evaluate what's in the global "tok" buffer if (expr(r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(); + // Hmm, the evaluator should report the error to us... +// return MalformedOpcode(0x00); + return ERROR; if ((challoc - ch_size) < 4) chcheck(4L); @@ -225,8 +222,8 @@ int GenerateRISCCode(int state) switch (type) { // No operand instructions - // NOP - case RI_NONE: + // NOP (57) + case RI_NONE: BuildRISCIntructionWord(parm, 0, 0); break; @@ -285,12 +282,12 @@ int GenerateRISCCode(int state) attrflg |= FU_SUB32; if (*tok != '#') - return MalformedOpcode(); + return MalformedOpcode(0x01); tok++; if (expr(r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(); + return MalformedOpcode(0x02); if ((challoc - ch_size) < 4) chcheck(4L); @@ -325,12 +322,24 @@ int GenerateRISCCode(int state) // Move Immediate--n,Rn--n in Second Word case RI_MOVEI: if (*tok != '#') - return MalformedOpcode(); + return MalformedOpcode(0x03); tok++; if (expr(r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(); + return MalformedOpcode(0x04); + + if (lastOpcode == RI_JUMP || lastOpcode == RI_JR) + { + if (legacy_flag) + { + // User doesn't care, emit a NOP to fix + BuildRISCIntructionWord(57, 0, 0); + warn("MOVEI following JUMP, inserting NOP to fix your BROKEN CODE"); + } + else + warn("MOVEI immediately follows JUMP"); + } if ((challoc - ch_size) < 4) chcheck(4L); @@ -383,7 +392,7 @@ int GenerateRISCCode(int state) parm = 41; if (*tok != '(') - return MalformedOpcode(); + return MalformedOpcode(0x05); tok++; @@ -452,14 +461,14 @@ int GenerateRISCCode(int state) else { if (expr(r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(); + return MalformedOpcode(0x06); if ((challoc - ch_size) < 4) chcheck(4L); if (!(eattr & DEFINED)) { - error("constant expected"); + error("constant expected after '+'"); return ERROR; } @@ -469,13 +478,13 @@ int GenerateRISCCode(int state) { reg1 = 14 + (parm - 58); parm = 41; - warn("NULL offset removed"); + warn("NULL offset in LOAD ignored"); } else { if (reg1 < 1 || reg1 > 32) { - error("constant out of range"); + error("constant in LOAD out of range"); return ERROR; } @@ -493,7 +502,7 @@ int GenerateRISCCode(int state) } if (*tok != ')') - return MalformedOpcode(); + return MalformedOpcode(0x07); tok++; CHECK_COMMA; @@ -509,7 +518,7 @@ int GenerateRISCCode(int state) CHECK_COMMA; if (*tok != '(') - return MalformedOpcode(); + return MalformedOpcode(0x08); tok++; indexed = 0; @@ -579,7 +588,7 @@ int GenerateRISCCode(int state) else { if (expr(r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(); + return MalformedOpcode(0x09); if ((challoc - ch_size) < 4) chcheck(4L); @@ -597,13 +606,13 @@ int GenerateRISCCode(int state) { reg2 = 14 + (parm - 60); parm = 47; - warn("NULL offset removed"); + warn("NULL offset in STORE ignored"); } else { if (reg2 < 1 || reg2 > 32) { - error("constant out of range"); + error("constant in STORE out of range"); return ERROR; } @@ -622,7 +631,7 @@ int GenerateRISCCode(int state) } if (*tok != ')') - return MalformedOpcode(); + return MalformedOpcode(0x0A); tok++; at_eol(); @@ -632,13 +641,13 @@ int GenerateRISCCode(int state) // LOADB/LOADP/LOADW (Rn),Rn case RI_LOADN: if (*tok != '(') - return MalformedOpcode(); + return MalformedOpcode(0x0B); tok++; reg1 = GetRegister(FU_REGONE); if (*tok != ')') - return MalformedOpcode(); + return MalformedOpcode(0x0C); tok++; CHECK_COMMA; @@ -653,13 +662,13 @@ int GenerateRISCCode(int state) CHECK_COMMA; if (*tok != '(') - return MalformedOpcode(); + return MalformedOpcode(0x0D); tok++; reg2 = GetRegister(FU_REGTWO); if (*tok != ')') - return MalformedOpcode(); + return MalformedOpcode(0x0E); tok++; at_eol(); @@ -756,7 +765,7 @@ int GenerateRISCCode(int state) { // JR cc,n if (expr(r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(); + return MalformedOpcode(0x0F); if ((challoc - ch_size) < 4) chcheck(4L); @@ -780,13 +789,13 @@ int GenerateRISCCode(int state) { // JUMP cc, (Rn) if (*tok != '(') - return MalformedOpcode(); + return MalformedOpcode(0x10); tok++; reg2 = GetRegister(FU_REGTWO); if (*tok != ')') - return MalformedOpcode(); + return MalformedOpcode(0x11); tok++; at_eol(); @@ -801,6 +810,7 @@ int GenerateRISCCode(int state) return ERROR; } + lastOpcode = type; return 0; }