feat: objects: tcb: update states

This commit is contained in:
Paul Pan 2024-06-09 15:40:26 +08:00
parent 9f4be01153
commit 3b3c68a203

View File

@ -1,5 +1,6 @@
use super::{
cap::{CapEntry, RawCap},
cnode::CNodeCap,
null::NullCap,
Cap, KernelObject,
};
@ -7,14 +8,15 @@ use crate::{
arch::{layout::mmap_phys_to_virt, trap::TrapContext},
plat::trap::TrapContextOps,
};
use uapi::cap::ObjectType;
use core::fmt::Debug;
use uapi::{cap::ObjectType, error::SysResult, fault::Fault, syscall::MessageInfo};
use utils::{
addr::*,
linked_list::{Link, LinkHelper},
LinkHelperImpl,
};
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub enum ThreadState {
Inactive,
Running,
@ -29,8 +31,11 @@ pub struct TcbObject {
cspace: CapEntry,
vspace: CapEntry,
notification: CapEntry,
buffer: CapEntry, // CapFrame
fault: Fault,
fault_handler: CapEntry,
// TODO: add reply, buffer, fault, caller ... priority, dom
state: ThreadState,
time_tick: usize,
pub link: Link<Self>,
@ -44,6 +49,10 @@ impl TcbObject {
trapframe: TrapContext::default(),
cspace: CapEntry::new(NullCap::mint()),
vspace: CapEntry::new(NullCap::mint()),
notification: CapEntry::new(NullCap::mint()),
buffer: CapEntry::new(NullCap::mint()),
fault: Fault::Null,
fault_handler: CapEntry::new(NullCap::mint()),
state: ThreadState::Inactive,
time_tick: 0,
link: Link::default(),
@ -55,6 +64,14 @@ impl TcbObject {
self.state = ThreadState::Idle;
}
pub fn state(&self) -> ThreadState {
self.state
}
pub fn set_state(&mut self, state: ThreadState) {
self.state = state;
}
pub fn timetick(&self) -> usize {
self.time_tick
}
@ -79,7 +96,19 @@ impl TcbObject {
}
pub fn handle_syscall(&mut self) {
todo!("TcbObject::handle_syscall");
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);
todo!("handle_syscall");
Ok(())
};
handle_syscall_inner().unwrap();
}
}
@ -108,3 +137,19 @@ impl<'a> TcbCap<'a> {
}
}
}
impl Debug for TcbCap<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let obj = self.as_object();
f.debug_struct("TcbCap")
.field("cspace", &obj.cspace)
.field("vspace", &obj.vspace)
.field("notification", &obj.notification)
.field("buffer", &obj.buffer)
.field("fault", &obj.fault)
.field("fault_handler", &obj.fault_handler)
.field("state", &obj.state)
.field("time_tick", &obj.time_tick)
.finish()
}
}