2008-04-04 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Fri, 4 Apr 2008 15:42:28 +0000 (15:42 -0000)
committerZoltan Varga <vargaz@gmail.com>
Fri, 4 Apr 2008 15:42:28 +0000 (15:42 -0000)
* exceptions-amd64.c (throw_exception): Unify the win32/non-win32 cases, save
caller saved registers as well.

svn path=/trunk/mono/; revision=99847

mono/mini/ChangeLog
mono/mini/exceptions-amd64.c

index 1601cd6886edc8509b71122f98f32ef1463c61c4..b1143db1ae0d51c7f06536573177a0d01cf9b21b 100644 (file)
@@ -1,5 +1,8 @@
 2008-04-04  Zoltan Varga  <vargaz@gmail.com>
 
+       * exceptions-amd64.c (throw_exception): Unify the win32/non-win32 cases, save
+       caller saved registers as well.
+       
        * exceptions-amd64.c (mono_arch_get_restore_context): Restore most caller
        saved registers as well.
 
index ac0d0a422e8d75e19c879c4aa1e5fd8d8f6c1951..db6173cddc4b87dd2ae3631ad0fe8eae6df745df 100644 (file)
@@ -267,17 +267,19 @@ mono_arch_get_call_filter (void)
 
        return start;
 }
-#ifdef PLATFORM_WIN32
-static void
-throw_exception (MonoObject *exc, guint64 rip, guint64 rsp,
-                guint64 rbx, guint64 rbp, guint64 r12, guint64 r13, 
-                guint64 r14, guint64 r15, guint64 rdi, guint64 rsi, guint64 rethrow)
-#else
+
+/* 
+ * The first few arguments are dummy, to force the other arguments to be passed on
+ * the stack, this avoids overwriting the argument registers in the throw trampoline.
+ */
 static void
-throw_exception (MonoObject *exc, guint64 rip, guint64 rsp,
-                guint64 rbx, guint64 rbp, guint64 r12, guint64 r13, 
-                guint64 r14, guint64 r15, guint64 rethrow)
-#endif
+throw_exception (guint64 dummy1, guint64 dummy2, guint64 dummy3, guint64 dummy4,
+                                guint64 dummy5, guint64 dummy6,
+                                MonoObject *exc, guint64 rip, guint64 rsp,
+                                guint64 rbx, guint64 rbp, guint64 r12, guint64 r13, 
+                                guint64 r14, guint64 r15, guint64 rdi, guint64 rsi, 
+                                guint64 rax, guint64 rcx, guint64 rdx,
+                                guint64 rethrow)
 {
        static void (*restore_context) (MonoContext *);
        MonoContext ctx;
@@ -293,10 +295,11 @@ throw_exception (MonoObject *exc, guint64 rip, guint64 rsp,
        ctx.r13 = r13;
        ctx.r14 = r14;
        ctx.r15 = r15;
-#ifdef PLATFORM_WIN32
        ctx.rdi = rdi;
        ctx.rsi = rsi;
-#endif
+       ctx.rax = rax;
+       ctx.rcx = rcx;
+       ctx.rdx = rdx;
 
        if (!rethrow && mono_debugger_throw_exception ((gpointer)(rip - 8), (gpointer)rsp, exc)) {
                /*
@@ -345,42 +348,44 @@ get_throw_trampoline (gboolean rethrow)
 
        code = start;
 
-       /* Exception */
-       amd64_mov_reg_reg (code, AMD64_ARG_REG1, AMD64_ARG_REG1, 8);
-       /* IP */
-       amd64_mov_reg_membase (code, AMD64_ARG_REG2, AMD64_RSP, 0, 8);
-       /* SP */
-       amd64_lea_membase (code, AMD64_ARG_REG3, AMD64_RSP, 8);
+       amd64_mov_reg_reg (code, AMD64_R11, AMD64_RSP, 8);
 
 #ifdef PLATFORM_WIN32
-       /* Callee saved regs */
-       amd64_mov_reg_reg (code, AMD64_R9, AMD64_RBX, 8);
-       /* reverse order */
-       amd64_push_imm (code, rethrow);
-       amd64_push_reg (code, AMD64_RSI);
-       amd64_push_reg (code, AMD64_RDI);
-       amd64_push_reg (code, AMD64_R15);
-       amd64_push_reg (code, AMD64_R14);
-       amd64_push_reg (code, AMD64_R13);
-       amd64_push_reg (code, AMD64_R12);
-       amd64_push_reg (code, AMD64_RBP);
+       // FIXME: Sync with the !WIN32 code below
+       NOT_IMPLEMENTED;
+
        /* align stack */
        amd64_push_imm (code, 0);
        amd64_push_imm (code, 0);
        amd64_push_imm (code, 0);
        amd64_push_imm (code, 0);
 #else
-       /* Callee saved regs */
-       amd64_mov_reg_reg (code, AMD64_RCX, AMD64_RBX, 8);
-       amd64_mov_reg_reg (code, AMD64_R8, AMD64_RBP, 8);
-       amd64_mov_reg_reg (code, AMD64_R9, AMD64_R12, 8);
-       /* align stack */
-       amd64_push_imm (code, 0);
+       /* No need to align stack */
+       //amd64_push_imm (code, 0);
+
        /* reverse order */
        amd64_push_imm (code, rethrow);
+       amd64_push_reg (code, AMD64_RDX);
+       amd64_push_reg (code, AMD64_RCX);
+       amd64_push_reg (code, AMD64_RAX);
+       amd64_push_reg (code, AMD64_RSI);
+       amd64_push_reg (code, AMD64_RDI);
        amd64_push_reg (code, AMD64_R15);
        amd64_push_reg (code, AMD64_R14);
        amd64_push_reg (code, AMD64_R13);
+       amd64_push_reg (code, AMD64_R12);
+       amd64_push_reg (code, AMD64_RBP);
+       amd64_push_reg (code, AMD64_RBX);
+
+       /* SP */
+       amd64_lea_membase (code, AMD64_RAX, AMD64_R11, 8);
+       amd64_push_reg (code, AMD64_RAX);
+
+       /* IP */
+       amd64_push_membase (code, AMD64_R11, 0);
+
+       /* Exception */
+       amd64_push_reg (code, AMD64_ARG_REG1);
 #endif
 
        amd64_mov_reg_imm (code, AMD64_R11, throw_exception);