From fa067f11371c9e27ccf13ffcb7c8a29989e17499 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 22 Dec 2024 00:32:40 +0800 Subject: [PATCH] retrofit swapper so that its print function can be selected out so that we can share app uart with other processes that need it for debug --- services/xous-swapper/Cargo.toml | 6 ++++-- services/xous-swapper/src/debug.rs | 6 +++--- services/xous-swapper/src/main.rs | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/services/xous-swapper/Cargo.toml b/services/xous-swapper/Cargo.toml index 0c0ca0532..0367662df 100644 --- a/services/xous-swapper/Cargo.toml +++ b/services/xous-swapper/Cargo.toml @@ -40,7 +40,9 @@ renode = ["utralib/renode"] swap-userspace-testing = [] oom-doom = [] -debug-print = [ -] # mutually exclusive feature with other crates that use the app UART +# mutually exclusive feature with other crates that use the app UART +# requires "userspace-debug" to be passed to the loader for this to work. +debug-print-swapper = [] + debug-verbose = [] default = [] diff --git a/services/xous-swapper/src/debug.rs b/services/xous-swapper/src/debug.rs index e44834b01..33992fd84 100644 --- a/services/xous-swapper/src/debug.rs +++ b/services/xous-swapper/src/debug.rs @@ -2,7 +2,7 @@ use core::fmt::{Error, Write}; pub struct DebugUart {} impl DebugUart { - #[cfg(all(feature = "debug-print", any(feature = "precursor", feature = "renode")))] + #[cfg(all(feature = "debug-print-swapper", any(feature = "precursor", feature = "renode")))] pub fn putc(&mut self, c: u8) { use utralib::generated::*; let mut csr = CSR::new(loader::swap::SWAP_APP_UART_VADDR as *mut u32); @@ -12,7 +12,7 @@ impl DebugUart { csr.wfo(utra::app_uart::RXTX_RXTX, c as u32); } - #[cfg(all(feature = "debug-print", any(feature = "cramium-soc")))] + #[cfg(all(feature = "debug-print-swapper", any(feature = "cramium-soc")))] pub fn putc(&mut self, c: u8) { use cramium_hal::udma; // safety: safe to call as long as the raw parts are initialized and we exclusively @@ -30,7 +30,7 @@ impl DebugUart { uart.write(&[c]); } - #[cfg(not(feature = "debug-print"))] + #[cfg(not(feature = "debug-print-swapper"))] pub fn putc(&self, _c: u8) {} } diff --git a/services/xous-swapper/src/main.rs b/services/xous-swapper/src/main.rs index 9f56c2858..aa6058485 100644 --- a/services/xous-swapper/src/main.rs +++ b/services/xous-swapper/src/main.rs @@ -330,7 +330,7 @@ fn write_to_swap_inner( }; // step 2: write the page to swap - #[cfg(feature = "debug-print")] + #[cfg(feature = "debug-print-swapper")] writeln!(DebugUart {}, "WTS PID{} VA {:x}", candidate.raw_pid(), candidate.vaddr()).ok(); // this is safe because the page is aligned and initialized as it comes from the kernel // remember that this page is overwritten with encrypted data @@ -448,7 +448,7 @@ fn swap_handler( // swapper is not allowed to use `log` for debugging under most circumstances, because // the swapper can't send messages when handling a swap call. Instead, we use a local - // debug UART to handle this. This needs to be enabled with the "debug-print" feature + // debug UART to handle this. This needs to be enabled with the "debug-print-swapper" feature // and is mutually exclusive with the "gdb-stub" feature in the kernel since it uses // the same physical hardware. sss.inner = Some(SwapperSharedState { @@ -507,7 +507,7 @@ fn swap_handler( }; // clear the used bit in swap ss.sct.counts[paddr_in_swap / PAGE_SIZE] &= !loader::FLG_SWAP_USED; - #[cfg(feature = "debug-print")] + #[cfg(feature = "debug-print-swapper")] writeln!( DebugUart {}, "RFS PID{} VA {:x} PA {:x} counts {:x}",