From 5bd9e40ace7f49b8d36218d67ac404a04ec2c9ab Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 10 May 2021 14:13:24 +0800 Subject: [PATCH] kernel: riscv: add `print_thread_*` family These calls can be used to print out thread information for debugging. This augments the existing `print_thread()` call, which has been renamed to `print_current_thread()`. Signed-off-by: Sean Cross --- kernel/src/arch/riscv/irq.rs | 2 +- kernel/src/arch/riscv/process.rs | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/kernel/src/arch/riscv/irq.rs b/kernel/src/arch/riscv/irq.rs index 2df99b25b..3f84ddd14 100644 --- a/kernel/src/arch/riscv/irq.rs +++ b/kernel/src/arch/riscv/irq.rs @@ -180,7 +180,7 @@ pub extern "C" fn trap_handler( println!("SYSTEM HALT: CPU Exception on PID {}: {}", pid, ex); ArchProcess::with_current(|process| { println!("Current thread {}:", process.current_tid()); - process.print_thread(); + process.print_current_thread(); }); MemoryMapping::current().print_map(); loop {} diff --git a/kernel/src/arch/riscv/process.rs b/kernel/src/arch/riscv/process.rs index 4df384389..ec7824101 100644 --- a/kernel/src/arch/riscv/process.rs +++ b/kernel/src/arch/riscv/process.rs @@ -353,8 +353,25 @@ impl Process { Ok(()) } - pub fn print_thread(&self) { - let _thread = self.current_thread(); + pub fn print_all_threads(&self) { + let process = unsafe { &mut *PROCESS }; + &mut process.threads[process.hardware_thread - 1]; + for (tid_idx, &thread) in process.threads.iter().enumerate() { + let tid = tid_idx + 1; + if thread.registers[1] != 0 { + Self::print_thread(tid, &thread); + } + } + } + + pub fn print_current_thread(&self) { + let thread = self.current_thread(); + let tid = self.current_tid(); + Self::print_thread(tid, &thread); + } + + pub fn print_thread(_tid: TID, _thread: &Thread) { + println!("Thread {}:", _tid); println!( "PC:{:08x} SP:{:08x} RA:{:08x}", _thread.sepc, _thread.registers[1], _thread.registers[0]