1 /*------------------------------------------------------------------*/
3 /* Name - tramp-s390x.c */
5 /* Function - JIT trampoline code for S/390. */
7 /* Name - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
9 /* Date - January, 2004 */
11 /* Derivation - From exceptions-x86 & exceptions-ppc */
12 /* Paolo Molaro (lupus@ximian.com) */
13 /* Dietmar Maurer (dietmar@ximian.com) */
15 /* Copyright - 2001 Ximian, Inc. */
17 /*------------------------------------------------------------------*/
19 /*------------------------------------------------------------------*/
21 /*------------------------------------------------------------------*/
23 #define GR_SAVE_SIZE 4*sizeof(long)
24 #define FP_SAVE_SIZE 16*sizeof(double)
25 #define METHOD_SAVE_OFFSET S390_MINIMAL_STACK_SIZE
26 #define CREATE_GR_OFFSET METHOD_SAVE_OFFSET+8
27 #define CREATE_FP_OFFSET CREATE_GR_OFFSET+GR_SAVE_SIZE
28 #define CREATE_LMF_OFFSET CREATE_FP_OFFSET+FP_SAVE_SIZE
29 #define CREATE_STACK_SIZE (CREATE_LMF_OFFSET+2*sizeof(long)+sizeof(MonoLMF))
30 #define GENERIC_REG_OFFSET CREATE_STACK_SIZE + \
31 S390_REG_SAVE_OFFSET + \
34 /*------------------------------------------------------------------*/
35 /* Method-specific trampoline code fragment sizes */
36 /*------------------------------------------------------------------*/
37 #define SPECIFIC_TRAMPOLINE_SIZE 96
39 /*========================= End of Defines =========================*/
41 /*------------------------------------------------------------------*/
43 /*------------------------------------------------------------------*/
49 #include <mono/metadata/abi-details.h>
50 #include <mono/metadata/appdomain.h>
51 #include <mono/metadata/gc-internal.h>
52 #include <mono/metadata/marshal.h>
53 #include <mono/metadata/monitor.h>
54 #include <mono/metadata/profiler-private.h>
55 #include <mono/metadata/tabledefs.h>
56 #include <mono/arch/s390x/s390x-codegen.h>
59 #include "mini-s390x.h"
60 #include "support-s390x.h"
62 /*========================= End of Includes ========================*/
64 /*------------------------------------------------------------------*/
66 /*------------------------------------------------------------------*/
68 /*========================= End of Typedefs ========================*/
70 /*------------------------------------------------------------------*/
71 /* P r o t o t y p e s */
72 /*------------------------------------------------------------------*/
74 /*========================= End of Prototypes ======================*/
76 /*------------------------------------------------------------------*/
77 /* G l o b a l V a r i a b l e s */
78 /*------------------------------------------------------------------*/
81 /*====================== End of Global Variables ===================*/
83 /*------------------------------------------------------------------*/
85 /* Name - mono_arch_get_unbox_trampoline */
87 /* Function - Return a pointer to a trampoline which does the */
88 /* unboxing before calling the method. */
90 /* When value type methods are called through the */
91 /* vtable we need to unbox the 'this' argument. */
93 /* Parameters - method - Methd pointer */
94 /* addr - Pointer to native code for method */
96 /*------------------------------------------------------------------*/
99 mono_arch_get_unbox_trampoline (MonoMethod *method, gpointer addr)
101 guint8 *code, *start;
102 int this_pos = s390_r2;
103 MonoDomain *domain = mono_domain_get ();
105 start = code = mono_domain_code_reserve (domain, 28);
107 S390_SET (code, s390_r1, addr);
108 s390_aghi (code, this_pos, sizeof(MonoObject));
109 s390_br (code, s390_r1);
111 g_assert ((code - start) <= 28);
113 mono_arch_flush_icache (start, code - start);
114 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_UNBOX_TRAMPOLINE, method);
119 /*========================= End of Function ========================*/
121 /*------------------------------------------------------------------*/
123 /* Name - mono_arch_patch_callsite */
125 /* Function - Patch a non-virtual callsite so it calls @addr. */
127 /*------------------------------------------------------------------*/
130 mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr)
133 unsigned short opcode;
135 opcode = *((unsigned short *) (orig_code - 2));
136 if (opcode == 0x0dee) {
137 /* This should be a 'iihf/iilf' sequence */
138 S390_EMIT_CALL((orig_code - 14), addr);
139 mono_arch_flush_icache (orig_code - 14, 12);
141 /* This is the 'brasl' instruction */
143 displace = ((gssize) addr - (gssize) (orig_code - 2)) / 2;
144 s390_patch_rel (orig_code, displace);
145 mono_arch_flush_icache (orig_code, 4);
149 /*========================= End of Function ========================*/
151 /*------------------------------------------------------------------*/
153 /* Name - mono_arch_patch_plt_entry. */
155 /* Function - Patch a PLT entry - unused as yet. */
157 /*------------------------------------------------------------------*/
160 mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
162 g_assert_not_reached ();
165 /*========================= End of Function ========================*/
167 /*------------------------------------------------------------------*/
169 /* Name - mono_arch_nullify_class_init_trampoline */
171 /* Function - Nullify a call which calls a class init trampoline*/
173 /*------------------------------------------------------------------*/
176 mono_arch_nullify_class_init_trampoline (guint8 *code, mgreg_t *regs)
178 char patch[2] = {0x07, 0x00};
182 memcpy(code, patch, sizeof(patch));
185 /*========================= End of Function ========================*/
187 /*------------------------------------------------------------------*/
189 /* Name - mono_arch_get_nullified_class_init */
191 /* Function - Nullify a PLT entry call. */
193 /*------------------------------------------------------------------*/
196 mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info)
200 code = buf = mono_global_codeman_reserve (16);
202 s390_br (code, s390_r14);
204 mono_arch_flush_icache (buf, code - buf);
205 mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL);
207 *info = mono_tramp_info_create ("nullified_class_init_trampoline",
208 buf, code - buf, NULL, NULL);
213 /*========================= End of Function ========================*/
215 /*------------------------------------------------------------------*/
217 /* Name - mono_arch_create_trampoline_code */
219 /* Function - Create the designated type of trampoline according*/
220 /* to the 'tramp_type' parameter. */
222 /*------------------------------------------------------------------*/
225 mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
228 guint8 *buf, *tramp, *code;
229 int i, offset, lmfOffset, has_caller;
230 GSList *unwind_ops = NULL;
231 MonoJumpInfo *ji = NULL;
235 /* Now we'll create in 'buf' the S/390 trampoline code. This
236 is the trampoline code common to all methods */
238 code = buf = mono_global_codeman_reserve(512);
240 if ((tramp_type == MONO_TRAMPOLINE_JUMP) ||
241 (tramp_type == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD))
246 /*-----------------------------------------------------------
247 STEP 0: First create a non-standard function prologue with a
248 stack size big enough to save our registers.
249 -----------------------------------------------------------*/
251 s390_stmg (buf, s390_r6, s390_r15, STK_BASE, S390_REG_SAVE_OFFSET);
252 s390_lgr (buf, s390_r11, s390_r15);
253 s390_aghi (buf, STK_BASE, -CREATE_STACK_SIZE);
254 s390_stg (buf, s390_r11, 0, STK_BASE, 0);
255 s390_stg (buf, s390_r1, 0, STK_BASE, METHOD_SAVE_OFFSET);
256 s390_stmg (buf, s390_r2, s390_r5, STK_BASE, CREATE_GR_OFFSET);
258 /* Save the FP registers */
259 offset = CREATE_FP_OFFSET;
260 for (i = s390_f0; i <= s390_f15; ++i) {
261 s390_std (buf, i, 0, STK_BASE, offset);
265 /*----------------------------------------------------------
266 STEP 1: call 'mono_get_lmf_addr()' to get the address of our
267 LMF. We'll need to restore it after the call to
268 's390_magic_trampoline' and before the call to the native
270 ----------------------------------------------------------*/
272 S390_SET (buf, s390_r1, mono_get_lmf_addr);
273 s390_basr (buf, s390_r14, s390_r1);
275 /*---------------------------------------------------------------*/
276 /* we build the MonoLMF structure on the stack - see mini-s390.h */
277 /* Keep in sync with the code in mono_arch_emit_prolog */
278 /*---------------------------------------------------------------*/
279 lmfOffset = CREATE_STACK_SIZE - sizeof(MonoLMF);
281 s390_lgr (buf, s390_r13, STK_BASE);
282 s390_aghi (buf, s390_r13, lmfOffset);
284 /*---------------------------------------------------------------*/
285 /* Set lmf.lmf_addr = jit_tls->lmf */
286 /*---------------------------------------------------------------*/
287 s390_stg (buf, s390_r2, 0, s390_r13,
288 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
290 /*---------------------------------------------------------------*/
291 /* Get current lmf */
292 /*---------------------------------------------------------------*/
293 s390_lg (buf, s390_r0, 0, s390_r2, 0);
295 /*---------------------------------------------------------------*/
296 /* Set our lmf as the current lmf */
297 /*---------------------------------------------------------------*/
298 s390_stg (buf, s390_r13, 0, s390_r2, 0);
300 /*---------------------------------------------------------------*/
301 /* Have our lmf.previous_lmf point to the last lmf */
302 /*---------------------------------------------------------------*/
303 s390_stg (buf, s390_r0, 0, s390_r13,
304 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
306 /*---------------------------------------------------------------*/
307 /* save method info */
308 /*---------------------------------------------------------------*/
309 s390_lg (buf, s390_r1, 0, STK_BASE, METHOD_SAVE_OFFSET);
310 s390_stg (buf, s390_r1, 0, s390_r13,
311 G_STRUCT_OFFSET(MonoLMF, method));
313 /*---------------------------------------------------------------*/
314 /* save the current SP */
315 /*---------------------------------------------------------------*/
316 s390_lg (buf, s390_r1, 0, STK_BASE, 0);
317 s390_stg (buf, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
319 /*---------------------------------------------------------------*/
320 /* save the current IP */
321 /*---------------------------------------------------------------*/
323 s390_lg (buf, s390_r1, 0, s390_r1, S390_RET_ADDR_OFFSET);
325 s390_lghi (buf, s390_r1, 0);
327 s390_stg (buf, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
329 /*---------------------------------------------------------------*/
330 /* Save general and floating point registers */
331 /*---------------------------------------------------------------*/
332 s390_mvc (buf, 4*sizeof(gulong), s390_r13, G_STRUCT_OFFSET(MonoLMF, gregs[2]),
333 STK_BASE, CREATE_GR_OFFSET);
334 s390_mvc (buf, 10*sizeof(gulong), s390_r13, G_STRUCT_OFFSET(MonoLMF, gregs[6]),
335 s390_r11, S390_REG_SAVE_OFFSET);
337 /* Simply copy fpregs already saved above */
338 s390_mvc (buf, 16*sizeof(double), s390_r13, G_STRUCT_OFFSET(MonoLMF, fregs[0]),
339 STK_BASE, CREATE_FP_OFFSET);
341 /*---------------------------------------------------------------*/
342 /* STEP 2: call the C trampoline function */
343 /*---------------------------------------------------------------*/
347 /* Arg 1: mgreg_t *regs. We pass sp instead */
348 s390_la (buf, s390_r2, 0, STK_BASE, CREATE_STACK_SIZE);
350 /* Arg 2: code (next address to the instruction that called us) */
352 s390_lg (buf, s390_r3, 0, s390_r11, S390_RET_ADDR_OFFSET);
354 s390_lghi (buf, s390_r3, 0);
357 /* Arg 3: Trampoline argument */
358 if (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
359 s390_lg (buf, s390_r4, 0, STK_BASE, GENERIC_REG_OFFSET);
361 s390_lg (buf, s390_r4, 0, STK_BASE, METHOD_SAVE_OFFSET);
363 /* Arg 4: trampoline address. */
364 S390_SET (buf, s390_r5, buf);
366 /* Calculate call address and call the C trampoline. Return value will be in r2 */
367 tramp = (guint8*)mono_get_trampoline_func (tramp_type);
368 S390_SET (buf, s390_r1, tramp);
369 s390_basr (buf, s390_r14, s390_r1);
371 /* OK, code address is now on r2. Move it to r1, so that we
372 can restore r2 and use it from r1 later */
373 s390_lgr (buf, s390_r1, s390_r2);
375 /*----------------------------------------------------------
376 STEP 3: Restore the LMF
377 ----------------------------------------------------------*/
378 restoreLMF(buf, STK_BASE, CREATE_STACK_SIZE);
380 /*----------------------------------------------------------
381 STEP 4: call the compiled method
382 ----------------------------------------------------------*/
384 /* Restore registers */
386 s390_lmg (buf, s390_r2, s390_r5, STK_BASE, CREATE_GR_OFFSET);
388 /* Restore the FP registers */
389 offset = CREATE_FP_OFFSET;
390 for (i = s390_f0; i <= s390_f15; ++i) {
391 s390_ld (buf, i, 0, STK_BASE, offset);
395 /* Restore stack pointer and jump to the code -
396 R14 contains the return address to our caller */
397 s390_lgr (buf, STK_BASE, s390_r11);
398 s390_lmg (buf, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
400 if (MONO_TRAMPOLINE_TYPE_MUST_RETURN(tramp_type)) {
401 s390_lgr (buf, s390_r2, s390_r1);
402 s390_br (buf, s390_r14);
404 s390_br (buf, s390_r1);
407 /* Flush instruction cache, since we've generated code */
408 mono_arch_flush_icache (code, buf - code);
409 mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL);
412 tramp_name = mono_get_generic_trampoline_name (tramp_type);
413 *info = mono_tramp_info_create (tramp_name, buf, buf - code, ji, unwind_ops);
417 g_assert ((buf - code) <= 512);
422 /*========================= End of Function ========================*/
424 /*------------------------------------------------------------------*/
426 /* Name - mono_arch_invalidate_method */
430 /*------------------------------------------------------------------*/
433 mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
435 /* FIXME: This is not thread safe */
436 guint8 *code = ji->code_start;
438 S390_SET (code, s390_r1, func);
439 S390_SET (code, s390_r2, func_arg);
440 s390_br (code, s390_r1);
444 /*========================= End of Function ========================*/
446 /*------------------------------------------------------------------*/
448 /* Name - mono_arch_create_specific_trampoline */
450 /* Function - Creates the given kind of specific trampoline */
452 /*------------------------------------------------------------------*/
455 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
457 guint8 *code, *buf, *tramp;
460 tramp = mono_get_trampoline_code (tramp_type);
462 /*----------------------------------------------------------*/
463 /* This is the method-specific part of the trampoline. Its */
464 /* purpose is to provide the generic part with the */
465 /* MonoMethod *method pointer. We'll use r1 to keep it. */
466 /*----------------------------------------------------------*/
467 code = buf = mono_domain_code_reserve (domain, SPECIFIC_TRAMPOLINE_SIZE);
469 switch (tramp_type) {
471 * Monitor tramps have the object in r2
473 case MONO_TRAMPOLINE_MONITOR_ENTER:
474 case MONO_TRAMPOLINE_MONITOR_ENTER_V4:
475 case MONO_TRAMPOLINE_MONITOR_EXIT:
476 s390_lgr (buf, s390_r1, s390_r2);
479 S390_SET (buf, s390_r1, arg1);
481 displace = (tramp - buf) / 2;
482 s390_jg (buf, displace);
484 /* Flush instruction cache, since we've generated code */
485 mono_arch_flush_icache (code, buf - code);
486 mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_SPECIFIC_TRAMPOLINE,
487 (void *) mono_get_generic_trampoline_simple_name (tramp_type));
490 g_assert ((buf - code) <= SPECIFIC_TRAMPOLINE_SIZE);
493 *code_len = buf - code;
498 /*========================= End of Function ========================*/
500 /*------------------------------------------------------------------*/
502 /* Name - mono_arch_create_rgctx_lazy_fetch_trampoline */
506 /*------------------------------------------------------------------*/
509 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
513 guint8 **rgctx_null_jumps;
521 MonoJumpInfo *ji = NULL;
522 GSList *unwind_ops = NULL;
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 = 48 + 16 * depth;
542 code = buf = mono_global_codeman_reserve (tramp_size);
544 unwind_ops = mono_arch_get_cie_program ();
546 rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
550 s390_lgr (code, s390_r1, s390_r2);
552 /* load rgctx ptr from vtable */
553 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET(MonoVTable, runtime_generic_context));
554 /* is the rgctx ptr null? */
555 s390_ltgr (code, s390_r1, s390_r1);
556 /* if yes, jump to actual trampoline */
557 rgctx_null_jumps [iPatch++] = code;
561 for (i = 0; i < depth; ++i) {
562 /* load ptr to next array */
563 if (mrgctx && i == 0)
564 s390_lg (code, s390_r1, 0, s390_r1, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT);
566 s390_lg (code, s390_r1, 0, s390_r1, 0);
567 s390_ltgr (code, s390_r1, s390_r1);
568 /* if the ptr is null then jump to actual trampoline */
569 rgctx_null_jumps [iPatch++] = code;
574 s390_lg (code, s390_r1, 0, s390_r1, (sizeof (gpointer) * (index + 1)));
575 /* is the slot null? */
576 s390_ltgr (code, s390_r1, s390_r1);
577 /* if yes, jump to actual trampoline */
578 rgctx_null_jumps [iPatch++] = code;
580 /* otherwise return r1 */
581 s390_lgr (code, s390_r2, s390_r1);
582 s390_br (code, s390_r14);
584 for (i = 0; i < iPatch; i++) {
585 displace = ((uintptr_t) code - (uintptr_t) rgctx_null_jumps[i]) / 2;
586 s390_patch_rel ((rgctx_null_jumps [i] + 2), displace);
589 g_free (rgctx_null_jumps);
591 /* move the rgctx pointer to the VTABLE register */
592 s390_lgr (code, MONO_ARCH_VTABLE_REG, s390_r2);
594 tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot),
595 MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), NULL);
597 /* jump to the actual trampoline */
598 displace = (tramp - code) / 2;
599 s390_jg (code, displace);
601 mono_arch_flush_icache (buf, code - buf);
602 mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL);
604 g_assert (code - buf <= tramp_size);
606 char *name = mono_get_rgctx_fetch_trampoline_name (slot);
607 *info = mono_tramp_info_create (name, buf, code - buf, ji, unwind_ops);
613 /*========================= End of Function ========================*/
615 /*------------------------------------------------------------------*/
617 /* Name - mono_arch_get_static_rgctx_trampoline */
619 /* Function - Create a trampoline which sets RGCTX_REG to MRGCTX*/
620 /* then jumps to ADDR. */
622 /*------------------------------------------------------------------*/
625 mono_arch_get_static_rgctx_trampoline (MonoMethod *m,
626 MonoMethodRuntimeGenericContext *mrgctx,
629 guint8 *code, *start;
633 MonoDomain *domain = mono_domain_get ();
637 start = code = mono_domain_code_reserve (domain, buf_len);
639 S390_SET (code, MONO_ARCH_RGCTX_REG, mrgctx);
640 displace = ((uintptr_t) addr - (uintptr_t) code) / 2;
641 s390_jg (code, displace);
642 g_assert ((code - start) < buf_len);
644 mono_arch_flush_icache (start, code - start);
645 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_HELPER, NULL);
650 /*========================= End of Function ========================*/
652 /*------------------------------------------------------------------*/
654 /* Name - handler_block_trampoline_helper */
658 /*------------------------------------------------------------------*/
661 handler_block_trampoline_helper (gpointer *ptr)
663 MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
664 *ptr = jit_tls->handler_block_return_address;
667 /*========================= End of Function ========================*/
669 /*------------------------------------------------------------------*/
671 /* Name - mono_arch_create_handler_block_trampoline */
675 /*------------------------------------------------------------------*/
678 mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot)
680 guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD);
683 MonoJumpInfo *ji = NULL;
684 GSList *unwind_ops = NULL;
688 code = buf = mono_global_codeman_reserve (tramp_size);
691 * This trampoline restore the call chain of the handler block
692 * then jumps into the code that deals with it.
695 if (mono_get_jit_tls_offset () != -1) {
696 s390_ear (code, s390_r1, 0);
697 s390_sllg (code, s390_r1, s390_r1, 0, 32);
698 s390_ear (code, s390_r1, 1);
699 S390_SET (code, s390_r14, mono_get_jit_tls_offset());
700 s390_lg (code, s390_r14, s390_r1, 0, G_STRUCT_OFFSET(MonoJitTlsData, handler_block_return_address));
704 S390_SET (code, s390_r1, tramp);
705 s390_br (code, s390_r1);
708 * Slow path uses a C helper
710 S390_SET (code, s390_r2, tramp);
711 S390_SET (code, s390_r1, handler_block_trampoline_helper);
712 s390_br (code, s390_r1);
715 mono_arch_flush_icache (buf, code - buf);
716 mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL);
717 g_assert (code - buf <= tramp_size);
719 *info = mono_tramp_info_create ("handler_block_trampoline", buf, code - buf, ji, unwind_ops);
724 /*========================= End of Function ========================*/
726 /*------------------------------------------------------------------*/
728 /* Name - mono_arch_create_generic_class_init_trampoline */
732 /*------------------------------------------------------------------*/
735 mono_arch_create_generic_class_init_trampoline (MonoTrampInfo **info, gboolean aot)
739 static int byte_offset = -1;
740 static guint8 bitmask;
743 GSList *unwind_ops = NULL;
744 MonoJumpInfo *ji = NULL;
748 code = buf = mono_global_codeman_reserve (tramp_size);
750 unwind_ops = mono_arch_get_cie_program ();
753 mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
755 s390_llgc(code, s390_r0, 0, MONO_ARCH_VTABLE_REG, byte_offset);
756 s390_nill(code, s390_r0, bitmask);
757 s390_bnzr(code, s390_r14);
759 tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT,
760 mono_get_root_domain (), NULL);
762 /* jump to the actual trampoline */
763 displace = (tramp - code) / 2;
764 s390_jg (code, displace);
766 mono_arch_flush_icache (buf, code - buf);
768 g_assert (code - buf <= tramp_size);
770 *info = mono_tramp_info_create ("generic_class_init_trampoline", buf, code - buf, ji, unwind_ops);
775 /*========================= End of Function ========================*/
777 #ifdef MONO_ARCH_MONITOR_OBJECT_REG
778 /*------------------------------------------------------------------*/
780 /* Name - mono_arch_create_monitor_enter_trampoline */
784 /*------------------------------------------------------------------*/
787 mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean is_v4, gboolean aot)
791 gint16 *jump_obj_null,
796 *jump_sync_thin_hash = NULL,
797 *jump_lock_taken_true = NULL;
799 status_reg = s390_r0,
800 lock_taken_reg = s390_r1,
806 MonoJumpInfo *ji = NULL;
807 GSList *unwind_ops = NULL;
809 g_assert (MONO_ARCH_MONITOR_OBJECT_REG == obj_reg);
810 #ifdef MONO_ARCH_MONITOR_LOCK_TAKEN_REG
811 g_assert (MONO_ARCH_MONITOR_LOCK_TAKEN_REG == lock_taken_reg);
816 mono_monitor_threads_sync_members_offset (&status_offset, &nest_offset);
817 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (status_offset) == sizeof (guint32));
818 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (nest_offset) == sizeof (guint32));
819 status_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (status_offset);
820 nest_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (nest_offset);
824 code = buf = mono_global_codeman_reserve (tramp_size);
826 unwind_ops = mono_arch_get_cie_program ();
828 if (mono_thread_get_tls_offset () != -1) {
829 /* MonoObject* obj is in obj_reg */
831 s390_ltgr (code, obj_reg, obj_reg);
832 /* if yes, jump to actual trampoline */
833 s390_jz (code, 0); CODEPTR(code, jump_obj_null);
836 s390_cli (code, lock_taken_reg, 0, 1);
837 /* if *lock_taken is 1, jump to actual trampoline */
838 s390_je (code, 0); CODEPTR(code, jump_lock_taken_true);
841 /* load obj->synchronization to sync_reg */
842 s390_lg (code, sync_reg, 0, obj_reg, MONO_STRUCT_OFFSET (MonoObject, synchronisation));
844 if (mono_gc_is_moving ()) {
845 /*if bit zero is set it's a thin hash*/
846 s390_tmll (code, sync_reg, 1);
847 s390_jo (code, 0); CODEPTR(code, jump_sync_thin_hash);
849 /* Clear bits used by the gc */
850 s390_nill (code, sync_reg, ~0x3);
853 /* is synchronization null? */
854 s390_ltgr (code, sync_reg, sync_reg);
855 /* if yes, jump to actual trampoline */
856 s390_jz (code, 0); CODEPTR(code, jump_sync_null);
858 /* load MonoInternalThread* into tid_reg */
859 s390_ear (code, s390_r5, 0);
860 s390_sllg(code, s390_r5, s390_r5, 0, 32);
861 s390_ear (code, s390_r5, 1);
863 s390_lg (code, tid_reg, 0, s390_r5, mono_thread_get_tls_offset ());
864 s390_lgf (code, tid_reg, 0, tid_reg, MONO_STRUCT_OFFSET (MonoInternalThread, small_id));
866 /* is synchronization->owner free */
867 s390_lgf (code, status_reg, 0, sync_reg, status_offset);
868 s390_nilf (code, status_reg, OWNER_MASK);
869 /* if not, jump to next case */
870 s390_jnz (code, 0); CODEPTR(code, jump_tid);
872 /* if yes, try a compare-exchange with the TID */
873 /* Form new status in tid_reg */
874 s390_xr (code, tid_reg, status_reg);
875 /* compare and exchange */
876 s390_cs (code, status_reg, tid_reg, sync_reg, status_offset);
877 s390_jnz (code, 0); CODEPTR(code, jump_cs_failed);
878 /* if successful, return */
880 s390_mvi (code, lock_taken_reg, 0, 1);
881 s390_br (code, s390_r14);
883 /* next case: synchronization->owner is not null */
884 PTRSLOT(code, jump_tid);
885 /* is synchronization->owner == TID? */
886 s390_nilf (code, status_reg, OWNER_MASK);
887 s390_cr (code, status_reg, tid_reg);
888 /* if not, jump to actual trampoline */
889 s390_jnz (code, 0); CODEPTR(code, jump_other_owner);
890 /* if yes, increment nest */
891 s390_lgf (code, s390_r5, 0, sync_reg, nest_offset);
892 s390_ahi (code, s390_r5, 1);
893 s390_st (code, s390_r5, 0, sync_reg, nest_offset);
896 s390_mvi (code, lock_taken_reg, 0, 1);
897 s390_br (code, s390_r14);
899 PTRSLOT (code, jump_obj_null);
900 if (jump_sync_thin_hash)
901 PTRSLOT (code, jump_sync_thin_hash);
902 PTRSLOT (code, jump_sync_null);
903 PTRSLOT (code, jump_cs_failed);
904 PTRSLOT (code, jump_other_owner);
906 PTRSLOT (code, jump_lock_taken_true);
909 /* jump to the actual trampoline */
911 tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_ENTER_V4, mono_get_root_domain (), NULL);
913 tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_ENTER, mono_get_root_domain (), NULL);
915 /* jump to the actual trampoline */
916 S390_SET (code, s390_r1, tramp);
917 s390_br (code, s390_r1);
919 mono_arch_flush_icache (code, code - buf);
920 mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_MONITOR, NULL);
921 g_assert (code - buf <= tramp_size);
925 *info = mono_tramp_info_create ("monitor_enter_v4_trampoline", buf, code - buf, ji, unwind_ops);
927 *info = mono_tramp_info_create ("monitor_enter_trampoline", buf, code - buf, ji, unwind_ops);
933 /*========================= End of Function ========================*/
935 /*------------------------------------------------------------------*/
937 /* Name - mono_arch_create_monitor_exit_trampoline */
941 /*------------------------------------------------------------------*/
944 mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot)
948 gint16 *jump_obj_null,
954 *jump_sync_thin_hash = NULL;
956 status_offset, nest_offset;
957 MonoJumpInfo *ji = NULL;
958 GSList *unwind_ops = NULL;
959 int obj_reg = s390_r2,
961 status_reg = s390_r4;
963 g_assert (obj_reg == MONO_ARCH_MONITOR_OBJECT_REG);
965 mono_monitor_threads_sync_members_offset (&status_offset, &nest_offset);
966 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (status_offset) == sizeof (guint32));
967 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (nest_offset) == sizeof (guint32));
968 status_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (status_offset);
969 nest_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (nest_offset);
973 code = buf = mono_global_codeman_reserve (tramp_size);
975 unwind_ops = mono_arch_get_cie_program ();
977 if (mono_thread_get_tls_offset () != -1) {
978 /* MonoObject* obj is in obj_reg */
980 s390_ltgr (code, obj_reg, obj_reg);
981 /* if yes, jump to actual trampoline */
982 s390_jz (code, 0); CODEPTR(code, jump_obj_null);
984 /* load obj->synchronization to RCX */
985 s390_lg (code, sync_reg, 0, obj_reg, MONO_STRUCT_OFFSET (MonoObject, synchronisation));
987 if (mono_gc_is_moving ()) {
988 /*if bit zero is set it's a thin hash*/
989 s390_tmll (code, sync_reg, 1);
990 s390_jo (code, 0); CODEPTR(code, jump_sync_thin_hash);
992 /* Clear bits used by the gc */
993 s390_nill (code, sync_reg, ~0x3);
996 /* is synchronization null? */
997 s390_ltgr (code, sync_reg, sync_reg);
998 /* if yes, jump to actual trampoline */
999 s390_jz (code, 0); CODEPTR(code, jump_sync_null);
1001 /* next case: synchronization is not null */
1002 /* load MonoInternalThread* into r5 */
1003 s390_ear (code, s390_r5, 0);
1004 s390_sllg(code, s390_r5, s390_r5, 0, 32);
1005 s390_ear (code, s390_r5, 1);
1006 /* load TID into r1 */
1007 s390_lg (code, s390_r1, 0, s390_r5, mono_thread_get_tls_offset ());
1008 s390_lgf (code, s390_r1, 0, s390_r1, MONO_STRUCT_OFFSET (MonoInternalThread, small_id));
1009 /* is synchronization->owner == TID */
1010 s390_lgf (code, status_reg, 0, sync_reg, status_offset);
1011 s390_xr (code, s390_r1, status_reg);
1012 s390_tmlh (code, s390_r1, OWNER_MASK);
1013 /* if not, jump to actual trampoline */
1014 s390_jno (code, 0); CODEPTR(code, jump_not_owned);
1016 /* next case: synchronization->owner == TID */
1017 /* is synchronization->nest == 1 */
1018 s390_lgf (code, s390_r0, 0, sync_reg, nest_offset);
1019 s390_chi (code, s390_r0, 1);
1020 /* if not, jump to next case */
1021 s390_jne (code, 0); CODEPTR(code, jump_next);
1022 /* if yes, is synchronization->entry_count greater than zero */
1023 s390_cfi (code, status_reg, ENTRY_COUNT_WAITERS);
1024 /* if not, jump to actual trampoline */
1025 s390_jnz (code, 0); CODEPTR(code, jump_have_waiters);
1026 /* if yes, try to set synchronization->owner to null and return */
1027 /* old status in s390_r0 */
1028 s390_lgfr (code, s390_r0, status_reg);
1029 /* form new status */
1030 s390_nilf (code, status_reg, ENTRY_COUNT_MASK);
1031 /* compare and exchange */
1032 s390_cs (code, s390_r0, status_reg, sync_reg, status_offset);
1033 /* if not successful, jump to actual trampoline */
1034 s390_jnz (code, 0); CODEPTR(code, jump_cs_failed);
1035 s390_br (code, s390_r14);
1037 /* next case: synchronization->nest is not 1 */
1038 PTRSLOT (code, jump_next);
1039 /* decrease synchronization->nest and return */
1040 s390_lgf (code, s390_r0, 0, sync_reg, nest_offset);
1041 s390_ahi (code, s390_r0, -1);
1042 s390_st (code, s390_r0, 0, sync_reg, nest_offset);
1043 s390_br (code, s390_r14);
1045 PTRSLOT (code, jump_obj_null);
1046 if (jump_sync_thin_hash)
1047 PTRSLOT (code, jump_sync_thin_hash);
1048 PTRSLOT (code, jump_have_waiters);
1049 PTRSLOT (code, jump_not_owned);
1050 PTRSLOT (code, jump_cs_failed);
1051 PTRSLOT (code, jump_sync_null);
1054 /* jump to the actual trampoline */
1055 tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_EXIT, mono_get_root_domain (), NULL);
1057 S390_SET (code, s390_r1, tramp);
1058 s390_br (code, s390_r1);
1060 mono_arch_flush_icache (code, code - buf);
1061 mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_MONITOR, NULL);
1062 g_assert (code - buf <= tramp_size);
1065 *info = mono_tramp_info_create ("monitor_exit_trampoline", buf, code - buf, ji, unwind_ops);
1070 /*========================= End of Function ========================*/