2 * tramp-arm.c: JIT trampoline code for ARM
5 * Paolo Molaro (lupus@ximian.com)
7 * (C) 2001 Ximian, Inc.
13 #include <mono/metadata/appdomain.h>
14 #include <mono/metadata/marshal.h>
15 #include <mono/metadata/tabledefs.h>
16 #include <mono/arch/arm/arm-codegen.h>
21 static guint8* nullified_class_init_trampoline;
24 * Return the instruction to jump from code to target, 0 if not
25 * reachable with a single instruction
28 branch_for_target_reachable (guint8 *branch, guint8 *target)
30 gint diff = target - branch - 8;
31 g_assert ((diff & 3) == 0);
34 return (ARMCOND_AL << ARMCOND_SHIFT) | (ARM_BR_TAG) | (diff >> 2);
36 /* diff between 0 and -33554432 */
37 if (diff >= -33554432)
38 return (ARMCOND_AL << ARMCOND_SHIFT) | (ARM_BR_TAG) | ((diff >> 2) & ~0xff000000);
44 * mono_arch_get_unbox_trampoline:
45 * @gsctx: the generic sharing context
47 * @addr: pointer to native code for @m
49 * when value type methods are called through the vtable we need to unbox the
50 * this argument. This method returns a pointer to a trampoline which does
51 * unboxing before calling the method
54 mono_arch_get_unbox_trampoline (MonoGenericSharingContext *gsctx, MonoMethod *m, gpointer addr)
58 MonoDomain *domain = mono_domain_get ();
60 if (MONO_TYPE_ISSTRUCT (mono_method_signature (m)->ret))
63 start = code = mono_domain_code_reserve (domain, 16);
65 ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 4);
66 ARM_ADD_REG_IMM8 (code, this_pos, this_pos, sizeof (MonoObject));
67 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_IP);
68 *(guint32*)code = (guint32)addr;
70 mono_arch_flush_icache (start, code - start);
71 g_assert ((code - start) <= 16);
72 /*g_print ("unbox trampoline at %d for %s:%s\n", this_pos, m->klass->name, m->name);
73 g_print ("unbox code is at %p for method at %p\n", start, addr);*/
79 mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
84 MonoDomain *domain = mono_domain_get ();
88 start = code = mono_domain_code_reserve (domain, buf_len);
90 ARM_LDR_IMM (code, MONO_ARCH_RGCTX_REG, ARMREG_PC, 0);
91 ARM_LDR_IMM (code, ARMREG_PC, ARMREG_PC, 0);
92 *(guint32*)code = (guint32)mrgctx;
94 *(guint32*)code = (guint32)addr;
97 g_assert ((code - start) <= buf_len);
99 mono_arch_flush_icache (start, code - start);
105 mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
107 guint32 *code = (guint32*)code_ptr;
109 /* This is the 'bl' or the 'mov pc' instruction */
113 * Note that methods are called also with the bl opcode.
115 if ((((*code) >> 25) & 7) == 5) {
116 /*g_print ("direct patching\n");*/
117 arm_patch ((guint8*)code, addr);
118 mono_arch_flush_icache ((guint8*)code, 4);
122 if ((((*code) >> 20) & 0xFF) == 0x12) {
123 /*g_print ("patching bx\n");*/
124 arm_patch ((guint8*)code, addr);
125 mono_arch_flush_icache ((guint8*)(code - 2), 4);
129 g_assert_not_reached ();
133 mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
137 /* Patch the jump table entry used by the plt entry */
138 if (*(guint32*)code == 0xe59fc000) {
139 /* ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0); */
140 guint32 offset = ((guint32*)code)[2];
142 jump_entry = code + offset + 12;
144 g_assert_not_reached ();
147 *(guint8**)jump_entry = addr;
151 mono_arch_nullify_class_init_trampoline (guint8 *code, mgreg_t *regs)
153 mono_arch_patch_callsite (NULL, code, nullified_class_init_trampoline);
157 mono_arch_nullify_plt_entry (guint8 *code, mgreg_t *regs)
159 if (mono_aot_only && !nullified_class_init_trampoline)
160 nullified_class_init_trampoline = mono_aot_get_named_code ("nullified_class_init_trampoline");
162 mono_arch_patch_plt_entry (code, NULL, regs, nullified_class_init_trampoline);
165 /* Stack size for trampoline function
167 #define STACK (sizeof (MonoLMF))
169 /* Method-specific trampoline code fragment size */
170 #define METHOD_TRAMPOLINE_SIZE 64
172 /* Jump-specific trampoline code fragment size */
173 #define JUMP_TRAMPOLINE_SIZE 64
175 #define GEN_TRAMP_SIZE 192
178 * Stack frame description when the generic trampoline is called.
180 * ------------------- old sp
182 * ------------------- sp
185 mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
190 GSList *unwind_ops, *l;
192 code = mono_arch_create_trampoline_code_full (tramp_type, &code_size, &ji, &unwind_ops, FALSE);
194 mono_save_trampoline_xdebug_info ("<generic_trampoline>", code, code_size, unwind_ops);
196 for (l = unwind_ops; l; l = l->next)
198 g_slist_free (unwind_ops);
204 mono_arch_create_trampoline_code_full (MonoTrampolineType tramp_type, guint32 *code_size, MonoJumpInfo **ji, GSList **out_unwind_ops, gboolean aot)
206 guint8 *buf, *code = NULL;
207 guint8 *load_get_lmf_addr, *load_trampoline;
209 GSList *unwind_ops = NULL;
214 /* Now we'll create in 'buf' the ARM trampoline code. This
215 is the trampoline code common to all methods */
217 code = buf = mono_global_codeman_reserve (GEN_TRAMP_SIZE);
220 * At this point lr points to the specific arg and sp points to the saved
221 * regs on the stack (all but PC and SP). The original LR value has been
222 * saved as sp + LR_OFFSET by the push in the specific trampoline
224 #define LR_OFFSET (sizeof (gpointer) * 13)
226 // FIXME: Finish the unwind info, the current info allows us to unwind
227 // when the trampoline is not in the epilog
229 // CFA = SP + (num registers pushed) * 4
230 cfa_offset = 14 * sizeof (gpointer);
231 mono_add_unwind_op_def_cfa (unwind_ops, code, buf, ARMREG_SP, cfa_offset);
232 // PC saved at sp+LR_OFFSET
233 mono_add_unwind_op_offset (unwind_ops, code, buf, ARMREG_LR, -4);
235 ARM_MOV_REG_REG (code, ARMREG_V1, ARMREG_SP);
236 if (aot && tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT) {
238 * The trampoline contains a pc-relative offset to the got slot
239 * preceeding the got slot where the value is stored. The offset can be
242 ARM_LDR_IMM (code, ARMREG_V2, ARMREG_LR, 0);
243 ARM_ADD_REG_IMM (code, ARMREG_V2, ARMREG_V2, 4, 0);
244 ARM_LDR_REG_REG (code, ARMREG_V2, ARMREG_V2, ARMREG_LR);
246 if (tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
247 ARM_LDR_IMM (code, ARMREG_V2, ARMREG_LR, 0);
249 ARM_MOV_REG_REG (code, ARMREG_V2, MONO_ARCH_VTABLE_REG);
251 ARM_LDR_IMM (code, ARMREG_V3, ARMREG_SP, LR_OFFSET);
253 /* ok, now we can continue with the MonoLMF setup, mostly untouched
254 * from emit_prolog in mini-arm.c
255 * This is a synthetized call to mono_get_lmf_addr ()
258 *ji = mono_patch_info_list_prepend (*ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_get_lmf_addr");
259 ARM_LDR_IMM (code, ARMREG_R0, ARMREG_PC, 0);
261 *(gpointer*)code = NULL;
263 ARM_LDR_REG_REG (code, ARMREG_R0, ARMREG_PC, ARMREG_R0);
265 load_get_lmf_addr = code;
268 ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
269 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_R0);
271 /* we build the MonoLMF structure on the stack - see mini-arm.h
272 * The pointer to the struct is put in r1.
273 * the iregs array is already allocated on the stack by push.
275 ARM_SUB_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, sizeof (MonoLMF) - sizeof (guint) * 14);
276 cfa_offset += sizeof (MonoLMF) - sizeof (guint) * 14;
277 mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset);
278 ARM_ADD_REG_IMM8 (code, ARMREG_R1, ARMREG_SP, STACK - sizeof (MonoLMF));
279 /* r0 is the result from mono_get_lmf_addr () */
280 ARM_STR_IMM (code, ARMREG_R0, ARMREG_R1, G_STRUCT_OFFSET (MonoLMF, lmf_addr));
281 /* new_lmf->previous_lmf = *lmf_addr */
282 ARM_LDR_IMM (code, ARMREG_R2, ARMREG_R0, G_STRUCT_OFFSET (MonoLMF, previous_lmf));
283 ARM_STR_IMM (code, ARMREG_R2, ARMREG_R1, G_STRUCT_OFFSET (MonoLMF, previous_lmf));
284 /* *(lmf_addr) = r1 */
285 ARM_STR_IMM (code, ARMREG_R1, ARMREG_R0, G_STRUCT_OFFSET (MonoLMF, previous_lmf));
286 /* save method info (it's in v2) */
287 if ((tramp_type == MONO_TRAMPOLINE_JIT) || (tramp_type == MONO_TRAMPOLINE_JUMP))
288 ARM_STR_IMM (code, ARMREG_V2, ARMREG_R1, G_STRUCT_OFFSET (MonoLMF, method));
289 ARM_STR_IMM (code, ARMREG_SP, ARMREG_R1, G_STRUCT_OFFSET (MonoLMF, ebp));
290 /* save the IP (caller ip) */
291 if (tramp_type == MONO_TRAMPOLINE_JUMP) {
292 ARM_MOV_REG_IMM8 (code, ARMREG_R2, 0);
294 /* assumes STACK == sizeof (MonoLMF) */
295 ARM_LDR_IMM (code, ARMREG_R2, ARMREG_SP, (G_STRUCT_OFFSET (MonoLMF, iregs) + 13*4));
297 ARM_STR_IMM (code, ARMREG_R2, ARMREG_R1, G_STRUCT_OFFSET (MonoLMF, eip));
300 * Now we're ready to call xxx_trampoline ().
302 /* Arg 1: the saved registers. It was put in v1 */
303 ARM_MOV_REG_REG (code, ARMREG_R0, ARMREG_V1);
305 /* Arg 2: code (next address to the instruction that called us) */
306 if (tramp_type == MONO_TRAMPOLINE_JUMP) {
307 ARM_MOV_REG_IMM8 (code, ARMREG_R1, 0);
309 ARM_MOV_REG_REG (code, ARMREG_R1, ARMREG_V3);
312 /* Arg 3: the specific argument, stored in v2
314 ARM_MOV_REG_REG (code, ARMREG_R2, ARMREG_V2);
317 char *icall_name = g_strdup_printf ("trampoline_func_%d", tramp_type);
318 *ji = mono_patch_info_list_prepend (*ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, icall_name);
319 ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
321 *(gpointer*)code = NULL;
323 ARM_LDR_REG_REG (code, ARMREG_IP, ARMREG_PC, ARMREG_IP);
325 load_trampoline = code;
329 ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
330 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_IP);
332 /* OK, code address is now on r0. Move it to the place on the stack
333 * where IP was saved (it is now no more useful to us and it can be
334 * clobbered). This way we can just restore all the regs in one inst
337 ARM_STR_IMM (code, ARMREG_R0, ARMREG_V1, (ARMREG_R12 * 4));
339 /* Check for thread interruption */
340 /* This is not perf critical code so no need to check the interrupt flag */
342 * Have to call the _force_ variant, since there could be a protected wrapper on the top of the stack.
345 *ji = mono_patch_info_list_prepend (*ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_thread_force_interruption_checkpoint");
346 ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
348 *(gpointer*)code = NULL;
350 ARM_LDR_REG_REG (code, ARMREG_IP, ARMREG_PC, ARMREG_IP);
352 ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
354 *(gpointer*)code = mono_thread_force_interruption_checkpoint;
357 ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
358 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_IP);
361 * Now we restore the MonoLMF (see emit_epilogue in mini-arm.c)
362 * and the rest of the registers, so the method called will see
363 * the same state as before we executed.
364 * The pointer to MonoLMF is in r2.
366 ARM_MOV_REG_REG (code, ARMREG_R2, ARMREG_SP);
367 /* ip = previous_lmf */
368 ARM_LDR_IMM (code, ARMREG_IP, ARMREG_R2, G_STRUCT_OFFSET (MonoLMF, previous_lmf));
370 ARM_LDR_IMM (code, ARMREG_LR, ARMREG_R2, G_STRUCT_OFFSET (MonoLMF, lmf_addr));
371 /* *(lmf_addr) = previous_lmf */
372 ARM_STR_IMM (code, ARMREG_IP, ARMREG_LR, G_STRUCT_OFFSET (MonoLMF, previous_lmf));
374 /* Non-standard function epilogue. Instead of doing a proper
375 * return, we just jump to the compiled code.
377 /* Restore the registers and jump to the code:
378 * Note that IP has been conveniently set to the method addr.
380 ARM_ADD_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, sizeof (MonoLMF) - sizeof (guint) * 14);
381 ARM_POP_NWB (code, 0x5fff);
382 if (tramp_type == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH)
383 ARM_MOV_REG_REG (code, ARMREG_R0, ARMREG_IP);
384 /* do we need to set sp? */
385 ARM_ADD_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, (14 * 4));
386 if ((tramp_type == MONO_TRAMPOLINE_CLASS_INIT) || (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT) || (tramp_type == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH))
387 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_LR);
389 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_IP);
391 constants = (gpointer*)code;
392 constants [0] = mono_get_lmf_addr;
393 constants [1] = (gpointer)mono_get_trampoline_func (tramp_type);
396 /* backpatch by emitting the missing instructions skipped above */
397 ARM_LDR_IMM (load_get_lmf_addr, ARMREG_R0, ARMREG_PC, (code - load_get_lmf_addr - 8));
398 ARM_LDR_IMM (load_trampoline, ARMREG_IP, ARMREG_PC, (code + 4 - load_trampoline - 8));
403 /* Flush instruction cache, since we've generated code */
404 mono_arch_flush_icache (buf, code - buf);
407 g_assert ((code - buf) <= GEN_TRAMP_SIZE);
409 *code_size = code - buf;
411 if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT) {
414 /* Initialize the nullified class init trampoline used in the AOT case */
415 nullified_class_init_trampoline = mono_arch_get_nullified_class_init_trampoline (&code_len);
418 *out_unwind_ops = unwind_ops;
424 mono_arch_get_nullified_class_init_trampoline (guint32 *code_len)
428 code = buf = mono_global_codeman_reserve (16);
430 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_LR);
432 mono_arch_flush_icache (buf, code - buf);
434 *code_len = code - buf;
439 #define SPEC_TRAMP_SIZE 24
442 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
444 guint8 *code, *buf, *tramp;
446 guint32 short_branch, size = SPEC_TRAMP_SIZE;
448 tramp = mono_get_trampoline_code (tramp_type);
450 mono_domain_lock (domain);
451 code = buf = mono_domain_code_reserve_align (domain, size, 4);
452 if ((short_branch = branch_for_target_reachable (code + 8, tramp))) {
454 mono_domain_code_commit (domain, code, SPEC_TRAMP_SIZE, size);
456 mono_domain_unlock (domain);
458 /* we could reduce this to 12 bytes if tramp is within reach:
462 * The called code can access method using the lr register
463 * A 20 byte sequence could be:
465 * ARM_MOV_REG_REG (lr, pc)
466 * ARM_LDR_IMM (pc, pc, 0)
470 /* We save all the registers, except PC and SP */
471 ARM_PUSH (code, 0x5fff);
473 constants = (gpointer*)code;
474 constants [0] = GUINT_TO_POINTER (short_branch | (1 << 24));
475 constants [1] = arg1;
478 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 8); /* temp reg */
479 ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
480 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_R1);
482 constants = (gpointer*)code;
483 constants [0] = arg1;
484 constants [1] = tramp;
488 /* Flush instruction cache, since we've generated code */
489 mono_arch_flush_icache (buf, code - buf);
491 g_assert ((code - buf) <= size);
494 *code_len = code - buf;
499 #define arm_is_imm12(v) ((int)(v) > -4096 && (int)(v) < 4096)
502 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot)
507 return mono_arch_create_rgctx_lazy_fetch_trampoline_full (slot, &code_size, &ji, FALSE);
511 mono_arch_create_rgctx_lazy_fetch_trampoline_full (guint32 slot, guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
517 guint8 **rgctx_null_jumps;
524 mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
525 index = MONO_RGCTX_SLOT_INDEX (slot);
527 index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
528 for (depth = 0; ; ++depth) {
529 int size = mono_class_rgctx_get_array_size (depth, mrgctx);
531 if (index < size - 1)
536 tramp_size = 64 + 16 * depth;
538 code = buf = mono_global_codeman_reserve (tramp_size);
540 rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
543 /* The vtable/mrgctx is in R0 */
544 g_assert (MONO_ARCH_VTABLE_REG == ARMREG_R0);
548 ARM_MOV_REG_REG (code, ARMREG_R1, ARMREG_R0);
550 /* load rgctx ptr from vtable */
551 g_assert (arm_is_imm12 (G_STRUCT_OFFSET (MonoVTable, runtime_generic_context)));
552 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_R0, G_STRUCT_OFFSET (MonoVTable, runtime_generic_context));
553 /* is the rgctx ptr null? */
554 ARM_CMP_REG_IMM (code, ARMREG_R1, 0, 0);
555 /* if yes, jump to actual trampoline */
556 rgctx_null_jumps [njumps ++] = code;
557 ARM_B_COND (code, ARMCOND_EQ, 0);
560 for (i = 0; i < depth; ++i) {
561 /* load ptr to next array */
562 if (mrgctx && i == 0) {
563 g_assert (arm_is_imm12 (MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT));
564 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_R1, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT);
566 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_R1, 0);
568 /* is the ptr null? */
569 ARM_CMP_REG_IMM (code, ARMREG_R1, 0, 0);
570 /* if yes, jump to actual trampoline */
571 rgctx_null_jumps [njumps ++] = code;
572 ARM_B_COND (code, ARMCOND_EQ, 0);
576 code = mono_arm_emit_load_imm (code, ARMREG_R2, sizeof (gpointer) * (index + 1));
577 ARM_LDR_REG_REG (code, ARMREG_R1, ARMREG_R1, ARMREG_R2);
578 /* is the slot null? */
579 ARM_CMP_REG_IMM (code, ARMREG_R1, 0, 0);
580 /* if yes, jump to actual trampoline */
581 rgctx_null_jumps [njumps ++] = code;
582 ARM_B_COND (code, ARMCOND_EQ, 0);
583 /* otherwise return, result is in R1 */
584 ARM_MOV_REG_REG (code, ARMREG_R0, ARMREG_R1);
585 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_LR);
587 g_assert (njumps <= depth + 2);
588 for (i = 0; i < njumps; ++i)
589 arm_patch (rgctx_null_jumps [i], code);
591 g_free (rgctx_null_jumps);
595 /* The vtable/mrgctx is still in R0 */
598 *ji = mono_patch_info_list_prepend (*ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("specific_trampoline_lazy_fetch_%u", slot));
599 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0);
601 *(gpointer*)code = NULL;
603 ARM_LDR_REG_REG (code, ARMREG_PC, ARMREG_PC, ARMREG_R1);
605 tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot), MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), &code_len);
607 /* Jump to the actual trampoline */
608 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0); /* temp reg */
609 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_R1);
610 *(gpointer*)code = tramp;
614 mono_arch_flush_icache (buf, code - buf);
616 g_assert (code - buf <= tramp_size);
618 *code_size = code - buf;
623 #define arm_is_imm8(v) ((v) > -256 && (v) < 256)
626 mono_arch_create_generic_class_init_trampoline (void)
631 return mono_arch_create_generic_class_init_trampoline_full (&code_size, &ji, FALSE);
635 mono_arch_create_generic_class_init_trampoline_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
639 static int byte_offset = -1;
640 static guint8 bitmask;
643 guint32 code_len, imm8;
650 code = buf = mono_global_codeman_reserve (tramp_size);
653 mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
655 g_assert (arm_is_imm8 (byte_offset));
656 ARM_LDRSB_IMM (code, ARMREG_IP, MONO_ARCH_VTABLE_REG, byte_offset);
657 imm8 = mono_arm_is_rotated_imm8 (bitmask, &rot_amount);
658 g_assert (imm8 >= 0);
659 ARM_AND_REG_IMM (code, ARMREG_IP, ARMREG_IP, imm8, rot_amount);
660 ARM_CMP_REG_IMM (code, ARMREG_IP, 0, 0);
662 ARM_B_COND (code, ARMCOND_EQ, 0);
664 /* Initialized case */
665 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_LR);
667 /* Uninitialized case */
668 arm_patch (jump, code);
671 *ji = mono_patch_info_list_prepend (*ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_generic_class_init");
672 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0);
674 *(gpointer*)code = NULL;
676 ARM_LDR_REG_REG (code, ARMREG_PC, ARMREG_PC, ARMREG_R1);
678 tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT, mono_get_root_domain (), &code_len);
680 /* Jump to the actual trampoline */
681 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0); /* temp reg */
682 ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_R1);
683 *(gpointer*)code = tramp;
687 mono_arch_flush_icache (buf, code - buf);
689 g_assert (code - buf <= tramp_size);
691 *code_size = code - buf;