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