{
// Obtain the string table index for the relocation symbol, look
// for it in the globals hash table to obtain information on that
{
// Obtain the string table index for the relocation symbol, look
// for it in the globals hash table to obtain information on that
// Add all global and external symbols to the output symbol table
// [This is confusing--is it adding globals or locals? common == local!
// but then again, we see this in the header:
// Add all global and external symbols to the output symbol table
// [This is confusing--is it adding globals or locals? common == local!
// but then again, we see this in the header:
- putword(himage + 0, 0x0150 ); // Magic Number (0x0150)
- putword(himage + 2, 0x0003 ); // Sections Number (3)
- putlong(himage + 4, 0x00000000 ); // Date (0L)
- putlong(himage + 8, dsoff + header->dsize); // Offset to Symbols Section
- putlong(himage + 12, ost_index); // Number of Symbols
- putword(himage + 16, 0x001C ); // Size of RUN_HDR (0x1C)
- putword(himage + 18, 0x0003 ); // Executable Flags (3)
+ putword(himage + 0, 0x0150 ); // Magic Number (0x0150)
+ putword(himage + 2, 0x0003 ); // Sections Number (3)
+ putlong(himage + 4, 0x00000000 ); // Date (0L)
+ putlong(himage + 8, dsoff + header->dsize); // Offset to Symbols Section
+ putlong(himage + 12, ost_index); // Number of Symbols
+ putword(himage + 16, 0x001C ); // Size of RUN_HDR (0x1C)
+ putword(himage + 18, 0x0003 ); // Executable Flags (3)
- putlong(himage + 20, 0x00000107 ); // Magic/vstamp
- putlong(himage + 24, header->tsize ); // TEXT size in bytes
- putlong(himage + 28, header->dsize ); // DATA size in bytes
- putlong(himage + 32, header->bsize ); // BSS size in bytes
- putlong(himage + 36, tbase ); // Start of executable, normally @TEXT
- putlong(himage + 40, tbase ); // @TEXT
- putlong(himage + 44, dbase ); // @DATA
+ putlong(himage + 20, 0x00000107 ); // Magic/vstamp
+ putlong(himage + 24, header->tsize ); // TEXT size in bytes
+ putlong(himage + 28, header->dsize ); // DATA size in bytes
+ putlong(himage + 32, header->bsize ); // BSS size in bytes
+ putlong(himage + 36, tbase ); // Start of executable, normally @TEXT
+ putlong(himage + 40, tbase ); // @TEXT
+ putlong(himage + 44, dbase ); // @DATA
// Build the TEXT SEC_HDR
putlong(himage + 48, 0x2E746578 );
// Build the TEXT SEC_HDR
putlong(himage + 48, 0x2E746578 );
- putlong(himage + 52, 0x74000000 ); // ".text"
- putlong(himage + 56, tbase ); // TEXT START
- putlong(himage + 60, tbase ); // TEXT START
- putlong(himage + 64, header->tsize ); // TEXT size in bytes
- putlong(himage + 68, tsoff ); // Offset to section data in file
- putlong(himage + 72, 0x00000000 ); // Offset to section reloc in file (0L)
- putlong(himage + 76, 0x00000000 ); // Offset to debug lines structures (0L)
- putlong(himage + 80, 0x00000000 ); // Nreloc/nlnno (0L)
- putlong(himage + 84, 0x00000020 ); // SEC_FLAGS: STYP_TEXT
+ putlong(himage + 52, 0x74000000 ); // ".text"
+ putlong(himage + 56, tbase ); // TEXT START
+ putlong(himage + 60, tbase ); // TEXT START
+ putlong(himage + 64, header->tsize ); // TEXT size in bytes
+ putlong(himage + 68, tsoff ); // Offset to section data in file
+ putlong(himage + 72, 0x00000000 ); // Offset to section reloc in file (0L)
+ putlong(himage + 76, 0x00000000 ); // Offset to debug lines structures (0L)
+ putlong(himage + 80, 0x00000000 ); // Nreloc/nlnno (0L)
+ putlong(himage + 84, 0x00000020 ); // SEC_FLAGS: STYP_TEXT
// Build the DATA SEC_HDR
putlong(himage + 88, 0x2E646174 );
// Build the DATA SEC_HDR
putlong(himage + 88, 0x2E646174 );
- putlong(himage + 92, 0x61000000 ); // ".data"
- putlong(himage + 96, dbase ); // DATA START
- putlong(himage + 100, dbase ); // DATA START
- putlong(himage + 104, header->dsize ); // DATA size in bytes
- putlong(himage + 108, dsoff ); // Offset to section data in file
- putlong(himage + 112, 0x00000000 ); // Offset to section reloc in file (0L)
- putlong(himage + 116, 0x00000000 ); // Offset to debugging lines structures (0L)
- putlong(himage + 120, 0x00000000 ); // Nreloc/nlnno (0L)
- putlong(himage + 124, 0x00000040 ); // SEC_FLAGS: STYP_DATA
+ putlong(himage + 92, 0x61000000 ); // ".data"
+ putlong(himage + 96, dbase ); // DATA START
+ putlong(himage + 100, dbase ); // DATA START
+ putlong(himage + 104, header->dsize ); // DATA size in bytes
+ putlong(himage + 108, dsoff ); // Offset to section data in file
+ putlong(himage + 112, 0x00000000 ); // Offset to section reloc in file (0L)
+ putlong(himage + 116, 0x00000000 ); // Offset to debugging lines structures (0L)
+ putlong(himage + 120, 0x00000000 ); // Nreloc/nlnno (0L)
+ putlong(himage + 124, 0x00000040 ); // SEC_FLAGS: STYP_DATA
- putlong(himage + 132, 0x00000000 ); // ".bss"
- putlong(himage + 136, bbase ); // BSS START
- putlong(himage + 140, bbase ); // BSS START
- putlong(himage + 144, header->bsize ); // BSS size in bytes
- putlong(himage + 148, bsoff ); // Offset to section data in file
- putlong(himage + 152, 0x00000000 ); // Offset to section reloc in file (0L)
- putlong(himage + 156, 0x00000000 ); // Offset to debugging lines structures (0L)
- putlong(himage + 160, 0x00000000 ); // Nreloc/nlnno (0L)
- putlong(himage + 164, 0x00000080 ); // SEC_FLAGS: STYP_BSS
-
- symoffset = 168; // Update symbol offset
+ putlong(himage + 132, 0x00000000 ); // ".bss"
+ putlong(himage + 136, bbase ); // BSS START
+ putlong(himage + 140, bbase ); // BSS START
+ putlong(himage + 144, header->bsize ); // BSS size in bytes
+ putlong(himage + 148, bsoff ); // Offset to section data in file
+ putlong(himage + 152, 0x00000000 ); // Offset to section reloc in file (0L)
+ putlong(himage + 156, 0x00000000 ); // Offset to debugging lines structures (0L)
+ putlong(himage + 160, 0x00000000 ); // Nreloc/nlnno (0L)
+ putlong(himage + 164, 0x00000080 ); // SEC_FLAGS: STYP_BSS
+
+ symoffset = 168; // Update symbol offset
- putword(himage + 0, 0x601B ); // Magic Number (0x601B)
- putlong(himage + 2, header->tsize ); // TEXT segment size
- putlong(himage + 6, header->dsize ); // DATA segment size
- putlong(himage + 10, header->bsize ); // BSS segment size
- putlong(himage + 14, ost_index * 14 ); // Symbol table size (?)
- putlong(himage + 18, 0x00000000 ); //
- putlong(himage + 22, tbase ); // TEXT base address
- putword(himage + 26, 0xFFFF ); // Flags (?)
- putlong(himage + 28, dbase ); // DATA base address
- putlong(himage + 32, bbase ); // BSS base address
+ putword(himage + 0, 0x601B ); // Magic Number (0x601B)
+ putlong(himage + 2, header->tsize ); // TEXT segment size
+ putlong(himage + 6, header->dsize ); // DATA segment size
+ putlong(himage + 10, header->bsize ); // BSS segment size
+ putlong(himage + 14, ost_index * 14 ); // Symbol table size (?)
+ putlong(himage + 18, 0x00000000 ); //
+ putlong(himage + 22, tbase ); // TEXT base address
+ putword(himage + 26, 0xFFFF ); // Flags (?)
+ putlong(himage + 28, dbase ); // DATA base address
+ putlong(himage + 32, bbase ); // BSS base address
- if (fwrite(ost, (ost_ptr - ost), 1, fd) != 1) goto werror;
- if (fwrite(oststr, (oststr_ptr - oststr), 1, fd) != 1) goto werror;
+ if (fwrite(ost, (ost_ptr - ost), 1, fd) != 1)
+ goto werror;
+
+ if (fwrite(oststr, (oststr_ptr - oststr), 1, fd) != 1)
+ goto werror;
}
}
// Absolute (ABS) symbol/string table
else
{
// The symbol and string table have been created as part of the
}
}
// Absolute (ABS) symbol/string table
else
{
// The symbol and string table have been created as part of the
- // DoSymbol() 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
+ // DoSymbol() 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
+ 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
index = getlong(ost + (i * 12)); // Get symbol index
type = getlong((ost + (i * 12)) + 4); // Get symbol type
- putword(symbol + 8, abstype); // Write back new ABS type
- putlong(symbol + 10, value); // Write back value
+ putword(symbol + 8, abstype); // Write back new ABS type
+ putlong(symbol + 10, value); // Write back value
- if (fwrite(symbol, 14, 1, fd) != 1) goto werror; // Write symbol record
+ // Write symbol record
+ if (fwrite(symbol, 14, 1, fd) != 1)
+ goto werror;
-//int atolx(char * string, long * value)
-int atolx(char * string, int * value)
+int GetHexValue(char * string, int * value)
-//
-// Stuff the (long) value of a string into the value argument. RETURNS TRUE if
-// the string doesn't parse. Parses only as a hex string.
-//
-int getval(char * string, int * value)
-{
- return atolx(string, value);
-}
-
-
//
// Create one big .o file from the images already in memory, returning a
// pointer to an OHEADER. Note that the oheader is just the header for the
//
// Create one big .o file from the images already in memory, returning a
// pointer to an OHEADER. Note that the oheader is just the header for the
{
unsigned tptr, dptr, bptr; // Bases in runtime model
int ret = 0; // Return value
{
unsigned tptr, dptr, bptr; // Bases in runtime model
int ret = 0; // Return value
// For each object file, accumulate the sizes of the segments but remove
// those object files which are unused
// For each object file, accumulate the sizes of the segments but remove
// those object files which are unused
- oprev = NULL; // Init previous obj file list ptr
- otemp = olist; // Set temp pointer to object file list
+ struct OFILE * oprev = NULL; // Init previous obj file list ptr
+ struct OFILE * otemp = olist; // Set temp pointer to object file list
+ int i = 0;
+
+ // Also need to remove them from the obj_* tables too :-P
+ // N.B.: Would probably be worthwhile to remove crap like this
+ // and stuff it into the OFILE structure...
+ if (wflag)
+ printf("ยป-> removing %s... (index == %i, len == %i)\n", obj_fname[i], i, obj_index - 1);
+
+ int k;
+
+ for(k=i; k<obj_index-1; k++)
+ {
+ memcpy(obj_fname[k], obj_fname[k + 1], FNLEN);
+ obj_segsize[k][0] = obj_segsize[k + 1][0];
+ obj_segsize[k][1] = obj_segsize[k + 1][1];
+ obj_segsize[k][2] = obj_segsize[k + 1][2];
+ }
+
+ obj_index--;
+ i--;
// Process the unresolved symbols list. This may involve pulling in symbols
// from any included .a units. Such units are lazy linked by default; we
// Process the unresolved symbols list. This may involve pulling in symbols
// from any included .a units. Such units are lazy linked by default; we
strcpy(obj_fname[obj_index], path_tail(fname));
obj_segsize[obj_index][0] = (getlong(ptr + 4) + secalign) & ~secalign;
obj_segsize[obj_index][1] = (getlong(ptr + 8) + secalign) & ~secalign;
strcpy(obj_fname[obj_index], path_tail(fname));
obj_segsize[obj_index][0] = (getlong(ptr + 4) + secalign) & ~secalign;
obj_segsize[obj_index][1] = (getlong(ptr + 8) + secalign) & ~secalign;
{
printf("Error in bss-segment address: %s is not 'r', 'x[td]', or an address.", argv[i]);
return 1;
{
printf("Error in bss-segment address: %s is not 'r', 'x[td]', or an address.", argv[i]);
return 1;