This commit is contained in:
Garen Tyler 2023-11-04 17:17:03 -06:00
parent 54753062e4
commit 42a3ff4c24
Signed by: garentyler
GPG Key ID: D7A048C454CB7054
6 changed files with 50 additions and 37 deletions

View File

@ -90,7 +90,6 @@ void userinit(void);
void wakeup(void *chan);
int either_copyout(int user_dst, uint64 dst, void *src, uint64 len);
int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
void procdump(void);
// swtch.S
void swtch(struct context *, struct context *);

View File

@ -157,35 +157,3 @@ either_copyin(void *dst, int user_src, uint64 src, uint64 len)
return 0;
}
}
// Print a process listing to console. For debugging.
// Runs when user types ^P on console.
// No lock to avoid wedging a stuck machine further.
void procdump(void)
{
static char *states[] = {
[UNUSED] "unused",
[USED] "used",
[SLEEPING] "sleep ",
[RUNNABLE] "runble",
[RUNNING] "run ",
[ZOMBIE] "zombie"
};
struct proc *p;
char *state;
printstr("\n");
for(p = proc; p < &proc[NPROC]; p++){
if(p->state == UNUSED)
continue;
if(p->state >= 0 && p->state < NELEM(states) && states[p->state])
state = states[p->state];
else
state = "???";
printint(p->pid);
printstr(" ");
printstr(state);
printstr("\n");
}
}

View File

@ -5,7 +5,7 @@ pub use crate::panic;
pub static PRINT_LOCK: Lock = Lock::new();
/// Print out formatted text to the UART.
/// Print out formatted text to the console.
/// Spins to acquire the lock.
macro_rules! print {
($($arg:tt)*) => {{
@ -28,6 +28,34 @@ macro_rules! println {
}
pub(crate) use println;
/// Print out formatted text to the UART.
/// Does not use any locks.
macro_rules! uprint {
($($arg:tt)*) => {{
use $crate::console::uart::Uart;
use core::fmt::Write;
// Do some casts to get a mutable reference.
// Safe because Uart's core::fmt::Write implementation
// only uses the &mut reference immutably.
let uart: *const Uart = &$crate::console::uart::UART0 as *const Uart;
let uart: &mut Uart = unsafe { &mut *uart.cast_mut() };
let _ = core::write!(uart, $($arg)*);
}};
}
pub(crate) use uprint;
macro_rules! uprintln {
($($arg:tt)*) => {{
use $crate::console::printf::uprint;
uprint!($($arg)*);
uprint!("\n");
}};
}
pub(crate) use uprintln;
#[no_mangle]
pub extern "C" fn printint(n: i32) {
print!("{}", n);

View File

@ -187,3 +187,9 @@ impl Uart {
}
}
}
impl core::fmt::Write for Uart {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
self.write_slice(s.as_bytes());
core::fmt::Result::Ok(())
}
}

View File

@ -24,7 +24,7 @@ mod trap;
use crate::{proc::cpu::Cpu, sync::mutex::Mutex};
use core::ffi::{c_char, CStr};
pub(crate) use crate::console::printf::{print, println};
pub(crate) use crate::console::printf::{print, println, uprint, uprintln};
pub static mut STARTED: bool = false;
pub static PANICKED: Mutex<bool> = Mutex::new(false);

View File

@ -23,8 +23,8 @@ use crate::{
copyout, mappages, uvmalloc, uvmcopy, uvmcreate, uvmdealloc, uvmfree, uvmunmap,
},
},
string::safestrcpy,
sync::spinlock::Spinlock,
uprintln,
};
use core::{
ffi::{c_char, c_void},
@ -51,7 +51,7 @@ extern "C" {
// pub fn fork() -> i32;
// pub fn exit(status: i32) -> !;
pub fn wait(addr: u64) -> i32;
pub fn procdump();
// pub fn procdump();
pub fn proc_mapstacks(kpgtbl: Pagetable);
}
@ -504,3 +504,15 @@ pub unsafe extern "C" fn proc_pagetable(p: *mut Process) -> Pagetable {
pub unsafe extern "C" fn proc_freepagetable(pagetable: Pagetable, size: u64) {
Process::free_pagetable(pagetable, size as usize)
}
/// Print a process listing to console for debugging.
/// Runs when a user types ^P on console.
/// No lock to avoid wedging a stuck machine further.
pub unsafe fn procdump() {
uprintln!("\nprocdump:");
for p in &proc {
if p.state != ProcessState::Unused {
uprintln!(" {}: {:?}", p.pid, p.state);
}
}
}