void DgAlignInternal( // ALIGN INTERNAL CONTROL BLOCK void ) { target_size_t adjust; adjust = SegmentAdjust( SEG_CONST, DGTell(), TARGET_POINTER ); alignInSegment( adjust, SEG_CONST ); }
void DgAlignSegment( // ALIGN SEGMENT TO CORRECT BOUNDARY fe_seg_id segid, // - aligned segment unsigned amount ) // - amount to align { target_size_t adjust; adjust = SegmentAdjust( segid, DGTell(), amount ); alignInSegment( adjust, segid ); }
void DgAlignSymbol( // ALIGN SYMBOL TO CORRECT BOUNDARY SYMBOL sym ) // - symbol to align { target_size_t adjust; fe_seg_id segid; segid = sym->segid; adjust = SegmentAdjust( segid, DGTell(), SegmentAlignment( sym ) ); alignInSegment( adjust, segid ); }
static bool same_segment( // DETERMINE IF SAME SEGMENT void * _curr, // - current segment const void * _lk ) // - segment lookup structure { PC_SEGMENT *curr = _curr; const struct seg_look* lk = _lk; target_offset_t align_adjust; target_size_t new_offset; if( lk->use_seg_id && lk->seg_id != SEG_NULL && curr->seg_id != lk->seg_id ) { return( FALSE ); } if( lk->use_attrs && curr->attrs != lk->attrs ) { return( FALSE ); } if( lk->use_align && curr->align != lk->align ) { return( FALSE ); } if( lk->use_sym_size_align ) { align_adjust = SegmentAdjust( curr->seg_id, curr->offset, lk->sym_align ); new_offset = curr->offset + align_adjust + lk->sym_size; if( _CHECK_ADJUST( new_offset, curr->offset ) ) { new_offset = 0; } if( new_offset == 0 ) { return( FALSE ); } } if( lk->use_name ) { if( strcmp( curr->name, lk->seg_name ) != 0 ) { return( FALSE ); } if( curr->class_name != NULL ) { if( lk->class_name == NULL ) { return( FALSE ); } if( strcmp( curr->class_name, lk->class_name ) != 0 ) { return( FALSE ); } } else { if( lk->class_name != NULL ) { return( FALSE ); } } } if( lk->use_only_strings && !curr->only_strings ) { return( FALSE ); } return( TRUE ); }
static fe_seg_id findFarSegment(// SEGMENT: ADD SYMBOL TO FAR SEGMENT target_size_t size, // - size of symbol target_offset_t align, // - alignment of symbol unsigned ads_control ) // - addDefSeg control word { PC_SEGMENT *curr; // - new segment struct seg_look lk; // - look-up structure lk.use_seg_id = FALSE; if( ads_control & ADS_CODE_SEGMENT ) { lk.attrs = SGAT_CODE_BASED; } else if( ads_control & ADS_CONST_SEGMENT ) { lk.attrs = SGAT_DATA_PRIVATE_RO; } else { lk.attrs = SGAT_DATA_PRIVATE_RW; } lk.use_attrs = TRUE; lk.use_align = FALSE; lk.sym_size = size; lk.sym_align = align; lk.use_sym_size_align = TRUE; lk.use_name = FALSE; lk.use_only_strings = FALSE; if( ads_control & ADS_STRING_SEGMENT ) { lk.use_only_strings = TRUE; } curr = RingLookup( seg_list, &same_segment, &lk ); if( curr == NULL ) { if( ads_control & ADS_CODE_SEGMENT ) { curr = addDefSeg( &code_def_seg, ads_control ); code_def_seg.ds_used = TRUE; } else { curr = addDefSeg( &data_def_seg, ads_control ); data_def_seg.ds_used = TRUE; } } curr->offset += SegmentAdjust( curr->seg_id, curr->offset, align ); curr->offset += size; accumAlignment( curr, align ); _markUsed( curr, TRUE ); curr->has_data = TRUE; return( curr->seg_id ); }
fe_seg_id SegmentAddSym( // SEGMENT: ADD SYMBOL TO SPECIFIED SEGMENT SYMBOL sym, // - sym to add fe_seg_id id, // - id of segment to use target_size_t size, // - size of sym target_offset_t align ) // - alignment for sym { PC_SEGMENT *curr; // - new segment target_size_t aligned_offset; target_size_t calc_offset; target_size_t total_size; if( id == SEG_DATA || ( id == SEG_BSS && flags.use_def_seg ) ) { curr = data_def_seg.pcseg; id = curr->seg_id; } else if( id == SEG_CODE ) { curr = code_def_seg.pcseg; id = curr->seg_id; } else { curr = segIdLookup( id ); } if( curr == NULL ) { CFatal( "segment: cannot find default segment" ); } else { accumAlignment( curr, align ); if( ( ! SymIsInitialized( sym ) ) && SymIsExtern( sym ) ) { id = curr->seg_id; _markUsed( curr, TRUE ); curr->has_data = TRUE; data_def_seg.ds_used = TRUE; } else { aligned_offset = SegmentAdjust( curr->seg_id, curr->offset, align ); calc_offset = curr->offset + aligned_offset + size; _CHECK_ADJUST( calc_offset, calc_offset, curr->offset ); if( calc_offset == 0 ) { if( size != 0 ) { CErr( ERR_MAX_SEGMENT_EXCEEDED, curr->name, sym ); } id = SEG_NULL; } else if( curr->dgroup ) { total_size = dgroup_size + size + aligned_offset; _CHECK_ADJUST( calc_offset, total_size, dgroup_size ); if( calc_offset == 0 ) { if( size != 0 ) { CErr( ERR_MAX_DGROUP_EXCEEDED, sym, curr->name ); } id = SEG_NULL; } else { dgroup_size += size + aligned_offset; curr->offset = calc_offset; _markUsed( curr, TRUE ); curr->has_data = TRUE; id = curr->seg_id; data_def_seg.ds_used = TRUE; } } else { curr->offset = calc_offset; _markUsed( curr, TRUE ); curr->has_data = TRUE; id = curr->seg_id; data_def_seg.ds_used = TRUE; } } } return id; }