ppcfmt.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,377 行 · 第 1/4 页

C
1,377
字号
static void ITFPMul( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//********************************************************************************************

    assert( ins->num_operands == 3 );
    doEncode4( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[0]->reg ), RegIndex( ins->operands[1]->reg ),
        RegIndex( ins->operands[2]->reg ), 0,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITBranch( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*********************************************************************************************

    ins_operand *op;
    ins_flags   flags;

    assert( ins->num_operands == 1 );
    flags = ( ins->format->flags & table->optional ) | table->required;
    op = ins->operands[0];
    *buffer = _Opcode( table->primary ) |
              _LI( _Longword_offset( op->constant ) ) |
              _AA( flags ) | _LK( flags );
    doReloc( reloc, op, OWL_RELOC_JUMP_REL, flags );
}

static void ITBranchCond( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*************************************************************************************************

    ins_operand *op[3];
    ins_flags   flags;
    int         ctr;

    assert( ins->num_operands == 3 );
    for( ctr = 0; ctr < 3; ++ctr ) {
        op[ctr] = ins->operands[ctr];
        if( ( ctr < 2 ) && !ensureOpAbsolute( op[ctr], ctr ) ) return;
    }
    flags = ( ins->format->flags & table->optional ) | table->required;
    doEncodeBoBiBd( buffer, table->primary, op[0]->constant, op[1]->constant,
        _Longword_offset( op[2]->constant ), flags );
    doReloc( reloc, op[2], OWL_RELOC_BRANCH_REL, flags );
}

static void ITBranchSpec( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*************************************************************************************************

    ins_operand *op[2];
    ins_flags   flags;
    int         ctr;

    assert( ins->num_operands == 2 );
    flags = ( ins->format->flags & table->optional ) | table->required;
    for( ctr = 0; ctr < 2; ++ctr ) {
        op[ctr] = ins->operands[ctr];
        if( !ensureOpAbsolute( op[ctr], ctr ) ) return;
    }
    doEncodeBoBiOp2( buffer, table->primary, table->secondary,
        op[0]->constant, op[1]->constant,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITCmp( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//******************************************************************************************

    ins_operand *op[4], *opRa, *opRb;
    uint        crfIdx, L_bit, ctr;
    ins_opcount opcount;
    op_type     verify4[4] = { OP_CRF, OP_IMMED, OP_GPR, OP_GPR };
    op_type     verify3[3] = { OP_IMMED, OP_GPR, OP_GPR };
    op_type     *verify;

    assert( ins->num_operands == 3 || ins->num_operands == 4 );
    opcount = ins->num_operands;
    verify = ( opcount == 3 ) ?  verify3 : verify4;
    for( ctr = 0; ctr < opcount; ctr++ ) {
        if( !ensureTypeCorrect( op[ctr] = ins->operands[ctr], verify[ctr], ctr ) ) return;
    }
    if( opcount == 4 ) {
        crfIdx = RegIndex( op[0]->reg );
        ctr = 1;
    } else {    // 3 operands
        crfIdx = 0;
        ctr = 0;
    }
    L_bit = op[ctr]->constant;
    if( ( L_bit & 1 ) != L_bit ) {
        Error( OP_OUT_OF_RANGE, ctr );
    }
    if( !ensureOpAbsolute( op[ctr], ctr ) ) return;
    opRa = op[++ctr];
    opRb = op[++ctr];
    doEncode3( buffer, table->primary, table->secondary,
        ( crfIdx << 2 ) | L_bit,
        RegIndex( opRa->reg ), RegIndex( opRb->reg ),
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITCmpImmed( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//***********************************************************************************************

    ins_operand *op[4], *opRa, *opSimm;
    uint        crfIdx, L_bit, ctr;
    ins_opcount opcount;
    op_type     verify4[4] = { OP_CRF, OP_IMMED, OP_GPR, OP_IMMED };
    op_type     verify3[3] = { OP_IMMED, OP_GPR, OP_IMMED };
    op_type     *verify;

    assert( ins->num_operands == 3 || ins->num_operands == 4 );
    opcount = ins->num_operands;
    verify = ( opcount == 3 ) ?  verify3 : verify4;
    for( ctr = 0; ctr < opcount; ctr++ ) {
        if( !ensureTypeCorrect( op[ctr] = ins->operands[ctr], verify[ctr], ctr ) ) return;
    }
    if( opcount == 4 ) {
        crfIdx = RegIndex( op[0]->reg );
        ctr = 1;
    } else {    // 3 operands
        crfIdx = 0;
        ctr = 0;
    }
    L_bit = op[ctr]->constant;
    if( ( L_bit & 1 ) != L_bit ) {
        Error( OP_OUT_OF_RANGE, ctr );
    }
    if( !ensureOpAbsolute( op[ctr], ctr ) ) return;
    opRa = op[++ctr];
    opSimm = op[++ctr];
    doEncode2( buffer, table->primary, ( crfIdx << 2 ) | L_bit,
        RegIndex( opRa->reg ), opSimm->constant,
        ( ins->format->flags & table->optional ) | table->required );
    doReloc( reloc, opSimm, OWL_RELOC_HALF_LO, 0 );
}

static void ITCondBit( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//**********************************************************************************************

    assert( ins->num_operands == 3 );
    doEncode3( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[0]->reg ), RegIndex( ins->operands[1]->reg ),
        RegIndex( ins->operands[2]->reg ),
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITCondUn( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*********************************************************************************************

    assert( ins->num_operands == 2 );
    doEncode3( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[0]->reg ) << 2,
        RegIndex( ins->operands[1]->reg ) << 2, 0,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITMcrxr( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//********************************************************************************************

    assert( ins->num_operands == 1 );
    doEncode3( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[0]->reg ) << 2, 0, 0,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITMfcr( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*******************************************************************************************

    assert( ins->num_operands == 1 );
    doEncode3( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[0]->reg ), 0, 0,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITMffs( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*******************************************************************************************

    ITMfcr( table, ins, buffer, reloc );
}

static bool SPRValidate( int_32 spr ) {
//*************************************

    int n, ctr;
    bool status = FALSE;

    if( ( spr & 0x3ff ) != spr ) return( FALSE );
    n = sizeof( SPRChkList ) / sizeof( SPRChkList[0] );
    for( ctr = 0; !status && ctr < n; ++ctr ) {
        status = ( spr == SPRChkList[ ctr ] ) ? TRUE : FALSE;
    }
    return( status );
}

static void ITMfspr( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//********************************************************************************************

    ins_operand *const_op;

    assert( ins->num_operands == 2 );
    const_op = ins->operands[1];
    if( !SPRValidate( const_op->constant ) ) {
        Error( BAD_REG_ENCODING, 1, "SPR" );
    }
    if( !ensureOpAbsolute( const_op, 1 ) ) return;
    doEncodeSPR( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[0]->reg ), const_op->constant,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITMfsr( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*******************************************************************************************

    ins_operand *const_op;

    assert( ins->num_operands == 2 );
    const_op = ins->operands[1];
    if( const_op->constant > 0xf ) {
        Error( OP_OUT_OF_RANGE, 1 );
    }
    if( !ensureOpAbsolute( const_op, 1 ) ) return;
    doEncode3( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[0]->reg ), const_op->constant, 0,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITMfsrin( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*********************************************************************************************

    assert( ins->num_operands == 2 );
    doEncode3( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[0]->reg ), 0, RegIndex( ins->operands[1]->reg ),
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITMftb( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*******************************************************************************************

    ins_operand *const_op;
    ins_flags   flags;

    assert( ins->num_operands == 2 );
    const_op = ins->operands[1];
    if( const_op->constant != 0x188 && const_op->constant != 0x1a8 ) {
        Error( BAD_REG_ENCODING, 1, "TBR" );
    }
    if( !ensureOpAbsolute( const_op, 1 ) ) return;
    flags = ( ins->format->flags & table->optional ) | table->required;
    *buffer = _Opcode( table->primary ) | _Opcode2( table->secondary ) |
              _D( RegIndex( ins->operands[0]->reg ) ) |
              _TBR( const_op->constant ) | _OE( flags ) | _RC( flags );
}

static void ITMtcrf( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//********************************************************************************************

    ins_operand *const_op;
    ins_flags   flags;

    assert( ins->num_operands == 2 );
    const_op = ins->operands[0];
    if( const_op->constant > 0xff ) {
        Error( OP_OUT_OF_RANGE, 0 );
    }
    if( !ensureOpAbsolute( const_op, 0 ) ) return;
    flags = ( ins->format->flags & table->optional ) | table->required;
    *buffer = _Opcode( table->primary ) | _Opcode2( table->secondary ) |
              _S( RegIndex( ins->operands[1]->reg ) ) |
              _CRM( const_op->constant ) | _OE( flags ) | _RC( flags );
}

static void ITMtfsb( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//********************************************************************************************

    ITMfcr( table, ins, buffer, reloc );
}

static void ITMtfsf( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//********************************************************************************************

    ins_operand *opFM;
    ins_flags   flags;

    assert( ins->num_operands == 2 );
    opFM = ins->operands[0];
    if( opFM->constant > 0xff ) {
        Error( OP_OUT_OF_RANGE, 0 );
    }
    if( !ensureOpAbsolute( opFM, 0 ) ) return;
    flags = ( ins->format->flags & table->optional ) | table->required;
    *buffer = _Opcode( table->primary ) | _Opcode2( table->secondary ) |
              _FM( opFM->constant ) | _B( RegIndex( ins->operands[1]->reg ) ) |
              _OE( flags ) | _RC( flags );
}

static void ITMtfsfImmed( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*************************************************************************************************

    ins_operand *const_op;

    assert( ins->num_operands == 2 );
    const_op = ins->operands[1];
    if( const_op->constant > 0xff ) {
        Error( OP_OUT_OF_RANGE, 1 );
    }
    if( !ensureOpAbsolute( const_op, 1 ) ) return;
    doEncode3( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[0]->reg ) << 2, 0, const_op->constant << 1,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITMtspr( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//********************************************************************************************

    ins_operand *const_op;

    assert( ins->num_operands == 2 );
    const_op = ins->operands[0];
    if( !SPRValidate( const_op->constant ) ) {
        Error( BAD_REG_ENCODING, 0, "SPR" );
        return;
    }
    if( !ensureOpAbsolute( const_op, 0 ) ) return;
    doEncodeSPR( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[1]->reg ), const_op->constant,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITMtsr( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*******************************************************************************************

    ins_operand *const_op;

    assert( ins->num_operands == 2 );
    const_op = ins->operands[0];
    if( const_op->constant > 0xf ) {
        Error( OP_OUT_OF_RANGE, 0 );
    }
    if( !ensureOpAbsolute( const_op, 1 ) ) return;
    doEncode3( buffer, table->primary, table->secondary,
        RegIndex( ins->operands[1]->reg ), const_op->constant, 0,
        ( ins->format->flags & table->optional ) | table->required );
}

static void ITDc( ins_table *table, instruction *ins, uint_32 *buffer, asm_reloc *reloc ) {
//*****************************************************************************************

    assert( ins->num_operands == 2 );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?