diff --git a/srcs/cli/commands/debugfs.rs b/srcs/cli/commands/debugfs.rs index 2df9ce4f..33815a0d 100644 --- a/srcs/cli/commands/debugfs.rs +++ b/srcs/cli/commands/debugfs.rs @@ -10,10 +10,10 @@ pub static CURRENTDIR_INODE: Mutex = Mutex::new(ROOT_INODE); pub static PWD: Mutex> = Mutex::new(None); pub static DISKNO: Mutex> = Mutex::new(None); +use crate::println; + fn help() { - crate::kprintln!( - "Command available: ls,stat,cat,imap,cd,touch,mkdir,rm,pwd,test" - ); + println!("Command available: ls,stat,cat,imap,cd,touch,mkdir,rm,pwd,test"); } pub fn debugfs(mut command: Vec) { @@ -31,7 +31,7 @@ pub fn debugfs(mut command: Vec) { "pwd" => pwd(), "test" => test(), _ => { - crate::kprintln!("Unknown command: {}", command[0]); + println!("Unknown command: {}", command[0]); help(); } } @@ -41,17 +41,17 @@ pub fn debugfs(mut command: Vec) { } fn pwd() { - crate::kprintln!( + println!( "[pwd] INODE: {:>6} PATH: {}", *CURRENTDIR_INODE.lock(), PWD.lock().as_ref().unwrap_or(&Path::new("/")) ); - crate::kprintln!("[root] INODE: {:>6} PATH: /", ROOT_INODE); + println!("[root] INODE: {:>6} PATH: /", ROOT_INODE); } fn rm(command: Vec) { if command.len() < 2 { - crate::kprintln!("usage: debugfs rm FILE"); + println!("usage: debugfs rm FILE"); return; } ext2::remove_file( @@ -63,7 +63,7 @@ fn rm(command: Vec) { fn stat(command: Vec) { if command.len() < 2 { - crate::kprintln!("usage: debugfs stat FILE"); + println!("usage: debugfs stat FILE"); return; } ext2::show_inode_info( @@ -75,7 +75,7 @@ fn stat(command: Vec) { fn mkdir(command: Vec) { if command.len() < 2 { - crate::kprintln!("usage: debugfs mkdir DIR"); + println!("usage: debugfs mkdir DIR"); return; } ext2::create_dir( @@ -87,7 +87,7 @@ fn mkdir(command: Vec) { fn touch(command: Vec) { if command.len() < 2 { - crate::kprintln!("usage: debugfs touch FILE"); + println!("usage: debugfs touch FILE"); return; } ext2::create_file( @@ -99,7 +99,7 @@ fn touch(command: Vec) { fn cat(command: Vec) { if command.len() < 2 { - crate::kprintln!("usage: debugfs cat FILE"); + println!("usage: debugfs cat FILE"); return; } let file_content = ext2::get_file_content( @@ -137,7 +137,7 @@ fn ls(command: Vec) { for i in dentries { crate::kprint!("{} ", i.name); } - crate::kprintln!(""); + println!(""); } fn cd(command: Vec) { @@ -150,7 +150,7 @@ fn cd(command: Vec) { let ext2 = binding.as_ref().unwrap(); let lookup = ext2.recurs_find(path.as_str(), *CURRENTDIR_INODE.lock()); match lookup { - None => crate::kprintln!("Dir not found"), + None => println!("Dir not found"), Some((inodeno, inode)) => { if inode.is_dir() { *CURRENTDIR_INODE.lock() = inodeno; @@ -166,7 +166,7 @@ fn cd(command: Vec) { pwd.cleanup(); *PWD.lock() = Some(pwd); } else { - crate::kprintln!("Error: {} is not a directory", path.as_str()); + println!("Error: {} is not a directory", path.as_str()); } }, }; diff --git a/srcs/cli/commands/hexdump.rs b/srcs/cli/commands/hexdump.rs index 06a50ce1..d376ce8c 100644 --- a/srcs/cli/commands/hexdump.rs +++ b/srcs/cli/commands/hexdump.rs @@ -1,6 +1,6 @@ use crate::alloc::string::String; use crate::alloc::vec::Vec; -use crate::kprintln; +use crate::println; use crate::vga_buffer::hexdump; pub fn hextou(string: &str) -> Option { @@ -31,24 +31,24 @@ pub fn hexdump_parser(command: Vec) { let mut args: [usize; 2] = [0, 0]; if command.len() != 3 { - kprintln!("Invalid number of arguments."); - kprintln!("Usage: hexdump [addr] [size]"); + println!("Invalid number of arguments."); + println!("Usage: hexdump [addr] [size]"); return; } if let Some(res) = atou(command[1].as_str()) { args[0] = res; } else { - kprintln!("Invalid number of arguments."); - kprintln!("Usage: hexdump [addr] [size]"); + println!("Invalid number of arguments."); + println!("Usage: hexdump [addr] [size]"); return; } if let Some(res) = atou(command[2].as_str()) { args[1] = res; } else { - kprintln!("Invalid number of arguments."); - kprintln!("Usage: hexdump [addr] [size]"); + println!("Invalid number of arguments."); + println!("Usage: hexdump [addr] [size]"); return; } diff --git a/srcs/cli/commands/mod.rs b/srcs/cli/commands/mod.rs index fcf450f3..6dbc71b5 100644 --- a/srcs/cli/commands/mod.rs +++ b/srcs/cli/commands/mod.rs @@ -8,7 +8,7 @@ use crate::syscalls::signal::sys_kill; use crate::syscalls::timer::sys_getppid; use crate::vec::Vec; use crate::vga_buffer::screenclear; -use crate::{io, kprint, kprintln}; +use crate::{io, kprint, print, println}; // Commands modules pub mod debugfs; @@ -61,16 +61,16 @@ fn play(command: Vec) { if command.len() == 2 { sound = command[1].as_str(); } - crate::kprintln!("sound: {}", sound); + println!("sound: {}", sound); crate::sound::play(sound); } fn clear(_: Vec) { screenclear!(); } fn help(_: Vec) { - kprintln!("Available commands:"); + println!("Available commands:"); for i in KNOWN_CMD { - kprintln!(" {}", i); + println!(" {}", i); } } @@ -91,8 +91,8 @@ use crate::keyboard::{KEYMAP, KEYMAP_FR, KEYMAP_US}; fn keymap(command: Vec) { if command.len() != 2 { - kprintln!("Invalid number of arguments."); - kprintln!("Usage: keymap {{us, fr}}"); + println!("Invalid number of arguments."); + println!("Usage: keymap {{us, fr}}"); return; } @@ -101,8 +101,8 @@ fn keymap(command: Vec) { } else if command[1] == "fr" { unsafe { KEYMAP = &KEYMAP_FR }; } else { - kprintln!("Invalid argument."); - kprintln!("Usage: keymap {{us, fr}}"); + println!("Invalid argument."); + println!("Usage: keymap {{us, fr}}"); } } @@ -112,22 +112,22 @@ fn interrupt(command: Vec) { let arg: usize; if command.len() != 2 { - kprintln!("Invalid number of arguments."); - kprintln!("Usage: int [nb]"); + println!("Invalid number of arguments."); + println!("Usage: int [nb]"); return; } if let Some(res) = hexdump::atou(command[1].as_str()) { arg = res; } else { - kprintln!("Invalid number of arguments."); - kprintln!("Usage: hexdump [addr] [size]"); + println!("Invalid number of arguments."); + println!("Usage: hexdump [addr] [size]"); return; } if arg > 255 { - kprintln!("Invalid argument."); - kprintln!("Usage: int [nb]"); + println!("Invalid argument."); + println!("Usage: int [nb]"); return; } unsafe { int(arg as u8) }; @@ -191,7 +191,7 @@ impl Command { let tmp: &str = &self.command[self.index - 1..self.command.len()]; self.index -= 1; - crate::kprint!( + print!( "{delbyte}{string} {delbyte}", string = tmp, delbyte = '\x08' @@ -202,17 +202,17 @@ impl Command { } } else if charcode >= ' ' && charcode <= '~' { if self.insert(charcode).is_err() { - kprintln!("Can't handle longer command, clearing buffer"); - kprint!("$> "); + println!("Can't handle longer command, clearing buffer"); + print!("$> "); self.clear(); } let tmp: &str = &self.command[self.index - 1..self.command.len()]; - crate::kprint!("{}", tmp); + print!("{}", tmp); crate::vga_buffer::WRITER .lock() .move_cursor(-(tmp.len() as i32) + 1); } else if charcode == '\n' { - crate::kprint!("{}", charcode); + print!("{}", charcode); match self.is_known() { Some(x) => { unsafe { LOCK_CMD = true }; @@ -250,12 +250,12 @@ impl Command { }, _ => { if self.command.len() != 0 { - kprintln!("Unknown command. Type `help` to list available commands"); + println!("Unknown command. Type `help` to list available commands"); } }, } self.clear(); - kprint!("$> "); + print!("$> "); } } } diff --git a/srcs/cli/commands/process.rs b/srcs/cli/commands/process.rs index b27bfef1..fd270d7a 100644 --- a/srcs/cli/commands/process.rs +++ b/srcs/cli/commands/process.rs @@ -1,6 +1,6 @@ use crate::alloc::string::String; use crate::alloc::vec::Vec; -use crate::kprintln; +use crate::println; use crate::cli::commands::hexdump::atou; use crate::proc::process::{Pid, Process}; @@ -10,15 +10,15 @@ pub fn pmap(command: Vec) { let pid: Pid; if command.len() != 2 { - kprintln!("Invalid argument."); - kprintln!("Usage: pmap [pid]"); + println!("Invalid argument."); + println!("Usage: pmap [pid]"); return; } if let Some(res) = atou(command[1].as_str()) { pid = res as Pid; } else { - kprintln!("Invalid argument."); - kprintln!("Usage: pmap [pid]"); + println!("Invalid argument."); + println!("Usage: pmap [pid]"); return; } @@ -29,42 +29,42 @@ pub fn pmap(command: Vec) { }; let process = binding.lock(); let mut used_size: usize = 0; - crate::kprintln!("{}:", pid); - crate::kprintln!("{}", process.heap); + println!("{}:", pid); + println!("{}", process.heap); used_size += process.heap.size; - crate::kprintln!("{}", process.stack); + println!("{}", process.stack); used_size += process.stack.size; - crate::kprintln!("{}", process.kernel_stack); + println!("{}", process.kernel_stack); used_size += process.kernel_stack.size; for i in &process.mem_map { let guard = i.lock(); - crate::kprintln!("{}", *guard); + println!("{}", *guard); used_size += guard.size; } - crate::kprintln!(" total: {:#x}", used_size); + println!(" total: {:#x}", used_size); } pub fn kill(command: Vec) { let pid: Pid; if command.len() != 2 { - kprintln!("Invalid argument."); - kprintln!("Usage: kill [pid]"); + println!("Invalid argument."); + println!("Usage: kill [pid]"); return; } if let Some(res) = atou(command[1].as_str()) { pid = res as Pid; } else { - kprintln!("Invalid argument."); - kprintln!("Usage: kill [pid]"); + println!("Invalid argument."); + println!("Usage: kill [pid]"); return; } let res: i32 = sys_kill(pid, 9); // SIGKILL if res != 0 { - kprintln!("[Error]: {}", res); + println!("[Error]: {}", res); return; } } diff --git a/srcs/cli/commands/time.rs b/srcs/cli/commands/time.rs index e4a886e6..30aaff22 100644 --- a/srcs/cli/commands/time.rs +++ b/srcs/cli/commands/time.rs @@ -1,19 +1,20 @@ use crate::alloc::string::String; use crate::alloc::vec::Vec; +use crate::println; + pub fn jiffies(_: Vec) { - crate::kprintln!("Jiffies: {}", crate::time::jiffies()); + println!("Jiffies: {}", crate::time::jiffies()); } pub fn uptime(_: Vec) { let time = crate::time::get_timestamp(); - crate::kprintln!( + println!( "Time elapsed since boot: {}s {}ms", - time.second, - time.millisecond + time.second, time.millisecond ); } pub fn date(_: Vec) { - crate::kprintln!("{}", crate::cmos::get_time()); + println!("{}", crate::cmos::get_time()); } diff --git a/srcs/cli/commands/valgrind.rs b/srcs/cli/commands/valgrind.rs index 46e9b5e3..0640ee75 100644 --- a/srcs/cli/commands/valgrind.rs +++ b/srcs/cli/commands/valgrind.rs @@ -1,12 +1,12 @@ use crate::alloc::string::String; use crate::alloc::vec::Vec; -use crate::kprintln; +use crate::println; pub fn valgrind(command: Vec) { if command.len() < 2 { - kprintln!("Invalid argument."); - kprintln!("Usage: valgrind [command] [command args]"); + println!("Invalid argument."); + println!("Usage: valgrind [command] [command args]"); return; } @@ -17,7 +17,7 @@ pub fn valgrind(command: Vec) { let cmd_id = super::KNOWN_CMD.iter().position(|&x| x == sub_command[0]); match cmd_id { Some(index) => super::COMMANDS[index](sub_command.to_vec()), - None => kprintln!("Command: [{}] not found", sub_command[0]) + None => println!("Command: [{}] not found", sub_command[0]) } let mut current_state = unsafe { crate::KTRACKER }; @@ -25,14 +25,14 @@ pub fn valgrind(command: Vec) { current_state.allocated_bytes -= heap_state.allocated_bytes; current_state.freed -= heap_state.freed; current_state.freed_bytes -= heap_state.freed_bytes; - crate::kprintln!("{}", current_state); + crate::println!("{}", current_state); if current_state.allocated_bytes < current_state.freed_bytes { - crate::kprintln!( + crate::println!( "Too much bytes freed: {}", current_state.freed_bytes - current_state.allocated_bytes ); } else { - crate::kprintln!( + crate::println!( "Leaks: {} bytes", current_state.allocated_bytes - current_state.freed_bytes ); diff --git a/srcs/kmain.rs b/srcs/kmain.rs index 1f18d93e..27523d82 100644 --- a/srcs/kmain.rs +++ b/srcs/kmain.rs @@ -1,7 +1,7 @@ use crate::syscalls::exit::sys_waitpid; use crate::vga_buffer::change_color; use crate::vga_buffer::color::Color; -use crate::{kprint, kprintln, string}; +use crate::{kprint, kprintln, print, println, string}; mod poc { use sys_macros::Poc; @@ -47,15 +47,15 @@ pub extern "C" fn kmain() -> ! { } } - kprintln!("Hello World of {}!", 42); + println!("Hello World of {}!", 42); change_color!(Color::Red, Color::White); let workspace_msg = string::String::from( "Press Ctrl-2 to navigate to the second workspace" ); - kprintln!("{}", workspace_msg); + println!("{}", workspace_msg); change_color!(Color::White, Color::Black); - kprint!("$> "); + print!("$> "); let mut pid = unsafe { crate::exec_fn!(crate::cli::cli) }; loop { // Auto-remove all zombies on pid 0 and relaunch cli if killed @@ -63,7 +63,7 @@ pub extern "C" fn kmain() -> ! { let ret = sys_waitpid(-1, &mut status, 0); if ret == pid { crate::dprintln!("Term has been killed"); - kprint!("$> "); + print!("$> "); pid = unsafe { crate::exec_fn!(crate::cli::cli) }; } } diff --git a/srcs/multiboot/mod.rs b/srcs/multiboot/mod.rs index e3e411c3..7043fad0 100644 --- a/srcs/multiboot/mod.rs +++ b/srcs/multiboot/mod.rs @@ -167,25 +167,29 @@ pub fn read_tags() { break; }, x if x as u32 == TagType::CmdLine as u32 => { - kprint!("Command line = "); let cstr: &[u8] = core::slice::from_raw_parts( (tag_ptr as *const u8).offset(8), (*tag_ptr).size as usize - 8 - 1 /* remove size and '\0' */ ); match core::str::from_utf8(cstr) { - Ok(string) => kprintln!("{}", string), - Err(error) => kprintln!("[Error]: {}", error) + Ok(string) => kprintln!("Command line = {}", string), + Err(error) => { + kprintln!("Command line = [Error]: {}", error) + } } }, x if x as u32 == TagType::BootLoaderName as u32 => { - kprint!("Boot loader name = "); let cstr: &[u8] = core::slice::from_raw_parts( (tag_ptr as *const u8).offset(8), (*tag_ptr).size as usize - 8 - 1 /* remove size and '\0' */ ); match core::str::from_utf8(cstr) { - Ok(string) => kprintln!("{}", string), - Err(error) => kprintln!("[Error]: {}", error) + Ok(string) => { + kprintln!("Boot loader name = {}", string) + }, + Err(error) => { + kprintln!("Boot loader name = [Error]: {}", error) + } } }, x if x as u32 == TagType::BasicMemInfo as u32 => { @@ -197,10 +201,9 @@ pub fn read_tags() { ); }, x if x as u32 == TagType::BootDev as u32 => { - kprint!("Boot device "); let elem: &BootDev = &*(tag_ptr as *const _); kprintln!( - "{:#x}, {}, {}", + "Boot device {:#x}, {}, {}", elem.biosdev, elem.partition, elem.sub_partition diff --git a/srcs/proc/process.rs b/srcs/proc/process.rs index c2243498..0e87efdc 100644 --- a/srcs/proc/process.rs +++ b/srcs/proc/process.rs @@ -36,6 +36,8 @@ use crate::KSTACK_ADDR; use crate::fs::FileInfo; use alloc::sync::Arc; +use crate::println; + pub type Pid = Id; pub static mut NEXT_PID: Pid = 0; @@ -105,7 +107,7 @@ impl Process { pub fn print_tree() { unsafe { for process in PROCESS_TREE.values() { - crate::kprintln!("{}", *process.lock()); + println!("{}", *process.lock()); } } } @@ -368,13 +370,9 @@ impl Process { } pub unsafe fn print_all_process() { - crate::kprintln!( + println!( "{:>10} {:>10} {:>20} {:>10} {}", - "PID", - "PPID", - "NAME", - "OWNER", - "STATUS" + "PID", "PPID", "NAME", "OWNER", "STATUS" ); Self::print_tree(); } diff --git a/srcs/test.rs b/srcs/test.rs index 183dfc98..4ab11a16 100644 --- a/srcs/test.rs +++ b/srcs/test.rs @@ -1,6 +1,8 @@ use crate::vga_buffer::color::Color; use crate::{io, vga_buffer, KTRACKER}; +use crate::{kprintln, println}; + #[cfg(test)] #[macro_export] macro_rules! function { @@ -20,7 +22,7 @@ macro_rules! function { #[macro_export] macro_rules! print_fn { () => { - crate::kprint!("{:40}{}", crate::function!(), ""); + $crate::print!("{:40}{}", $crate::function!(), ""); }; } @@ -34,9 +36,9 @@ pub fn leaks() -> bool { #[cfg(test)] pub fn test_runner(tests: &[&dyn Fn()]) { use crate::memory::paging::bitmap::physmap_as_mut; - crate::kprintln!("Running {} tests", tests.len()); + kprintln!("Running {} tests", tests.len()); let used_pages = physmap_as_mut().used; - crate::kprintln!("Kernel as mapped {} pages", used_pages); + kprintln!("Kernel as mapped {} pages", used_pages); for test in tests { let pages_before_test = physmap_as_mut().used; test.run(); @@ -46,17 +48,14 @@ pub fn test_runner(tests: &[&dyn Fn()]) { panic!("Memory leaks test failed"); } if pages_before_test != pages_after_test { - crate::kprintln!( + kprintln!( "Before {} pages\n After {} pages", pages_before_test, pages_after_test ); } } - crate::kprintln!( - "Kernel uses {} more pages", - physmap_as_mut().used - used_pages - ); + kprintln!("Kernel uses {} more pages", physmap_as_mut().used - used_pages); crate::memory_state(); io::outb(0xf4, 0x10); } @@ -74,7 +73,7 @@ where fn run(&self) { self(); vga_buffer::change_color!(Color::Green, Color::Black); - crate::kprintln!("[ok]"); + println!("[ok]"); vga_buffer::change_color!(Color::White, Color::Black); } } diff --git a/srcs/vga_buffer/mod.rs b/srcs/vga_buffer/mod.rs index 75ea19bf..6eb65e89 100644 --- a/srcs/vga_buffer/mod.rs +++ b/srcs/vga_buffer/mod.rs @@ -237,7 +237,22 @@ macro_rules! kprint { macro_rules! kprintln { () => ($crate::kprint!("\n")); ($($arg:tt)*) => ( - $crate::kprint!("{}\n", format_args!($($arg)*)) + $crate::kprint!("[{:>12.6}] {}\n", $crate::time::get_timestamp().as_f64(), format_args!($($arg)*)) + ) +} + +#[macro_export] +macro_rules! print { + ($($arg:tt)*) => ( + $crate::kprint!("{}", format_args!($($arg)*)) + ) +} + +#[macro_export] +macro_rules! println { + () => ($crate::print!("\n")); + ($($arg:tt)*) => ( + $crate::print!("{}\n", format_args!($($arg)*)) ) }