]> Shamusworld >> Repos - rmac/blob - rmac.c
Version bump for last commit; now at v2.0.14.
[rmac] / rmac.c
1 //
2 // RMAC - Reboot's Macro Assembler for all Atari computers
3 // RMAC.C - Main Application Code
4 // Copyright (C) 199x Landon Dyer, 2011-2020 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source utilised with the kind permission of Landon Dyer
7 //
8
9 #include "rmac.h"
10 #include "6502.h"
11 #include "debug.h"
12 #include "direct.h"
13 #include "dsp56k.h"
14 #include "error.h"
15 #include "expr.h"
16 #include "listing.h"
17 #include "mark.h"
18 #include "macro.h"
19 #include "object.h"
20 #include "procln.h"
21 #include "riscasm.h"
22 #include "sect.h"
23 #include "symbol.h"
24 #include "token.h"
25 #include "version.h"
26
27 int perm_verb_flag;                             // Permanently verbose, interactive mode
28 int list_flag;                                  // "-l" listing flag on command line
29 int list_pag = 1;                               // Enable listing pagination by default
30 int verb_flag;                                  // Be verbose about what's going on
31 int m6502;                                              // 1, assembling 6502 code
32 int as68_flag;                                  // as68 kludge mode
33 int glob_flag;                                  // Assume undefined symbols are global
34 int lsym_flag;                                  // Include local symbols in object file
35 int sbra_flag;                                  // Warn about possible short branches
36 int prg_flag;                                   // !=0, produce .PRG executable (2=symbols)
37 int prg_extend;                                 // !=0, output extended .PRG symbols
38 int legacy_flag;                                // Do stuff like insert code in RISC assembler
39 int obj_format;                                 // Object format flag
40 int debug;                                              // [1..9] Enable debugging levels
41 int err_flag;                                   // '-e' specified
42 int err_fd;                                             // File to write error messages to
43 int rgpu, rdsp;                                 // Assembling Jaguar GPU or DSP code
44 int robjproc;                                   // Assembling Jaguar Object Processor code
45 int dsp56001;                                   // Assembling DSP 56001 code
46 int list_fd;                                    // File to write listing to
47 int regbank;                                    // RISC register bank
48 int segpadsize;                                 // Segment padding size
49 int endian;                                             // Host processor endianess (0 = LE, 1 = BE)
50 char * objfname;                                // Object filename pointer
51 char * firstfname;                              // First source filename
52 char * cmdlnexec;                               // Executable name, pointer to ARGV[0]
53 char * searchpath = NULL;               // Search path for include files
54 char defname[] = "noname.o";    // Default output filename
55 int optim_flags[OPT_COUNT];             // Specific optimisations on/off matrix
56 int optim_pc = 0;                               // Enforce PC relative
57 int activecpu = CPU_68000;              // Active 68k CPU (68000 by default)
58 int activefpu = FPU_NONE;               // Active FPU (none by default)
59 int org68k_active = 0;                  // .org switch for 68k (only with RAW output format)
60 uint32_t org68k_address;                // .org for 68k
61
62 //
63 // Convert a string to uppercase
64 //
65 void strtoupper(char * s)
66 {
67         while (*s)
68                 *s++ &= 0xDF;
69 }
70
71
72 //
73 // Manipulate file extension.
74 //
75 // 'name' must be large enough to hold any possible filename. If 'stripp' is
76 // nonzero, any old extension is removed. If the file does not already have an
77 // extension, 'extension' is appended to the filename.
78 //
79 char * fext(char * name, char * extension, int stripp)
80 {
81         char * s;
82
83         // Find beginning of "real" name (strip off path)
84         char * beg = strrchr(name, SLASHCHAR);
85
86         if (beg == NULL)
87                 beg = name;
88
89         // Clobber any old extension, if requested
90         if (stripp)
91         {
92                 for(s=beg; *s && *s!='.'; ++s)
93                         ;
94
95                 *s = '\0';
96         }
97
98         if (strrchr(beg, '.') == NULL)
99                 strcat(beg, extension);
100
101         return name;
102 }
103
104
105 //
106 // Return 'item'nth element of semicolon-seperated pathnames specified in the
107 // enviroment string 's'. Copy the pathname to 'buf'.  Return 0 if the 'item'
108 // nth path doesn't exist.
109 //
110 // ['item' ranges from 0 to N-1, where N = #elements in search path]
111 //
112 int nthpath(char * env_var, int itemno, char * buf)
113 {
114         char * s = searchpath;
115
116         if (s == NULL)
117                 s = getenv(env_var);
118
119         if (s == NULL)
120                 return 0;
121
122         while (itemno--)
123                 while (*s != EOS && *s++ != ';')
124                         ;
125
126         if (*s == EOS)
127                 return 0;
128
129         while (*s != EOS && *s != ';')
130                 *buf++ = *s++;
131
132         *buf++ = EOS;
133
134         return 1;
135 }
136
137
138 //
139 // Display command line help
140 //
141 void DisplayHelp(void)
142 {
143         printf("Usage:\n"
144                 "    %s [options] srcfile\n"
145                 "\n"
146                 "Options:\n"
147                 "  -? or -h          Display usage information\n"
148                 "  -dsymbol[=value]  Define symbol (with optional value, default=0)\n"
149                 "  -e[errorfile]     Send error messages to file, not stdout\n"
150                 "  -f[format]        Output object file format\n"
151                 "                    a: ALCYON\n"
152                 "                    b: BSD (use this for Jaguar)\n"
153                 "                    e: ELF\n"
154                 "                    p: P56 (use this for DSP56001 only)\n"
155                 "                    l: LOD (use this for DSP56001 only)\n"
156                 "                    x: com/exe/xex (Atari 800)\n"
157                 "                    r: absolute address\n"
158                 "  -i[path]          Directory to search for include files\n"
159                 "  -l[filename]      Create an output listing file\n"
160                 "  -l*[filename]     Create an output listing file without pagination\n"
161                 "  -m[cpu]           Select default CPU. Available options:\n"
162                 "                    68000, 68020, 68030, 68040, 68060, 6502, tom, jerry, 56001\n"
163                 "  -n                Don't do things behind your back in RISC assembler\n"
164                 "  -o file           Output file name\n"
165                 "  +o[value]         Turn a specific optimisation on\n"
166                 "                    Available optimisation values and default settings:\n"
167                 "                    o0: Absolute long adddresses to word        (on)\n"
168                 "                    o1: move.l #x,dn/an to moveq                (on)\n"
169                 "                    o2: Word branches to short                  (on)\n"
170                 "                    o3: Outer displacement 0(an) to (an)        (off)\n"
171                 "                    o4: lea size(An),An to addq #size,An        (off)\n"
172                 "                    o5: Absolute long base displacement to word (off)\n"
173                 "                    o6: Null branches to NOP                    (off)\n"
174                 "                    o7: clr.l Dx to moveq #0,Dx                 (off)\n"
175                 "                    o8: adda.w/l #x,Dy to addq.w/l #x,Dy        (off)\n"
176                 "                    o9: adda.w/l #x,Dy to lea x(Dy),Dy          (off)\n"
177                 "                    op: Enforce PC relative                     (off)\n"
178                 "  ~o[value]         Turn a specific optimisation off\n"
179                 "  +oall             Turn all optimisations on\n"
180                 "  ~oall             Turn all optimisations off\n"
181                 "  -p                Create an ST .prg (without symbols). Forces -fa\n"
182                 "  -ps               Create an ST .prg (with symbols). Forces -fa\n"
183                 "  -px               Create an ST .prg (with exsymbols). Forces -fa\n"
184                 "  -r[size]          Pad segments to boundary size specified\n"
185                 "                    w: word (2 bytes, default alignment)\n"
186                 "                    l: long (4 bytes)\n"
187                 "                    p: phrase (8 bytes)\n"
188                 "                    d: double phrase (16 bytes)\n"
189                 "                    q: quad phrase (32 bytes)\n"
190                 "  -s                Warn about possible short branches\n"
191                 "                    and applied optimisations\n"
192                 "  -u                Force referenced and undefined symbols global\n"
193                 "  -v                Set verbose mode\n"
194                 "  -x                Turn on debugging mode\n"
195                 "  -y[pagelen]       Set page line length (default: 61)\n"
196                 "\n", cmdlnexec);
197 }
198
199
200 //
201 // Display version information
202 //
203 void DisplayVersion(void)
204 {
205         printf("\n"
206                 " _ __ _ __ ___   __ _  ___ \n"
207                 "| '__| '_ ` _ \\ / _` |/ __|\n"
208                 "| |  | | | | | | (_| | (__ \n"
209                 "|_|  |_| |_| |_|\\__,_|\\___|\n"
210                 "\nReboot's Macro Assembler\n"
211                 "Copyright (C) 199x Landon Dyer, 2011-2020 Reboot\n"
212                 "V%01i.%01i.%01i %s (%s)\n\n", MAJOR, MINOR, PATCH, __DATE__, PLATFORM);
213 }
214
215
216 //
217 // Parse optimisation options
218 //
219 int ParseOptimization(char * optstring)
220 {
221         int onoff = 0;
222
223         if (*optstring == '+')
224                 onoff = 1;
225         else if (*optstring != '~')
226                 return ERROR;
227
228         if ((optstring[2] == 'a' || optstring[2] == 'A')
229                 && (optstring[3] == 'l' || optstring[3] == 'L')
230                 && (optstring[4] == 'l' || optstring[4] == 'L'))
231         {
232                 memset(optim_flags, onoff, OPT_COUNT * sizeof(int));
233                 return OK;
234         }
235         else if (optstring[1] == 'o' || optstring[1] == 'O') // Turn on specific optimisation
236         {
237                 if (optstring[2] == 'p' || optstring[2] == 'P')
238                 {
239                         optim_pc = 1;
240                         return OK;
241                 }
242
243                 int opt_no = atoi(&optstring[2]);
244
245                 if ((opt_no >= 0) && (opt_no < OPT_COUNT))
246                 {
247                         optim_flags[opt_no] = onoff;
248                         return OK;
249                 }
250                 else
251                         return ERROR;
252         }
253         else
254         {
255                 return ERROR;
256         }
257 }
258
259
260 //
261 // Process command line arguments and do an assembly
262 //
263 int Process(int argc, char ** argv)
264 {
265         int argno;                                              // Argument number
266         SYM * sy;                                               // Pointer to a symbol record
267         char * s;                                               // String pointer
268         int fd;                                                 // File descriptor
269         char fnbuf[FNSIZ];                              // Filename buffer
270         int i;                                                  // Iterator
271
272         errcnt = 0;                                             // Initialize error count
273         listing = 0;                                    // Initialize listing level
274         list_flag = 0;                                  // Initialize listing flag
275         verb_flag = perm_verb_flag;             // Initialize verbose flag
276         as68_flag = 0;                                  // Initialize as68 kludge mode
277         glob_flag = 0;                                  // Initialize .globl flag
278         sbra_flag = 0;                                  // Initialize short branch flag
279         debug = 0;                                              // Initialize debug flag
280         searchpath = NULL;                              // Initialize search path
281         objfname = NULL;                                // Initialize object filename
282         list_fname = NULL;                              // Initialize listing filename
283         err_fname = NULL;                               // Initialize error filename
284         obj_format = BSD;                               // Initialize object format
285         firstfname = NULL;                              // Initialize first filename
286         err_fd = ERROUT;                                // Initialize error file descriptor
287         err_flag = 0;                                   // Initialize error flag
288         rgpu = 0;                                               // Initialize GPU assembly flag
289         rdsp = 0;                                               // Initialize DSP assembly flag
290         robjproc = 0;                                   // Initialize OP assembly flag
291         lsym_flag = 1;                                  // Include local symbols in object file
292         regbank = BANK_N;                               // No RISC register bank specified
293         orgactive = 0;                                  // Not in RISC org section
294         orgwarning = 0;                                 // No ORG warning issued
295         segpadsize = 2;                                 // Initialize segment padding size
296     dsp_orgmap[0].start = 0;            // Initialize 56001 org initial address
297     dsp_orgmap[0].memtype = ORG_P;      // Initialize 56001 org start segment
298         m6502 = 0;                                              // 6502 mode off by default
299
300         // Initialize modules
301         InitSymbolTable();                              // Symbol table
302         InitTokenizer();                                // Tokenizer
303         InitLineProcessor();                    // Line processor
304         InitExpression();                               // Expression analyzer
305         InitSection();                                  // Section manager / code generator
306         InitMark();                                             // Mark tape-recorder
307         InitMacro();                                    // Macro processor
308         InitListing();                                  // Listing generator
309         Init6502();                                             // 6502 assembler
310
311         // Process command line arguments and assemble source files
312         for(argno=0; argno<argc; argno++)
313         {
314                 if (*argv[argno] == '-')
315                 {
316                         switch (argv[argno][1])
317                         {
318                         case 'd':                               // Define symbol
319                         case 'D':
320                                 for(s=argv[argno]+2; *s!=EOS;)
321                                 {
322                                         if (*s++ == '=')
323                                         {
324                                                 s[-1] = EOS;
325                                                 break;
326                                         }
327                                 }
328
329                                 if (argv[argno][2] == EOS)
330                                 {
331                                         printf("-d: empty symbol\n");
332                                         errcnt++;
333                                         return errcnt;
334                                 }
335
336                                 sy = lookup(argv[argno] + 2, 0, 0);
337
338                                 if (sy == NULL)
339                                 {
340                                         sy = NewSymbol(argv[argno] + 2, LABEL, 0);
341                                         sy->svalue = 0;
342                                 }
343
344                                 sy->sattr = DEFINED | EQUATED | ABS;
345                                 sy->svalue = (*s ? (uint64_t)atoi(s) : 0);
346                                 break;
347                         case 'e':                               // Redirect error message output
348                         case 'E':
349                                 err_fname = argv[argno] + 2;
350                                 break;
351                         case 'f':                               // -f<format>
352                         case 'F':
353                                 switch (argv[argno][2])
354                                 {
355                                 case EOS:
356                                 case 'a':                       // -fa = Alcyon [the default]
357                                 case 'A':
358                                         obj_format = ALCYON;
359                                         break;
360                                 case 'b':                       // -fb = BSD (Jaguar Recommended: 3 out 4 jaguars recommend it!)
361                                 case 'B':
362                                         obj_format = BSD;
363                                         break;
364                                 case 'e':                       // -fe = ELF
365                                 case 'E':
366                                         obj_format = ELF;
367                                         break;
368                 case 'l':           // -fl = LOD
369                 case 'L':
370                     obj_format = LOD;
371                     break;
372                 case 'p':           // -fp = P56
373                 case 'P':
374                     obj_format = P56;
375                                         break;
376                                 case 'x':                       // -fx = COM/EXE/XEX
377                                 case 'X':
378                                         obj_format = XEX;
379                                         break;
380                 case 'r':           // -fr = Absolute address
381                 case 'R':
382                     obj_format = RAW;
383                     break;
384                                 default:
385                                         printf("-f: unknown object format specified\n");
386                                         errcnt++;
387                                         return errcnt;
388                                 }
389                                 break;
390                         case 'g':                               // Debugging flag
391                         case 'G':
392                                 printf("Debugging flag (-g) not yet implemented\n");
393                                 break;
394                         case 'i':                               // Set directory search path
395                         case 'I':
396                         {
397                                 searchpath = argv[argno] + 2;
398
399                                 // Check to see if include paths actually exist
400                                 if (strlen(searchpath) > 0)
401                                 {
402                                         DIR * test = opendir(searchpath);
403
404                                         if (test == NULL)
405                                         {
406                                                 printf("Invalid include path: %s\n", searchpath);
407                                                 errcnt++;
408                                                 return errcnt;
409                                         }
410
411                                         closedir(test);
412                                 }
413
414                                 break;
415                         }
416                         case 'l':                               // Produce listing file
417                         case 'L':
418                                 if (*(argv[argno] + 2) == '*')
419                                 {
420                                         list_fname = argv[argno] + 3;
421                                         list_pag = 0;    // Special case - turn off pagination
422                                 }
423                                 else
424                                 {
425                                         list_fname = argv[argno] + 2;
426                                 }
427
428                                 listing = 1;
429                                 list_flag = 1;
430                                 lnsave++;
431                                 break;
432                         case 'm':
433                         case 'M':
434                                 if (strcmp(argv[argno] + 2, "68000") == 0)
435                                         d_68000();
436                                 else if (strcmp(argv[argno] + 2, "68020") == 0)
437                                         d_68020();
438                                 else if (strcmp(argv[argno] + 2, "68030") == 0)
439                                         d_68030();
440                                 else if (strcmp(argv[argno] + 2, "68040") == 0)
441                                         d_68040();
442                                 else if (strcmp(argv[argno] + 2, "68060") == 0)
443                                         d_68060();
444                                 else if (strcmp(argv[argno] + 2, "68881") == 0)
445                                         d_68881();
446                                 else if (strcmp(argv[argno] + 2, "68882") == 0)
447                                         d_68882();
448                                 else if (strcmp(argv[argno] + 2, "56001") == 0)
449                                         d_56001();
450                                 else if (strcmp(argv[argno] + 2, "6502") == 0)
451                                         d_6502();
452                                 else if (strcmp(argv[argno] + 2, "tom") == 0)
453                                         d_gpu();
454                                 else if (strcmp(argv[argno] + 2, "jerry") == 0)
455                                         d_dsp();
456                                 else
457                                 {
458                                         printf("Unrecognized CPU '%s'\n", argv[argno] + 2);
459                                         errcnt++;
460                                         return errcnt;
461                                 }
462                                 break;
463                         case 'o':                               // Direct object file output
464                         case 'O':
465                                 if (argv[argno][2] != EOS)
466                                         objfname = argv[argno] + 2;
467                                 else
468                                 {
469                                         if (++argno >= argc)
470                                         {
471                                                 printf("Missing argument to -o");
472                                                 errcnt++;
473                                                 return errcnt;
474                                         }
475
476                                         objfname = argv[argno];
477                                 }
478
479                                 break;
480                         case 'p':               /* -p: generate ".PRG" executable output */
481                         case 'P':
482                                 /*
483                                  * -p           .PRG generation w/o symbols
484                                  * -ps          .PRG generation with symbols
485                                  * -px          .PRG generation with extended symbols
486                                  */
487                                 switch (argv[argno][2])
488                                 {
489                                         case EOS:
490                                                 prg_flag = 1;
491                                                 break;
492
493                                         case 's':
494                                         case 'S':
495                                                 prg_flag = 2;
496                                                 break;
497
498                                         case 'x':
499                                         case 'X':
500                                                 prg_flag = 3;
501                                                 break;
502
503                                         default:
504                                                 printf("-p: syntax error\n");
505                                                 errcnt++;
506                                                 return errcnt;
507                                 }
508
509                                 // Enforce Alcyon object format - kind of silly
510                                 // to ask for .prg output without it!
511                                 obj_format = ALCYON;
512                                 break;
513                         case 'r':                               // Pad seg to requested boundary size
514                         case 'R':
515                                 switch(argv[argno][2])
516                                 {
517                                 case 'w': case 'W': segpadsize = 2;  break;
518                                 case 'l': case 'L': segpadsize = 4;  break;
519                                 case 'p': case 'P': segpadsize = 8;  break;
520                                 case 'd': case 'D': segpadsize = 16; break;
521                                 case 'q': case 'Q': segpadsize = 32; break;
522                                 default: segpadsize = 2; break; // Effective autoeven();
523                                 }
524                                 break;
525                         case 's':                               // Warn about possible short branches
526                         case 'S':
527                                 sbra_flag = 1;
528                                 break;
529                         case 'u':                               // Make undefined symbols .globl
530                         case 'U':
531                                 glob_flag = 1;
532                                 break;
533                         case 'v':                               // Verbose flag
534                         case 'V':
535                                 verb_flag++;
536
537                                 if (verb_flag > 1)
538                                         DisplayVersion();
539
540                                 break;
541                         case 'x':                               // Turn on debugging
542                         case 'X':
543                                 debug = 1;
544                                 printf("~ Debugging ON\n");
545                                 break;
546                         case 'y':                               // -y<pagelen>
547                         case 'Y':
548                                 pagelen = atoi(argv[argno] + 2);
549
550                                 if (pagelen < 10)
551                                 {
552                                         printf("-y: bad page length\n");
553                                         errcnt++;
554                                         return errcnt;
555                                 }
556
557                                 break;
558                         case EOS:                               // Input is stdin
559                                 if (firstfname == NULL) // Kludge first filename
560                                         firstfname = defname;
561
562                                 include(0, "(stdin)");
563                                 Assemble();
564                                 break;
565                         case 'h':                               // Display command line usage
566                         case 'H':
567                         case '?':
568                                 DisplayVersion();
569                                 DisplayHelp();
570                                 errcnt++;
571                                 break;
572                         case 'n':                               // Turn off legacy mode
573                         case 'N':
574                                 legacy_flag = 0;
575                                 printf("Legacy mode OFF\n");
576                                 break;
577                         default:
578                                 DisplayVersion();
579                                 printf("Unknown switch: %s\n\n", argv[argno]);
580                                 DisplayHelp();
581                                 errcnt++;
582                                 break;
583                         }
584                 }
585                 else if (*argv[argno] == '+' || *argv[argno] == '~')
586                 {
587                         if (ParseOptimization(argv[argno]) != OK)
588                         {
589                                 DisplayVersion();
590                                 printf("Unknown switch: %s\n\n", argv[argno]);
591                                 DisplayHelp();
592                                 errcnt++;
593                                 break;
594                         }
595                 }
596                 else
597                 {
598                         // Record first filename.
599                         if (firstfname == NULL)
600                                 firstfname = argv[argno];
601
602                         strcpy(fnbuf, argv[argno]);
603                         fext(fnbuf, ".s", 0);
604                         fd = open(fnbuf, 0);
605
606                         if (fd < 0)
607                         {
608                                 printf("Cannot open: %s\n", fnbuf);
609                                 errcnt++;
610                                 continue;
611                         }
612
613                         include(fd, fnbuf);
614                         Assemble();
615                 }
616         }
617
618         // Wind-up processing;
619         // o  save current section (no more code generation)
620         // o  do auto-even of all sections (or boundary alignment as requested
621         //    through '-r')
622     // o  save the last pc value for 6502 (if we used 6502 at all) and
623     //    detemine if the last section contains anything
624         // o  determine name of object file:
625         //    -  "foo.o" for linkable output;
626         //    -  "foo.prg" for GEMDOS executable (-p flag).
627         SaveSection();
628         int temp_section = cursect;
629
630         for(i=TEXT; i<=BSS; i<<=1)
631         {
632                 SwitchSection(i);
633
634                 switch(segpadsize)
635                 {
636                 case 2:  d_even();    break;
637                 case 4:  d_long();    break;
638                 case 8:  d_phrase();  break;
639                 case 16: d_dphrase(); break;
640                 case 32: d_qphrase(); break;
641                 }
642
643                 SaveSection();
644         }
645
646         SwitchSection(M6502);
647
648         if (sloc != currentorg[0])
649         {
650                 currentorg[1] = sloc;
651                 currentorg += 2;
652         }
653
654         // This looks like an awful kludge...  !!! FIX !!!
655         if (temp_section & (M56001P | M56001X | M56001Y))
656         {
657                 SwitchSection(temp_section);
658
659                 if (chptr != dsp_currentorg->start)
660                 {
661                         dsp_currentorg->end = chptr;
662                         dsp_currentorg++;
663                 }
664         }
665
666         SwitchSection(TEXT);
667
668         if (objfname == NULL)
669         {
670                 if (firstfname == NULL)
671                         firstfname = defname;
672
673                 strcpy(fnbuf, firstfname);
674                 fext(fnbuf, (prg_flag ? ".prg" : ".o"), 1);
675                 objfname = fnbuf;
676         }
677
678         // With one pass finished, go back and:
679         // (1)   run through all the fixups and resolve forward references;
680         // (1.5) ensure that remaining fixups can be handled by the linker
681         //       (`lo68' format, extended (postfix) format....)
682         // (2)   generate the output file image and symbol table;
683         // (3)   generate relocation information from left-over fixups.
684         ResolveAllFixups();                                             // Do all fixups
685         StopMark();                                                             // Stop mark tape-recorder
686
687         if (errcnt == 0)
688         {
689                 if ((fd = open(objfname, _OPEN_FLAGS, _PERM_MODE)) < 0)
690                         CantCreateFile(objfname);
691
692                 if (verb_flag)
693                 {
694                         s = (prg_flag ? "executable" : "object");
695                         printf("[Writing %s file: %s]\n", s, objfname);
696                 }
697
698                 WriteObject(fd);
699                 close(fd);
700
701                 if (errcnt != 0)
702                         unlink(objfname);
703         }
704
705         if (list_flag)
706         {
707                 if (verb_flag)
708                         printf("[Wrapping-up listing file]\n");
709
710                 listing = 1;
711                 symtable();
712                 close(list_fd);
713         }
714
715         if (err_flag)
716                 close(err_fd);
717
718         DEBUG dump_everything();
719
720         return errcnt;
721 }
722
723
724 //
725 // Determine processor endianess
726 //
727 int GetEndianess(void)
728 {
729         int i = 1;
730         char * p = (char *)&i;
731
732         if (p[0] == 1)
733                 return 0;
734
735         return 1;
736 }
737
738
739 //
740 // Application entry point
741 //
742 int main(int argc, char ** argv)
743 {
744         perm_verb_flag = 0;                             // Clobber "permanent" verbose flag
745         legacy_flag = 1;                                // Default is legacy mode on (:-P)
746
747         // Set legacy optimisation flags to on and everything else to off
748         memset(optim_flags, 0, OPT_COUNT * sizeof(int));
749         optim_flags[OPT_ABS_SHORT] =
750                 optim_flags[OPT_MOVEL_MOVEQ] =
751                 optim_flags[OPT_BSR_BCC_S] = 1;
752
753         cmdlnexec = argv[0];                    // Obtain executable name
754         endian = GetEndianess();                // Get processor endianess
755
756         // If commands were passed in, process them
757         if (argc > 1)
758                 return Process(argc - 1, argv + 1);
759
760         DisplayVersion();
761         DisplayHelp();
762
763         return 0;
764 }
765