2014-12-24 14:28:21 +08:00
|
|
|
use core::prelude::*;
|
2015-04-16 03:56:57 +08:00
|
|
|
use stack::StackSource;
|
2015-04-16 02:22:28 +08:00
|
|
|
use arch::Registers;
|
2015-01-14 15:31:17 +08:00
|
|
|
use platform;
|
2014-12-24 13:12:39 +08:00
|
|
|
|
2014-12-23 11:24:40 +08:00
|
|
|
pub struct Context {
|
|
|
|
regs: Registers,
|
2015-01-14 15:31:17 +08:00
|
|
|
_stack: platform::Stack
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Context {
|
2015-01-14 15:31:17 +08:00
|
|
|
#[inline]
|
|
|
|
pub unsafe fn new<F>(f: F) -> Context where F: FnOnce() + Send + 'static {
|
2015-04-16 03:56:57 +08:00
|
|
|
let mut stack = platform::StackSource::get_stack(4 << 20);
|
2015-04-16 02:22:28 +08:00
|
|
|
let regs = Registers::new(&mut stack, f);
|
2014-12-23 11:24:40 +08:00
|
|
|
Context {
|
2015-01-14 15:31:17 +08:00
|
|
|
regs: regs,
|
|
|
|
_stack: stack
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
2015-01-14 15:31:17 +08:00
|
|
|
pub unsafe fn swap(&mut self) {
|
2015-04-16 02:22:28 +08:00
|
|
|
self.regs.swap()
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
}
|