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:
edef 2015-04-15 14:22:28 -04:00
parent 67b26662c3
commit 5c5f5095c3
2 changed files with 33 additions and 31 deletions

View File

@ -14,37 +14,39 @@ pub struct Registers {
rsp: *mut uintptr_t
}
#[inline(always)]
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");
}
impl Registers {
#[inline]
pub unsafe fn new<S, F>(stack: &mut S, f: F) -> Registers where S: Stack, F: FnOnce() {
let sp_limit = stack.limit();
let mut sp = stack.top() as *mut uintptr_t;
let f_ptr = push(&mut sp, f);
#[inline]
pub unsafe fn initialize_call_frame<S, F>(stack: &mut S, f: F) -> Registers where S: Stack, F: FnOnce() {
let sp_limit = stack.limit();
let mut sp = stack.top() as *mut uintptr_t;
let f_ptr = push(&mut sp, f);
asm!(include_str!("init.s")
: "={rdi}"(sp)
: "{rdi}" (sp),
"{rsi}" (rust_trampoline::<F>),
"{rdx}" (f_ptr),
"{rcx}" (sp_limit)
:
: "volatile");
asm!(include_str!("init.s")
: "={rdi}"(sp)
: "{rdi}" (sp),
"{rsi}" (rust_trampoline::<F>),
"{rdx}" (f_ptr),
"{rcx}" (sp_limit)
:
: "volatile");
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) {

View File

@ -1,6 +1,6 @@
use core::prelude::*;
use platform::Stack;
use arch::{self, Registers};
use arch::Registers;
use platform;
pub struct Context {
@ -12,7 +12,7 @@ impl Context {
#[inline]
pub unsafe fn new<F>(f: F) -> Context where F: FnOnce() + Send + 'static {
let mut stack = Stack::new(4 << 20);
let regs = arch::initialize_call_frame(&mut stack, f);
let regs = Registers::new(&mut stack, f);
Context {
regs: regs,
_stack: stack
@ -21,6 +21,6 @@ impl Context {
#[inline(always)]
pub unsafe fn swap(&mut self) {
arch::swap(&mut self.regs)
self.regs.swap()
}
}