Added "legacy mode" to assembler, which is on by default.
authorShamus Hammons <jlhamm@acm.org>
Mon, 13 Jan 2014 03:44:04 +0000 (21:44 -0600)
committerShamus Hammons <jlhamm@acm.org>
Mon, 13 Jan 2014 03:44:04 +0000 (21:44 -0600)
Apparently MAC did fixups for programmers who forgot that they couldn't
put a MOVEI immediately after a JUMP or JR, so we do the same to keep
legacy code assembling (though we may flip the default to OFF at some
time in the future :-P). If you don't like the assembler doing stuff like
that behind your back, you can tell it not to by adding the -n switch to
your command line.

There are lots of other cases that the user should be warned about with
RISC code; these will be added in future commits. :-)

riscasm.c
rmac.c
rmac.h
version.h

index 89dfd3a881b831b3a6c9ac7e28d94b2c68c756fe..4925adce0c8cc2b46ac0750af4ed422ac5df9702 100644 (file)
--- a/riscasm.c
+++ b/riscasm.c
@@ -26,6 +26,7 @@ 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";
 
@@ -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
 }
 
 
@@ -229,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;
 
@@ -336,6 +329,18 @@ int GenerateRISCCode(int state)
                if (expr(r_expr, &eval, &eattr, &esym) != OK)
                        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 following JUMP");
+               }
+
                if ((challoc - ch_size) < 4)
                        chcheck(4L);
 
@@ -463,7 +468,7 @@ int GenerateRISCCode(int state)
 
                                        if (!(eattr & DEFINED))
                                        {
-                                               error("constant expected");
+                                               error("constant expected after '+'");
                                                return ERROR;
                                        }
 
@@ -473,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;
                                                }
 
@@ -601,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;
                                                        }
 
@@ -805,6 +810,7 @@ int GenerateRISCCode(int state)
                return ERROR;
        }
 
+       lastOpcode = type;
        return 0;
 }
 
diff --git a/rmac.c b/rmac.c
index ffa3165553e2e7df78f0ba4f165ccb10e69b5545..c47adf2b2997cd60fe8e519cab9f3f1b516cdc3c 100644 (file)
--- a/rmac.c
+++ b/rmac.c
@@ -29,6 +29,7 @@ int as68_flag;                                                // as68 kludge mode
 int glob_flag;                                         // Assume undefined symbols are global
 int lsym_flag;                                         // Include local symbols in object file
 int sbra_flag;                                         // Warn about possible short branches
+int legacy_flag;                                       // Do stuff like insert code in RISC assembler
 int obj_format;                                                // Object format flag
 int debug;                                                     // [1..9] Enable debugging levels
 int err_flag;                                          // '-e' specified
@@ -203,6 +204,7 @@ void display_help(void)
                "                    b: BSD (use this for Jaguar)\n"
                "  -i[path]          Directory to search for include files\n"
                "  -l[filename]      Create an output listing file\n"
+               "  -n                Don't do things behind your back in RISC assembler\n"
                "  -o file           Output file name\n"
                "  -r[size]          Pad segments to boundary size specified\n"
                "                    w: word (2 bytes, default alignment)\n"
@@ -427,6 +429,11 @@ int process(int argc, char ** argv)
                                display_help();
                                errcnt++;
                                break;
+                       case 'n':                                       // Turn off legacy mode
+                       case 'N':
+                               legacy_flag = 0;
+                               printf("Legacy mode OFF\n");
+                               break;
                        default:
                                display_version();
                                printf("Unknown switch: %s\n\n", argv[argno]);
@@ -559,6 +566,7 @@ int get_endianess(void)
 int main(int argc, char ** argv)
 {
        perm_verb_flag = 0;                             // Clobber "permanent" verbose flag
+       legacy_flag = 1;                                // Default is legacy mode on (:-P)
        cmdlnexec = argv[0];                    // Obtain executable name
 
        endian = get_endianess();               // Get processor endianess
@@ -574,3 +582,4 @@ int main(int argc, char ** argv)
 
        return 0;
 }
+
diff --git a/rmac.h b/rmac.h
index 27bfe69c0f49a3acb1972925bbad7216e534011e..25f69f58757f4e42951387d42b1f3ccaabade7b2 100644 (file)
--- a/rmac.h
+++ b/rmac.h
@@ -182,6 +182,7 @@ extern int glob_flag;
 extern int lsym_flag;
 extern int sbra_flag;
 extern int obj_format;
+extern int legacy_flag;
 extern LONG amemtot;
 
 // Prototypes
index b071eb7d4a11fcb3c767036d8ea4279ed1ce2c13..fc7fd37bb99b289110bd36b8f06813baea209c98 100644 (file)
--- a/version.h
+++ b/version.h
@@ -13,6 +13,6 @@
 
 #define MAJOR   1                      // Major version number
 #define MINOR   2                      // Minor version number
-#define PATCH   8                      // Patch release number
+#define PATCH   9                      // Patch release number
 
 #endif // __VERSION_H__