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;
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)) {
/*
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);