Exemple #1
0
/*			     void *this_obj, stackval *arguments);  */
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)
	alpha_lda( p, alpha_sp, alpha_sp, -((SIZE & 8) ? (SIZE+8) : SIZE) ); // grow stack down SIZE (align to 16 bytes like gcc does)
	
	/* TODO: we really don't need to store everything.
	   alpha_a1: We have to store this in order to return the retval.
	   
	   alpha_a0: func pointer can be moved directly to alpha_pv
	   alpha_a3: don't need args after we are finished.
	   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
	
	/* set the frame pointer */
	alpha_mov1( p, alpha_sp, alpha_fp );
       
	/* move the args into t0, pv */
	alpha_mov1( p, alpha_a0, alpha_pv );
	alpha_mov1( p, alpha_a3, alpha_t0 );

	// Move the this pointer into a0.	
	if( hasthis )
	    alpha_mov1( p, alpha_a2, alpha_a0 );
	return p;
}
Exemple #2
0
void _jit_create_closure(unsigned char *buf, void *func, void *closure, void *_type) {
	alpha_inst inst = (alpha_inst) buf;

	/* Compute and load the global pointer (2 instructions) */
	alpha_ldah(inst,ALPHA_GP,ALPHA_PV,0);
	alpha_lda( inst,ALPHA_GP,ALPHA_GP,0);

	/* Allocate space for a new stack frame. (1 instruction) */
	alpha_lda(inst,ALPHA_SP,ALPHA_SP,-(13*8));

	/* Save the return address. (1 instruction) */
	alpha_stq(inst,ALPHA_RA,ALPHA_SP,0*8);

	/* Save integer register arguments as local variables (6 instructions) */
	alpha_stq(inst,ALPHA_A0,ALPHA_SP,1*8);
	alpha_stq(inst,ALPHA_A1,ALPHA_SP,2*8);
	alpha_stq(inst,ALPHA_A2,ALPHA_SP,3*8);
	alpha_stq(inst,ALPHA_A3,ALPHA_SP,4*8);
	alpha_stq(inst,ALPHA_A4,ALPHA_SP,5*8);
	alpha_stq(inst,ALPHA_A5,ALPHA_SP,6*8);

	/* Save floating-point register arguments as local variables (8 instructions) */
	alpha_stt(inst,ALPHA_FA0,ALPHA_SP, 7*8);
	alpha_stt(inst,ALPHA_FA1,ALPHA_SP, 8*8);
	alpha_stt(inst,ALPHA_FA2,ALPHA_SP, 9*8);
	alpha_stt(inst,ALPHA_FA3,ALPHA_SP,10*8);
	alpha_stt(inst,ALPHA_FA4,ALPHA_SP,11*8);
	alpha_stt(inst,ALPHA_FA5,ALPHA_SP,12*8);

	/* Call the closure handling function (1 instruction) */
	alpha_call(inst,func);

	/* Restore the return address (1 instruction) */
	alpha_ldq(inst,ALPHA_RA,ALPHA_SP,0*8);

	/* Restore integer register arguments (6 instructions) */
	alpha_ldq(inst,ALPHA_A0,ALPHA_SP,1*8);
	alpha_ldq(inst,ALPHA_A1,ALPHA_SP,2*8);
	alpha_ldq(inst,ALPHA_A2,ALPHA_SP,3*8);
	alpha_ldq(inst,ALPHA_A3,ALPHA_SP,4*8);
	alpha_ldq(inst,ALPHA_A4,ALPHA_SP,5*8);
	alpha_ldq(inst,ALPHA_A5,ALPHA_SP,6*8);

	/* Restore floating-point register arguments (8 instructions) */
	alpha_ldt(inst,ALPHA_FA0,ALPHA_SP, 7*8);
	alpha_ldt(inst,ALPHA_FA1,ALPHA_SP, 8*8);
	alpha_ldt(inst,ALPHA_FA2,ALPHA_SP, 9*8);
	alpha_ldt(inst,ALPHA_FA3,ALPHA_SP,10*8);
	alpha_ldt(inst,ALPHA_FA4,ALPHA_SP,11*8);
	alpha_ldt(inst,ALPHA_FA5,ALPHA_SP,12*8);

	/* restore the stack pointer (1 instruction) */
	alpha_lda(inst,ALPHA_SP,ALPHA_SP,(13*8));
}
Exemple #3
0
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)

	/* reload the gp */
	alpha_ldah( p, alpha_gp, alpha_ra, 0 );  
	alpha_lda( p, alpha_gp, alpha_gp, 0 );     // ldgp gp, 0(ra)
	
	return p;
}
Exemple #4
0
void *_jit_create_redirector(unsigned char *buf, void *func, void *user_data, int abi) {
	alpha_inst inst = (alpha_inst) buf;

	/* Allocate space for a new stack frame. (1 instruction) */
	alpha_lda(inst,ALPHA_SP,ALPHA_SP,-(16*8));

	/* Save the return address. (1 instruction) */
	alpha_stq(inst,ALPHA_RA,ALPHA_SP,0*8);

	/* Save the frame pointer. (1 instruction) */
	alpha_stq(inst,ALPHA_FP,ALPHA_SP,1*8);

	/* Save the integer save registers (6 instructions) */
	alpha_stq(inst,ALPHA_S0,ALPHA_SP,2*8);
	alpha_stq(inst,ALPHA_S1,ALPHA_SP,3*8);
	alpha_stq(inst,ALPHA_S2,ALPHA_SP,4*8);
	alpha_stq(inst,ALPHA_S3,ALPHA_SP,5*8);
	alpha_stq(inst,ALPHA_S4,ALPHA_SP,6*8);
	alpha_stq(inst,ALPHA_S5,ALPHA_SP,7*8);

	/* Save the floating point save registers (8 instructions) */
	alpha_stt(inst,ALPHA_FS0,ALPHA_SP, 8*8);
	alpha_stt(inst,ALPHA_FS1,ALPHA_SP, 9*8);
	alpha_stt(inst,ALPHA_FS2,ALPHA_SP,10*8);
	alpha_stt(inst,ALPHA_FS3,ALPHA_SP,11*8);
	alpha_stt(inst,ALPHA_FS4,ALPHA_SP,12*8);
	alpha_stt(inst,ALPHA_FS5,ALPHA_SP,13*8);
	alpha_stt(inst,ALPHA_FS6,ALPHA_SP,14*8);
	alpha_stt(inst,ALPHA_FS7,ALPHA_SP,15*8);

	/* Set the frame pointer (1 instruction) */
	alpha_mov(inst,ALPHA_SP,ALPHA_FP);

	/* Compute and load the global pointer (2 instructions) */
	alpha_ldah(inst,ALPHA_GP,ALPHA_PV,0);
	alpha_lda( inst,ALPHA_GP,ALPHA_GP,0);

	/* Force any pending hardware exceptions to be raised. (1 instruction) */
	alpha_trapb(inst);

	/* Call the redirector handling function (6 instruction) */
	alpha_call(inst, func);

	/* Restore the return address. (1 instruction) */
	alpha_ldq(inst,ALPHA_RA,ALPHA_SP,0*8);

	/* Restore the frame pointer. (1 instruction) */
	alpha_ldq(inst,ALPHA_FP,ALPHA_SP,1*8);

	/* Restore the integer save registers (6 instructions) */
	alpha_ldq(inst,ALPHA_S0,ALPHA_SP,2*8);
	alpha_ldq(inst,ALPHA_S1,ALPHA_SP,3*8);
	alpha_ldq(inst,ALPHA_S2,ALPHA_SP,4*8);
	alpha_ldq(inst,ALPHA_S3,ALPHA_SP,5*8);
	alpha_ldq(inst,ALPHA_S4,ALPHA_SP,6*8);
	alpha_ldq(inst,ALPHA_S5,ALPHA_SP,7*8);

	/* Restore the floating point save registers (8 instructions) */
	alpha_ldt(inst,ALPHA_FS0,ALPHA_SP, 8*8);
	alpha_ldt(inst,ALPHA_FS1,ALPHA_SP, 9*8);
	alpha_ldt(inst,ALPHA_FS2,ALPHA_SP,10*8);
	alpha_ldt(inst,ALPHA_FS3,ALPHA_SP,11*8);
	alpha_ldt(inst,ALPHA_FS4,ALPHA_SP,12*8);
	alpha_ldt(inst,ALPHA_FS5,ALPHA_SP,13*8);
	alpha_ldt(inst,ALPHA_FS6,ALPHA_SP,14*8);
	alpha_ldt(inst,ALPHA_FS7,ALPHA_SP,15*8);

	/* Restore the stack pointer (1 instruction) */
	alpha_lda(inst,ALPHA_SP,ALPHA_SP,16*8);

	/* Force any pending hardware exceptions to be raised. (1 instruction) */
	alpha_trapb(inst);

	/* Jump to the function that the redirector indicated (1 instruction) */
	alpha_jsr(inst,ALPHA_RA,ALPHA_V0,1);

	/* Return the start of the buffer as the redirector entry point */
	return (void *)buf;
}