Fix Windows x64 ABI

This commit is contained in:
edef 2016-07-17 16:33:49 -04:00
parent 42f37c967e
commit 8c761d944f
1 changed files with 82 additions and 45 deletions

View File

@ -42,8 +42,8 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
#[inline(always)]
pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer) -> usize {
let ret: usize;
asm!(
macro_rules! swap_body {
() => {
r#"
# Save frame pointer explicitly; LLVM doesn't spill it even if it is
# marked as clobbered.
@ -71,6 +71,14 @@ pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer)
jmpq *%rbx
2:
"#
}
}
#[cfg(not(windows))]
#[inline(always)]
unsafe fn swap_impl(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer) -> usize {
let ret: usize;
asm!(swap_body!()
: "={rdi}" (ret)
: "{rdi}" (arg)
"{rsi}" (old_sp)
@ -90,3 +98,32 @@ pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer)
: "volatile", "alignstack");
ret
}
#[cfg(windows)]
#[inline(always)]
unsafe fn swap_impl(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer) -> usize {
let ret: usize;
asm!(swap_body!()
: "={rcx}" (ret)
: "{rcx}" (arg)
"{rsi}" (old_sp)
"{rdx}" (new_sp)
: "rax", "rbx", "rcx", "rdx", "rsi", "rdi", //"rbp", "rsp",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
"xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
"xmm16", "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "xmm22", "xmm23",
"xmm24", "xmm25", "xmm26", "xmm27", "xmm28", "xmm29", "xmm30", "xmm31"
"cc", "fpsr", "flags", "memory"
// Ideally, we would set the LLVM "noredzone" attribute on this function
// (and it would be propagated to the call site). Unfortunately, rustc
// provides no such functionality. Fortunately, by a lucky coincidence,
// the "alignstack" LLVM inline assembly option does exactly the same
// thing on x86_64.
: "volatile", "alignstack");
ret
}
swap_impl(arg, old_sp, new_sp)
}