b0333d3cf18a92c3cfbca8fdec243131d1216168
[mono.git] / mono / mini / tramp-s390x.c
1 /**
2  * \file
3  * Function    - JIT trampoline code for S/390.
4  *
5  * Name        - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com)
6  *
7  * Date        - January, 2004
8  *
9  * Derivation  - From exceptions-x86 & exceptions-ppc
10  *               Paolo Molaro (lupus@ximian.com)
11  *               Dietmar Maurer (dietmar@ximian.com)
12  *
13  * Copyright   - 2001 Ximian, Inc.
14  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
15  *
16  */
17
18 /*------------------------------------------------------------------*/
19 /*                 D e f i n e s                                    */
20 /*------------------------------------------------------------------*/
21
22 #define LMFReg  s390_r13
23
24 /*
25  * Method-specific trampoline code fragment sizes                   
26  */
27 #define SPECIFIC_TRAMPOLINE_SIZE        96
28
29 /*========================= End of Defines =========================*/
30
31 /*------------------------------------------------------------------*/
32 /*                 I n c l u d e s                                  */
33 /*------------------------------------------------------------------*/
34
35 #include <config.h>
36 #include <glib.h>
37 #include <string.h>
38
39 #include <mono/metadata/abi-details.h>
40 #include <mono/metadata/appdomain.h>
41 #include <mono/metadata/gc-internals.h>
42 #include <mono/metadata/marshal.h>
43 #include <mono/metadata/profiler-private.h>
44 #include <mono/metadata/tabledefs.h>
45 #include <mono/arch/s390x/s390x-codegen.h>
46
47 #include "mini.h"
48 #include "mini-s390x.h"
49 #include "support-s390x.h"
50 #include "jit-icalls.h"
51
52 /*========================= End of Includes ========================*/
53
54 /*------------------------------------------------------------------*/
55 /*                 T y p e d e f s                                  */
56 /*------------------------------------------------------------------*/
57
58 typedef struct {
59         guint8  stk[S390_MINIMAL_STACK_SIZE];   /* Standard s390x stack */
60         guint64 saveFn;                         /* Call address         */
61         struct MonoLMF  LMF;                    /* LMF                  */
62 } trampStack_t;
63
64 /*========================= End of Typedefs ========================*/
65
66 /*------------------------------------------------------------------*/
67 /*                   P r o t o t y p e s                            */
68 /*------------------------------------------------------------------*/
69
70 /*========================= End of Prototypes ======================*/
71
72 /*------------------------------------------------------------------*/
73 /*                 G l o b a l   V a r i a b l e s                  */
74 /*------------------------------------------------------------------*/
75
76
77 /*====================== End of Global Variables ===================*/
78
79 /*------------------------------------------------------------------*/
80 /*                                                                  */
81 /* Name         - mono_arch_get_unbox_trampoline                    */
82 /*                                                                  */
83 /* Function     - Return a pointer to a trampoline which does the   */
84 /*                unboxing before calling the method.               */
85 /*                                                                  */
86 /*                When value type methods are called through the    */
87 /*                vtable we need to unbox the 'this' argument.      */
88 /*                                                                  */
89 /* Parameters   - method - Methd pointer                            */
90 /*                addr   - Pointer to native code for method        */
91 /*                                                                  */
92 /*------------------------------------------------------------------*/
93
94 gpointer
95 mono_arch_get_unbox_trampoline (MonoMethod *method, gpointer addr)
96 {
97         guint8 *code, *start;
98         int this_pos = s390_r2;
99         MonoDomain *domain = mono_domain_get ();
100         char trampName[128];
101
102         start = code = mono_domain_code_reserve (domain, 28);
103
104         S390_SET  (code, s390_r1, addr);
105         s390_aghi (code, this_pos, sizeof(MonoObject));
106         s390_br   (code, s390_r1);
107
108         g_assert ((code - start) <= 28);
109
110         mono_arch_flush_icache (start, code - start);
111         MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_UNBOX_TRAMPOLINE, method));
112
113         snprintf(trampName, sizeof(trampName), "%s_unbox_trampoline", method->name);
114
115         mono_tramp_info_register (mono_tramp_info_create (trampName, start, code - start, NULL, NULL), domain);
116
117         return start;
118 }
119
120 /*========================= End of Function ========================*/
121
122 /*------------------------------------------------------------------*/
123 /*                                                                  */
124 /* Name         - mono_arch_patch_callsite                          */
125 /*                                                                  */
126 /* Function     - Patch a non-virtual callsite so it calls @addr.   */
127 /*                                                                  */
128 /*------------------------------------------------------------------*/
129
130 void
131 mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr)
132 {
133         gint32 displace;
134         unsigned short opcode;
135
136         opcode = *((unsigned short *) (orig_code - 2));
137         if (opcode == 0x0dee) {
138                 /* This should be a 'iihf/iilf' sequence */
139                 S390_EMIT_CALL((orig_code - 14), addr);
140                 mono_arch_flush_icache (orig_code - 14, 12);
141         } else {
142                 /* This is the 'brasl' instruction */
143                 orig_code    -= 4;
144                 displace = ((gssize) addr - (gssize) (orig_code - 2)) / 2;
145                 s390_patch_rel (orig_code, displace);
146                 mono_arch_flush_icache (orig_code, 4);
147         }
148 }
149
150 /*========================= End of Function ========================*/
151
152 /*------------------------------------------------------------------*/
153 /*                                                                  */
154 /* Name         - mono_arch_patch_plt_entry.                        */
155 /*                                                                  */
156 /* Function     - Patch a PLT entry - unused as yet.                */
157 /*                                                                  */
158 /*------------------------------------------------------------------*/
159
160 void
161 mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
162 {
163         g_assert_not_reached ();
164 }
165
166 /*========================= End of Function ========================*/
167
168 /*------------------------------------------------------------------*/
169 /*                                                                  */
170 /* Name         - mono_arch_create_trampoline_code                  */
171 /*                                                                  */
172 /* Function     - Create the designated type of trampoline according*/
173 /*                to the 'tramp_type' parameter.                    */
174 /*                                                                  */
175 /*------------------------------------------------------------------*/
176
177 guchar*
178 mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
179 {
180         char *tramp_name;
181         guint8 *buf, *tramp, *code;
182         int i, offset, has_caller;
183         GSList *unwind_ops = NULL;
184         MonoJumpInfo *ji = NULL;
185
186         g_assert (!aot);
187
188         /* Now we'll create in 'buf' the S/390 trampoline code. This
189            is the trampoline code common to all methods  */
190                 
191         code = buf = mono_global_codeman_reserve(512);
192                 
193         if ((tramp_type == MONO_TRAMPOLINE_JUMP) ||
194             (tramp_type == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD)) 
195                 has_caller = 0;
196         else
197                 has_caller = 1;
198
199         /*-----------------------------------------------------------
200           STEP 0: First create a non-standard function prologue with a
201           stack size big enough to save our registers.
202           -----------------------------------------------------------*/
203                 
204         s390_stmg (buf, s390_r6, s390_r15, STK_BASE, S390_REG_SAVE_OFFSET);
205         s390_lgr  (buf, s390_r11, s390_r15);
206         s390_aghi (buf, STK_BASE, -sizeof(trampStack_t));
207         s390_stg  (buf, s390_r11, 0, STK_BASE, 0);
208
209         /*---------------------------------------------------------------*/
210         /* we build the MonoLMF structure on the stack - see mini-s390.h */
211         /* Keep in sync with the code in mono_arch_emit_prolog           */
212         /*---------------------------------------------------------------*/
213                                                                                         
214         s390_lgr   (buf, LMFReg, STK_BASE);
215         s390_aghi  (buf, LMFReg, G_STRUCT_OFFSET(trampStack_t, LMF));
216                                                                                         
217         /*---------------------------------------------------------------*/     
218         /* Save general and floating point registers in LMF              */     
219         /*---------------------------------------------------------------*/     
220         s390_stmg (buf, s390_r0, s390_r1, LMFReg, G_STRUCT_OFFSET(MonoLMF, gregs[0]));
221         s390_stmg (buf, s390_r2, s390_r5, LMFReg, G_STRUCT_OFFSET(MonoLMF, gregs[2]));
222         s390_mvc  (buf, 10*sizeof(gulong), LMFReg, G_STRUCT_OFFSET(MonoLMF, gregs[6]),
223                    s390_r11, S390_REG_SAVE_OFFSET);
224
225         offset = G_STRUCT_OFFSET(MonoLMF, fregs[0]);
226         for (i = s390_f0; i <= s390_f15; ++i) {
227                 s390_std  (buf, i, 0, LMFReg, offset);
228                 offset += sizeof(gdouble);
229         }
230
231         /*----------------------------------------------------------
232           STEP 1: call 'mono_get_lmf_addr()' to get the address of our
233           LMF. We'll need to restore it after the call to
234           's390_magic_trampoline' and before the call to the native
235           method.
236           ----------------------------------------------------------*/
237                                 
238         S390_SET  (buf, s390_r1, mono_get_lmf_addr);
239         s390_basr (buf, s390_r14, s390_r1);
240                                                                                         
241         /*---------------------------------------------------------------*/     
242         /* Set lmf.lmf_addr = jit_tls->lmf                               */     
243         /*---------------------------------------------------------------*/     
244         s390_stg   (buf, s390_r2, 0, LMFReg,                            
245                             G_STRUCT_OFFSET(MonoLMF, lmf_addr));                        
246                                                                                         
247         /*---------------------------------------------------------------*/     
248         /* Get current lmf                                               */     
249         /*---------------------------------------------------------------*/     
250         s390_lg    (buf, s390_r0, 0, s390_r2, 0);                               
251                                                                                         
252         /*---------------------------------------------------------------*/     
253         /* Set our lmf as the current lmf                                */     
254         /*---------------------------------------------------------------*/     
255         s390_stg   (buf, LMFReg, 0, s390_r2, 0);                                
256                                                                                         
257         /*---------------------------------------------------------------*/     
258         /* Have our lmf.previous_lmf point to the last lmf               */     
259         /*---------------------------------------------------------------*/     
260         s390_stg   (buf, s390_r0, 0, LMFReg,                            
261                             G_STRUCT_OFFSET(MonoLMF, previous_lmf));                    
262                                                                                         
263         /*---------------------------------------------------------------*/     
264         /* save method info                                              */     
265         /*---------------------------------------------------------------*/     
266         s390_lg    (buf, s390_r1, 0, LMFReg, G_STRUCT_OFFSET(MonoLMF, gregs[1]));
267         s390_stg   (buf, s390_r1, 0, LMFReg, G_STRUCT_OFFSET(MonoLMF, method));                         
268                                                                         
269         /*---------------------------------------------------------------*/     
270         /* save the current SP                                           */     
271         /*---------------------------------------------------------------*/     
272         s390_lg    (buf, s390_r1, 0, STK_BASE, 0);
273         s390_stg   (buf, s390_r1, 0, LMFReg, G_STRUCT_OFFSET(MonoLMF, ebp));    
274                                                                         
275         /*---------------------------------------------------------------*/     
276         /* save the current IP                                           */     
277         /*---------------------------------------------------------------*/     
278         if (has_caller) {
279                 s390_lg    (buf, s390_r1, 0, s390_r1, S390_RET_ADDR_OFFSET);
280         } else {
281                 s390_lghi  (buf, s390_r1, 0);
282         }
283         s390_stg   (buf, s390_r1, 0, LMFReg, G_STRUCT_OFFSET(MonoLMF, eip));    
284                                                                                         
285         /*---------------------------------------------------------------*/
286         /* STEP 2: call the C trampoline function                        */
287         /*---------------------------------------------------------------*/
288                                 
289         /* Set arguments */
290
291         /* Arg 1: mgreg_t *regs */
292         s390_la  (buf, s390_r2, 0, LMFReg, G_STRUCT_OFFSET(MonoLMF, gregs[0]));
293                 
294         /* Arg 2: code (next address to the instruction that called us) */
295         if (has_caller) {
296                 s390_lg   (buf, s390_r3, 0, s390_r11, S390_RET_ADDR_OFFSET);
297         } else {
298                 s390_lghi (buf, s390_r3, 0);
299         }
300
301         /* Arg 3: Trampoline argument */
302         s390_lg (buf, s390_r4, 0, LMFReg, G_STRUCT_OFFSET(MonoLMF, gregs[1]));
303
304         /* Arg 4: trampoline address. */
305         S390_SET (buf, s390_r5, buf);
306                 
307         /* Calculate call address and call the C trampoline. Return value will be in r2 */
308         tramp = (guint8*)mono_get_trampoline_func (tramp_type);
309         S390_SET  (buf, s390_r1, tramp);
310         s390_basr (buf, s390_r14, s390_r1);
311                 
312         /* OK, code address is now on r2. Save it, so that we
313            can restore r2 and use it later */
314         s390_stg  (buf, s390_r2, 0, STK_BASE, G_STRUCT_OFFSET(trampStack_t, saveFn));
315
316         /* Check for thread interruption */
317         S390_SET  (buf, s390_r1, (guint8 *)mono_interruption_checkpoint_from_trampoline);
318         s390_basr (buf, s390_r14, s390_r1);
319
320         /*----------------------------------------------------------
321           STEP 3: Restore the LMF
322           ----------------------------------------------------------*/
323         restoreLMF(buf, STK_BASE, sizeof(trampStack_t));
324         
325         /* Reload result */
326         s390_lg   (buf, s390_r1, 0, STK_BASE, G_STRUCT_OFFSET(trampStack_t, saveFn));
327
328         /*----------------------------------------------------------
329           STEP 4: call the compiled method
330           ----------------------------------------------------------*/
331                 
332         /* Restore parameter registers */
333         s390_lmg (buf, s390_r2, s390_r5, LMFReg, G_STRUCT_OFFSET(MonoLMF, gregs[2]));
334                 
335         /* Restore the FP registers */
336         offset = G_STRUCT_OFFSET(MonoLMF, fregs[0]);
337         for (i = s390_f0; i <= s390_f15; ++i) {
338                 s390_ld  (buf, i, 0, LMFReg, offset);
339                 offset += sizeof(gdouble);
340         }
341
342         /* Restore stack pointer and jump to the code -
343          * R14 contains the return address to our caller 
344          */
345         s390_lgr  (buf, STK_BASE, s390_r11);
346         s390_lmg  (buf, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
347
348         if (MONO_TRAMPOLINE_TYPE_MUST_RETURN(tramp_type)) {
349                 s390_lgr (buf, s390_r2, s390_r1);
350                 s390_br  (buf, s390_r14);
351         } else {
352                 s390_br  (buf, s390_r1);
353         }
354
355         /* Flush instruction cache, since we've generated code */
356         mono_arch_flush_icache (code, buf - code);
357         MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
358         
359         g_assert (info);
360         tramp_name = mono_get_generic_trampoline_name (tramp_type);
361         *info = mono_tramp_info_create (tramp_name, buf, buf - code, ji, unwind_ops);
362         g_free (tramp_name);
363
364         /* Sanity check */
365         g_assert ((buf - code) <= 512);
366
367         return code;
368 }
369
370 /*========================= End of Function ========================*/
371
372 /*------------------------------------------------------------------*/
373 /*                                                                  */
374 /* Name         - mono_arch_invalidate_method                       */
375 /*                                                                  */
376 /* Function     -                                                   */
377 /*                                                                  */
378 /*------------------------------------------------------------------*/
379
380 void
381 mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
382 {
383         /* FIXME: This is not thread safe */
384         guint8 *code = ji->code_start;
385
386         S390_SET  (code, s390_r1, func);
387         S390_SET  (code, s390_r2, func_arg);
388         s390_br   (code, s390_r1);
389
390 }
391
392 /*========================= End of Function ========================*/
393
394 /*------------------------------------------------------------------*/
395 /*                                                                  */
396 /* Name         - mono_arch_create_specific_trampoline              */
397 /*                                                                  */
398 /* Function     - Creates the given kind of specific trampoline     */
399 /*                                                                  */
400 /*------------------------------------------------------------------*/
401
402 gpointer
403 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
404 {
405         guint8 *code, *buf, *tramp;
406         gint32 displace;
407
408         tramp = mono_get_trampoline_code (tramp_type);
409
410         /*----------------------------------------------------------*/
411         /* This is the method-specific part of the trampoline. Its  */
412         /* purpose is to provide the generic part with the          */
413         /* MonoMethod *method pointer. We'll use r1 to keep it.     */
414         /*----------------------------------------------------------*/
415         code = buf = mono_domain_code_reserve (domain, SPECIFIC_TRAMPOLINE_SIZE);
416
417         S390_SET  (buf, s390_r1, arg1);
418         displace = (tramp - buf) / 2;
419         s390_jg   (buf, displace);
420
421         /* Flush instruction cache, since we've generated code */
422         mono_arch_flush_icache (code, buf - code);
423         MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf,
424                              MONO_PROFILER_CODE_BUFFER_SPECIFIC_TRAMPOLINE,
425                              (void *) mono_get_generic_trampoline_simple_name (tramp_type)));
426
427         /* Sanity check */
428         g_assert ((buf - code) <= SPECIFIC_TRAMPOLINE_SIZE);
429
430         if (code_len)
431                 *code_len = buf - code;
432         
433         return code;
434 }       
435
436 /*========================= End of Function ========================*/
437
438 /*------------------------------------------------------------------*/
439 /*                                                                  */
440 /* Name         - mono_arch_create_rgctx_lazy_fetch_trampoline      */
441 /*                                                                  */
442 /* Function     -                                                   */
443 /*                                                                  */
444 /*------------------------------------------------------------------*/
445
446 gpointer
447 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
448 {
449         guint8 *tramp;
450         guint8 *code, *buf;
451         guint8 **rgctx_null_jumps;
452         gint32 displace;
453         int tramp_size,
454             depth, 
455             index, 
456             iPatch = 0,
457             i;
458         gboolean mrgctx;
459         MonoJumpInfo *ji = NULL;
460         GSList *unwind_ops = NULL;
461
462         mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
463         index = MONO_RGCTX_SLOT_INDEX (slot);
464         if (mrgctx)
465                 index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
466         for (depth = 0; ; ++depth) {
467                 int size = mono_class_rgctx_get_array_size (depth, mrgctx);
468
469                 if (index < size - 1)
470                         break;
471                 index -= size - 1;
472         }
473
474         tramp_size = 48 + 16 * depth;
475         if (mrgctx)
476                 tramp_size += 4;
477         else
478                 tramp_size += 12;
479
480         code = buf = mono_global_codeman_reserve (tramp_size);
481
482         unwind_ops = mono_arch_get_cie_program ();
483
484         rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
485
486         if (mrgctx) {
487                 /* get mrgctx ptr */
488                 s390_lgr (code, s390_r1, s390_r2);
489         } else {
490                 /* load rgctx ptr from vtable */
491                 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET(MonoVTable, runtime_generic_context));
492                 /* is the rgctx ptr null? */
493                 s390_ltgr (code, s390_r1, s390_r1);
494                 /* if yes, jump to actual trampoline */
495                 rgctx_null_jumps [iPatch++] = code;
496                 s390_jge (code, 0);
497         }
498
499         for (i = 0; i < depth; ++i) {
500                 /* load ptr to next array */
501                 if (mrgctx && i == 0)
502                         s390_lg (code, s390_r1, 0, s390_r1, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT);
503                 else
504                         s390_lg (code, s390_r1, 0, s390_r1, 0);
505                 s390_ltgr (code, s390_r1, s390_r1);
506                 /* if the ptr is null then jump to actual trampoline */
507                 rgctx_null_jumps [iPatch++] = code;
508                 s390_jge (code, 0);
509         }
510
511         /* fetch slot */
512         s390_lg (code, s390_r1, 0, s390_r1, (sizeof (gpointer) * (index  + 1)));
513         /* is the slot null? */
514         s390_ltgr (code, s390_r1, s390_r1);
515         /* if yes, jump to actual trampoline */
516         rgctx_null_jumps [iPatch++] = code;
517         s390_jge (code, 0);
518         /* otherwise return r1 */
519         s390_lgr (code, s390_r2, s390_r1);
520         s390_br  (code, s390_r14);
521
522         for (i = 0; i < iPatch; i++) {
523                 displace = ((uintptr_t) code - (uintptr_t) rgctx_null_jumps[i]) / 2;
524                 s390_patch_rel ((rgctx_null_jumps [i] + 2), displace);
525         }
526
527         g_free (rgctx_null_jumps);
528
529         /* move the rgctx pointer to the VTABLE register */
530         s390_lgr (code, MONO_ARCH_VTABLE_REG, s390_r2);
531
532         tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot),
533                 MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), NULL);
534
535         /* jump to the actual trampoline */
536         displace = (tramp - code) / 2;
537         s390_jg (code, displace);
538
539         mono_arch_flush_icache (buf, code - buf);
540         MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
541
542         g_assert (code - buf <= tramp_size);
543
544         char *name = mono_get_rgctx_fetch_trampoline_name (slot);
545         *info = mono_tramp_info_create (name, buf, code - buf, ji, unwind_ops);
546         g_free (name);
547
548         return(buf);
549 }       
550
551 /*========================= End of Function ========================*/
552
553 /*------------------------------------------------------------------*/
554 /*                                                                  */
555 /* Name         - mono_arch_get_static_rgctx_trampoline             */
556 /*                                                                  */
557 /* Function     - Create a trampoline which sets RGCTX_REG to ARG       */
558 /*                then jumps to ADDR.                               */
559 /*                                                                  */
560 /*------------------------------------------------------------------*/
561
562 gpointer
563 mono_arch_get_static_rgctx_trampoline (gpointer arg,
564                                                                            gpointer addr)
565 {
566         guint8 *code, *start;
567         gint32 displace;
568         int buf_len;
569
570         MonoDomain *domain = mono_domain_get ();
571
572         buf_len = 32;
573
574         start = code = mono_domain_code_reserve (domain, buf_len);
575
576         S390_SET  (code, MONO_ARCH_RGCTX_REG, arg);
577         displace = ((uintptr_t) addr - (uintptr_t) code) / 2;
578         s390_jg   (code, displace);
579         g_assert ((code - start) < buf_len);
580
581         mono_arch_flush_icache (start, code - start);
582         MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_HELPER, NULL));
583
584         mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), domain);
585
586         return(start);
587 }       
588
589 /*========================= End of Function ========================*/
590
591 /*------------------------------------------------------------------*/
592 /*                                                                  */
593 /* Name         - handler_block_trampoline_helper                   */
594 /*                                                                  */
595 /* Function     -                                                   */
596 /*                                                                  */
597 /*------------------------------------------------------------------*/
598
599 static void
600 handler_block_trampoline_helper (gpointer *ptr)
601 {
602         MonoJitTlsData *jit_tls = mono_tls_get_jit_tls ();
603         *ptr = jit_tls->handler_block_return_address;
604 }
605
606 /*========================= End of Function ========================*/
607
608 /*------------------------------------------------------------------*/
609 /*                                                                  */
610 /* Name         - mono_arch_create_handler_block_trampoline         */
611 /*                                                                  */
612 /* Function     -                                                   */
613 /*                                                                  */
614 /*------------------------------------------------------------------*/
615
616 gpointer
617 mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot)
618 {
619         guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD);
620         guint8 *code, *buf;
621         int tramp_size = 64;
622         MonoJumpInfo *ji = NULL;
623         GSList *unwind_ops = NULL;
624
625         g_assert (!aot);
626
627         code = buf = mono_global_codeman_reserve (tramp_size);
628
629         /*
630          * This trampoline restore the call chain of the handler block 
631          * then jumps into the code that deals with it.
632          */
633
634         /*
635          * Slow path uses a C helper
636          */
637         S390_SET  (code, s390_r2, tramp);
638         S390_SET  (code, s390_r1, handler_block_trampoline_helper);
639         s390_br   (code, s390_r1);
640
641         mono_arch_flush_icache (buf, code - buf);
642         MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL));
643         g_assert (code - buf <= tramp_size);
644
645         *info = mono_tramp_info_create ("handler_block_trampoline", buf, code - buf, ji, unwind_ops);
646
647         return buf;
648 }
649
650 /*========================= End of Function ========================*/