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
static void
init_plt (MonoAotModule *amodule)
{
-#ifndef MONO_CROSS_COMPILE
-
-#ifdef MONO_ARCH_AOT_SUPPORTED
int i;
gpointer plt_0;
gpointer tramp;
((gpointer*)amodule->got)[amodule->info.plt_got_offset_base + i] = plt_0;
amodule->plt_inited = TRUE;
-#endif
-
-#endif /* MONO_CROSS_COMPILE */
}
/*
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;
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;
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;
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);
+}
}
#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];
+}
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
+}
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);
+}