Merge pull request #820 from brendanzagaeski/master
[mono.git] / mono / mini / mini-s390x.c
index 43677fc3ec9af85edfff546a6ef25c921c73a99e..5374adc8b029f1c637417f777d1560339a3186e2 100644 (file)
@@ -263,6 +263,7 @@ if (ins->inst_target_bb->native_offset) {                                   \
 #include <mono/metadata/profiler-private.h>
 #include <mono/utils/mono-math.h>
 #include <mono/utils/mono-mmap.h>
+#include <mono/utils/mono-hwcap-s390x.h>
 
 #include "mini-s390x.h"
 #include "cpu-s390x.h"
@@ -364,14 +365,12 @@ static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
 static void decodeParm (MonoType *, void *, int);
 static void enter_method (MonoMethod *, RegParm *, char *);
 static void leave_method (MonoMethod *, ...);
-static gboolean is_regsize_var (MonoType *);
 static inline void add_general (guint *, size_data *, ArgInfo *);
 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
 static inline void add_float (guint *, size_data *, ArgInfo *);
 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *);
 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
-static void catch_SIGILL(int, siginfo_t *, void *);
 static __inline__ void emit_unwind_regs(MonoCompile *, guint8 *, int, int, long);
 
 /*========================= End of Prototypes ======================*/
@@ -384,8 +383,6 @@ int mono_exc_esp_offset = 0;
 
 static int indent_level = 0;
 
-int has_ld = 0;
-
 static gint appdomain_tls_offset = -1,
            lmf_tls_offset = -1,
            lmf_addr_tls_offset = -1;
@@ -417,11 +414,6 @@ static gpointer bp_trigger_page;
 
 breakpoint_t breakpointCode;
 
-/* 
- * This mutex protects architecture specific caches 
- */
-static CRITICAL_SECTION mini_arch_mutex;
-
 /*====================== End of Global Variables ===================*/
 
 /*------------------------------------------------------------------*/
@@ -1235,30 +1227,12 @@ handle_enum:
                        mono_method_signature (method)->ret->type);
        }
 
-       ip = ((gint64) __builtin_return_address (0));
+       ip = ((gint64) __builtin_extract_return_addr (__builtin_return_address (0)));
        printf (" ip: %p\n", (gpointer) ip);
 }
 
 /*========================= End of Function ========================*/
 
-/*------------------------------------------------------------------*/
-/*                                                                  */
-/* Name                - catch_SIGILL                                      */
-/*                                                                  */
-/* Function    - Catch SIGILL as a result of testing for long      */
-/*               displacement facility.                            */
-/*                                                                 */
-/*------------------------------------------------------------------*/
-
-void
-catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
-
-       has_ld = 0;
-
-}
-
-/*========================= End of Function ========================*/
-
 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Name                - mono_arch_cpu_init                                */
@@ -1271,35 +1245,6 @@ catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
 void
 mono_arch_cpu_init (void)
 {
-       struct sigaction sa,
-                        *oldSa = NULL;
-       guint mode = 1;
-
-       /*--------------------------------------*/      
-       /* Set default rounding mode for FP     */
-       /*--------------------------------------*/      
-       __asm__ ("SRNM\t%0\n\t"
-               : : "m" (mode));
-
-       /*--------------------------------------*/      
-       /* Determine if we have long displace-  */
-       /* ment facility on this processor      */
-       /*--------------------------------------*/      
-       sa.sa_sigaction = catch_SIGILL;
-       sigemptyset (&sa.sa_mask);
-       sa.sa_flags = SA_SIGINFO;
-
-       sigaction (SIGILL, &sa, oldSa);
-
-       /*--------------------------------------*/
-       /* We test by executing the STY inst    */
-       /*--------------------------------------*/
-       __asm__ ("LGHI\t0,1\n\t"
-                "LA\t1,%0\n\t"
-                ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
-               : "=m" (has_ld) : : "0", "1");
-
-       sigaction (SIGILL, oldSa, NULL);
 }
 
 /*========================= End of Function ========================*/
@@ -1377,8 +1322,7 @@ mono_arch_cpu_optimizations (guint32 *exclude_mask)
        /*----------------------------------------------------------*/
        /* No s390-specific optimizations yet                       */
        /*----------------------------------------------------------*/
