+ 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)
+ newdata = tbase + textoffset + olddata;
+ else
+ newdata = tbase + dataoffset + olddata;
+ }
+
+ break;
+ case 0x00000600: // DATA segment relocation record
+ if (!glblreloc)
+ newdata = dbase + dataoffset + (olddata - ofile->o_header.tsize);
+
+ break;
+ case 0x00000800: // BSS segment relocation record
+ if (!glblreloc)
+ newdata = bbase + bssoffset
+ + (olddata - (ofile->o_header.tsize + ofile->o_header.dsize));
+
+ break;
+ }
+ }
+ else
+ {
+ if (!relreloc)
+ newdata += olddata;
+ }
+
+ // Set absolute (long) or relative (word) address of symbol
+ if (absreloc)
+ {
+ // Flip the new long word segment data if the relocation record
+ // indicated a RISC MOVEI instruction and place the resulting data
+ // back in the COF segment
+ if (rflg & 0x01)
+ newdata = _SWAPWORD(newdata);
+
+ putlong(sptr + addr, newdata);
+ }
+ else if (relreloc)
+ {
+ putword(sptr + addr, newdata - tbase - addr - ofile->o_tbase);
+ }
+
+ // Shamus: Let's output some info to aid in debugging this crap
+ if (vflag)
+ {
+ printf("reloc_segment(): %s, $%08X: $%08X => $%08X\n", sym, addr, olddata, getlong(sptr + addr));
+ }
+
+ rptr += 8; // Point to the next relocation record
+ }
+
+ // Update the COF segment offset allowing for the phrase padding.
+ if (flag == T_TEXT)
+ {
+ // TEXT segment plus padding
+ pad = ((ofile->o_header.tsize + secalign) & ~secalign);
+ textoffset += (ofile->o_header.tsize + (pad - ofile->o_header.tsize));
+ }
+ else
+ {
+ // DATA segment plus padding
+ pad = ((ofile->o_header.dsize + secalign) & ~secalign);
+ dataoffset += (ofile->o_header.dsize + (pad - ofile->o_header.dsize));
+ // BSS segment plus padding
+ pad = ((ofile->o_header.bsize + secalign) & ~secalign);
+ bssoffset += (ofile->o_header.bsize + (pad - ofile->o_header.bsize));
+ }
+
+ // Return value, should always be zero
+ return 0;