From 7f69b3e394b026d359912adf5670faf255934f5c Mon Sep 17 00:00:00 2001 From: Aleksey Demakov Date: Sat, 7 Feb 2009 16:15:58 +0000 Subject: [PATCH] integrate mikyt's arm apply patch --- jit/jit-apply-arm.c | 43 +++++++++++++++++++++++++++++++++++++++++++ jit/jit-apply-arm.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/jit/jit-apply-arm.c b/jit/jit-apply-arm.c index 35d3307..0f0513d 100644 --- a/jit/jit-apply-arm.c +++ b/jit/jit-apply-arm.c @@ -97,4 +97,47 @@ void *_jit_create_redirector(unsigned char *buf, void *func, return (void *)buf; } +/** + * Creates the indirector, that is the trampoline that permits the Just In Time + * compilation of a method the first time that it is executed and its direct execution + * the following times + */ +void *_jit_create_indirector(unsigned char *buf, void **entry) +{ + arm_inst_buf inst; + void *start = (void *)buf; + + /* Initialize the instruction buffer */ + arm_inst_buf_init(inst, buf, buf + jit_indirector_size); + + //Load the content of memory at address "entry", that is, the entry point of the function + arm_mov_reg_imm(inst,ARM_WORK,entry); + arm_mov_reg_membase(inst,ARM_WORK,ARM_WORK,0,4); + + /* Jump to the entry point. */ + arm_mov_reg_reg(inst, ARM_PC, ARM_WORK); + + /* Flush the cache lines that we just wrote */ + jit_flush_exec(buf, ((unsigned char *)(inst.current)) - buf); + + return start; +} + +void _jit_pad_buffer(unsigned char *buf, int len) +{ + arm_inst_buf inst; + + /* Initialize the instruction buffer */ + arm_inst_buf_init(inst, buf, buf + len*4); + while(len > 0) + { + /* Traditional arm NOP */ + arm_nop(inst); + --len; + } + + /* Flush the cache lines that we just wrote */ + jit_flush_exec(buf, ((unsigned char *)(inst.current)) - buf); +} + #endif /* arm */ diff --git a/jit/jit-apply-arm.h b/jit/jit-apply-arm.h index a9dc963..2ccaa98 100644 --- a/jit/jit-apply-arm.h +++ b/jit/jit-apply-arm.h @@ -36,4 +36,39 @@ */ #define jit_redirector_size 128 +/* + * The number of bytes that are needed for a indirector stub. + * This includes any extra bytes that are needed for alignment. + */ +#define jit_indirector_size 24 + +/* + * We should pad unused code space with NOP's. + */ +#define jit_should_pad 1 + +/* + * Defines the alignment for the stack pointer at a public interface. + * As of the "Procedure Call Standard for the ARM Architecture" (AAPCS release 2.07) + * SP mod 8 = 0 + * must always be true at every public interface (function calls, etc) + */ +#define JIT_SP_ALIGN_PUBLIC 8 + +/* + * Redefine jit_builtin_apply in order to correctly align the stack pointer + * to JIT_SP_ALING_PUBLIC bytes before calling __builtin_apply to execute the + * jit-compiled function + */ +#define jit_builtin_apply(func,args,size,return_float,return_buf) \ +do { \ + register void *sp asm("sp"); \ + while(((unsigned int)sp) % JIT_SP_ALIGN_PUBLIC != 0) \ + { \ + sp=(void *)(((unsigned int) sp)+1); \ + } \ + (return_buf) = __builtin_apply \ + ((void (*)())(func), (args), (size)); \ +} while (0) + #endif /* _JIT_APPLY_ARM_H */ -- 2.47.3