forked from M-Labs/libfringe
move arch::{initialize_call_frame, swap} to inherent mthods of Registers
they're now Registers::{new, swap}, because they're already effectively a constructor and a method.
This commit is contained in:
parent
67b26662c3
commit
5c5f5095c3
34
src/arch.rs
34
src/arch.rs
|
@ -14,23 +14,9 @@ pub struct Registers {
|
||||||
rsp: *mut uintptr_t
|
rsp: *mut uintptr_t
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
impl Registers {
|
||||||
pub unsafe fn swap(regs: &mut Registers) {
|
|
||||||
asm!(include_str!("swap.s")
|
|
||||||
:
|
|
||||||
: "{rdi}" (&mut regs.rsp)
|
|
||||||
: "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"
|
|
||||||
: "volatile");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn initialize_call_frame<S, F>(stack: &mut S, f: F) -> Registers where S: Stack, F: FnOnce() {
|
pub unsafe fn new<S, F>(stack: &mut S, f: F) -> Registers where S: Stack, F: FnOnce() {
|
||||||
let sp_limit = stack.limit();
|
let sp_limit = stack.limit();
|
||||||
let mut sp = stack.top() as *mut uintptr_t;
|
let mut sp = stack.top() as *mut uintptr_t;
|
||||||
let f_ptr = push(&mut sp, f);
|
let f_ptr = push(&mut sp, f);
|
||||||
|
@ -47,6 +33,22 @@ pub unsafe fn initialize_call_frame<S, F>(stack: &mut S, f: F) -> Registers wher
|
||||||
Registers { rsp: sp }
|
Registers { rsp: sp }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn swap(&mut self) {
|
||||||
|
asm!(include_str!("swap.s")
|
||||||
|
:
|
||||||
|
: "{rdi}" (&mut self.rsp)
|
||||||
|
: "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"
|
||||||
|
: "volatile");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn rust_trampoline<F: FnOnce()>(f: *const F) {
|
unsafe extern "C" fn rust_trampoline<F: FnOnce()>(f: *const F) {
|
||||||
ptr::read(f)()
|
ptr::read(f)()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
use platform::Stack;
|
use platform::Stack;
|
||||||
use arch::{self, Registers};
|
use arch::Registers;
|
||||||
use platform;
|
use platform;
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
|
@ -12,7 +12,7 @@ impl Context {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn new<F>(f: F) -> Context where F: FnOnce() + Send + 'static {
|
pub unsafe fn new<F>(f: F) -> Context where F: FnOnce() + Send + 'static {
|
||||||
let mut stack = Stack::new(4 << 20);
|
let mut stack = Stack::new(4 << 20);
|
||||||
let regs = arch::initialize_call_frame(&mut stack, f);
|
let regs = Registers::new(&mut stack, f);
|
||||||
Context {
|
Context {
|
||||||
regs: regs,
|
regs: regs,
|
||||||
_stack: stack
|
_stack: stack
|
||||||
|
@ -21,6 +21,6 @@ impl Context {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn swap(&mut self) {
|
pub unsafe fn swap(&mut self) {
|
||||||
arch::swap(&mut self.regs)
|
self.regs.swap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue