2 * tramp-ppc.c: JIT trampoline code for PowerPC
5 * Dietmar Maurer (dietmar@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
7 * Carlos Valiente <yo@virutass.net>
8 * Andreas Faerber <andreas.faerber@web.de>
10 * (C) 2001 Ximian, Inc.
11 * (C) 2007-2008 Andreas Faerber
17 #include <mono/metadata/appdomain.h>
18 #include <mono/metadata/marshal.h>
19 #include <mono/metadata/tabledefs.h>
20 #include <mono/arch/ppc/ppc-codegen.h>
25 /* Same as mono_create_ftnptr, but doesn't require a domain */
27 mono_ppc_create_ftnptr (guint8 *code)
29 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
30 MonoPPCFunctionDescriptor *ftnptr = mono_global_codeman_reserve (sizeof (MonoPPCFunctionDescriptor));
43 * Return the instruction to jump from code to target, 0 if not
44 * reachable with a single instruction
47 branch_for_target_reachable (guint8 *branch, guint8 *target)
49 gint diff = target - branch;
50 g_assert ((diff & 3) == 0);
53 return (18 << 26) | (diff);
55 /* diff between 0 and -33554432 */
56 if (diff >= -33554432)
57 return (18 << 26) | (diff & ~0xfc000000);
63 * get_unbox_trampoline:
65 * @addr: pointer to native code for @m
67 * when value type methods are called through the vtable we need to unbox the
68 * this argument. This method returns a pointer to a trampoline which does
69 * unboxing before calling the method
72 mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
77 MonoDomain *domain = mono_domain_get ();
78 int size = MONO_PPC_32_64_CASE (20, 32) + PPC_FTNPTR_SIZE;
80 addr = mono_get_addr_from_ftnptr (addr);
82 mono_domain_lock (domain);
83 start = code = mono_domain_code_reserve (domain, size);
84 code = mono_ppc_create_pre_code_ftnptr (code);
85 short_branch = branch_for_target_reachable (code + 4, addr);
87 mono_domain_code_commit (domain, code, size, 8);
88 mono_domain_unlock (domain);
91 ppc_addi (code, this_pos, this_pos, sizeof (MonoObject));
92 ppc_emit32 (code, short_branch);
94 ppc_load_ptr (code, ppc_r0, addr);
95 ppc_mtctr (code, ppc_r0);
96 ppc_addi (code, this_pos, this_pos, sizeof (MonoObject));
97 ppc_bcctr (code, 20, 0);
99 mono_arch_flush_icache (start, code - start);
100 g_assert ((code - start) <= size);
101 /*g_print ("unbox trampoline at %d for %s:%s\n", this_pos, m->klass->name, m->name);
102 g_print ("unbox code is at %p for method at %p\n", start, addr);*/
108 * mono_arch_get_static_rgctx_trampoline:
110 * Create a trampoline which sets RGCTX_REG to MRGCTX, then jumps to ADDR.
113 mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
115 guint8 *code, *start, *p;
116 guint8 imm_buf [128];
117 guint32 short_branch;
118 MonoDomain *domain = mono_domain_get ();
120 int size = MONO_PPC_32_64_CASE (24, (PPC_LOAD_SEQUENCE_LENGTH * 2) + 8) + PPC_FTNPTR_SIZE;
122 addr = mono_get_addr_from_ftnptr (addr);
124 /* Compute size of code needed to emit mrgctx */
126 ppc_load_ptr (p, MONO_ARCH_RGCTX_REG, mrgctx);
127 imm_size = p - imm_buf;
129 mono_domain_lock (domain);
130 start = code = mono_domain_code_reserve (domain, size);
131 code = mono_ppc_create_pre_code_ftnptr (code);
132 short_branch = branch_for_target_reachable (code + imm_size, addr);
134 mono_domain_code_commit (domain, code, size, imm_size + 4);
135 mono_domain_unlock (domain);
138 ppc_load_ptr (code, MONO_ARCH_RGCTX_REG, mrgctx);
139 ppc_emit32 (code, short_branch);
141 ppc_load_ptr (code, ppc_r0, addr);
142 ppc_mtctr (code, ppc_r0);
143 ppc_load_ptr (code, MONO_ARCH_RGCTX_REG, mrgctx);
144 ppc_bcctr (code, 20, 0);
146 mono_arch_flush_icache (start, code - start);
147 g_assert ((code - start) <= size);
153 mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
155 guint32 *code = (guint32*)code_ptr;
157 addr = mono_get_addr_from_ftnptr (addr);
159 /* This is the 'blrl' instruction */
163 * Note that methods are called also with the bl opcode.
165 if (((*code) >> 26) == 18) {
166 /*g_print ("direct patching\n");*/
167 ppc_patch ((guint8*)code, addr);
168 mono_arch_flush_icache ((guint8*)code, 4);
173 g_assert (mono_ppc_is_direct_call_sequence (code));
175 ppc_patch ((guint8*)code, addr);
179 mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
181 guint32 ins1, ins2, offset;
183 /* Patch the jump table entry used by the plt entry */
185 /* Should be a lis+ori */
186 ins1 = ((guint32*)code)[0];
187 g_assert (ins1 >> 26 == 15);
188 ins2 = ((guint32*)code)[1];
189 g_assert (ins2 >> 26 == 24);
190 offset = ((ins1 & 0xffff) << 16) | (ins2 & 0xffff);
192 /* Either got or regs is set */
194 got = (gpointer*)(gsize) regs [30];
195 *(guint8**)((guint8*)got + offset) = addr;
199 mono_arch_nullify_class_init_trampoline (guint8 *code, mgreg_t *regs)
201 mono_arch_patch_callsite (NULL, code, mini_get_nullified_class_init_trampoline ());
205 mono_arch_nullify_plt_entry (guint8 *code, mgreg_t *regs)
207 mono_arch_patch_plt_entry (code, NULL, regs, mini_get_nullified_class_init_trampoline ());
210 /* Stack size for trampoline function
211 * PPC_MINIMAL_STACK_SIZE + 16 (args + alignment to ppc_magic_trampoline)
212 * + MonoLMF + 14 fp regs + 13 gregs + alignment
214 #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))
216 /* Method-specific trampoline code fragment size */
217 #define METHOD_TRAMPOLINE_SIZE 64
219 /* Jump-specific trampoline code fragment size */
220 #define JUMP_TRAMPOLINE_SIZE 64
222 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
223 #define PPC_TOC_REG ppc_r2
225 #define PPC_TOC_REG -1
229 * Stack frame description when the generic trampoline is called.
231 * --------------------
233 * -------------------
234 * Saved FP registers 0-13
235 * -------------------
236 * Saved general registers 0-30
237 * -------------------
238 * param area for 3 args to ppc_magic_trampoline
239 * -------------------
241 * -------------------
244 mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
247 guint8 *buf, *code = NULL;
249 gconstpointer tramp_handler;
250 int size = MONO_PPC_32_64_CASE (600, 800);
251 GSList *unwind_ops = NULL;
252 MonoJumpInfo *ji = NULL;
254 /* Now we'll create in 'buf' the PowerPC trampoline code. This
255 is the trampoline code common to all methods */
257 code = buf = mono_global_codeman_reserve (size);
259 ppc_str_update (code, ppc_r1, -STACK, ppc_r1);
261 /* start building the MonoLMF on the stack */
262 offset = STACK - sizeof (double) * MONO_SAVED_FREGS;
263 for (i = 14; i < 32; i++) {
264 ppc_stfd (code, i, offset, ppc_r1);
265 offset += sizeof (double);
268 * now the integer registers.
270 offset = STACK - sizeof (MonoLMF) + G_STRUCT_OFFSET (MonoLMF, iregs);
271 ppc_str_multiple (code, ppc_r13, offset, ppc_r1);
273 /* Now save the rest of the registers below the MonoLMF struct, first 14
274 * fp regs and then the 31 gregs.
276 offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double));
277 for (i = 0; i < 14; i++) {
278 ppc_stfd (code, i, offset, ppc_r1);
279 offset += sizeof (double);
281 #define GREGS_OFFSET (STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (31 * sizeof (mgreg_t)))
282 offset = GREGS_OFFSET;
283 for (i = 0; i < 31; i++) {
284 ppc_str (code, i, offset, ppc_r1);
285 offset += sizeof (mgreg_t);
288 /* we got here through a jump to the ctr reg, we must save the lr
289 * in the parent frame (we do it here to reduce the size of the
290 * method-specific trampoline)
292 ppc_mflr (code, ppc_r0);
293 ppc_str (code, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
295 /* ok, now we can continue with the MonoLMF setup, mostly untouched
296 * from emit_prolog in mini-ppc.c
299 code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_get_lmf_addr");
300 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
301 ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
302 ppc_ldptr (code, ppc_r11, 0, ppc_r11);
304 ppc_mtlr (code, ppc_r11);
307 ppc_load_func (code, ppc_r0, mono_get_lmf_addr);
308 ppc_mtlr (code, ppc_r0);
311 /* we build the MonoLMF structure on the stack - see mini-ppc.h
312 * The pointer to the struct is put in ppc_r11.
314 ppc_addi (code, ppc_r11, ppc_sp, STACK - sizeof (MonoLMF));
315 ppc_stptr (code, ppc_r3, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
316 /* new_lmf->previous_lmf = *lmf_addr */
317 ppc_ldptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
318 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
319 /* *(lmf_addr) = r11 */
320 ppc_stptr (code, ppc_r11, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
321 /* save method info (it's stored on the stack, so get it first). */
322 if ((tramp_type == MONO_TRAMPOLINE_JIT) || (tramp_type == MONO_TRAMPOLINE_JUMP)) {
323 ppc_ldr (code, ppc_r0, GREGS_OFFSET, ppc_r1);
324 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
326 ppc_load (code, ppc_r0, 0);
327 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
329 /* store the frame pointer of the calling method */
330 ppc_addi (code, ppc_r0, ppc_sp, STACK);
331 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, ebp), ppc_r11);
332 /* save the IP (caller ip) */
333 if (tramp_type == MONO_TRAMPOLINE_JUMP) {
334 ppc_li (code, ppc_r0, 0);
336 ppc_ldr (code, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
338 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, eip), ppc_r11);
341 * Now we're ready to call trampoline (mgreg_t *regs, guint8 *code, gpointer value, guint8 *tramp)
342 * Note that the last argument is unused.
344 /* Arg 1: a pointer to the registers */
345 ppc_addi (code, ppc_r3, ppc_r1, GREGS_OFFSET);
347 /* Arg 2: code (next address to the instruction that called us) */
348 if (tramp_type == MONO_TRAMPOLINE_JUMP)
349 ppc_li (code, ppc_r4, 0);
351 ppc_ldr (code, ppc_r4, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
353 /* Arg 3: trampoline argument */
354 if (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
355 ppc_ldr (code, ppc_r5, GREGS_OFFSET + MONO_ARCH_VTABLE_REG * sizeof (mgreg_t), ppc_r1);
357 ppc_ldr (code, ppc_r5, GREGS_OFFSET, ppc_r1);
360 code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("trampoline_func_%d", tramp_type));
361 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
362 ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
363 ppc_ldptr (code, ppc_r11, 0, ppc_r11);
365 ppc_mtlr (code, ppc_r11);
368 tramp_handler = mono_get_trampoline_func (tramp_type);
369 ppc_load_func (code, ppc_r0, tramp_handler);
370 ppc_mtlr (code, ppc_r0);
374 /* OK, code address is now on r3. Move it to the counter reg
375 * so it will be ready for the final jump: this is safe since we
376 * won't do any more calls.
378 if (!MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type)) {
379 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
380 ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r3);
381 ppc_ldptr (code, ppc_r3, 0, ppc_r3);
383 ppc_mtctr (code, ppc_r3);
387 * Now we restore the MonoLMF (see emit_epilogue in mini-ppc.c)
388 * and the rest of the registers, so the method called will see
389 * the same state as before we executed.
390 * The pointer to MonoLMF is in ppc_r11.
392 ppc_addi (code, ppc_r11, ppc_r1, STACK - sizeof (MonoLMF));
393 /* r5 = previous_lmf */
394 ppc_ldptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
396 ppc_ldptr (code, ppc_r6, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
397 /* *(lmf_addr) = previous_lmf */
398 ppc_stptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r6);
400 ppc_ldr_multiple (code, ppc_r13, G_STRUCT_OFFSET(MonoLMF, iregs), ppc_r11);
402 for (i = 14; i < 32; i++)
403 ppc_lfd (code, i, G_STRUCT_OFFSET(MonoLMF, fregs) + ((i-14) * sizeof (gdouble)), ppc_r11);
405 /* restore the volatile registers, we skip r1, of course */
406 offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double));
407 for (i = 0; i < 14; i++) {
408 ppc_lfd (code, i, offset, ppc_r1);
409 offset += sizeof (double);
411 offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (31 * sizeof (mgreg_t));
412 ppc_ldr (code, ppc_r0, offset, ppc_r1);
413 offset += 2 * sizeof (mgreg_t);
414 for (i = 2; i < 13; i++) {
415 if (i != PPC_TOC_REG && (i != 3 || tramp_type != MONO_TRAMPOLINE_RGCTX_LAZY_FETCH))
416 ppc_ldr (code, i, offset, ppc_r1);
417 offset += sizeof (mgreg_t);
420 /* Non-standard function epilogue. Instead of doing a proper
421 * return, we just jump to the compiled code.
423 /* Restore stack pointer and LR and jump to the code */
424 ppc_ldr (code, ppc_r1, 0, ppc_r1);
425 ppc_ldr (code, ppc_r11, PPC_RET_ADDR_OFFSET, ppc_r1);
426 ppc_mtlr (code, ppc_r11);
427 if (MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type))
430 ppc_bcctr (code, 20, 0);
432 /* Flush instruction cache, since we've generated code */
433 mono_arch_flush_icache (buf, code - buf);
436 g_assert ((code - buf) <= size);
439 tramp_name = mono_get_generic_trampoline_name (tramp_type);
440 *info = mono_tramp_info_create (tramp_name, buf, code - buf, ji, unwind_ops);
447 #define TRAMPOLINE_SIZE (MONO_PPC_32_64_CASE (24, (5+5+1+1)*4))
449 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
451 guint8 *code, *buf, *tramp;
452 guint32 short_branch;
454 tramp = mono_get_trampoline_code (tramp_type);
456 mono_domain_lock (domain);
457 code = buf = mono_domain_code_reserve_align (domain, TRAMPOLINE_SIZE, 4);
458 short_branch = branch_for_target_reachable (code + MONO_PPC_32_64_CASE (8, 5*4), tramp);
459 #ifdef __mono_ppc64__
460 /* FIXME: make shorter if possible */
463 mono_domain_code_commit (domain, code, TRAMPOLINE_SIZE, 12);
465 mono_domain_unlock (domain);
468 ppc_load_sequence (code, ppc_r0, (mgreg_t)(gsize) arg1);
469 ppc_emit32 (code, short_branch);
471 /* Prepare the jump to the generic trampoline code.*/
472 ppc_load_ptr (code, ppc_r0, tramp);
473 ppc_mtctr (code, ppc_r0);
475 /* And finally put 'arg1' in r0 and fly! */
476 ppc_load_ptr (code, ppc_r0, arg1);
477 ppc_bcctr (code, 20, 0);
480 /* Flush instruction cache, since we've generated code */
481 mono_arch_flush_icache (buf, code - buf);
483 g_assert ((code - buf) <= TRAMPOLINE_SIZE);
486 *code_len = code - buf;
492 emit_trampoline_jump (guint8 *code, guint8 *tramp)
494 guint32 short_branch = branch_for_target_reachable (code, tramp);
496 /* FIXME: we can save a few bytes here by committing if the
497 short branch is possible */
499 ppc_emit32 (code, short_branch);
501 ppc_load_ptr (code, ppc_r0, tramp);
502 ppc_mtctr (code, ppc_r0);
503 ppc_bcctr (code, 20, 0);
510 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
512 #ifdef MONO_ARCH_VTABLE_REG
515 guint8 **rgctx_null_jumps;
520 MonoJumpInfo *ji = NULL;
521 GSList *unwind_ops = NULL;
523 mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
524 index = MONO_RGCTX_SLOT_INDEX (slot);
526 index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
527 for (depth = 0; ; ++depth) {
528 int size = mono_class_rgctx_get_array_size (depth, mrgctx);
530 if (index < size - 1)
535 tramp_size = MONO_PPC_32_64_CASE (40, 52) + 12 * depth;
543 code = buf = mono_global_codeman_reserve (tramp_size);
545 rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
549 ppc_mr (code, ppc_r4, PPC_FIRST_ARG_REG);
551 /* load rgctx ptr from vtable */
552 ppc_ldptr (code, ppc_r4, G_STRUCT_OFFSET (MonoVTable, runtime_generic_context), PPC_FIRST_ARG_REG);
553 /* is the rgctx ptr null? */
554 ppc_compare_reg_imm (code, 0, ppc_r4, 0);
555 /* if yes, jump to actual trampoline */
556 rgctx_null_jumps [0] = code;
557 ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
560 for (i = 0; i < depth; ++i) {
561 /* load ptr to next array */
562 if (mrgctx && i == 0)
563 ppc_ldptr (code, ppc_r4, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT, ppc_r4);
565 ppc_ldptr (code, ppc_r4, 0, ppc_r4);
566 /* is the ptr null? */
567 ppc_compare_reg_imm (code, 0, ppc_r4, 0);
568 /* if yes, jump to actual trampoline */
569 rgctx_null_jumps [i + 1] = code;
570 ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
574 ppc_ldptr (code, ppc_r4, sizeof (gpointer) * (index + 1), ppc_r4);
575 /* is the slot null? */
576 ppc_compare_reg_imm (code, 0, ppc_r4, 0);
577 /* if yes, jump to actual trampoline */
578 rgctx_null_jumps [depth + 1] = code;
579 ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
580 /* otherwise return r4 */
581 /* FIXME: if we use r3 as the work register we can avoid this copy */
582 ppc_mr (code, ppc_r3, ppc_r4);
585 for (i = mrgctx ? 1 : 0; i <= depth + 1; ++i)
586 ppc_patch (rgctx_null_jumps [i], code);
588 g_free (rgctx_null_jumps);
590 /* move the rgctx pointer to the VTABLE register */
591 ppc_mr (code, MONO_ARCH_VTABLE_REG, ppc_r3);
594 code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("specific_trampoline_lazy_fetch_%u", slot));
595 /* Branch to the trampoline */
596 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
597 ppc_ldptr (code, ppc_r11, 0, ppc_r11);
599 ppc_mtctr (code, ppc_r11);
600 ppc_bcctr (code, PPC_BR_ALWAYS, 0);
602 tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot),
603 MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), NULL);
605 /* jump to the actual trampoline */
606 code = emit_trampoline_jump (code, tramp);
609 mono_arch_flush_icache (buf, code - buf);
611 g_assert (code - buf <= tramp_size);
614 char *name = mono_get_rgctx_fetch_trampoline_name (slot);
615 *info = mono_tramp_info_create (name, buf, code - buf, ji, unwind_ops);
621 g_assert_not_reached ();
626 mono_arch_create_generic_class_init_trampoline (MonoTrampInfo **info, gboolean aot)
630 static int byte_offset = -1;
631 static guint8 bitmask;
634 GSList *unwind_ops = NULL;
635 MonoJumpInfo *ji = NULL;
637 tramp_size = MONO_PPC_32_64_CASE (32, 44);
641 code = buf = mono_global_codeman_reserve (tramp_size);
644 mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
646 ppc_lbz (code, ppc_r4, byte_offset, MONO_ARCH_VTABLE_REG);
647 ppc_andid (code, ppc_r4, ppc_r4, bitmask);
649 ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
653 ppc_patch (jump, code);
656 code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_generic_class_init");
657 /* Branch to the trampoline */
658 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
659 ppc_ldptr (code, ppc_r11, 0, ppc_r11);
661 ppc_mtctr (code, ppc_r11);
662 ppc_bcctr (code, PPC_BR_ALWAYS, 0);
664 tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT,
665 mono_get_root_domain (), NULL);
667 /* jump to the actual trampoline */
668 code = emit_trampoline_jump (code, tramp);
671 mono_arch_flush_icache (buf, code - buf);
673 g_assert (code - buf <= tramp_size);
676 *info = mono_tramp_info_create ("generic_class_init_trampoline", buf, code - buf, ji, unwind_ops);
682 mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info)
685 guint32 tramp_size = 64;
687 code = buf = mono_global_codeman_reserve (tramp_size);
690 mono_arch_flush_icache (buf, code - buf);
692 g_assert (code - buf <= tramp_size);
695 *info = mono_tramp_info_create ("nullified_class_init_trampoline", buf, code - buf, NULL, NULL);
701 mono_arch_get_call_target (guint8 *code)
704 guint32 ins = ((guint32*)(gpointer)code) [-1];
706 if ((ins >> 26 == 18) && ((ins & 1) == 1) && ((ins & 2) == 0)) {
707 gint32 disp = (((gint32)ins) >> 2) & 0xffffff;
708 guint8 *target = code - 4 + (disp * 4);
717 mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
719 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
720 return ((guint32*)plt_entry) [8];
722 return ((guint32*)plt_entry) [6];