[Mammoth] Move thread syscalls to wrappers.

This commit is contained in:
Drew Galbraith 2024-07-28 19:48:05 -07:00
parent 612a5ac572
commit ca67da16e6
3 changed files with 51 additions and 46 deletions

View file

@ -1,11 +1,13 @@
extern crate alloc;
use crate::zion;
use crate::zion::z_cap_t;
use crate::zion::ZError;
use core::ffi::c_void;
use core::panic::PanicInfo;
#[must_use]
pub fn syscall<T>(id: u64, req: &T) -> Result<(), zion::ZError> {
pub fn syscall<T>(id: u64, req: &T) -> Result<(), ZError> {
unsafe {
let resp = zion::SysCall1(id, req as *const T as *const c_void);
if resp != 0 {
@ -37,3 +39,36 @@ pub fn debug(msg: &str) {
};
syscall(zion::kZionDebug, &req).expect("Failed to write");
}
pub fn thread_create(proc_cap: z_cap_t) -> Result<z_cap_t, ZError> {
let mut cap = 0;
syscall(
zion::kZionThreadCreate,
&zion::ZThreadCreateReq {
proc_cap,
thread_cap: &mut cap as *mut z_cap_t,
},
)?;
Ok(cap)
}
pub fn thread_start(thread_cap: z_cap_t, entry: u64, arg1: u64, arg2: u64) -> Result<(), ZError> {
syscall(
zion::kZionThreadStart,
&zion::ZThreadStartReq {
thread_cap,
entry,
arg1,
arg2,
},
)
}
pub fn thread_wait(thread_cap: z_cap_t) -> Result<(), ZError> {
syscall(zion::kZionThreadWait, &zion::ZThreadWaitReq { thread_cap })
}
pub fn thread_exit() -> ! {
let _ = syscall(zion::kZionThreadExit, &zion::ZThreadExitReq {});
unreachable!();
}