386rtrtn.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 478 行 · 第 1/2 页
C
478 行
byte_seq_len length;
char data[];
} rt_aux_info;
static rt_aux_info Scn1 = {
0, 2,
{0xF2, /* repne */
0xAE} /* scasb */
};
static rt_aux_info Scn1ES = {
0, 6,
{0x06, /* push es */
0x0e, /* push cs */
0x07, /* pop es */
0xF2, /* repne */
0xAE, /* scasb */
0x07} /* pop es */
};
static rt_aux_info Scn2 = { /* or Scn4 in USE16 */
0, 3,
{0xF2, /* repne */
0x66, 0xAF} /* scasw */
};
static rt_aux_info Scn2ES = { /* or Scn4 in USE16 */
0, 7,
{0x06, /* push es */
0x0e, /* push cs */
0x07, /* pop es */
0xF2, /* repne */
0x66, 0xAF, /* scasw */
0x07} /* pop es */
};
static rt_aux_info Scn4 = { /* or Scn2 in USE16 */
0, 2,
{0xF2, /* repne */
0xAF} /* scasd */
};
static rt_aux_info Scn4ES = { /* or Scn2 in USE16 */
0, 6,
{0x06, /* push es */
0x0e, /* push cs */
0x07, /* pop es */
0xF2, /* repne */
0xAF, /* scasd */
0x07} /* pop es */
};
#include "cgrealgn.h"
extern char *AskRTName( int rtindex )
/***************************************/
{
if( _IsTargetModel( INDEXED_GLOBALS ) ) {
switch( rtindex + BEG_RTNS ) {
case RT_FDA:
return( "__FXA" );
case RT_FDS:
return( "__FXS" );
case RT_FDM:
return( "__FXM" );
case RT_FDD:
return( "__FXD" );
case RT_FDC:
return( "__FXC" );
case RT_DPOW:
return( "RT@XPOW" );
case RT_DATAN2:
return( "IF@XATAN2" );
case RT_DFMOD:
return( "IF@XFMOD" );
}
}
return( RTInfo[ rtindex ].nam );
}
extern bool RTLeaveOp2( instruction *ins )
/*********************************************
return true if it's a bad idea to put op2 into a temporary since we're
gonna take the bugger's address in rMAKECALL.
*/
{
ins = ins;
return( FALSE );
}
extern name *ScanCall( tbl_control *table, name *value,
type_class_def tipe )
/**********************************************************
generates a fake call to a rutime routine that looks up "value" in a table
and jumps to the appropriate case, using either a pointer or index
returned by the "routine". The "routine" will be generated inline later.
See BEAuxInfo for the code sequences generated. That will explain
how the jump destination is determined as well.
*/
{
instruction *new_ins;
name *reg_name;
name *result;
name *label;
hw_reg_set tmp;
switch( tipe ) {
case U1:
RoutineNum = RT_SCAN1 - BEG_RTNS;
break;
case U2:
RoutineNum = RT_SCAN2 - BEG_RTNS;
break;
case U4:
RoutineNum = RT_SCAN4 - BEG_RTNS;
break;
}
reg_name = AllocRegName( FirstReg( RTInfo[ RoutineNum ].left ) );
new_ins = MakeConvert( value, reg_name, tipe, value->n.name_class );
AddIns( new_ins );
reg_name = AllocRegName( HW_ECX );
new_ins = MakeMove( AllocIntConst( table->size + 1 ), reg_name, U4 );
AddIns( new_ins );
reg_name = AllocRegName( HW_EDI );
label = AllocMemory( table, 0, CG_VTB, U4 );
label = AddrConst( label, AskBackSeg(), CONS_OFFSET );
new_ins = MakeMove( label, reg_name, U4 );
AddIns( new_ins );
new_ins = NewIns( 3 );
new_ins->head.opcode = OP_CALL;
new_ins->type_class = U2;
tmp = FirstReg( RTInfo[ RoutineNum ].left );
HW_CTurnOn( tmp, HW_ECX );
HW_CTurnOn( tmp, HW_EDI );
HW_CTurnOn( tmp, HW_ES );
new_ins->operands[ CALL_OP_USED ] = AllocRegName( tmp );
new_ins->operands[ CALL_OP_USED2 ] = new_ins->operands[ CALL_OP_USED ];
new_ins->operands[ CALL_OP_ADDR ] = AllocMemory( RTLabel(RoutineNum),
0, CG_LBL, U4 );
new_ins->result = NULL;
new_ins->num_operands = 2;
AddIns( new_ins );
result = AllocMemory( table, 0, CG_TBL, U4 ); /* so table gets freed!*/
if( tipe == U4 ) {
HW_CAsgn( tmp, HW_ECX );
HW_CTurnOn( tmp, HW_EDI );
new_ins->zap = &AllocRegName( tmp )->r;
new_ins->result = AllocRegName( HW_EDI );
HW_CAsgn( tmp, HW_CS );
HW_CTurnOn( tmp, HW_EDI );
result = AllocRegName( tmp );
result = AllocIndex( result, NULL, ( table->size - 1 )*4, U4 );
new_ins = MakeMove( result, AllocTemp( WD ), WD );
AddIns( new_ins );
result = new_ins->result;
} else {
HW_CAsgn( tmp, HW_ECX );
HW_CTurnOn( tmp, HW_EDI );
new_ins->zap = &AllocRegName( tmp )->r;
new_ins->result = AllocRegName( HW_ECX );
new_ins = MakeMove( new_ins->result, AllocTemp( WD ), WD );
AddIns( new_ins );
result = AllocIndex( new_ins->result, result, 0, U4 );
result->i.scale = 2; /* 2**2 == 4 */
}
return( result );
}
extern name *Addressable( name *cons, type_class_def class )
/***************************************************************
make sure a floating point constant is addressable (dropped
it into memory if it isnt)
*/
{
if( cons->n.class == N_CONSTANT ) return( GenFloat( cons, class ) );
return( cons );
}
extern pointer BEAuxInfo( pointer hdl, aux_class request )
/**********************************************************
see ScanCall for explanation
*/
{
pointer info;
switch( request ) {
case AUX_LOOKUP:
switch( FindRTLabel( hdl ) ) {
case RT_SCAN1:
if( _IsntTargetModel( FLAT_MODEL ) ) return( &Scn1ES );
return( &Scn1 );
case RT_SCAN2:
if( _IsntTargetModel( USE_32 ) ) {
if( _IsntTargetModel( FLAT_MODEL ) ) return( &Scn4ES );
return( &Scn4 );
} else {
if( _IsntTargetModel( FLAT_MODEL ) ) return( &Scn2ES );
return( &Scn2 );
}
case RT_SCAN4:
if( _IsntTargetModel( USE_32 ) ) {
if( _IsntTargetModel( FLAT_MODEL ) ) return( &Scn2ES );
return( &Scn2 );
} else {
if( _IsntTargetModel( FLAT_MODEL ) ) return( &Scn4ES );
return( &Scn4 );
}
default:
return( NULL );
}
case CALL_CLASS:
info = hdl;
return( &((rt_aux_info *)info)->class );
case CALL_BYTES:
info = hdl;
return( &((rt_aux_info *)info)->length );
default:
_Zoiks( ZOIKS_128 );
return( NULL );
}
}
extern instruction *rMAKEFNEG( instruction *ins )
/*****************************************************
this is intentionally a stub for the 386.
*/
{
return( ins );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?