Author: lupus
Date: 2007-10-09 14:48:27 -0400 (Tue, 09 Oct 2007)
New Revision: 87211

Modified:
   trunk/mono/mono/mini/ChangeLog
   trunk/mono/mono/mini/Makefile.am
   trunk/mono/mono/mini/mini-arm.c
   trunk/mono/mono/mini/mini-arm.h
   trunk/mono/mono/mini/tramp-arm.c
Log:


Tue Oct 9 21:01:03 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>

        * Makefile.am, mini-arm.c, mini-arm.h, tramp-arm.c: ported
        ARM to the new style trampoline.



Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog      2007-10-09 18:38:10 UTC (rev 87210)
+++ trunk/mono/mono/mini/ChangeLog      2007-10-09 18:48:27 UTC (rev 87211)
@@ -1,3 +1,9 @@
+
+Tue Oct 9 21:01:03 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>
+
+       * Makefile.am, mini-arm.c, mini-arm.h, tramp-arm.c: ported
+       ARM to the new style trampoline.
+
 2007-10-09  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * tramp-amd64.c: Rework the specific trampoline code to make it smaller.

Modified: trunk/mono/mono/mini/Makefile.am
===================================================================
--- trunk/mono/mono/mini/Makefile.am    2007-10-09 18:38:10 UTC (rev 87210)
+++ trunk/mono/mono/mini/Makefile.am    2007-10-09 18:48:27 UTC (rev 87211)
@@ -143,6 +143,7 @@
        mini-arm.c              \
        mini-arm.h              \
        exceptions-arm.c        \
+       mini-trampolines.c      \
        tramp-arm.c
 
 mips_sources = \

Modified: trunk/mono/mono/mini/mini-arm.c
===================================================================
--- trunk/mono/mono/mini/mini-arm.c     2007-10-09 18:38:10 UTC (rev 87210)
+++ trunk/mono/mono/mini/mini-arm.c     2007-10-09 18:48:27 UTC (rev 87211)
@@ -208,6 +208,71 @@
        return frame_size;
 }
 
+gpointer*
+mono_arch_get_vcall_slot_addr (guint8 *code_ptr, gpointer *regs)
+{
+       char *o = NULL;
+       int reg, offset = 0;
+       guint32* code = (guint32*)code_ptr;
+
+       /* Locate the address of the method-specific trampoline. The call using
+       the vtable slot that took the processing flow to 
'arch_create_jit_trampoline' 
+       looks something like this:
+
+               ldr rA, rX, #offset
+               mov lr, pc
+               mov pc, rA
+       or better:
+               mov lr, pc
+               ldr pc, rX, #offset
+
+       The call sequence could be also:
+               ldr ip, pc, 0
+               b skip
+               function pointer literal
+               skip:
+               mov lr, pc
+               mov pc, ip
+       Note that on ARM5+ we can use one instruction instead of the last two.
+       Therefore, we need to locate the 'ldr rA' instruction to know which
+       register was used to hold the method addrs.
+       */
+       
+       /* This is the 'bl' or 'mov pc' instruction */
+       --code;
+
+       /* called directly with the bl opcode */
+       if ((((*code) >> 25)  & 7) == 5)
+               return NULL;
+
+       /* ldr pc, rX, #offset */
+#define LDR_MASK ((0xf << ARMCOND_SHIFT) | (3 << 26) | (1 << 22) | (1 << 20) | 
(15 << 12))
+#define LDR_PC_VAL ((ARMCOND_AL << ARMCOND_SHIFT) | (1 << 26) | (0 << 22) | (1 
<< 20) | (15 << 12))
+       if ((*code & LDR_MASK) == LDR_PC_VAL) {
+               reg = (*code >> 16 ) & 0xf;
+               offset = *code & 0xfff;
+               /*g_print ("found vcall at r%d + %d\n", reg, offset);*/
+               o = regs [reg];
+               return (gpointer*)(o + offset);
+       }
+       return NULL;
+}
+
+gpointer
+mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean 
has_target)
+{
+       return NULL;
+}
+
+gpointer
+mono_arch_get_this_arg_from_call (MonoMethodSignature *sig, gssize *regs, 
guint8 *code)
+{
+       /* FIXME: handle returning a struct */
+       if (MONO_TYPE_ISSTRUCT (sig->ret))
+               return (gpointer)regs [ARMREG_R1];
+       return (gpointer)regs [ARMREG_R0];
+}
+
 /*
  * Initialize the cpu to execute managed code.
  */

