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