* Makefile.am (test_sources2): Add generics.2.cs.
[mono.git] / mono / mini / tramp-ia64.c
index bc36ec7515357ba176d5cd7bed2c05550d3910df..4356e2502c40178f62e9e9a615ca41878d7d8e98 100644 (file)
@@ -158,6 +158,24 @@ mono_arch_nullify_class_init_trampoline (guint8 *code, gssize *regs)
        mono_arch_flush_icache (callsite_begin, code - callsite_begin);
 }
 
+void
+mono_arch_patch_delegate_trampoline (guint8 *code, guint8 *tramp, gssize *regs, guint8 *addr)
+{
+       /* 
+        * This is called by the code generated by OP_CALL_REG:
+        * ld8 r30=[r8],8
+        * nop.i 0x0;;
+        * mov.sptk b6=r30
+        * ld8 r1=[r8]
+        * br.call.sptk.few b0=b6
+        */
+
+       /* We patch the function descriptor instead of delegate->method_ptr */
+       //g_assert (((gpointer*)(regs [8] - 8))[0] == tramp);
+       ((gpointer*)(regs [8] - 8))[0] = mono_get_addr_from_ftnptr (addr);
+       ((gpointer*)(regs [8] - 8))[1] = NULL;
+}
+
 guchar*
 mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
 {
@@ -212,7 +230,9 @@ mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
         * 16 locals
         * 4 output (number of parameters passed to trampoline)
         */
+       ia64_unw_save_reg (code, UNW_IA64_AR_PFS, UNW_IA64_GR + l5);
        ia64_alloc (code, l5, local0 - in0, out0 - local0, 4, 0);
+       ia64_unw_save_reg (code, UNW_IA64_SP, UNW_IA64_GR + l8);
        ia64_mov (code, l8, IA64_SP);
        ia64_adds_imm (code, IA64_SP, (-framesize), IA64_SP);
 
@@ -222,22 +242,12 @@ mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
        ia64_mov (code, l6, GP_SCRATCH_REG);
 
        /* Save the calling address */
+       ia64_unw_save_reg (code, UNW_IA64_RP, UNW_IA64_GR + local0 + 7);
        ia64_mov_from_br (code, l7, IA64_B0);
 
-       /* FIXME: Emit prolog/epilog manually */
-
        /* Create unwind info for the prolog */
-       r_pro = g_malloc0 (_U_dyn_region_info_size (3));
-       r_pro->op_count = 3;
-       r_pro->insn_count = 16;
-       i = 0;
-       _U_dyn_op_save_reg (&r_pro->op[i++], _U_QP_TRUE, /* when=*/ 2,
-                                               /* reg=*/ UNW_IA64_AR_PFS, /* dst=*/ UNW_IA64_GR + local0 + 5);
-       _U_dyn_op_save_reg (&r_pro->op[i++], _U_QP_TRUE, /* when=*/ 5,
-                                               /* reg=*/ UNW_IA64_SP, /* dst=*/ UNW_IA64_GR + local0 + 8);
-       _U_dyn_op_save_reg (&r_pro->op[i++], _U_QP_TRUE, /* when=*/ 14,
-                                               /* reg=*/ UNW_IA64_RP, /* dst=*/ UNW_IA64_GR + local0 + 7);
-       g_assert ((unsigned) i <= r_pro->op_count);     
+       ia64_begin_bundle (code);
+       r_pro = mono_ia64_create_unwind_region (&code);
 
        /* Save registers */
        /* Not needed for jump trampolines */
@@ -253,7 +263,7 @@ mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
                        if ((1 << i) & MONO_ARCH_CALLEE_REGS) {
                                if (last_offset != i * 8)
                                        ia64_adds_imm (code, l1, saved_regs_offset + (i * 8), IA64_SP);
-                               ia64_st8_inc_imm_hint (code, l1, i, 8, 0);
+                               ia64_st8_spill_inc_imm_hint (code, l1, i, 8, 0);
                                last_offset = (i + 1) * 8;
                        }
        }
@@ -287,6 +297,8 @@ mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
                tramp = (guint8*)mono_class_init_trampoline;
        else if (tramp_type == MONO_TRAMPOLINE_AOT)
                tramp = (guint8*)mono_aot_trampoline;
+       else if (tramp_type == MONO_TRAMPOLINE_DELEGATE)
+               tramp = (guint8*)mono_delegate_trampoline;
        else
                tramp = (guint8*)mono_magic_trampoline;