Modified: trunk/mono/mono/mini/mini-arm.h
===================================================================
--- trunk/mono/mono/mini/mini-arm.h     2007-10-09 18:38:10 UTC (rev 87210)
+++ trunk/mono/mono/mini/mini-arm.h     2007-10-09 18:48:27 UTC (rev 87211)
@@ -108,6 +108,10 @@
 #define MONO_ARCH_USE_SIGACTION 1
 #define MONO_ARCH_NEED_DIV_CHECK 1
 
+#define MONO_ARCH_HAVE_CREATE_SPECIFIC_TRAMPOLINE
+#define MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN
+#define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
+
 #define ARM_NUM_REG_ARGS (ARM_LAST_ARG_REG-ARM_FIRST_ARG_REG+1)
 #define ARM_NUM_REG_FPARGS 0
 

Modified: trunk/mono/mono/mini/tramp-arm.c
===================================================================
--- trunk/mono/mono/mini/tramp-arm.c    2007-10-09 18:38:10 UTC (rev 87210)
+++ trunk/mono/mono/mini/tramp-arm.c    2007-10-09 18:48:27 UTC (rev 87211)
@@ -19,7 +19,7 @@
 #include "mini-arm.h"
 
 /*
- * get_unbox_trampoline:
+ * mono_arch_get_unbox_trampoline:
  * @m: method pointer
  * @addr: pointer to native code for @m
  *
@@ -27,8 +27,8 @@
  * this argument. This method returns a pointer to a trampoline which does
  * unboxing before calling the method
  */
-static gpointer
-get_unbox_trampoline (MonoMethod *m, gpointer addr)
+gpointer
+mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
 {
        guint8 *code, *start;
        int this_pos = 0;
@@ -54,75 +54,11 @@
        return start;
 }
 
-/* Stack size for trampoline function 
- */
-#define STACK (sizeof (MonoLMF))
-
-/* Method-specific trampoline code fragment size */
-#define METHOD_TRAMPOLINE_SIZE 64
-
-/* Jump-specific trampoline code fragment size */
-#define JUMP_TRAMPOLINE_SIZE   64
-
-/**
- * arm_magic_trampoline:
- * @code: pointer into caller code
- * @method: the method to translate
- * @sp: stack pointer
- *
- * This method is called by the function 'arch_create_jit_trampoline', which in
- * turn is called by the trampoline functions for virtual methods.
- * After having called the JIT compiler to compile the method, it inspects the
- * caller code to find the address of the method-specific part of the
- * trampoline vtable slot for this method, updates it with a fragment that 
calls
- * the newly compiled code and returns this address of the compiled code to
- * 'arch_create_jit_trampoline' 
- */
-static gpointer
-arm_magic_trampoline (MonoMethod *method, guint32 *code, gchar **sp)
+void
+mono_arch_patch_callsite (guint8 *code_ptr, guint8 *addr)
 {
-       char *o = NULL;
-       gpointer addr;
-        MonoJitInfo *ji, *target_ji;
-       int reg, offset = 0;
+       guint32 *code = (guint32*)code_ptr;
 
-       addr = mono_compile_method (method);
-       /*g_print ("method code at %p for %s:%s\n", addr, method->klass->name, 
method->name);*/
-       g_assert(addr);
-
-       if (!code) {
-               return addr;
-       }
-
-       /* We can't trampoline across domains */
-       ji = mono_jit_info_table_find (mono_domain_get (), code);
-       target_ji = mono_jit_info_table_find (mono_domain_get (), addr);
-       if (!mono_method_same_domain (ji, target_ji))
-               return addr;
-
-       /* Locate the address of the method-specific trampoline. The call using
-       the vtable slot that took the processing flow to 
'arch_create_jit_trampoline' 
-       looks something like this:
-
-               ldr rA, rX, #offset
-               mov lr, pc
-               mov pc, rA
-       or better:
-               mov lr, pc
-               ldr pc, rX, #offset
-
-       The call sequence could be also:
-               ldr ip, pc, 0
-               b skip
-               function pointer literal
-               skip:
-               mov lr, pc
-               mov pc, ip
-       Note that on ARM5+ we can use one instruction instead of the last two.
-       Therefore, we need to locate the 'ldr rA' instruction to know which
-       register was used to hold the method addrs.
-       */
-       
        /* This is the 'bl' or the 'mov pc' instruction */
        --code;
        
@@ -133,57 +69,43 @@
                /*g_print ("direct patching\n");*/
                arm_patch ((char*)code, addr);
                mono_arch_flush_icache ((char*)code, 4);
-               return addr;
+               return;
        }
 
