#include <mono/metadata/marshal.h>
#include <mono/metadata/tabledefs.h>
#include <mono/arch/arm/arm-codegen.h>
+#include <mono/arch/arm/arm-vfp-codegen.h>
#include "mini.h"
#include "mini-arm.h"
#define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1))
-static guint8* nullified_class_init_trampoline;
-
-
#ifdef USE_JUMP_TABLES
static guint16
decode_imm16 (guint32 insn)
{
- return (((insn >> 16) & 0xf) << 12) | (insn & 0xfff);
+ return (((insn >> 16) & 0xf) << 12) | (insn & 0xfff);
}
#define INSN_MASK 0xff00000
gpointer*
mono_arch_jumptable_entry_from_code (guint8 *code)
{
- guint32 insn1 = ((guint32*)code) [0];
- guint32 insn2 = ((guint32*)code) [1];
-
- if (((insn1 & INSN_MASK) == MOVW_MASK) &&
- ((insn2 & INSN_MASK) == MOVT_MASK) ) {
- guint32 imm_lo = decode_imm16 (insn1);
- guint32 imm_hi = decode_imm16 (insn2);
- return (gpointer*) GUINT_TO_POINTER (imm_lo | (imm_hi << 16));
- } else {
- g_assert_not_reached ();
- return NULL;
- }
+ guint32 insn1 = ((guint32*)code) [0];
+ guint32 insn2 = ((guint32*)code) [1];
+
+ if (((insn1 & INSN_MASK) == MOVW_MASK) &&
+ ((insn2 & INSN_MASK) == MOVT_MASK) ) {
+ guint32 imm_lo = decode_imm16 (insn1);
+ guint32 imm_hi = decode_imm16 (insn2);
+ return (gpointer*) GUINT_TO_POINTER (imm_lo | (imm_hi << 16));
+ } else {
+ g_assert_not_reached ();
+ return NULL;
+ }
}
#undef INSN_MASK
void
mono_arch_nullify_class_init_trampoline (guint8 *code, mgreg_t *regs)
{
- mono_arch_patch_callsite (NULL, code, nullified_class_init_trampoline);
+ mono_arch_patch_callsite (NULL, code, mini_get_nullified_class_init_trampoline ());
}
void
mono_arch_nullify_plt_entry (guint8 *code, mgreg_t *regs)
{
- if (mono_aot_only && !nullified_class_init_trampoline)
- nullified_class_init_trampoline = mono_aot_get_trampoline ("nullified_class_init_trampoline");
-
- mono_arch_patch_plt_entry (code, NULL, regs, nullified_class_init_trampoline);
+ mono_arch_patch_plt_entry (code, NULL, regs, mini_get_nullified_class_init_trampoline ());
}
#ifndef DISABLE_JIT
return code;
}
-/* Stack size for trampoline function
+/* Stack size for trampoline function
*/
#define STACK ALIGN_TO (sizeof (MonoLMF), 8)
guchar*
mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
{
+ char *tramp_name;
guint8 *buf, *code = NULL;
#ifdef USE_JUMP_TABLES
gpointer *load_get_lmf_addr = NULL, *load_trampoline = NULL;
gpointer *constants;
#endif
- int cfa_offset, lmf_offset, regsave_size, lr_offset;
+ int cfa_offset, regsave_size, lr_offset;
GSList *unwind_ops = NULL;
MonoJumpInfo *ji = NULL;
int buf_len;
/* Now we'll create in 'buf' the ARM trampoline code. This
is the trampoline code common to all methods */
- buf_len = 212;
+ buf_len = 272;
+
+ /* Add space for saving/restoring VFP regs. */
+ if (mono_arm_is_hard_float ())
+ buf_len += 8 * 2;
+
code = buf = mono_global_codeman_reserve (buf_len);
/*
* saved as sp + LR_OFFSET by the push in the specific trampoline
*/
- /* The offset of lmf inside the stack frame */
- lmf_offset = STACK - sizeof (MonoLMF);
/* The size of the area already allocated by the push in the specific trampoline */
regsave_size = 14 * sizeof (mgreg_t);
/* The offset where lr was saved inside the regsave area */
* The pointer to the struct is put in r1.
* the iregs array is already allocated on the stack by push.
*/
- ARM_SUB_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, STACK - regsave_size);
+ code = mono_arm_emit_load_imm (code, ARMREG_R2, STACK - regsave_size);
+ ARM_SUB_REG_REG (code, ARMREG_SP, ARMREG_SP, ARMREG_R2);
cfa_offset += STACK - regsave_size;
mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset);
/* V1 == lmf */
- ARM_ADD_REG_IMM8 (code, ARMREG_V1, ARMREG_SP, STACK - sizeof (MonoLMF));
+ code = mono_arm_emit_load_imm (code, ARMREG_R2, STACK - sizeof (MonoLMF));
+ ARM_ADD_REG_REG (code, ARMREG_V1, ARMREG_SP, ARMREG_R2);
/*
* The stack now looks like:
ARM_STR_IMM (code, ARMREG_R2, ARMREG_V1, G_STRUCT_OFFSET (MonoLMF, method));
}
/* save caller SP */
- ARM_ADD_REG_IMM8 (code, ARMREG_R2, ARMREG_SP, cfa_offset);
+ code = mono_arm_emit_load_imm (code, ARMREG_R2, cfa_offset);
+ ARM_ADD_REG_REG (code, ARMREG_R2, ARMREG_SP, ARMREG_R2);
ARM_STR_IMM (code, ARMREG_R2, ARMREG_V1, G_STRUCT_OFFSET (MonoLMF, sp));
/* save caller FP */
ARM_LDR_IMM (code, ARMREG_R2, ARMREG_V1, (G_STRUCT_OFFSET (MonoLMF, iregs) + ARMREG_FP*4));
}
ARM_STR_IMM (code, ARMREG_R2, ARMREG_V1, G_STRUCT_OFFSET (MonoLMF, ip));
+ /* Save VFP registers. */
+ if (mono_arm_is_hard_float ()) {
+ /*
+ * Strictly speaking, we don't have to save d0-d7 in the LMF, but
+ * it's easier than attempting to store them on the stack since
+ * this trampoline code is pretty messy.
+ */
+ ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_V1, G_STRUCT_OFFSET (MonoLMF, fregs));
+ ARM_FSTMD (code, ARM_VFP_D0, 8, ARMREG_R0);
+ }
+
/*
* Now we're ready to call xxx_trampoline ().
*/
/* Arg 1: the saved registers */
- ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_V1, G_STRUCT_OFFSET (MonoLMF, iregs));
+ ARM_ADD_REG_IMM (code, ARMREG_R0, ARMREG_V1, G_STRUCT_OFFSET (MonoLMF, iregs), 0);
/* Arg 2: code (next address to the instruction that called us) */
if (tramp_type == MONO_TRAMPOLINE_JUMP) {
/* *(lmf_addr) = previous_lmf */
ARM_STR_IMM (code, ARMREG_IP, ARMREG_LR, G_STRUCT_OFFSET (MonoLMF, previous_lmf));
+ /* Restore VFP registers. */
+ if (mono_arm_is_hard_float ()) {
+ ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_V1, G_STRUCT_OFFSET (MonoLMF, fregs));
+ ARM_FLDMD (code, ARM_VFP_D0, 8, ARMREG_R0);
+ }
+
/* Non-standard function epilogue. Instead of doing a proper
* return, we just jump to the compiled code.
*/
/* Sanity check */
g_assert ((code - buf) <= buf_len);
- if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT)
- /* Initialize the nullified class init trampoline used in the AOT case */
- nullified_class_init_trampoline = mono_arch_get_nullified_class_init_trampoline (NULL);
-
- if (info)
- *info = mono_tramp_info_create (mono_get_generic_trampoline_name (tramp_type), buf, code - buf, ji, unwind_ops);
+ if (info) {
+ tramp_name = mono_get_generic_trampoline_name (tramp_type);
+ *info = mono_tramp_info_create (tramp_name, buf, code - buf, ji, unwind_ops);
+ g_free (tramp_name);
+ }
return buf;
}
mono_arch_flush_icache (buf, code - buf);
if (info)
- *info = mono_tramp_info_create (g_strdup_printf ("nullified_class_init_trampoline"), buf, code - buf, NULL, NULL);
+ *info = mono_tramp_info_create ("nullified_class_init_trampoline", buf, code - buf, NULL, NULL);
return buf;
}
#ifdef USE_JUMP_TABLES
/* For jumptables case we always generate the same code for trampolines,
- * namely
+ * namely
* push {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}
* movw lr, lo(jte)
* movt lr, hi(jte)
* bx r1
*/
ARM_PUSH (code, 0x5fff);
- constants = mono_jumptable_add_entries (2);
- code = mono_arm_load_jumptable_entry_addr (code, constants, ARMREG_LR);
- ARM_LDR_IMM (code, ARMREG_R1, ARMREG_LR, 4);
+ constants = mono_jumptable_add_entries (2);
+ code = mono_arm_load_jumptable_entry_addr (code, constants, ARMREG_LR);
+ ARM_LDR_IMM (code, ARMREG_R1, ARMREG_LR, 4);
code = emit_bx (code, ARMREG_R1);
- constants[0] = arg1;
- constants[1] = tramp;
+ constants [0] = arg1;
+ constants [1] = tramp;
#else
/* we could reduce this to 12 bytes if tramp is within reach:
* ARM_PUSH ()
MonoDomain *domain = mono_domain_get ();
#ifdef USE_JUMP_TABLES
gpointer *jte;
- guint32 size = 20;
+ guint32 size = 20;
#else
guint32 size = 16;
#endif
g_assert (code - buf <= tramp_size);
- if (info)
- *info = mono_tramp_info_create (mono_get_rgctx_fetch_trampoline_name (slot), buf, code - buf, ji, unwind_ops);
+ if (info) {
+ char *name = mono_get_rgctx_fetch_trampoline_name (slot);
+ *info = mono_tramp_info_create (name, buf, code - buf, ji, unwind_ops);
+ g_free (name);
+ }
return buf;
}
g_assert (code - buf <= tramp_size);
if (info)
- *info = mono_tramp_info_create (g_strdup_printf ("generic_class_init_trampoline"), buf, code - buf, ji, unwind_ops);
+ *info = mono_tramp_info_create ("generic_class_init_trampoline", buf, code - buf, ji, unwind_ops);
return buf;
}
g_assert_not_reached ();
return NULL;
}
+
+gpointer
+mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
#endif /* DISABLE_JIT */
return start;
}
+#else
+
+gpointer
+mono_arch_get_gsharedvt_arg_trampoline (MonoDomain *domain, gpointer arg, gpointer addr)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
#endif
-#if defined(MONOTOUCH) || defined(MONO_EXTENSIONS)
+#if defined(ENABLE_GSHAREDVT)
#include "../../../mono-extensions/mono/mini/tramp-arm-gsharedvt.c"
#else
gpointer
-mono_arm_start_gsharedvt_call (GSharedVtCallInfo *info, gpointer *caller, gpointer *callee, gpointer *caller_regs, gpointer *callee_regs, gpointer mrgctx_reg)
+mono_arm_start_gsharedvt_call (GSharedVtCallInfo *info, gpointer *caller, gpointer *callee, gpointer mrgctx_reg)
{
g_assert_not_reached ();
return NULL;