Added new optimisation option "+op" which enforces PC relative mode (#123)
authorggn <ggn.dbug@gmail.com>
Fri, 17 Jan 2020 11:56:40 +0000 (13:56 +0200)
committerShamus Hammons <jlhamm@acm.org>
Fri, 17 Jan 2020 19:56:41 +0000 (13:56 -0600)
eagen0.c
expr.c
parmode.h
rmac.c
rmac.h
sect.c

index 1d94c077cf49b8d7424f9ba1b5447daca78f2642..2df5eceea09d11eb470232e8796d48c950bca594 100644 (file)
--- a/eagen0.c
+++ b/eagen0.c
@@ -326,6 +326,10 @@ int eaNgen(WORD siz)
        case ABSL:
                if (w) // Defined
                {
+                       if (optim_pc)
+                               if (aNexattr&(DEFINED | REFERENCED | EQUATED) == DEFINED | REFERENCED)
+                                       return error("relocation not allowed");
+
                        if (tdb)
                                MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
 
diff --git a/expr.c b/expr.c
index 3e60d88ace2a8028c85b9cf9f027f7e78e86e2cf..f31e9e59ddf67c1be317af23a1428c22da4ee534 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -180,7 +180,7 @@ int expr1(void)
 
                        if ((fd = open(string[*tok], _OPEN_INC)) < 0)
                        {
-                               for(i=0; nthpath("RMACPATH", i, buf1)!= 0; i++)
+                               for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
                                {
                                        fd = strlen(buf1);
 
index ca313efb1bd8dbcff02169303831d0c8bc4f6bc8..955fade88621de27095dad9fba6f613c8498f76f 100644 (file)
--- a/parmode.h
+++ b/parmode.h
@@ -81,7 +81,7 @@
                }
                else if ((*tok >= KW_D0) && (*tok <= KW_D7))
                {
-                       //Since index register isn't used here, store register number in this field
+                       // Since index register isn't used here, store register number in this field
                        AnIXREG = *tok++ & 7;                                // (Dn)
 
                        if (*tok == ')')
@@ -1169,6 +1169,14 @@ CHK_FOR_DISPn:
                        // expr[.L]
                        AMn = ABSL;
 
+                       // When PC relative is enforced, check for any symbols that aren't 
+                       // EQU'd, in this case it's an illegal mode
+                       if (optim_pc)
+                               if (AnEXATTR & REFERENCED)
+                                       if (AnEXATTR & DEFINED)
+                                               if (!(AnEXATTR & EQUATED))
+                                                       return error("relocation not allowed");
+
                        // .L is forced here
                        if (*tok == DOTL)
                        {
diff --git a/rmac.c b/rmac.c
index 087225eec049263c548aba1dd0cac2654f412c58..bcb587a8925e64d79a6699966da33328617b5bdd 100644 (file)
--- a/rmac.c
+++ b/rmac.c
@@ -53,6 +53,7 @@ char * cmdlnexec;                             // Executable name, pointer to ARGV[0]
 char * searchpath;                             // Search path for include files
 char defname[] = "noname.o";   // Default output filename
 int optim_flags[OPT_COUNT];            // Specific optimisations on/off matrix
+int optim_pc = 0;                              // Enforce PC relative
 int activecpu = CPU_68000;             // Active 68k CPU (68000 by default)
 int activefpu = FPU_NONE;              // Active FPU (none by default)
 int org68k_active = 0;                 // .org switch for 68k (only with RAW output format)
@@ -173,6 +174,7 @@ void DisplayHelp(void)
                "                    o7: clr.l Dx to moveq #0,Dx                 (off)\n"
                "                    o8: adda.w/l #x,Dy to addq.w/l #x,Dy        (off)\n"
                "                    o9: adda.w/l #x,Dy to lea x(Dy),Dy          (off)\n"
+               "                    op: Enforce PC relative                     (off)\n"
                "  ~o[value]         Turn a specific optimisation off\n"
                "  +oall             Turn all optimisations on\n"
                "  ~oall             Turn all optimisations off\n"
@@ -232,6 +234,12 @@ int ParseOptimization(char * optstring)
        }
        else if (optstring[1] == 'o' || optstring[1] == 'O') // Turn on specific optimisation
        {
+               if (optstring[2] == 'p' || optstring[2] == 'P')
+               {
+                       optim_pc = 1;
+                       return OK;
+               }
+
                int opt_no = atoi(&optstring[2]);
 
                if ((opt_no >= 0) && (opt_no < OPT_COUNT))
diff --git a/rmac.h b/rmac.h
index 5ae6d13f76f15a9ced6144513909c4dd204a7101..1c6fcf15c71249d6c562b0a6bbd649f4d8eca8b8 100644 (file)
--- a/rmac.h
+++ b/rmac.h
@@ -316,6 +316,7 @@ extern int legacy_flag;
 extern int prg_flag;   // 1 = write ".PRG" relocatable executable
 extern LONG PRGFLAGS;
 extern int optim_flags[OPT_COUNT];
+extern int optim_pc;
 extern int activecpu;
 extern int activefpu;
 extern uint32_t org68k_address;
diff --git a/sect.c b/sect.c
index 0ea53a843f1c4568dec445fcab7c7f3a179ed014..781a81bda516c5e5fdbf7f0f06351a8a3e63f69e 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -415,6 +415,15 @@ int ResolveFixups(int sno)
                        // evexpr presumably issues the errors/warnings here
                        if (evexpr(fup->expr, &eval, &eattr, &esym) != OK)
                                continue;
+
+                       if (optim_pc)
+                               if (eattr & REFERENCED)
+                                       if (eattr & DEFINED)
+                                               if (!(eattr & EQUATED))
+                                               {
+                                                       error("relocation not allowed");
+                                                       continue;
+                                               }
                }
                // Simple symbol
                else
@@ -422,6 +431,15 @@ int ResolveFixups(int sno)
                        SYM * sy = fup->symbol;
                        eattr = sy->sattr;
 
+                       if (optim_pc)
+                               if (eattr & REFERENCED)
+                                       if (eattr & DEFINED)
+                                               if (!(eattr & EQUATED))
+                                               {
+                                                       error("relocation not allowed");
+                                                       continue;
+                                               }
+
                        if (eattr & DEFINED)
                                eval = sy->svalue;
                        else