2010-05-01 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Sat, 1 May 2010 19:01:48 +0000 (19:01 -0000)
committerZoltan Varga <vargaz@gmail.com>
Sat, 1 May 2010 19:01:48 +0000 (19:01 -0000)
* aot-runtime.c (mono_aot_get_plt_entry): Move the arch specific parts to an
arch-specific function.
(mono_aot_get_plt_info_offset): Ditto.

svn path=/trunk/mono/; revision=156575

mono/mini/ChangeLog
mono/mini/aot-runtime.c
mono/mini/mini.h
mono/mini/tramp-amd64.c
mono/mini/tramp-arm.c
mono/mini/tramp-ppc.c
mono/mini/tramp-x86.c

index 7d4ce32899187afaf3bb37142f5acaebcc3089e1..97273fbad7db9a8dbbf4fc76d4564e6315ae8ada 100755 (executable)
@@ -1,5 +1,9 @@
 2010-05-01  Zoltan Varga  <vargaz@gmail.com>
 
+       * aot-runtime.c (mono_aot_get_plt_entry): Move the arch specific parts to an
+       arch-specific function.
+       (mono_aot_get_plt_info_offset): Ditto.
+
        * aot-runtime.c (mono_aot_register_jit_icall): New helper function called from
        mono_arch_init () to register jit icalls called from full-aot trampolines.
        (load_function): Get rid of the arch specific #ifdefs, move the relevant code
index a6ddd92b99545ae548d37435ffee88b4a4fbc3d4..55da9c4e83a0518fc19e2c8bfdc95e73d6c3fcef 100644 (file)
@@ -3264,9 +3264,6 @@ mono_aot_plt_resolve (gpointer aot_module, guint32 plt_info_offset, guint8 *code
 static void
 init_plt (MonoAotModule *amodule)
 {
-#ifndef MONO_CROSS_COMPILE
-
-#ifdef MONO_ARCH_AOT_SUPPORTED
        int i;
        gpointer plt_0;
        gpointer tramp;
@@ -3289,9 +3286,6 @@ init_plt (MonoAotModule *amodule)
                 ((gpointer*)amodule->got)[amodule->info.plt_got_offset_base + i] = plt_0;
 
        amodule->plt_inited = TRUE;
-#endif
-
-#endif /* MONO_CROSS_COMPILE */
 }
 
 /*
@@ -3303,39 +3297,13 @@ guint8*
 mono_aot_get_plt_entry (guint8 *code)
 {
        MonoAotModule *aot_module = find_aot_module (code);
-#if defined(__arm__) || defined(__mono_ppc__)
-       guint32 ins;
-#endif
 
        if (!aot_module)
                return NULL;
 
-#if defined(__i386__) || defined(__x86_64__)
-       if (code [-5] == 0xe8) {
-               guint32 disp = *(guint32*)(code - 4);
-               guint8 *target = code + disp;
-
-               if ((target >= (guint8*)(aot_module->plt)) && (target < (guint8*)(aot_module->plt_end)))
-                       return target;
-       }
-#elif defined(__arm__)
-       ins = ((guint32*)(gpointer)code) [-1];
-
-       /* Should be a 'bl' */
-       if ((((ins >> 25) & 0x7) == 0x5) && (((ins >> 24) & 0x1) == 0x1)) {
-               gint32 disp = ((gint32)ins) & 0xffffff;
-               guint8 *target = code - 4 + 8 + (disp * 4);
-
-               if ((target >= (guint8*)(aot_module->plt)) && (target < (guint8*)(aot_module->plt_end)))
-                       return target;
-       }               
-#elif defined(__mono_ppc__)
-       /* Should be a bl */
-       ins = ((guint32*)(gpointer)code) [-1];
-
-       if ((ins >> 26 == 18) && ((ins & 1) == 1) && ((ins & 2) == 0)) {
-               gint32 disp = (((gint32)ins) >> 2) & 0xffffff;
-               guint8 *target = code - 4 + (disp * 4);
+#ifdef MONO_ARCH_AOT_SUPPORTED
+       {
+               guint8 *target = mono_arch_get_call_target (code);
 
                if ((target >= (guint8*)(aot_module->plt)) && (target < (guint8*)(aot_module->plt_end)))
                        return target;
@@ -3360,19 +3328,8 @@ mono_aot_get_plt_info_offset (mgreg_t *regs, guint8 *code)
        g_assert (plt_entry);
 
        /* The offset is embedded inside the code after the plt entry */
-#if defined(__i386__)
-       return *(guint32*)(plt_entry + 6);
-#elif defined(__x86_64__)
-       return *(guint32*)(plt_entry + 6);
-#elif defined(__arm__)
-       /* The offset is stored as the 4th word of the plt entry */
-       return ((guint32*)plt_entry) [3];          
-#elif defined(__mono_ppc__)
-#ifdef PPC_USES_FUNCTION_DESCRIPTOR
-       return ((guint32*)plt_entry) [8];
-#else
-       return ((guint32*)plt_entry) [6];
-#endif
+#ifdef MONO_ARCH_AOT_SUPPORTED
+       return mono_arch_get_plt_info_offset (plt_entry, regs, code);
 #else
        g_assert_not_reached ();
        return 0;
index 7b7f745379aa4d3f6bda97d2bb0f65ab4f2bd184..0ac24538a61fc9dad9aa217b9e49f3331bde3e5d 100644 (file)
@@ -1822,6 +1822,8 @@ MonoMethod* mono_arch_find_imt_method           (mgreg_t *regs, guint8 *code) MO
 MonoVTable* mono_arch_find_static_call_vtable   (mgreg_t *regs, guint8 *code) MONO_INTERNAL;
 gpointer    mono_arch_build_imt_thunk           (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckItem **imt_entries, int count, gpointer fail_tramp) MONO_INTERNAL;
 void    mono_arch_notify_pending_exc            (void) MONO_INTERNAL;
+guint8* mono_arch_get_call_target               (guint8 *code) MONO_INTERNAL;
+guint32 mono_arch_get_plt_info_offset           (guint8 *plt_entry, mgreg_t *regs, guint8 *code) MONO_INTERNAL;
 
 /* Handle block guard */
 gpointer mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause, MonoContext *ctx, gpointer new_value) MONO_INTERNAL;
index 9e2a1acbdcfe947249cd7c2e77147961f71aaf1a..058c9b839b4d2b9ad3cf0ab9b9a1b0821e9ad9f1 100644 (file)
@@ -989,3 +989,32 @@ mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
        x86_push_imm (code, (guint64)func_arg);
        amd64_call_reg (code, AMD64_R11);
 }
+
+/*
+ * mono_arch_get_call_target:
+ *
+ *   Return the address called by the code before CODE if exists.
+ */
+guint8*
+mono_arch_get_call_target (guint8 *code)
+{
+       if (code [-5] == 0xe8) {
+               guint32 disp = *(guint32*)(code - 4);
+               guint8 *target = code + disp;
+
+               return target;
+       } else {
+               return NULL;
+       }
+}
+
+/*
+ * mono_arch_get_plt_info_offset:
+ *
+ *   Return the PLT info offset belonging to the plt entry PLT_ENTRY.
+ */
+guint32
+mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
+{
+       return *(guint32*)(plt_entry + 6);
+}
index d33ce05aba30af175619922563a548c24e0530ff..8113f1964b5f306dd56cb7115e11e8f71d94d42f 100644 (file)
@@ -708,3 +708,26 @@ mono_arch_create_generic_class_init_trampoline_full (MonoTrampInfo **info, gbool
 }
        
 #endif /* DISABLE_JIT */
+
+guint8*
+mono_arch_get_call_target (guint8 *code)
+{
+       guint32 ins = ((guint32*)(gpointer)code) [-1];
+
+       /* Should be a 'bl' */
+       if ((((ins >> 25) & 0x7) == 0x5) && (((ins >> 24) & 0x1) == 0x1)) {
+               gint32 disp = ((gint32)ins) & 0xffffff;
+               guint8 *target = code - 4 + 8 + (disp * 4);
+
+               return target;
+       } else {
+               return NULL;
+       }
+}
+
+guint32
+mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
+{
+       /* The offset is stored as the 4th word of the plt entry */
+       return ((guint32*)plt_entry) [3];
+}
index 9443484a89fa559f02b19a7b7cb1ff4f375f6c86..089fc65c8a3ea458a7b7a87b915dad3b9453aff5 100644 (file)
@@ -704,3 +704,29 @@ mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info)
 
        return buf;
 }
