* roottypes.cs: Rename from tree.cs.
[mono.git] / mono / mini / jit-icalls.c
index 9cba59303d03a1290b2aeb4f7c4b510ce0292c84..2458102b3005cbbd2a481653d84bc58c555ca202 100644 (file)
@@ -10,7 +10,9 @@
 
 #include <math.h>
 
-static void*
+#include "jit-icalls.h"
+
+void*
 mono_ldftn (MonoMethod *method)
 {
        gpointer addr;
@@ -19,14 +21,14 @@ mono_ldftn (MonoMethod *method)
 
        addr = mono_create_jump_trampoline (mono_domain_get (), method, TRUE);
 
-       return addr;
+       return mono_create_ftnptr (mono_domain_get (), addr);
 }
 
 /*
  * Same as mono_ldftn, but do not add a synchronized wrapper. Used in the
  * synchronized wrappers to avoid infinite recursion.
  */
-static void*
+void*
 mono_ldftn_nosync (MonoMethod *method)
 {
        gpointer addr;
@@ -35,10 +37,10 @@ mono_ldftn_nosync (MonoMethod *method)
 
        addr = mono_create_jump_trampoline (mono_domain_get (), method, FALSE);
 
-       return addr;
+       return mono_create_ftnptr (mono_domain_get (), addr);
 }
 
-static void*
+void*
 mono_ldvirtfn (MonoObject *obj, MonoMethod *method) 
 {
        MONO_ARCH_SAVE_REGS;
@@ -51,8 +53,8 @@ mono_ldvirtfn (MonoObject *obj, MonoMethod *method)
        return mono_ldftn (method);
 }
 
-static void
-helper_stelem_ref (MonoArray *array, int index, MonoObject *val)
+void
+mono_helper_stelem_ref (MonoArray *array, int index, MonoObject *val)
 {
        MONO_ARCH_SAVE_REGS;
 
@@ -65,8 +67,8 @@ helper_stelem_ref (MonoArray *array, int index, MonoObject *val)
        mono_array_set (array, gpointer, index, val);
 }
 