-       *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
-//     *exclude_mask = MONO_OPT_INLINE;
+       *exclude_mask = MONO_OPT_LINEARS;
        return opts;
 }
 
@@ -1399,44 +1343,6 @@ mono_arch_cpu_enumerate_simd_versions (void)
 }
 /*========================= End of Function ========================*/
 
-/*------------------------------------------------------------------*/
-/*                                                                  */
-/* Name                -                                                   */
-/*                                                                  */
-/* Function    -                                                   */
-/*                                                                 */
-/*------------------------------------------------------------------*/
-
-static gboolean
-is_regsize_var (MonoType *t) {
-       if (t->byref)
-               return TRUE;
-       switch (mono_type_get_underlying_type (t)->type) {
-       case MONO_TYPE_I4:
-       case MONO_TYPE_U4:
-       case MONO_TYPE_I:
-       case MONO_TYPE_I8:
-       case MONO_TYPE_U8:
-       case MONO_TYPE_U:
-       case MONO_TYPE_PTR:
-       case MONO_TYPE_FNPTR:
-               return TRUE;
-       case MONO_TYPE_OBJECT:
-       case MONO_TYPE_STRING:
-       case MONO_TYPE_CLASS:
-       case MONO_TYPE_SZARRAY:
-       case MONO_TYPE_ARRAY:
-               return FALSE;
-       case MONO_TYPE_VALUETYPE:
-               if (t->data.klass->enumtype)
-                       return is_regsize_var (mono_class_enum_basetype (t->data.klass));
-               return FALSE;
-       }
-       return FALSE;
-}
-
-/*========================= End of Function ========================*/
-
 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Name                - mono_arch_get_allocatable_int_vars                */
@@ -1464,7 +1370,7 @@ mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
                        continue;
 
                /* we can only allocate 32 bit values */
