From 2432a6c9b33659fe3cefdcd9e6956e900b224b8a Mon Sep 17 00:00:00 2001 From: losfair Date: Mon, 25 Feb 2019 22:47:27 +0800 Subject: [PATCH] Fix function calls. --- lib/dynasm-backend/src/codegen_x64.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/dynasm-backend/src/codegen_x64.rs b/lib/dynasm-backend/src/codegen_x64.rs index bbd3d4f3a..ae0664c31 100644 --- a/lib/dynasm-backend/src/codegen_x64.rs +++ b/lib/dynasm-backend/src/codegen_x64.rs @@ -876,13 +876,13 @@ impl X64FunctionCode { if is_dword(size) { dynasm!( assembler - ; mov eax, [rsp + (total_size + 16 + caller_stack_offset) as i32] + ; mov eax, [rsp + (total_size + 16 + saved_regs.len() * 8 + caller_stack_offset) as i32] ; mov [rsp + offset as i32], eax ); } else { dynasm!( assembler - ; mov rax, [rsp + (total_size + 16 + caller_stack_offset) as i32] + ; mov rax, [rsp + (total_size + 16 + saved_regs.len() * 8 + caller_stack_offset) as i32] ; mov [rsp + offset as i32], rax ); } @@ -910,6 +910,14 @@ impl X64FunctionCode { ; jmp =>target ; after_call: ); + + for reg in saved_regs.iter().rev() { + dynasm!( + assembler + ; pop Rq(*reg as u8) + ); + } + if caller_stack_offset != 0 { dynasm!( assembler @@ -929,13 +937,6 @@ impl X64FunctionCode { } } - for reg in saved_regs.iter().rev() { - dynasm!( - assembler - ; pop Rq(*reg as u8) - ); - } - Ok(()) } }