-       /* ldr pc, rX, #offset */
-#define LDR_MASK ((0xf << ARMCOND_SHIFT) | (3 << 26) | (1 << 22) | (1 << 20) | 
(15 << 12))
-#define LDR_PC_VAL ((ARMCOND_AL << ARMCOND_SHIFT) | (1 << 26) | (0 << 22) | (1 
<< 20) | (15 << 12))
-       if ((*code & LDR_MASK) == LDR_PC_VAL) {
-               reg = (*code >> 16 ) & 0xf;
-               offset = *code & 0xfff;
-               /*g_print ("found vcall at r%d + %d\n", reg, offset);*/
-               o = sp [reg];
-       }
+       g_assert_not_reached ();
+}
 
-       /* this is not done for non-virtual calls, because in that case
-          we won't have an object, but the actual pointer to the 
-          valuetype as the this argument
-        */
-       if (method->klass->valuetype && !mono_aot_is_got_entry (code, o))
-               addr = get_unbox_trampoline (method, addr);
-
-       if (o) {
-               o += offset;
-               if (mono_aot_is_got_entry (code, o) || 
mono_domain_owns_vtable_slot (mono_domain_get (), o))
-                       *((gpointer *)o) = addr;
-       } else {
-               /*g_print ("no callsite patching\n");
-               mono_disassemble_code (code -3, 16, "callsite");*/
-       }
-
-       return addr;
+void
+mono_arch_patch_plt_entry (guint8 *code, guint8 *addr)
+{
+       g_assert_not_reached ();
 }
 
-static void
-arm_class_init_trampoline (void *vtable, guint32 *code, char *sp)
+void
+mono_arch_nullify_class_init_trampoline (guint8 *code, gssize *regs)
 {
-       mono_runtime_class_init (vtable);
+       return;
+}
 
-#if 0
-       /* This is the 'bl' instruction */
-       --code;
-       
-       if ((((*code) >> 25)  & 7) == 5) {
-               ARM_NOP (code); /* nop */
-               mono_arch_flush_icache (code, 4);
-               return;
-       } else {
-               g_assert_not_reached ();
-       }
-#endif
+void
+mono_arch_nullify_plt_entry (guint8 *code)
+{
+       g_assert_not_reached ();
 }
 
+
+/* Stack size for trampoline function 
+ */
+#define STACK (sizeof (MonoLMF))
+
+/* Method-specific trampoline code fragment size */
+#define METHOD_TRAMPOLINE_SIZE 64
+
+/* Jump-specific trampoline code fragment size */
+#define JUMP_TRAMPOLINE_SIZE   64
+
+#define GEN_TRAMP_SIZE 148
+
 /*
  * Stack frame description when the generic trampoline is called.
  * caller frame
@@ -202,10 +124,10 @@
        /* Now we'll create in 'buf' the ARM trampoline code. This
         is the trampoline code common to all methods  */
        
-       code = buf = g_malloc (148);
+       code = buf = mono_global_codeman_reserve (GEN_TRAMP_SIZE);
 
        /*
-        * At this point r0 has the method and sp points to the saved
+        * At this point r0 has the specific arg and sp points to the saved
         * regs on the stack (all but PC and SP).
         */
        ARM_MOV_REG_REG (buf, ARMREG_V1, ARMREG_SP);
@@ -235,7 +157,8 @@
        /* *(lmf_addr) = r1 */
        ARM_STR_IMM (buf, ARMREG_R1, ARMREG_R0, G_STRUCT_OFFSET (MonoLMF, 
previous_lmf));
        /* save method info (it's in v2) */