-               if (is_regsize_var (ins->inst_vtype)) {
+               if (mono_is_regsize_var(ins->inst_vtype)) {
                        g_assert (MONO_VARINFO (cfg, i)->reg == -1);
                        g_assert (i == vmv->idx);
                        vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
@@ -1874,7 +1780,11 @@ enum_retvalue:
                        MonoMarshalType *info;
                        MonoClass *klass = mono_class_from_mono_type (ptype);
 
-                       size = mini_type_stack_size_full(gsctx, &klass->byval_arg, NULL, sig->pinvoke);
+                       if (sig->pinvoke)
+                               size = mono_class_native_size(klass, NULL);
+                       else
+                               size = mono_class_value_size(klass, NULL);
+
                        if (simpleType != MONO_TYPE_GENERICINST) {
                                info = mono_marshal_load_type_info(klass);
 
@@ -2050,7 +1960,7 @@ mono_arch_allocate_vars (MonoCompile *cfg)
        cinfo   = get_call_info (cfg, cfg->mempool, sig);
 
        if (!cinfo->struct_ret) {
-               switch (mono_type_get_underlying_type (sig->ret)->type) {
+               switch (mini_type_get_underlying_type (cfg->generic_sharing_context, sig->ret)->type) {
                case MONO_TYPE_VOID:
                        break;
                default:
@@ -2423,7 +2333,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
                        t = sig->params [i - sig->hasthis];
                else
                        t = &mono_defaults.int_class->byval_arg;
-               t = mono_type_get_underlying_type (t);
+               t = mini_type_get_underlying_type (cfg->generic_sharing_context, t);
 
                in = call->args [i];
 
@@ -2639,7 +2549,8 @@ mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
 void
 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
 {
-       MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
+       MonoType *ret = mini_type_get_underlying_type (cfg->generic_sharing_context,
+                               mono_method_signature (method)->ret);
 
        if (!ret->byref) {
                if (ret->type == MONO_TYPE_R4) {
@@ -2697,7 +2608,7 @@ mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
        if (cfg->method->save_lmf)
                parmOffset -= sizeof(MonoLMF);
        fpOffset   = parmOffset + (5*sizeof(gpointer));
-       if ((!has_ld) && (fpOffset > 4096)) {
+       if ((!mono_hwcap_s390x_has_ld) && (fpOffset > 4096)) {
                s390_lgr (code, s390_r12, STK_BASE);
                baseReg = s390_r12;
                while (fpOffset > 4096) {
@@ -2710,7 +2621,7 @@ mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
        }       
 
        s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
-       if (has_ld) {
+       if (mono_hwcap_s390x_has_ld) {
                s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
                s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
                s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
@@ -2726,7 +2637,7 @@ mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
        s390_llong(code, cfg->method);
        s390_llong(code, func);
        s390_lg   (code, s390_r2, 0, s390_r13, 4);
-       if (has_ld)
+       if (mono_hwcap_s390x_has_ld)
                s390_lay  (code, s390_r3, 0, STK_BASE, parmOffset);
        else
                s390_la   (code, s390_r3, 0, baseReg, parmOffset);
@@ -2734,7 +2645,7 @@ mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
        s390_aghi (code, s390_r4, cfg->stack_usage);
        s390_lg   (code, s390_r1, 0, s390_r13, 12);
        s390_basr (code, s390_r14, s390_r1);
-       if (has_ld) {
+       if (mono_hwcap_s390x_has_ld) {
                s390_ldy  (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
                s390_ldy  (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
                s390_ldy  (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
@@ -2769,7 +2680,8 @@ mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolea
                   saveOffset,
                   offset;
        MonoMethod *method = cfg->method;
-       int        rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
+       int rtype = mini_type_get_underlying_type (cfg->generic_sharing_context,
+                       mono_method_signature (method)->ret)->type;
 
        offset = code - cfg->native_code;
        /*-----------------------------------------*/
@@ -4177,7 +4089,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        /* ensure ins->sreg1 is not NULL */
                        s390_lg   (code, s390_r0, 0, ins->sreg1, 0);
                        s390_ltgr (code, s390_r0, s390_r0);
-                       EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
+//                     EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
                }
                        break;
                case OP_ARGLIST: {
@@ -5802,31 +5714,6 @@ mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
 
 /*========================= End of Function ========================*/
 
-/*------------------------------------------------------------------*/
-/*                                                                  */
-/* Name                - mono_arch_get_domain_intrinsic                    */
-/*                                                                  */
-/* Function    -                                                   */
-/*                                                                 */
-/* Returns     -                                                   */
-/*                                                                  */
-/*------------------------------------------------------------------*/
-
-MonoInst * 
-mono_arch_get_domain_intrinsic (MonoCompile* cfg)
-{
-       MonoInst *ins;
-
-       if (appdomain_tls_offset == -1)
-               return NULL;
-       
-       MONO_INST_NEW (cfg, ins, OP_TLS_GET);
-       ins->inst_offset = appdomain_tls_offset;
-       return (ins);
-}
-
-/*========================= End of Function ========================*/
-
 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Name                - mono_arch_flush_register_windows                  */
@@ -5999,13 +5886,16 @@ mono_arch_get_delegate_invoke_impls (void)
        guint8 *code;
        guint32 code_len;
        int i;
+       char *tramp_name;
 
        code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
-       res = g_slist_prepend (res, mono_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len, NULL, NULL));
+       res = g_slist_prepend (res, mono_tramp_info_create ("delegate_invoke_impl_has_target", code, code_len, NULL, NULL));
 
        for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
                code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
-               res = g_slist_prepend (res, mono_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len, NULL, NULL));
+               tramp_name = g_strdup_printf ("delegate_invoke_impl_target_%d", i);
+               res = g_slist_prepend (res, mono_tramp_info_create (tramp_name, code, code_len, NULL, NULL));
+               g_free (tramp_name);
        }
 
        return res;
@@ -6469,6 +6359,23 @@ mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
        return NULL;
 }
 
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name                - mono_arch_init_lmf_ext.                               */
+/*                                                                  */
+/* Function -                                                       */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+
+void
+mono_arch_init_lmf_ext (MonoLMFExt *ext, gpointer prev_lmf)
+{
+       ext->lmf.previous_lmf = prev_lmf;
+       /* Mark that this is a MonoLMFExt */
+       ext->lmf.previous_lmf = (gpointer)(((gssize)ext->lmf.previous_lmf) | 2);
+       ext->lmf.ebp = (gssize)ext;
+}
+
 /*========================= End of Function ========================*/
 
 #endif