-int hflags; // Value of the arg to -h option
-int ttype, dtype, btype; // Type flag: 0, -1, -2, -3, -4
-int tval, dval, bval; // Values of these abs bases
+int hflags; // Value of the arg to -h option
+int ttype, dtype, btype; // Type flag: 0, -1, -2, -3, -4
+int tval, dval, bval; // Values of these abs bases
struct OFILE * plist = NULL; // Object image list pointer
struct OFILE * plast; // Last object image list pointer
struct OFILE * olist = NULL; // Pointer to first object file in list
struct OFILE * olast; // Pointer to last object file in list
char obj_fname[512][FNLEN]; // Object file names
unsigned obj_segsize[512][3]; // Object file seg sizes; TEXT,DATA,BSS
struct OFILE * plist = NULL; // Object image list pointer
struct OFILE * plast; // Last object image list pointer
struct OFILE * olist = NULL; // Pointer to first object file in list
struct OFILE * olast; // Pointer to last object file in list
char obj_fname[512][FNLEN]; // Object file names
unsigned obj_segsize[512][3]; // Object file seg sizes; TEXT,DATA,BSS
- char * symptr; // Symbol pointer
- char * symend; // Symbol end pointer
- int type; // Symbol type
- long value; // Symbol value
- int index; // Symbol index
- int j; // Iterator
- int ssidx; // Segment size table index
- unsigned tsegoffset; // Cumulative TEXT segment offset
- unsigned dsegoffset; // Cumulative DATA segment offset
- unsigned bsegoffset; // Cumulative BSS segment offset
- struct HREC * hptr; // Hash table pointer for globl/extrn
- char sym[SYMLEN]; // String for symbol name/hash search
+ char * symptr; // Symbol pointer
+ char * symend; // Symbol end pointer
+ int type; // Symbol type
+ long value; // Symbol value
+ int index; // Symbol index
+ int j; // Iterator
+ int ssidx; // Segment size table index
+ unsigned tsegoffset; // Cumulative TEXT segment offset
+ unsigned dsegoffset; // Cumulative DATA segment offset
+ unsigned bsegoffset; // Cumulative BSS segment offset
+ struct HREC * hptr; // Hash table pointer for globl/extrn
+ char sym[SYMLEN]; // String for symbol name/hash search
- // Obtain the string table index for the relocation symbol, look for it in the globals
- // hash table to obtain information on that symbol. For the hash calculation to work
- // correctly it must be placed in a 'clean' string before looking it up.
- memset(sym, 0, SYMLEN);
+ // Obtain the string table index for the relocation symbol, look
+ // for it in the globals hash table to obtain information on that
+ // symbol. For the hash calculation to work correctly it must be
+ // placed in a 'clean' string before looking it up.
+ memset(sym, 0, SYMLEN);
- // Search through object segment size table to obtain segment sizes for the object
- // that has the required external/global as a local symbol. As each object is
- // interrogated the segment sizes are accumulated to ensure the correct offsets are
- // used in the resulting COF file. This is effectively 'done again' only as we
+ // Search through object segment size table to obtain segment sizes
+ // for the object that has the required external/global as a local
+ // symbol. As each object is interrogated the segment sizes are
+ // accumulated to ensure the correct offsets are used in the
+ // resulting COF file. This is effectively 'done again' only as we
- // The symbol and string table have been created as part of the dosym() function and the
- // output symbol and string tables are in COF format. For an ABS file we need to process
- // through this to create the 14 character long combined symbol and string table.
- // Format of symbol table in ABS: AAAAAAAATTVVVV, where (A)=STRING, (T)=TYPE & (V)=VALUE
+ // The symbol and string table have been created as part of the
+ // dosym() function and the output symbol and string tables are in
+ // COF format. For an ABS file we need to process through this to
+ // create the 14 character long combined symbol and string table.
+ // Format of symbol table in ABS: AAAAAAAATTVVVV, where (A)=STRING,
+ // (T)=TYPE & (V)=VALUE
- memset(symbol, 0, 14); // Initialise symbol record
- abstype = 0; // Initialise ABS symbol type
- slen = 0; // Initialise symbol string length
- index = getlong(ost + (i * 12)); // Get symbol index
- type = getlong((ost + (i * 12)) + 4); // Get symbol type
+ memset(symbol, 0, 14); // Initialise symbol record
+ abstype = 0; // Initialise ABS symbol type
+ slen = 0; // Initialise symbol string length
+ index = getlong(ost + (i * 12)); // Get symbol index
+ type = getlong((ost + (i * 12)) + 4); // Get symbol type
- unsigned tptr, dptr, bptr; // Bases in runtime model
- int ret = 0; // Return value
- struct OFILE * otemp, * oprev, * ohold; // Object file list pointers
- struct OHEADER * header; // Output header pointer
+ unsigned tptr, dptr, bptr; // Bases in runtime model
+ int ret = 0; // Return value
+ struct OFILE * otemp, * oprev, * ohold; // Object file list pointers
+ struct OHEADER * header; // Output header pointer
- strcpy(plast->o_name, path_tail(fname)); // Store filename, not path
- *plast->o_arname = 0; // No archive name for this file
- plast->o_image = ptr; // Store data pointer
- plast->o_flags = O_USED; // File is used
- plast->o_next = NULL; // Initialise next record pointer
+ strcpy(plast->o_name, path_tail(fname)); // Store filename, not path
+ *plast->o_arname = 0; // No archive name for this file
+ plast->o_image = ptr; // Store data pointer
+ plast->o_flags = O_USED; // File is used
+ plast->o_next = NULL; // Initialise next record pointer
// test = getlong(magic); printf("Magic Number is 0x%08X\n", test);
if (getlong(magic) == 0x00000107)
{ // Look for SMAC/MAC object files
if (doobject(name[i], handle[i], 0L)) // Process input object file
// test = getlong(magic); printf("Magic Number is 0x%08X\n", test);
if (getlong(magic) == 0x00000107)
{ // Look for SMAC/MAC object files
if (doobject(name[i], handle[i], 0L)) // Process input object file
- int i = 1; // Iterator
- int c; // Command line character
- char * ifile, * isym; // File name and symbol name for -i
-
- while (i < argc)
- { // Parse through option switches & files
- if (argv[i][0] == '-')
- { // Process command line switches
- if (!argv[i][1])
- {
- printf("Illegal option argument: %s\n\n", argv[i]);
- display_help();
- return 1;
- }
-
- c = argv[i++][1]; // Get next character in command line
-
- switch (c)
- { // Process command line switch
- case '?': // Display usage information
- case 'h':
+ int i = 1; // Iterator
+ int c; // Command line character
+ char * ifile, * isym; // File name and symbol name for -i
+
+ while (i < argc)
+ { // Parse through option switches & files
+ if (argv[i][0] == '-')
+ { // Process command line switches
+ if (!argv[i][1])
+ {
+ printf("Illegal option argument: %s\n\n", argv[i]);
+ display_help();
+ return 1;
+ }
+
+ c = argv[i++][1]; // Get next character in command line
+
+ switch (c)
+ { // Process command line switch
+ case '?': // Display usage information
+ case 'h':
- display_version();
- display_help();
- return 1;
- case 'a':
- case 'A': // Set absolute linking on
- if (aflag)
- warn('a', 1);
-
- if (i + 2 >= argc)
- {
- printf("Not enough arguments to -a\n");
- return 1;
- }
-
- aflag = 1; // Set abs link flag
- // Segment order is TEXT, DATA, BSS
- // Text segment can be 'r', 'x' or a value
- ttype = 0;
-
- if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
- {
- ttype = -1; // TEXT segment is relocatable
- }
- else if ((*argv[i] == 'x' || *argv[i] == 'X'))
- {
- printf("Error in text-segment address: cannot be contiguous\n");
- return 1;
- }
- else if ((ttype = 0), getval(argv[i], &tval))
- {
- printf("Error in text-segment address: %s is not 'r', 'x' or an address.", argv[i]);
- return 1;
- }
-
- i++;
- // Data segment can be 'r', 'x' or a value
- dtype = 0;
-
- if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
- {
- dtype = -1; // DATA segment is relocatable
- }
- else if ((*argv[i] == 'x' || *argv[i] == 'X'))
- {
- dtype = -2; // DATA follows TEXT
- }
- else if ((dtype = 0), getval(argv[i],&dval))
- {
- printf("Error in data-segment address: %s is not 'r', 'x' or an address.", argv[i]);
- return 1;
- }
-
- i++;
- btype = 0;
-
- // BSS segment can be 'r', 'x' or a value
- if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
- {
- btype = -1; // BSS segment is relocatable
- }
- else if ((*argv[i] == 'x' || *argv[i] == 'X'))
- {
- btype = -3; // BSS follows DATA
- }
- else if ((btype = 0), getval(argv[i],&bval))
- {
- printf("Error in bss-segment address: %s is not 'r', 'x[td]', or an address.", argv[i]);
- return 1;
- }
-
- i++;
- break;
- case 'b':
+ display_version();
+ display_help();
+ return 1;
+ case 'a':
+ case 'A': // Set absolute linking on
+ if (aflag)
+ warn('a', 1);
+
+ if (i + 2 >= argc)
+ {
+ printf("Not enough arguments to -a\n");
+ return 1;
+ }
+
+ aflag = 1; // Set abs link flag
+ // Segment order is TEXT, DATA, BSS
+ // Text segment can be 'r', 'x' or a value
+ ttype = 0;
+
+ if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
+ {
+ ttype = -1; // TEXT segment is relocatable
+ }
+ else if ((*argv[i] == 'x' || *argv[i] == 'X'))
+ {
+ printf("Error in text-segment address: cannot be contiguous\n");
+ return 1;
+ }
+ else if ((ttype = 0), getval(argv[i], &tval))
+ {
+ printf("Error in text-segment address: %s is not 'r', 'x' or an address.", argv[i]);
+ return 1;
+ }
+
+ i++;
+ // Data segment can be 'r', 'x' or a value
+ dtype = 0;
+
+ if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
+ {
+ dtype = -1; // DATA segment is relocatable
+ }
+ else if ((*argv[i] == 'x' || *argv[i] == 'X'))
+ {
+ dtype = -2; // DATA follows TEXT
+ }
+ else if ((dtype = 0), getval(argv[i],&dval))
+ {
+ printf("Error in data-segment address: %s is not 'r', 'x' or an address.", argv[i]);
+ return 1;
+ }
+
+ i++;
+ btype = 0;
+
+ // BSS segment can be 'r', 'x' or a value
+ if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
+ {
+ btype = -1; // BSS segment is relocatable
+ }
+ else if ((*argv[i] == 'x' || *argv[i] == 'X'))
+ {
+ btype = -3; // BSS follows DATA
+ }
+ else if ((btype = 0), getval(argv[i],&bval))
+ {
+ printf("Error in bss-segment address: %s is not 'r', 'x[td]', or an address.", argv[i]);
+ return 1;
+ }
+
+ i++;
+ break;
+ case 'b':
- if (i + 2 > argc)
- {
- printf("Not enough arguments to -i\n");
- return 1;
- }
-
- ifile = argv[i++];
- isym = argv[i++];
-
- if ((argv[i-3][2] == 'i') || (argv[i-3][2] == 'I'))
- { // handle -ii (No truncation)
- if (!cflag)
- printf("warning: (-ii) COFF format output not specified\n");
- }
- else
- { // handle -i (Truncation)
- if (strlen(isym) > 7)
- isym[7] = '\0';
- }
-
- // Place include files in the DATA segment only
- if (dofile(ifile, DSTSEG_D, isym))
- return 1;
-
- break;
- case 'l':
+ if (i + 2 > argc)
+ {
+ printf("Not enough arguments to -i\n");
+ return 1;
+ }
+
+ ifile = argv[i++];
+ isym = argv[i++];
+
+ if ((argv[i-3][2] == 'i') || (argv[i-3][2] == 'I'))
+ { // handle -ii (No truncation)
+ if (!cflag)
+ printf("warning: (-ii) COFF format output not specified\n");
+ }
+ else
+ { // handle -i (Truncation)
+ if (strlen(isym) > 7)
+ isym[7] = '\0';
+ }
+
+ // Place include files in the DATA segment only
+ if (dofile(ifile, DSTSEG_D, isym))
+ return 1;
+
+ break;
+ case 'l':
- if (noheaderflag)
- warn('n', 1);
-
- noheaderflag = 1;
- break;
- case 'o':
- case 'O': // Specify an output file
- if (oflag)
- warn('o', 1);
-
- oflag = 1;
-
- if (i >= argc)
- {
- printf("No output filename following -o switch\n");
- return 1;
- }
-
- if (strlen(argv[i]) > FARGSIZE - 5)
- {
- printf("Output file name too long (sorry!)\n");
- return 1;
- }
-
- strcpy(ofile, argv[i++]);
- break;
- case 'r':
+ if (noheaderflag)
+ warn('n', 1);
+
+ noheaderflag = 1;
+ break;
+ case 'o':
+ case 'O': // Specify an output file
+ if (oflag)
+ warn('o', 1);
+
+ oflag = 1;
+
+ if (i >= argc)
+ {
+ printf("No output filename following -o switch\n");
+ return 1;
+ }
+
+ if (strlen(argv[i]) > FARGSIZE - 5)
+ {
+ printf("Output file name too long (sorry!)\n");
+ return 1;
+ }
+
+ strcpy(ofile, argv[i++]);
+ break;
+ case 'r':
- if (rflag)
- warn('r', 1);
-
- rflag = 1;
-
- switch (argv[i-1][2])
- {
- case 'w': case 'W': secalign = 1; break; // Word alignment
- case 'l': case 'L': secalign = 3; break; // Long alignment
- case 'p': case 'P': secalign = 7; break; // Phrase alignment
- case 'd': case 'D': secalign = 15; break; // Double phrase alignment
- case 'q': case 'Q': secalign = 31; break; // Quad phrase alignment
- default: secalign = 7; break; // Default phrase alignment
- }
-
- break;
- case 's':
+ if (rflag)
+ warn('r', 1);
+
+ rflag = 1;
+
+ switch (argv[i-1][2])
+ {
+ case 'w': case 'W': secalign = 1; break; // Word alignment
+ case 'l': case 'L': secalign = 3; break; // Long alignment
+ case 'p': case 'P': secalign = 7; break; // Phrase alignment
+ case 'd': case 'D': secalign = 15; break; // Double phrase alignment
+ case 'q': case 'Q': secalign = 31; break; // Quad phrase alignment
+ default: secalign = 7; break; // Default phrase alignment
+ }
+
+ break;
+ case 's':
- if (!vflag && !versflag)
- {
- display_version();
- }
-
- vflag++;
- break;
- case 'z':
- case 'Z': // Suppress banner flag
- if (zflag)
- warn('z', 1);
-
- zflag = 1;
- break;
- default:
- printf("unknown option argument `%c'\n", c);
- return 1;
- }
- }
- else
- { // Not a switch, then process as a file
- if (dofile(argv[i++], 0, NULL))
- return 1;
- }
-
- }
-
- if (!oflag && vflag)
- {
- strcpy(ofile, "output");
- printf("Output file is %s[.ext]\n", ofile);
- }
-
- if (oflag && vflag)
- printf("Output file is %s\n", ofile);
-
- if (sflag)
- lflag = 0;
-
- return 0; // No problems encountered
+ if (!vflag && !versflag)
+ {
+ display_version();
+ }
+
+ vflag++;
+ break;
+ case 'w':
+ case 'W': // Show warnings flag
+ if (wflag)
+ warn('w', 1);
+
+ wflag = 1;
+ break;
+ case 'z':
+ case 'Z': // Suppress banner flag
+ if (zflag)
+ warn('z', 1);
+
+ zflag = 1;
+ break;
+ default:
+ printf("unknown option argument `%c'\n", c);
+ return 1;
+ }
+ }
+ else
+ { // Not a switch, then process as a file
+ if (dofile(argv[i++], 0, NULL))
+ return 1;
+ }
+
+ }
+
+ if (!oflag && vflag)
+ {
+ strcpy(ofile, "output");
+ printf("Output file is %s[.ext]\n", ofile);
+ }
+
+ if (oflag && vflag)
+ printf("Output file is %s\n", ofile);
+
+ if (sflag)
+ lflag = 0;
+
+ return 0; // No problems encountered