X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=rmac.c;h=4772d203bd93d612f5e9e6a7121ae37e98fc9786;hp=a1ae0bdd5ec4f727a2a0d0b666f0f7b66bfee609;hb=HEAD;hpb=5b53a2a9e5340f11db9670cda34c4da4fd19ea85 diff --git a/rmac.c b/rmac.c index a1ae0bd..17715f7 100644 --- a/rmac.c +++ b/rmac.c @@ -1,7 +1,7 @@ // // RMAC - Renamed Macro Assembler for all Atari computers // RMAC.C - Main Application Code -// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2022 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // @@ -30,7 +30,8 @@ int list_pag = 1; // Enable listing pagination by default int verb_flag; // Be verbose about what's going on int m6502; // 1, assembling 6502 code int glob_flag; // Assume undefined symbols are global -int lsym_flag; // Include local symbols in object file +int lsym_flag; // Include local symbols in object file (ALWAYS true) +int dsym_flag; // Gen debug syms (Requires obj_format = BSD) int optim_warn_flag; // Warn about possible short branches int prg_flag; // !=0, produce .PRG executable (2=symbols) int prg_extend; // !=0, output extended .PRG symbols @@ -43,9 +44,12 @@ int rgpu, rdsp; // Assembling Jaguar GPU or DSP code int robjproc; // Assembling Jaguar Object Processor code int dsp56001; // Assembling DSP 56001 code int list_fd; // File to write listing to -int regbank; // RISC register bank int segpadsize; // Segment padding size int endian; // Host processor endianess (0 = LE, 1 = BE) +int *regbase; // Points to current DFA register table (base) +int *regtab; // Points to current DFA register table (tab) +int *regcheck; // Points to current DFA register table (check) +int *regaccept; // Points to current DFA register table (accept) char * objfname; // Object filename pointer char * firstfname; // First source filename char * cmdlnexec; // Executable name, pointer to ARGV[0] @@ -57,6 +61,8 @@ 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) uint32_t org68k_address; // .org for 68k +int correctMathRules; // 1, use C operator precedence in expressions +uint32_t used_architectures; // Bitmask that records exactly which architectures were used during assembly // // Convert a string to uppercase @@ -158,11 +164,13 @@ void DisplayHelp(void) " -f[format] Output object file format\n" " a: ALCYON\n" " b: BSD (use this for Jaguar)\n" + " c: PRG (C64)\n" " e: ELF\n" " p: P56 (use this for DSP56001 only)\n" " l: LOD (use this for DSP56001 only)\n" " x: com/exe/xex (Atari 800)\n" " r: absolute address\n" + " -g Output source level debug information (BSD object only)\n" " -i[path] Directory to search for include files\n" " -l[filename] Create an output listing file\n" " -l*[filename] Create an output listing file without pagination\n" @@ -203,6 +211,7 @@ void DisplayHelp(void) " -v Set verbose mode\n" " -x Turn on debugging mode\n" " -y[pagelen] Set page line length (default: 61)\n" + " -4 Use C style operator precedence\n" "\n", cmdlnexec); } @@ -218,7 +227,7 @@ void DisplayVersion(void) "| | | | | | | | (_| | (__ \n" "|_| |_| |_| |_|\\__,_|\\___|\n" "\nRenamed Macro Assembler\n" - "Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends\n" + "Copyright (C) 199x Landon Dyer, 2011-2022 Reboot and Friends\n" "V%01i.%01i.%01i %s (%s)\n\n", MAJOR, MINOR, PATCH, __DATE__, PLATFORM); } @@ -285,6 +294,47 @@ int ParseOptimization(char * optstring) return OK; } +static void ProcessFile(int fd, char *fname) +{ + char *dbgname = fname; + + if (NULL == fname) + { + fname = defname; // Kludge first filename + dbgname = "(stdin)"; + } + + // First file operations: + if (firstfname == NULL) + { + // Record first filename. + firstfname = fname; + + // Validate option compatibility + if (dsym_flag) + { + if (obj_format != BSD) + { + printf("-g: debug information only supported with BSD object file format\n"); + dsym_flag = 0; + errcnt++; + } + else + { + GenMainFileSym(dbgname); + } + } + } + + include(fd, dbgname); + Assemble(); +} + +extern int reg68base[53]; +extern int reg68tab[222]; +extern int reg68check[222]; +extern int reg68accept[222]; + // // Process command line arguments and do an assembly // @@ -316,14 +366,19 @@ int Process(int argc, char ** argv) rdsp = 0; // Initialize DSP assembly flag robjproc = 0; // Initialize OP assembly flag lsym_flag = 1; // Include local symbols in object file - regbank = BANK_N; // No RISC register bank specified + dsym_flag = 0; // No debug sym generation by default orgactive = 0; // Not in RISC org section orgwarning = 0; // No ORG warning issued segpadsize = 2; // Initialize segment padding size dsp_orgmap[0].start = 0; // Initialize 56001 org initial address dsp_orgmap[0].memtype = ORG_P; // Initialize 56001 org start segment m6502 = 0; // 6502 mode off by default - + regbase = reg68base; // Initialise DFA register tables + regtab = reg68tab; // Idem + regcheck = reg68check; // Idem + regaccept = reg68accept; // Idem + correctMathRules = 0; // respect operator precedence + used_architectures = 0; // Initialise used architectures bitfield // Initialize modules InitSymbolTable(); // Symbol table InitTokenizer(); // Tokenizer @@ -342,6 +397,9 @@ int Process(int argc, char ** argv) { switch (argv[argno][1]) { + case '4': + correctMathRules = 1; + break; case 'd': // Define symbol case 'D': for(s=argv[argno]+2; *s!=EOS;) @@ -388,6 +446,10 @@ int Process(int argc, char ** argv) case 'B': obj_format = BSD; break; + case 'c': + case 'C': + obj_format = C64PRG; + break; case 'e': // -fe = ELF case 'E': obj_format = ELF; @@ -416,7 +478,7 @@ int Process(int argc, char ** argv) break; case 'g': // Debugging flag case 'G': - printf("Debugging flag (-g) not yet implemented\n"); + dsym_flag = 1; break; case 'i': // Set directory search path case 'I': @@ -591,11 +653,7 @@ int Process(int argc, char ** argv) break; case EOS: // Input is stdin - if (firstfname == NULL) // Kludge first filename - firstfname = defname; - - include(0, "(stdin)"); - Assemble(); + ProcessFile(0, NULL); break; case 'h': // Display command line usage case 'H': @@ -630,10 +688,6 @@ int Process(int argc, char ** argv) } else { - // Record first filename. - if (firstfname == NULL) - firstfname = argv[argno]; - strcpy(fnbuf, argv[argno]); fext(fnbuf, ".s", 0); fd = open(fnbuf, 0); @@ -645,8 +699,7 @@ int Process(int argc, char ** argv) continue; } - include(fd, fnbuf); - Assemble(); + ProcessFile(fd, fnbuf); } } @@ -705,7 +758,9 @@ int Process(int argc, char ** argv) if (firstfname == NULL) firstfname = defname; - strcpy(fnbuf, firstfname); + // It's the size of fnbuf minus 5 because of the possible 4 char suffix + // + trailing null (added by fext()). + strncpy(fnbuf, firstfname, sizeof(fnbuf) - 5); fext(fnbuf, (prg_flag ? ".prg" : ".o"), 1); objfname = fnbuf; } @@ -776,6 +831,7 @@ int main(int argc, char ** argv) { perm_verb_flag = 0; // Clobber "permanent" verbose flag legacy_flag = 1; // Default is legacy mode on (:-P) + optim_flags[OPT_56K_SHORT] = 1; // This ensures compatibilty with Motorola's 56k assembler cmdlnexec = argv[0]; // Obtain executable name endian = GetEndianess(); // Get processor endianess