+
+guint8*
+mono_arch_get_call_target (guint8 *code)
+{
+       /* Should be a bl */
+       guint32 ins = ((guint32*)(gpointer)code) [-1];
+
+       if ((ins >> 26 == 18) && ((ins & 1) == 1) && ((ins & 2) == 0)) {
+               gint32 disp = (((gint32)ins) >> 2) & 0xffffff;
+               guint8 *target = code - 4 + (disp * 4);
+
+               return target;
+       } else {
+               return NULL;
+       }
+}
+
+guint32
+mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
+{
+#ifdef PPC_USES_FUNCTION_DESCRIPTOR
+       return ((guint32*)plt_entry) [8];
+#else
+       return ((guint32*)plt_entry) [6];
+#endif
+}
index 0c1eb121de98e6f5955328b82243a995ba6e1472..309aff75d184e6a04a8d627b9d336457bbd23ff3 100644 (file)
@@ -931,3 +931,22 @@ mono_arch_create_handler_block_trampoline (void)
 
        return buf;
 }
+
+guint8*
+mono_arch_get_call_target (guint8 *code)
+{
+       if (code [-5] == 0xe8) {
+               guint32 disp = *(guint32*)(code - 4);
+               guint8 *target = code + disp;
+
+               return target;
+       } else {
+               return NULL;
+       }
+}
+
+guint32
+mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
+{
+       return *(guint32*)(plt_entry + 6);
+}