Fix the build.
[mono.git] / mono / mini / exceptions-s390x.c
index 36a5e93c67ea89370be1a1d53609564498864168..74c8a0f37a3dfc9fb29813eb87029ad251f7421f 100644 (file)
 #define S390_THROWSTACK_ACCREGS                (S390_THROWSTACK_FLTREGS+(16*sizeof(gdouble)))
 #define S390_THROWSTACK_SIZE           (S390_THROWSTACK_ACCREGS+(16*sizeof(gint32)))
 
+#define S390_REG_SAVE_R13              (S390_REG_SAVE_OFFSET+(7*sizeof(gulong)))
+
 #define SZ_THROW       384
 
+#define setup_context(ctx)
+
 /*========================= End of Defines =========================*/
 
 /*------------------------------------------------------------------*/
@@ -65,8 +69,7 @@
 /*------------------------------------------------------------------*/
 
 gboolean mono_arch_handle_exception (void     *ctx,
-                                    gpointer obj, 
-                                    gboolean test_only);
+                                    gpointer obj);
 
 /*========================= End of Prototypes ======================*/
 
@@ -99,10 +102,10 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
        static int inited = 0;
        guint8 *code;
        int alloc_size, pos, i;
+       GSList *unwind_ops = NULL;
+       MonoJumpInfo *ji = NULL;
 
        g_assert (!aot);
-       if (info)
-               *info = NULL;
 
        if (inited)
                return start;
@@ -161,7 +164,18 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
                s390_ld  (code, i, 0, s390_r13, pos);
                pos += sizeof(gdouble);
        }
-       
+
+#if 0
+       /*------------------------------------------------------*/
+       /* We need to preserve current SP before calling filter */
+       /* with SP from the context                             */
+       /*------------------------------------------------------*/
+       s390_lgr  (code, s390_r14, STK_BASE);
+       s390_lg   (code, STK_BASE, 0, s390_r13,
+                  G_STRUCT_OFFSET(MonoContext, uc_mcontext.gregs[15]));
+       s390_lgr  (code, s390_r13, s390_r14);
+#endif
+
        /*------------------------------------------------------*/
        /* Go call filter                                       */
        /*------------------------------------------------------*/
@@ -173,6 +187,13 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
        /*------------------------------------------------------*/
        s390_lgr  (code, s390_r14, s390_r2);
 
+#if 0
+       /*------------------------------------------------------*/
+       /* Reload our stack register with value saved in context*/
+       /*------------------------------------------------------*/
+       s390_lgr  (code, STK_BASE, s390_r13);
+#endif
+
        /*------------------------------------------------------*/
        /* Restore all the regs from the stack                  */
        /*------------------------------------------------------*/
@@ -190,6 +211,12 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
        s390_br   (code, s390_r14);
 
        g_assert ((code - start) < SZ_THROW); 
+
+       if (info)
+               *info = mono_tramp_info_create ("call_filter",
+                                               start, code - start, ji,
+                                               unwind_ops);
+
        return start;
 }
 
