diff --git a/docs/README.md b/docs/README.md index c6aa616e0..8c0a30cd1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,3 @@ # Xous Documentation -Xous is the operating system powering Betrusted. This repository -documents the inner workings of this operating system. +This directory is about to be deprecated. Please refer to the [Xous Book](https://betrusted.io/xous-book/) for up to date documentation. \ No newline at end of file diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 1403e66a3..64694aa94 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -69,12 +69,13 @@ memmap-flash = [] debug-swap = [] debug-swap-verbose = [] raw-trng = ["xous-kernel/raw-trng"] +debug-proc = [] # patches for simulation targets ONLY. Applying these flags will result in totally broken security. hwsim = [] # default = ["print-panics", "debug-print", "wrap-print"] -default = ["print-panics"] +default = ["debug-proc", "print-panics"] [target.'cfg(any(windows, unix))'.dependencies] crossbeam-channel = "0.5" diff --git a/kernel/src/swap.rs b/kernel/src/swap.rs index 15e9ffb74..dba674107 100644 --- a/kernel/src/swap.rs +++ b/kernel/src/swap.rs @@ -43,6 +43,10 @@ pub enum SwapAbi { ReleaseMemory = 6, WritePage = 7, BlockErase = 8, + DebugProcesses = 9, + DebugServers = 10, + DebugFree = 11, + DebugInterrupts = 12, } /// SYNC WITH `xous-swapper/src/main.rs` impl SwapAbi { @@ -57,6 +61,10 @@ impl SwapAbi { 6 => ReleaseMemory, 7 => WritePage, 8 => BlockErase, + 9 => DebugProcesses, + 10 => DebugServers, + 11 => DebugFree, + 12 => DebugInterrupts, _ => Invalid, } } diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index d46097cea..f7267f469 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -1180,6 +1180,94 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR }); Ok(xous_kernel::Result::Ok) } + SwapAbi::DebugProcesses => { + #[cfg(feature = "debug-proc")] + crate::services::SystemServices::with(|system_services| { + println!("Printing processes"); + let current_pid = system_services.current_pid(); + for process in &system_services.processes { + if !process.free() { + process.activate().unwrap(); + let mut connection_count = 0; + ArchProcess::with_inner(|process_inner| { + for conn in &process_inner.connection_map { + if conn.is_some() { + connection_count += 1; + } + } + }); + println!( + "{:x?} conns:{}/32 {}", + process, + connection_count, + system_services.process_name(process.pid).unwrap_or("") + ); + } + } + system_services.get_process(current_pid).unwrap().activate().unwrap(); + }); + Ok(xous_kernel::Result::Ok) + } + SwapAbi::DebugServers => { + #[cfg(feature = "debug-proc")] + crate::services::SystemServices::with(|system_services| { + println!("Servers in use:"); + println!(" idx | pid | process | sid"); + println!(" --- + --- + -------------------- | ------------------"); + for (idx, server) in system_services.servers.iter().enumerate() { + if let Some(s) = server { + println!( + " {:3} | {:3} | {:20} | {:x?}", + idx, + s.pid, + system_services.process_name(s.pid).unwrap_or(""), + s.sid + ); + } + } + }); + Ok(xous_kernel::Result::Ok) + } + SwapAbi::DebugFree => { + #[cfg(feature = "debug-proc")] + crate::services::SystemServices::with(|system_services| { + println!("RAM usage:"); + let mut total_bytes = 0; + crate::mem::MemoryManager::with(|mm| { + for process in &system_services.processes { + if !process.free() { + let bytes_used = mm.ram_used_by(process.pid); + total_bytes += bytes_used; + println!( + " PID {:>3}: {:>4} k {}", + process.pid, + bytes_used / 1024, + system_services.process_name(process.pid).unwrap_or("") + ); + } + } + }); + println!("{} k total", total_bytes / 1024); + }); + Ok(xous_kernel::Result::Ok) + } + SwapAbi::DebugInterrupts => { + #[cfg(feature = "debug-proc")] + crate::services::SystemServices::with(|system_services| { + println!("Interrupt handlers:"); + println!(" IRQ | Process | Handler | Argument"); + crate::irq::for_each_irq(|irq, pid, address, arg| { + println!( + " {}: {} @ {:x?} {:x?}", + irq, + system_services.process_name(*pid).unwrap_or(""), + address, + arg + ); + }); + }); + Ok(xous_kernel::Result::Ok) + } SwapAbi::Invalid => { println!( "Invalid SwapOp: {:x} {:x} {:x} {:x} {:x} {:x} {:x}", diff --git a/services/bao1x-hal-service/src/i2c_lib.rs b/libs/bao1x-hal/src/i2c.rs similarity index 100% rename from services/bao1x-hal-service/src/i2c_lib.rs rename to libs/bao1x-hal/src/i2c.rs diff --git a/services/xous-swapper/src/lib.rs b/services/xous-swapper/src/lib.rs index c4857ff00..298acecd5 100644 --- a/services/xous-swapper/src/lib.rs +++ b/services/xous-swapper/src/lib.rs @@ -22,6 +22,10 @@ pub enum SwapAbi { ReleaseMemory = 6, WritePage = 7, BlockErase = 8, + DebugProcesses = 9, + DebugServers = 10, + DebugFree = 11, + DebugInterrupts = 12, } /// SYNC WITH `kernel/src/swap.rs` impl SwapAbi { @@ -36,6 +40,10 @@ impl SwapAbi { 6 => ReleaseMemory, 7 => WritePage, 8 => BlockErase, + 9 => DebugProcesses, + 10 => DebugServers, + 11 => DebugFree, + 12 => DebugInterrupts, _ => Invalid, } } @@ -46,18 +54,25 @@ impl SwapAbi { #[repr(usize)] pub enum Opcode { /// Userspace request to GC some physical pages - GarbageCollect, + GarbageCollect = 0, /// This call will only process full-page writes to an offset in SPI FLASH. /// The full-page criteria is acceptable because (a) we need the full page anyways /// due to the sector erase constraint and (b) the caller has to have the full page /// anyways because the page was read in and mapped into the caller's space at some /// point in time. - WritePage, - BulkErase, + WritePage = 1, + BulkErase = 2, /// Test messages #[cfg(feature = "swap-userspace-testing")] - Test0, - None, + Test0 = 3, + // kernel has to be compiled with "debug-proc" for these to work + // the Debug* series of opcodes are hard-coded in other crates, so don't change their discriminant. + DebugProcesses = 9, + DebugServers = 10, + DebugFree = 11, + DebugInterrupts = 12, + + None = 255, } /// An aligned structure for sending FLASH data between structures. This only works diff --git a/services/xous-swapper/src/main.rs b/services/xous-swapper/src/main.rs index 79cd87321..5be061593 100644 --- a/services/xous-swapper/src/main.rs +++ b/services/xous-swapper/src/main.rs @@ -822,6 +822,21 @@ fn main() { .expect("couldn't Block Erase region"); } } + Some(Opcode::DebugProcesses) => { + xous::rsyscall(xous::SysCall::SwapOp(SwapAbi::DebugProcesses as usize, 0, 0, 0, 0, 0, 0)) + .unwrap(); + } + Some(Opcode::DebugServers) => { + xous::rsyscall(xous::SysCall::SwapOp(SwapAbi::DebugServers as usize, 0, 0, 0, 0, 0, 0)) + .unwrap(); + } + Some(Opcode::DebugFree) => { + xous::rsyscall(xous::SysCall::SwapOp(SwapAbi::DebugFree as usize, 0, 0, 0, 0, 0, 0)).unwrap(); + } + Some(Opcode::DebugInterrupts) => { + xous::rsyscall(xous::SysCall::SwapOp(SwapAbi::DebugInterrupts as usize, 0, 0, 0, 0, 0, 0)) + .unwrap(); + } #[cfg(feature = "swap-userspace-testing")] Some(Opcode::Test0) => { log::info!("Free mem: {}kiB", get_free_pages() * PAGE_SIZE / 1024);