Esempio n. 1
0
void PrintExterns( externs sec_externs )
{
    int                 loop;
    ref_entry           entry;
    label_entry         prev_label = NULL;

    BufferMsg( EXTERNAL_REFS );
    BufferConcatNL();
    BufferConcatNL();
    BufferMsg( SYMBOL );
    BufferConcatNL();
    BufferConcat( "-------" );
    BufferPrint();
    for( loop = 0; loop < sec_externs->number; loop++ ) {
        entry = sec_externs->extern_refs[loop];
        if( prev_label != entry->label ) {
            BufferStore( "\n%s", entry->label->label.name );
            BufferAlignToTab( ADDRESSES_POS );
            BufferPrint();
            prev_label = entry->label;
        }
        BufferStore( "%04X ", entry->offset );
    }
    BufferPrint();
    Print( "\n\n" );
}
Esempio n. 2
0
	/** Get a GPU buffer for the input data. 
	 * Try to reuse existing memory if available.
	 * 
	 */
	BufferPtr get(DATA_PTR data)
	{
		// clear out deleted data
		for (typename BufferMap::iterator iter=mRemovedData.begin(); iter!=mRemovedData.end(); )
		{
			if (!iter->second.lock())
			{
				typename BufferMap::iterator temp = iter;
				++iter;
				mRemovedData.erase(temp);
			}
			else
			{
				++iter;
			}
		}

		// reclaim weak pointer to buffer if it exists.
		if (mRemovedData.count(data))
		{
			BufferPtr object = mRemovedData[data].lock();
			if (object)
			{
				mData.push_front(BufferStore(data, object));
				mRemovedData.erase(data);
			}
		}

		// move current data to front of buffer (i.e. increase importance)
		BufferPtr retval;
		for (typename std::list<BufferStore>::iterator iter=mData.begin(); iter!=mData.end(); ++iter)
		{
			if (iter->mData==data)
			{
				retval = iter->mBuffer; // retrieve data
				mData.push_front(*iter); // push on queue front (most recent)
				mData.erase(iter); // erase from old position
				break;
			}
		}

		// create buffer if nonexistent
		if (!retval)
		{
			retval = createGPUImageBuffer<BUFFER>(data);
			mData.push_front(BufferStore(data, retval));
		}

		// reduce repository size if too large.
		while (mData.size()>mMaxBuffers)
		{
			mRemovedData[mData.back().mData] = mData.back().mBuffer;
			mData.pop_back();;
		}

		return retval;
	}
Esempio n. 3
0
static label_entry handleLabels( char *sec_name, orl_sec_offset offset, orl_sec_offset end,
                             label_entry l_entry, orl_sec_size size )