-static void
-helper_stelem_ref_check (MonoArray *array, MonoObject *val)
+void
+mono_helper_stelem_ref_check (MonoArray *array, MonoObject *val)
 {
        MONO_ARCH_SAVE_REGS;
 
@@ -76,14 +78,14 @@ helper_stelem_ref_check (MonoArray *array, MonoObject *val)
 
 #ifndef MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS
 
-static gint64 
+gint64 
 mono_llmult (gint64 a, gint64 b)
 {
        /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
        return a * b;
 }
 
-static guint64  
+guint64  
 mono_llmult_ovf_un (guint64 a, guint64 b)
 {
        guint32 al = a;
@@ -115,7 +117,7 @@ mono_llmult_ovf_un (guint64 a, guint64 b)
        return 0;
 }
 
-static guint64  
+guint64  
 mono_llmult_ovf (gint64 a, gint64 b) 
 {
        guint32 al = a;
@@ -226,17 +228,9 @@ mono_llmult_ovf (gint64 a, gint64 b)
        return 0;
 }
 
-#ifdef MONO_ARCH_EMULATE_MUL_DIV
-
-static gint32
-mono_imul (gint32 a, gint32 b)
-{
-       MONO_ARCH_SAVE_REGS;
-
-       return a * b;
-}
+#if defined(MONO_ARCH_EMULATE_MUL_DIV) || defined(MONO_ARCH_EMULATE_DIV)
 
-static gint32
+gint32
 mono_idiv (gint32 a, gint32 b)
 {
        MONO_ARCH_SAVE_REGS;
@@ -250,7 +244,7 @@ mono_idiv (gint32 a, gint32 b)
        return a / b;
 }
 
-static guint32
+guint32
 mono_idiv_un (guint32 a, guint32 b)
 {
        MONO_ARCH_SAVE_REGS;
@@ -262,7 +256,7 @@ mono_idiv_un (guint32 a, guint32 b)
        return a / b;
 }
 
-static gint32
+gint32
 mono_irem (gint32 a, gint32 b)
 {
        MONO_ARCH_SAVE_REGS;
@@ -277,7 +271,7 @@ mono_irem (gint32 a, gint32 b)
        return a % b;
 }
 
-static guint32
+guint32
 mono_irem_un (guint32 a, guint32 b)
 {
        MONO_ARCH_SAVE_REGS;
@@ -289,7 +283,19 @@ mono_irem_un (guint32 a, guint32 b)
        return a % b;
 }
 
-static gint32
+#endif
+
+#ifdef MONO_ARCH_EMULATE_MUL_DIV
+
+gint32
+mono_imul (gint32 a, gint32 b)
+{
+       MONO_ARCH_SAVE_REGS;
+
+       return a * b;
+}
+
+gint32
 mono_imul_ovf (gint32 a, gint32 b)
 {
        gint64 res;
@@ -304,7 +310,7 @@ mono_imul_ovf (gint32 a, gint32 b)
        return res;
 }
 
-static gint32
+gint32
 mono_imul_ovf_un (guint32 a, guint32 b)
 {
        guint64 res;
@@ -319,7 +325,7 @@ mono_imul_ovf_un (guint32 a, guint32 b)
        return res;
 }
 
-static double
+double
 mono_fdiv (double a, double b)
 {
        MONO_ARCH_SAVE_REGS;
@@ -328,7 +334,7 @@ mono_fdiv (double a, double b)
 }
 #endif
 
-static gint64 
+gint64 
 mono_lldiv (gint64 a, gint64 b)
 {
        MONO_ARCH_SAVE_REGS;
@@ -342,7 +348,7 @@ mono_lldiv (gint64 a, gint64 b)
        return a / b;
 }
 
-static gint64 
+gint64 
 mono_llrem (gint64 a, gint64 b)
 {
        MONO_ARCH_SAVE_REGS;
@@ -356,7 +362,7 @@ mono_llrem (gint64 a, gint64 b)
        return a % b;
 }
 
-static guint64 
+guint64 
 mono_lldiv_un (guint64 a, guint64 b)
 {
        MONO_ARCH_SAVE_REGS;
@@ -368,7 +374,7 @@ mono_lldiv_un (guint64 a, guint64 b)
        return a / b;
 }
 
-static guint64 
+guint64 
 mono_llrem_un (guint64 a, guint64 b)
 {
        MONO_ARCH_SAVE_REGS;
@@ -384,7 +390,7 @@ mono_llrem_un (guint64 a, guint64 b)
 
 #ifndef MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
 
-static guint64 
+guint64 
 mono_lshl (guint64 a, gint32 shamt)
 {
        guint64 res;
@@ -397,7 +403,7 @@ mono_lshl (guint64 a, gint32 shamt)
        return res;
 }
 
-static guint64 
+guint64 
 mono_lshr_un (guint64 a, gint32 shamt)
 {
        guint64 res;
@@ -410,7 +416,7 @@ mono_lshr_un (guint64 a, gint32 shamt)
        return res;
 }
 
-static gint64 
+gint64 
 mono_lshr (gint64 a, gint32 shamt)
 {
        gint64 res;
@@ -431,7 +437,7 @@ mono_lshr (gint64 a, gint32 shamt)
  *
  * Returns: the address of an array element.
  */
-static gpointer 
+gpointer 
 ves_array_element_address (MonoArray *this, ...)
 {
        MonoClass *class;
@@ -470,7 +476,7 @@ ves_array_element_address (MonoArray *this, ...)
        return ea;
 }
 
-static MonoArray *
+MonoArray *
 mono_array_new_va (MonoMethod *cm, ...)
 {
        MonoDomain *domain = mono_domain_get ();
@@ -494,7 +500,12 @@ mono_array_new_va (MonoMethod *cm, ...)
 
        if (rank == pcount) {
                /* Only lengths provided. */
-               lower_bounds = NULL;
+               if (cm->klass->byval_arg.type == MONO_TYPE_ARRAY) {
+                       lower_bounds = alloca (sizeof (guint32) * rank);
+                       memset (lower_bounds, 0, sizeof (guint32) * rank);
+               } else {
+                       lower_bounds = NULL;
+               }
        } else {
                g_assert (pcount == (rank * 2));
                /* lower bounds are first. */
@@ -506,7 +517,7 @@ mono_array_new_va (MonoMethod *cm, ...)
        return mono_array_new_full (domain, cm->klass, lengths, lower_bounds);
 }
 
-static gpointer
+gpointer
 mono_class_static_field_address (MonoDomain *domain, MonoClassField *field)
 {
        MonoVTable *vtable;
@@ -532,7 +543,7 @@ mono_class_static_field_address (MonoDomain *domain, MonoClassField *field)
        return addr;
 }
 
-static gpointer
+gpointer
 mono_ldtoken_wrapper (MonoImage *image, int token, MonoGenericContext *context)
 {
        MonoClass *handle_class;
@@ -545,14 +556,14 @@ mono_ldtoken_wrapper (MonoImage *image, int token, MonoGenericContext *context)
        return res;
 }
 
-static guint64
+guint64
 mono_fconv_u8 (double v)
 {
        return (guint64)v;
 }
 
 #ifdef MONO_ARCH_EMULATE_FCONV_TO_I8
-static gint64
+gint64
 mono_fconv_i8 (double v)
 {
        /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
@@ -560,7 +571,7 @@ mono_fconv_i8 (double v)
 }
 #endif
 
-static guint32
+guint32
 mono_fconv_u4 (double v)
 {
        /* no need, no exceptions: MONO_ARCH_SAVE_REGS;*/
@@ -578,7 +589,7 @@ extern long double aintl (long double);
 #endif
 #endif /* HAVE_TRUNC */
 
-static gint64
+gint64
 mono_fconv_ovf_i8 (double v)
 {
        gint64 res;
@@ -593,7 +604,7 @@ mono_fconv_ovf_i8 (double v)
        return res;
 }
 
-static guint64
+guint64
 mono_fconv_ovf_u8 (double v)
 {
        guint64 res;
@@ -609,7 +620,7 @@ mono_fconv_ovf_u8 (double v)
 }
 
 #ifdef MONO_ARCH_EMULATE_LCONV_TO_R8
-static double
+double
 mono_lconv_to_r8 (gint64 a)
 {
        return (double)a;
@@ -617,7 +628,7 @@ mono_lconv_to_r8 (gint64 a)
 #endif
 
 #ifdef MONO_ARCH_EMULATE_LCONV_TO_R4
-static float
+float
 mono_lconv_to_r4 (gint64 a)
 {
        return (float)a;
@@ -625,7 +636,7 @@ mono_lconv_to_r4 (gint64 a)
 #endif
 
 #ifdef MONO_ARCH_EMULATE_CONV_R8_UN
-static double
+double
 mono_conv_to_r8_un (guint32 a)
 {
        return (double)a;
@@ -633,23 +644,57 @@ mono_conv_to_r8_un (guint32 a)
 #endif
 
 #ifdef MONO_ARCH_EMULATE_LCONV_TO_R8_UN
-static double
+double
 mono_lconv_to_r8_un (guint64 a)
 {
        return (double)a;
 }
 #endif
 
-static gpointer
-helper_compile_generic_method (MonoObject *obj, MonoMethod *method, MonoGenericContext *context)
+gpointer
+mono_helper_compile_generic_method (MonoObject *obj, MonoMethod *method, MonoGenericContext *context)
 {
        MonoMethod *vmethod, *inflated;
        gpointer addr;
 
+       if (obj == NULL)
+               mono_raise_exception (mono_get_exception_null_reference ());
        vmethod = mono_object_get_virtual_method (obj, method);
+
+       /* 'vmethod' is partially inflated.  All the blanks corresponding to the type parameters of the
+          declaring class have been inflated.  We still need to fully inflate the method parameters.
+
+          FIXME: This code depends on the declaring class being fully inflated, since we inflate it twice with 
+          the same context.
+       */
+       g_assert (!vmethod->klass->generic_container);
+       g_assert (!vmethod->klass->generic_class || !vmethod->klass->generic_class->inst->is_open);
+       g_assert (!context->gmethod || !context->gmethod->inst->is_open);
        inflated = mono_class_inflate_generic_method (vmethod, context);
        inflated = mono_get_inflated_method (inflated);
        addr = mono_compile_method (inflated);
 
        return addr;
 }
+
+MonoString*
+mono_helper_ldstr (MonoImage *image, guint32 idx)
+{
+       return mono_ldstr (mono_domain_get (), image, idx);
+}
+
+MonoString*
+mono_helper_ldstr_mscorlib (guint32 idx)
+{
+       return mono_ldstr (mono_domain_get (), mono_defaults.corlib, idx);
+}
+
+MonoObject*
+mono_helper_newobj_mscorlib (guint32 idx)
+{
+       MonoClass *klass = mono_class_get (mono_defaults.corlib, MONO_TOKEN_TYPE_DEF | idx);
+       
+       g_assert (klass);
+
+       return mono_object_new (mono_domain_get (), klass);
+}