1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
extern "C" {
fn _kernel_context_create(
ctxcb: *mut Context,
isp: usize,
entry: extern "C" fn(isize),
exinf: isize,
);
fn _kernel_context_start(ctxcb_new: *mut Context);
fn _kernel_context_switch(ctxcb_next: *mut Context, ctxcb_current: *mut Context);
}
#[repr(C)]
pub struct Context {
pub sp: usize,
}
impl Context {
pub const fn new() -> Self {
Context { sp: 0 }
}
pub(crate) unsafe fn _create(
&mut self,
stack: &mut [u8],
entry: extern "C" fn(isize),
exinf: isize,
) {
let isp = (&mut stack[0] as *mut u8 as usize) + stack.len();
_kernel_context_create(self as *mut Context, isp as usize, entry, exinf);
}
pub(crate) unsafe fn _start(&mut self) {
_kernel_context_start(self as *mut Context);
}
pub(crate) unsafe fn _switch(&mut self, current: &mut Context) {
_kernel_context_switch(self as *mut Context, current as *mut Context);
}
}