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 static guint8* nullified_class_init_trampoline;
27 /* Same as mono_create_ftnptr, but doesn't require a domain */
29 mono_ppc_create_ftnptr (guint8 *code)
31 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
32 MonoPPCFunctionDescriptor *ftnptr = mono_global_codeman_reserve (sizeof (MonoPPCFunctionDescriptor));
45 * Return the instruction to jump from code to target, 0 if not
46 * reachable with a single instruction
49 branch_for_target_reachable (guint8 *branch, guint8 *target)
51 gint diff = target - branch;
52 g_assert ((diff & 3) == 0);
55 return (18 << 26) | (diff);
57 /* diff between 0 and -33554432 */
58 if (diff >= -33554432)
59 return (18 << 26) | (diff & ~0xfc000000);
65 * get_unbox_trampoline:
66 * @gsctx: the generic sharing context
68 * @addr: pointer to native code for @m
70 * when value type methods are called through the vtable we need to unbox the
71 * this argument. This method returns a pointer to a trampoline which does
72 * unboxing before calling the method
75 mono_arch_get_unbox_trampoline (MonoGenericSharingContext *gsctx, MonoMethod *m, gpointer addr)
80 MonoDomain *domain = mono_domain_get ();
81 int size = MONO_PPC_32_64_CASE (20, 32) + PPC_FTNPTR_SIZE;
83 addr = mono_get_addr_from_ftnptr (addr);
85 if (MONO_TYPE_ISSTRUCT (mono_method_signature (m)->ret))
88 mono_domain_lock (domain);
89 start = code = mono_domain_code_reserve (domain, size);
90 code = mono_ppc_create_pre_code_ftnptr (code);
91 short_branch = branch_for_target_reachable (code + 4, addr);
93 mono_domain_code_commit (domain, code, size, 8);
94 mono_domain_unlock (domain);
97 ppc_addi (code, this_pos, this_pos, sizeof (MonoObject));
98 ppc_emit32 (code, short_branch);
100 ppc_load_ptr (code, ppc_r0, addr);
101 ppc_mtctr (code, ppc_r0);
102 ppc_addi (code, this_pos, this_pos, sizeof (MonoObject));
103 ppc_bcctr (code, 20, 0);
105 mono_arch_flush_icache (start, code - start);
106 g_assert ((code - start) <= size);
107 /*g_print ("unbox trampoline at %d for %s:%s\n", this_pos, m->klass->name, m->name);
108 g_print ("unbox code is at %p for method at %p\n", start, addr);*/
114 * mono_arch_get_static_rgctx_trampoline:
116 * Create a trampoline which sets RGCTX_REG to MRGCTX, then jumps to ADDR.
119 mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
121 guint8 *code, *start, *p;
122 guint8 imm_buf [128];
123 guint32 short_branch;
124 MonoDomain *domain = mono_domain_get ();
126 int size = MONO_PPC_32_64_CASE (24, (PPC_LOAD_SEQUENCE_LENGTH * 2) + 8) + PPC_FTNPTR_SIZE;
128 addr = mono_get_addr_from_ftnptr (addr);
130 /* Compute size of code needed to emit mrgctx */
132 ppc_load_ptr (p, MONO_ARCH_RGCTX_REG, mrgctx);
133 imm_size = p - imm_buf;
135 mono_domain_lock (domain);
136 start = code = mono_domain_code_reserve (domain, size);
137 code = mono_ppc_create_pre_code_ftnptr (code);
138 short_branch = branch_for_target_reachable (code + imm_size, addr);
140 mono_domain_code_commit (domain, code, size, imm_size + 4);
141 mono_domain_unlock (domain);
144 ppc_load_ptr (code, MONO_ARCH_RGCTX_REG, mrgctx);
145 ppc_emit32 (code, short_branch);
147 ppc_load_ptr (code, ppc_r0, addr);
148 ppc_mtctr (code, ppc_r0);
149 ppc_load_ptr (code, MONO_ARCH_RGCTX_REG, mrgctx);
150 ppc_bcctr (code, 20, 0);
152 mono_arch_flush_icache (start, code - start);
153 g_assert ((code - start) <= size);
159 mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
161 guint32 *code = (guint32*)code_ptr;
163 addr = mono_get_addr_from_ftnptr (addr);
165 /* This is the 'blrl' instruction */
169 * Note that methods are called also with the bl opcode.
171 if (((*code) >> 26) == 18) {
172 /*g_print ("direct patching\n");*/
173 ppc_patch ((guint8*)code, addr);
174 mono_arch_flush_icache ((guint8*)code, 4);
179 g_assert (mono_ppc_is_direct_call_sequence (code));
181 ppc_patch ((guint8*)code, addr);
185 mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
187 guint32 ins1, ins2, offset;
189 /* Patch the jump table entry used by the plt entry */
191 /* Should be a lis+ori */
192 ins1 = ((guint32*)code)[0];
193 g_assert (ins1 >> 26 == 15);
194 ins2 = ((guint32*)code)[1];
195 g_assert (ins2 >> 26 == 24);
196 offset = ((ins1 & 0xffff) << 16) | (ins2 & 0xffff);
198 /* Either got or regs is set */
200 got = (gpointer*)(gsize) regs [30];
201 *(guint8**)((guint8*)got + offset) = addr;
205 mono_arch_nullify_class_init_trampoline (guint8 *code, mgreg_t *regs)
207 mono_arch_patch_callsite (NULL, code, nullified_class_init_trampoline);
211 mono_arch_nullify_plt_entry (guint8 *code, mgreg_t *regs)
213 if (mono_aot_only && !nullified_class_init_trampoline)
214 nullified_class_init_trampoline = mono_aot_get_trampoline ("nullified_class_init_trampoline");
216 mono_arch_patch_plt_entry (code, NULL, regs, nullified_class_init_trampoline);
219 /* Stack size for trampoline function
220 * PPC_MINIMAL_STACK_SIZE + 16 (args + alignment to ppc_magic_trampoline)
221 * + MonoLMF + 14 fp regs + 13 gregs + alignment
223 #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))
225 /* Method-specific trampoline code fragment size */
226 #define METHOD_TRAMPOLINE_SIZE 64
228 /* Jump-specific trampoline code fragment size */
229 #define JUMP_TRAMPOLINE_SIZE 64
231 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
232 #define PPC_TOC_REG ppc_r2
234 #define PPC_TOC_REG -1
238 * Stack frame description when the generic trampoline is called.
240 * --------------------
242 * -------------------
243 * Saved FP registers 0-13
244 * -------------------
245 * Saved general registers 0-30
246 * -------------------
247 * param area for 3 args to ppc_magic_trampoline
248 * -------------------
250 * -------------------
253 mono_arch_create_generic_trampoline_full (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
256 guint8 *buf, *code = NULL;
258 gconstpointer tramp_handler;
259 int size = MONO_PPC_32_64_CASE (600, 800);
260 GSList *unwind_ops = NULL;
261 MonoJumpInfo *ji = NULL;
263 /* Now we'll create in 'buf' the PowerPC trampoline code. This
264 is the trampoline code common to all methods */
266 code = buf = mono_global_codeman_reserve (size);
268 ppc_str_update (code, ppc_r1, -STACK, ppc_r1);
270 /* start building the MonoLMF on the stack */
271 offset = STACK - sizeof (double) * MONO_SAVED_FREGS;
272 for (i = 14; i < 32; i++) {
273 ppc_stfd (code, i, offset, ppc_r1);
274 offset += sizeof (double);
277 * now the integer registers.
279 offset = STACK - sizeof (MonoLMF) + G_STRUCT_OFFSET (MonoLMF, iregs);
280 ppc_str_multiple (code, ppc_r13, offset, ppc_r1);
282 /* Now save the rest of the registers below the MonoLMF struct, first 14
283 * fp regs and then the 31 gregs.
285 offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double));
286 for (i = 0; i < 14; i++) {
287 ppc_stfd (code, i, offset, ppc_r1);
288 offset += sizeof (double);
290 #define GREGS_OFFSET (STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (31 * sizeof (mgreg_t)))
291 offset = GREGS_OFFSET;
292 for (i = 0; i < 31; i++) {
293 ppc_str (code, i, offset, ppc_r1);
294 offset += sizeof (mgreg_t);
297 /* we got here through a jump to the ctr reg, we must save the lr
298 * in the parent frame (we do it here to reduce the size of the
299 * method-specific trampoline)
301 ppc_mflr (code, ppc_r0);
302 ppc_str (code, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
304 /* ok, now we can continue with the MonoLMF setup, mostly untouched
305 * from emit_prolog in mini-ppc.c
308 code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_get_lmf_addr");
309 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
310 ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
311 ppc_ldptr (code, ppc_r11, 0, ppc_r11);
313 ppc_mtlr (code, ppc_r11);
316 ppc_load_func (code, ppc_r0, mono_get_lmf_addr);
317 ppc_mtlr (code, ppc_r0);
320 /* we build the MonoLMF structure on the stack - see mini-ppc.h
321 * The pointer to the struct is put in ppc_r11.
323 ppc_addi (code, ppc_r11, ppc_sp, STACK - sizeof (MonoLMF));
324 ppc_stptr (code, ppc_r3, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
325 /* new_lmf->previous_lmf = *lmf_addr */
326 ppc_ldptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
327 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
328 /* *(lmf_addr) = r11 */
329 ppc_stptr (code, ppc_r11, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
330 /* save method info (it's stored on the stack, so get it first). */
331 if ((tramp_type == MONO_TRAMPOLINE_JIT) || (tramp_type == MONO_TRAMPOLINE_JUMP)) {
332 ppc_ldr (code, ppc_r0, GREGS_OFFSET, ppc_r1);
333 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
335 ppc_load (code, ppc_r0, 0);
336 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
338 /* store the frame pointer of the calling method */
339 ppc_addi (code, ppc_r0, ppc_sp, STACK);
340 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, ebp), ppc_r11);
341 /* save the IP (caller ip) */
342 if (tramp_type == MONO_TRAMPOLINE_JUMP) {
343 ppc_li (code, ppc_r0, 0);
345 ppc_ldr (code, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
347 ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, eip), ppc_r11);
350 * Now we're ready to call trampoline (mgreg_t *regs, guint8 *code, gpointer value, guint8 *tramp)
351 * Note that the last argument is unused.
353 /* Arg 1: a pointer to the registers */
354 ppc_addi (code, ppc_r3, ppc_r1, GREGS_OFFSET);
356 /* Arg 2: code (next address to the instruction that called us) */
357 if (tramp_type == MONO_TRAMPOLINE_JUMP)
358 ppc_li (code, ppc_r4, 0);
360 ppc_ldr (code, ppc_r4, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
362 /* Arg 3: trampoline argument */
363 if (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
364 ppc_ldr (code, ppc_r5, GREGS_OFFSET + MONO_ARCH_VTABLE_REG * sizeof (mgreg_t), ppc_r1);
366 ppc_ldr (code, ppc_r5, GREGS_OFFSET, ppc_r1);
369 code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("trampoline_func_%d", tramp_type));
370 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
371 ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
372 ppc_ldptr (code, ppc_r11, 0, ppc_r11);
374 ppc_mtlr (code, ppc_r11);
377 tramp_handler = mono_get_trampoline_func (tramp_type);
378 ppc_load_func (code, ppc_r0, tramp_handler);
379 ppc_mtlr (code, ppc_r0);
383 /* OK, code address is now on r3. Move it to the counter reg
384 * so it will be ready for the final jump: this is safe since we
385 * won't do any more calls.
387 if (!MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type)) {
388 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
389 ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r3);
390 ppc_ldptr (code, ppc_r3, 0, ppc_r3);
392 ppc_mtctr (code, ppc_r3);
396 * Now we restore the MonoLMF (see emit_epilogue in mini-ppc.c)
397 * and the rest of the registers, so the method called will see
398 * the same state as before we executed.
399 * The pointer to MonoLMF is in ppc_r11.
401 ppc_addi (code, ppc_r11, ppc_r1, STACK - sizeof (MonoLMF));
402 /* r5 = previous_lmf */
403 ppc_ldptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
405 ppc_ldptr (code, ppc_r6, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
406 /* *(lmf_addr) = previous_lmf */
407 ppc_stptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r6);
409 ppc_ldr_multiple (code, ppc_r13, G_STRUCT_OFFSET(MonoLMF, iregs), ppc_r11);
411 for (i = 14; i < 32; i++)
412 ppc_lfd (code, i, G_STRUCT_OFFSET(MonoLMF, fregs) + ((i-14) * sizeof (gdouble)), ppc_r11);
414 /* restore the volatile registers, we skip r1, of course */
415 offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double));
416 for (i = 0; i < 14; i++) {
417 ppc_lfd (code, i, offset, ppc_r1);
418 offset += sizeof (double);
420 offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double)) - (31 * sizeof (mgreg_t));
421 ppc_ldr (code, ppc_r0, offset, ppc_r1);
422 offset += 2 * sizeof (mgreg_t);
423 for (i = 2; i < 13; i++) {
424 if (i != PPC_TOC_REG && (i != 3 || tramp_type != MONO_TRAMPOLINE_RGCTX_LAZY_FETCH))
425 ppc_ldr (code, i, offset, ppc_r1);
426 offset += sizeof (mgreg_t);
429 /* Non-standard function epilogue. Instead of doing a proper
430 * return, we just jump to the compiled code.
432 /* Restore stack pointer and LR and jump to the code */
433 ppc_ldr (code, ppc_r1, 0, ppc_r1);
434 ppc_ldr (code, ppc_r11, PPC_RET_ADDR_OFFSET, ppc_r1);
435 ppc_mtlr (code, ppc_r11);
436 if (MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type))
439 ppc_bcctr (code, 20, 0);
441 /* Flush instruction cache, since we've generated code */
442 mono_arch_flush_icache (buf, code - buf);
445 g_assert ((code - buf) <= size);
447 if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT) {
448 /* Initialize the nullified class init trampoline */
449 nullified_class_init_trampoline = mono_ppc_create_ftnptr (mono_arch_get_nullified_class_init_trampoline (NULL));
453 *info = mono_tramp_info_create (g_strdup_printf ("generic_trampoline_%d", tramp_type), buf, code - buf, ji, unwind_ops);
458 #define TRAMPOLINE_SIZE (MONO_PPC_32_64_CASE (24, (5+5+1+1)*4))
460 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
462 guint8 *code, *buf, *tramp;
463 guint32 short_branch;
465 tramp = mono_get_trampoline_code (tramp_type);
467 mono_domain_lock (domain);
468 code = buf = mono_domain_code_reserve_align (domain, TRAMPOLINE_SIZE, 4);
469 short_branch = branch_for_target_reachable (code + MONO_PPC_32_64_CASE (8, 5*4), tramp);
470 #ifdef __mono_ppc64__
471 /* FIXME: make shorter if possible */
474 mono_domain_code_commit (domain, code, TRAMPOLINE_SIZE, 12);
476 mono_domain_unlock (domain);
479 ppc_load_sequence (code, ppc_r0, (mgreg_t)(gsize) arg1);
480 ppc_emit32 (code, short_branch);
482 /* Prepare the jump to the generic trampoline code.*/
483 ppc_load_ptr (code, ppc_r0, tramp);
484 ppc_mtctr (code, ppc_r0);
486 /* And finally put 'arg1' in r0 and fly! */
487 ppc_load_ptr (code, ppc_r0, arg1);
488 ppc_bcctr (code, 20, 0);
491 /* Flush instruction cache, since we've generated code */
492 mono_arch_flush_icache (buf, code - buf);
494 g_assert ((code - buf) <= TRAMPOLINE_SIZE);
497 *code_len = code - buf;
503 emit_trampoline_jump (guint8 *code, guint8 *tramp)
505 guint32 short_branch = branch_for_target_reachable (code, tramp);
507 /* FIXME: we can save a few bytes here by committing if the
508 short branch is possible */
510 ppc_emit32 (code, short_branch);
512 ppc_load_ptr (code, ppc_r0, tramp);
513 ppc_mtctr (code, ppc_r0);
514 ppc_bcctr (code, 20, 0);
521 mono_arch_create_rgctx_lazy_fetch_trampoline_full (guint32 slot, MonoTrampInfo **info, gboolean aot)
523 #ifdef MONO_ARCH_VTABLE_REG
526 guint8 **rgctx_null_jumps;
531 MonoJumpInfo *ji = NULL;
532 GSList *unwind_ops = NULL;
534 mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
535 index = MONO_RGCTX_SLOT_INDEX (slot);
537 index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
538 for (depth = 0; ; ++depth) {
539 int size = mono_class_rgctx_get_array_size (depth, mrgctx);
541 if (index < size - 1)
546 tramp_size = MONO_PPC_32_64_CASE (40, 52) + 12 * depth;
554 code = buf = mono_global_codeman_reserve (tramp_size);
556 rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
560 ppc_mr (code, ppc_r4, PPC_FIRST_ARG_REG);
562 /* load rgctx ptr from vtable */
563 ppc_ldptr (code, ppc_r4, G_STRUCT_OFFSET (MonoVTable, runtime_generic_context), PPC_FIRST_ARG_REG);
564 /* is the rgctx ptr null? */
565 ppc_compare_reg_imm (code, 0, ppc_r4, 0);
566 /* if yes, jump to actual trampoline */
567 rgctx_null_jumps [0] = code;
568 ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
571 for (i = 0; i < depth; ++i) {
572 /* load ptr to next array */
573 if (mrgctx && i == 0)
574 ppc_ldptr (code, ppc_r4, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT, ppc_r4);
576 ppc_ldptr (code, ppc_r4, 0, ppc_r4);
577 /* is the ptr null? */
578 ppc_compare_reg_imm (code, 0, ppc_r4, 0);
579 /* if yes, jump to actual trampoline */
580 rgctx_null_jumps [i + 1] = code;
581 ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
585 ppc_ldptr (code, ppc_r4, sizeof (gpointer) * (index + 1), ppc_r4);
586 /* is the slot null? */
587 ppc_compare_reg_imm (code, 0, ppc_r4, 0);
588 /* if yes, jump to actual trampoline */
589 rgctx_null_jumps [depth + 1] = code;
590 ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
591 /* otherwise return r4 */
592 /* FIXME: if we use r3 as the work register we can avoid this copy */
593 ppc_mr (code, ppc_r3, ppc_r4);
596 for (i = mrgctx ? 1 : 0; i <= depth + 1; ++i)
597 ppc_patch (rgctx_null_jumps [i], code);
599 g_free (rgctx_null_jumps);
601 /* move the rgctx pointer to the VTABLE register */
602 ppc_mr (code, MONO_ARCH_VTABLE_REG, ppc_r3);
605 code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("specific_trampoline_lazy_fetch_%u", slot));
606 /* Branch to the trampoline */
607 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
608 ppc_ldptr (code, ppc_r11, 0, ppc_r11);
610 ppc_mtctr (code, ppc_r11);
611 ppc_bcctr (code, PPC_BR_ALWAYS, 0);
613 tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot),
614 MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), NULL);
616 /* jump to the actual trampoline */
617 code = emit_trampoline_jump (code, tramp);
620 mono_arch_flush_icache (buf, code - buf);
622 g_assert (code - buf <= tramp_size);
625 *info = mono_tramp_info_create (g_strdup_printf ("rgctx_fetch_trampoline_%u", slot), buf, code - buf, ji, unwind_ops);
629 g_assert_not_reached ();
634 mono_arch_create_generic_class_init_trampoline_full (MonoTrampInfo **info, gboolean aot)
638 static int byte_offset = -1;
639 static guint8 bitmask;
642 GSList *unwind_ops = NULL;
643 MonoJumpInfo *ji = NULL;
645 tramp_size = MONO_PPC_32_64_CASE (32, 44);
649 code = buf = mono_global_codeman_reserve (tramp_size);
652 mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
654 ppc_lbz (code, ppc_r4, byte_offset, MONO_ARCH_VTABLE_REG);
655 ppc_andid (code, ppc_r4, ppc_r4, bitmask);
657 ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
661 ppc_patch (jump, code);
664 code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_generic_class_init");
665 /* Branch to the trampoline */
666 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
667 ppc_ldptr (code, ppc_r11, 0, ppc_r11);
669 ppc_mtctr (code, ppc_r11);
670 ppc_bcctr (code, PPC_BR_ALWAYS, 0);
672 tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT,
673 mono_get_root_domain (), NULL);
675 /* jump to the actual trampoline */
676 code = emit_trampoline_jump (code, tramp);
679 mono_arch_flush_icache (buf, code - buf);
681 g_assert (code - buf <= tramp_size);
684 *info = mono_tramp_info_create (g_strdup_printf ("generic_class_init_trampoline"), buf, code - buf, ji, unwind_ops);
690 mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info)
693 guint32 tramp_size = 64;
695 code = buf = mono_global_codeman_reserve (tramp_size);
698 mono_arch_flush_icache (buf, code - buf);
700 g_assert (code - buf <= tramp_size);
703 *info = mono_tramp_info_create (g_strdup_printf ("nullified_class_init_trampoline"), buf, code - buf, NULL, NULL);
709 mono_arch_get_call_target (guint8 *code)
712 guint32 ins = ((guint32*)(gpointer)code) [-1];
714 if ((ins >> 26 == 18) && ((ins & 1) == 1) && ((ins & 2) == 0)) {
715 gint32 disp = (((gint32)ins) >> 2) & 0xffffff;
716 guint8 *target = code - 4 + (disp * 4);
725 mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
727 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
728 return ((guint32*)plt_entry) [8];
730 return ((guint32*)plt_entry) [6];