mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: add debug support for cnode
This commit is contained in:
parent
a58110f013
commit
9f4be01153
@ -1,5 +1,6 @@
|
|||||||
use crate::objects::*;
|
use crate::objects::*;
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
|
use core::fmt::{write, Debug};
|
||||||
use uapi::cap::ObjectType;
|
use uapi::cap::ObjectType;
|
||||||
use utils::addr::PhysAddr;
|
use utils::addr::PhysAddr;
|
||||||
use utils::{
|
use utils::{
|
||||||
@ -71,3 +72,18 @@ impl From<RawCap> for CapEntry {
|
|||||||
Self::new(value)
|
Self::new(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for CapEntry {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
let cap_type = self.cap.get().cap_type;
|
||||||
|
match cap_type {
|
||||||
|
ObjectType::CNode => write!(f, "{:?}", CNodeCap::try_from(self)),
|
||||||
|
ObjectType::Frame => write!(f, "{:?}", FrameCap::try_from(self)),
|
||||||
|
ObjectType::Null => write!(f, "{:?}", NullCap::try_from(self)),
|
||||||
|
ObjectType::PageTable => write!(f, "{:?}", TableCap::try_from(self)),
|
||||||
|
ObjectType::TCB => write!(f, "{:?}", TcbCap::try_from(self)),
|
||||||
|
ObjectType::Untyped => write!(f, "{:?}", UntypedCap::try_from(self)),
|
||||||
|
_ => write!(f, "UnknownCap"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,11 +3,12 @@ use super::{
|
|||||||
Cap, KernelObject,
|
Cap, KernelObject,
|
||||||
};
|
};
|
||||||
use crate::arch::layout::mmap_phys_to_virt;
|
use crate::arch::layout::mmap_phys_to_virt;
|
||||||
|
use core::fmt::Debug;
|
||||||
use uapi::{cap::ObjectType, fault::LookupFailure};
|
use uapi::{cap::ObjectType, fault::LookupFailure};
|
||||||
use utils::addr::{AddressOps, PhysAddr};
|
use utils::addr::{AddressOps, PhysAddr};
|
||||||
use utils::MASK;
|
use utils::MASK;
|
||||||
|
|
||||||
/// CNodeObject is a array of Capabilities (`RawCap`)
|
/// CNodeObject is a array of Capabilities (`CapEntry`)
|
||||||
/// The size of the array is stored in CNodeCap
|
/// The size of the array is stored in CNodeCap
|
||||||
pub type CNodeObject = [CapEntry];
|
pub type CNodeObject = [CapEntry];
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ impl KernelObject for CNodeObject {
|
|||||||
* > args[1]: guard
|
* > args[1]: guard
|
||||||
*
|
*
|
||||||
* in our implementation, CNodeCap layout:
|
* in our implementation, CNodeCap layout:
|
||||||
* > args[0]: [guard_size, radix]
|
* > args[0]: [guard_bits, radix_bits]
|
||||||
* > args[1]: guard
|
* > args[1]: guard
|
||||||
* > ptr: cnode_ptr
|
* > ptr: cnode_ptr
|
||||||
* > cap_type: cap_tag
|
* > cap_type: cap_tag
|
||||||
@ -38,9 +39,9 @@ impl<'a> CNodeCap<'a> {
|
|||||||
const RADIX_MASK: usize = MASK!(Self::RADIX_BITS);
|
const RADIX_MASK: usize = MASK!(Self::RADIX_BITS);
|
||||||
const RADIX_OFFSET: usize = 0;
|
const RADIX_OFFSET: usize = 0;
|
||||||
|
|
||||||
pub fn mint(radix: usize, guard_size: usize, guard: usize, ptr: PhysAddr) -> RawCap {
|
pub fn mint(radix_bits: usize, guard_bits: usize, guard: usize, ptr: PhysAddr) -> RawCap {
|
||||||
let arg0 = ((radix & Self::RADIX_MASK) << Self::RADIX_OFFSET)
|
let arg0 = ((radix_bits & Self::RADIX_MASK) << Self::RADIX_OFFSET)
|
||||||
| ((guard_size & Self::GUARD_SIZE_MASK) << Self::GUARD_SIZE_OFFSET);
|
| ((guard_bits & Self::GUARD_SIZE_MASK) << Self::GUARD_SIZE_OFFSET);
|
||||||
let arg1 = guard;
|
let arg1 = guard;
|
||||||
let cap: RawCap = RawCap::new(arg0, arg1, ptr, ObjectType::CNode);
|
let cap: RawCap = RawCap::new(arg0, arg1, ptr, ObjectType::CNode);
|
||||||
|
|
||||||
@ -55,11 +56,11 @@ impl<'a> CNodeCap<'a> {
|
|||||||
cap
|
cap
|
||||||
}
|
}
|
||||||
|
|
||||||
fn radix(&self) -> usize {
|
fn radix_bits(&self) -> usize {
|
||||||
(self.cte.cap.get().args[0] >> Self::RADIX_OFFSET) & Self::RADIX_MASK
|
(self.cte.cap.get().args[0] >> Self::RADIX_OFFSET) & Self::RADIX_MASK
|
||||||
}
|
}
|
||||||
|
|
||||||
fn guard_size(&self) -> usize {
|
fn guard_bits(&self) -> usize {
|
||||||
(self.cte.cap.get().args[0] >> Self::GUARD_SIZE_OFFSET) & Self::GUARD_SIZE_MASK
|
(self.cte.cap.get().args[0] >> Self::GUARD_SIZE_OFFSET) & Self::GUARD_SIZE_MASK
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ impl<'a> CNodeCap<'a> {
|
|||||||
// Return the limited size of the CNode, Rust will help us to check the boundary :)
|
// Return the limited size of the CNode, Rust will help us to check the boundary :)
|
||||||
// > the kernel then uses the next most-significant `radix` bits of the
|
// > the kernel then uses the next most-significant `radix` bits of the
|
||||||
// > capability address as an `index` into the CNode to which the CNode capability refers
|
// > capability address as an `index` into the CNode to which the CNode capability refers
|
||||||
1 << self.radix()
|
1 << self.radix_bits()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_object(&self) -> &CNodeObject {
|
pub fn as_object(&self) -> &CNodeObject {
|
||||||
@ -94,8 +95,8 @@ impl<'a> CNodeCap<'a> {
|
|||||||
let mut slot = self.cte;
|
let mut slot = self.cte;
|
||||||
|
|
||||||
while let Ok(cnode) = CNodeCap::try_from(slot) {
|
while let Ok(cnode) = CNodeCap::try_from(slot) {
|
||||||
let radix_bits = cnode.radix();
|
let radix_bits = cnode.radix_bits();
|
||||||
let guard_bits = cnode.guard_size();
|
let guard_bits = cnode.guard_bits();
|
||||||
let level_bits = radix_bits + guard_bits;
|
let level_bits = radix_bits + guard_bits;
|
||||||
let cap_guard = cnode.guard();
|
let cap_guard = cnode.guard();
|
||||||
|
|
||||||
@ -134,6 +135,18 @@ impl<'a> CNodeCap<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for CNodeCap<'_> {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
f.debug_struct("CNodeCap")
|
||||||
|
.field("radix_bits", &self.radix_bits())
|
||||||
|
.field("guard_bits", &self.guard_bits())
|
||||||
|
.field("guard", &self.guard())
|
||||||
|
.field("length", &self.length())
|
||||||
|
.field("ptr", &self.cte.cap.get().ptr)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -4,6 +4,7 @@ use crate::{
|
|||||||
objects::cap::CapEntry,
|
objects::cap::CapEntry,
|
||||||
vspace::*,
|
vspace::*,
|
||||||
};
|
};
|
||||||
|
use core::fmt::Debug;
|
||||||
use uapi::{
|
use uapi::{
|
||||||
cap::ObjectType,
|
cap::ObjectType,
|
||||||
error::{SysError, SysResult},
|
error::{SysError, SysResult},
|
||||||
@ -161,3 +162,16 @@ impl<'a> FrameCap<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for FrameCap<'_> {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
f.debug_struct("FrameCap")
|
||||||
|
.field("ptr", &self.cte.cap.get().ptr)
|
||||||
|
.field("size", &self.size())
|
||||||
|
.field("attr", &self.attr())
|
||||||
|
.field("is_device", &self.is_device())
|
||||||
|
.field("mapped_asid", &self.mapped_asid())
|
||||||
|
.field("mapped_vaddr", &self.mapped_vaddr())
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@ pub use cap::{CapEntry, RawCap};
|
|||||||
pub use cnode::{CNodeCap, CNodeObject};
|
pub use cnode::{CNodeCap, CNodeObject};
|
||||||
pub use frame::{FrameCap, FrameObject};
|
pub use frame::{FrameCap, FrameObject};
|
||||||
pub use null::{NullCap, NullObject};
|
pub use null::{NullCap, NullObject};
|
||||||
|
pub use table::{TableCap, TableObject};
|
||||||
pub use tcb::{TcbCap, TcbObject};
|
pub use tcb::{TcbCap, TcbObject};
|
||||||
pub use untyped::{UntypedCap, UntypedObject};
|
pub use untyped::{UntypedCap, UntypedObject};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use super::cap::RawCap;
|
use super::cap::RawCap;
|
||||||
use super::{Cap, KernelObject};
|
use super::{Cap, KernelObject};
|
||||||
|
use core::fmt::Debug;
|
||||||
use uapi::cap::ObjectType;
|
use uapi::cap::ObjectType;
|
||||||
use utils::addr::PhysAddr;
|
use utils::addr::PhysAddr;
|
||||||
|
|
||||||
@ -15,3 +16,9 @@ impl<'a> NullCap<'a> {
|
|||||||
RawCap::new(0, 0, PhysAddr(0), ObjectType::Null)
|
RawCap::new(0, 0, PhysAddr(0), ObjectType::Null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for NullCap<'_> {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
write!(f, "NullCap")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use super::{cap::RawCap, Cap, KernelObject};
|
use super::{cap::RawCap, Cap, KernelObject};
|
||||||
use crate::{arch::layout::mmap_phys_to_virt, vspace::*};
|
use crate::{arch::layout::mmap_phys_to_virt, vspace::*};
|
||||||
|
use core::fmt::Debug;
|
||||||
use uapi::{
|
use uapi::{
|
||||||
cap::ObjectType,
|
cap::ObjectType,
|
||||||
error::{SysError, SysResult},
|
error::{SysError, SysResult},
|
||||||
@ -130,3 +131,9 @@ impl<'a> TableCap<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for TableCap<'_> {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
f.debug_struct("TableCap").field("ptr", &self.cte.cap.get().ptr).finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ use super::cap::RawCap;
|
|||||||
use super::cnode::{CNodeCap, CNodeObject};
|
use super::cnode::{CNodeCap, CNodeObject};
|
||||||
use super::null::NullCap;
|
use super::null::NullCap;
|
||||||
use super::{Cap, KernelObject};
|
use super::{Cap, KernelObject};
|
||||||
|
use core::fmt::Debug;
|
||||||
use uapi::cap::ObjectType;
|
use uapi::cap::ObjectType;
|
||||||
use uapi::error::{SysError, SysResult};
|
use uapi::error::{SysError, SysResult};
|
||||||
use utils::addr::{align_up, PhysAddr};
|
use utils::addr::{align_up, PhysAddr};
|
||||||
@ -131,6 +132,17 @@ impl UntypedCap<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for UntypedCap<'_> {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
f.debug_struct("UntypedCap")
|
||||||
|
.field("free_offset", &self.free_offset())
|
||||||
|
.field("block_bits", &self.block_bits())
|
||||||
|
.field("is_device", &self.is_device())
|
||||||
|
.field("ptr", &self.cte.cap.get().ptr)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -42,6 +42,7 @@ pub struct VMFault {
|
|||||||
ip: VirtAddr,
|
ip: VirtAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum Fault {
|
pub enum Fault {
|
||||||
Null,
|
Null,
|
||||||
CapFault(CapFault),
|
CapFault(CapFault),
|
||||||
|
Loading…
Reference in New Issue
Block a user