Six registers are used on x86-64 to pass parameters to the callee and we must make sure they aren't altered by the trampoline.
Signed-off-by: Eduard - Gabriel Munteanu <eduard.munte...@linux360.ro> --- arch/x86/emit-code.c | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/x86/emit-code.c b/arch/x86/emit-code.c index 642c89b..4099c04 100644 --- a/arch/x86/emit-code.c +++ b/arch/x86/emit-code.c @@ -2077,8 +2077,14 @@ void emit_trampoline(struct compilation_unit *cu, __emit64_push_reg(buf, REG_RBP); __emit64_mov_reg_reg(buf, REG_RSP, REG_RBP); + /* + * %rdi, %rsi, %rdx, %rcx, %r8 and %r9 are used + * to pass parameters, so save them if they get modified. + */ + __emit64_push_reg(buf, REG_RDI); __emit64_mov_imm_reg(buf, (unsigned long) cu, REG_RDI); __emit_call(buf, call_target); + __emit64_pop_reg(buf, REG_RDI); /* * Test for exception occurance. @@ -2088,18 +2094,25 @@ void emit_trampoline(struct compilation_unit *cu, * mov fs:(0xXXX), %rcx * test (%rcx), %rcx */ + __emit64_push_reg(buf, REG_RCX); emit(buf, 0x64); __emit_memdisp_reg(buf, 1, 0x8b, get_thread_local_offset(&trampoline_exception_guard), REG_RCX); __emit64_test_membase_reg(buf, REG_RCX, 0, REG_RCX); - - __emit64_mov_reg_reg(buf, REG_RAX, REG_RDI); + __emit64_pop_reg(buf, REG_RCX); if (method_is_virtual(cu->method)) { + __emit64_push_reg(buf, REG_RDI); + __emit64_push_reg(buf, REG_RSI); + + __emit64_mov_reg_reg(buf, REG_RAX, REG_RDI); __emit64_mov_membase_reg(buf, REG_RBP, 0x08, REG_RSI); __emit64_mov_imm_reg(buf, (unsigned long) cu, REG_RDX); __emit_call(buf, fixup_vtable); + + __emit64_pop_reg(buf, REG_RSI); + __emit64_pop_reg(buf, REG_RDI); } __emit64_pop_reg(buf, REG_RBP); -- 1.6.0.6 ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel