feat: kernel: separate syscall from tcb

This commit is contained in:
Paul Pan 2024-06-17 00:41:33 +08:00
parent 41208c1e15
commit b62c378a38
3 changed files with 38 additions and 14 deletions

View File

@ -29,6 +29,7 @@ mod objects;
mod plat;
mod root;
mod scheduler;
mod syscall;
mod vspace;
// test infrastructure

View File

@ -1,8 +1,9 @@
use crate::arch::{layout::mmap_phys_to_virt, trap::TrapContext, vspace::*};
use crate::syscall::handle_syscall;
use crate::{objects::*, plat::trap::TrapContextOps, vspace::*};
use core::fmt::Debug;
use core::sync::atomic::{AtomicUsize, Ordering};
use uapi::{cap::ObjectType, error::SysResult, fault::*, syscall::*};
use uapi::{cap::ObjectType, fault::*};
use utils::{
addr::*,
linked_list::{Link, LinkHelper},
@ -59,6 +60,10 @@ impl TcbObject {
}
}
pub fn cspace(&self) -> &CapEntry {
&self.cspace
}
pub fn set_cspace(&mut self, cspace: CapEntry) {
CNodeCap::try_from(&cspace).expect("set_cspace: invalid cap");
self.cspace = cspace;
@ -119,19 +124,8 @@ impl TcbObject {
}
pub fn handle_syscall(&mut self) {
let handle_syscall_inner = || -> SysResult {
let info = MessageInfo::try_from(self.trapframe.get_reg(0))?;
let cspace = CNodeCap::try_from(&self.cspace)?;
let cap_ptr = self.trapframe.get_reg(1);
let cap = cspace.resolve_address_bits(cap_ptr, usize::BITS as usize);
debug!("handle_syscall: info={:?}, cap={:?}", info, cap);
todo!("handle_syscall");
};
handle_syscall_inner().unwrap();
// TODO: don't panic here, return error to user instead
handle_syscall(self).unwrap();
}
}

29
kernel/src/syscall.rs Normal file
View File

@ -0,0 +1,29 @@
use crate::{objects::*, plat::trap::TrapContextOps};
use log::trace;
use uapi::{error::*, syscall::*};
pub fn handle_syscall(tcb: &mut TcbObject) -> SysResult {
let info = MessageInfo::try_from(tcb.trapframe.get_reg(0))?;
let cspace = CNodeCap::try_from(tcb.cspace())?;
let cap_ptr = tcb.trapframe.get_reg(1);
let cap = cspace
.resolve_address_bits(cap_ptr, usize::BITS as usize)
.map_err(|e| SysError::from(e))?;
trace!("handle_syscall: info={:?} cap={:?}", info, cap);
match info.label() {
Syscall::DebugPutChar => {
if info.length() != 3 {
return Err(SysError::InvalidArgument);
}
let c = tcb.trapframe.get_reg(2) as u8 as char;
crate::print!("{}", c);
return Ok(());
},
_ => unimplemented!("handle_syscall: {:?}, {:?}", info.label(), cap),
}
}