+ relocsize = ofile->o_header.absrel.reloc.tsize;
+
+ if (vflag)
+ {
+ printf("RELOCSIZE :: %d Records = %d\n",relocsize,relocsize/8);
+ }
+
+ // Update pointers if DATA relocation records are being processed
+ if (flag == T_DATA)
+ {
+ sptr += ofile->o_header.tsize; // Start of DATA segment
+ rptr += ofile->o_header.absrel.reloc.tsize; // Start of DATA relocation records
+ relocsize = ofile->o_header.absrel.reloc.dsize;
+ }
+
+ // Process each relocation record for the TEXT segment
+ for(i=0; i<(int)relocsize; i+=8)
+ {
+ // Obtain both the relocation address and the relocation flags from the
+ // object file image
+ addr = getlong(rptr);
+ rflg = getlong(rptr + 4);
+ glblreloc = (rflg & 0x00000010 ? 1 : 0); // Set global relocation flag
+ absreloc = (rflg & 0x00000040 ? 1 : 0); // Set absolute relocation flag
+ relreloc = (rflg & 0x000000A0 ? 1 : 0); // Set relative relocation flag
+
+ // Additional processing required for global relocations
+ if (glblreloc)
+ {
+ // 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.
+ symidx = getlong(symtab + ((rflg >> 8) * 12));
+ memset(sym, 0, SYMLEN);
+ strcpy(sym, symbols + symidx);
+ olddata = newdata = 0; // Initialise old and new segment data
+ ssidx = ost_lookup(sym);
+ newdata = getlong(ost + ((ssidx - 1) * 12) + 8);
+ }
+
+ // Obtain the existing long word segment data and flip words if the
+ // relocation flags indicate it relates to a RISC MOVEI instruction
+ olddata = getlong(sptr + addr);
+
+ if (rflg & 0x01)
+ olddata = _SWAPWORD(olddata);
+
+ // Process record dependant on segment it relates to; TEXT, DATA or
+ // BSS. Construct a new relocated segment long word based on the
+ // required segment base address, the segment data offset in the
+ // resulting COF file and the offsets from the incoming object file.
+ //swcond = glblreloc ? ((hptr->h_type & 0x0E000000) >> 16) : (rflg & 0xFFFFFF00);
+ swcond = (rflg & 0xFFFFFF00);
+
+ if (!glblreloc)
+ {
+ switch (swcond)
+ {
+ case 0x00000200: // Absolute Value
+ break;
+ case 0x00000400: // TEXT segment relocation record
+//AARRRGGGGHHHHH! does the else belong to the 1st 'if' or the 2nd?
+// can we trust the indention to tell the truth here???
+// Braces were not here, so if something breaks, try pairing the else to the 1st 'if'...
+ if (!glblreloc)
+ {
+ if (flag == T_TEXT) // Is this a TEXT section record?
+ newdata = tbase + textoffset + olddata;
+ else
+ newdata = tbase + dataoffset + olddata; // Nope, must be DATA section
+ }
+
+ break;
+ case 0x00000600: // DATA segment relocation record
+ if (!glblreloc)
+ newdata = dbase + dataoffset + (olddata - ofile->o_header.tsize);