mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: objects: tcb: update states
This commit is contained in:
parent
9f4be01153
commit
3b3c68a203
@ -1,5 +1,6 @@
|
|||||||
use super::{
|
use super::{
|
||||||
cap::{CapEntry, RawCap},
|
cap::{CapEntry, RawCap},
|
||||||
|
cnode::CNodeCap,
|
||||||
null::NullCap,
|
null::NullCap,
|
||||||
Cap, KernelObject,
|
Cap, KernelObject,
|
||||||
};
|
};
|
||||||
@ -7,14 +8,15 @@ use crate::{
|
|||||||
arch::{layout::mmap_phys_to_virt, trap::TrapContext},
|
arch::{layout::mmap_phys_to_virt, trap::TrapContext},
|
||||||
plat::trap::TrapContextOps,
|
plat::trap::TrapContextOps,
|
||||||
};
|
};
|
||||||
use uapi::cap::ObjectType;
|
use core::fmt::Debug;
|
||||||
|
use uapi::{cap::ObjectType, error::SysResult, fault::Fault, syscall::MessageInfo};
|
||||||
use utils::{
|
use utils::{
|
||||||
addr::*,
|
addr::*,
|
||||||
linked_list::{Link, LinkHelper},
|
linked_list::{Link, LinkHelper},
|
||||||
LinkHelperImpl,
|
LinkHelperImpl,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum ThreadState {
|
pub enum ThreadState {
|
||||||
Inactive,
|
Inactive,
|
||||||
Running,
|
Running,
|
||||||
@ -27,10 +29,13 @@ pub enum ThreadState {
|
|||||||
pub struct TcbObject {
|
pub struct TcbObject {
|
||||||
pub trapframe: TrapContext, // must be the first field
|
pub trapframe: TrapContext, // must be the first field
|
||||||
|
|
||||||
cspace: CapEntry,
|
cspace: CapEntry,
|
||||||
vspace: CapEntry,
|
vspace: CapEntry,
|
||||||
|
notification: CapEntry,
|
||||||
|
buffer: CapEntry, // CapFrame
|
||||||
|
fault: Fault,
|
||||||
|
fault_handler: CapEntry,
|
||||||
|
|
||||||
// TODO: add reply, buffer, fault, caller ... priority, dom
|
|
||||||
state: ThreadState,
|
state: ThreadState,
|
||||||
time_tick: usize,
|
time_tick: usize,
|
||||||
pub link: Link<Self>,
|
pub link: Link<Self>,
|
||||||
@ -41,12 +46,16 @@ LinkHelperImpl!(TcbObject:link);
|
|||||||
impl TcbObject {
|
impl TcbObject {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
trapframe: TrapContext::default(),
|
trapframe: TrapContext::default(),
|
||||||
cspace: CapEntry::new(NullCap::mint()),
|
cspace: CapEntry::new(NullCap::mint()),
|
||||||
vspace: CapEntry::new(NullCap::mint()),
|
vspace: CapEntry::new(NullCap::mint()),
|
||||||
state: ThreadState::Inactive,
|
notification: CapEntry::new(NullCap::mint()),
|
||||||
time_tick: 0,
|
buffer: CapEntry::new(NullCap::mint()),
|
||||||
link: Link::default(),
|
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;
|
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 {
|
pub fn timetick(&self) -> usize {
|
||||||
self.time_tick
|
self.time_tick
|
||||||
}
|
}
|
||||||
@ -79,7 +96,19 @@ impl TcbObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_syscall(&mut self) {
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user