1
0
Fork 0

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

View File

@ -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()
} }
} }