int ost_index = 0; // Index of next ost addition
int endian; // Processor endianess
+// Some human readable defines for endianess
+#define ENDIANNESS_BIG 1
+#define ENDIANNESS_LITTLE 0
+
//
// Get a Long Word from Memory
//
-unsigned getlong(char * src)
+uint32_t getlong(uint8_t * src)
{
- unsigned temp;
- char * out;
+ uint32_t temp;
+ uint8_t * out;
- out = (char *)&temp;
+ out = (uint8_t *)&temp;
- if (endian == 1)
+ if (endian == ENDIANNESS_BIG)
{
*out++ = src[0];
*out++ = src[1];
//
// Put a Long Word into Memory
//
-void putlong(char * dest, unsigned val)
+void putlong(uint8_t * dest, uint32_t val)
{
- *dest++ = (char)(val >> 24);
- *dest++ = (char)(val >> 16);
- *dest++ = (char)(val >> 8);
- *dest = (char)val;
+ *dest++ = (uint8_t)(val >> 24);
+ *dest++ = (uint8_t)(val >> 16);
+ *dest++ = (uint8_t)(val >> 8);
+ *dest = (uint8_t)val;
}
//
// Get a Word from Memory
//
-int getword(char * src)
+uint16_t getword(uint8_t * src)
{
- unsigned temp;
- char * out;
+ uint16_t temp;
+ uint8_t * out;
- out = (char *)&temp;
+ out = (uint8_t *)&temp;
+#if 0
+ // Shamus: This assumes little endian...
*out++ = src[1];
*out++ = src[0];
- *out++ = 0;
- *out = 0;
+// Shamus: And *why* do this as a uint32_t???
+// *out++ = 0;
+// *out = 0;
+#else
+ if (endian == ENDIANNESS_BIG)
+ {
+ out[0] = src[0];
+ out[1] = src[1];
+ }
+ else
+ {
+ out[0] = src[1];
+ out[1] = src[0];
+ }
+#endif
return temp;
}
//
// Put a Word into Memory
//
-void putword(char * dest, int val)
+void putword(uint8_t * dest, uint16_t val)
{
- *dest++ = (char)(val >> 8);
- *dest = (char)val;
+ *dest++ = (uint8_t)(val >> 8);
+ *dest = (uint8_t)val;
}
//
long docommon(void)
{
- struct HREC * hptr; // Hash record pointer
- int i; // Iterator
+ struct HREC * hptr; // Hash record pointer
+ int i; // Iterator
for(i=0; i<NBUCKETS; i++)
{
if (iscommon(hptr->h_type))
{
if (hptr->h_type == 0x03000000)
- hptr->h_type = 0x02000000; // Absolutes can't be externals
+ hptr->h_type = 0x02000000; // Absolutes can't be externals
if (ost_add(hptr->h_sym, hptr->h_type, hptr->h_value) == -1)
return -1;
//
int ost_add(char * name, int type, long value)
{
- int ost_offset_p, ost_offset_e = 0; // OST table offsets for position calcs
- int slen = 0; // Symbol string length
- int ostresult; // OST index result
+ int ost_offset_p, ost_offset_e = 0; // OST table offsets for position calcs
+ int slen = 0; // Symbol string length
+ int ostresult; // OST index result
slen = strlen(name);
ost_offset_p = (ost_ptr - ost);
ost_offset_e = (ost_end - ost);
+ // 3 x int (12)
if ((ost_ptr + 12) > ost_end)
- { // 3 x int (12)
+ {
if ((ost = realloc(ost, (unsigned)(ost_end + OST_BLOCK))) == NULL)
{
printf("OST memory reallocation error.\n");
ost_offset_p = (oststr_ptr - oststr);
ost_offset_e = (oststr_end - oststr);
- if ((oststr_ptr + (slen+1+4)) > oststr_end)
+ if ((oststr_ptr + (slen + 1 + 4)) > oststr_end)
{
if ((oststr = realloc(oststr, (unsigned)(oststr_end + OST_BLOCK))) == NULL)
{
}
}
- // If this is a debug symbol and the include debug symbol flag (-g) is not set then do nothing
+#if 0
+if ((strcmp(name, "U235SE_playback_rate") == 0)
+ || (strcmp(name, "U235SE_playback_period") == 0))
+{
+ printf("%s found: ost[0]=$%08X, ost[1]=$%08X, ost[2]=$%08X\n", name, getlong(ost_ptr), type, value);
+}
+#endif
+ // If this is a debug symbol and the include debug symbol flag (-g) is not
+ // set then do nothing
if ((type & 0xF0000000) && !gflag)
{
// Do nothing
+#if 0
+if ((strcmp(name, "U235SE_playback_rate") == 0)
+ || (strcmp(name, "U235SE_playback_period") == 0))
+ printf("%s was IGNORED!\n", name);
+#endif
}
else
{
ostresult = ost_lookup(name); // Get symbol index in OST
- // If the symbol is in the output symbol table and the bflag is set (don't remove multiply
- // defined locals) and this is not an external/global symbol *** OR *** the symbol is not
- // in the output symbol table then add it.
+
+ // If the symbol is in the output symbol table and the bflag is set
+ // (don't remove multiply defined locals) and this is not an
+ // external/global symbol *** OR *** the symbol is not in the output
+ // symbol table then add it.
if (((ostresult != -1) && bflag && !(type & 0x01000000))
- || ((ostresult != -1) && gflag && (type & 0xF0000000)) || (ostresult == -1))
+ || ((ostresult != -1) && gflag && (type & 0xF0000000)) || (ostresult == -1))
{
+#if 1
+if ((strcmp(name, "U235SE_playback_rate") == 0)
+ || (strcmp(name, "U235SE_playback_period") == 0))
+ printf("%s was added to the ost.\n", name);
+#endif
if ((type & 0xF0000000) == 0x40000000)
putlong(ost_ptr, 0x00000000); // Zero string table offset for dbg line
else
putlong(ost_ptr + 8, value);
ost_ptr += 12;
- // If the symbol type is anything but a debug line information symbol then write
- // the symbol string to the string table
+ // If the symbol type is anything but a debug line information
+ // symbol then write the symbol string to the string table
if ((type & 0xF0000000) != 0x40000000)
{
strcpy(oststr_ptr, name); // Put symbol name in string table
}
}
- return 0; // not sure about this as it could affect return indices. needed to stop return error.
+ // not sure about this as it could affect return indices. needed to stop return error.
+ return 0;
}
for(i=0; i<ost_index; i++)
{
- if (!strcmp(oststr + stro, sym))
+ if (strcmp(oststr + stro, sym) == 0)
+ {
+#if 0
+ // Shamus: More debug stuffs...
+ if (vflag > 1)
+ {
+ printf("ost_lookup(): Found @ %i (looking for '%s', found '%s')\n", i, sym, oststr + stro);
+ }
+#endif
+
return i + 1;
- else
- stro += strlen(oststr + stro) + 1;
+ }
+
+ stro += strlen(oststr + stro) + 1;
}
return -1;
olddata = newdata = 0; // Initialise old and new segment data
ssidx = ost_lookup(sym);
newdata = getlong(ost + ((ssidx - 1) * 12) + 8);
+//nope, false lead. -0 & -2 give bad results
+// newdata = getlong(ost + ((ssidx - 2) * 12) + 8);
}
// Obtain the existing long word segment data and flip words if the
}
// Shamus: Let's output some info to aid in debugging this crap
- if (vflag)
+ if (vflag > 1)
{
- printf("reloc_segment(%d): %s, $%08X: $%08X => $%08X\n",i, (glblreloc ? sym : "(LOCAL)"), addr, olddata, getlong(sptr + addr));
+ char ssiString[128];
+ ssiString[0] = 0;
+
+ if (glblreloc)
+ sprintf(ssiString, " [ssi:%i]", ssidx);
+
+ printf("reloc_segment($%08X): %s, $%08X: $%08X => $%08X%s\n", rflg, (glblreloc ? sym : "(LOCAL)"), addr, olddata, getlong(sptr + addr), ssiString);
}
rptr += 8; // Point to the next relocation record
void put_name(struct OFILE * p)
{
int flag = *(p->o_arname);
- printf("%s%s%s", flag ? p->o_arname : "", flag ? ":" : "", p->o_name);
+ printf("%s%s%s", (flag ? (char *)(p->o_arname) : ""), (flag ? ":" : ""), p->o_name);
}
return 1;
}
+ // Shamus: Moar testing...
+ if (vflag > 1)
+ {
+ printf("add_to_hlist(): hptr=$%08X, sym=\"%s\", ofile=$%08X, value=%li, type=%i", (unsigned int)hptr, sym, (unsigned int)ofile, value, type);
+ }
+
for(i=0; i<SYMLEN; i++)
htemp->h_sym[i] = '\0';
while (hptr != NULL)
{
- // if (symcmp(symbol, hptr->h_sym)) <-- left here for giggles :D - LinkoVitch
- if (strcmp(symbol,hptr->h_sym)==0)
+//This is utter failure...
+// if (symcmp(symbol, hptr->h_sym)) <-- left here for giggles :D - LinkoVitch
+ if (strcmp(symbol, hptr->h_sym) == 0)
return hptr;
hptr = hptr->h_next; // Return hash pointer if found
char * p = (char *)&i;
if (p[0] == 1)
- return 0; // LITTLE
+ return ENDIANNESS_LITTLE;
- return 1; // BIG
+ return ENDIANNESS_BIG;
}
printf("Absolute linking ");
if (cflag)
- printf("(COF)\n");
+ printf("(COF)\n");
else
- printf("(ABS)\n");
+ printf("(ABS)\n");
}
if (vflag > 1)
printf("+---------+----------+----------+----------+\n\n");
}
+//printf("BIG_ENDIAN = %i, LITTLE_ENDIAN = %i\n", BIG_ENDIAN, LITTLE_ENDIAN);
+
free(header); // Free allocated memory
rln_exit(); // Perform application exit
}
#endif
#define MAJOR 1 // Major version number
-#define MINOR 0 // Minor version number
-#define PATCH 2 // Patch release number
+#define MINOR 1 // Minor version number
+#define PATCH 0 // Patch release number
#ifdef WIN32
#define PLATFORM "Win32" // Release platform - Windows
// will have to read the file into a buffer and stuff the values into the
// structure (see slongio.c).
+// Rather than rely on dodgy compilers for something that's now a C99 standard,
+// let's do this:
+#include <stdint.h>
+
struct OHEADER
{
- long magic; // $0107 for .o, $601B for abs
- long tsize;
- long dsize;
- long bsize;
- long ssize;
- union {
- struct { // For .o
- long tsize; // Text relocation size
- long dsize; // Data relocation size
- char reserved[12];
- } reloc;
- struct { // For .abs
- long stksize; // Unused
- long tstart; // Start of TEXT
- long rbflag; // -1 if no fixups at all
- long dstart; // Start of DATA
- long bstart; // Start of BSS
- } abs;
- } absrel;
- char * ostbase; // Base of output symbol table
- long fsize; // Length of fixups
- char * fixups; // Start of fixups
+ uint32_t magic; // $0107 for .o, $601B for abs
+ uint32_t tsize;
+ uint32_t dsize;
+ uint32_t bsize;
+ uint32_t ssize;
+ union {
+ struct { // For .o
+ uint32_t tsize; // Text relocation size
+ uint32_t dsize; // Data relocation size
+ uint8_t reserved[12];
+ } reloc;
+ struct { // For .abs
+ uint32_t stksize; // Unused
+ uint32_t tstart; // Start of TEXT
+ uint32_t rbflag; // -1 if no fixups at all
+ uint32_t dstart; // Start of DATA
+ uint32_t bstart; // Start of BSS
+ } abs;
+ } absrel;
+ uint8_t * ostbase; // Base of output symbol table
+ uint32_t fsize; // Length of fixups
+ uint8_t * fixups; // Start of fixups
};
-#define new_oheader() (struct OHEADER *)malloc((long)sizeof(struct OHEADER))
+#define new_oheader() (struct OHEADER *)malloc((uint32_t)sizeof(struct OHEADER))
struct ARHEADER
{
- char a_fname[14];
- long a_modti;
- char a_userid;
- char a_gid;
- int a_fimode;
- long a_fsize;
- int reserved; // Two bytes zeroes btw header & file
+ uint8_t a_fname[14];
+ uint32_t a_modti;
+ uint8_t a_userid;
+ uint8_t a_gid;
+ uint16_t a_fimode;
+ uint32_t a_fsize;
+ uint16_t reserved; // Two bytes zeroes btw header & file
};
-#define new_arheader() (struct ARHEADER *)malloc((long)sizeof(struct ARHEADER))
+#define new_arheader() (struct ARHEADER *)malloc((uint32_t)sizeof(struct ARHEADER))
// Object File Structure and Related Items
struct OFILE
{
- char o_name[FNLEN]; // Fixed-length names
- char o_arname[FNLEN]; // Name of archive this is from
- struct OFILE * o_next; // Next object file
- long o_tbase, o_dbase, o_bbase; // Computed bases for this ofile
- int o_symstart; // First sym in image is nth in out
- int o_flags; // Flags (see O_*)
- struct OHEADER o_header; // Header of this file
- char * o_image; // Image of this file
+ uint8_t o_name[FNLEN]; // Fixed-length names
+ uint8_t o_arname[FNLEN]; // Name of archive this is from
+ struct OFILE * o_next; // Next object file
+ uint32_t o_tbase, o_dbase, o_bbase; // Computed bases for this ofile
+ uint16_t o_symstart; // First sym in image is nth in out
+ uint16_t o_flags; // Flags (see O_*)
+ struct OHEADER o_header; // Header of this file
+ uint8_t * o_image; // Image of this file
};
-#define new_ofile() (struct OFILE *)malloc((long)sizeof(struct OFILE))
+#define new_ofile() (struct OFILE *)malloc((uint32_t)sizeof(struct OFILE))
// Flags in an Object File's o_flags field
// O_USED: means this ofile is used or is on the command line or in a -x
-#define O_USED 0x0001
+#define O_USED 0x0001
#define O_ARCHIVE 0x0002 // This is a dummy archive entry
// Symbol Record
struct SYMREC
{
- char s_name[SYMLEN]; // Including null terminator
- int s_type;
- long s_value;
- struct SYMREC *s_next;
+ uint8_t s_name[SYMLEN]; // Including null terminator
+ uint16_t s_type;
+ uint32_t s_value;
+ struct SYMREC * s_next;
};
-#define new_symrec() (struct SYMREC *)malloc((long)sizeof(struct SYMREC))
+#define new_symrec() (struct SYMREC *)malloc((uint32_t)sizeof(struct SYMREC))
// Hash Record
struct HREC
{
- char h_sym[SYMLEN];
- struct HREC * h_next;
- struct OFILE * h_ofile;
- long h_value;
- int h_type;
+ uint8_t h_sym[SYMLEN];
+ struct HREC * h_next;
+ struct OFILE * h_ofile;
+ uint32_t h_value;
+//Shamus: This was an "int" but as per above, should have been a 16-bit value.
+// Changing it to a 32-bit value (as per compiler warning).
+ uint32_t h_type;
};
-#define new_hrec() (struct HREC *)malloc((long)sizeof(struct HREC))
+#define new_hrec() (struct HREC *)malloc((uint32_t)sizeof(struct HREC))
#define NBUCKETS 1024 // Number of hash buckets
// Symbol Table - Type Definitions
#define T_UNDF 0x00000000 // Undefined Symbol
-#define T_EXT 0x01000000 // External Bit, OR\92ed In
+#define T_EXT 0x01000000 // External Bit, OR'ed In
#define T_ABS 0x02000000 // Absolute Symbol
#define T_TEXT 0x04000000 // TEXT Segment
#define T_DATA 0x06000000 // DATA Segment
#define isextern(type) (((type) & T_EXT) == T_EXT)
#define islocal(type) (((type) & T_EXT) == 0)
+/*
+Shamus:
+Just look at this. I can't believe that somebody actually wrote this piece of
+failure and thought it was a good idea. I'm leaving it here as a testament to
+complete, total, and utter failure. :-)
+*/
+
+// This macro is used to compare two symbols for equality. It depends on
+// symcopy remaining as it is (copies two longs plus a null)
+
+//#define symcmp(a,b) ((*(uint32_t *)(a) == *(uint32_t *)(b)) && \
+// (*(uint32_t *)((a) + sizeof(uint32_t)) == \
+// *(uint32_t *)((b) + sizeof(uint32_t))))
+
// Function Prototypes
int doargs(int, char *[]);