1
0
Fork 0

Move x86 trampoline to naked function

Close #19
This commit is contained in:
John Ericson 2016-07-16 13:17:22 -07:00 committed by edef
parent 1ea4b01eda
commit 75ca6f66e1
2 changed files with 15 additions and 23 deletions

View File

@ -29,35 +29,26 @@ impl StackPointer {
} }
pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer { pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer {
let g: usize; #[naked]
unsafe extern "C" fn trampoline() -> ! {
asm!( asm!(
r#" r#"
# Push address of the trampoline.
call 1f
# Pop function. # Pop function.
popl %ebx popl %ebx
# Push argument. # Push argument.
pushl %eax pushl %eax
# Call it. # Call it.
call *%ebx call *%ebx
"# ::: "memory" : "volatile");
1: ::core::intrinsics::unreachable()
# Pop address of the trampoline. }
popl %eax
"#
: "={eax}" (g)
:
: "memory"
: "volatile"
);
let mut sp = StackPointer::new(stack); let mut sp = StackPointer::new(stack);
sp.push(0); // alignment sp.push(0); // alignment
sp.push(0); // alignment sp.push(0); // alignment
sp.push(0); // alignment sp.push(0); // alignment
sp.push(f as usize); // function sp.push(f as usize); // function
sp.push(g as usize); // trampoline sp.push(trampoline as usize);
sp sp
} }

View File

@ -2,6 +2,7 @@
// Copyright (c) edef <edef@edef.eu> // Copyright (c) edef <edef@edef.eu>
// See the LICENSE file included in this distribution. // See the LICENSE file included in this distribution.
#![feature(asm)] #![feature(asm)]
#![cfg_attr(target_arch = "x86", feature(naked_functions, core_intrinsics))]
#![no_std] #![no_std]
//! libfringe is a low-level green threading library. //! libfringe is a low-level green threading library.