From f0ecfc5b90009bfa32ebd026dc08a008f06acd9b Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Wed, 19 Jul 2006 12:09:09 +0000 Subject: [PATCH] 2006-07-19 Zoltan Varga * alpha/alpha-codegen.h alpha/test.c alpha/tramp.c: Applied patch from Sergey Tikhonov . Updates to alpha support. svn path=/trunk/mono/; revision=62745 --- mono/arch/ChangeLog | 4 ++ mono/arch/alpha/alpha-codegen.h | 84 ++++++++++++++++++++++++--------- mono/arch/alpha/test.c | 16 ++++--- mono/arch/alpha/tramp.c | 46 ++++++++++-------- 4 files changed, 103 insertions(+), 47 deletions(-) diff --git a/mono/arch/ChangeLog b/mono/arch/ChangeLog index 48bea1677b8..c2c4f24f713 100644 --- a/mono/arch/ChangeLog +++ b/mono/arch/ChangeLog @@ -1,3 +1,7 @@ +2006-07-19 Zoltan Varga + + * alpha/alpha-codegen.h alpha/test.c alpha/tramp.c: Applied patch from + Sergey Tikhonov . Updates to alpha support. Thu Jun 15 16:59:36 CEST 2006 Paolo Molaro diff --git a/mono/arch/alpha/alpha-codegen.h b/mono/arch/alpha/alpha-codegen.h index 26dc591a210..194c3272c4e 100644 --- a/mono/arch/alpha/alpha-codegen.h +++ b/mono/arch/alpha/alpha-codegen.h @@ -160,7 +160,6 @@ typedef enum { #define __alpha_int_32 unsigned int - /***************************************/ #define AXP_OFF26_MASK 0x03ffffff #define AXP_OFF21_MASK 0x01fffff @@ -210,7 +209,7 @@ typedef enum { ((func & AXP_OFF7_MASK) << AXP_REGSIZE) #define alpha_op_literal( lit ) \ - ((lit & AXP_OFF7_MASK) << AXP_LIT_SHIFT) + ((lit & AXP_OFF8_MASK) << AXP_LIT_SHIFT) #define alpha_mem_br_func( func, hint ) \ (((func & AXP_OFF2_MASK ) << AXP_MEM_BR_SHIFT ) | (hint&AXP_OFF14_MASK)) @@ -236,48 +235,56 @@ typedef enum { #define alpha_encode_palcall( ins, op, func ) \ - *((__alpha_int_32*)(ins))++ = ( 0 |\ - alpha_opcode( op ) | ( func & AXP_OFF26_MASK )) + *((__alpha_int_32*)(ins)) = ( 0 |\ + alpha_opcode( op ) | ( func & AXP_OFF26_MASK )),\ + ((__alpha_int_32*)(ins))++ #define alpha_encode_mem( ins, op, Rdest, Rsrc, offset ) \ - *((__alpha_int_32*)(ins))++ = ( 0 |\ + *((__alpha_int_32*)(ins)) = ( 0 |\ alpha_opcode( op ) | alpha_reg_a( Rdest ) | \ - alpha_reg_b( Rsrc ) | (offset & AXP_OFF16_MASK )) + alpha_reg_b( Rsrc ) | (offset & AXP_OFF16_MASK )),\ + ((__alpha_int_32*)(ins))++ #define alpha_encode_mem_fc( ins, op, func, Rdest, Rsrc, offset ) \ - *((__alpha_int_32*)(ins))++ = ( 0 |\ + *((__alpha_int_32*)(ins)) = ( 0 |\ alpha_opcode( op ) | alpha_reg_a( Rdest ) | \ - alpha_reg_b( Rsrc ) | alpha_mem_fc_func( func )) + alpha_reg_b( Rsrc ) | alpha_mem_fc_func( func )),\ + *((__alpha_int_32*)(ins))++ #define alpha_encode_mem_br( ins, op, func, Rdest, Rsrc, hint ) \ - *((__alpha_int_32*)(ins))++ = ( 0 |\ + *((__alpha_int_32*)(ins)) = ( 0 |\ alpha_opcode( op ) | alpha_reg_a( Rdest ) | \ - alpha_reg_b( Rsrc ) | alpha_mem_br_func( func, hint ) ) + alpha_reg_b( Rsrc ) | alpha_mem_br_func( func, hint ) ),\ + ((__alpha_int_32*)(ins))++ #define alpha_encode_branch( ins, op, Reg, offset ) \ - *((__alpha_int_32*)(ins))++ = ( 0 |\ + *((__alpha_int_32*)(ins)) = ( 0 |\ alpha_opcode( op ) | alpha_reg_a( Reg ) | \ - (offset & AXP_OFF21_MASK )) + (offset & AXP_OFF21_MASK )),\ + ((__alpha_int_32*)(ins))++ #define alpha_encode_op( ins, op, func, Rsrc1, Rsrc2, Rdest ) \ - *((__alpha_int_32*)(ins))++ = ( 0 |\ + *((__alpha_int_32*)(ins)) = ( 0 |\ alpha_opcode( op ) | alpha_reg_a( Rsrc1 ) | \ alpha_reg_b( Rsrc2 ) | alpha_op_func( func ) | \ - alpha_reg_c( Rdest )) + alpha_reg_c( Rdest )),\ + ((__alpha_int_32*)(ins))++ #define alpha_encode_opl( ins, op, func, Rsrc, lit, Rdest ) \ - *((__alpha_int_32*)(ins))++ = ( 0 |\ - alpha_opcode( op ) | alpha_reg_a( Rsrc1 ) | \ + *((__alpha_int_32*)(ins)) = ( 0 |\ + alpha_opcode( op ) | alpha_reg_a( Rsrc ) | \ alpha_op_literal(lit) | ( 1 << 12 ) | \ - alpha_op_func( func ) | alpha_reg_c( Rdest ) ) + alpha_op_func( func ) | alpha_reg_c( Rdest ) ),\ + ((__alpha_int_32*)(ins))++ #define alpha_encode_fpop( ins, op, func, Rsrc1, Rsrc2, Rdest ) \ - *((__alpha_int_32*)(ins))++ = ( 0 |\ + *((__alpha_int_32*)(ins)) = ( 0 |\ alpha_opcode( op ) | alpha_reg_a( Rsrc1 ) | \ alpha_reg_b( Rsrc2 ) | alpha_fp_func( func ) | \ - alpha_reg_c( Rdest )) + alpha_reg_c( Rdest )),\ + ((__alpha_int_32*)(ins))++ /***************************************/ @@ -504,13 +511,48 @@ typedef enum { #define alpha_extqh( ins, Rsrc1, Rsrc2, Rdest ) alpha_encode_op( ins, 0x12, 0x7a, Rsrc1, Rsrc2, Rdest ) #define alpha_extqh_( ins, Rsrc1, lit, Rdest ) alpha_encode_opl( ins, 0x12, 0x7a, Rsrc1, lit, Rdest ) +#define alpha_mull(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_op( ins, 0x13, 0x00, Rsrc1, Rsrc2, Rdest ) +#define alpha_mull_(ins, Rsrc1, lit, Rdest) alpha_encode_op( ins, 0x13, 0x00, Rsrc1, lit, Rdest ) +#define alpha_mulq(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_op( ins, 0x13, 0x20, Rsrc1, Rsrc2, Rdest ) +#define alpha_mulq_(ins, Rsrc1, lit, Rdest) alpha_encode_op( ins, 0x13, 0x20, Rsrc1, lit, Rdest ) + +// For 264 #define alpha_ftois( ins, RFsrc, Rdest ) alpha_encode_fpop( ins, 0x1c, 0x078, RFsrc, alpha_zero, Rdest ) #define alpha_ftoit( ins, RFsrc, Rdest ) alpha_encode_fpop( ins, 0x1c, 0x070, RFsrc, alpha_zero, Rdest ) #define alpha_ftoi_qf( ins, RFsrc, Rdest ) alpha_encode_fpop( ins, 0x1c, 0x070, RFsrc, alpha_zero, Rdest ) - +// For 264 #define alpha_itofs( ins, Rsrc, RFdest ) alpha_encode_fpop( ins, 0x14, 0x004, Rsrc, alpha_zero, RFdest ) #define alpha_itoff( ins, Rsrc, RFdest ) alpha_encode_fpop( ins, 0x14, 0x014, Rsrc, alpha_zero, RFdest ) #define alpha_itoft( ins, Rsrc, RFdest ) alpha_encode_fpop( ins, 0x14, 0x024, Rsrc, alpha_zero, RFdest ) #define alpha_itof_qf( ins, Rsrc, RFdest ) alpha_encode_fpop( ins, 0x14, 0x024, Rsrc, alpha_zero, RFdest ) -#endif \ No newline at end of file +#define alpha_cvtts_c(ins, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x2C, alpha_fzero, Rsrc2, Rdest ) +#define alpha_cvttq_c(ins, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x2F, alpha_fzero, Rsrc2, Rdest ) +#define alpha_cvtqs_c(ins, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x3C, alpha_fzero, Rsrc2, Rdest ) +#define alpha_cvtqt_c(ins, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x3E, alpha_fzero, Rsrc2, Rdest ) + + +#define alpha_adds(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x080, Rsrc1, Rsrc2, Rdest ) +#define alpha_subs(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x081, Rsrc1, Rsrc2, Rdest ) +#define alpha_addt(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0A0, Rsrc1, Rsrc2, Rdest ) +#define alpha_subt(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0A1, Rsrc1, Rsrc2, Rdest ) +#define alpha_mult(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0A2, Rsrc1, Rsrc2, Rdest ) +#define alpha_divt(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0A3, Rsrc1, Rsrc2, Rdest ) +#define alpha_cmptun(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0A4, Rsrc1, Rsrc2, Rdest ) +#define alpha_cmpteq(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0A5, Rsrc1, Rsrc2, Rdest ) +#define alpha_cmptlt(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0A6, Rsrc1, Rsrc2, Rdest ) +#define alpha_cmptle(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0A7, Rsrc1, Rsrc2, Rdest ) + +#define alpha_cvtts(ins, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0AC, alpha_fzero, Rsrc2, Rdest ) +#define alpha_cvttq(ins, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0AF, alpha_fzero, Rsrc2, Rdest ) +#define alpha_cvtqs(ins, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0BC, alpha_fzero, Rsrc2, Rdest ) +#define alpha_cvtqt(ins, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x16, 0x0BE, alpha_fzero, Rsrc2, Rdest ) + + +#define alpha_cpys(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x17, 0x020, Rsrc1, Rsrc2, Rdest ) +#define alpha_cpysn(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x17, 0x021, Rsrc1, Rsrc2, Rdest ) +#define alpha_cpyse(ins, Rsrc1, Rsrc2, Rdest) alpha_encode_fpop( ins, 0x17, 0x022, Rsrc1, Rsrc2, Rdest ) + + +#endif + diff --git a/mono/arch/alpha/test.c b/mono/arch/alpha/test.c index 27db190efdb..b922750640c 100644 --- a/mono/arch/alpha/test.c +++ b/mono/arch/alpha/test.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include /* A typical Alpha stack frame looks like this */ /* @@ -39,13 +41,13 @@ fun..ng: // called from inside the module. // // Simple function which returns 10. // -int testfunc() +static int testfunc(void) { return 10; } // Write it using the known asm bytecodes. -char * write_testfunc_1( char * p ) +static unsigned int * write_testfunc_1(unsigned int * p ) { // // ldah gp, 0(pv) @@ -81,7 +83,7 @@ int _func_code[] = { } // The same function encoded with alpha-codegen.h -char * write_testfunc_2( char * p ) +unsigned int * write_testfunc_2( unsigned int * p ) { alpha_ldah( p, alpha_gp, alpha_pv, 0 ); // start the gp load alpha_lda( p, alpha_sp, alpha_sp, -16 ); // allocate the stack @@ -118,10 +120,12 @@ void output( char * p, int len ) close( fd ); } +unsigned int code [16000/4]; + int main( int argc, char ** argv ) { - char code [16000]; - char *p = code; - char * cp; +// unsigned int code [16000/4]; + unsigned int *p = code; + unsigned int * cp; int (*x)() = 0; int y = 0; diff --git a/mono/arch/alpha/tramp.c b/mono/arch/alpha/tramp.c index 7d9fe02861b..23c3846e0a4 100644 --- a/mono/arch/alpha/tramp.c +++ b/mono/arch/alpha/tramp.c @@ -111,9 +111,10 @@ call_func..ng: /* */ /* void func (void (*callme)(), void *retval, */ /* void *this_obj, stackval *arguments); */ -static inline guint8 * -emit_prolog (guint8 *p, const gint SIZE, int hasthis ) +static inline unsigned int * +emit_prolog (unsigned int *pi, const gint SIZE, int hasthis ) { + unsigned int *p = (unsigned int *)pi; // 9 instructions. alpha_ldah( p, alpha_gp, alpha_pv, 0 ); alpha_lda( p, alpha_gp, alpha_gp, 0 ); // ldgp gp, 0(pv) @@ -127,9 +128,9 @@ emit_prolog (guint8 *p, const gint SIZE, int hasthis ) alpha_a2: will be moved into alpha_a0... if hasthis is true. */ /* store parameters on stack.*/ - alpha_stq( p, alpha_ra, alpha_sp, SIZE-24 ); // ra - alpha_stq( p, alpha_fp, alpha_sp, SIZE-16 ); // fp - alpha_stq( p, alpha_a1, alpha_sp, SIZE-8 ); // retval + alpha_stq( p, alpha_ra, alpha_sp, (SIZE-24) ); // ra + alpha_stq( p, alpha_fp, alpha_sp, (SIZE-16) ); // fp + alpha_stq( p, alpha_a1, alpha_sp, (SIZE-8) ); // retval /* set the frame pointer */ alpha_mov1( p, alpha_sp, alpha_fp ); @@ -144,9 +145,11 @@ emit_prolog (guint8 *p, const gint SIZE, int hasthis ) return p; } -static inline guint8 * -emit_call( guint8 *p , const gint SIZE ) +static inline unsigned int * +emit_call( unsigned int *pi , const gint SIZE ) { + unsigned int *p = (unsigned int *)pi; + // 3 instructions /* call func */ alpha_jsr( p, alpha_ra, alpha_pv, 0 ); // jsr ra, 0(pv) @@ -158,29 +161,32 @@ emit_call( guint8 *p , const gint SIZE ) return p; } -static inline guint8 * -emit_store_return_default(guint8 *p, const gint SIZE ) +static inline unsigned int * +emit_store_return_default(unsigned int *pi, const gint SIZE ) { // 2 instructions. + unsigned int *p = (unsigned int *)pi; /* TODO: This probably do different stuff based on the value. you know, like stq/l/w. and s/f. */ - alpha_ldq( p, alpha_t0, alpha_fp, SIZE-8 ); // load void * retval + alpha_ldq( p, alpha_t0, alpha_fp, (SIZE-8) ); // load void * retval alpha_stq( p, alpha_v0, alpha_t0, 0 ); // store the result to *retval. return p; } -static inline guint8 * -emit_epilog (guint8 *p, const gint SIZE ) +static inline unsigned int * +emit_epilog (unsigned int *pi, const gint SIZE ) { + unsigned int *p = (unsigned int *)pi; + // 5 instructions. alpha_mov1( p, alpha_fp, alpha_sp ); /* restore fp, ra, sp */ - alpha_ldq( p, alpha_ra, alpha_sp, SIZE-24 ); - alpha_ldq( p, alpha_fp, alpha_sp, SIZE-16 ); + alpha_ldq( p, alpha_ra, alpha_sp, (SIZE-24) ); + alpha_ldq( p, alpha_fp, alpha_sp, (SIZE-16) ); alpha_lda( p, alpha_sp, alpha_sp, ((SIZE & 8) ? (SIZE+8) : SIZE) ); /* return */ @@ -215,8 +221,8 @@ static void calculate_size(MonoMethodSignature *sig, int * INSTRUCTIONS, int * S MonoPIFunc mono_arch_create_trampoline (MonoMethodSignature *sig, gboolean string_ctor) { - unsigned char *p; - unsigned char *buffer; + unsigned int *p; + unsigned int *buffer; MonoType* param; int i, pos; @@ -240,7 +246,7 @@ mono_arch_create_trampoline (MonoMethodSignature *sig, gboolean string_ctor) // allocate. - buffer = p = malloc(BUFFER_SIZE); + buffer = p = (unsigned int *)malloc(BUFFER_SIZE); memset( buffer, 0, BUFFER_SIZE ); pos = 8 * (sig->param_count - alpharegs - 1); @@ -264,7 +270,7 @@ mono_arch_create_trampoline (MonoMethodSignature *sig, gboolean string_ctor) else { // load into register - alpha_ldq( p, regbase + i, alpha_t0, ARG_LOC( i ) ); + alpha_ldq( p, (regbase + i), alpha_t0, ARG_LOC( i ) ); } } else @@ -299,7 +305,7 @@ mono_arch_create_trampoline (MonoMethodSignature *sig, gboolean string_ctor) else { // load into register - alpha_ldl( p, regbase + i, alpha_t0, ARG_LOC(i) ); + alpha_ldl( p, (regbase + i), alpha_t0, (ARG_LOC(i)) ); } break; case MONO_TYPE_I: @@ -321,7 +327,7 @@ mono_arch_create_trampoline (MonoMethodSignature *sig, gboolean string_ctor) else { // load into register - alpha_ldq( p, regbase + i, alpha_t0, ARG_LOC(i) ); + alpha_ldq( p, (regbase + i), alpha_t0, ARG_LOC(i) ); } break; case MONO_TYPE_R4: -- 2.25.1