@@ -210,14 +237,10 @@ throw_exception (MonoObject *exc, unsigned long ip, unsigned long sp,
 {
        MonoContext ctx;
        int iReg;
-       static void (*restore_context) (MonoContext *);
 
-       if (!restore_context)
-               restore_context = mono_get_restore_context();
-       
        memset(&ctx, 0, sizeof(ctx));
 
-       getcontext(&ctx);
+       setup_context(&ctx);
 
        /* adjust eip so that it point into the call instruction */
        ip -= 2;
@@ -238,8 +261,9 @@ throw_exception (MonoObject *exc, unsigned long ip, unsigned long sp,
                if (!rethrow)
                        mono_ex->stack_trace = NULL;
        }
-       mono_arch_handle_exception (&ctx, exc, FALSE);
-       restore_context(&ctx);
+//     mono_arch_handle_exception (&ctx, exc, FALSE);
+       mono_handle_exception (&ctx, exc);
+       mono_restore_context(&ctx);
 
        g_assert_not_reached ();
 }
@@ -264,6 +288,8 @@ mono_arch_get_throw_exception_generic (int size, MonoTrampInfo **info,
 {
        guint8 *code, *start;
        int alloc_size, pos, i;
+       MonoJumpInfo *ji = NULL;
+       GSList *unwind_ops = NULL;
 
        code = start = mono_global_codeman_reserve(size);
 
@@ -332,6 +358,13 @@ mono_arch_get_throw_exception_generic (int size, MonoTrampInfo **info,
        /* we should never reach this breakpoint */
        s390_break (code);
        g_assert ((code - start) < size);
+
+       if (info)
+               *info = mono_tramp_info_create (corlib ? "throw_corlib_exception" 
+                                                                      : (rethrow ? "rethrow_exception" 
+                                                                      : "throw_exception"), 
+                                               start, code - start, ji, unwind_ops);
+
        return start;
 }
 
@@ -411,16 +444,16 @@ mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
 /*                                                                  */
 /* Name                - mono_arch_find_jit_info                           */
 /*                                                                  */
-/* Function    - See exceptions-amd64.c for docs.                      */
+/* Function    - See exceptions-amd64.c for docs.                  */
 /*                                                                  */
 /*------------------------------------------------------------------*/
 
 gboolean
 mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, 
-                                                        MonoJitInfo *ji, MonoContext *ctx, 
-                                                        MonoContext *new_ctx, MonoLMF **lmf,
-                                                        mgreg_t **save_locations,
-                                                        StackFrameInfo *frame)
+                        MonoJitInfo *ji, MonoContext *ctx, 
+                        MonoContext *new_ctx, MonoLMF **lmf,
+                        mgreg_t **save_locations,
+                        StackFrameInfo *frame)
 {
        gpointer ip = (gpointer) MONO_CONTEXT_GET_IP (ctx);
        MonoS390StackFrame *sframe;
@@ -432,31 +465,35 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
 
        if (ji != NULL) {
                gint64 address;
+               guint8 *cfa;
+               guint32 unwind_info_len;
+               guint8 *unwind_info;
+               mgreg_t regs[16];
 
                frame->type = FRAME_TYPE_MANAGED;
 
-               if (*lmf && (MONO_CONTEXT_GET_SP (ctx) >= (gpointer)(*lmf)->ebp)) {
-                       /* remove any unused lmf */
-                       *lmf = (*lmf)->previous_lmf;
-               }
+               unwind_info = mono_jinfo_get_unwind_info (ji, &unwind_info_len);
 
                address = (char *)ip - (char *)ji->code_start;
 
-               sframe = (MonoS390StackFrame *) MONO_CONTEXT_GET_SP (ctx);
-               MONO_CONTEXT_SET_BP (new_ctx, sframe->prev);
-               sframe = (MonoS390StackFrame *) sframe->prev;
-               MONO_CONTEXT_SET_IP (new_ctx, (guint8*)sframe->return_address - 2);
-               memcpy (&new_ctx->uc_mcontext.gregs[6], sframe->regs, (8*sizeof(gint64)));
+               memcpy(&regs, &ctx->uc_mcontext.gregs, sizeof(regs));
+               mono_unwind_frame (unwind_info, unwind_info_len, ji->code_start,
+                                                  (guint8 *) ji->code_start + ji->code_size,
+                                                  ip, NULL, regs, 16, save_locations,
+                                                  MONO_MAX_IREGS, &cfa);
+               memcpy (&new_ctx->uc_mcontext.gregs, &regs, sizeof(regs));
+               MONO_CONTEXT_SET_IP(new_ctx, regs[14] - 2);
+               MONO_CONTEXT_SET_BP(new_ctx, cfa);
+       
                return TRUE;
-
        } else if (*lmf) {
-               if (!(*lmf)->method)
-                       return FALSE;
 
                ji = mini_jit_info_table_find (domain, (gpointer)(*lmf)->eip, NULL);
                if (!ji) {
-                       // FIXME: This can happen with multiple appdomains (bug #444383)
-                       return FALSE;
+                       if (!(*lmf)->method)
+                               return FALSE;
+               
+                       frame->method = (*lmf)->method;
                }
 
                frame->ji = ji;
@@ -464,7 +501,6 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
 
                memcpy(new_ctx->uc_mcontext.gregs, (*lmf)->gregs, sizeof((*lmf)->gregs));
                memcpy(new_ctx->uc_mcontext.fpregs.fprs, (*lmf)->fregs, sizeof((*lmf)->fregs));
-
                MONO_CONTEXT_SET_BP (new_ctx, (*lmf)->ebp);
                MONO_CONTEXT_SET_IP (new_ctx, (*lmf)->eip - 2);
                *lmf = (*lmf)->previous_lmf;
@@ -485,15 +521,13 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
 /*                                                                  */
 /* Parameters   - ctx       - Saved processor state                 */
 /*                obj       - The exception object                  */
-/*                test_only - Only test if the exception is caught, */
-/*                            but don't call handlers               */
 /*                                                                  */
 /*------------------------------------------------------------------*/
 
 gboolean
-mono_arch_handle_exception (void *uc, gpointer obj, gboolean test_only)
+mono_arch_handle_exception (void *uc, gpointer obj)
 {
-       return mono_handle_exception (uc, obj, mono_arch_ip_from_context(uc), test_only);
+       return mono_handle_exception (uc, obj);
 }
 
 /*========================= End of Function ========================*/
@@ -510,7 +544,7 @@ mono_arch_handle_exception (void *uc, gpointer obj, gboolean test_only)
 void
 mono_arch_sigctx_to_monoctx (void *ctx, MonoContext *mctx)
 {
-       memcpy (mctx, ctx, sizeof(MonoContext));
+       mono_sigctx_to_monoctx(ctx, mctx);
 }
 
 /*========================= End of Function ========================*/
@@ -526,7 +560,7 @@ mono_arch_sigctx_to_monoctx (void *ctx, MonoContext *mctx)
 void
 mono_arch_monoctx_to_sigctx (MonoContext *mctx, void *ctx)
 {
-       memcpy (ctx, mctx, sizeof(MonoContext));
+       mono_monoctx_to_sigctx(mctx, ctx);
 }
 
 /*========================= End of Function ========================*/