2007-10-07 Andreia Gaita <avidigal@novell.com>
[mono.git] / mono / mini / tramp-s390.c
index 47453ea4413a0a099689e00b2fd120a8de97cb1b..59f1403513262bce43ba8739c3cfce5bfebe7f76 100644 (file)
 
 #define GR_SAVE_SIZE           4*sizeof(long)
 #define FP_SAVE_SIZE           16*sizeof(double)
-#define CREATE_GR_OFFSET       S390_MINIMAL_STACK_SIZE
+#define METHOD_SAVE_OFFSET     S390_MINIMAL_STACK_SIZE
+#define CREATE_GR_OFFSET       METHOD_SAVE_OFFSET+sizeof(gpointer)
 #define CREATE_FP_OFFSET       CREATE_GR_OFFSET+GR_SAVE_SIZE
 #define CREATE_LMF_OFFSET      CREATE_FP_OFFSET+FP_SAVE_SIZE
 #define CREATE_STACK_SIZE      (CREATE_LMF_OFFSET+2*sizeof(long)+sizeof(MonoLMF))
-#define METHOD_SAVE_OFFSET     S390_RET_ADDR_OFFSET-4
 
 /*------------------------------------------------------------------*/
 /* Method-specific trampoline code fragment sizes                  */
@@ -48,7 +48,6 @@
 #include <mono/metadata/marshal.h>
 #include <mono/metadata/tabledefs.h>
 #include <mono/arch/s390/s390-codegen.h>
-#include <mono/metadata/mono-debug-debugger.h>
 
 #include "mini.h"
 #include "mini-s390.h"
@@ -148,7 +147,6 @@ s390_magic_trampoline (MonoMethod *method, guchar *code, char *sp)
        int reg;
        guchar* base;
        unsigned short opcode;
-       char *fname;
        MonoJitInfo *codeJi, 
                    *addrJi;
 
@@ -161,45 +159,45 @@ s390_magic_trampoline (MonoMethod *method, guchar *code, char *sp)
                /* The top bit needs to be ignored on S/390 */
                code = (guchar*)((guint32)code & 0x7fffffff);
 
-               fname  = mono_method_full_name (method, TRUE);
                codeJi = mono_jit_info_table_find (mono_domain_get(), code);
                addrJi = mono_jit_info_table_find (mono_domain_get(), addr);
                if (mono_method_same_domain (codeJi, addrJi)) {
 
                        opcode = *((unsigned short *) (code - 6));
                        switch (opcode) {
-                               case 0x5810 :
-                                       /* This is a bras r14,r1 instruction */
-                                       code    -= 4;
-                                       reg      = *code >> 4;
-                                       displace = *((short *)code) & 0x0fff;
-                                       if (reg > 5) 
-                                               base = *((guchar **) (sp + S390_REG_SAVE_OFFSET+
-                                                                      sizeof(int)*(reg-6)));
-                                       else
-                                               base = *((guchar **) (sp + CREATE_GR_OFFSET+
-                                                                      sizeof(int)*(reg-2)));
-
-                                       if ((method->klass->valuetype) && 
-                                           (!mono_aot_is_got_entry(code, base))) 
-                                               addr = get_unbox_trampoline(method, addr);
-
-                                       code = base + displace;
-                                       if (mono_domain_owns_vtable_slot(mono_domain_get(), 
-                                                                        code))
-                                               s390_patch(code, addr);
-                                       break;
-                               case 0xc0e5 :
-                                       /* This is the 'brasl' instruction */
-                                       code    -= 4;
-                                       displace = ((gint32) addr - (gint32) (code - 2)) / 2;
-                                       if (mono_method_same_domain (codeJi, addrJi)) {
-                                               s390_patch (code, displace);
-                                               mono_arch_flush_icache (code, 4);
-                                       }
-                                       break;
-                               default :
-                                       g_error("Unable to patch instruction prior to %p",code);
+                       case 0x5810 :
+                               /* This is a bras r14,r1 instruction */
+                               code    -= 4;
+                               reg      = *code >> 4;
+                               displace = *((short *)code) & 0x0fff;
+                               if (reg > 5) 
+                                       base = *((guchar **) (sp + S390_REG_SAVE_OFFSET+
+                                                              sizeof(int)*(reg-6)));
+                               else
+                                       base = *((guchar **) ((sp - CREATE_STACK_SIZE) + 
+                                                              CREATE_GR_OFFSET +
+                                                              sizeof(int)*(reg-2)));
+
+                               if ((method->klass->valuetype) && 
+                                   (!mono_aot_is_got_entry(code, base))) 
+                                       addr = get_unbox_trampoline(method, addr);
+
+                               code = base + displace;
+                               if (mono_domain_owns_vtable_slot(mono_domain_get(), 
+                                                                code))
+                                       s390_patch(code, (guint32) addr);
+                               break;
+                       case 0xc0e5 :
+                               /* This is the 'brasl' instruction */
+                               code    -= 4;
+                               displace = ((gint32) addr - (gint32) (code - 2)) / 2;
+                               if (mono_method_same_domain (codeJi, addrJi)) {
+                                       s390_patch (code, displace);
+                                       mono_arch_flush_icache (code, 4);
+                               }
+                               break;
+                       default :
+                               g_error("Unable to patch instruction prior to %p",code);
                        }
                }
        }
