4 * @author Neale Ferguson <neale@sinenomine.net>
8 * Function - JIT trampoline code for S/390.
10 * Date - January, 2004
12 * Derivation - From tramp-x86 & tramp-ppc
13 * Paolo Molaro (lupus@ximian.com)
14 * Dietmar Maurer (dietmar@ximian.com)
16 * Copyright - 2001 Ximian, Inc.
17 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
21 /*------------------------------------------------------------------*/
23 /*------------------------------------------------------------------*/
25 #define LMFReg s390_r13
28 * Method-specific trampoline code fragment sizes
30 #define SPECIFIC_TRAMPOLINE_SIZE 96
32 /*========================= End of Defines =========================*/
34 /*------------------------------------------------------------------*/
36 /*------------------------------------------------------------------*/
42 #include <mono/metadata/abi-details.h>
43 #include <mono/metadata/appdomain.h>
44 #include <mono/metadata/gc-internals.h>
45 #include <mono/metadata/marshal.h>
46 #include <mono/metadata/profiler-private.h>
47 #include <mono/metadata/tabledefs.h>
48 #include <mono/utils/mono-hwcap.h>
49 #include <mono/arch/s390x/s390x-codegen.h>
52 #include "mini-s390x.h"
53 #include "mini-runtime.h"
54 #include "support-s390x.h"
55 #include "jit-icalls.h"
56 #include "debugger-agent.h"
57 #include "mono/utils/mono-tls-inline.h"
59 /*========================= End of Includes ========================*/
61 /*------------------------------------------------------------------*/
63 /*------------------------------------------------------------------*/
66 guint8 stk
[S390_MINIMAL_STACK_SIZE
]; /* Standard s390x stack */
67 guint64 saveFn
; /* Call address */
68 struct MonoLMF LMF
; /* LMF */
71 /*========================= End of Typedefs ========================*/
73 /*------------------------------------------------------------------*/
74 /* P r o t o t y p e s */
75 /*------------------------------------------------------------------*/
77 /*========================= End of Prototypes ======================*/
79 /*------------------------------------------------------------------*/
80 /* G l o b a l V a r i a b l e s */
81 /*------------------------------------------------------------------*/
84 /*====================== End of Global Variables ===================*/
88 * @brief Build the unbox trampoline
90 * @param[in] Method pointer
91 * @param[in] Pointer to native code for method
93 * Return a pointer to a trampoline which does the unboxing before
96 * When value type methods are called through the
97 * vtable we need to unbox the 'this' argument.
101 mono_arch_get_unbox_trampoline (MonoMethod
*m
, gpointer addr
)
103 guint8
*code
, *start
;
104 int this_pos
= s390_r2
;
105 MonoDomain
*domain
= mono_domain_get ();
106 MonoMemoryManager
*mem_manager
= m_method_get_mem_manager (domain
, m
);
109 start
= code
= mono_mem_manager_code_reserve (mem_manager
, 28);
111 S390_SET (code
, s390_r1
, addr
);
112 s390_aghi (code
, this_pos
, MONO_ABI_SIZEOF (MonoObject
));
113 s390_br (code
, s390_r1
);
115 g_assert ((code
- start
) <= 28);
117 mono_arch_flush_icache (start
, code
- start
);
118 MONO_PROFILER_RAISE (jit_code_buffer
, (start
, code
- start
, MONO_PROFILER_CODE_BUFFER_UNBOX_TRAMPOLINE
, m
));
120 snprintf(trampName
, sizeof(trampName
), "%s_unbox_trampoline", m
->name
);
122 mono_tramp_info_register (mono_tramp_info_create (trampName
, start
, code
- start
, NULL
, NULL
), domain
);
127 /*========================= End of Function ========================*/
131 * @brief Build the SDB trampoline
133 * @param[in] Type of trampoline (ss or bp)
134 * @param[in] MonoTrampInfo
135 * @param[in] Ahead of time indicator
137 * Return a trampoline which captures the current context, passes it to
138 * mono_debugger_agent_single_step_from_context ()/mono_debugger_agent_breakpoint_from_context (),
139 * then restores the (potentially changed) context.
143 mono_arch_create_sdb_trampoline (gboolean single_step
, MonoTrampInfo
**info
, gboolean aot
)
145 int tramp_size
= 512;
146 int i
, framesize
, ctx_offset
,
147 gr_offset
, fp_offset
, ip_offset
,
151 GSList
*unwind_ops
= NULL
;
152 MonoJumpInfo
*ji
= NULL
;
154 code
= buf
= (guint8
*)mono_global_codeman_reserve (tramp_size
);
156 framesize
= S390_MINIMAL_STACK_SIZE
;
158 ctx_offset
= framesize
;
159 framesize
+= sizeof (MonoContext
);
161 framesize
= ALIGN_TO (framesize
, MONO_ARCH_FRAME_ALIGNMENT
);
164 * Create unwind information - On entry s390_r1 has value of method's frame reg
166 mono_add_unwind_op_def_cfa (unwind_ops
, code
, buf
, STK_BASE
, 0);
167 s390_stmg (code
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
168 gr_offset
= S390_REG_SAVE_OFFSET
;
169 for (i
= s390_r6
; i
< s390_r15
; i
++) {
170 mono_add_unwind_op_offset (unwind_ops
, code
, buf
, i
, gr_offset
);
171 gr_offset
+= sizeof(uintptr_t);
174 s390_lgr (code
, s390_r0
, STK_BASE
);
175 s390_aghi (code
, STK_BASE
, -framesize
);
176 mono_add_unwind_op_def_cfa_offset (unwind_ops
, code
, buf
, framesize
);
177 mono_add_unwind_op_fp_alloc (unwind_ops
, code
, buf
, STK_BASE
, 0);
178 s390_stg (code
, s390_r0
, 0, STK_BASE
, 0);
180 gr_offset
= ctx_offset
+ G_STRUCT_OFFSET(MonoContext
, uc_mcontext
.gregs
);
181 sp_offset
= ctx_offset
+ G_STRUCT_OFFSET(MonoContext
, uc_mcontext
.gregs
[15]);
182 ip_offset
= ctx_offset
+ G_STRUCT_OFFSET(MonoContext
, uc_mcontext
.psw
.addr
);
184 /* Initialize a MonoContext structure on the stack */
185 s390_stmg (code
, s390_r0
, s390_r14
, STK_BASE
, gr_offset
);
186 s390_stg (code
, s390_r1
, 0, STK_BASE
, sp_offset
);
187 sp_offset
= ctx_offset
+ G_STRUCT_OFFSET(MonoContext
, uc_stack
.ss_sp
);
188 s390_stg (code
, s390_r1
, 0, STK_BASE
, sp_offset
);
189 s390_stg (code
, s390_r14
, 0, STK_BASE
, ip_offset
);
191 fp_offset
= ctx_offset
+ G_STRUCT_OFFSET(MonoContext
, uc_mcontext
.fpregs
.fprs
);
192 for (i
= s390_f0
; i
< s390_f15
; ++i
) {
193 s390_std (code
, i
, 0, STK_BASE
, fp_offset
);
194 fp_offset
+= sizeof(double);
198 * Call the single step/breakpoint function in sdb using
199 * the context address as the parameter
201 s390_la (code
, s390_r2
, 0, STK_BASE
, ctx_offset
);
204 ep
= (mini_get_dbg_callbacks())->single_step_from_context
;
206 ep
= (mini_get_dbg_callbacks())->breakpoint_from_context
;
208 S390_SET (code
, s390_r1
, ep
);
209 s390_basr (code
, s390_r14
, s390_r1
);
214 s390_lmg (code
, s390_r0
, s390_r5
, STK_BASE
, gr_offset
);
217 * Restore FP registers
219 fp_offset
= ctx_offset
+ G_STRUCT_OFFSET(MonoContext
, uc_mcontext
.fpregs
.fprs
);
220 for (i
= s390_f0
; i
< s390_f15
; ++i
) {
221 s390_ld (code
, i
, 0, STK_BASE
, fp_offset
);
222 fp_offset
+= sizeof(double);
226 * Load the IP from the context to pick up any SET_IP command results
228 s390_lg (code
, s390_r14
, 0, STK_BASE
, ip_offset
);
231 * Restore everything else from the on-entry values
233 s390_aghi (code
, STK_BASE
, framesize
);
234 mono_add_unwind_op_def_cfa_offset (unwind_ops
, code
, buf
, -framesize
);
235 s390_lmg (code
, s390_r6
, s390_r13
, STK_BASE
, S390_REG_SAVE_OFFSET
);
236 s390_br (code
, s390_r14
);
238 g_assertf ((code
- buf
) <= tramp_size
, "%d %d", (int)(code
- buf
), tramp_size
);
239 mono_arch_flush_icache (code
, code
- buf
);
241 MONO_PROFILER_RAISE (jit_code_buffer
, (buf
, code
- buf
, MONO_PROFILER_CODE_BUFFER_HELPER
, NULL
));
242 g_assert (code
- buf
<= tramp_size
);
244 const char *tramp_name
= single_step
? "sdb_single_step_trampoline" : "sdb_breakpoint_trampoline";
245 *info
= mono_tramp_info_create (tramp_name
, buf
, code
- buf
, ji
, unwind_ops
);
250 /*------------------------------------------------------------------*/
252 /* Name - mono_arch_patch_callsite */
254 /* Function - Patch a non-virtual callsite so it calls @addr. */
256 /*------------------------------------------------------------------*/
259 mono_arch_patch_callsite (guint8
*method_start
, guint8
*orig_code
, guint8
*addr
)
262 unsigned short opcode
;
264 opcode
= *((unsigned short *) (orig_code
- 2));
265 if (opcode
== 0x0dee) {
266 /* This should be a 'iihf/iilf' sequence */
267 S390_EMIT_CALL((orig_code
- 14), addr
);
268 mono_arch_flush_icache (orig_code
- 14, 12);
270 /* This is the 'brasl' instruction */
272 displace
= ((gssize
) addr
- (gssize
) (orig_code
- 2)) / 2;
273 s390_patch_rel (orig_code
, displace
);
274 mono_arch_flush_icache (orig_code
, 4);
278 /*========================= End of Function ========================*/
280 /*------------------------------------------------------------------*/
282 /* Name - mono_arch_patch_plt_entry. */
284 /* Function - Patch a PLT entry - unused as yet. */
286 /*------------------------------------------------------------------*/
289 mono_arch_patch_plt_entry (guint8
*code
, gpointer
*got
, host_mgreg_t
*regs
, guint8
*addr
)
291 g_assert_not_reached ();
294 /*========================= End of Function ========================*/
296 /*------------------------------------------------------------------*/
298 /* Name - mono_arch_create_trampoline_code */
300 /* Function - Create the designated type of trampoline according*/
301 /* to the 'tramp_type' parameter. */
303 /*------------------------------------------------------------------*/
306 mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type
, MonoTrampInfo
**info
, gboolean aot
)
308 const char *tramp_name
;
309 guint8
*buf
, *tramp
, *code
;
310 int i
, offset
, has_caller
;
312 GSList
*unwind_ops
= NULL
;
313 MonoJumpInfo
*ji
= NULL
;
317 /* Now we'll create in 'buf' the S/390 trampoline code. This
318 is the trampoline code common to all methods */
320 code
= buf
= mono_global_codeman_reserve(512);
322 if (tramp_type
== MONO_TRAMPOLINE_JUMP
)
327 /*-----------------------------------------------------------
328 STEP 0: First create a non-standard function prologue with a
329 stack size big enough to save our registers.
330 -----------------------------------------------------------*/
332 mono_add_unwind_op_def_cfa (unwind_ops
, code
, buf
, STK_BASE
, 0);
333 s390_stmg (buf
, s390_r6
, s390_r15
, STK_BASE
, S390_REG_SAVE_OFFSET
);
334 offset
= S390_REG_SAVE_OFFSET
;
335 for (i
= s390_r6
; i
< s390_r15
; i
++) {
336 mono_add_unwind_op_offset (unwind_ops
, code
, buf
, i
, offset
);
337 offset
+= sizeof(uintptr_t);
340 s390_lgr (buf
, s390_r11
, s390_r15
);
341 s390_aghi (buf
, STK_BASE
, -sizeof(trampStack_t
));
342 mono_add_unwind_op_def_cfa_offset (unwind_ops
, code
, buf
, sizeof(trampStack_t
));
343 s390_stg (buf
, s390_r11
, 0, STK_BASE
, 0);
345 /*---------------------------------------------------------------*/
346 /* we build the MonoLMF structure on the stack - see mini-s390.h */
347 /* Keep in sync with the code in mono_arch_emit_prolog */
348 /*---------------------------------------------------------------*/
350 s390_lgr (buf
, LMFReg
, STK_BASE
);
351 s390_aghi (buf
, LMFReg
, G_STRUCT_OFFSET(trampStack_t
, LMF
));
353 /*---------------------------------------------------------------*/
354 /* Save general and floating point registers in LMF */
355 /*---------------------------------------------------------------*/
356 s390_stmg (buf
, s390_r0
, s390_r1
, LMFReg
, G_STRUCT_OFFSET(MonoLMF
, gregs
[0]));
357 s390_stmg (buf
, s390_r2
, s390_r5
, LMFReg
, G_STRUCT_OFFSET(MonoLMF
, gregs
[2]));
358 s390_mvc (buf
, 10*sizeof(gulong
), LMFReg
, G_STRUCT_OFFSET(MonoLMF
, gregs
[6]),
359 s390_r11
, S390_REG_SAVE_OFFSET
);
361 offset
= G_STRUCT_OFFSET(MonoLMF
, fregs
[0]);
362 for (i
= s390_f0
; i
<= s390_f15
; ++i
) {
363 s390_std (buf
, i
, 0, LMFReg
, offset
);
364 offset
+= sizeof(gdouble
);
367 /*----------------------------------------------------------
368 STEP 1: call 'mono_get_lmf_addr()' to get the address of our
369 LMF. We'll need to restore it after the call to
370 's390_magic_trampoline' and before the call to the native
372 ----------------------------------------------------------*/
374 S390_SET (buf
, s390_r1
, mono_get_lmf_addr
);
375 s390_basr (buf
, s390_r14
, s390_r1
);
377 /*---------------------------------------------------------------*/
378 /* Set lmf.lmf_addr = jit_tls->lmf */
379 /*---------------------------------------------------------------*/
380 s390_stg (buf
, s390_r2
, 0, LMFReg
,
381 G_STRUCT_OFFSET(MonoLMF
, lmf_addr
));
383 /*---------------------------------------------------------------*/
384 /* Get current lmf */
385 /*---------------------------------------------------------------*/
386 s390_lg (buf
, s390_r0
, 0, s390_r2
, 0);
388 /*---------------------------------------------------------------*/
389 /* Set our lmf as the current lmf */
390 /*---------------------------------------------------------------*/
391 s390_stg (buf
, LMFReg
, 0, s390_r2
, 0);
393 /*---------------------------------------------------------------*/
394 /* Have our lmf.previous_lmf point to the last lmf */
395 /*---------------------------------------------------------------*/
396 s390_stg (buf
, s390_r0
, 0, LMFReg
,
397 G_STRUCT_OFFSET(MonoLMF
, previous_lmf
));
399 /*---------------------------------------------------------------*/
400 /* save method info */
401 /*---------------------------------------------------------------*/
402 s390_lg (buf
, s390_r1
, 0, LMFReg
, G_STRUCT_OFFSET(MonoLMF
, gregs
[1]));
403 s390_stg (buf
, s390_r1
, 0, LMFReg
, G_STRUCT_OFFSET(MonoLMF
, method
));
405 /*---------------------------------------------------------------*/
406 /* save the current SP */
407 /*---------------------------------------------------------------*/
408 s390_lg (buf
, s390_r1
, 0, STK_BASE
, 0);
409 s390_stg (buf
, s390_r1
, 0, LMFReg
, G_STRUCT_OFFSET(MonoLMF
, ebp
));
411 /*---------------------------------------------------------------*/
412 /* save the current IP */
413 /*---------------------------------------------------------------*/
415 s390_lg (buf
, s390_r1
, 0, s390_r1
, S390_RET_ADDR_OFFSET
);
417 s390_lghi (buf
, s390_r1
, 0);
419 s390_stg (buf
, s390_r1
, 0, LMFReg
, G_STRUCT_OFFSET(MonoLMF
, eip
));
421 /*---------------------------------------------------------------*/
422 /* STEP 2: call the C trampoline function */
423 /*---------------------------------------------------------------*/
427 /* Arg 1: host_mgreg_t *regs */
428 s390_la (buf
, s390_r2
, 0, LMFReg
, G_STRUCT_OFFSET(MonoLMF
, gregs
[0]));
430 /* Arg 2: code (next address to the instruction that called us) */
432 s390_lg (buf
, s390_r3
, 0, s390_r11
, S390_RET_ADDR_OFFSET
);
434 s390_lghi (buf
, s390_r3
, 0);
437 /* Arg 3: Trampoline argument */
438 s390_lg (buf
, s390_r4
, 0, LMFReg
, G_STRUCT_OFFSET(MonoLMF
, gregs
[1]));
440 /* Arg 4: trampoline address. */
441 S390_SET (buf
, s390_r5
, buf
);
443 /* Calculate call address and call the C trampoline. Return value will be in r2 */
444 tramp
= (guint8
*)mono_get_trampoline_func (tramp_type
);
445 S390_SET (buf
, s390_r1
, tramp
);
446 s390_basr (buf
, s390_r14
, s390_r1
);
448 /* OK, code address is now on r2. Save it, so that we
449 can restore r2 and use it later */
450 s390_stg (buf
, s390_r2
, 0, STK_BASE
, G_STRUCT_OFFSET(trampStack_t
, saveFn
));
452 /*----------------------------------------------------------
453 STEP 3: Restore the LMF
454 ----------------------------------------------------------*/
455 restoreLMF(buf
, STK_BASE
, sizeof(trampStack_t
));
457 /* Check for thread interruption */
458 S390_SET (buf
, s390_r1
, (guint8
*)mono_thread_force_interruption_checkpoint_noraise
);
459 s390_basr (buf
, s390_r14
, s390_r1
);
460 s390_ltgr (buf
, s390_r2
, s390_r2
);
461 s390_jz (buf
, 0); CODEPTR (buf
, o
[0]);
465 * We have an exception we want to throw in the caller's frame, so pop
466 * the trampoline frame and throw from the caller.
468 S390_SET (buf
, s390_r1
, (guint
*)mono_get_rethrow_preserve_exception_addr ());
469 s390_aghi (buf
, STK_BASE
, sizeof(trampStack_t
));
470 s390_lg (buf
, s390_r1
, 0, s390_r1
, 0);
471 s390_lmg (buf
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
472 s390_br (buf
, s390_r1
);
476 s390_lg (buf
, s390_r1
, 0, STK_BASE
, G_STRUCT_OFFSET(trampStack_t
, saveFn
));
478 /*----------------------------------------------------------
479 STEP 4: call the compiled method
480 ----------------------------------------------------------*/
482 /* Restore parameter registers */
483 s390_lmg (buf
, s390_r2
, s390_r5
, LMFReg
, G_STRUCT_OFFSET(MonoLMF
, gregs
[2]));
485 /* Restore the FP registers */
486 offset
= G_STRUCT_OFFSET(MonoLMF
, fregs
[0]);
487 for (i
= s390_f0
; i
<= s390_f15
; ++i
) {
488 s390_ld (buf
, i
, 0, LMFReg
, offset
);
489 offset
+= sizeof(gdouble
);
492 /* Restore stack pointer and jump to the code -
493 * R14 contains the return address to our caller
495 s390_lgr (buf
, STK_BASE
, s390_r11
);
496 // mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, -sizeof(trampStack_t));
497 s390_lmg (buf
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
499 if (MONO_TRAMPOLINE_TYPE_MUST_RETURN(tramp_type
)) {
500 s390_lgr (buf
, s390_r2
, s390_r1
);
501 s390_br (buf
, s390_r14
);
503 s390_br (buf
, s390_r1
);
506 /* Flush instruction cache, since we've generated code */
507 mono_arch_flush_icache (code
, buf
- code
);
508 MONO_PROFILER_RAISE (jit_code_buffer
, (buf
, code
- buf
, MONO_PROFILER_CODE_BUFFER_HELPER
, NULL
));
511 tramp_name
= mono_get_generic_trampoline_name (tramp_type
);
512 *info
= mono_tramp_info_create (tramp_name
, buf
, buf
- code
, ji
, unwind_ops
);
515 g_assert ((buf
- code
) <= 512);
520 /*========================= End of Function ========================*/
522 /*------------------------------------------------------------------*/
524 /* Name - mono_arch_invalidate_method */
528 /*------------------------------------------------------------------*/
531 mono_arch_invalidate_method (MonoJitInfo
*ji
, void *func
, gpointer func_arg
)
533 /* FIXME: This is not thread safe */
534 guint8
*code
= ji
->code_start
;
536 S390_SET (code
, s390_r1
, func
);
537 S390_SET (code
, s390_r2
, func_arg
);
538 s390_br (code
, s390_r1
);
542 /*========================= End of Function ========================*/
544 /*------------------------------------------------------------------*/
546 /* Name - mono_arch_create_specific_trampoline */
548 /* Function - Creates the given kind of specific trampoline */
550 /*------------------------------------------------------------------*/
553 mono_arch_create_specific_trampoline (gpointer arg1
, MonoTrampolineType tramp_type
, MonoMemoryManager
*mem_manager
, guint32
*code_len
)
555 guint8
*code
, *buf
, *tramp
;
558 tramp
= mono_get_trampoline_code (tramp_type
);
560 /*----------------------------------------------------------*/
561 /* This is the method-specific part of the trampoline. Its */
562 /* purpose is to provide the generic part with the */
563 /* MonoMethod *method pointer. We'll use r1 to keep it. */
564 /*----------------------------------------------------------*/
565 code
= buf
= mono_mem_manager_code_reserve (mem_manager
, SPECIFIC_TRAMPOLINE_SIZE
);
567 S390_SET (buf
, s390_r1
, arg1
);
568 displace
= (tramp
- buf
) / 2;
569 s390_jg (buf
, displace
);
571 /* Flush instruction cache, since we've generated code */
572 mono_arch_flush_icache (code
, buf
- code
);
573 MONO_PROFILER_RAISE (jit_code_buffer
, (buf
, code
- buf
,
574 MONO_PROFILER_CODE_BUFFER_SPECIFIC_TRAMPOLINE
,
575 (void *) mono_get_generic_trampoline_simple_name (tramp_type
)));
578 g_assert ((buf
- code
) <= SPECIFIC_TRAMPOLINE_SIZE
);
581 *code_len
= buf
- code
;
586 /*========================= End of Function ========================*/
588 /*------------------------------------------------------------------*/
590 /* Name - mono_arch_create_rgctx_lazy_fetch_trampoline */
594 /*------------------------------------------------------------------*/
597 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot
, MonoTrampInfo
**info
, gboolean aot
)
601 guint8
**rgctx_null_jumps
;
609 MonoJumpInfo
*ji
= NULL
;
610 GSList
*unwind_ops
= NULL
;
612 mrgctx
= MONO_RGCTX_SLOT_IS_MRGCTX (slot
);
613 index
= MONO_RGCTX_SLOT_INDEX (slot
);
615 index
+= MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT
/ sizeof (target_mgreg_t
);
616 for (depth
= 0; ; ++depth
) {
617 int size
= mono_class_rgctx_get_array_size (depth
, mrgctx
);
619 if (index
< size
- 1)
624 tramp_size
= 48 + 16 * depth
;
630 code
= buf
= mono_global_codeman_reserve (tramp_size
);
632 unwind_ops
= mono_arch_get_cie_program ();
634 rgctx_null_jumps
= g_malloc (sizeof (guint8
*) * (depth
+ 2));
638 s390_lgr (code
, s390_r1
, s390_r2
);
640 /* load rgctx ptr from vtable */
641 s390_lg (code
, s390_r1
, 0, s390_r2
, MONO_STRUCT_OFFSET(MonoVTable
, runtime_generic_context
));
642 /* is the rgctx ptr null? */
643 s390_ltgr (code
, s390_r1
, s390_r1
);
644 /* if yes, jump to actual trampoline */
645 rgctx_null_jumps
[iPatch
++] = code
;
649 for (i
= 0; i
< depth
; ++i
) {
650 /* load ptr to next array */
651 if (mrgctx
&& i
== 0)
652 s390_lg (code
, s390_r1
, 0, s390_r1
, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT
);
654 s390_lg (code
, s390_r1
, 0, s390_r1
, 0);
655 s390_ltgr (code
, s390_r1
, s390_r1
);
656 /* if the ptr is null then jump to actual trampoline */
657 rgctx_null_jumps
[iPatch
++] = code
;
662 s390_lg (code
, s390_r1
, 0, s390_r1
, (sizeof (target_mgreg_t
) * (index
+ 1)));
663 /* is the slot null? */
664 s390_ltgr (code
, s390_r1
, s390_r1
);
665 /* if yes, jump to actual trampoline */
666 rgctx_null_jumps
[iPatch
++] = code
;
668 /* otherwise return r1 */
669 s390_lgr (code
, s390_r2
, s390_r1
);
670 s390_br (code
, s390_r14
);
672 for (i
= 0; i
< iPatch
; i
++) {
673 displace
= ((uintptr_t) code
- (uintptr_t) rgctx_null_jumps
[i
]) / 2;
674 s390_patch_rel ((rgctx_null_jumps
[i
] + 2), displace
);
677 g_free (rgctx_null_jumps
);
679 /* move the rgctx pointer to the VTABLE register */
680 #if MONO_ARCH_VTABLE_REG != s390_r2
681 s390_lgr (code
, MONO_ARCH_VTABLE_REG
, s390_r2
);
684 MonoMemoryManager
*mem_manager
= mono_domain_ambient_memory_manager (mono_get_root_domain ());
685 tramp
= (guint8
*)mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot
),
686 MONO_TRAMPOLINE_RGCTX_LAZY_FETCH
, mem_manager
, NULL
);
688 /* jump to the actual trampoline */
689 displace
= (tramp
- code
) / 2;
690 s390_jg (code
, displace
);
692 mono_arch_flush_icache (buf
, code
- buf
);
693 MONO_PROFILER_RAISE (jit_code_buffer
, (buf
, code
- buf
, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE
, NULL
));
695 g_assert (code
- buf
<= tramp_size
);
697 char *name
= mono_get_rgctx_fetch_trampoline_name (slot
);
698 *info
= mono_tramp_info_create (name
, buf
, code
- buf
, ji
, unwind_ops
);
704 /*========================= End of Function ========================*/
706 /*------------------------------------------------------------------*/
708 /* Name - mono_arch_get_static_rgctx_trampoline */
710 /* Function - Create a trampoline which sets RGCTX_REG to ARG */
711 /* then jumps to ADDR. */
713 /*------------------------------------------------------------------*/
716 mono_arch_get_static_rgctx_trampoline (MonoMemoryManager
*mem_manager
, gpointer arg
, gpointer addr
)
718 guint8
*code
, *start
;
721 MonoDomain
*domain
= mono_domain_get ();
725 start
= code
= mono_mem_manager_code_reserve (mem_manager
, buf_len
);
727 S390_SET (code
, MONO_ARCH_RGCTX_REG
, arg
);
728 displace
= ((uintptr_t) addr
- (uintptr_t) code
) / 2;
729 s390_jg (code
, displace
);
730 g_assert ((code
- start
) < buf_len
);
732 mono_arch_flush_icache (start
, code
- start
);
733 MONO_PROFILER_RAISE (jit_code_buffer
, (start
, code
- start
, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE
, NULL
));
735 mono_tramp_info_register (mono_tramp_info_create (NULL
, start
, code
- start
, NULL
, NULL
), domain
);
740 /*========================= End of Function ========================*/