forked from M-Labs/libfringe
parent
1ea4b01eda
commit
75ca6f66e1
|
@ -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]
|
||||||
asm!(
|
unsafe extern "C" fn trampoline() -> ! {
|
||||||
r#"
|
asm!(
|
||||||
# Push address of the trampoline.
|
r#"
|
||||||
call 1f
|
# Pop function.
|
||||||
|
popl %ebx
|
||||||
# Pop function.
|
# Push argument.
|
||||||
popl %ebx
|
pushl %eax
|
||||||
# Push argument.
|
# Call it.
|
||||||
pushl %eax
|
call *%ebx
|
||||||
# Call it.
|
"# ::: "memory" : "volatile");
|
||||||
call *%ebx
|
::core::intrinsics::unreachable()
|
||||||
|
}
|
||||||
1:
|
|
||||||
# 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue