feat: implement context switching, SavedContext with pc/status fields, wire all syscall outcomes and timer preemption

This commit is contained in:
2026-10-18 02:34:36 +02:00
parent 5a45c14cf5
commit 7724a5bd0a
7 changed files with 195 additions and 27 deletions

View File

@@ -113,6 +113,29 @@ impl<P: Platform> Kernel<P> {
self.processes.get(pid).is_ok()
}
pub fn thread_context(&self, tid: ThreadId) -> Option<&domain::thread::SavedContext> {
self.threads.get(tid).ok().map(|t| t.saved_context())
}
pub fn thread_context_mut(&mut self, tid: ThreadId) -> Option<&mut domain::thread::SavedContext> {
self.threads.get_mut(tid).ok().map(|t| t.saved_context_mut())
}
pub fn thread_process(&self, tid: ThreadId) -> Option<ProcessId> {
self.threads.get(tid).ok().map(|t| t.process())
}
pub fn current_thread(&self) -> Option<ThreadId> {
let core = self.platform.core_id();
self.scheduler.current(core)
}
pub fn pick_next_thread(&mut self) -> Option<ThreadId> {
use domain::scheduler::Scheduler;
let core = self.platform.core_id();
self.scheduler.next(core)
}
pub fn create_endpoint(&mut self) -> Result<types::id::EndpointId, KernelError> {
self.endpoints.create().ok_or(KernelError::NoFreeSlot)
}

View File

@@ -97,8 +97,4 @@ impl Kernel<MockPlatform> {
) -> CapSlot {
self.grant_cap(pid, resource, permissions).expect("grant cap")
}
pub fn thread_context(&self, tid: ThreadId) -> &domain::thread::SavedContext {
self.threads.get(tid).expect("thread").saved_context()
}
}

View File

@@ -28,9 +28,9 @@ fn spawn_thread_preserves_entry_and_stack() {
SyscallOutcome::Complete(SyscallResult::Value(v)) => ThreadId::from_raw(v as u16),
_ => panic!("expected Value"),
};
let ctx = k.thread_context(tid);
let ctx = k.thread_context(tid).unwrap();
assert_eq!(ctx.program_counter(), 0xDEAD);
assert_eq!(ctx.stack_pointer(), 0xBEEF);
assert_eq!(ctx.registers()[2], 0xBEEF);
}
#[test]