Added new optimisation option "+op" which enforces PC relative mode (#123)
[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;                              // 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"
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                                 searchpath = argv[argno] + 2;
397                                 break;
398                         case 'l':                               // Produce listing file
399                         case 'L':
400                                 if (*(argv[argno] + 2) == '*')
401                                 {
402                                         list_fname = argv[argno] + 3;
403                                         list_pag = 0;    // Special case - turn off pagination
404                                 }
405                                 else
406                                 {
407                                         list_fname = argv[argno] + 2;
408                                 }
409
410                                 listing = 1;
411                                 list_flag = 1;
412                                 lnsave++;
413                                 break;
414                         case 'm':
415                         case 'M':
416                                 if (strcmp(argv[argno] + 2, "68000") == 0)
417                                         d_68000();
418                                 else if (strcmp(argv[argno] + 2, "68020") == 0)
419                                         d_68020();
420                                 else if (strcmp(argv[argno] + 2, "68030") == 0)
421                                         d_68030();
422                                 else if (strcmp(argv[argno] + 2, "68040") == 0)
423                                         d_68040();
424                                 else if (strcmp(argv[argno] + 2, "68060") == 0)
425                                         d_68060();
426                                 else if (strcmp(argv[argno] + 2, "68881") == 0)
427                                         d_68881();
428                                 else if (strcmp(argv[argno] + 2, "68882") == 0)
429                                         d_68882();
430                                 else if (strcmp(argv[argno] + 2, "56001") == 0)
431                                         d_56001();
432                                 else if (strcmp(argv[argno] + 2, "6502") == 0)
433                                         d_6502();
434                                 else if (strcmp(argv[argno] + 2, "tom") == 0)
435                                         d_gpu();
436                                 else if (strcmp(argv[argno] + 2, "jerry") == 0)
437                                         d_dsp();
438                                 else
439                                 {
440                                         printf("Unrecognized CPU '%s'\n", argv[argno] + 2);
441                                         errcnt++;
442                                         return errcnt;
443                                 }
444                                 break;
445                         case 'o':                               // Direct object file output
446                         case 'O':
447                                 if (argv[argno][2] != EOS)
448                                         objfname = argv[argno] + 2;
449                                 else
450                                 {
451                                         if (++argno >= argc)
452                                         {
453                                                 printf("Missing argument to -o");
454                                                 errcnt++;
455                                                 return errcnt;
456                                         }
457
458                                         objfname = argv[argno];
459                                 }
460
461                                 break;
462                         case 'p':               /* -p: generate ".PRG" executable output */
463                         case 'P':
464                                 /*
465                                  * -p           .PRG generation w/o symbols
466                                  * -ps          .PRG generation with symbols
467                                  * -px          .PRG generation with extended symbols
468                                  */
469                                 switch (argv[argno][2])
470                                 {
471                                         case EOS:
472                                                 prg_flag = 1;
473                                                 break;
474
475                                         case 's':
476                                         case 'S':
477                                                 prg_flag = 2;
478                                                 break;
479
480                                         case 'x':
481                                         case 'X':
482                                                 prg_flag = 3;
483                                                 break;
484
485                                         default:
486                                                 printf("-p: syntax error\n");
487                                                 errcnt++;
488                                                 return errcnt;
489                                 }
490
491                                 // Enforce Alcyon object format - kind of silly
492                                 // to ask for .prg output without it!
493                                 obj_format = ALCYON;
494                                 break;
495                         case 'r':                               // Pad seg to requested boundary size
496                         case 'R':
497                                 switch(argv[argno][2])
498                                 {
499                                 case 'w': case 'W': segpadsize = 2;  break;
500                                 case 'l': case 'L': segpadsize = 4;  break;
501                                 case 'p': case 'P': segpadsize = 8;  break;
502                                 case 'd': case 'D': segpadsize = 16; break;
503                                 case 'q': case 'Q': segpadsize = 32; break;
504                                 default: segpadsize = 2; break; // Effective autoeven();
505                                 }
506                                 break;
507                         case 's':                               // Warn about possible short branches
508                         case 'S':
509                                 sbra_flag = 1;
510                                 break;
511                         case 'u':                               // Make undefined symbols .globl
512                         case 'U':
513                                 glob_flag = 1;
514                                 break;
515                         case 'v':                               // Verbose flag
516                         case 'V':
517                                 verb_flag++;
518
519                                 if (verb_flag > 1)
520                                         DisplayVersion();
521
522                                 break;
523                         case 'x':                               // Turn on debugging
524                         case 'X':
525                                 debug = 1;
526                                 printf("~ Debugging ON\n");
527                                 break;
528                         case 'y':                               // -y<pagelen>
529                         case 'Y':
530                                 pagelen = atoi(argv[argno] + 2);
531
532                                 if (pagelen < 10)
533                                 {
534                                         printf("-y: bad page length\n");
535                                         errcnt++;
536                                         return errcnt;
537                                 }
538
539                                 break;
540                         case EOS:                               // Input is stdin
541                                 if (firstfname == NULL) // Kludge first filename
542                                         firstfname = defname;
543
544                                 include(0, "(stdin)");
545                                 Assemble();
546                                 break;
547                         case 'h':                               // Display command line usage
548                         case 'H':
549                         case '?':
550                                 DisplayVersion();
551                                 DisplayHelp();
552                                 errcnt++;
553                                 break;
554                         case 'n':                               // Turn off legacy mode
555                         case 'N':
556                                 legacy_flag = 0;
557                                 printf("Legacy mode OFF\n");
558                                 break;
559                         default:
560                                 DisplayVersion();
561                                 printf("Unknown switch: %s\n\n", argv[argno]);
562                                 DisplayHelp();
563                                 errcnt++;
564                                 break;
565                         }
566                 }
567                 else if (*argv[argno] == '+' || *argv[argno] == '~')
568                 {
569                         if (ParseOptimization(argv[argno]) != OK)
570                         {
571                                 DisplayVersion();
572                                 printf("Unknown switch: %s\n\n", argv[argno]);
573                                 DisplayHelp();
574                                 errcnt++;
575                                 break;
576                         }
577                 }
578                 else
579                 {
580                         // Record first filename.
581                         if (firstfname == NULL)
582                                 firstfname = argv[argno];
583
584                         strcpy(fnbuf, argv[argno]);
585                         fext(fnbuf, ".s", 0);
586                         fd = open(fnbuf, 0);
587
588                         if (fd < 0)
589                         {
590                                 printf("Cannot open: %s\n", fnbuf);
591                                 errcnt++;
592                                 continue;
593                         }
594
595                         include(fd, fnbuf);
596                         Assemble();
597                 }
598         }
599
600         // Wind-up processing;
601         // o  save current section (no more code generation)
602         // o  do auto-even of all sections (or boundary alignment as requested
603         //    through '-r')
604     // o  save the last pc value for 6502 (if we used 6502 at all) and
605     //    detemine if the last section contains anything
606         // o  determine name of object file:
607         //    -  "foo.o" for linkable output;
608         //    -  "foo.prg" for GEMDOS executable (-p flag).
609         SaveSection();
610         int temp_section = cursect;
611
612         for(i=TEXT; i<=BSS; i<<=1)
613         {
614                 SwitchSection(i);
615
616                 switch(segpadsize)
617                 {
618                 case 2:  d_even();    break;
619                 case 4:  d_long();    break;
620                 case 8:  d_phrase();  break;
621                 case 16: d_dphrase(); break;
622                 case 32: d_qphrase(); break;
623                 }
624
625                 SaveSection();
626         }
627
628         SwitchSection(M6502);
629
630         if (sloc != currentorg[0])
631         {
632                 currentorg[1] = sloc;
633                 currentorg += 2;
634         }
635
636         // This looks like an awful kludge...  !!! FIX !!!
637         if (temp_section & (M56001P | M56001X | M56001Y))
638         {
639                 SwitchSection(temp_section);
640
641                 if (chptr != dsp_currentorg->start)
642                 {
643                         dsp_currentorg->end = chptr;
644                         dsp_currentorg++;
645                 }
646         }
647
648         SwitchSection(TEXT);
649
650         if (objfname == NULL)
651         {
652                 if (firstfname == NULL)
653                         firstfname = defname;
654
655                 strcpy(fnbuf, firstfname);
656                 fext(fnbuf, (prg_flag ? ".prg" : ".o"), 1);
657                 objfname = fnbuf;
658         }
659
660         // With one pass finished, go back and:
661         // (1)   run through all the fixups and resolve forward references;
662         // (1.5) ensure that remaining fixups can be handled by the linker
663         //       (`lo68' format, extended (postfix) format....)
664         // (2)   generate the output file image and symbol table;
665         // (3)   generate relocation information from left-over fixups.
666         ResolveAllFixups();                                             // Do all fixups
667         StopMark();                                                             // Stop mark tape-recorder
668
669         if (errcnt == 0)
670         {
671                 if ((fd = open(objfname, _OPEN_FLAGS, _PERM_MODE)) < 0)
672                         CantCreateFile(objfname);
673
674                 if (verb_flag)
675                 {
676                         s = (prg_flag ? "executable" : "object");
677                         printf("[Writing %s file: %s]\n", s, objfname);
678                 }
679
680                 WriteObject(fd);
681                 close(fd);
682
683                 if (errcnt != 0)
684                         unlink(objfname);
685         }
686
687         if (list_flag)
688         {
689                 if (verb_flag)
690                         printf("[Wrapping-up listing file]\n");
691
692                 listing = 1;
693                 symtable();
694                 close(list_fd);
695         }
696
697         if (err_flag)
698                 close(err_fd);
699
700         DEBUG dump_everything();
701
702         return errcnt;
703 }
704
705
706 //
707 // Determine processor endianess
708 //
709 int GetEndianess(void)
710 {
711         int i = 1;
712         char * p = (char *)&i;
713
714         if (p[0] == 1)
715                 return 0;
716
717         return 1;
718 }
719
720
721 //
722 // Application entry point
723 //
724 int main(int argc, char ** argv)
725 {
726         perm_verb_flag = 0;                             // Clobber "permanent" verbose flag
727         legacy_flag = 1;                                // Default is legacy mode on (:-P)
728
729         // Set legacy optimisation flags to on and everything else to off
730         memset(optim_flags, 0, OPT_COUNT * sizeof(int));
731         optim_flags[OPT_ABS_SHORT] =
732                 optim_flags[OPT_MOVEL_MOVEQ] =
733                 optim_flags[OPT_BSR_BCC_S] = 1;
734
735         cmdlnexec = argv[0];                    // Obtain executable name
736         endian = GetEndianess();                // Get processor endianess
737
738         // If commands were passed in, process them
739         if (argc > 1)
740                 return Process(argc - 1, argv + 1);
741
742         DisplayVersion();
743         DisplayHelp();
744
745         return 0;
746 }
747