-       ARM_STR_IMM (buf, ARMREG_V2, ARMREG_R1, G_STRUCT_OFFSET (MonoLMF, 
method));
+       if ((tramp_type == MONO_TRAMPOLINE_GENERIC) || (tramp_type == 
MONO_TRAMPOLINE_JUMP))
+               ARM_STR_IMM (buf, ARMREG_V2, ARMREG_R1, G_STRUCT_OFFSET 
(MonoLMF, method));
        ARM_STR_IMM (buf, ARMREG_SP, ARMREG_R1, G_STRUCT_OFFSET (MonoLMF, ebp));
        /* save the IP (caller ip) */
        if (tramp_type == MONO_TRAMPOLINE_JUMP) {
@@ -247,10 +170,10 @@
        ARM_STR_IMM (buf, ARMREG_R2, ARMREG_R1, G_STRUCT_OFFSET (MonoLMF, eip));
 
        /*
-        * Now we're ready to call arm_magic_trampoline ().
+        * Now we're ready to call xxx_trampoline ().
         */
-       /* Arg 1: MonoMethod *method. It was put in v2 */
-       ARM_MOV_REG_REG (buf, ARMREG_R0, ARMREG_V2);
+       /* Arg 1: the saved registers. It was put in v1 */
+       ARM_MOV_REG_REG (buf, ARMREG_R0, ARMREG_V1);
 
        /* Arg 2: code (next address to the instruction that called us) */
        if (tramp_type == MONO_TRAMPOLINE_JUMP) {
@@ -259,10 +182,9 @@
                ARM_MOV_REG_REG (buf, ARMREG_R1, ARMREG_V3);
        }
        
-       /* Arg 3: stack pointer so that the magic trampoline can access the
-        * registers we saved above
+       /* Arg 3: the specific argument, stored in v2
         */
-       ARM_MOV_REG_REG (buf, ARMREG_R2, ARMREG_V1);
+       ARM_MOV_REG_REG (buf, ARMREG_R2, ARMREG_V2);
 
        load_trampoline = buf;
        buf += 4;
@@ -301,15 +223,23 @@
        ARM_POP_NWB (buf, 0x5fff);
        /* do we need to set sp? */
        ARM_ADD_REG_IMM8 (buf, ARMREG_SP, ARMREG_SP, (14 * 4));
-       ARM_MOV_REG_REG (buf, ARMREG_PC, ARMREG_IP);
+       if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT)
+               ARM_MOV_REG_REG (buf, ARMREG_PC, ARMREG_LR);
+       else
+               ARM_MOV_REG_REG (buf, ARMREG_PC, ARMREG_IP);
 
        constants = (gpointer*)buf;
        constants [0] = mono_get_lmf_addr;
-       if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT) {
-               constants [1] = arm_class_init_trampoline;
-       } else {
-               constants [1] = arm_magic_trampoline;
-       }
+       if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT)
+               constants [1] = mono_class_init_trampoline;
+       else if (tramp_type == MONO_TRAMPOLINE_AOT)
+               constants [1] = mono_aot_trampoline;
+       else if (tramp_type == MONO_TRAMPOLINE_AOT_PLT)
+               constants [1] = mono_aot_plt_trampoline;
+       else if (tramp_type == MONO_TRAMPOLINE_DELEGATE)
+               constants [1] = mono_delegate_trampoline;
+       else
+               constants [1] = mono_magic_trampoline;
 
        /* backpatch by emitting the missing instructions skipped above */
        ARM_LDR_IMM (load_get_lmf_addr, ARMREG_R0, ARMREG_PC, (buf - 
load_get_lmf_addr - 8));
@@ -321,17 +251,19 @@
        mono_arch_flush_icache (code, buf - code);
 
        /* Sanity check */
-       g_assert ((buf - code) <= 512);
+       g_assert ((buf - code) <= GEN_TRAMP_SIZE);
 
        return code;
 }
 