// handle any labels at this offset and skip all unused non-label symbols
{
    bool    is32bit;

    is32bit = ( size >= 0x10000 );
    for( ; ( l_entry != NULL ) && ( l_entry->offset < end ); l_entry = l_entry->next ) {
        switch( l_entry->type ) {
        case LTYP_SECTION:
        case LTYP_NAMED:
            if( strcmp( l_entry->label.name, sec_name ) == 0 )
                continue;
            /* fall through */
        case LTYP_UNNAMED:
            if( l_entry->offset > offset )
                return( l_entry );
            break;
        case LTYP_ABSOLUTE:
        case LTYP_FUNC_INFO:
        default:
            continue;
        }
        switch( l_entry->type ) {
        case LTYP_NAMED:
            if( !( DFormat & DFF_ASM ) ) {
                if( offset != 0 && l_entry->binding == ORL_SYM_BINDING_GLOBAL ) {
                    routineSize = offset - routineBase;
                    BufferConcatNL();
                    BufferMsg( ROUTINE_SIZE );
                    BufferStore(" %d ", routineSize );
                    BufferMsg( BYTES );
                    BufferConcat(",    ");
                    BufferMsg( ROUTINE_BASE );
                    BufferStore(" %s + %04X\n\n", sec_name, routineBase );
                    routineBase = offset;
                }
            }
        case LTYP_SECTION:
            if( !( DFormat & DFF_ASM ) ) {
                PrintLinePrefixAddress( offset, is32bit );
                BufferAlignToTab( PREFIX_SIZE_TABS );
            }
            BufferStore( "%s:\n", l_entry->label.name );
            break;
        case LTYP_UNNAMED:
            if( !( DFormat & DFF_ASM ) ) {
                PrintLinePrefixAddress( offset, is32bit );
                BufferAlignToTab( PREFIX_SIZE_TABS );
            }
            BufferStore( "%c$%d:\n", LabelChar, l_entry->label.number );
            break;
        }
        BufferPrint();
    }
    return( l_entry );
}
Esempio n. 4
0
static return_val bssMasmASMSection( section_ptr section, dis_sec_size size, label_entry l_entry )
{
    size_t      offset = OFFSET_UNDEF;
    dis_value   value;

    PrintHeader( section );

    value.u._32[I64HI32] = 0;
    for( ; l_entry != NULL; l_entry = l_entry->next ) {
        if( l_entry->type != LTYP_SECTION ) {
            if( offset != l_entry->offset ) {
                BufferStore( "    ORG " );
                value.u._32[I64LO32] = l_entry->offset;
                BufferHex( 8, value );
                offset = l_entry->offset;
                BufferConcatNL();
                BufferPrint();
            }

            switch( l_entry->type ) {
            case LTYP_UNNAMED:
                BufferStore( "%c$%d", LabelChar, l_entry->label.number );
                break;
            case LTYP_SECTION:
            case LTYP_NAMED:
                BufferStore( "%s", l_entry->label.name );
                break;
            }

            BufferConcat( "    LABEL\tBYTE" );
            BufferConcatNL();
            BufferPrint();
        }
    }
    if( offset == OFFSET_UNDEF ) {
        if( size > 0 ) {
            BufferStore( "    ORG 0" );
            BufferConcatNL();
            BufferPrint();
        }
        offset = 0;
    }
    if( size > offset ) {
        BufferStore( "    ORG " );
        value.u._32[I64LO32] = size;
        BufferHex( 8, value );
        BufferConcatNL();
        BufferPrint();
    }

    PrintTail( section );

    BufferConcatNL();
    BufferPrint();

    return( RC_OKAY );
}
Esempio n. 5
0
unsigned HandleRefInData( ref_entry r_entry, void *data, bool asmLabels )
{
    unsigned            rv;
    const char          * const *types;
    char                buff[MAX_SYM_LEN];      // fixme: should be TS_MAX_OBJNAME or something
    dis_value           value;

    if( IsMasmOutput() ) {
        types = masmTypes;
    } else {
        types = unixTypes;
    }
    rv = RelocSize( r_entry );
    value.u._32[I64HI32] = 0;
    switch( rv ) {
    case 6:
        value.u._32[I64LO32] = *(unsigned_32 *)data;
        break;
    case 4:
        value.u._32[I64LO32] = *(unsigned_32 *)data;
        break;
    case 2:
        value.u._32[I64LO32] = *(unsigned_16 *)data;
        break;
    case 1:
        value.u._32[I64LO32] = *(unsigned_8 *)data;
        break;
    case 8:
        value.u._32[I64LO32] = 0;
        break;
    default:
        value.u._32[I64LO32] = 0;
        break;
    }
    if( asmLabels && types[rv] != NULL ) {
        BufferConcat( types[rv] );
    }
    HandleAReference( value, 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset, r_entry->offset + rv, &r_entry, buff );
    BufferConcat( buff );
    switch( rv ) {
    case 8:
        value.u._32[I64LO32] = *(unsigned_32 *)data;
        value.u._32[I64HI32] = *((unsigned_32 *)data + 1);
        if( value.u._32[I64LO32] != 0 || value.u._32[I64HI32] != 0 ) {
            BufferConcat( "+" );
            if( value.u._32[I64HI32] != 0 ) {
                BufferStore( "0x%x", value.u._32[I64HI32] );
                BufferStore( "%08x", value.u._32[I64LO32] );
            } else {
                BufferStore( "0x%x", value.u._32[I64LO32] );
            }
        }
        break;
    }
    return( rv );
}
Esempio n. 6
0
return_val      DumpASMGroupName( char *name, bool fasm )
{
    assert( name );

    useComma = 0;

    if( fasm ) {
        BufferQuoteName( name );
        BufferStore( "\t\tGROUP\t", name );
    } else {
        BufferStore( "GROUP: '%s' ", name );
    }
    return( RC_OKAY );
}
Esempio n. 7
0
static size_t tryDUP( unsigned_8 *bytes, size_t i, size_t size )
{
    size_t      d;
    size_t      dup;
    dis_value   value;


    if( i >= ( size - ( 8 * MIN_DUP_LINES ) ) )
        return( 0 );

    for( d = i + 8; d < ( size - 8 ); d += 8 ) {
        if( memcmp( &bytes[i], &bytes[d], 8 ) ) {
            return( 0 );
        }
    }

    d -= i;
    dup = d / 8;
    if( dup < MIN_DUP_LINES )
        return( 0 );

    BufferStore( "0%XH DUP(", dup );

    value.u._32[I64HI32] = 0;
    for( dup = 0; dup < 7; dup++ ) {
        value.u._32[I64LO32] = bytes[i + dup];
        BufferHex( 2, value );
        BufferConcat( "," );
    }
    value.u._32[I64LO32] = bytes[i + 7];
    BufferHex( 2, value );
    BufferConcat( ")" );
    return( d );
}
Esempio n. 8
0
static size_t tryDUP( unsigned_8 *bytes, size_t i, size_t size )
{
    size_t      d;
    size_t      dup;


    if( i >= ( size - ( 8 * MIN_DUP_LINES ) ) )
        return( 0 );

    for( d = i + 8; d < ( size - 8 ); d += 8 ) {
        if( memcmp( &bytes[i], &bytes[d], 8 ) ) {
            return( 0 );
        }
    }

    d -= i;
    dup = d / 8;
    if( dup < MIN_DUP_LINES )
        return( 0 );

    BufferStore( "0%XH DUP(", dup );

    for( dup = 0; dup < 7; dup++ ) {
        BufferHex( 2, bytes[i + dup] );
        BufferConcat( "," );
    }
    BufferHex( 2, bytes[i + 7] );
    BufferConcat( ")" );
    return( d );
}
Esempio n. 9
0
void PrintPublics( void ) {
    int                 loop;
    label_entry         entry;
    hash_data *         data_ptr;
    section_ptr         sec;

    // fixme:  data labels get a _ in front, others one after ??
    BufferMsg( LIST_OF_PUBLICS );
    BufferMsg( SYMBOL );
    BufferConcat("\t\t\t");
    BufferMsg( SECTION );
    BufferConcat("\t\t\t");
    BufferMsg( OFFSET );
    BufferConcatNL();
    BufferPrint();
    Print( "--------------------------------------------------------\n" );
    for( loop = 0; loop < Publics.number; loop++ ) {
        entry = Publics.public_symbols[loop];
        BufferConcat( entry->label.name );
        data_ptr = HashTableQuery( HandleToSectionTable, (hash_value) entry->shnd );
        // fixme: what is the proper behavour if no section found??
        if( data_ptr ) {
            sec = (section_ptr) *data_ptr;
            BufferAlignToTab( SECTION_TAB_POS );
            BufferConcat( sec->name );
        }
        BufferAlignToTab( ADDRESS_TAB_POS );
        BufferStore( "%08X\n", entry->offset );
        BufferPrint();
    }
}
Esempio n. 10
0
static size_t printString( char *string, string_type type )
{
    char        *buffer;
    size_t      i, j;

    buffer = MemAlloc( strlen( string ) * 2 + 1 );
    for( i = 0, j = 0; i < strlen( string ); i++ ) {
        switch( string[i] ){
            case '\n':
                buffer[j++] = '\\';
                buffer[j++] = 'n';
                break;
            case '\r':
                buffer[j++] = '\\';
                buffer[j++] = 'r';
                break;
            case '\t':
                buffer[j++] = '\\';
                buffer[j++] = 't';
                break;
            case '\f':
                buffer[j++] = '\\';
                buffer[j++] = 'f';
                break;
            case '\\':
                buffer[j++] = '\\';
                buffer[j++] = '\\';
                break;
            case '\"':
                buffer[j++] = QuoteChar;
                buffer[j++] = '\"';
                break;
            case '\'':
                buffer[j++] = '\\';
                buffer[j++] = '\'';
                break;
            default:
                buffer[j++] = string[i];
                break;
        }
    }
    buffer[j] = 0;

    BufferStore( "\"%s\"", buffer );
    BufferPrint();
    MemFree( buffer );
    switch( type ) {
        case ASCII:
            return( strlen( string ) );
        case ASCIZ:
            return( strlen( string ) + 1 );
    }
    // shouldn't get here, but compiler complains.
    return( 0 );
}
Esempio n. 11
0
static void printRawAndAddress( const char *raw_data, dis_sec_offset address )
{
    switch( strlen( raw_data ) ) {
    case 0:
        BufferStore( "      00     %04X", address );
        break;
    case 1:
        BufferStore( "    00%02X     %04X", raw_data[0], address );
        break;
    case 2:
        BufferStore( "  00%02X%02X     %04X", raw_data[1], raw_data[0], address );
        break;
    case 3:
        BufferStore( "00%02X%02X%02X     %04X", raw_data[2], raw_data[1], raw_data[0], address );
        break;
    default:
        BufferStore( "%02X%02X%02X%02X     %04X", raw_data[3], raw_data[2], raw_data[1], raw_data[0], address );
        break;
    }
}
Esempio n. 12
0
static void doDescriptorRelocs( ref_entry *r_entry, orl_sec_offset offset, uint_32 address )
{
    /* Skip over pair relocs */
    while( (*r_entry) && ((*r_entry)->type == ORL_RELOC_TYPE_PAIR || (*r_entry)->offset < offset ) ) {
        (*r_entry) = (*r_entry)->next;
    }
    if( (*r_entry) && (*r_entry)->offset == offset ) {
        HandleRefInData( *r_entry, &address, FALSE );
        (*r_entry) = (*r_entry)->next;
    } else {
        BufferStore("%08X", address );
    }
}
Esempio n. 13
0
return_val DumpPDataSection( section_ptr sec, unsigned_8 *contents,
                        orl_sec_size size, unsigned pass )
{
    orl_sec_offset      loop;
    hash_data *         data_ptr;
    ref_list            r_list;
    ref_entry           r_entry;
    descriptor_struct   descriptor;
    bool                is32bit;

    if( pass == 1 ) return( OKAY );
    if( size == 0 ) return( OKAY );

    is32bit = ( size >= 0x10000 );

    data_ptr = HashTableQuery( HandleToRefListTable, (hash_value)sec->shnd );
    if( *data_ptr ) {
        r_list = (ref_list)*data_ptr;
        if( r_list ) {
            r_entry = r_list->first;
        } else {
            r_entry = NULL;
        }
    }
    BufferConcatNL();
    PrintHeader( sec );
    BufferConcatNL();
    for( loop = 0; loop < size; loop += sizeof( descriptor_struct ) ) {
        if( r_entry == NULL ) break;
        memcpy( &descriptor, contents + loop, sizeof( descriptor_struct ) );
        if( DFormat & DFF_ASM ) {
            BufferStore( "\t\t" );
            BufferStore( "%s %04X\t\t", CommentString, loop );
        } else {
            PrintLinePrefixAddress( loop, is32bit );
            BufferAlignToTab( PREFIX_SIZE_TABS );
            BufferStore( "%s ", CommentString );
        }
        BufferMsg( PROCEDURE_DESCRIPTOR );

        /* Skip over pair relocs */
        while( r_entry && (r_entry->type == ORL_RELOC_TYPE_PAIR || r_entry->offset < loop) ) {
            r_entry = r_entry->next;
        }
        switch( r_entry->label->type ) {
        case LTYP_EXTERNAL_NAMED:
            BufferStore( "%s", r_entry->label->label.name );
            break;
        case LTYP_NAMED:
        case LTYP_SECTION:
        case LTYP_GROUP:
            BufferStore( "%s", r_entry->label->label.name );
            break;
        default:
            BufferStore( "%c$%d", LabelChar, r_entry->label->label.number );
            break;
        }
        BufferConcatNL();
        printDescriptor( loop, &descriptor, &r_entry );
    }
    return( OKAY );
}
Esempio n. 14
0
void HandleArgs( char *cmd )
{
    char *                      ptr;
    bool                        list_file = FALSE;

    DFormat |= DFF_PSEUDO | DFF_SYMBOLIC_REG;
    cmd = skipBlanks( cmd );
    if( *cmd == '\0' || *cmd == '?' ) {
        printUsage( 0 );
    } else {
        while( *cmd ) {
            if( IS_OPT_DELIM( *cmd ) ) {
                cmd++;
                switch( tolower( *cmd ) ) {
                    case 'a':
                        DFormat |= DFF_ASM;
                        if( cmd[1] == 'u' ) {
                            ++cmd;
                            DFormat |= DFF_X86_UNIX;
                        }
                        break;
                    case 'e':
                        Options |= PRINT_EXTERNS;
                        break;
                    case 'i':
                        cmd++;
                        if( *cmd == '=' ) {
                            cmd++;
                            if( !isspace( *cmd ) ) {
                                LabelChar = toupper( *cmd );
                            } else {
                                printUsage( INVALID_I );
                            }
                        } else {
                            printUsage( INVALID_I );
                        }
                        break;
                    case 'l':
                        if( ListFileName ) {
                            printUsage( ONLY_ONE_LISTING );
                        }
                        list_file = TRUE;
                        cmd++;
                        if( *cmd == '=' ) {
                            cmd++;
                            ptr = cmd;
                            cmd = FindNextWS( cmd );
                            ListFileName = getFileName( ptr, cmd );
                        }
                        break;
                    case 'f':
                        switch( cmd[1] ) {
                        case 'p':
                            DFormat ^= DFF_PSEUDO;
                            ++cmd;
                            break;
                        case 'r':
                            DFormat ^= DFF_SYMBOLIC_REG;
                            ++cmd;
                            break;
                        case 'f':
                            Options |= PRINT_FPU_EMU_FIXUP;
                            break;
                        case 'i':
                            DFormat ^= DFF_X86_ALT_INDEXING;
                            ++cmd;
                            break;
                        case 'u':
                            ++cmd;
                            switch( cmd[1] ) {
                            case 'r':
                                DFormat ^= DFF_REG_UP;
                                ++cmd;
                                break;
                            case 'i':
                                DFormat ^= DFF_INS_UP;
                                ++cmd;
                                break;
                            default:
                                DFormat ^= DFF_INS_UP | DFF_REG_UP;
                            }
                            break;
                        }
                        break;
                    case 'm':
                        if( cmd[1] == 'w' ) {
                            Options |= METAWARE_COMPATIBLE;
                            ++cmd;
                            break;
                        }
                        Options |= NODEMANGLE_NAMES;
                        break;
                    case 'p':
                        Options |= PRINT_PUBLICS;
                        break;
                    case 's':
                        if( SourceFileName ) {
                            printUsage( ONLY_ONE_SOURCE );
                        }
                        source_mix = TRUE;
                        cmd++;
                        if( *cmd == '=' ) {
                            cmd++;
                            ptr = cmd;
                            cmd = FindNextWS( cmd );
                            SourceFileName = getFileName( ptr, cmd );
                        }
                        break;
                    default:
                        BufferMsg( INVALID_OPTION );
                        BufferStore( "  -%c\n\n", *cmd );
                        BufferPrint();
                        printUsage( 0 );
                        break;
                }
            } else {
                if( ObjFileName ) {
                    printUsage( ONLY_ONE_OBJECT );
                }
                ptr = cmd;
                cmd = FindNextWS( cmd );
                ObjFileName = getFileName( ptr, cmd );
            }
            cmd = skipToNextArg( cmd );
        }
    }
    if( !ObjFileName ) {
        printUsage( NO_OBJECT );
    }
    composeFileNames( list_file );
    if( DFormat & DFF_ASM ) {
        Options &= ~(PRINT_PUBLICS | PRINT_EXTERNS);
    }
}
Esempio n. 15
0
static return_val bssUnixASMSection( section_ptr sec, orl_sec_size size,
                                     label_entry l_entry )
{
    orl_sec_offset              dsiz = 0;
    char                        *prefix;
    label_entry                 prev_entry;

    if( ( size == 0 ) && ( l_entry == NULL ) )
        return( RC_OKAY );

    PrintHeader( sec );
    prev_entry = NULL;
    for( ; l_entry != NULL; l_entry = l_entry->next ) {
        if( ( l_entry->type == LTYP_SECTION ) && ( strcmp( l_entry->label.name, sec->name ) == 0 ) ) {
            continue;
        } else if( prev_entry == NULL ) {
            prev_entry = l_entry;
            continue;
        } else if( prev_entry->offset > l_entry->offset ) {
            continue;
        } else if( prev_entry->offset == l_entry->offset ) {
            dsiz = 0;
            prefix = "";
        } else {
            dsiz = l_entry->offset - prev_entry->offset;
            prefix = "    .lcomm\t";
        }
        switch( prev_entry->type ) {
        case LTYP_UNNAMED:
            BufferStore( "%s%c$%d", prefix, LabelChar, prev_entry->label.number );
            break;
        case LTYP_SECTION:
        case LTYP_NAMED:
            BufferStore( "%s%s", prefix, prev_entry->label.name );
            break;
        default:
            break;
        }
        if( dsiz ) {
            BufferStore( ", 0x%08x", dsiz );
        } else {
            BufferConcat( ":" );
        }
        BufferConcatNL();
        BufferPrint();
        prev_entry = l_entry;
    }
    if( prev_entry != NULL ) {
        if( prev_entry->offset < size ) {
            dsiz = size - prev_entry->offset;
            prefix = "    .lcomm\t";
        } else {
            dsiz = 0;
            prefix = "";
        }
        switch( prev_entry->type ) {
        case LTYP_UNNAMED:
            BufferStore( "%s%c$%d", prefix, LabelChar, prev_entry->label.number );
            break;
        case LTYP_SECTION:
        case LTYP_NAMED:
            BufferStore( "%s%s", prefix, prev_entry->label.name );
            break;
        default:
            break;
        }
        if( dsiz ) {
            BufferStore( ", 0x%08x", dsiz );
        } else {
            BufferConcat( ":" );
        }
        BufferConcatNL();
        BufferPrint();
    }
    BufferConcatNL();
    BufferPrint();

    return( RC_OKAY );
}
Esempio n. 16
0
static label_entry dumpAsmLabel( label_entry l_entry, section_ptr sec,
                                 orl_sec_offset curr_pos, orl_sec_offset end,
                                 unsigned_8 *contents, char *buffer )
{
    int         raw;
    int         is_masm;

    end = end;

    raw = buffer && contents;

    is_masm = IsMasmOutput();

    while( l_entry != NULL
        && ( l_entry->type == LTYP_ABSOLUTE || l_entry->offset <= curr_pos ) ) {
        switch( l_entry->type ) {
        case( LTYP_ABSOLUTE ):
            // no print any absolute label here
            break;
        case( LTYP_SECTION ):
            if( is_masm )
                break;
            /* fall through */
        case( LTYP_NAMED ):
            if( strcmp( l_entry->label.name, sec->name ) == 0 )
                break;
            /* fall through */
        case( LTYP_UNNAMED ):

            if( raw ) {
                strncpy( buffer, (char *)contents + curr_pos, sizeof( unsigned_32 ) );
            }
            if( l_entry->type == LTYP_UNNAMED ) {
                if( !(DFormat & DFF_ASM) ) {
                    BufferStore( "\t     %04X\t%c$%d:", LabelChar, curr_pos,
                                 l_entry->label.number );
                    if( raw ) {
                        printRawAndAddress( buffer, curr_pos );
                    }
                } else {
                    if( l_entry->offset != curr_pos ) {
                        BufferStore( "%c$%d equ $-%d", LabelChar, l_entry->label.number, (int)( curr_pos - l_entry->offset ) );
                    } else {
                        BufferStore( "%c$%d:", LabelChar, l_entry->label.number );
                    }
                }
            } else {
                if( !(DFormat & DFF_ASM) ) {
                    BufferStore( "\t     %04X\t%s:", curr_pos,
                                 l_entry->label.name );
                    if( raw ) {
                        printRawAndAddress( buffer, curr_pos );
                    }
                } else {
                    if( l_entry->offset != curr_pos ) {
                        BufferStore( "%s equ $-%d", l_entry->label.name, (int)( curr_pos - l_entry->offset ) );
                    } else {
                        BufferStore( "%s:", l_entry->label.name );
                    }
                }
            }
            BufferConcatNL();
            BufferPrint();
        }
        l_entry = l_entry->next;
    }
    return( l_entry );
}
Esempio n. 17
0
orl_sec_offset HandleRefInData( ref_entry r_entry, void *data, bool asmLabels )
{
    orl_sec_offset      rv;
    const char          * const *types;
    char                buff[MAX_SYM_LEN];      // fixme: should be TS_MAX_OBJNAME or something

    if( IsMasmOutput() ) {
        types = masmTypes;
    } else {
        types = unixTypes;
    }

    rv = RelocSize( r_entry );
    switch( rv ) {
    case 6:
        if( asmLabels && types[rv] ) {
            BufferConcat( types[rv] );
        }
        HandleAReference(*((unsigned_32 *)data), 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                         r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        break;
    case 4:
        if( asmLabels ) {
            BufferConcat( types[rv] );
        }
        HandleAReference(*((unsigned_32 *)data), 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                         r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        break;
    case 2:
        if( asmLabels ) {
            BufferConcat( types[rv] );
        }
        HandleAReference(*((unsigned_16 *)data), 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                         r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        break;
    case 1:
        if( asmLabels ) {
            BufferConcat( types[rv] );
        }
        HandleAReference(*((unsigned_8 *)data), 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                         r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        break;
    case 8:
        if( asmLabels ) {
            BufferConcat( types[rv] );
        }
        HandleAReference( 0, 0, RFLAG_DEFAULT | RFLAG_IS_IMMED, r_entry->offset,
                          r_entry->offset + rv, &r_entry, buff );
        BufferConcat( buff );
        if( *((long *)data)!=0 || *((long *)data+4)!=0 ) {
            BufferConcat("+");
            if( *((long *)data+4)!=0 ) {
                BufferStore("0x%x", *((long *)data+4) );
                BufferStore("%08x", *((long *)data) );
            } else {
                BufferStore("0x%x", *((long *)data) );
            }
        }
        break;
    }
    return( rv );
}
Esempio n. 18
0
static void printDescriptor( orl_sec_offset offset,
                             descriptor_struct *descriptor, ref_entry *r_entry )
{
    char *PreString;

    if( DFormat & DFF_ASM ) {
        PreString = "\t\t.long\t";
    } else {
        PreString = "\t";
    }
    BufferStore("%s", PreString );
    doDescriptorRelocs( r_entry, offset, descriptor->begin_address );
    BufferAlignToTab(6);
    BufferStore("%s ", CommentString );
    BufferMsg( BEGIN_ADDRESS );
    BufferStore(": %d\n", descriptor->begin_address );

    BufferStore("%s", PreString );
    doDescriptorRelocs( r_entry, offset+4, descriptor->end_address );
    BufferAlignToTab(6);
    BufferStore("%s ", CommentString );
    BufferMsg( END_ADDRESS );
    BufferStore(": %d\n", descriptor->end_address );

    BufferPrint();

    BufferStore("%s", PreString );
    doDescriptorRelocs( r_entry, offset+8, descriptor->exception_handler );
    BufferAlignToTab(6);
    BufferStore("%s ", CommentString );
    BufferMsg( EXCEPTION_HANDLER );
    BufferStore(": %d\n", descriptor->exception_handler );

    BufferStore("%s", PreString );
    doDescriptorRelocs( r_entry, offset+12, descriptor->handler_data );
    BufferAlignToTab(6);
    BufferStore("%s ", CommentString );
    BufferMsg( HANDLER_DATA );
    BufferStore(": %d\n", descriptor->handler_data );

    BufferStore("%s", PreString );
    doDescriptorRelocs( r_entry, offset+16, descriptor->prolog_end );
    BufferAlignToTab(6);
    BufferStore("%s ", CommentString );
    BufferMsg( PROLOG_END );
    BufferStore(": %d\n\n", descriptor->prolog_end );

    BufferPrint();
}
Esempio n. 19
0
static void printUnixHeader( section_ptr sec )
{
    orl_sec_alignment   alignment;
    orl_sec_flags       flags;
    orl_sec_type        type;
    char                attributes[10];
    char *              ca;

    alignment = ORLSecGetAlignment( sec->shnd );
    type = ORLSecGetType( sec->shnd );
    flags = ORLSecGetFlags( sec->shnd );

    ca = attributes;
    if( !(Options & METAWARE_COMPATIBLE) ) {
        if( (flags & ORL_SEC_FLAG_EXEC) || sec->type == SECTION_TYPE_TEXT ) {
            *ca++ = 'c';
        }
        if( (flags & ORL_SEC_FLAG_INITIALIZED_DATA) || sec->type == SECTION_TYPE_DATA || sec->type == SECTION_TYPE_PDATA ) {
            *ca++ = 'd';
        }
        if( (flags & ORL_SEC_FLAG_UNINITIALIZED_DATA) || sec->type == SECTION_TYPE_BSS ) {
            *ca++ = 'u';
        }
        if( (type == ORL_SEC_TYPE_NOTE) || sec->type == SECTION_TYPE_DRECTVE ) {
            *ca++ = 'i';
        }
        if( flags & ORL_SEC_FLAG_DISCARDABLE ) {
            *ca++ = 'n';
        }
        if( flags & ORL_SEC_FLAG_REMOVE ) {
            *ca++ = 'R';
        }
        if( flags & ORL_SEC_FLAG_READ_PERMISSION ) {
            *ca++ = 'r';
        }
        if( flags & ORL_SEC_FLAG_WRITE_PERMISSION ) {
            *ca++ = 'w';
        }
        if( flags & ORL_SEC_FLAG_EXECUTE_PERMISSION ) {
            *ca++ = 'x';
        }
        if( flags & ORL_SEC_FLAG_SHARED ) {
            *ca++ = 's';
        }
        *ca++ = '0' + alignment;
        *ca = '\0';

        if( !( DFormat & DFF_ASM ) ){
            BufferConcat("\t\t\t\t");
        }
        BufferStore(".new_section %s, \"%s\"", sec->name, attributes );
    } else {
        if( !(flags & ORL_SEC_FLAG_REMOVE ) ) {
            *ca++ = 'a';
        }
        if( flags & ORL_SEC_FLAG_EXEC ) {
            *ca++ = 'x';
        }
        if( flags & ORL_SEC_FLAG_WRITE_PERMISSION ) {
            *ca++ = 'w';
        }
        *ca++ = '\0';
        if( !( DFormat & DFF_ASM ) ) {
            BufferConcat("\t\t\t\t");
        }
        BufferStore(".section %s, \"%s\"", sec->name, attributes );
        BufferConcatNL();
        if( !( DFormat & DFF_ASM ) ) {
            BufferConcat("\t\t\t\t");
        }
        BufferStore(".align %d", (int)alignment );
    }

    BufferConcatNL();
    BufferPrint();
}
Esempio n. 20
0
static label_entry dumpAsmLabel( label_entry l_entry, section_ptr section,
                                 dis_sec_offset curr_pos, dis_sec_offset end,
                                 unsigned_8 *contents, char *buffer )
{
    bool        raw;
    bool        is_masm;

    /* unused parameters */ (void)end;

    raw = ( buffer != NULL && contents != NULL );

    is_masm = IsMasmOutput();

    for( ; l_entry != NULL && ( l_entry->type == LTYP_ABSOLUTE || l_entry->offset <= curr_pos ); l_entry = l_entry->next ) {
        switch( l_entry->type ) {
        case LTYP_ABSOLUTE:
            // no print any absolute label here
            break;
        case LTYP_SECTION:
            if( is_masm )
                break;
            /* fall through */
        case LTYP_NAMED:
            if( strcmp( l_entry->label.name, section->name ) == 0 )
                break;
            /* fall through */
        case LTYP_UNNAMED:
            if( raw ) {
                strncpy( buffer, (char *)contents + curr_pos, sizeof( unsigned_32 ) );
            }
            if( l_entry->type == LTYP_UNNAMED ) {
                if( (DFormat & DFF_ASM) == 0 ) {
                    BufferStore( "\t     %04X\t%c$%d:", LabelChar, curr_pos, l_entry->label.number );
                    if( raw ) {
                        printRawAndAddress( buffer, curr_pos );
                    }
                } else {
                    if( l_entry->offset != curr_pos ) {
                        BufferStore( "%c$%d equ $-%d", LabelChar, l_entry->label.number, (int)( curr_pos - l_entry->offset ) );
                    } else {
                        BufferStore( "%c$%d:", LabelChar, l_entry->label.number );
                    }
                }
            } else {
                if( (DFormat & DFF_ASM) == 0 ) {
                    BufferStore( "\t     %04X\t%s:", curr_pos, l_entry->label.name );
                    if( raw ) {
                        printRawAndAddress( buffer, curr_pos );
                    }
                } else {
                    if( l_entry->offset != curr_pos ) {
                        BufferStore( "%s equ $-%d", l_entry->label.name, (int)( curr_pos - l_entry->offset ) );
                    } else {
                        BufferStore( "%s:", l_entry->label.name );
                    }
                }
            }
            BufferConcatNL();
            BufferPrint();
        }
    }
    return( l_entry );
}
Esempio n. 21
0
size_t HandleAReference( dis_value value, int ins_size, ref_flags flags,
                           orl_sec_offset offset, orl_sec_size sec_size,
                           ref_entry * r_entry, char *buff )
// handle any references at this offset
{
    return_val          error;
    dis_value           nvalue;
    char                *p;

    buff[0] = '\0';
    for( ; *r_entry && (*r_entry)->offset == offset; *r_entry = (*r_entry)->next ) {
        if( (*r_entry)->no_val == 0 ) {
            nvalue = value;
        } else if( (*r_entry)->addend ) {
            nvalue = HandleAddend( *r_entry );
        } else {
            nvalue = 0;
        }
        switch( (*r_entry)->type ) {
        case ORL_RELOC_TYPE_MAX + 1:
        case ORL_RELOC_TYPE_JUMP:
        case ORL_RELOC_TYPE_REL_21_SH:
        case ORL_RELOC_TYPE_WORD_26:
            error = referenceString( *r_entry, sec_size, "j^", "", "",
                                     buff, flags );
            if( error != RC_OKAY ) {
                // label is defined to be beyond the boundaries of the section!
                if( !(DFormat & DFF_ASM) ){
                    BufferStore("\t     %04X", offset );
                    BufferAlignToTab( COMMENT_TAB_POS );
                } else {
                    BufferConcat("\t" );
                }
                BufferConcat( CommentString );
                BufferMsg( LABEL_BEYOND_SECTION );
                BufferConcatNL();
                BufferPrint();
                *r_entry = (*r_entry)->next;
                return( 0 );
            }
            continue; // Don't print addend
            break;
        case ORL_RELOC_TYPE_SEC_REL:
            referenceString( *r_entry, sec_size, "s^", "s^", "@s", buff,
                             flags );
            break;
        case ORL_RELOC_TYPE_HALF_HI:
            referenceString( *r_entry, sec_size, "h^", "h^", "@h", buff,
                             flags );
            break;
        case ORL_RELOC_TYPE_HALF_HA:
            referenceString( *r_entry, sec_size, "ha^", "ha^", "@ha", buff,
                             flags );
            break;
        case ORL_RELOC_TYPE_HALF_LO:
            referenceString( *r_entry, sec_size, "l^", "l^", "@l", buff,
                             flags );
            break;
        case ORL_RELOC_TYPE_REL_14:
        case ORL_RELOC_TYPE_REL_24:
        case ORL_RELOC_TYPE_WORD_14:
        case ORL_RELOC_TYPE_WORD_24:
            nvalue &= ~0x3;
        case ORL_RELOC_TYPE_WORD_16:
        case ORL_RELOC_TYPE_WORD_32:
        case ORL_RELOC_TYPE_WORD_64:
            if( ( (*r_entry)->label->type != LTYP_GROUP ) &&
              ( flags & RFLAG_IS_IMMED ) && IsMasmOutput() ) {
                referenceString( *r_entry, sec_size, "offset ", "offset ",
                                 "", buff, flags );
            } else {
                referenceString( *r_entry, sec_size, "", "", "", buff,
                                 flags );
            }
            break;
        case ORL_RELOC_TYPE_REL_16:
            if( IsIntelx86() && !(*r_entry)->no_val ) {
                nvalue -= ins_size;
            }
            if( ( (*r_entry)->label->type != LTYP_GROUP ) &&
              ( flags & RFLAG_IS_IMMED ) && IsMasmOutput() ) {
                referenceString( *r_entry, sec_size, "offset ", "offset ",
                                 "", buff, flags );
            } else {
                referenceString( *r_entry, sec_size, "", "", "", buff,
                                 flags  );
            }
            break;
        case ORL_RELOC_TYPE_WORD_8:
        case ORL_RELOC_TYPE_WORD_16_SEG:
        case ORL_RELOC_TYPE_WORD_HI_8:
        case ORL_RELOC_TYPE_WORD_32_SEG:
            // Keep these seperate because they are OMF specific
            referenceString( *r_entry, sec_size, "", "", "", buff, flags );
            break;
        case ORL_RELOC_TYPE_SEGMENT:
            if( ( (*r_entry)->label->type != LTYP_GROUP )
                && ( (*r_entry)->label->type != LTYP_SECTION )
                && ( flags & RFLAG_IS_IMMED )
                && IsMasmOutput() ) {
                referenceString( *r_entry, sec_size, "seg ", "seg ", "",
                                 buff, flags );
            } else {
                referenceString( *r_entry, sec_size, "", "", "", buff,
                                 flags );
            }
            break;

        case ORL_RELOC_TYPE_REL_32_NOADJ:
            // this is a little kluge because Brian's ELF files seem to have
            // -4 in the implicit addend for calls and such BBB May 09, 1997
            nvalue += 4;
            // fall through
        case ORL_RELOC_TYPE_REL_8:
        case ORL_RELOC_TYPE_REL_16_SEG:
        case ORL_RELOC_TYPE_REL_HI_8:
        case ORL_RELOC_TYPE_REL_32_SEG:
        case ORL_RELOC_TYPE_REL_32:
        case ORL_RELOC_TYPE_REL_32_ADJ5:
        case ORL_RELOC_TYPE_REL_32_ADJ4:
        case ORL_RELOC_TYPE_REL_32_ADJ3:
        case ORL_RELOC_TYPE_REL_32_ADJ2:
        case ORL_RELOC_TYPE_REL_32_ADJ1:
            // For some reason we add the instruction size to the value
            // of the displacement in a relative call and get a bad
            // offset, due to CORE implementation
            //
            // Main reason :
            // instruction size with displacement and with addend is correct for
            // relative addresses without relocate
            //
            // in amd64 code the instruction size will be added in pass1.c!
            if( (*r_entry)->no_val == 0 && !( GetMachineType() == ORL_MACHINE_TYPE_AMD64 ) ) {
                nvalue -= ins_size;
            }
            referenceString( *r_entry, sec_size, "", "", "", buff, flags );
            break;
        case ORL_RELOC_TYPE_TOCREL_14:
            nvalue &= ~0x3;
        case ORL_RELOC_TYPE_TOCREL_16:
            referenceString( *r_entry, sec_size, "[toc]", "[toc]", "@toc",
                             buff, flags );
            break;
        case ORL_RELOC_TYPE_TOCVREL_14:
            nvalue &= ~0x3;
        case ORL_RELOC_TYPE_TOCVREL_16:
            referenceString( *r_entry, sec_size, "[tocv]", "[tocv]", "@tocv",
                             buff, flags );
            break;
        case ORL_RELOC_TYPE_GOT_16:
            referenceString( *r_entry, sec_size, "", "", "@got", buff, flags );
            break;
        case ORL_RELOC_TYPE_GOT_16_HI:
            referenceString( *r_entry, sec_size, "", "", "@got@h", buff, flags );
            break;
        case ORL_RELOC_TYPE_GOT_16_HA:
            referenceString( *r_entry, sec_size, "", "", "@got@ha", buff, flags );
            break;
        case ORL_RELOC_TYPE_GOT_16_LO:
            referenceString( *r_entry, sec_size, "", "", "@got@l", buff, flags );
            break;
        case ORL_RELOC_TYPE_PLTREL_24:
        case ORL_RELOC_TYPE_PLTREL_32:
        case ORL_RELOC_TYPE_PLT_32:
            referenceString( *r_entry, sec_size, "", "", "@plt", buff, flags );
            break;
        case ORL_RELOC_TYPE_PLT_16_HI:
            referenceString( *r_entry, sec_size, "", "", "@plt@h", buff, flags );
            break;
        case ORL_RELOC_TYPE_PLT_16_HA:
            referenceString( *r_entry, sec_size, "", "", "@plt@ha", buff, flags );
            break;
        case ORL_RELOC_TYPE_PLT_16_LO:
            referenceString( *r_entry, sec_size, "", "", "@plt@l", buff, flags );
            break;
        default:
            continue;
        }
        // LTYP_UNNAMED labels are always at the correct location
        // if( nvalue != 0 && (*r_entry)->label->type != LTYP_UNNAMED ) {
        // not so - BBB Oct 28, 1996
        if(( (*r_entry)->no_val == 0 ) && ( nvalue != 0 )) {
            p = &buff[strlen(buff)];
            if( nvalue < 0 ) {
                *p++ = '-';
                nvalue = -nvalue;
            } else {
                *p++ = '+';
            }
            FmtHexNum( p, 0, nvalue, FALSE );
        }
    }
    return( strlen( buff ) );
}
Esempio n. 22
0
num_errors DoPass2( section_ptr sec, unsigned_8 *contents, orl_sec_size size,
                    label_list sec_label_list, ref_list sec_ref_list )
// perform pass 2 on one section
{
    struct pass2        data;
    label_entry         l_entry;
    dis_dec_ins         decoded;
    char                name[ MAX_INS_NAME ];
    char                ops[ MAX_OBJ_NAME + 24 ];       // at most 1 label/relocation per instruction, plus room for registers, brackets and other crap
    dis_inst_flags      flags;
    scantab_ptr         st;
    int                 is_intel;
    sa_disasm_struct    sds;
    char                *FPU_fixup;
    int                 pos_tabs;
    bool                is32bit;

    routineBase = 0;
    st = sec->scan;
    data.size = size;
    sds.data = contents;
    sds.last = size - 1;
    l_entry = NULL;
    if( sec_label_list != NULL ) {
        l_entry = sec_label_list->first;
    }
    if( sec_ref_list != NULL ) {
        data.r_entry = sec_ref_list->first;
    } else {
        data.r_entry = NULL;
    }
    data.disassembly_errors = 0;

    if( source_mix ) {
        GetSourceFile( sec );
    }

    PrintHeader( sec );
    if( size && sec_label_list )
        PrintAssumeHeader( sec );
    flags.u.all = DIF_NONE;
    if( GetMachineType() == ORL_MACHINE_TYPE_I386 ) {
        if( ( GetFormat() != ORL_OMF ) ||
            ( ORLSecGetFlags( sec->shnd ) & ORL_SEC_FLAG_USE_32 ) ) {
            flags.u.x86 = DIF_X86_USE32_FLAGS;
        }
        is_intel = 1;
    } else {
        is_intel = IsIntelx86();
    }
    is32bit = ( size >= 0x10000 );
    for( data.loop = 0; data.loop < size; data.loop += decoded.size ) {

        // process data in code segment
        while( st && ( data.loop > st->end ) ) {
            st = st->next;
        }
        if( st && ( data.loop >= st->start ) ) {
            decoded.size = 0;
            processDataInCode( sec, contents, &data, st->end - data.loop, &l_entry );
            st = st->next;
            continue;
        }
        // data may not be listed in scan table, but a fixup at this offset will
        // give it away
        while( data.r_entry && ( data.r_entry->offset < data.loop ) ) {
            data.r_entry = data.r_entry->next;
        }
        FPU_fixup = processFpuEmulatorFixup( &data.r_entry, data.loop );
        if( data.r_entry && ( data.r_entry->offset == data.loop ) ) {
            if( is_intel || IsDataReloc( data.r_entry ) ) {
                // we just skip the data
                decoded.size = 0;
                processDataInCode( sec, contents, &data, RelocSize( data.r_entry ), &l_entry );
                continue;
            }
        }

        if( source_mix ) {
            MixSource( data.loop );
        }
        DisDecodeInit( &DHnd, &decoded );
        decoded.flags.u.all |= flags.u.all;
        sds.offs = data.loop;
        DisDecode( &DHnd, &sds, &decoded );
        if( sec_label_list ) {
            l_entry = handleLabels( sec->name, data.loop, data.loop + decoded.size, l_entry, size );
            if( ( l_entry != NULL )
                && ( l_entry->offset > data.loop )
                && ( l_entry->offset < data.loop + decoded.size ) ) {
                /*
                    If we have a label planted in the middle of this
                    instruction (see inline memchr for example), put
                    out a couple of data bytes, and then restart decode
                    and label process from offset of actual label.
                */
                decoded.size = 0;
                processDataInCode( sec, contents, &data, l_entry->offset - data.loop, &l_entry );
                continue;
            }
        }
        DisFormat( &DHnd, &data, &decoded, DFormat, name, sizeof( name ), ops, sizeof( ops ) );
        if( FPU_fixup != NULL ) {
            if( !(DFormat & DFF_ASM) ) {
                BufferAlignToTab( PREFIX_SIZE_TABS );
            }
            BufferStore( "\t%sFPU fixup %s\n", CommentString, FPU_fixup );
        }
        if( !(DFormat & DFF_ASM) ) {
            unsigned_64     *tmp_64;
            unsigned_32     *tmp_32;
            unsigned_16     *tmp_16;

            tmp_64 = (unsigned_64 *)(contents + data.loop);
            tmp_32 = (unsigned_32 *)(contents + data.loop);
            tmp_16 = (unsigned_16 *)(contents + data.loop);
            if( DHnd.need_bswap ) {
                switch( DisInsSizeInc( &DHnd ) ) {
                //case 8: SWAP_64( *tmp_64 );
                //    break;
                case 4: SWAP_32( *tmp_32 );
                    break;
                case 2: SWAP_16( *tmp_16 );
                    break;
                default:
                    break;
                }
            }
            PrintLinePrefixAddress( data.loop, is32bit );
            PrintLinePrefixData( contents, data.loop, size, DisInsSizeInc( &DHnd ), decoded.size );
            BufferAlignToTab( PREFIX_SIZE_TABS );
        }
        BufferStore( "\t%s", name );
        if( *ops != '\0' ) {
            pos_tabs = ( DisInsNameMax( &DHnd ) + TAB_WIDTH ) / TAB_WIDTH + 1;
            if( !(DFormat & DFF_ASM) ) {
                pos_tabs += PREFIX_SIZE_TABS;
            }
            BufferAlignToTab( pos_tabs );
            BufferConcat( ops );
        }
        BufferConcatNL();
        BufferPrint();
    }
    if( sec_label_list ) {
        l_entry = handleLabels( sec->name, size, (orl_sec_offset)-1, l_entry, size );
    }
    if( !(DFormat & DFF_ASM) ) {
        routineSize = data.loop - routineBase;
        BufferConcatNL();
        BufferMsg( ROUTINE_SIZE );
        BufferStore(" %d ", routineSize );
        BufferMsg( BYTES );
        BufferConcat(",    ");
        BufferMsg( ROUTINE_BASE );
        BufferStore(" %s + %04X\n\n", sec->name, routineBase );
        BufferPrint();
    }
    if( source_mix ) {
        EndSourceMix();
    }
    PrintTail( sec );
    return( data.disassembly_errors );
}