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 WriteHeader32( void ) /* write 32-bit device header */ { rdos_dev32_header exe_head; unsigned_16 temp16; unsigned_32 temp32; SeekLoad( 0 ); _HostU16toTarg( RDOS_SIGNATURE_32, exe_head.signature ); _HostU32toTarg( StartInfo.addr.off, exe_head.EIP ); temp32 = (unsigned_32)CodeSize; _HostU32toTarg( temp32, exe_head.code_size ); temp16 = (unsigned_16)FmtData.u.rdos.code_sel; _HostU16toTarg( temp16, exe_head.code_sel ); temp32 = (unsigned_32)DataSize; _HostU32toTarg( temp32, exe_head.data_size ); temp16 = (unsigned_16)FmtData.u.rdos.data_sel; _HostU16toTarg( temp16, exe_head.data_sel ); WriteLoad( &exe_head, sizeof( rdos_dev32_header ) ); }
void CVGenLines( lineinfo *info ) /*******************************/ // called during pass 2 linnum processing { ln_off_pair UNALIGN *pair; unsigned_32 temp_off; unsigned_16 temp_num; offset adjust; unsigned long cvsize; unsigned size; segdata *seg; seg = info->seg; size = info->size & ~LINE_IS_32BIT; if( !( CurrMod->modinfo & DBI_LINE ) ) return; adjust = seg->a.delta + seg->u.leader->seg_addr.off; if( LineInfo.offbase == 0 ) { // this is our first time through. LineInfo.seg = GetCVSegment( seg->u.leader ); LineInfo.linestart = SectAddrs[CVSECT_MISC]; cvsize = sizeof( cheesy_module_header ) + sizeof( cheesy_mapping_table ) + ROUND_UP( sizeof( cheesy_file_table ) + strlen( CurrMod->name ), 4 ); LineInfo.offbase = SectAddrs[CVSECT_MISC] + cvsize; LineInfo.numbase = LineInfo.offbase + CurrMod->d.cv->numlines * sizeof( unsigned_32 ); cvsize += CurrMod->d.cv->numlines * sizeof( unsigned_32 ); cvsize += ROUND_UP( CurrMod->d.cv->numlines * sizeof( unsigned_16 ), 4 ); GenSubSection( sstSrcModule, cvsize ); SectAddrs[CVSECT_MISC] += cvsize; LineInfo.range.start = adjust; LineInfo.range.end = adjust + seg->length; } else { if( adjust < LineInfo.range.start ) { LineInfo.range.start = adjust; } if( adjust + seg->length > LineInfo.range.end ) { LineInfo.range.end = adjust + seg->length; } } pair = (ln_off_pair *)info->data; if( info->size & LINE_IS_32BIT ) { while( size > 0 ) { pair->_386.off += adjust; if( pair->_386.off < LineInfo.prevaddr ) { LineInfo.needsort = TRUE; } LineInfo.prevaddr = pair->_386.off; _HostU32toTarg( pair->_386.off, temp_off ); _HostU16toTarg( pair->_386.linnum, temp_num ); PutInfo( LineInfo.offbase, &temp_off, sizeof( unsigned_32 ) ); PutInfo( LineInfo.numbase, &temp_num, sizeof( unsigned_16 ) ); LineInfo.offbase += sizeof( unsigned_32 ); LineInfo.numbase += sizeof( unsigned_16 ); pair = (void *)( (char *)pair + sizeof( ln_off_386 ) ); size -= sizeof( ln_off_386 ); } } else { while( size > 0 ) { pair->_286.off += adjust; if( pair->_286.off < LineInfo.prevaddr ) { LineInfo.needsort = TRUE; } LineInfo.prevaddr = pair->_286.off; _HostU16toTarg( pair->_286.off, temp_off ); _HostU16toTarg( pair->_286.linnum, temp_num ); PutInfo( LineInfo.offbase, &temp_off, sizeof( unsigned_32 ) ); PutInfo( LineInfo.numbase, &temp_num, sizeof( unsigned_16 ) ); LineInfo.offbase += sizeof( unsigned_32 ); LineInfo.numbase += sizeof( unsigned_16 ); pair = (void *)( (char *)pair + sizeof( ln_off_286 ) ); size -= sizeof( ln_off_286 ); } } }
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 ) ); }