fe_seg_id SegmentFindNamed( // FIND SEGMENT ENTRY FOR NAME char* segname ) // - segment name { PC_SEGMENT *segmt; // - defined segment if( 0 == strcmp( segname, "_STACK" ) ) { return SEG_STACK; } if( 0 == strcmp( segname, "_CODE" ) ) { return SEG_CODE; } segmt = segNameLookup( segname ); if( segmt == NULL ) { if( isCodeSegmentName( segname ) ) { segmt = segmentDefine( segname , NULL , SEG_NULL , SGAT_CODE_BASED , SA_NULL ); } else { segmt = segmentDefine( segname , NULL , SEG_NULL , SGAT_DATA_BASED , SA_NULL ); } } _markUsed( segmt, TRUE ); return segmt->seg_id; }
static SYMBOL segDefineLabel( // DEFINE LABEL FOR SEGMENT, IF REQ'D PC_SEGMENT *seg ) // - current segment { SYMBOL label; // - reference symbol char *name; // - label's name SYMBOL func; // - function being compiled label = seg->label; if( label == NULL ) { func = ScopeFunctionInProgress(); if( ( func != NULL ) && ( func->segid == seg->seg_id ) ) { label = func; } } if( label == NULL ) { label = SymMakeDummy( GetBasicType( TYP_CHAR ), &name ); label->segid = seg->seg_id; if( label->segid == SEG_STACK ) { label->id = SC_AUTO; } else { label->id = SC_STATIC; InsertSymbol( GetFileScope(), label, name ); } seg->label = label; _markUsed( seg, TRUE ); } return label; }
static void initDefaultDataSeg( void ) { PC_SEGMENT *pcseg; SegmentData( NULL, NULL ); data_def_seg.ds_used = TRUE; // used for data externs pcseg = data_def_seg.pcseg; _markUsed( pcseg, TRUE ); }
static void initDefaultCodeSeg( char *code_seg_name ) { PC_SEGMENT *pcseg; SegmentCode( code_seg_name, NULL ); code_def_seg.ds_used = TRUE; pcseg = code_def_seg.pcseg; _markUsed( pcseg, TRUE ); seg_default_code = pcseg->seg_id; }
void SegmentMarkUsed( // MARK SEGMENT AS BEING USED fe_seg_id segid ) // - XI, YI segment id { PC_SEGMENT *seg; // - the segment if( segid != SEG_NULL ) { seg = segIdLookup( segid ); // extern segments are not SEG_NULL, but will not be found if( seg != NULL ) { _markUsed( seg, TRUE ); } } }
static void initP5TimingSegs( void ) { PC_SEGMENT *seg; PC_SEGMENT *sib; if( TargetSwitches & (P5_PROFILING|NEW_P5_PROFILING) ) { seg = segmentAllocRom( TS_SEG_TIB, SEG_PROF_BEG ); sib = segmentAllocRW( TS_SEG_TI, SEG_PROF_REF ); addSibling( seg, sib ); sib = segmentAllocRom( TS_SEG_TIE, SEG_PROF_END ); addSibling( seg, sib ); _markUsed( seg, TRUE ); } }
static PC_SEGMENT *addDefSeg( // ADD A DEFAULT PC SEGMENT DEF_SEG *def_seg, // - default segment info. unsigned ads_control ) // - control mask { unsigned attrs; // - attributes for segment PC_SEGMENT *curr; // - segment pointer VBUF seg_name; // - virtual buffer for name unsigned sa_control; // - segmentAlloc control mask VbufInit( &seg_name ); ++def_seg->ctr; sa_control = SA_NULL; if( ads_control & ADS_MODULE_PREFIX ) { if(( ads_control & ADS_CODE_SEGMENT ) == 0 && DataSegName[0] != '\0' ) { VbufConcStr( &seg_name, DataSegName ); } else { VbufConcStr( &seg_name, ModuleName ); } sa_control |= SA_MODULE_PREFIX; } if( ads_control & ADS_STRING_SEGMENT ) { sa_control |= SA_DEFINE_ANYTIME; } VbufConcStr( &seg_name, def_seg->pcseg->name ); if( ads_control & ADS_ZM_SEGMENT ) { VbufConcDecimal( &seg_name, def_seg->ctr ); } if( def_seg == &code_def_seg ) { attrs = SGAT_CODE_GEN; } else { if( ads_control & ADS_CONST_SEGMENT ) { attrs = SGAT_DATA_PRIVATE_RO; } else { attrs = SGAT_DATA_PRIVATE_RW; } VbufConcDecimal( &seg_name, def_seg->ctr ); } curr = segmentAlloc( VbufString( &seg_name ), NULL, SEG_NULL, attrs, sa_control ); if( 0 == ( attrs & EXEC ) ) { _markUsed( curr, TRUE ); } if( ads_control & ADS_STRING_SEGMENT ) { curr->only_strings = TRUE; } VbufFree( &seg_name ); return( curr ); }
static SYMBOL segEmitLabel( // EMIT SEGMENT LABEL PC_SEGMENT* seg ) // - current segment { SYMBOL label; // - label in segment label = seg->label; if( label != NULL && ! seg->lab_gened ) { if( seg->seg_id == SEG_STACK ) { CGAutoDecl( (cg_sym_handle)label, TY_UINT_1 ); } else { CgBackGenLabel( label ); } seg->lab_gened = TRUE; _markUsed( seg, TRUE ); } return label; }
void SegmentCodeCgInit( // TURN OFF USED BIT FOR ALL CODE SEGMENTS void ) { PC_SEGMENT *segment; // - current segment // reset any #pragma data_seg/code_seg changes back to defaults SegmentData( NULL, NULL ); SegmentCode( NULL, NULL ); RingIterBeg( seg_list, segment ) { if( ( segment->attrs & EXEC ) && ! segment->has_data ) { _markUsed( segment, FALSE ); } } RingIterEnd( segment ) // call out for non-call graph code segment uses DbgSuppSegRequest(); // used for default code segment externs SegmentMarkUsed( SEG_CODE ); }
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 ); }
static fe_seg_id createHugeSegment( target_size_t size, unsigned ads_control ) { PC_SEGMENT *curr; fe_seg_id id; target_size_t used; id = SEG_NULL; while( size > 0 ) { curr = addDefSeg( &data_def_seg, ads_control ); if( id == SEG_NULL ) { id = curr->seg_id; } used = min( size, TARGET_UINT_MAX+1 ); curr->offset = used; curr->align = 16; _markUsed( curr, TRUE ); curr->has_data = TRUE; size -= used; } return( 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; }