Merge branch 'master' into msbuilddll2
[mono.git] / mono / mini / tramp-ppc.c
index 694392c136514b1e484d05ac6db910f3d3343865..7cec84281ebd8c12065fb0b56256d0156647873b 100644 (file)
@@ -22,8 +22,7 @@
 #include "mini.h"
 #include "mini-ppc.h"
 
-static guint8* nullified_class_init_trampoline;
-
+#if 0
 /* Same as mono_create_ftnptr, but doesn't require a domain */
 static gpointer
 mono_ppc_create_ftnptr (guint8 *code)
@@ -40,6 +39,7 @@ mono_ppc_create_ftnptr (guint8 *code)
        return code;
 #endif
 }
+#endif
 
 /*
  * Return the instruction to jump from code to target, 0 if not
@@ -63,7 +63,6 @@ branch_for_target_reachable (guint8 *branch, guint8 *target)
 
 /*
  * get_unbox_trampoline:
- * @gsctx: the generic sharing context
  * @m: method pointer
  * @addr: pointer to native code for @m
  *
@@ -72,7 +71,7 @@ branch_for_target_reachable (guint8 *branch, guint8 *target)
  * unboxing before calling the method
  */
 gpointer
-mono_arch_get_unbox_trampoline (MonoGenericSharingContext *gsctx, MonoMethod *m, gpointer addr)
+mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
 {
        guint8 *code, *start;
        int this_pos = 3;
@@ -82,9 +81,6 @@ mono_arch_get_unbox_trampoline (MonoGenericSharingContext *gsctx, MonoMethod *m,
 
        addr = mono_get_addr_from_ftnptr (addr);
 
-       if (MONO_TYPE_ISSTRUCT (mono_method_signature (m)->ret))
-               this_pos = 4;
-           
        mono_domain_lock (domain);
        start = code = mono_domain_code_reserve (domain, size);
        code = mono_ppc_create_pre_code_ftnptr (code);
@@ -97,7 +93,7 @@ mono_arch_get_unbox_trampoline (MonoGenericSharingContext *gsctx, MonoMethod *m,
                ppc_addi (code, this_pos, this_pos, sizeof (MonoObject));
                ppc_emit32 (code, short_branch);
        } else {
-               ppc_load (code, ppc_r0, addr);
+               ppc_load_ptr (code, ppc_r0, addr);
                ppc_mtctr (code, ppc_r0);
                ppc_addi (code, this_pos, this_pos, sizeof (MonoObject));
                ppc_bcctr (code, 20, 0);
@@ -129,7 +125,7 @@ mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericCo
 
        /* Compute size of code needed to emit mrgctx */
        p = imm_buf;
-       ppc_load (p, MONO_ARCH_RGCTX_REG, mrgctx);
+       ppc_load_ptr (p, MONO_ARCH_RGCTX_REG, mrgctx);
        imm_size = p - imm_buf;
 
        mono_domain_lock (domain);
@@ -141,12 +137,12 @@ mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericCo
        mono_domain_unlock (domain);
 
        if (short_branch) {
-               ppc_load (code, MONO_ARCH_RGCTX_REG, mrgctx);
+               ppc_load_ptr (code, MONO_ARCH_RGCTX_REG, mrgctx);
                ppc_emit32 (code, short_branch);
        } else {
-               ppc_load (code, ppc_r0, addr);
+               ppc_load_ptr (code, ppc_r0, addr);
                ppc_mtctr (code, ppc_r0);
-               ppc_load (code, MONO_ARCH_RGCTX_REG, mrgctx);
+               ppc_load_ptr (code, MONO_ARCH_RGCTX_REG, mrgctx);
                ppc_bcctr (code, 20, 0);
        }
        mono_arch_flush_icache (start, code - start);
@@ -197,30 +193,27 @@ mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *a
 
        /* Either got or regs is set */
        if (!got)
-               got = (gpointer*)regs [30];
+               got = (gpointer*)(gsize) regs [30];
        *(guint8**)((guint8*)got + offset) = addr;
 }
 
 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_named_code ("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 ());
 }
 
 /* Stack size for trampoline function 
  * PPC_MINIMAL_STACK_SIZE + 16 (args + alignment to ppc_magic_trampoline)
- * + MonoLMF + 14 fp regs + 31 gregs + alignment
+ * + MonoLMF + 14 fp regs + 13 gregs + alignment
  */
-#define STACK (PPC_MINIMAL_STACK_SIZE + 4 * sizeof (gulong) + sizeof (MonoLMF) + 14 * sizeof (double) + 31 * sizeof (gulong))
+#define STACK (((PPC_MINIMAL_STACK_SIZE + 4 * sizeof (mgreg_t) + sizeof (MonoLMF) + 14 * sizeof (double) + 31 * sizeof (mgreg_t)) + (MONO_ARCH_FRAME_ALIGNMENT - 1)) & ~(MONO_ARCH_FRAME_ALIGNMENT - 1))
 
 /* Method-specific trampoline code fragment size */
 #define METHOD_TRAMPOLINE_SIZE 64
@@ -234,25 +227,6 @@ mono_arch_nullify_plt_entry (guint8 *code, mgreg_t *regs)
 #define PPC_TOC_REG -1
 #endif
 
-guchar*
-mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
-{
-       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);
-
-       //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;
-}
-
 /*
  * Stack frame description when the generic trampoline is called.
  * caller frame
@@ -269,132 +243,134 @@ mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
  *  -------------------
  */
 guchar*
-mono_arch_create_trampoline_code_full (MonoTrampolineType tramp_type, guint32 *code_size, MonoJumpInfo **ji, GSList **out_unwind_ops, gboolean aot)
+mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
 {
+       char *tramp_name;
        guint8 *buf, *code = NULL;
        int i, offset;
        gconstpointer tramp_handler;
        int size = MONO_PPC_32_64_CASE (600, 800);
+       GSList *unwind_ops = NULL;
+       MonoJumpInfo *ji = NULL;
 
        /* Now we'll create in 'buf' the PowerPC trampoline code. This
           is the trampoline code common to all methods  */
 
        code = buf = mono_global_codeman_reserve (size);
 
-       *ji = NULL;
-       *out_unwind_ops = NULL;
-
-       ppc_stptr_update (buf, ppc_r1, -STACK, ppc_r1);
+       ppc_str_update (code, ppc_r1, -STACK, ppc_r1);
 
        /* start building the MonoLMF on the stack */
        offset = STACK - sizeof (double) * MONO_SAVED_FREGS;
        for (i = 14; i < 32; i++) {
-               ppc_stfd (buf, i, offset, ppc_r1);
+               ppc_stfd (code, i, offset, ppc_r1);
                offset += sizeof (double);
        }
        /* 
         * now the integer registers.
         */
        offset = STACK - sizeof (MonoLMF) + G_STRUCT_OFFSET (MonoLMF, iregs);
-       ppc_store_multiple_regs (buf, ppc_r13, offset, ppc_r1);
+       ppc_str_multiple (code, ppc_r13, offset, ppc_r1);
 
        /* Now save the rest of the registers below the MonoLMF struct, first 14
         * fp regs and then the 31 gregs.
         */
        offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double));
        for (i = 0; i < 14; i++) {
-               ppc_stfd (buf, i, offset, ppc_r1);
+               ppc_stfd (code, i, offset, ppc_r1);
                offset += sizeof (double);
        }
