if (MONO_TYPE_ISSTRUCT (mono_method_signature (m)->ret))
this_pos = 1;
- mono_domain_lock (domain);
- start = code = mono_code_manager_reserve (domain->code_mp, 16);
- mono_domain_unlock (domain);
+ start = code = mono_domain_code_reserve (domain, 16);
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 4);
ARM_ADD_REG_IMM8 (code, this_pos, this_pos, sizeof (MonoObject));
return start;
}
+gpointer
+mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
+{
+ guint8 *code, *start;
+ int buf_len;
+
+ MonoDomain *domain = mono_domain_get ();
+
+ buf_len = 16;
+
+ start = code = mono_domain_code_reserve (domain, buf_len);
+
+ ARM_LDR_IMM (code, MONO_ARCH_RGCTX_REG, ARMREG_PC, 0);
+ ARM_LDR_IMM (code, ARMREG_PC, ARMREG_PC, 0);
+ *(guint32*)code = (guint32)mrgctx;
+ code += 4;
+ *(guint32*)code = (guint32)addr;
+ code += 4;
+
+ g_assert ((code - start) <= buf_len);
+
+ mono_arch_flush_icache (start, code - start);
+
+ return start;
+}
+
void
mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
{
{
MonoJumpInfo *ji;
guint32 code_size;
+ guchar *code;
+ GSList *unwind_ops, *l;
+
+ code = mono_arch_create_trampoline_code_full (tramp_type, &code_size, &ji, &unwind_ops, FALSE);
- return mono_arch_create_trampoline_code_full (tramp_type, &code_size, &ji, FALSE);
+ mono_save_trampoline_xdebug_info ("<generic_trampoline>", code, code_size, unwind_ops);
+
+ for (l = unwind_ops; l; l = l->next)
+ g_free (l->data);
+ g_slist_free (unwind_ops);
+
+ return code;
}
guchar*
-mono_arch_create_trampoline_code_full (MonoTrampolineType tramp_type, guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
+mono_arch_create_trampoline_code_full (MonoTrampolineType tramp_type, guint32 *code_size, MonoJumpInfo **ji, GSList **out_unwind_ops, gboolean aot)
{
guint8 *buf, *code = NULL;
guint8 *load_get_lmf_addr, *load_trampoline;
gpointer *constants;
+ GSList *unwind_ops = NULL;
+ int cfa_offset;
*ji = NULL;
* saved as sp + LR_OFFSET by the push in the specific trampoline
*/
#define LR_OFFSET (sizeof (gpointer) * 13)
+
+ // FIXME: Finish the unwind info, the current info allows us to unwind
+ // when the trampoline is not in the epilog
+
+ // CFA = SP + (num registers pushed) * 4
+ cfa_offset = 14 * sizeof (gpointer);
+ mono_add_unwind_op_def_cfa (unwind_ops, code, buf, ARMREG_SP, cfa_offset);
+ // PC saved at sp+LR_OFFSET
+ mono_add_unwind_op_offset (unwind_ops, code, buf, ARMREG_LR, -4);
+
ARM_MOV_REG_REG (code, ARMREG_V1, ARMREG_SP);
if (aot && tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT) {
/*
- * The trampoline contains a pc-relative offset to the got slot where the
- * value is stored. The offset can be found at [lr + 4].
+ * The trampoline contains a pc-relative offset to the got slot
+ * preceeding the got slot where the value is stored. The offset can be
+ * found at [lr + 0].
*/
- ARM_LDR_IMM (code, ARMREG_V2, ARMREG_LR, 4);
+ ARM_LDR_IMM (code, ARMREG_V2, ARMREG_LR, 0);
+ ARM_ADD_REG_IMM (code, ARMREG_V2, ARMREG_V2, 4, 0);
ARM_LDR_REG_REG (code, ARMREG_V2, ARMREG_V2, ARMREG_LR);
} else {
if (tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
* the iregs array is already allocated on the stack by push.
*/
ARM_SUB_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, sizeof (MonoLMF) - sizeof (guint) * 14);
+ cfa_offset += sizeof (MonoLMF) - sizeof (guint) * 14;
+ mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset);
ARM_ADD_REG_IMM8 (code, ARMREG_R1, ARMREG_SP, STACK - sizeof (MonoLMF));
/* r0 is the result from mono_get_lmf_addr () */
ARM_STR_IMM (code, ARMREG_R0, ARMREG_R1, G_STRUCT_OFFSET (MonoLMF, lmf_addr));
code += 8;
/* Flush instruction cache, since we've generated code */
- mono_arch_flush_icache (code, code - buf);
+ mono_arch_flush_icache (buf, code - buf);
/* Sanity check */
g_assert ((code - buf) <= GEN_TRAMP_SIZE);
nullified_class_init_trampoline = mono_arch_get_nullified_class_init_trampoline (&code_len);
}
+ *out_unwind_ops = unwind_ops;
+
return buf;
}
ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_LR);
- mono_arch_flush_icache (code, code - buf);
+ mono_arch_flush_icache (buf, code - buf);
*code_len = code - buf;
tramp = mono_get_trampoline_code (tramp_type);
mono_domain_lock (domain);
- code = buf = mono_code_manager_reserve_align (domain->code_mp, size, 4);
+ code = buf = mono_domain_code_reserve_align (domain, size, 4);
if ((short_branch = branch_for_target_reachable (code + 8, tramp))) {
size = 12;
- mono_code_manager_commit (domain->code_mp, code, SPEC_TRAMP_SIZE, size);
+ mono_domain_code_commit (domain, code, SPEC_TRAMP_SIZE, size);
}
mono_domain_unlock (domain);
}
/* Flush instruction cache, since we've generated code */
- mono_arch_flush_icache (code, code - buf);
+ mono_arch_flush_icache (buf, code - buf);
g_assert ((code - buf) <= size);
/* Jump to the actual trampoline */
ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0); /* temp reg */
ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_R1);
- *(guint32*)code = tramp;
+ *(gpointer*)code = tramp;
code += 4;
}
gpointer
mono_arch_create_generic_class_init_trampoline (void)
+{
+ guint32 code_size;
+ MonoJumpInfo *ji;
+
+ return mono_arch_create_generic_class_init_trampoline_full (&code_size, &ji, FALSE);
+}
+
+gpointer
+mono_arch_create_generic_class_init_trampoline_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
{
guint8 *tramp;
guint8 *code, *buf;
guint32 code_len, imm8;
gint rot_amount;
+ *ji = NULL;
+
tramp_size = 64;
code = buf = mono_global_codeman_reserve (tramp_size);
/* Uninitialized case */
arm_patch (jump, code);
- tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT, mono_get_root_domain (), &code_len);
+ if (aot) {
+ *ji = mono_patch_info_list_prepend (*ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_generic_class_init");
+ ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0);
+ ARM_B (code, 0);
+ *(gpointer*)code = NULL;
+ code += 4;
+ ARM_LDR_REG_REG (code, ARMREG_PC, ARMREG_PC, ARMREG_R1);
+ } else {
+ tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT, mono_get_root_domain (), &code_len);
- /* Jump to the actual trampoline */
- ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0); /* temp reg */
- ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_R1);
- *(guint32*)code = tramp;
- code += 4;
+ /* Jump to the actual trampoline */
+ ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0); /* temp reg */
+ ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_R1);
+ *(gpointer*)code = tramp;
+ code += 4;
+ }
mono_arch_flush_icache (buf, code - buf);
g_assert (code - buf <= tramp_size);
+ *code_size = code - buf;
+
return buf;
}