@@ -264,6 +262,7 @@ mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
                s390_lr   (buf, s390_r11, s390_r15);
                s390_ahi  (buf, STK_BASE, -CREATE_STACK_SIZE);
                s390_st   (buf, s390_r11, 0, STK_BASE, 0);
+               s390_st   (buf, s390_r1, 0, STK_BASE, METHOD_SAVE_OFFSET);
                s390_stm  (buf, s390_r2, s390_r5, STK_BASE, CREATE_GR_OFFSET);
 
                /* Save the FP registers */
@@ -320,7 +319,7 @@ mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
                /*---------------------------------------------------------------*/     
                /* save method info                                              */     
                /*---------------------------------------------------------------*/     
-               s390_l     (buf, s390_r1, 0, s390_r11, METHOD_SAVE_OFFSET);
+               s390_l     (buf, s390_r1, 0, STK_BASE, METHOD_SAVE_OFFSET);
                s390_st    (buf, s390_r1, 0, s390_r13,                          
                            G_STRUCT_OFFSET(MonoLMF, method));                          
                                                                        
@@ -358,10 +357,10 @@ mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
                                
                /* Set arguments */
                
-               /* Arg 1: MonoMethod *method. It was put in r11 by the
+               /* Arg 1: MonoMethod *method. It was put in r1 by the
                method-specific trampoline code, and then saved before the call
-               to mono_get_lmf_addr()'. Restore r13, by the way :-) */
-               s390_l  (buf, s390_r2, 0, s390_r11, METHOD_SAVE_OFFSET);
+               to mono_get_lmf_addr()'. */
+               s390_l  (buf, s390_r2, 0, STK_BASE, METHOD_SAVE_OFFSET);
                
                /* Arg 2: code (next address to the instruction that called us) */
                if (tramp_type == MONO_TRAMPOLINE_JUMP) {
@@ -372,6 +371,7 @@ mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
                
                /* Arg 3: stack pointer */
                s390_lr   (buf, s390_r4, STK_BASE);
+               s390_ahi  (buf, s390_r4, CREATE_STACK_SIZE);
                
                /* Calculate call address and call
                's390_magic_trampoline'. Return value will be in r2 */
@@ -450,10 +450,10 @@ mono_arch_create_jump_trampoline (MonoMethod *method)
        code = buf = mono_code_manager_reserve (domain->code_mp, METHOD_TRAMPOLINE_SIZE);
        mono_domain_unlock (domain);
 
-       s390_basr (buf, s390_r13, 0);
+       s390_basr (buf, s390_r1, 0);
        s390_j    (buf, 4);
        s390_word (buf, method);
-       s390_l    (buf, s390_r13, 0, s390_r13, 4);
+       s390_l    (buf, s390_r1, 0, s390_r1, 4);
        displace = (tramp - buf) / 2;
        s390_jcl  (buf, S390_CC_UN, displace);
 
@@ -510,17 +510,17 @@ mono_arch_create_jit_trampoline (MonoMethod *method)
 
        vc = mono_get_trampoline_code (MONO_TRAMPOLINE_GENERIC);
 
-       /* This is the method-specific part of the trampoline. Its purpose is
-       to provide the generic part with the MonoMethod *method pointer. We'll
-       use r13 to keep that value, for instance. However, the generic part of
-       the trampoline relies on r11 having the same value it had before coming
-       here, so we must save it before. */
+       /*----------------------------------------------------------*/
+       /* This is the method-specific part of the trampoline. Its  */
+       /* purpose is to provide the generic part with the          */
+       /* MonoMethod *method pointer. We'll use r1 to keep it.     */
+       /*----------------------------------------------------------*/
        code = buf = mono_global_codeman_reserve(METHOD_TRAMPOLINE_SIZE);
 
-       s390_basr (buf, s390_r13, 0);
+       s390_basr (buf, s390_r1, 0);
        s390_j    (buf, 4);
        s390_word (buf, method);
-       s390_l    (buf, s390_r13, 0, s390_r13, 4);
+       s390_l    (buf, s390_r1, 0, s390_r1, 4);
        displace = (vc - buf) / 2;
        s390_jcl  (buf, S390_CC_UN, displace);
 
@@ -609,14 +609,12 @@ mono_arch_create_class_init_trampoline (MonoVTable *vtable)
 /*------------------------------------------------------------------*/
 
 gpointer
-mono_debugger_create_notification_function (gpointer *notification_address)
+mono_debugger_create_notification_function (void)
 {
        guint8 *ptr, *buf;
 
        ptr = buf = mono_global_codeman_reserve (16);
        s390_break (buf);
-       if (notification_address)
-               *notification_address = buf;
        s390_br (buf, s390_r14);
 
        return ptr;