-#define GREGS_OFFSET (STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (31 * sizeof (gulong)))
+#define GREGS_OFFSET (STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (31 * sizeof (mgreg_t)))
        offset = GREGS_OFFSET;
        for (i = 0; i < 31; i++) {
-               ppc_stptr (buf, i, offset, ppc_r1);
-               offset += sizeof (gulong);
+               ppc_str (code, i, offset, ppc_r1);
+               offset += sizeof (mgreg_t);
        }
 
        /* we got here through a jump to the ctr reg, we must save the lr
         * in the parent frame (we do it here to reduce the size of the
         * method-specific trampoline)
         */
-       ppc_mflr (buf, ppc_r0);
-       ppc_stptr (buf, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
+       ppc_mflr (code, ppc_r0);
+       ppc_str (code, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
 
        /* ok, now we can continue with the MonoLMF setup, mostly untouched 
         * from emit_prolog in mini-ppc.c
         */
        if (aot) {
-               buf = mono_arch_emit_load_aotconst (code, buf, ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_get_lmf_addr");
+               code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_get_lmf_addr");
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-               ppc_ldptr (buf, ppc_r2, sizeof (gpointer), ppc_r11);
-               ppc_ldptr (buf, ppc_r11, 0, ppc_r11);
+               ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
+               ppc_ldptr (code, ppc_r11, 0, ppc_r11);
 #endif
-               ppc_mtlr (buf, ppc_r11);
-               ppc_blrl (buf);
+               ppc_mtlr (code, ppc_r11);
+               ppc_blrl (code);
        }  else {
-               ppc_load_func (buf, ppc_r0, mono_get_lmf_addr);
-               ppc_mtlr (buf, ppc_r0);
-               ppc_blrl (buf);
+               ppc_load_func (code, ppc_r0, mono_get_lmf_addr);
+               ppc_mtlr (code, ppc_r0);
+               ppc_blrl (code);
        }
        /* we build the MonoLMF structure on the stack - see mini-ppc.h
         * The pointer to the struct is put in ppc_r11.
         */
-       ppc_addi (buf, ppc_r11, ppc_sp, STACK - sizeof (MonoLMF));
-       ppc_stptr (buf, ppc_r3, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
+       ppc_addi (code, ppc_r11, ppc_sp, STACK - sizeof (MonoLMF));
+       ppc_stptr (code, ppc_r3, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
        /* new_lmf->previous_lmf = *lmf_addr */
-       ppc_ldptr (buf, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
-       ppc_stptr (buf, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
+       ppc_ldptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
+       ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
        /* *(lmf_addr) = r11 */
-       ppc_stptr (buf, ppc_r11, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
-       /* save method info (it's stored on the stack, so get it first and put it
-        * in r5 as it's the third argument to the function)
-        */
-       if (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
-               ppc_ldptr (buf, ppc_r5, GREGS_OFFSET + PPC_FIRST_ARG_REG * sizeof (gpointer), ppc_r1);
-       else
-               ppc_ldptr (buf, ppc_r5, GREGS_OFFSET, ppc_r1);
-       if ((tramp_type == MONO_TRAMPOLINE_JIT) || (tramp_type == MONO_TRAMPOLINE_JUMP))
-               ppc_stptr (buf, ppc_r5, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
+       ppc_stptr (code, ppc_r11, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
+       /* save method info (it's stored on the stack, so get it first). */
+       if ((tramp_type == MONO_TRAMPOLINE_JIT) || (tramp_type == MONO_TRAMPOLINE_JUMP)) {
+               ppc_ldr (code, ppc_r0, GREGS_OFFSET, ppc_r1);
+               ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
+       } else {
+               ppc_load (code, ppc_r0, 0);
+               ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
+       }
        /* store the frame pointer of the calling method */
-       ppc_addi (buf, ppc_r0, ppc_sp, STACK);
-       ppc_stptr (buf, ppc_r0, G_STRUCT_OFFSET(MonoLMF, ebp), ppc_r11);
+       ppc_addi (code, ppc_r0, ppc_sp, STACK);
+       ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, ebp), ppc_r11);
        /* save the IP (caller ip) */
        if (tramp_type == MONO_TRAMPOLINE_JUMP) {
-               ppc_li (buf, ppc_r0, 0);
+               ppc_li (code, ppc_r0, 0);
        } else {
-               ppc_ldptr (buf, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
+               ppc_ldr (code, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
        }
-       ppc_stptr (buf, ppc_r0, G_STRUCT_OFFSET(MonoLMF, eip), ppc_r11);
+       ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, eip), ppc_r11);
 
        /*
         * Now we're ready to call trampoline (mgreg_t *regs, guint8 *code, gpointer value, guint8 *tramp)
         * Note that the last argument is unused.
         */
        /* Arg 1: a pointer to the registers */
-       ppc_addi (buf, ppc_r3, ppc_r1, GREGS_OFFSET);
+       ppc_addi (code, ppc_r3, ppc_r1, GREGS_OFFSET);
                
        /* Arg 2: code (next address to the instruction that called us) */
        if (tramp_type == MONO_TRAMPOLINE_JUMP)
-               ppc_li (buf, ppc_r4, 0);
+               ppc_li (code, ppc_r4, 0);
        else
-               ppc_ldptr  (buf, ppc_r4, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
+               ppc_ldr  (code, ppc_r4, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
 
-       /* Arg 3: MonoMethod *method. It was put in r5 already above */
-       /*ppc_mr  (buf, ppc_r5, ppc_r5);*/
+       /* Arg 3: trampoline argument */
+       if (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
+               ppc_ldr (code, ppc_r5, GREGS_OFFSET + MONO_ARCH_VTABLE_REG * sizeof (mgreg_t), ppc_r1);
+       else
+               ppc_ldr (code, ppc_r5, GREGS_OFFSET, ppc_r1);
 
        if (aot) {
-               buf = mono_arch_emit_load_aotconst (code, buf, ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("trampoline_func_%d", tramp_type));
+               code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("trampoline_func_%d", tramp_type));
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-               ppc_ldptr (buf, ppc_r2, sizeof (gpointer), ppc_r11);
-               ppc_ldptr (buf, ppc_r11, 0, ppc_r11);
+               ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
+               ppc_ldptr (code, ppc_r11, 0, ppc_r11);
 #endif
-               ppc_mtlr (buf, ppc_r11);
-               ppc_blrl (buf);
+               ppc_mtlr (code, ppc_r11);
+               ppc_blrl (code);
        } else {
                tramp_handler = mono_get_trampoline_func (tramp_type);
-               ppc_load_func (buf, ppc_r0, tramp_handler);
-               ppc_mtlr (buf, ppc_r0);
-               ppc_blrl (buf);
+               ppc_load_func (code, ppc_r0, tramp_handler);
+               ppc_mtlr (code, ppc_r0);
+               ppc_blrl (code);
        }
                
        /* OK, code address is now on r3. Move it to the counter reg
@@ -403,10 +379,10 @@ mono_arch_create_trampoline_code_full (MonoTrampolineType tramp_type, guint32 *c
         */
        if (!MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type)) {
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-               ppc_ldptr (buf, ppc_r2, sizeof (gpointer), ppc_r3);
-               ppc_ldptr (buf, ppc_r3, 0, ppc_r3);
+               ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r3);
+               ppc_ldptr (code, ppc_r3, 0, ppc_r3);
 #endif
-               ppc_mtctr (buf, ppc_r3);
+               ppc_mtctr (code, ppc_r3);
        }
 
        /*
@@ -415,62 +391,59 @@ mono_arch_create_trampoline_code_full (MonoTrampolineType tramp_type, guint32 *c
         * the same state as before we executed.
         * The pointer to MonoLMF is in ppc_r11.
         */
-       ppc_addi (buf, ppc_r11, ppc_r1, STACK - sizeof (MonoLMF));
+       ppc_addi (code, ppc_r11, ppc_r1, STACK - sizeof (MonoLMF));
        /* r5 = previous_lmf */
-       ppc_ldptr (buf, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
+       ppc_ldptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
        /* r6 = lmf_addr */
-       ppc_ldptr (buf, ppc_r6, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
+       ppc_ldptr (code, ppc_r6, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
        /* *(lmf_addr) = previous_lmf */
-       ppc_stptr (buf, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r6);
+       ppc_stptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r6);
        /* restore iregs */
-       ppc_load_multiple_regs (buf, ppc_r13, G_STRUCT_OFFSET(MonoLMF, iregs), ppc_r11);
+       ppc_ldr_multiple (code, ppc_r13, G_STRUCT_OFFSET(MonoLMF, iregs), ppc_r11);
        /* restore fregs */
        for (i = 14; i < 32; i++)
-               ppc_lfd (buf, i, G_STRUCT_OFFSET(MonoLMF, fregs) + ((i-14) * sizeof (gdouble)), ppc_r11);
+               ppc_lfd (code, i, G_STRUCT_OFFSET(MonoLMF, fregs) + ((i-14) * sizeof (gdouble)), ppc_r11);
 
        /* restore the volatile registers, we skip r1, of course */
        offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double));
        for (i = 0; i < 14; i++) {
-               ppc_lfd (buf, i, offset, ppc_r1);
+               ppc_lfd (code, i, offset, ppc_r1);
                offset += sizeof (double);
        }
-       offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (31 * sizeof (gulong));
-       ppc_ldptr (buf, ppc_r0, offset, ppc_r1);
-       offset += 2 * sizeof (gulong);
+       offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (31 * sizeof (mgreg_t));
+       ppc_ldr (code, ppc_r0, offset, ppc_r1);
+       offset += 2 * sizeof (mgreg_t);
        for (i = 2; i < 13; i++) {
                if (i != PPC_TOC_REG && (i != 3 || tramp_type != MONO_TRAMPOLINE_RGCTX_LAZY_FETCH))
-                       ppc_ldptr (buf, i, offset, ppc_r1);
-               offset += sizeof (gulong);
+                       ppc_ldr (code, i, offset, ppc_r1);
+               offset += sizeof (mgreg_t);
        }
 
        /* Non-standard function epilogue. Instead of doing a proper
         * return, we just jump to the compiled code.
         */
        /* Restore stack pointer and LR and jump to the code */
-       ppc_ldptr  (buf, ppc_r1,  0, ppc_r1);
-       ppc_ldptr  (buf, ppc_r11, PPC_RET_ADDR_OFFSET, ppc_r1);
-       ppc_mtlr (buf, ppc_r11);
+       ppc_ldr  (code, ppc_r1,  0, ppc_r1);
+       ppc_ldr  (code, ppc_r11, PPC_RET_ADDR_OFFSET, ppc_r1);
+       ppc_mtlr (code, ppc_r11);
        if (MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type))
-               ppc_blr (buf);
+               ppc_blr (code);
        else
-               ppc_bcctr (buf, 20, 0);
+               ppc_bcctr (code, 20, 0);
 
        /* Flush instruction cache, since we've generated code */
-       mono_arch_flush_icache (code, buf - code);
+       mono_arch_flush_icache (buf, code - buf);
        
-       *code_size = buf - code;
-
        /* Sanity check */
-       g_assert ((buf - code) <= size);
+       g_assert ((code - buf) <= size);
 
-       if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT) {
-               guint32 code_len;
-
-               /* Initialize the nullified class init trampoline */
-               nullified_class_init_trampoline = mono_ppc_create_ftnptr (mono_arch_get_nullified_class_init_trampoline (&code_len));
+       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 code;
+       return buf;
 }
 
 #define TRAMPOLINE_SIZE (MONO_PPC_32_64_CASE (24, (5+5+1+1)*4))
@@ -494,26 +467,27 @@ mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_ty
        mono_domain_unlock (domain);
 
        if (short_branch) {
-               ppc_load_sequence (buf, ppc_r0, (gulong) arg1);
-               ppc_emit32 (buf, short_branch);
+               ppc_load_sequence (code, ppc_r0, (mgreg_t)(gsize) arg1);
+               ppc_emit32 (code, short_branch);
        } else {
                /* Prepare the jump to the generic trampoline code.*/
-               ppc_load (buf, ppc_r0, (gulong) tramp);
-               ppc_mtctr (buf, ppc_r0);
+               ppc_load_ptr (code, ppc_r0, tramp);
+               ppc_mtctr (code, ppc_r0);
        
                /* And finally put 'arg1' in r0 and fly! */
-               ppc_load (buf, ppc_r0, (gulong) arg1);
-               ppc_bcctr (buf, 20, 0);
+               ppc_load_ptr (code, ppc_r0, arg1);
+               ppc_bcctr (code, 20, 0);
        }
        
        /* Flush instruction cache, since we've generated code */
-       mono_arch_flush_icache (code, buf - code);
+       mono_arch_flush_icache (buf, code - buf);
+
+       g_assert ((code - buf) <= TRAMPOLINE_SIZE);
 
-       g_assert ((buf - code) <= TRAMPOLINE_SIZE);
        if (code_len)
-               *code_len = buf - code;
+               *code_len = code - buf;
 
-       return code;
+       return buf;
 }
 
 static guint8*
@@ -526,7 +500,7 @@ emit_trampoline_jump (guint8 *code, guint8 *tramp)
        if (short_branch) {
                ppc_emit32 (code, short_branch);
        } else {
-               ppc_load (code, ppc_r0, tramp);
+               ppc_load_ptr (code, ppc_r0, tramp);
                ppc_mtctr (code, ppc_r0);
                ppc_bcctr (code, 20, 0);
        }
@@ -535,16 +509,7 @@ emit_trampoline_jump (guint8 *code, guint8 *tramp)
 }
 
 gpointer
-mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot)
-{
-       guint32 code_size;
-       MonoJumpInfo *ji;
-
-       return mono_arch_create_rgctx_lazy_fetch_trampoline_full (slot, &code_size, &ji, FALSE);
-}
-
-gpointer
-mono_arch_create_rgctx_lazy_fetch_trampoline_full (guint32 slot, guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
+mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
 {
 #ifdef MONO_ARCH_VTABLE_REG
        guint8 *tramp;
@@ -554,13 +519,13 @@ mono_arch_create_rgctx_lazy_fetch_trampoline_full (guint32 slot, guint32 *code_s
        int depth, index;
        int i;
        gboolean mrgctx;
-
-       *ji = NULL;
+       MonoJumpInfo *ji = NULL;
+       GSList *unwind_ops = NULL;
 
        mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
        index = MONO_RGCTX_SLOT_INDEX (slot);
        if (mrgctx)
-               index += sizeof (MonoMethodRuntimeGenericContext) / sizeof (gpointer);
+               index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
        for (depth = 0; ; ++depth) {
                int size = mono_class_rgctx_get_array_size (depth, mrgctx);
 
@@ -597,7 +562,7 @@ mono_arch_create_rgctx_lazy_fetch_trampoline_full (guint32 slot, guint32 *code_s
        for (i = 0; i < depth; ++i) {
                /* load ptr to next array */
                if (mrgctx && i == 0)
-                       ppc_ldptr (code, ppc_r4, sizeof (MonoMethodRuntimeGenericContext), ppc_r4);
+                       ppc_ldptr (code, ppc_r4, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT, ppc_r4);
                else
                        ppc_ldptr (code, ppc_r4, 0, ppc_r4);
                /* is the ptr null? */
@@ -628,7 +593,7 @@ mono_arch_create_rgctx_lazy_fetch_trampoline_full (guint32 slot, guint32 *code_s
        ppc_mr (code, MONO_ARCH_VTABLE_REG, ppc_r3);
 
        if (aot) {
-               code = mono_arch_emit_load_aotconst (buf, code, ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("specific_trampoline_lazy_fetch_%u", slot));
+               code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("specific_trampoline_lazy_fetch_%u", slot));
                /* Branch to the trampoline */
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
                ppc_ldptr (code, ppc_r11, 0, ppc_r11);
@@ -647,7 +612,11 @@ mono_arch_create_rgctx_lazy_fetch_trampoline_full (guint32 slot, guint32 *code_s
 
        g_assert (code - buf <= tramp_size);
 
-       *code_size = code - buf;
+       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;
 #else
@@ -656,16 +625,7 @@ mono_arch_create_rgctx_lazy_fetch_trampoline_full (guint32 slot, guint32 *code_s
 }
 
 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)
+mono_arch_create_generic_class_init_trampoline (MonoTrampInfo **info, gboolean aot)
 {
        guint8 *tramp;
        guint8 *code, *buf;
@@ -673,6 +633,8 @@ mono_arch_create_generic_class_init_trampoline_full (guint32 *code_size, MonoJum
        static guint8 bitmask;
        guint8 *jump;
        int tramp_size;
+       GSList *unwind_ops = NULL;
+       MonoJumpInfo *ji = NULL;
 
        tramp_size = MONO_PPC_32_64_CASE (32, 44);
        if (aot)
@@ -680,12 +642,10 @@ mono_arch_create_generic_class_init_trampoline_full (guint32 *code_size, MonoJum
 
        code = buf = mono_global_codeman_reserve (tramp_size);
 
-       *ji = NULL;
-
        if (byte_offset < 0)
                mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
 
-       ppc_lbz (code, ppc_r4, byte_offset, PPC_FIRST_ARG_REG);
+       ppc_lbz (code, ppc_r4, byte_offset, MONO_ARCH_VTABLE_REG);
        ppc_andid (code, ppc_r4, ppc_r4, bitmask);
        jump = code;
        ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
@@ -695,7 +655,7 @@ mono_arch_create_generic_class_init_trampoline_full (guint32 *code_size, MonoJum
        ppc_patch (jump, code);
 
        if (aot) {
-               code = mono_arch_emit_load_aotconst (buf, code, ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_generic_class_init");
+               code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_generic_class_init");
                /* Branch to the trampoline */
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
                ppc_ldptr (code, ppc_r11, 0, ppc_r11);
@@ -712,15 +672,16 @@ mono_arch_create_generic_class_init_trampoline_full (guint32 *code_size, MonoJum
 
        mono_arch_flush_icache (buf, code - buf);
 
-       *code_size = code - buf;
-
        g_assert (code - buf <= tramp_size);
 
+       if (info)
+               *info = mono_tramp_info_create ("generic_class_init_trampoline", buf, code - buf, ji, unwind_ops);
+
        return buf;
 }
 
 gpointer
-mono_arch_get_nullified_class_init_trampoline (guint32 *code_len)
+mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info)
 {
        guint8 *code, *buf;
        guint32 tramp_size = 64;
@@ -730,9 +691,36 @@ mono_arch_get_nullified_class_init_trampoline (guint32 *code_len)
 
        mono_arch_flush_icache (buf, code - buf);
 
-       *code_len = code - buf;
-
        g_assert (code - buf <= tramp_size);
 
+       if (info)
+               *info = mono_tramp_info_create ("nullified_class_init_trampoline", buf, code - buf, NULL, NULL);
+
        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
+}