[runtime] Register static rgctx trampolines
[mono.git] / mono / mini / tramp-arm.c
1 /*
2  * tramp-arm.c: JIT trampoline code for ARM
3  *
4  * Authors:
5  *   Paolo Molaro (lupus@ximian.com)
6  *
7  * (C) 2001-2003 Ximian, Inc.
8  * Copyright 2003-2011 Novell Inc
9  * Copyright 2011 Xamarin Inc
10  */
11
12 #include <config.h>
13 #include <glib.h>
14
15 #include <mono/metadata/abi-details.h>
16 #include <mono/metadata/appdomain.h>
17 #include <mono/metadata/marshal.h>
18 #include <mono/metadata/tabledefs.h>
19 #include <mono/metadata/profiler-private.h>
20 #include <mono/arch/arm/arm-codegen.h>
21 #include <mono/arch/arm/arm-vfp-codegen.h>
22
23 #include "mini.h"
24 #include "mini-arm.h"
25 #include "debugger-agent.h"
26
27 #define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1))
28
29 #ifdef USE_JUMP_TABLES
30
31 static guint16
32 decode_imm16 (guint32 insn)
33 {
34         return (((insn >> 16) & 0xf) << 12) | (insn & 0xfff);
35 }
36
37 #define INSN_MASK 0xff00000
38 #define MOVW_MASK ((3 << 24) | (0 << 20))
39 #define MOVT_MASK ((3 << 24) | (4 << 20))
40
41 gpointer*
42 mono_arch_jumptable_entry_from_code (guint8 *code)
43 {
44         guint32 insn1 = ((guint32*)code) [0];
45         guint32 insn2 = ((guint32*)code) [1];
46
47         if (((insn1 & INSN_MASK) == MOVW_MASK) &&
48             ((insn2 & INSN_MASK) == MOVT_MASK) ) {
49                 guint32 imm_lo = decode_imm16 (insn1);
50                 guint32 imm_hi = decode_imm16 (insn2);
51                 return (gpointer*) GUINT_TO_POINTER (imm_lo | (imm_hi << 16));
52         } else {
53                 g_assert_not_reached ();
54                 return NULL;
55         }
56 }
57
58 #undef INSN_MASK
59 #undef MOVW_MASK
60 #undef MOVT_MASK
61
62 void
63 mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
64 {
65         gpointer *jte;
66         /*
67          * code_ptr is 4 instructions after MOVW/MOVT used to address
68          * jumptable entry.
69          */
70         jte = mono_jumptable_get_entry (code_ptr - 16);
71         g_assert ( jte != NULL);
72         *jte = addr;
73 }
74 #else
75 void
76 mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
77 {
78         guint32 *code = (guint32*)code_ptr;
79
80         /* This is the 'bl' or the 'mov pc' instruction */
81         --code;
82         
83         /*
84          * Note that methods are called also with the bl opcode.
85          */
86         if ((((*code) >> 25)  & 7) == 5) {
87                 /*g_print ("direct patching\n");*/
88                 arm_patch ((guint8*)code, addr);
89                 mono_arch_flush_icache ((guint8*)code, 4);
90                 return;
91         }
92
93         if ((((*code) >> 20) & 0xFF) == 0x12) {
94                 /*g_print ("patching bx\n");*/
95                 arm_patch ((guint8*)code, addr);
96                 mono_arch_flush_icache ((guint8*)(code - 2), 4);
97                 return;
98         }
99
100         g_assert_not_reached ();
101 }
102 #endif
103
104 void
105 mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
106 {
107         guint8 *jump_entry;
108
109         /* Patch the jump table entry used by the plt entry */
110         if (*(guint32*)code == 0xe59fc000) {
111                 /* ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0); */
112                 guint32 offset = ((guint32*)code)[2];
113                 
114                 jump_entry = code + offset + 12;
115         } else if (*(guint16*)(code - 4) == 0xf8df) {
116                 /* 
117                  * Thumb PLT entry, begins with ldr.w ip, [pc, #8], code points to entry + 4, see
118                  * mono_arm_get_thumb_plt_entry ().
119                  */
120                 guint32 offset;
121
122                 code -= 4;
123                 offset = *(guint32*)(code + 12);
124                 jump_entry = code + offset + 8;
125         } else {
126                 g_assert_not_reached ();
127         }
128
129         *(guint8**)jump_entry = addr;
130 }
131
132 #ifndef DISABLE_JIT
133
134 #define arm_is_imm12(v) ((int)(v) > -4096 && (int)(v) < 4096)
135
136 #ifndef USE_JUMP_TABLES
137 /*
138  * Return the instruction to jump from code to target, 0 if not
139  * reachable with a single instruction
140  */
141 static guint32
142 branch_for_target_reachable (guint8 *branch, guint8 *target)
143 {
144         gint diff = target - branch - 8;
145         g_assert ((diff & 3) == 0);
146         if (diff >= 0) {
147                 if (diff <= 33554431)
148                         return (ARMCOND_AL << ARMCOND_SHIFT) | (ARM_BR_TAG) | (diff >> 2);
149         } else {
150                 /* diff between 0 and -33554432 */
151                 if (diff >= -33554432)
152                         return (ARMCOND_AL << ARMCOND_SHIFT) | (ARM_BR_TAG) | ((diff >> 2) & ~0xff000000);
153         }
154         return 0;
155 }
156 #endif
157
158 static inline guint8*
159 emit_bx (guint8* code, int reg)
160 {
161         if (mono_arm_thumb_supported ())
162                 ARM_BX (code, reg);
163         else
164                 ARM_MOV_REG_REG (code, ARMREG_PC, reg);
165         return code;
166 }
167
168 /* Stack size for trampoline function
169  */
170 #define STACK ALIGN_TO (sizeof (MonoLMF), 8)
171
172 /* Method-specific trampoline code fragment size */
173 #define METHOD_TRAMPOLINE_SIZE 64
174
175 /* Jump-specific trampoline code fragment size */
176 #define JUMP_TRAMPOLINE_SIZE   64
177
178 guchar*
179 mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
180 {
181         char *tramp_name;
182         guint8 *buf, *code = NULL;
183 #ifdef USE_JUMP_TABLES
184         gpointer *load_get_lmf_addr = NULL, *load_trampoline = NULL;
185 #else
186         guint8 *load_get_lmf_addr  = NULL, *load_trampoline  = NULL;
187         gpointer *constants;
188 #endif
189
190         int cfa_offset, regsave_size, lr_offset;
191         GSList *unwind_ops = NULL;
192         MonoJumpInfo *ji = NULL;
193         int buf_len;
194
195 #ifdef USE_JUMP_TABLES
196         g_assert (!aot);
197 #endif
198
199         /* Now we'll create in 'buf' the ARM trampoline code. This
200          is the trampoline code common to all methods  */
201
202         buf_len = 272;
203
204         /* Add space for saving/restoring VFP regs. */
205         if (mono_arm_is_hard_float ())
206                 buf_len += 8 * 2;
207
208         code = buf = mono_global_codeman_reserve (buf_len);
209
210         /*
211          * At this point lr points to the specific arg and sp points to the saved
212          * regs on the stack (all but PC and SP). The original LR value has been
213          * saved as sp + LR_OFFSET by the push in the specific trampoline
214          */
215
216         /* The size of the area already allocated by the push in the specific trampoline */
217         regsave_size = 14 * sizeof (mgreg_t);
218         /* The offset where lr was saved inside the regsave area */
219         lr_offset = 13 * sizeof (mgreg_t);
220
221         // FIXME: Finish the unwind info, the current info allows us to unwind
222         // when the trampoline is not in the epilog
223
224         // CFA = SP + (num registers pushed) * 4
225         cfa_offset = 14 * sizeof (mgreg_t);
226         mono_add_unwind_op_def_cfa (unwind_ops, code, buf, ARMREG_SP, cfa_offset);
227         // PC saved at sp+LR_OFFSET
228         mono_add_unwind_op_offset (unwind_ops, code, buf, ARMREG_LR, -4);
229
230         if (aot) {
231                 /* 
232                  * For page trampolines the data is in r1, so just move it, otherwise use the got slot as below.
233                  * The trampoline contains a pc-relative offset to the got slot 
234                  * preceeding the got slot where the value is stored. The offset can be
235                  * found at [lr + 0].
236                  */
237                 if (aot == 2) {
238                         ARM_MOV_REG_REG (code, ARMREG_V2, ARMREG_R1);
239                 } else {
240                         ARM_LDR_IMM (code, ARMREG_V2, ARMREG_LR, 0);
241                         ARM_ADD_REG_IMM (code, ARMREG_V2, ARMREG_V2, 4, 0);
242                         ARM_LDR_REG_REG (code, ARMREG_V2, ARMREG_V2, ARMREG_LR);
243                 }
244         } else {
245                 ARM_LDR_IMM (code, ARMREG_V2, ARMREG_LR, 0);
246         }
247         ARM_LDR_IMM (code, ARMREG_V3, ARMREG_SP, lr_offset);
248
249         /* ok, now we can continue with the MonoLMF setup, mostly untouched 
250          * from emit_prolog in mini-arm.c
251          * This is a synthetized call to mono_get_lmf_addr ()
252          */
253         if (aot) {
254                 ji = mono_patch_info_list_prepend (ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_get_lmf_addr");
255                 ARM_LDR_IMM (code, ARMREG_R0, ARMREG_PC, 0);
256                 ARM_B (code, 0);
257                 *(gpointer*)code = NULL;
258                 code += 4;
259                 ARM_LDR_REG_REG (code, ARMREG_R0, ARMREG_PC, ARMREG_R0);
260         } else {
261 #ifdef USE_JUMP_TABLES
262                 load_get_lmf_addr = mono_jumptable_add_entry ();
263                 code = mono_arm_load_jumptable_entry (code, load_get_lmf_addr, ARMREG_R0);
264 #else
265                 load_get_lmf_addr = code;
266                 code += 4;
267 #endif
268         }
269         ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
270         code = emit_bx (code, ARMREG_R0);
271
272         /* we build the MonoLMF structure on the stack - see mini-arm.h
273          * The pointer to the struct is put in r1.
274          * the iregs array is already allocated on the stack by push.
275          */
276         code = mono_arm_emit_load_imm (code, ARMREG_R2, STACK - regsave_size);
277         ARM_SUB_REG_REG (code, ARMREG_SP, ARMREG_SP, ARMREG_R2);
278         cfa_offset += STACK - regsave_size;
279         mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset);
280         /* V1 == lmf */
281         code = mono_arm_emit_load_imm (code, ARMREG_R2, STACK - sizeof (MonoLMF));
282         ARM_ADD_REG_REG (code, ARMREG_V1, ARMREG_SP, ARMREG_R2);
283
284         /*
285          * The stack now looks like:
286          *       <saved regs>
287          * v1 -> <rest of LMF>
288          * sp -> <alignment>
289          */
290
291         /* r0 is the result from mono_get_lmf_addr () */
292         ARM_STR_IMM (code, ARMREG_R0, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, lmf_addr));
293         /* new_lmf->previous_lmf = *lmf_addr */
294         ARM_LDR_IMM (code, ARMREG_R2, ARMREG_R0, MONO_STRUCT_OFFSET (MonoLMF, previous_lmf));
295         ARM_STR_IMM (code, ARMREG_R2, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, previous_lmf));
296         /* *(lmf_addr) = r1 */
297         ARM_STR_IMM (code, ARMREG_V1, ARMREG_R0, MONO_STRUCT_OFFSET (MonoLMF, previous_lmf));
298         /* save method info (it's in v2) */
299         if ((tramp_type == MONO_TRAMPOLINE_JIT) || (tramp_type == MONO_TRAMPOLINE_JUMP))
300                 ARM_STR_IMM (code, ARMREG_V2, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, method));
301         else {
302                 ARM_MOV_REG_IMM8 (code, ARMREG_R2, 0);
303                 ARM_STR_IMM (code, ARMREG_R2, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, method));
304         }
305         /* save caller SP */
306         code = mono_arm_emit_load_imm (code, ARMREG_R2, cfa_offset);
307         ARM_ADD_REG_REG (code, ARMREG_R2, ARMREG_SP, ARMREG_R2);
308         ARM_STR_IMM (code, ARMREG_R2, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, sp));
309         /* save caller FP */
310         ARM_LDR_IMM (code, ARMREG_R2, ARMREG_V1, (MONO_STRUCT_OFFSET (MonoLMF, iregs) + ARMREG_FP*4));
311         ARM_STR_IMM (code, ARMREG_R2, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, fp));
312         /* save the IP (caller ip) */
313         if (tramp_type == MONO_TRAMPOLINE_JUMP) {
314                 ARM_MOV_REG_IMM8 (code, ARMREG_R2, 0);
315         } else {
316                 ARM_LDR_IMM (code, ARMREG_R2, ARMREG_V1, (MONO_STRUCT_OFFSET (MonoLMF, iregs) + 13*4));
317         }
318         ARM_STR_IMM (code, ARMREG_R2, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, ip));
319
320         /* Save VFP registers. */
321         if (mono_arm_is_hard_float ()) {
322                 /*
323                  * Strictly speaking, we don't have to save d0-d7 in the LMF, but
324                  * it's easier than attempting to store them on the stack since
325                  * this trampoline code is pretty messy.
326                  */
327                 ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, fregs));
328                 ARM_FSTMD (code, ARM_VFP_D0, 8, ARMREG_R0);
329         }
330
331         /*
332          * Now we're ready to call xxx_trampoline ().
333          */
334         /* Arg 1: the saved registers */
335         ARM_ADD_REG_IMM (code, ARMREG_R0, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, iregs), 0);
336
337         /* Arg 2: code (next address to the instruction that called us) */
338         if (tramp_type == MONO_TRAMPOLINE_JUMP) {
339                 ARM_MOV_REG_IMM8 (code, ARMREG_R1, 0);
340         } else {
341                 ARM_MOV_REG_REG (code, ARMREG_R1, ARMREG_V3);
342         }
343         
344         /* Arg 3: the specific argument, stored in v2
345          */
346         ARM_MOV_REG_REG (code, ARMREG_R2, ARMREG_V2);
347
348         if (aot) {
349                 char *icall_name = g_strdup_printf ("trampoline_func_%d", tramp_type);
350                 ji = mono_patch_info_list_prepend (ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, icall_name);
351                 ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
352                 ARM_B (code, 0);
353                 *(gpointer*)code = NULL;
354                 code += 4;
355                 ARM_LDR_REG_REG (code, ARMREG_IP, ARMREG_PC, ARMREG_IP);
356         } else {
357 #ifdef USE_JUMP_TABLES
358                 load_trampoline = mono_jumptable_add_entry ();
359                 code = mono_arm_load_jumptable_entry (code, load_trampoline, ARMREG_IP);
360 #else
361                 load_trampoline = code;
362                 code += 4;
363 #endif
364         }
365
366         ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
367         code = emit_bx (code, ARMREG_IP);
368
369         /* OK, code address is now on r0. Move it to the place on the stack
370          * where IP was saved (it is now no more useful to us and it can be
371          * clobbered). This way we can just restore all the regs in one inst
372          * and branch to IP.
373          */
374         ARM_STR_IMM (code, ARMREG_R0, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, iregs) + (ARMREG_R12 * sizeof (mgreg_t)));
375
376         /* Check for thread interruption */
377         /* This is not perf critical code so no need to check the interrupt flag */
378         /* 
379          * Have to call the _force_ variant, since there could be a protected wrapper on the top of the stack.
380          */
381         if (aot) {
382                 ji = mono_patch_info_list_prepend (ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_thread_force_interruption_checkpoint");
383                 ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
384                 ARM_B (code, 0);
385                 *(gpointer*)code = NULL;
386                 code += 4;
387                 ARM_LDR_REG_REG (code, ARMREG_IP, ARMREG_PC, ARMREG_IP);
388         } else {
389 #ifdef USE_JUMP_TABLES
390                 gpointer *jte = mono_jumptable_add_entry ();
391                 code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
392                 jte [0] = mono_thread_force_interruption_checkpoint;
393 #else
394                 ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
395                 ARM_B (code, 0);
396                 *(gpointer*)code = mono_thread_force_interruption_checkpoint;
397                 code += 4;
398 #endif
399         }
400         ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
401         code = emit_bx (code, ARMREG_IP);
402
403         /*
404          * Now we restore the MonoLMF (see emit_epilogue in mini-arm.c)
405          * and the rest of the registers, so the method called will see
406          * the same state as before we executed.
407          */
408         /* ip = previous_lmf */
409         ARM_LDR_IMM (code, ARMREG_IP, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, previous_lmf));
410         /* lr = lmf_addr */
411         ARM_LDR_IMM (code, ARMREG_LR, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, lmf_addr));
412         /* *(lmf_addr) = previous_lmf */
413         ARM_STR_IMM (code, ARMREG_IP, ARMREG_LR, MONO_STRUCT_OFFSET (MonoLMF, previous_lmf));
414
415         /* Restore VFP registers. */
416         if (mono_arm_is_hard_float ()) {
417                 ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_V1, MONO_STRUCT_OFFSET (MonoLMF, fregs));
418                 ARM_FLDMD (code, ARM_VFP_D0, 8, ARMREG_R0);
419         }
420
421         /* Non-standard function epilogue. Instead of doing a proper
422          * return, we just jump to the compiled code.
423          */
424         /* Restore the registers and jump to the code:
425          * Note that IP has been conveniently set to the method addr.
426          */
427         ARM_ADD_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, STACK - regsave_size);
428         ARM_POP_NWB (code, 0x5fff);
429         if (tramp_type == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH)
430                 ARM_MOV_REG_REG (code, ARMREG_R0, ARMREG_IP);
431         ARM_ADD_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, regsave_size);
432         if (MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type))
433                 code = emit_bx (code, ARMREG_LR);
434         else
435                 code = emit_bx (code, ARMREG_IP);
436
437 #ifdef USE_JUMP_TABLES
438         load_get_lmf_addr [0] = mono_get_lmf_addr;
439         load_trampoline [0] = (gpointer)mono_get_trampoline_func (tramp_type);
440 #else
441         constants = (gpointer*)code;
442         constants [0] = mono_get_lmf_addr;
443         constants [1] = (gpointer)mono_get_trampoline_func (tramp_type);
444
445         if (!aot) {
446                 /* backpatch by emitting the missing instructions skipped above */
447                 ARM_LDR_IMM (load_get_lmf_addr, ARMREG_R0, ARMREG_PC, (code - load_get_lmf_addr - 8));
448                 ARM_LDR_IMM (load_trampoline, ARMREG_IP, ARMREG_PC, (code + 4 - load_trampoline - 8));
449         }
450
451         code += 8;
452 #endif
453
454         /* Flush instruction cache, since we've generated code */
455         mono_arch_flush_icache (buf, code - buf);
456         mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL);
457
458         /* Sanity check */
459         g_assert ((code - buf) <= buf_len);
460
461         g_assert (info);
462         tramp_name = mono_get_generic_trampoline_name (tramp_type);
463         *info = mono_tramp_info_create (tramp_name, buf, code - buf, ji, unwind_ops);
464         g_free (tramp_name);
465
466         return buf;
467 }
468
469 #define SPEC_TRAMP_SIZE 24
470
471 gpointer
472 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
473 {
474         guint8 *code, *buf, *tramp;
475         gpointer *constants;
476 #ifndef USE_JUMP_TABLES
477         guint32 short_branch = FALSE;
478 #endif
479         guint32 size = SPEC_TRAMP_SIZE;
480
481         tramp = mono_get_trampoline_code (tramp_type);
482
483         if (domain) {
484                 mono_domain_lock (domain);
485 #ifdef USE_JUMP_TABLES
486                 code = buf = mono_domain_code_reserve_align (domain, size, 4);
487 #else
488                 code = buf = mono_domain_code_reserve_align (domain, size, 4);
489                 if ((short_branch = branch_for_target_reachable (code + 4, tramp))) {
490                         size = 12;
491                         mono_domain_code_commit (domain, code, SPEC_TRAMP_SIZE, size);
492         }
493 #endif
494                 mono_domain_unlock (domain);
495         } else {
496                 code = buf = mono_global_codeman_reserve (size);
497                 short_branch = FALSE;
498         }
499
500 #ifdef USE_JUMP_TABLES
501         /* For jumptables case we always generate the same code for trampolines,
502          * namely
503          *   push {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}
504          *   movw lr, lo(jte)
505          *   movt lr, hi(jte)
506          *   ldr r1, [lr + 4]
507          *   bx r1
508          */
509         ARM_PUSH (code, 0x5fff);
510         constants = mono_jumptable_add_entries (2);
511         code = mono_arm_load_jumptable_entry_addr (code, constants, ARMREG_LR);
512         ARM_LDR_IMM (code, ARMREG_R1, ARMREG_LR, 4);
513         code = emit_bx (code, ARMREG_R1);
514         constants [0] = arg1;
515         constants [1] = tramp;
516 #else
517         /* we could reduce this to 12 bytes if tramp is within reach:
518          * ARM_PUSH ()
519          * ARM_BL ()
520          * method-literal
521          * The called code can access method using the lr register
522          * A 20 byte sequence could be:
523          * ARM_PUSH ()
524          * ARM_MOV_REG_REG (lr, pc)
525          * ARM_LDR_IMM (pc, pc, 0)
526          * method-literal
527          * tramp-literal
528          */
529         /* We save all the registers, except PC and SP */
530         ARM_PUSH (code, 0x5fff);
531         if (short_branch) {
532                 constants = (gpointer*)code;
533                 constants [0] = GUINT_TO_POINTER (short_branch | (1 << 24));
534                 constants [1] = arg1;
535                 code += 8;
536         } else {
537                 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 8); /* temp reg */
538                 ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
539                 code = emit_bx (code, ARMREG_R1);
540
541                 constants = (gpointer*)code;
542                 constants [0] = arg1;
543                 constants [1] = tramp;
544                 code += 8;
545         }
546 #endif
547
548         /* Flush instruction cache, since we've generated code */
549         mono_arch_flush_icache (buf, code - buf);
550         mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_SPECIFIC_TRAMPOLINE, mono_get_generic_trampoline_simple_name (tramp_type));
551
552         g_assert ((code - buf) <= size);
553
554         if (code_len)
555                 *code_len = code - buf;
556
557         return buf;
558 }
559
560 /*
561  * mono_arch_get_unbox_trampoline:
562  * @m: method pointer
563  * @addr: pointer to native code for @m
564  *
565  * when value type methods are called through the vtable we need to unbox the
566  * this argument. This method returns a pointer to a trampoline which does
567  * unboxing before calling the method
568  */
569 gpointer
570 mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
571 {
572         guint8 *code, *start;
573         MonoDomain *domain = mono_domain_get ();
574 #ifdef USE_JUMP_TABLES
575         gpointer *jte;
576         guint32 size = 20;
577 #else
578         guint32 size = 16;
579 #endif
580
581         start = code = mono_domain_code_reserve (domain, size);
582
583 #ifdef USE_JUMP_TABLES
584         jte = mono_jumptable_add_entry ();
585         code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
586         ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_R0, sizeof (MonoObject));
587         code = emit_bx (code, ARMREG_IP);
588         jte [0] = addr;
589 #else
590         ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 4);
591         ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_R0, sizeof (MonoObject));
592         code = emit_bx (code, ARMREG_IP);
593         *(guint32*)code = (guint32)addr;
594         code += 4;
595 #endif
596         mono_arch_flush_icache (start, code - start);
597         mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_UNBOX_TRAMPOLINE, m);
598         g_assert ((code - start) <= size);
599         /*g_print ("unbox trampoline at %d for %s:%s\n", this_pos, m->klass->name, m->name);
600         g_print ("unbox code is at %p for method at %p\n", start, addr);*/
601
602         return start;
603 }
604
605 gpointer
606 mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
607 {
608         guint8 *code, *start;
609 #ifdef USE_JUMP_TABLES
610         int buf_len = 20;
611         gpointer *jte;
612 #else
613         int buf_len = 16;
614 #endif
615         MonoDomain *domain = mono_domain_get ();
616
617         start = code = mono_domain_code_reserve (domain, buf_len);
618
619 #ifdef USE_JUMP_TABLES
620         jte = mono_jumptable_add_entries (2);
621         code = mono_arm_load_jumptable_entry_addr (code, jte, ARMREG_IP);
622         ARM_LDR_IMM (code, MONO_ARCH_RGCTX_REG, ARMREG_IP, 0);
623         ARM_LDR_IMM (code, ARMREG_IP, ARMREG_IP, 4);
624         ARM_BX (code, ARMREG_IP);
625         jte [0] = mrgctx;
626         jte [1] = addr;
627 #else
628         ARM_LDR_IMM (code, MONO_ARCH_RGCTX_REG, ARMREG_PC, 0);
629         ARM_LDR_IMM (code, ARMREG_PC, ARMREG_PC, 0);
630         *(guint32*)code = (guint32)mrgctx;
631         code += 4;
632         *(guint32*)code = (guint32)addr;
633         code += 4;
634 #endif
635
636         g_assert ((code - start) <= buf_len);
637
638         mono_arch_flush_icache (start, code - start);
639         mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL);
640
641         mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL));
642
643         return start;
644 }
645
646 gpointer
647 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
648 {
649         guint8 *tramp;
650         guint8 *code, *buf;
651         int tramp_size;
652         guint32 code_len;
653         guint8 **rgctx_null_jumps;
654         int depth, index;
655         int i, njumps;
656         gboolean mrgctx;
657         MonoJumpInfo *ji = NULL;
658         GSList *unwind_ops = NULL;
659 #ifdef USE_JUMP_TABLES
660         gpointer *jte;
661 #endif
662
663         mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
664         index = MONO_RGCTX_SLOT_INDEX (slot);
665         if (mrgctx)
666                 index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
667         for (depth = 0; ; ++depth) {
668                 int size = mono_class_rgctx_get_array_size (depth, mrgctx);
669
670                 if (index < size - 1)
671                         break;
672                 index -= size - 1;
673         }
674
675         tramp_size = 64 + 16 * depth;
676
677         code = buf = mono_global_codeman_reserve (tramp_size);
678
679         mono_add_unwind_op_def_cfa (unwind_ops, code, buf, ARMREG_SP, 0);
680
681         rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
682         njumps = 0;
683
684         /* The vtable/mrgctx is in R0 */
685         g_assert (MONO_ARCH_VTABLE_REG == ARMREG_R0);
686
687         if (mrgctx) {
688                 /* get mrgctx ptr */
689                 ARM_MOV_REG_REG (code, ARMREG_R1, ARMREG_R0);
690         } else {
691                 /* load rgctx ptr from vtable */
692                 g_assert (arm_is_imm12 (MONO_STRUCT_OFFSET (MonoVTable, runtime_generic_context)));
693                 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_R0, MONO_STRUCT_OFFSET (MonoVTable, runtime_generic_context));
694                 /* is the rgctx ptr null? */
695                 ARM_CMP_REG_IMM (code, ARMREG_R1, 0, 0);
696                 /* if yes, jump to actual trampoline */
697                 rgctx_null_jumps [njumps ++] = code;
698                 ARM_B_COND (code, ARMCOND_EQ, 0);
699         }
700
701         for (i = 0; i < depth; ++i) {
702                 /* load ptr to next array */
703                 if (mrgctx && i == 0) {
704                         g_assert (arm_is_imm12 (MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT));
705                         ARM_LDR_IMM (code, ARMREG_R1, ARMREG_R1, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT);
706                 } else {
707                         ARM_LDR_IMM (code, ARMREG_R1, ARMREG_R1, 0);
708                 }
709                 /* is the ptr null? */
710                 ARM_CMP_REG_IMM (code, ARMREG_R1, 0, 0);
711                 /* if yes, jump to actual trampoline */
712                 rgctx_null_jumps [njumps ++] = code;
713                 ARM_B_COND (code, ARMCOND_EQ, 0);
714         }
715
716         /* fetch slot */
717         code = mono_arm_emit_load_imm (code, ARMREG_R2, sizeof (gpointer) * (index + 1));
718         ARM_LDR_REG_REG (code, ARMREG_R1, ARMREG_R1, ARMREG_R2);
719         /* is the slot null? */
720         ARM_CMP_REG_IMM (code, ARMREG_R1, 0, 0);
721         /* if yes, jump to actual trampoline */
722         rgctx_null_jumps [njumps ++] = code;
723         ARM_B_COND (code, ARMCOND_EQ, 0);
724         /* otherwise return, result is in R1 */
725         ARM_MOV_REG_REG (code, ARMREG_R0, ARMREG_R1);
726         code = emit_bx (code, ARMREG_LR);
727
728         g_assert (njumps <= depth + 2);
729         for (i = 0; i < njumps; ++i)
730                 arm_patch (rgctx_null_jumps [i], code);
731
732         g_free (rgctx_null_jumps);
733
734         /* Slowpath */
735
736         /* The vtable/mrgctx is still in R0 */
737
738         if (aot) {
739                 ji = mono_patch_info_list_prepend (ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("specific_trampoline_lazy_fetch_%u", slot));
740                 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0);
741                 ARM_B (code, 0);
742                 *(gpointer*)code = NULL;
743                 code += 4;
744                 ARM_LDR_REG_REG (code, ARMREG_PC, ARMREG_PC, ARMREG_R1);
745         } else {
746                 tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot), MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), &code_len);
747
748                 /* Jump to the actual trampoline */
749 #ifdef USE_JUMP_TABLES
750                 jte = mono_jumptable_add_entry ();
751                 jte [0] = tramp;
752                 code = mono_arm_load_jumptable_entry (code, jte, ARMREG_R1);
753                 code = emit_bx (code, ARMREG_R1);
754 #else
755                 ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0); /* temp reg */
756                 code = emit_bx (code, ARMREG_R1);
757                 *(gpointer*)code = tramp;
758                 code += 4;
759 #endif
760         }
761
762         mono_arch_flush_icache (buf, code - buf);
763         mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL);
764
765         g_assert (code - buf <= tramp_size);
766
767         char *name = mono_get_rgctx_fetch_trampoline_name (slot);
768         *info = mono_tramp_info_create (name, buf, code - buf, ji, unwind_ops);
769         g_free (name);
770
771         return buf;
772 }
773
774 gpointer
775 mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboolean aot)
776 {
777         guint8 *code, *buf;
778         int tramp_size;
779         MonoJumpInfo *ji = NULL;
780         GSList *unwind_ops = NULL;
781
782         g_assert (aot);
783
784         tramp_size = 32;
785
786         code = buf = mono_global_codeman_reserve (tramp_size);
787
788         mono_add_unwind_op_def_cfa (unwind_ops, code, buf, ARMREG_SP, 0);
789
790         // FIXME: Currently, we always go to the slow path.
791         /* Load trampoline addr */
792         ARM_LDR_IMM (code, ARMREG_R1, MONO_ARCH_RGCTX_REG, 4);
793         /* The vtable/mrgctx is in R0 */
794         g_assert (MONO_ARCH_VTABLE_REG == ARMREG_R0);
795         code = emit_bx (code, ARMREG_R1);
796
797         mono_arch_flush_icache (buf, code - buf);
798         mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL);
799
800         g_assert (code - buf <= tramp_size);
801
802         *info = mono_tramp_info_create ("rgctx_fetch_trampoline_general", buf, code - buf, ji, unwind_ops);
803
804         return buf;
805 }
806
807 static gpointer
808 handler_block_trampoline_helper (gpointer *ptr)
809 {
810         MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
811         return jit_tls->handler_block_return_address;
812 }
813
814 gpointer
815 mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot)
816 {
817         guint8 *tramp;
818         guint8 *code, *buf;
819         int tramp_size = 64;
820         MonoJumpInfo *ji = NULL;
821         GSList *unwind_ops = NULL;
822
823         g_assert (!aot);
824
825         code = buf = mono_global_codeman_reserve (tramp_size);
826
827         tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD, NULL, NULL);
828
829         /*
830         This trampoline restore the call chain of the handler block then jumps into the code that deals with it.
831         */
832
833         /*
834          * We are in a method frame after the call emitted by OP_CALL_HANDLER.
835          */
836         /* Obtain jit_tls->handler_block_return_address */
837         ARM_LDR_IMM (code, ARMREG_R0, ARMREG_PC, 0);
838         ARM_B (code, 0);
839         *(gpointer*)code = handler_block_trampoline_helper;
840         code += 4;
841
842         /* Set it as the return address so the trampoline will return to it */
843         ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_R0);
844
845         /* Call the trampoline */
846         ARM_LDR_IMM (code, ARMREG_R0, ARMREG_PC, 0);
847         code = emit_bx (code, ARMREG_R0);
848         *(gpointer*)code = tramp;
849         code += 4;
850
851         mono_arch_flush_icache (buf, code - buf);
852         mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL);
853         g_assert (code - buf <= tramp_size);
854
855         *info = mono_tramp_info_create ("handler_block_trampoline", buf, code - buf, ji, unwind_ops);
856
857         return buf;
858 }
859
860 guint8*
861 mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot)
862 {
863         guint8 *buf, *code;
864         GSList *unwind_ops = NULL;
865         MonoJumpInfo *ji = NULL;
866         int frame_size;
867
868         buf = code = mono_global_codeman_reserve (96);
869
870         /*
871          * Construct the MonoContext structure on the stack.
872          */
873
874         frame_size = sizeof (MonoContext);
875         frame_size = ALIGN_TO (frame_size, MONO_ARCH_FRAME_ALIGNMENT);
876         ARM_SUB_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, frame_size);
877
878         /* save ip, lr and pc into their correspodings ctx.regs slots. */
879         ARM_STR_IMM (code, ARMREG_IP, ARMREG_SP, MONO_STRUCT_OFFSET (MonoContext, regs) + sizeof (mgreg_t) * ARMREG_IP);
880         ARM_STR_IMM (code, ARMREG_LR, ARMREG_SP, MONO_STRUCT_OFFSET (MonoContext, regs) + 4 * ARMREG_LR);
881         ARM_STR_IMM (code, ARMREG_LR, ARMREG_SP, MONO_STRUCT_OFFSET (MonoContext, regs) + 4 * ARMREG_PC);
882
883         /* save r0..r10 and fp */
884         ARM_ADD_REG_IMM8 (code, ARMREG_IP, ARMREG_SP, MONO_STRUCT_OFFSET (MonoContext, regs));
885         ARM_STM (code, ARMREG_IP, 0x0fff);
886
887         /* now we can update fp. */
888         ARM_MOV_REG_REG (code, ARMREG_FP, ARMREG_SP);
889
890         /* make ctx.esp hold the actual value of sp at the beginning of this method. */
891         ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_FP, frame_size);
892         ARM_STR_IMM (code, ARMREG_R0, ARMREG_IP, 4 * ARMREG_SP);
893         ARM_STR_IMM (code, ARMREG_R0, ARMREG_FP, MONO_STRUCT_OFFSET (MonoContext, regs) + 4 * ARMREG_SP);
894
895         /* make ctx.eip hold the address of the call. */
896         ARM_SUB_REG_IMM8 (code, ARMREG_LR, ARMREG_LR, 4);
897         ARM_STR_IMM (code, ARMREG_LR, ARMREG_FP, MONO_STRUCT_OFFSET (MonoContext, pc));
898
899         /* r0 now points to the MonoContext */
900         ARM_MOV_REG_REG (code, ARMREG_R0, ARMREG_FP);
901
902         /* call */
903         // FIXME: AOT
904 #ifdef USE_JUMP_TABLES
905         {
906                 gpointer *jte = mono_jumptable_add_entry ();
907                 code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
908                 jte [0] = function;
909         }
910 #else
911         ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
912         ARM_B (code, 0);
913         if (single_step)
914                 *(gpointer*)code = debugger_agent_single_step_from_context;
915         else
916                 *(gpointer*)code = debugger_agent_breakpoint_from_context;
917         code += 4;
918 #endif
919         ARM_BLX_REG (code, ARMREG_IP);
920
921         /* we're back; save ctx.eip and ctx.esp into the corresponding regs slots. */
922         ARM_LDR_IMM (code, ARMREG_R0, ARMREG_FP, MONO_STRUCT_OFFSET (MonoContext, pc));
923         ARM_STR_IMM (code, ARMREG_R0, ARMREG_FP, MONO_STRUCT_OFFSET (MonoContext, regs) + 4 * ARMREG_LR);
924         ARM_STR_IMM (code, ARMREG_R0, ARMREG_FP, MONO_STRUCT_OFFSET (MonoContext, regs) + 4 * ARMREG_PC);
925
926         /* make ip point to the regs array, then restore everything, including pc. */
927         ARM_ADD_REG_IMM8 (code, ARMREG_IP, ARMREG_FP, MONO_STRUCT_OFFSET (MonoContext, regs));
928         ARM_LDM (code, ARMREG_IP, 0xffff);
929
930         mono_arch_flush_icache (buf, code - buf);
931         mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL);
932
933         const char *tramp_name = single_step ? "sdb_single_step_trampoline" : "sdb_breakpoint_trampoline";
934         *info = mono_tramp_info_create (tramp_name, buf, code - buf, ji, unwind_ops);
935
936         return buf;
937 }
938
939 #else
940
941 guchar*
942 mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
943 {
944         g_assert_not_reached ();
945         return NULL;
946 }
947
948 gpointer
949 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
950 {
951         g_assert_not_reached ();
952         return NULL;
953 }
954
955 gpointer
956 mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
957 {
958         g_assert_not_reached ();
959         return NULL;
960 }
961
962 gpointer
963 mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
964 {
965         g_assert_not_reached ();
966         return NULL;
967 }
968
969 gpointer
970 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
971 {
972         g_assert_not_reached ();
973         return NULL;
974 }
975
976 gpointer
977 mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot)
978 {
979         g_assert_not_reached ();
980         return NULL;
981 }
982
983 guint8*
984 mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot)
985 {
986         g_assert_not_reached ();
987         return NULL;
988 }
989         
990 #endif /* DISABLE_JIT */
991
992 guint8*
993 mono_arch_get_call_target (guint8 *code)
994 {
995         guint32 ins = ((guint32*)(gpointer)code) [-1];
996
997 #if MONOTOUCH
998         /* Should be a 'bl' or a 'b' */
999         if (((ins >> 25) & 0x7) == 0x5) {
1000 #else
1001         /* Should be a 'bl' */
1002         if ((((ins >> 25) & 0x7) == 0x5) && (((ins >> 24) & 0x1) == 0x1)) {
1003 #endif
1004                 gint32 disp = ((((gint32)ins) & 0xffffff) << 8) >> 8;
1005                 guint8 *target = code - 4 + 8 + (disp * 4);
1006
1007                 return target;
1008         } else {
1009                 return NULL;
1010         }
1011 }
1012
1013 guint32
1014 mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
1015 {
1016         /* The offset is stored as the 4th word of the plt entry */
1017         return ((guint32*)plt_entry) [3];
1018 }
1019
1020 /*
1021  * Return the address of the PLT entry called by the thumb code CODE.
1022  */
1023 guint8*
1024 mono_arm_get_thumb_plt_entry (guint8 *code)
1025 {
1026         int s, j1, j2, imm10, imm11, i1, i2, imm32;
1027         guint8 *bl, *base;
1028         guint16 t1, t2;
1029         guint8 *target;
1030
1031         /* code should be right after a BL */
1032         code = (guint8*)((mgreg_t)code & ~1);
1033         base = (guint8*)((mgreg_t)code & ~3);
1034         bl = code - 4;
1035         t1 = ((guint16*)bl) [0];
1036         t2 = ((guint16*)bl) [1];
1037
1038         g_assert ((t1 >> 11) == 0x1e);
1039
1040         s = (t1 >> 10) & 0x1;
1041         imm10 = (t1 >> 0) & 0x3ff;
1042         j1 = (t2 >> 13) & 0x1;
1043         j2 = (t2 >> 11) & 0x1;
1044         imm11 = t2 & 0x7ff;
1045
1046         i1 = (s ^ j1) ? 0 : 1;
1047         i2 = (s ^ j2) ? 0 : 1;
1048
1049         imm32 = (imm11 << 1) | (imm10 << 12) | (i2 << 22) | (i1 << 23);
1050         if (s)
1051                 /* Sign extend from 24 bits to 32 bits */
1052                 imm32 = ((gint32)imm32 << 8) >> 8;
1053
1054         target = code + imm32;
1055
1056         /* target now points to the thumb plt entry */
1057         /* ldr.w r12, [pc, #8] */
1058         g_assert (((guint16*)target) [0] == 0xf8df);
1059         g_assert (((guint16*)target) [1] == 0xc008);
1060
1061         /* 
1062          * The PLT info offset is at offset 16, but mono_arch_get_plt_entry_offset () returns
1063          * the 3rd word, so compensate by returning a different value.
1064          */
1065         target += 4;
1066
1067         return target;
1068 }
1069
1070 #ifndef DISABLE_JIT
1071
1072 /*
1073  * mono_arch_get_gsharedvt_arg_trampoline:
1074  *
1075  *   See tramp-x86.c for documentation.
1076  */
1077 gpointer
1078 mono_arch_get_gsharedvt_arg_trampoline (MonoDomain *domain, gpointer arg, gpointer addr)
1079 {
1080         guint8 *code, *buf;
1081         int buf_len;
1082         gpointer *constants;
1083
1084         buf_len = 24;
1085
1086         buf = code = mono_domain_code_reserve (domain, buf_len);
1087
1088         /* Similar to the specialized trampoline code */
1089         ARM_PUSH (code, (1 << ARMREG_R0) | (1 << ARMREG_R1) | (1 << ARMREG_R2) | (1 << ARMREG_R3) | (1 << ARMREG_LR));
1090         ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 8);
1091         /* arg is passed in LR */
1092         ARM_LDR_IMM (code, ARMREG_LR, ARMREG_PC, 0);
1093         code = emit_bx (code, ARMREG_IP);
1094         constants = (gpointer*)code;
1095         constants [0] = arg;
1096         constants [1] = addr;
1097         code += 8;
1098
1099         g_assert ((code - buf) <= buf_len);
1100
1101         nacl_domain_code_validate (domain, &buf, buf_len, &code);
1102         mono_arch_flush_icache (buf, code - buf);
1103         mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL);
1104
1105         return buf;
1106 }
1107
1108 #else
1109
1110 gpointer
1111 mono_arch_get_gsharedvt_arg_trampoline (MonoDomain *domain, gpointer arg, gpointer addr)
1112 {
1113         g_assert_not_reached ();
1114         return NULL;
1115 }
1116
1117 #endif
1118
1119 #if defined(ENABLE_GSHAREDVT)
1120
1121 #include "../../../mono-extensions/mono/mini/tramp-arm-gsharedvt.c"
1122
1123 #else
1124
1125 gpointer
1126 mono_arm_start_gsharedvt_call (GSharedVtCallInfo *info, gpointer *caller, gpointer *callee, gpointer mrgctx_reg)
1127 {
1128         g_assert_not_reached ();
1129         return NULL;
1130 }
1131
1132 gpointer
1133 mono_arch_get_gsharedvt_trampoline (MonoTrampInfo **info, gboolean aot)
1134 {
1135         *info = NULL;
1136         return NULL;
1137 }
1138
1139 #endif /* !MONOTOUCH */