- if(!code) {
- /* 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 (512);
-
- ppc_stwu (buf, 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);
- offset += sizeof (double);
- }
- /*
- * now the integer registers. r13 is already saved in the trampoline,
- * and at this point contains the method to compile, so we skip it.
- */
- offset = STACK - sizeof (MonoLMF) + G_STRUCT_OFFSET (MonoLMF, iregs) + sizeof (gulong);
- ppc_stmw (buf, ppc_r14, ppc_r1, offset);
-
- /* Now save the rest of the registers below the MonoLMF struct, first 14
- * fp regs and then the 13 gregs.
- */
- offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double));
- for (i = 0; i < 14; i++) {
- ppc_stfd (buf, i, offset, ppc_r1);
- offset += sizeof (double);
- }
- offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (13 * sizeof (gulong));
- for (i = 0; i < 13; i++) {
- ppc_stw (buf, i, offset, ppc_r1);
- offset += sizeof (gulong);
- }
- /* 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_stw (buf, 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
- */
- ppc_load (buf, ppc_r0, mono_get_lmf_addr);
- ppc_mtlr (buf, ppc_r0);
- ppc_blrl (buf);
- /* 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_stw (buf, ppc_r3, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
- /* new_lmf->previous_lmf = *lmf_addr */
- ppc_lwz (buf, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
- ppc_stw (buf, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
- /* *(lmf_addr) = r11 */
- ppc_stw (buf, ppc_r11, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
- /* save method info (it's in r13) */
- ppc_stw (buf, ppc_r13, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
- ppc_stw (buf, ppc_sp, G_STRUCT_OFFSET(MonoLMF, ebp), ppc_r11);
- /* save the IP (caller ip) */
- if (tramp_type == MONO_TRAMPOLINE_JUMP) {
- ppc_li (buf, ppc_r0, 0);
- } else {
- ppc_lwz (buf, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
- }
- ppc_stw (buf, ppc_r0, G_STRUCT_OFFSET(MonoLMF, eip), ppc_r11);
-
- /*
- * Now we're ready to call ppc_magic_trampoline ().
- */
- /* Arg 1: MonoMethod *method. It was put in r13 */
- ppc_mr (buf, ppc_r3, ppc_r13);
-
- /* Arg 2: code (next address to the instruction that called us) */
- if (tramp_type == MONO_TRAMPOLINE_JUMP) {
- ppc_li (buf, ppc_r4, 0);
- } else {
- ppc_lwz (buf, ppc_r4, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
- }
-
- /* Arg 3: stack pointer so that the magic trampoline can access the
- * registers we saved above
- */
- ppc_mr (buf, ppc_r5, ppc_r1);
+ /* 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);
+
+ 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 (code, i, offset, ppc_r1);
+ offset += sizeof (double);
+ }
+ /*
+ * now the integer registers.
+ */
+ offset = STACK - sizeof (MonoLMF) + G_STRUCT_OFFSET (MonoLMF, iregs);
+ 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 (code, i, offset, ppc_r1);
+ offset += sizeof (double);
+ }
+#define GREGS_OFFSET (STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (31 * sizeof (mgreg_t)))
+ offset = GREGS_OFFSET;
+ for (i = 0; i < 31; i++) {
+ 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 (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) {
+ 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 (code, ppc_r2, sizeof (gpointer), ppc_r11);
+ ppc_ldptr (code, ppc_r11, 0, ppc_r11);
+#endif
+ ppc_mtlr (code, ppc_r11);
+ ppc_blrl (code);
+ } else {
+ 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 (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 (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 (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 (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 (code, ppc_r0, 0);
+ } else {
+ ppc_ldr (code, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
+ }
+ 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 (code, ppc_r3, ppc_r1, GREGS_OFFSET);