-static MonoJitInfo*
-create_specific_tramp (MonoMethod *method, guint8* tramp, MonoDomain *domain) {
-       guint8 *code, *buf;
-       MonoJitInfo *ji;
+gpointer
+mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType 
tramp_type, MonoDomain *domain, guint32 *code_len)
+{
+       guint8 *code, *buf, *tramp;
        gpointer *constants;
 
+       tramp = mono_get_trampoline_code (tramp_type);
+
        mono_domain_lock (domain);
        code = buf = mono_code_manager_reserve (domain->code_mp, 24);
        mono_domain_unlock (domain);
@@ -350,12 +282,12 @@
         */
        /* We save all the registers, except PC and SP */
        ARM_PUSH (buf, 0x5fff);
-       ARM_LDR_IMM (buf, ARMREG_R0, ARMREG_PC, 4); /* method is the only arg */
+       ARM_LDR_IMM (buf, ARMREG_R0, ARMREG_PC, 4); /* arg1 is the only arg */
        ARM_LDR_IMM (buf, ARMREG_R1, ARMREG_PC, 4); /* temp reg */
        ARM_MOV_REG_REG (buf, ARMREG_PC, ARMREG_R1);
 
        constants = (gpointer*)buf;
-       constants [0] = method;
+       constants [0] = arg1;
        constants [1] = tramp;
        buf += 8;
 
@@ -364,109 +296,9 @@
 
        g_assert ((buf - code) <= 24);
 
-       ji = g_new0 (MonoJitInfo, 1);
-       ji->method = method;
-       ji->code_start = code;
-       ji->code_size = buf - code;
+       if (code_len)
+               *code_len = buf - code;
 
-       mono_jit_stats.method_trampolines++;
-
-       return ji;
-}
-
-MonoJitInfo*
-mono_arch_create_jump_trampoline (MonoMethod *method)
-{
-       guint8 *tramp;
-       MonoDomain* domain = mono_domain_get ();
-       
-       tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_JUMP);
-       return create_specific_tramp (method, tramp, domain);
-}
-
-/**
- * arch_create_jit_trampoline:
- * @method: pointer to the method info
- *
- * Creates a trampoline function for virtual methods. If the created
- * code is called it first starts JIT compilation of method,
- * and then calls the newly created method. It also replaces the
- * corresponding vtable entry (see arm_magic_trampoline).
- *
- * A trampoline consists of two parts: a main fragment, shared by all method
- * trampolines, and some code specific to each method, which hard-codes a
- * reference to that method and then calls the main fragment.
- *
- * The main fragment contains a call to 'arm_magic_trampoline', which performs
- * call to the JIT compiler and substitutes the method-specific fragment with
- * some code that directly calls the JIT-compiled method.
- * 
- * Returns: a pointer to the newly created code 
- */
-gpointer
-mono_arch_create_jit_trampoline (MonoMethod *method)
-{
-       guint8 *tramp;
-       MonoJitInfo *ji;
-       MonoDomain* domain = mono_domain_get ();
-       gpointer code_start;
-
-       tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_GENERIC);
-       /* FIXME: should pass the domain down to this function */
-       ji = create_specific_tramp (method, tramp, domain);
-       code_start = ji->code_start;
-       g_free (ji);
-
-       return code_start;
-}
-
-/**
- * mono_arch_create_class_init_trampoline:
- *  @vtable: the type to initialize
- *
- * Creates a trampoline function to run a type initializer. 
- * If the trampoline is called, it calls mono_runtime_class_init with the
- * given vtable, then patches the caller code so it does not get called any
- * more.
- * 
- * Returns: a pointer to the newly created code 
- */
-gpointer
-mono_arch_create_class_init_trampoline (MonoVTable *vtable)
-{
-       guint8 *code, *buf, *tramp;
-       gpointer *constants;
-
-       tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_CLASS_INIT);
-
-       mono_domain_lock (vtable->domain);
-       code = buf = mono_code_manager_reserve (vtable->domain->code_mp, 
METHOD_TRAMPOLINE_SIZE);
-       mono_domain_unlock (vtable->domain);
-
-       ARM_MOV_REG_REG (buf, ARMREG_IP, ARMREG_SP);
-       ARM_PUSH (buf, ((1 << ARMREG_IP) | (1 << ARMREG_LR)));
-       ARM_MOV_REG_REG (buf, ARMREG_R1, ARMREG_LR);
-       ARM_LDR_IMM (buf, ARMREG_R0, ARMREG_PC, 12); /* load vtable */
-       ARM_LDR_IMM (buf, ARMREG_R3, ARMREG_PC, 12); /* load the func address */
-       /* make the call */
-       ARM_MOV_REG_REG (buf, ARMREG_LR, ARMREG_PC);
-       ARM_MOV_REG_REG (buf, ARMREG_PC, ARMREG_R3);
-
-       /* restore and return */
-       ARM_POP_NWB (buf, ((1 << ARMREG_SP) | (1 << ARMREG_PC)));
-       constants = (gpointer*)buf;
-       constants [0] = vtable;
-       constants [1] = arm_class_init_trampoline;
-       buf += 8;
-
-       /* Flush instruction cache, since we've generated code */
-       mono_arch_flush_icache (code, buf - code);
-               
-       /* Sanity check */
-       g_assert ((buf - code) <= METHOD_TRAMPOLINE_SIZE);
-
-       mono_jit_stats.method_trampolines++;
-
        return code;
 }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to