Merge pull request #2816 from xmcclure/profile-clean-0
[mono.git] / mono / mini / tramp-arm64.c
1 /*
2  * tramp-arm64.c: JIT trampoline code for ARM64
3  *
4  * Copyright 2013 Xamarin Inc
5  *
6  * Based on tramp-arm.c:
7  * 
8  * Authors:
9  *   Paolo Molaro (lupus@ximian.com)
10  *
11  * (C) 2001-2003 Ximian, Inc.
12  * Copyright 2003-2011 Novell Inc
13  * Copyright 2011 Xamarin Inc
14  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
15  */
16
17 #include "mini.h"
18 #include "debugger-agent.h"
19
20 #include <mono/arch/arm64/arm64-codegen.h>
21 #include <mono/metadata/abi-details.h>
22
23 #define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1))
24
25 void
26 mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
27 {
28         mono_arm_patch (code_ptr - 4, addr, MONO_R_ARM64_BL);
29         mono_arch_flush_icache (code_ptr - 4, 4);
30 }
31
32 void
33 mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
34 {
35         guint32 ins;
36         guint64 slot_addr;
37         int disp;
38
39         /* 
40          * Decode the address loaded by the PLT entry emitted by arch_emit_plt_entry () in
41          * aot-compiler.c
42          */
43
44         /* adrp */
45         ins = ((guint32*)code) [0];
46         g_assert (((ins >> 24) & 0x1f) == 0x10);
47         disp = (((ins >> 5) & 0x7ffff) << 2) | ((ins >> 29) & 0x3);
48         /* FIXME: disp is signed */
49         g_assert ((disp >> 20) == 0);
50
51         slot_addr = ((guint64)code + (disp << 12)) & ~0xfff;
52
53         /* add x16, x16, :lo12:got */
54         ins = ((guint32*)code) [1];
55         g_assert (((ins >> 22) & 0x3) == 0);
56         slot_addr += (ins >> 10) & 0xfff;
57
58         /* ldr x16, [x16, <offset>] */
59         ins = ((guint32*)code) [2];
60         g_assert (((ins >> 24) & 0x3f) == 0x39);
61         slot_addr += ((ins >> 10) & 0xfff) * 8;
62
63         g_assert (*(guint64*)slot_addr);
64         *(gpointer*)slot_addr = addr;
65 }
66
67 guint8*
68 mono_arch_get_call_target (guint8 *code)
69 {
70         guint32 imm;
71         int disp;
72
73         code -= 4;
74
75         imm = *(guint32*)code;
76         /* Should be a bl */
77         g_assert (((imm >> 31) & 0x1) == 0x1);
78         g_assert (((imm >> 26) & 0x7) == 0x5);
79
80         disp = (imm & 0x3ffffff);
81         if ((disp >> 25) != 0)
82                 /* Negative, sing extend to 32 bits */
83                 disp = disp | 0xfc000000;
84
85         return code + (disp * 4);
86 }
87
88 guint32
89 mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code)
90 {
91         /* The offset is stored as the 5th word of the plt entry */
92         return ((guint32*)plt_entry) [4];
93 }
94
95 #ifndef DISABLE_JIT
96
97 guchar*
98 mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
99 {
100         guint8 *code, *buf, *tramp;
101         int i, buf_len, imm;
102         int frame_size, offset, gregs_offset, num_fregs, fregs_offset, arg_offset, lmf_offset;
103         guint64 gregs_regset;
104         GSList *unwind_ops = NULL;
105         MonoJumpInfo *ji = NULL;
106         char *tramp_name;
107
108         buf_len = 768;
109         buf = code = mono_global_codeman_reserve (buf_len);
110
111         /*
112          * We are getting called by a specific trampoline, ip1 contains the trampoline argument.
113          */
114
115         /* Compute stack frame size and offsets */
116         offset = 0;
117         /* frame block */
118         offset += 2 * 8;
119         /* gregs */
120         gregs_offset = offset;
121         offset += 32 * 8;
122         /* fregs */
123         // FIXME: Save 128 bits
124         /* Only have to save the argument regs */
125         num_fregs = 8;
126         fregs_offset = offset;
127         offset += num_fregs * 8;
128         /* arg */
129         arg_offset = offset;
130         offset += 8;
131         /* LMF */
132         lmf_offset = offset;
133         offset += sizeof (MonoLMF);
134         //offset += 22 * 8;
135         frame_size = ALIGN_TO (offset, MONO_ARCH_FRAME_ALIGNMENT);
136
137         /* Setup stack frame */
138         imm = frame_size;
139         while (imm > 256) {
140                 arm_subx_imm (code, ARMREG_SP, ARMREG_SP, 256);
141                 imm -= 256;
142         }
143         arm_subx_imm (code, ARMREG_SP, ARMREG_SP, imm);
144         arm_stpx (code, ARMREG_FP, ARMREG_LR, ARMREG_SP, 0);
145         arm_movspx (code, ARMREG_FP, ARMREG_SP);
146
147         /* Save gregs */
148         // FIXME: Optimize this
149         gregs_regset = ~((1 << ARMREG_FP) | (1 << ARMREG_SP));
150         code = mono_arm_emit_store_regarray (code, gregs_regset, ARMREG_FP, gregs_offset);
151         /* Save fregs */
152         for (i = 0; i < num_fregs; ++i)
153                 arm_strfpx (code, i, ARMREG_FP, fregs_offset + (i * 8));
154         /* Save trampoline arg */
155         arm_strx (code, ARMREG_IP1, ARMREG_FP, arg_offset);
156
157         /* Setup LMF */
158         arm_addx_imm (code, ARMREG_IP0, ARMREG_FP, lmf_offset);
159         code = mono_arm_emit_store_regset (code, MONO_ARCH_LMF_REGS, ARMREG_IP0, MONO_STRUCT_OFFSET (MonoLMF, gregs));
160         /* Save caller fp */
161         arm_ldrx (code, ARMREG_IP1, ARMREG_FP, 0);
162         arm_strx (code, ARMREG_IP1, ARMREG_IP0, MONO_STRUCT_OFFSET (MonoLMF, gregs) + (MONO_ARCH_LMF_REG_FP * 8));
163         /* Save caller sp */
164         arm_movx (code, ARMREG_IP1, ARMREG_FP);
165         imm = frame_size;
166         while (imm > 256) {
167                 arm_addx_imm (code, ARMREG_IP1, ARMREG_IP1, 256);
168                 imm -= 256;
169         }
170         arm_addx_imm (code, ARMREG_IP1, ARMREG_IP1, imm);
171         arm_strx (code, ARMREG_IP1, ARMREG_IP0, MONO_STRUCT_OFFSET (MonoLMF, gregs) + (MONO_ARCH_LMF_REG_SP * 8));
172         /* Save caller pc */
173         if (tramp_type == MONO_TRAMPOLINE_JUMP)
174                 arm_movx (code, ARMREG_LR, ARMREG_RZR);
175         else
176                 arm_ldrx (code, ARMREG_LR, ARMREG_FP, 8);
177         arm_strx (code, ARMREG_LR, ARMREG_IP0, MONO_STRUCT_OFFSET (MonoLMF, pc));
178
179         /* Save LMF */
180         /* Similar to emit_save_lmf () */
181         if (aot) {
182                 code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_IP0, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_get_lmf_addr");
183         } else {
184                 tramp = (guint8*)mono_get_lmf_addr;
185                 code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)tramp);
186         }
187         arm_blrx (code, ARMREG_IP0);
188         /* r0 contains the address of the tls slot holding the current lmf */
189         /* ip0 = lmf */
190         arm_addx_imm (code, ARMREG_IP0, ARMREG_FP, lmf_offset);
191         /* lmf->lmf_addr = lmf_addr */
192         arm_strx (code, ARMREG_R0, ARMREG_IP0, MONO_STRUCT_OFFSET (MonoLMF, lmf_addr));
193         /* lmf->previous_lmf = *lmf_addr */
194         arm_ldrx (code, ARMREG_IP1, ARMREG_R0, 0);
195         arm_strx (code, ARMREG_IP1, ARMREG_IP0, MONO_STRUCT_OFFSET (MonoLMF, previous_lmf));
196         /* *lmf_addr = lmf */
197         arm_strx (code, ARMREG_IP0, ARMREG_R0, 0);
198
199         /* Call the C trampoline function */
200         /* Arg 1 = gregs */
201         arm_addx_imm (code, ARMREG_R0, ARMREG_FP, gregs_offset);
202         /* Arg 2 = caller */
203         if (tramp_type == MONO_TRAMPOLINE_JUMP)
204                 arm_movx (code, ARMREG_R1, ARMREG_RZR);
205         else
206                 arm_ldrx (code, ARMREG_R1, ARMREG_FP, gregs_offset + (ARMREG_LR * 8));
207         /* Arg 3 = arg */
208         if (MONO_TRAMPOLINE_TYPE_HAS_ARG (tramp_type))
209                 /* Passed in r0 */
210                 arm_ldrx (code, ARMREG_R2, ARMREG_FP, gregs_offset + (ARMREG_R0 * 8));
211         else
212                 arm_ldrx (code, ARMREG_R2, ARMREG_FP, arg_offset);
213         /* Arg 4 = trampoline addr */
214         arm_movx (code, ARMREG_R3, ARMREG_RZR);
215
216         if (aot) {
217                 char *icall_name = g_strdup_printf ("trampoline_func_%d", tramp_type);
218                 code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_IP0, MONO_PATCH_INFO_JIT_ICALL_ADDR, icall_name);
219         } else {
220                 tramp = (guint8*)mono_get_trampoline_func (tramp_type);
221                 code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)tramp);
222         }
223         arm_blrx (code, ARMREG_IP0);
224
225         /* Restore LMF */
226         /* Similar to emit_restore_lmf () */
227         /* Clobbers ip0/ip1 */
228         /* ip0 = lmf */
229         arm_addx_imm (code, ARMREG_IP0, ARMREG_FP, lmf_offset);
230         /* ip1 = lmf->previous_lmf */
231         arm_ldrx (code, ARMREG_IP1, ARMREG_IP0, MONO_STRUCT_OFFSET (MonoLMF, previous_lmf));
232         /* ip0 = lmf->lmf_addr */
233         arm_ldrx (code, ARMREG_IP0, ARMREG_IP0, MONO_STRUCT_OFFSET (MonoLMF, lmf_addr));
234         /* *lmf_addr = previous_lmf */
235         arm_strx (code, ARMREG_IP1, ARMREG_IP0, 0);
236
237         /* Save the result to ip1 */
238         arm_movx (code, ARMREG_IP1, ARMREG_R0);
239
240         /* Restore gregs */
241         /* Only have to load the argument regs (r0..r8) and the rgctx reg */
242         code = mono_arm_emit_load_regarray (code, 0x1ff | (1 << ARMREG_LR) | (1 << MONO_ARCH_RGCTX_REG), ARMREG_FP, gregs_offset);
243         /* Restore fregs */
244         for (i = 0; i < num_fregs; ++i)
245                 arm_ldrfpx (code, i, ARMREG_FP, fregs_offset + (i * 8));
246
247         /* These trampolines return a value */
248         if (tramp_type == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH)
249                 arm_movx (code, ARMREG_R0, ARMREG_IP1);
250
251         /* Cleanup frame */
252         code = mono_arm_emit_destroy_frame (code, frame_size, ((1 << ARMREG_IP0)));
253
254         if (tramp_type == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH)
255                 arm_retx (code, ARMREG_LR);
256         else
257                 arm_brx (code, ARMREG_IP1);
258
259         g_assert ((code - buf) < buf_len);
260         mono_arch_flush_icache (buf, code - buf);
261
262         if (info) {
263                 tramp_name = mono_get_generic_trampoline_name (tramp_type);
264                 *info = mono_tramp_info_create (tramp_name, buf, code - buf, ji, unwind_ops);
265                 g_free (tramp_name);
266         }
267
268         return buf;
269 }
270
271 gpointer
272 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
273 {
274         guint8 *code, *buf, *tramp;
275         int buf_len = 64;
276
277         /*
278          * Return a trampoline which calls generic trampoline TRAMP_TYPE passing in ARG1.
279          * Pass the argument in ip1, clobbering ip0.
280          */
281         tramp = mono_get_trampoline_code (tramp_type);
282
283         buf = code = mono_global_codeman_reserve (buf_len);
284
285         code = mono_arm_emit_imm64 (code, ARMREG_IP1, (guint64)arg1);
286         code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)tramp);
287
288         arm_brx (code, ARMREG_IP0);
289
290         g_assert ((code - buf) < buf_len);
291         mono_arch_flush_icache (buf, code - buf);
292         if (code_len)
293                 *code_len = code - buf;
294
295         return buf;
296 }
297
298 gpointer
299 mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
300 {
301         guint8 *code, *start;
302         guint32 size = 32;
303         MonoDomain *domain = mono_domain_get ();
304
305         start = code = mono_domain_code_reserve (domain, size);
306         code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)addr);
307         arm_addx_imm (code, ARMREG_R0, ARMREG_R0, sizeof (MonoObject));
308         arm_brx (code, ARMREG_IP0);
309
310         g_assert ((code - start) <= size);
311         mono_arch_flush_icache (start, code - start);
312         return start;
313 }
314
315 gpointer
316 mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
317 {
318         guint8 *code, *start;
319         guint32 buf_len = 32;
320         MonoDomain *domain = mono_domain_get ();
321
322         start = code = mono_domain_code_reserve (domain, buf_len);
323         code = mono_arm_emit_imm64 (code, MONO_ARCH_RGCTX_REG, (guint64)mrgctx);
324         code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)addr);
325         arm_brx (code, ARMREG_IP0);
326
327         g_assert ((code - start) <= buf_len);
328
329         mono_arch_flush_icache (start, code - start);
330
331         return start;
332 }
333
334 gpointer
335 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
336 {
337         guint8 *code, *buf;
338         int buf_size;
339         int i, depth, index, njumps;
340         gboolean is_mrgctx;
341         guint8 **rgctx_null_jumps;
342         MonoJumpInfo *ji = NULL;
343         GSList *unwind_ops = NULL;
344         guint8 *tramp;
345         guint32 code_len;
346
347         is_mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
348         index = MONO_RGCTX_SLOT_INDEX (slot);
349         if (is_mrgctx)
350                 index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
351         for (depth = 0; ; ++depth) {
352                 int size = mono_class_rgctx_get_array_size (depth, is_mrgctx);
353
354                 if (index < size - 1)
355                         break;
356                 index -= size - 1;
357         }
358
359         buf_size = 64 + 16 * depth;
360         code = buf = mono_global_codeman_reserve (buf_size);
361
362         rgctx_null_jumps = g_malloc0 (sizeof (guint8*) * (depth + 2));
363         njumps = 0;
364
365         /* The vtable/mrgtx is in R0 */
366         g_assert (MONO_ARCH_VTABLE_REG == ARMREG_R0);
367
368         if (is_mrgctx) {
369                 /* get mrgctx ptr */
370                 arm_movx (code, ARMREG_IP1, ARMREG_R0);
371         } else {
372                 /* load rgctx ptr from vtable */
373                 code = mono_arm_emit_ldrx (code, ARMREG_IP1, ARMREG_R0, MONO_STRUCT_OFFSET (MonoVTable, runtime_generic_context));
374                 /* is the rgctx ptr null? */
375                 /* if yes, jump to actual trampoline */
376                 rgctx_null_jumps [njumps ++] = code;
377                 arm_cbzx (code, ARMREG_IP1, 0);
378         }
379
380         for (i = 0; i < depth; ++i) {
381                 /* load ptr to next array */
382                 if (is_mrgctx && i == 0) {
383                         code = mono_arm_emit_ldrx (code, ARMREG_IP1, ARMREG_IP1, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT);
384                 } else {
385                         code = mono_arm_emit_ldrx (code, ARMREG_IP1, ARMREG_IP1, 0);
386                 }
387                 /* is the ptr null? */
388                 /* if yes, jump to actual trampoline */
389                 rgctx_null_jumps [njumps ++] = code;
390                 arm_cbzx (code, ARMREG_IP1, 0);
391         }
392
393         /* fetch slot */
394         code = mono_arm_emit_ldrx (code, ARMREG_IP1, ARMREG_IP1, sizeof (gpointer) * (index + 1));
395         /* is the slot null? */
396         /* if yes, jump to actual trampoline */
397         rgctx_null_jumps [njumps ++] = code;
398         arm_cbzx (code, ARMREG_IP1, 0);
399         /* otherwise return, result is in IP1 */
400         arm_movx (code, ARMREG_R0, ARMREG_IP1);
401         arm_brx (code, ARMREG_LR);
402
403         g_assert (njumps <= depth + 2);
404         for (i = 0; i < njumps; ++i)
405                 mono_arm_patch (rgctx_null_jumps [i], code, MONO_R_ARM64_CBZ);
406
407         g_free (rgctx_null_jumps);
408
409         /* Slowpath */
410
411         /* Call mono_rgctx_lazy_fetch_trampoline (), passing in the slot as argument */
412         /* The vtable/mrgctx is still in R0 */
413         if (aot) {
414                 code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_IP0, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("specific_trampoline_lazy_fetch_%u", slot));
415         } else {
416                 tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot), MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), &code_len);
417                 code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)tramp);
418         }
419         arm_brx (code, ARMREG_IP0);
420
421         mono_arch_flush_icache (buf, code - buf);
422
423         g_assert (code - buf <= buf_size);
424
425         if (info) {
426                 char *name = mono_get_rgctx_fetch_trampoline_name (slot);
427                 *info = mono_tramp_info_create (name, buf, code - buf, ji, unwind_ops);
428                 g_free (name);
429         }
430
431         return buf;
432 }
433
434 gpointer
435 mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboolean aot)
436 {
437         guint8 *code, *buf;
438         int tramp_size;
439         MonoJumpInfo *ji = NULL;
440         GSList *unwind_ops = NULL;
441
442         g_assert (aot);
443
444         tramp_size = 32;
445
446         code = buf = mono_global_codeman_reserve (tramp_size);
447
448         mono_add_unwind_op_def_cfa (unwind_ops, code, buf, ARMREG_SP, 0);
449
450         // FIXME: Currently, we always go to the slow path.
451         /* Load trampoline addr */
452         arm_ldrx (code, ARMREG_IP0, MONO_ARCH_RGCTX_REG, 8);
453         /* The vtable/mrgctx is in R0 */
454         g_assert (MONO_ARCH_VTABLE_REG == ARMREG_R0);
455         arm_brx (code, ARMREG_IP0);
456
457         mono_arch_flush_icache (buf, code - buf);
458
459         g_assert (code - buf <= tramp_size);
460
461         if (info)
462                 *info = mono_tramp_info_create ("rgctx_fetch_trampoline_general", buf, code - buf, ji, unwind_ops);
463
464         return buf;
465 }
466
467 /*
468  * mono_arch_create_sdb_trampoline:
469  *
470  *   Return a trampoline which captures the current context, passes it to
471  * debugger_agent_single_step_from_context ()/debugger_agent_breakpoint_from_context (),
472  * then restores the (potentially changed) context.
473  */
474 guint8*
475 mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot)
476 {
477         int tramp_size = 512;
478         int offset, imm, frame_size, ctx_offset;
479         guint64 gregs_regset;
480         guint8 *code, *buf;
481         GSList *unwind_ops = NULL;
482         MonoJumpInfo *ji = NULL;
483
484         code = buf = mono_global_codeman_reserve (tramp_size);
485
486         /* Compute stack frame size and offsets */
487         offset = 0;
488         /* frame block */
489         offset += 2 * 8;
490         /* MonoContext */
491         ctx_offset = offset;
492         offset += sizeof (MonoContext);
493         offset = ALIGN_TO (offset, MONO_ARCH_FRAME_ALIGNMENT);
494         frame_size = offset;
495
496         // FIXME: Unwind info
497
498         /* Setup stack frame */
499         imm = frame_size;
500         while (imm > 256) {
501                 arm_subx_imm (code, ARMREG_SP, ARMREG_SP, 256);
502                 imm -= 256;
503         }
504         arm_subx_imm (code, ARMREG_SP, ARMREG_SP, imm);
505         arm_stpx (code, ARMREG_FP, ARMREG_LR, ARMREG_SP, 0);
506         arm_movspx (code, ARMREG_FP, ARMREG_SP);
507
508         /* Initialize a MonoContext structure on the stack */
509         /* No need to save fregs */
510         gregs_regset = ~((1 << ARMREG_FP) | (1 << ARMREG_SP));
511         code = mono_arm_emit_store_regarray (code, gregs_regset, ARMREG_FP, ctx_offset + G_STRUCT_OFFSET (MonoContext, regs));
512         /* Save caller fp */
513         arm_ldrx (code, ARMREG_IP1, ARMREG_FP, 0);
514         arm_strx (code, ARMREG_IP1, ARMREG_FP, ctx_offset + G_STRUCT_OFFSET (MonoContext, regs) + (ARMREG_FP * 8));
515         /* Save caller sp */
516         arm_movx (code, ARMREG_IP1, ARMREG_FP);
517         imm = frame_size;
518         while (imm > 256) {
519                 arm_addx_imm (code, ARMREG_IP1, ARMREG_IP1, 256);
520                 imm -= 256;
521         }
522         arm_addx_imm (code, ARMREG_IP1, ARMREG_IP1, imm);
523         arm_strx (code, ARMREG_IP1, ARMREG_FP, ctx_offset + G_STRUCT_OFFSET (MonoContext, regs) + (ARMREG_SP * 8));
524         /* Save caller ip */
525         arm_ldrx (code, ARMREG_IP1, ARMREG_FP, 8);
526         arm_strx (code, ARMREG_IP1, ARMREG_FP, ctx_offset + G_STRUCT_OFFSET (MonoContext, pc));
527
528         /* Call the single step/breakpoint function in sdb */
529         /* Arg1 = ctx */
530         arm_addx_imm (code, ARMREG_R0, ARMREG_FP, ctx_offset);
531         if (aot) {
532                 if (single_step)
533                         code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_IP0, MONO_PATCH_INFO_JIT_ICALL_ADDR, "debugger_agent_single_step_from_context");
534                 else
535                         code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_IP0, MONO_PATCH_INFO_JIT_ICALL_ADDR, "debugger_agent_breakpoint_from_context");
536         } else {
537                 gpointer addr = single_step ? debugger_agent_single_step_from_context : debugger_agent_breakpoint_from_context;
538
539                 code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)addr);
540         }
541         arm_blrx (code, ARMREG_IP0);
542
543         /* Restore ctx */
544         /* Save fp/pc into the frame block */
545         arm_ldrx (code, ARMREG_IP0, ARMREG_FP, ctx_offset + G_STRUCT_OFFSET (MonoContext, regs) + (ARMREG_FP * 8));
546         arm_strx (code, ARMREG_IP0, ARMREG_FP, 0);
547         arm_ldrx (code, ARMREG_IP0, ARMREG_FP, ctx_offset + G_STRUCT_OFFSET (MonoContext, pc));
548         arm_strx (code, ARMREG_IP0, ARMREG_FP, 8);
549         gregs_regset = ~((1 << ARMREG_FP) | (1 << ARMREG_SP));
550         code = mono_arm_emit_load_regarray (code, gregs_regset, ARMREG_FP, ctx_offset + G_STRUCT_OFFSET (MonoContext, regs));
551
552         code = mono_arm_emit_destroy_frame (code, frame_size, ((1 << ARMREG_IP0) | (1 << ARMREG_IP1)));
553
554         arm_retx (code, ARMREG_LR);
555
556         mono_arch_flush_icache (code, code - buf);
557         g_assert (code - buf <= tramp_size);
558
559         const char *tramp_name = single_step ? "sdb_single_step_trampoline" : "sdb_breakpoint_trampoline";
560         *info = mono_tramp_info_create (tramp_name, buf, code - buf, ji, unwind_ops);
561
562         return buf;
563 }
564
565 #else /* DISABLE_JIT */
566
567 guchar*
568 mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
569 {
570         g_assert_not_reached ();
571         return NULL;
572 }
573
574 gpointer
575 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
576 {
577         g_assert_not_reached ();
578         return NULL;
579 }
580
581 gpointer
582 mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
583 {
584         g_assert_not_reached ();
585         return NULL;
586 }
587
588 gpointer
589 mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
590 {
591         g_assert_not_reached ();
592         return NULL;
593 }
594
595 gpointer
596 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
597 {
598         g_assert_not_reached ();
599         return NULL;
600 }
601
602 gpointer
603 mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info)
604 {
605         g_assert_not_reached ();
606         return NULL;
607 }
608
609 guint8*
610 mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot)
611 {
612         g_assert_not_reached ();
613         return NULL;
614 }
615
616 #endif /* !DISABLE_JIT */