static void AssignFileLocs( section *sect ) /*****************************************/ { if( FmtData.u.dos.pad_sections ) { sect->outfile->file_loc = ROUND_UP( sect->outfile->file_loc, SECTOR_SIZE ); } sect->u.file_loc = sect->outfile->file_loc; sect->outfile->file_loc += MAKE_PARA( sect->size ) + MAKE_PARA( sect->relocs * sizeof( dos_addr ) ); DEBUG((DBG_LOADDOS, "section %d assigned to %l in %s", sect->ovl_num, sect->u.file_loc, sect->outfile->fname )); }
static void WritePharSimple( unsigned_32 start ) /**********************************************/ { simple_header header; unsigned_32 file_size; unsigned_32 header_size; unsigned_32 extra; unsigned_32 temp; if( FmtData.type & MK_PHAR_REX ) { SeekLoad( start + sizeof(simple_header) ); extra = start + sizeof( simple_header ) + WritePharRelocs(); header_size = MAKE_PARA( extra ); PadLoad( header_size - extra ); } else { SeekLoad( start + MAKE_PARA( sizeof(simple_header) ) ); header_size = MAKE_PARA( sizeof(simple_header) ); // para align. } file_size = header_size + WritePharData( start + header_size ); DBIWrite(); if( FmtData.type & MK_PHAR_SIMPLE ) { _HostU16toTarg( SIMPLE_SIGNATURE, header.signature ); } else { _HostU16toTarg( REX_SIGNATURE, header.signature ); } _HostU16toTarg( file_size % 512U, header.mod_size ); _HostU16toTarg( (file_size + 511U) / 512U, header.file_size ); _HostU16toTarg( Root->relocs, header.num_relocs ); _HostU16toTarg( header_size / 16, header.hdr_size ); extra = MemorySize() - file_size + header_size + 0xfff; temp = FmtData.u.phar.mindata + extra; if( temp < FmtData.u.phar.mindata ) temp = 0xffffffff; _HostU16toTarg( temp >> 12, header.min_data ); temp = FmtData.u.phar.maxdata + extra; if( temp < FmtData.u.phar.maxdata ) temp = 0xffffffff; _HostU16toTarg( temp >> 12, header.max_data ); _HostU32toTarg( StackAddr.off, header.ESP ); _HostU16toTarg( 0, header.checksum ); _HostU32toTarg( StartInfo.addr.off, header.EIP ); _HostU16toTarg( 0x1E, header.reloc_offset ); _HostU16toTarg( 0, header.overlay_num ); /* allow header size to exceed 1M */ _HostU16toTarg( (header_size / (16*0x10000ul)) + 1, header.always_one ); SeekLoad( start ); WriteLoad( &header, sizeof( simple_header ) ); if( FmtData.type & MK_PHAR_SIMPLE ) { PadLoad( 2 ); // header occupies a full paragraph. } }
static void WriteDOSSectRelocs( section *sect, bool repos ) /*********************************************************/ /* write all relocs associated with sect to the file */ { unsigned long loc; OUTFILELIST *out; if( sect->relocs != 0 ) { loc = sect->u.file_loc + MAKE_PARA( sect->size ); out = sect->outfile; if( out->file_loc > loc ) { SeekLoad( loc ); } else { if( repos ) { SeekLoad( out->file_loc ); } if( out->file_loc < loc ) { PadLoad( loc - out->file_loc ); out->file_loc = loc; } } loc += sect->relocs * sizeof( dos_addr ); DumpRelocList( sect->reloclist ); if( loc > out->file_loc ) { out->file_loc = loc; } } }
void FiniDOSLoadFile( void ) /*********************************/ /* terminate writing of load file */ { unsigned_32 hdr_size; unsigned_32 mz_hdr_size; unsigned_32 temp; unsigned_32 min_size; unsigned_32 root_size; dos_exe_header exe_head; if( FmtData.type & MK_COM ) { WriteCOMFile(); return; } if( FmtData.u.dos.full_mz_hdr ) { mz_hdr_size = 0x40; } else { mz_hdr_size = sizeof( dos_exe_header ) + sizeof( unsigned_32 ); } SeekLoad( mz_hdr_size ); root_size = WriteDOSData( mz_hdr_size ); if( FmtData.type & MK_OVERLAYS ) { PadOvlFiles(); } // output debug info into root main output file CurrSect = Root; DBIWrite(); hdr_size = MAKE_PARA( (unsigned long)Root->relocs * sizeof( dos_addr ) + mz_hdr_size ); DEBUG((DBG_LOADDOS, "root size %l, hdr size %l", root_size, hdr_size )); SeekLoad( 0 ); _HostU16toTarg( DOS_SIGNATURE, exe_head.signature ); temp = hdr_size / 16U; _HostU16toTarg( temp, exe_head.hdr_size ); _HostU16toTarg( root_size % 512U, exe_head.mod_size ); temp = ( root_size + 511U ) / 512U; _HostU16toTarg( temp, exe_head.file_size ); _HostU16toTarg( Root->relocs, exe_head.num_relocs ); min_size = MemorySize() - ( root_size - hdr_size ) + FmtData.SegMask; min_size >>= FmtData.SegShift; _HostU16toTarg( min_size, exe_head.min_16 ); _HostU16toTarg( 0xffff, exe_head.max_16 ); _HostU16toTarg( StartInfo.addr.off, exe_head.IP ); _HostU16toTarg( StartInfo.addr.seg, exe_head.CS_offset ); _HostU16toTarg( StackAddr.seg, exe_head.SS_offset ); _HostU16toTarg( StackAddr.off, exe_head.SP ); _HostU16toTarg( 0, exe_head.chk_sum ); _HostU16toTarg( mz_hdr_size, exe_head.reloc_offset ); _HostU16toTarg( 0, exe_head.overlay_num ); WriteLoad( &exe_head, sizeof( dos_exe_header ) ); WriteLoad( &OvlTabOffset, sizeof( unsigned_32 ) ); }
static unsigned_32 WriteDOSRootRelocs( unsigned_32 mz_hdr_size ) /**************************************************************/ /* write all relocs to the file */ { unsigned long header_size; DumpRelocList( Root->reloclist ); NullAlign( 0x10 ); header_size = (unsigned long)Root->relocs * sizeof( dos_addr ) + mz_hdr_size; return( MAKE_PARA( header_size ) ); }