From fbbe9b115f949735421485513154ce8abb8453eb Mon Sep 17 00:00:00 2001 From: ggn Date: Fri, 17 Jan 2020 13:56:40 +0200 Subject: [PATCH] Added new optimisation option "+op" which enforces PC relative mode (#123) --- eagen0.c | 4 ++++ expr.c | 2 +- parmode.h | 10 +++++++++- rmac.c | 8 ++++++++ rmac.h | 1 + sect.c | 18 ++++++++++++++++++ 6 files changed, 41 insertions(+), 2 deletions(-) diff --git a/eagen0.c b/eagen0.c index 1d94c07..2df5ece 100644 --- 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 3e60d88..f31e9e5 100644 --- 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); diff --git a/parmode.h b/parmode.h index ca313ef..955fade 100644 --- 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 087225e..bcb587a 100644 --- 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 5ae6d13..1c6fcf1 100644 --- 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 0ea53a8..781a81b 100644 --- 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 -- 2.37.2