merge -r 60814:60815
[mono.git] / mono / mini / tramp-s390x.c
1 /*------------------------------------------------------------------*/
2 /*                                                                  */
3 /* Name        - tramp-s390.c                                       */
4 /*                                                                  */
5 /* Function    - JIT trampoline code for S/390.                     */
6 /*                                                                  */
7 /* Name        - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
8 /*                                                                  */
9 /* Date        - January, 2004                                      */
10 /*                                                                  */
11 /* Derivation  - From exceptions-x86 & exceptions-ppc               */
12 /*               Paolo Molaro (lupus@ximian.com)                    */
13 /*               Dietmar Maurer (dietmar@ximian.com)                */
14 /*                                                                  */
15 /* Copyright   - 2001 Ximian, Inc.                                  */
16 /*                                                                  */
17 /*------------------------------------------------------------------*/
18
19 /*------------------------------------------------------------------*/
20 /*                 D e f i n e s                                    */
21 /*------------------------------------------------------------------*/
22
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
31 /*------------------------------------------------------------------*/
32 /* Method-specific trampoline code fragment sizes                   */
33 /*------------------------------------------------------------------*/
34 #define METHOD_TRAMPOLINE_SIZE  96
35 #define JUMP_TRAMPOLINE_SIZE    96
36
37 /*========================= End of Defines =========================*/
38
39 /*------------------------------------------------------------------*/
40 /*                 I n c l u d e s                                  */
41 /*------------------------------------------------------------------*/
42
43 #include <config.h>
44 #include <glib.h>
45 #include <string.h>
46
47 #include <mono/metadata/appdomain.h>
48 #include <mono/metadata/marshal.h>
49 #include <mono/metadata/tabledefs.h>
50 #include <mono/arch/s390x/s390x-codegen.h>
51
52 #include "mini.h"
53 #include "mini-s390x.h"
54
55 /*========================= End of Includes ========================*/
56
57 /*------------------------------------------------------------------*/
58 /*                 T y p e d e f s                                  */
59 /*------------------------------------------------------------------*/
60
61 /*========================= End of Typedefs ========================*/
62
63 /*------------------------------------------------------------------*/
64 /*                   P r o t o t y p e s                            */
65 /*------------------------------------------------------------------*/
66
67 /*========================= End of Prototypes ======================*/
68
69 /*------------------------------------------------------------------*/
70 /*                 G l o b a l   V a r i a b l e s                  */
71 /*------------------------------------------------------------------*/
72
73
74 /*====================== End of Global Variables ===================*/
75
76 /*------------------------------------------------------------------*/
77 /*                                                                  */
78 /* Name         - get_unbox_trampoline                              */
79 /*                                                                  */
80 /* Function     - Return a pointer to a trampoline which does the   */
81 /*                unboxing before calling the method.               */
82 /*                                                                  */
83 /*                When value type methods are called through the    */
84 /*                vtable we need to unbox the 'this' argument.      */
85 /*                                                                  */
86 /* Parameters   - method - Methd pointer                            */
87 /*                addr   - Pointer to native code for method        */
88 /*                                                                  */
89 /*------------------------------------------------------------------*/
90
91 static gpointer
92 get_unbox_trampoline (MonoMethod *method, gpointer addr)
93 {
94         guint8 *code, *start;
95         int this_pos = s390_r2;
96
97         start = addr;
98         if ((!mono_method_signature (method)->ret->byref) && 
99             (MONO_TYPE_ISSTRUCT (mono_method_signature (method)->ret)))
100                 this_pos = s390_r3;
101     
102         start = code = mono_global_codeman_reserve (28);
103
104         s390_basr (code, s390_r1, 0);
105         s390_j    (code, 6);
106         s390_llong(code, addr);
107         s390_lg   (code, s390_r1, 0, s390_r1, 4);
108         s390_aghi (code, this_pos, sizeof(MonoObject));
109         s390_br   (code, s390_r1);
110
111         g_assert ((code - start) <= 28);
112
113         return start;
114 }
115
116 /*========================= End of Function ========================*/
117
118 /*------------------------------------------------------------------*/
119 /*                                                                  */
120 /* Name         - s390_magic_trampoline                             */
121 /*                                                                  */
122 /* Function     - This method is called by the function             */
123 /*                "arch_create_jit_trampoline", which in turn is    */
124 /*                called by the trampoline functions for virtual    */
125 /*                methods. After having called the JIT compiler to  */
126 /*                compile the method, it inspects the caller code   */
127 /*                to find the address of the method-specific part   */
128 /*                of the trampoline vtable slot for this method,    */
129 /*                updates it with a fragment that calls the newly   */
130 /*                compiled code and returns this address. The calls */
131 /*                generated by mono for S/390 will look like either:*/
132 /*                1. l     %r1,xxx(%rx)                             */
133 /*                   bras  %r14,%r1                                 */
134 /*                2. brasl %r14,xxxxxx                              */
135 /*                                                                  */
136 /* Parameters   - code   - Pointer into caller code                 */
137 /*                method - The method to compile                    */
138 /*                sp     - Stack pointer                            */
139 /*                                                                  */
140 /*------------------------------------------------------------------*/
141
142 static gpointer
143 s390_magic_trampoline (MonoMethod *method, guchar *code, char *sp)
144 {
145         gpointer addr;
146         gint64 displace;
147         guchar reg, lkReg;
148         guchar *base;
149         unsigned short opcode;
150         MonoJitInfo *codeJi, 
151                     *addrJi;
152
153         addr = mono_compile_method(method);
154         g_assert(addr);
155
156         if (code) {
157
158                 codeJi = mono_jit_info_table_find (mono_domain_get(), code);
159                 addrJi = mono_jit_info_table_find (mono_domain_get(), addr);
160                 if (mono_method_same_domain (codeJi, addrJi)) {
161
162                         opcode = *((unsigned short *) (code - 6));
163                         if (opcode == 0xc0e5) {
164                                 /* This is the 'brasl' instruction */
165                                 code    -= 4;
166                                 displace = ((gint64) addr - (gint64) (code - 2)) / 2;
167                                 if (mono_method_same_domain (codeJi, addrJi)) {
168                                         s390_patch_rel (code, displace);
169                                         mono_arch_flush_icache (code, 4);
170                                 }
171                         } else {
172                                 /*-----------------------------------*/
173                                 /* This is a bras r14,Rz instruction */
174                                 /* If it's preceded by a LG Rx,d(Ry) */
175                                 /* If Rz == 1 then we check if unbox-*/
176                                 /* is required. We patch the address */
177                                 /* by determining the location desc- */
178                                 /* cribed by *Ry+d.                  */ 
179                                 /*-----------------------------------*/
180                                 code    -= 6;
181
182                                 /*-----------------------------------*/
183                                 /* If call is preceded by LGR then   */
184                                 /* there's nothing to patch          */
185                                 /*-----------------------------------*/
186                                 if ((code[0] == 0xb9) &&
187                                     (code[1] == 0x04))
188                                         return addr;
189
190                                 /*-----------------------------------*/
191                                 /* We back up until we're pointing at*/
192                                 /* the base/displacement portion of  */
193                                 /* the LG instruction                */
194                                 /*-----------------------------------*/
195                                 lkReg    = code[5] & 0x0f;
196
197                                 /*-----------------------------------*/
198                                 /* The LG instruction has format:    */
199                                 /* E3x0ylllhh04 - where:             */
200                                 /* x = Rx; y = Ry;                   */
201                                 /* lll = low 12 bits of displacement */
202                                 /* hh  = high 8 bits of displacement */
203                                 /*-----------------------------------*/
204                                 reg      = code[0] >> 4;
205                                 displace = (code[2] << 12) +
206                                            ((code[0] & 0x0f) << 8) + 
207                                            code[1];
208
209                                 if (reg > 5) 
210                                         base = *((guchar **) (sp + S390_REG_SAVE_OFFSET +
211                                                                sizeof(long)*(reg-6)));
212                                 else
213                                         base = *((guchar **) ((sp - CREATE_STACK_SIZE) + 
214                                                                CREATE_GR_OFFSET +
215                                                                sizeof(long)*(reg-2)));
216
217                                 /* Calls that need unboxing use R1 */
218                                 if (lkReg == 1)  {
219                                         if ((method->klass->valuetype) && 
220                                             (!mono_aot_is_got_entry(code, base)))
221                                                 addr = get_unbox_trampoline(method, addr);
222
223                                         code = base + displace;
224                                         if (mono_domain_owns_vtable_slot(mono_domain_get(), 
225                                                                          code))
226                                                 s390_patch_addr(code, addr);
227                                 } else {
228                                         code = base + displace;
229                                         s390_patch_addr(code, addr);
230                                 }
231                         }
232                 }
233         }
234
235         return addr;
236 }
237
238 /*========================= End of Function ========================*/
239
240 /*------------------------------------------------------------------*/
241 /*                                                                  */
242 /* Name         - s390_class_init_trampoline                        */
243 /*                                                                  */
244 /* Function     - Initialize a class and then no-op the call to     */
245 /*                the trampoline.                                   */
246 /*                                                                  */
247 /*------------------------------------------------------------------*/
248
249 static void
250 s390_class_init_trampoline (void *vtable, guchar *code, char *sp)
251 {
252         char patch[2] = {0x07, 0x00};
253
254         mono_runtime_class_init (vtable);
255
256         code = code - 2;
257
258         memcpy(code, patch, sizeof(patch));
259 }
260
261 /*========================= End of Function ========================*/
262
263 /*------------------------------------------------------------------*/
264 /*                                                                  */
265 /* Name         - mono_arch_create_trampoline_code                            */
266 /*                                                                  */
267 /* Function     - Create the designated type of trampoline according*/
268 /*                to the 'tramp_type' parameter.                    */
269 /*                                                                  */
270 /*------------------------------------------------------------------*/
271
272 guchar *
273 mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
274 {
275
276         guint8 *buf, *code = NULL;
277         int i, offset, lmfOffset;
278
279         if(!code) {
280                 /* Now we'll create in 'buf' the S/390 trampoline code. This
281                  is the trampoline code common to all methods  */
282                 
283                 code = buf = mono_global_codeman_reserve(512);
284                 
285                 /*-----------------------------------------------------------
286                 STEP 0: First create a non-standard function prologue with a
287                 stack size big enough to save our registers.
288                 -----------------------------------------------------------*/
289                 
290                 s390_stmg (buf, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
291                 s390_lgr  (buf, s390_r11, s390_r15);
292                 s390_aghi (buf, STK_BASE, -CREATE_STACK_SIZE);
293                 s390_stg  (buf, s390_r11, 0, STK_BASE, 0);
294                 s390_stg  (buf, s390_r1, 0, STK_BASE, METHOD_SAVE_OFFSET);
295                 s390_stmg (buf, s390_r2, s390_r5, STK_BASE, CREATE_GR_OFFSET);
296
297                 /* Save the FP registers */
298                 offset = CREATE_FP_OFFSET;
299                 for (i = s390_f0; i <= s390_f15; ++i) {
300                         s390_std  (buf, i, 0, STK_BASE, offset);
301                         offset += 8;
302                 }
303
304                 /*----------------------------------------------------------
305                 STEP 1: call 'mono_get_lmf_addr()' to get the address of our
306                 LMF. We'll need to restore it after the call to
307                 's390_magic_trampoline' and before the call to the native
308                 method.
309                 ----------------------------------------------------------*/
310                                 
311                 s390_basr (buf, s390_r13, 0);
312                 s390_j    (buf, 6);
313                 s390_llong(buf, mono_get_lmf_addr);
314                 s390_lg   (buf, s390_r1, 0, s390_r13, 4);
315                 s390_basr (buf, s390_r14, s390_r1);
316
317                 /*---------------------------------------------------------------*/
318                 /* we build the MonoLMF structure on the stack - see mini-s390.h */
319                 /* Keep in sync with the code in mono_arch_emit_prolog           */
320                 /*---------------------------------------------------------------*/
321                 lmfOffset = CREATE_STACK_SIZE - sizeof(MonoLMF);
322                                                                                         
323                 s390_lgr   (buf, s390_r13, STK_BASE);
324                 s390_aghi  (buf, s390_r13, lmfOffset);  
325                                                                                         
326                 /*---------------------------------------------------------------*/     
327                 /* Set lmf.lmf_addr = jit_tls->lmf                               */     
328                 /*---------------------------------------------------------------*/     
329                 s390_stg   (buf, s390_r2, 0, s390_r13,                          
330                             G_STRUCT_OFFSET(MonoLMF, lmf_addr));                        
331                                                                                         
332                 /*---------------------------------------------------------------*/     
333                 /* Get current lmf                                               */     
334                 /*---------------------------------------------------------------*/     
335                 s390_lg    (buf, s390_r0, 0, s390_r2, 0);                               
336                                                                                         
337                 /*---------------------------------------------------------------*/     
338                 /* Set our lmf as the current lmf                                */     
339                 /*---------------------------------------------------------------*/     
340                 s390_stg   (buf, s390_r13, 0, s390_r2, 0);                              
341                                                                                         
342                 /*---------------------------------------------------------------*/     
343                 /* Have our lmf.previous_lmf point to the last lmf               */     
344                 /*---------------------------------------------------------------*/     
345                 s390_stg   (buf, s390_r0, 0, s390_r13,                          
346                             G_STRUCT_OFFSET(MonoLMF, previous_lmf));                    
347                                                                                         
348                 /*---------------------------------------------------------------*/     
349                 /* save method info                                              */     
350                 /*---------------------------------------------------------------*/     
351                 s390_lg    (buf, s390_r1, 0, STK_BASE, METHOD_SAVE_OFFSET);
352                 s390_stg   (buf, s390_r1, 0, s390_r13,                          
353                             G_STRUCT_OFFSET(MonoLMF, method));                          
354                                                                         
355                 /*---------------------------------------------------------------*/     
356                 /* save the current SP                                           */     
357                 /*---------------------------------------------------------------*/     
358                 s390_lg    (buf, s390_r1, 0, STK_BASE, 0);
359                 s390_stg   (buf, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));  
360                                                                         
361                 /*---------------------------------------------------------------*/     
362                 /* save the current IP                                           */     
363                 /*---------------------------------------------------------------*/     
364                 if (tramp_type == MONO_TRAMPOLINE_JUMP) {
365                         s390_lghi  (buf, s390_r1, 0);
366                 } else {
367                         s390_lg    (buf, s390_r1, 0, s390_r1, S390_RET_ADDR_OFFSET);
368 //                      s390_la    (buf, s390_r1, 0, s390_r1, 0);
369                 }
370                 s390_stg   (buf, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));  
371                                                                                         
372                 /*---------------------------------------------------------------*/     
373                 /* Save general and floating point registers                     */     
374                 /*---------------------------------------------------------------*/     
375                 s390_stmg  (buf, s390_r2, s390_r12, s390_r13,                           
376                             G_STRUCT_OFFSET(MonoLMF, gregs[2]));                        
377                 for (i = 0; i < 16; i++) {                                              
378                         s390_std  (buf, i, 0, s390_r13,                                 
379                                    G_STRUCT_OFFSET(MonoLMF, fregs[i]));                 
380                 }                                                                       
381
382                 /*---------------------------------------------------------------*/
383                 /* STEP 2: call 's390_magic_trampoline()', who will compile the  */
384                 /* code and fix the method vtable entry for us                   */
385                 /*---------------------------------------------------------------*/
386                                 
387                 /* Set arguments */
388                 
389                 /* Arg 1: MonoMethod *method. It was put in r1 by the
390                 method-specific trampoline code, and then saved before the call
391                 to mono_get_lmf_addr()'. */
392                 s390_lg (buf, s390_r2, 0, STK_BASE, METHOD_SAVE_OFFSET);
393                 
394                 /* Arg 2: code (next address to the instruction that called us) */
395                 if (tramp_type == MONO_TRAMPOLINE_JUMP) {
396                         s390_lghi (buf, s390_r3, 0);
397                 } else {
398                         s390_lg   (buf, s390_r3, 0, s390_r11, S390_RET_ADDR_OFFSET);
399                 }
400                 
401                 /* Arg 3: stack pointer */
402                 s390_lgr  (buf, s390_r4, STK_BASE);
403                 s390_ahi  (buf, s390_r4, CREATE_STACK_SIZE);
404                 
405                 /* Calculate call address and call
406                 's390_magic_trampoline'. Return value will be in r2 */
407                 s390_basr (buf, s390_r13, 0);
408                 s390_j    (buf, 6);
409                 if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT) {
410                         s390_llong(buf, s390_class_init_trampoline);
411                 } else {
412                         s390_llong(buf, s390_magic_trampoline);
413                 }
414                 s390_lg   (buf, s390_r1, 0, s390_r13, 4);
415                 s390_basr (buf, s390_r14, s390_r1);
416                 
417                 /* OK, code address is now on r2. Move it to r1, so that we
418                 can restore r2 and use it from r1 later */
419                 s390_lgr  (buf, s390_r1, s390_r2);
420
421                 /*----------------------------------------------------------
422                 STEP 3: Restore the LMF
423                 ----------------------------------------------------------*/
424                 restoreLMF(buf, STK_BASE, CREATE_STACK_SIZE);
425         
426                 /*----------------------------------------------------------
427                 STEP 4: call the compiled method
428                 ----------------------------------------------------------*/
429                 
430                 /* Restore registers */
431
432                 s390_lmg  (buf, s390_r2, s390_r5, STK_BASE, CREATE_GR_OFFSET);
433                 
434                 /* Restore the FP registers */
435                 offset = CREATE_FP_OFFSET;
436                 for (i = s390_f0; i <= s390_f15; ++i) {
437                         s390_ld  (buf, i, 0, STK_BASE, offset);
438                         offset += 8;
439                 }
440
441                 /* Restore stack pointer and jump to the code - 
442                    R14 contains the return address to our caller */
443                 s390_lgr  (buf, STK_BASE, s390_r11);
444                 s390_lmg  (buf, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
445                 s390_br   (buf, s390_r1);
446
447                 /* Flush instruction cache, since we've generated code */
448                 mono_arch_flush_icache (code, buf - code);
449         
450                 /* Sanity check */
451                 g_assert ((buf - code) <= 512);
452         }
453
454         return code;
455 }
456
457 /*========================= End of Function ========================*/
458
459 /*------------------------------------------------------------------*/
460 /*                                                                  */
461 /* Name         - mono_arch_create_jump_trampoline                  */
462 /*                                                                  */
463 /* Function     - Create the designated type of trampoline according*/
464 /*                to the 'tramp_type' parameter.                    */
465 /*                                                                  */
466 /*------------------------------------------------------------------*/
467
468 MonoJitInfo *
469 mono_arch_create_jump_trampoline (MonoMethod *method)
470 {
471         guint8 *code, *buf, *tramp = NULL;
472         MonoJitInfo *ji;
473         MonoDomain *domain = mono_domain_get();
474         gint32 displace;
475
476         tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_JUMP);
477
478         mono_domain_lock (domain);
479         code = buf = mono_code_manager_reserve (domain->code_mp, JUMP_TRAMPOLINE_SIZE);
480         mono_domain_unlock (domain);
481
482         s390_basr (buf, s390_r1, 0);
483         s390_j    (buf, 6);
484         s390_llong(buf, method);
485         s390_lg   (buf, s390_r1, 0, s390_r1, 4);
486         displace = (tramp - buf) / 2;
487         s390_jcl  (buf, S390_CC_UN, displace);
488
489         mono_arch_flush_icache (code, buf-code);
490
491         g_assert ((buf - code) <= JUMP_TRAMPOLINE_SIZE);
492         
493         ji              = g_new0 (MonoJitInfo, 1);
494         ji->method      = method;
495         ji->code_start  = code;
496         ji->code_size   = buf - code;
497         
498         mono_jit_stats.method_trampolines++;
499
500         return ji;
501 }
502
503 /*========================= End of Function ========================*/
504
505 /*------------------------------------------------------------------*/
506 /*                                                                  */
507 /* Name         - mono_arch_create_jit_trampoline                   */
508 /*                                                                  */
509 /* Function     - Creates a trampoline function for virtual methods.*/
510 /*                If the created code is called it first starts JIT */
511 /*                compilation and then calls the newly created      */
512 /*                method. It also replaces the corresponding vtable */
513 /*                entry (see s390_magic_trampoline).                */
514 /*                                                                  */
515 /*                A trampoline consists of two parts: a main        */
516 /*                fragment, shared by all method trampolines, and   */
517 /*                and some code specific to each method, which      */
518 /*                hard-codes a reference to that method and then    */
519 /*                calls the main fragment.                          */
520 /*                                                                  */
521 /*                The main fragment contains a call to              */
522 /*                's390_magic_trampoline', which performs a call    */
523 /*                to the JIT compiler and substitutes the method-   */
524 /*                specific fragment with some code that directly    */
525 /*                calls the JIT-compiled method.                    */
526 /*                                                                  */
527 /* Parameter    - method - Pointer to the method information        */
528 /*                                                                  */
529 /* Returns      - A pointer to the newly created code               */
530 /*                                                                  */
531 /*------------------------------------------------------------------*/
532
533 gpointer
534 mono_arch_create_jit_trampoline (MonoMethod *method)
535 {
536         guint8 *code, *buf;
537         static guint8 *vc = NULL;
538         gint32 displace;
539
540         vc = mono_get_trampoline_code (MONO_TRAMPOLINE_GENERIC);
541
542         /* This is the method-specific part of the trampoline. Its purpose is
543         to provide the generic part with the MonoMethod *method pointer. We'll
544         use r1 to keep that value, for instance. */
545         code = buf = mono_global_codeman_reserve(METHOD_TRAMPOLINE_SIZE);
546
547         s390_basr (buf, s390_r1, 0);
548         s390_j    (buf, 6);
549         s390_llong(buf, method);
550         s390_lg   (buf, s390_r1, 0, s390_r1, 4);
551         displace = (vc - buf) / 2;
552         s390_jcl  (buf, S390_CC_UN, displace);
553
554         /* Flush instruction cache, since we've generated code */
555         mono_arch_flush_icache (code, buf - code);
556                 
557         /* Sanity check */
558         g_assert ((buf - code) <= METHOD_TRAMPOLINE_SIZE);
559         
560         return code;
561 }
562
563 /*========================= End of Function ========================*/
564
565 /*------------------------------------------------------------------*/
566 /*                                                                  */
567 /* Name         - mono_arch_create_class_init_trampoline            */
568 /*                                                                  */
569 /* Function     - Creates a trampoline function to run a type init- */
570 /*                ializer. If the trampoline is called, it calls    */
571 /*                mono_runtime_class_init with the given vtable,    */
572 /*                then patches the caller code so it does not get   */
573 /*                called any more.                                  */
574 /*                                                                  */
575 /* Parameter    - vtable - The type to initialize                   */
576 /*                                                                  */
577 /* Returns      - A pointer to the newly created code               */
578 /*                                                                  */
579 /*------------------------------------------------------------------*/
580
581 gpointer
582 mono_arch_create_class_init_trampoline (MonoVTable *vtable)
583 {
584         guint8 *code, *buf, *tramp;
585
586         tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_CLASS_INIT);
587
588         /*-----------------------------------------------------------*/
589         /* This is the method-specific part of the trampoline. Its   */
590         /* purpose is to provide the generic part with the MonoMethod*/
591         /* *method pointer.                                          */
592         /*-----------------------------------------------------------*/
593         code = buf = mono_global_codeman_reserve(METHOD_TRAMPOLINE_SIZE);
594
595         s390_stg  (buf, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
596         s390_aghi (buf, STK_BASE, -S390_MINIMAL_STACK_SIZE);
597
598         s390_basr (buf, s390_r1, 0);
599         s390_j    (buf, 10);
600         s390_llong(buf, vtable);
601         s390_llong(buf, s390_class_init_trampoline);
602         s390_lgr  (buf, s390_r3, s390_r14);
603         s390_lg   (buf, s390_r2, 0, s390_r1, 4);
604         s390_lghi (buf, s390_r4, 0);
605         s390_lg   (buf, s390_r1, 0, s390_r1, 12);
606         s390_basr (buf, s390_r14, s390_r1);
607
608         s390_aghi (buf, STK_BASE, S390_MINIMAL_STACK_SIZE);
609         s390_lg   (buf, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
610         s390_br   (buf, s390_r14);
611
612         /* Flush instruction cache, since we've generated code */
613         mono_arch_flush_icache (code, buf - code);
614                 
615         /* Sanity check */
616         g_assert ((buf - code) <= METHOD_TRAMPOLINE_SIZE);
617
618         mono_jit_stats.method_trampolines++;
619
620         return code;
621 }
622
623 /*========================= End of Function ========================*/
624
625 /*------------------------------------------------------------------*/
626 /*                                                                  */
627 /* Name         - mono_debuger_create_notification_function         */
628 /*                                                                  */
629 /* Function     - This method is only called when running in the    */
630 /*                Mono debugger. It returns a pointer to the        */
631 /*                arch specific notification function.              */
632 /*                                                                  */
633 /*------------------------------------------------------------------*/
634
635 gpointer
636 mono_debugger_create_notification_function (gpointer *notification_address)
637 {
638         guint8 *ptr, *buf;
639
640         ptr = buf = mono_global_codeman_reserve (16);
641         s390_break (buf);
642         if (notification_address)
643                 *notification_address = buf;
644         s390_br (buf, s390_r14);
645
646         return ptr;
647 }
648
649 /*========================= End of Function ========================*/