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 */
*/
#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 */