kernel: update debug and shell modules

This commit is contained in:
eupn 2023-03-14 18:32:52 +04:00
parent 38a02f9dbb
commit 3451d106f9
No known key found for this signature in database
GPG key ID: 0BBE77FB42014014
2 changed files with 31 additions and 25 deletions

View file

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2020 Sean Cross <sean@xobs.io> // SPDX-FileCopyrightText: 2020 Sean Cross <sean@xobs.io>
// SPDX-FileCopyrightText: 2022 Foundation Devices, Inc. <hello@foundationdevices.com> // SPDX-FileCopyrightText: 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
/// Prints to the debug output directly. /// Prints to the debug output directly.
@ -36,13 +36,13 @@ macro_rules! println {
#[macro_export] #[macro_export]
macro_rules! klog { macro_rules! klog {
() => ({ () => ({
print!(" [{}:{}]", file!(), line!()) println!(" [{}:{}]", file!(), line!())
}); });
($fmt:expr) => ({ ($fmt:expr) => ({
print!(concat!(" [{}:{} ", $fmt, "]"), file!(), line!()) println!(concat!(" [{}:{} ", $fmt, "]"), file!(), line!())
}); });
($fmt:expr, $($args:tt)+) => ({ ($fmt:expr, $($args:tt)+) => ({
print!(concat!(" [{}:{} ", $fmt, "]"), file!(), line!(), $($args)+) println!(concat!(" [{}:{} ", $fmt, "]"), file!(), line!(), $($args)+)
}); });
} }

View file

@ -1,12 +1,12 @@
// SPDX-FileCopyrightText: 2020 Sean Cross <sean@xobs.io> // SPDX-FileCopyrightText: 2020 Sean Cross <sean@xobs.io>
// SPDX-FileCopyrightText: 2022 Foundation Devices, Inc. <hello@foundationdevices.com> // SPDX-FileCopyrightText: 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use core::fmt;
use crate::{ use crate::{
args::KernelArguments, args::KernelArguments,
io::{SerialWrite, SerialRead}, io::{SerialRead, SerialWrite},
}; };
use core::fmt;
/// Instance of the shell output. /// Instance of the shell output.
pub static mut OUTPUT: Option<Output> = None; pub static mut OUTPUT: Option<Output> = None;
@ -53,12 +53,10 @@ impl fmt::Write for Output {
} }
/// Initialize the kernel shell. /// Initialize the kernel shell.
/// ///
/// This should be called in platform initialization code. /// This should be called in platform initialization code.
pub fn init(serial: &'static mut dyn SerialWrite) { pub fn init(serial: &'static mut dyn SerialWrite) {
unsafe { unsafe { OUTPUT = Some(Output::new(serial)) }
OUTPUT = Some(Output::new(serial))
}
// Print the processed kernel arguments // Print the processed kernel arguments
let args = KernelArguments::get(); let args = KernelArguments::get();
@ -66,14 +64,19 @@ pub fn init(serial: &'static mut dyn SerialWrite) {
for arg in args.iter() { for arg in args.iter() {
println!(" {}", arg); println!(" {}", arg);
} }
println!("=== Kernel Debug Shell Available ====");
print_help();
println!("=====================================");
} }
/// Process possible characters received through a serial interface. /// Process possible characters received through a serial interface.
/// ///
/// This should be called when a serial interface has new data, for example, /// This should be called when a serial interface has new data, for example,
/// on an interrupt. /// on an interrupt.
pub fn process_characters<R: SerialRead>(serial: &mut R) { pub fn process_characters<R: SerialRead>(serial: &mut R) {
while let Some(b) = serial.getc() { while let Some(b) = serial.getc() {
println!("> {}", b as char);
handle_character(b); handle_character(b);
} }
} }
@ -136,7 +139,7 @@ fn handle_character(b: u8) {
} }
}); });
println!( println!(
"{:?} conns:{}/32 {}", "{:x?} conns:{}/32 {}",
process, process,
connection_count, connection_count,
system_services.process_name(process.pid).unwrap_or("") system_services.process_name(process.pid).unwrap_or("")
@ -157,7 +160,7 @@ fn handle_character(b: u8) {
for process in &system_services.processes { for process in &system_services.processes {
if !process.free() { if !process.free() {
println!( println!(
"{:?} {}:", "{:x?} {}:",
process, process,
system_services.process_name(process.pid).unwrap_or("") system_services.process_name(process.pid).unwrap_or("")
); );
@ -214,17 +217,20 @@ fn handle_character(b: u8) {
} }
}); });
} }
b'h' => { b'h' => print_help(),
println!("Xous Kernel Debug");
println!("key | command");
println!("--- + -----------------------");
println!(" i | print irq handlers");
println!(" m | print MMU page tables of all processes");
println!(" p | print all processes");
println!(" P | print all processes and threads");
println!(" r | report RAM usage of all processes");
println!(" s | print all allocated servers");
}
_ => {} _ => {}
} }
} }
fn print_help() {
println!("Xous Kernel Debug");
println!("key | command");
println!("--- + -----------------------");
println!(" h | print this message");
println!(" i | print irq handlers");
println!(" m | print MMU page tables of all processes");
println!(" p | print all processes");
println!(" P | print all processes and threads");
println!(" r | report RAM usage of all processes");
println!(" s | print all allocated servers");
}