From bb56af20ed036bed8d9d2f8bf68376ce4d55e79a Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Wed, 24 Aug 2022 19:33:08 -0700 Subject: Rename to serial print --- src/draw.rs | 40 ++++++++++++++++++++-------------------- src/kernel.rs | 24 ++++++++++++------------ src/mem/alloc.rs | 50 +++++++++++++++++++++++++------------------------- src/panic_wait.rs | 4 ++-- src/print.rs | 18 +++++++++--------- src/util/fifo_queue.rs | 22 +++++++++++----------- 6 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/draw.rs b/src/draw.rs index 907aa5c..9327715 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -1,29 +1,29 @@ //! Flag Drawing //! //! Provides Ukrainian flag and American flag. -use crate::println; +use crate::serial_println; pub fn draw_american_flag() { - println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); - println!("\x1b[97;104m * * * * * \x1b[107m \x1b[0m"); - println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); - println!("\x1b[97;104m * * * * * \x1b[107m \x1b[0m"); - println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); - println!("\x1b[97;104m * * * * * \x1b[107m \x1b[0m"); - println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); - println!("\x1b[97;104m * * * * * \x1b[107m \x1b[0m"); - println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); - println!("\x1b[107m \x1b[0m"); - println!("\x1b[101m \x1b[0m"); - println!("\x1b[107m \x1b[0m"); - println!("\x1b[101m \x1b[0m"); + serial_println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); + serial_println!("\x1b[97;104m * * * * * \x1b[107m \x1b[0m"); + serial_println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); + serial_println!("\x1b[97;104m * * * * * \x1b[107m \x1b[0m"); + serial_println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); + serial_println!("\x1b[97;104m * * * * * \x1b[107m \x1b[0m"); + serial_println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); + serial_println!("\x1b[97;104m * * * * * \x1b[107m \x1b[0m"); + serial_println!("\x1b[97;104m * * * * * * \x1b[101m \x1b[0m"); + serial_println!("\x1b[107m \x1b[0m"); + serial_println!("\x1b[101m \x1b[0m"); + serial_println!("\x1b[107m \x1b[0m"); + serial_println!("\x1b[101m \x1b[0m"); } pub fn draw_ukraine_flag() { - println!("\x1b[30;104m \x1b[0m"); - println!("\x1b[30;104m Slava \x1b[0m"); - println!("\x1b[30;104m \x1b[0m"); - println!("\x1b[30;103m \x1b[0m"); - println!("\x1b[30;103m Ukraina \x1b[0m"); - println!("\x1b[30;103m \x1b[0m"); + serial_println!("\x1b[30;104m \x1b[0m"); + serial_println!("\x1b[30;104m Slava \x1b[0m"); + serial_println!("\x1b[30;104m \x1b[0m"); + serial_println!("\x1b[30;103m \x1b[0m"); + serial_println!("\x1b[30;103m Ukraina \x1b[0m"); + serial_println!("\x1b[30;103m \x1b[0m"); } diff --git a/src/kernel.rs b/src/kernel.rs index 24de020..ff33f48 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -44,9 +44,9 @@ use crate::mem::alloc::allocator; /// - format! /// - UART /// - print! -/// - println! +/// - serial_println! /// - vprint! -/// - vprintln! +/// - vserial_println! /// /// After initialization, jump to /// the regular main. @@ -65,22 +65,22 @@ fn kernel_main() -> ! { #[cfg(feature = "flag")] { draw::draw_ukraine_flag(); - println!(); + serial_println!(); draw::draw_american_flag(); - println!(); + serial_println!(); } - println!( + serial_println!( "\x1b[91mInitialized\x1b[0m \x1b[92m{}\x1b[0m \x1b[93mv{}\x1b[0m", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION") ); - println!( + serial_println!( "\x1b[94mAuthors:\x1b[0m \x1b[95m{}\x1b[0m", env!("CARGO_PKG_AUTHORS") ); use crate::console::interface::Statistics; - println!( + serial_println!( "Characters written to UART: \x1b[91m{}\x1b[0m", console().chars_written() ); @@ -93,7 +93,7 @@ fn kernel_main() -> ! { } fn run_verbose() { - println!("U8: {:?}", mem::alloc::U8_GRAND_ALLOC); + serial_println!("U8: {:?}", mem::alloc::U8_GRAND_ALLOC); { let mut s = String::new(); for _ in 0..128 { @@ -109,7 +109,7 @@ fn run_verbose() { { let a: Box = Box::new(1); assert_eq!(*a, 1); - println!("{}", a); + serial_println!("{}", a); } { let a: Box = Box::new(2); @@ -118,7 +118,7 @@ fn run_verbose() { assert_eq!(*a, 2); assert_eq!(*b, 3); assert_eq!(*c, 4); - println!("{} {} {}", a, b, c); + serial_println!("{} {} {}", a, b, c); } { let a: Box = Box::new(5); @@ -127,10 +127,10 @@ fn run_verbose() { assert_eq!(*a, 5); assert_eq!(*b, 6); assert_eq!(*c, 7); - println!("{} {} {}", a, b, c); + serial_println!("{} {} {}", a, b, c); } use crate::console::interface::Statistics; - println!( + serial_println!( "Characters written to UART: \x1b[91m{}\x1b[0m", console().chars_written() ); diff --git a/src/mem/alloc.rs b/src/mem/alloc.rs index a388c85..514f34f 100644 --- a/src/mem/alloc.rs +++ b/src/mem/alloc.rs @@ -5,7 +5,7 @@ use super::types::*; use crate::sync::interface::Mutex; use crate::sync::NullLock; -use crate::vprintln; +use crate::serial_vprintln; use alloc::alloc::{GlobalAlloc, Layout}; use os_pic::init_lifo_queue; use os_pic::util::lifo_queue::LifoQueue; @@ -33,27 +33,27 @@ init_lifo_queue!(U4096_GRAND_ALLOC, GRAND_ALLOC_SIZE, { U4096::new() }, U4096); impl GrandAllocator { pub fn init(&self) -> Result<(), &'static str> { - vprintln!("GA: \x1b[93mInit U8 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U8 Pool\x1b[0m"); U8_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[93mInit U16 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U16 Pool\x1b[0m"); U16_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[93mInit U32 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U32 Pool\x1b[0m"); U32_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[93mInit U64 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U64 Pool\x1b[0m"); U64_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[93mInit U128 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U128 Pool\x1b[0m"); U128_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[93mInit U256 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U256 Pool\x1b[0m"); U256_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[93mInit U512 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U512 Pool\x1b[0m"); U512_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[93mInit U1024 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U1024 Pool\x1b[0m"); U1024_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[93mInit U2048 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U2048 Pool\x1b[0m"); U2048_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[93mInit U4096 Pool\x1b[0m"); + serial_vprintln!("GA: \x1b[93mInit U4096 Pool\x1b[0m"); U4096_GRAND_ALLOC.init(); - vprintln!("GA: \x1b[94mPools Initialized!\x1b[0m"); + serial_vprintln!("GA: \x1b[94mPools Initialized!\x1b[0m"); Ok(()) } } @@ -63,7 +63,7 @@ unsafe impl GlobalAlloc for GrandAllocator { /// /// Allocate the fixed size chunks unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - vprintln!("GA: Allocating chunk of size {}!", layout.size()); + serial_vprintln!("GA: Allocating chunk of size {}!", layout.size()); match layout.size() { 1 => match U8_GRAND_ALLOC.pop() { None => { @@ -155,7 +155,7 @@ unsafe impl GlobalAlloc for GrandAllocator { /// /// Deallocate the fixed size chunks by searching for them unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - vprintln!("GA: Deallocating chunk of size {}!", layout.size()); + serial_vprintln!("GA: Deallocating chunk of size {}!", layout.size()); match layout.size() { 1 => { U8_GRAND_ALLOC.inner.lock(|pool| { @@ -165,7 +165,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U8_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } 2 => { @@ -176,7 +176,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U16_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } 3..=4 => { @@ -187,7 +187,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U32_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } 5..=8 => { @@ -198,7 +198,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U64_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } 9..=16 => { @@ -209,7 +209,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U128_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } 17..=32 => { @@ -220,7 +220,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U256_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } 33..=64 => { @@ -231,7 +231,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U512_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } 65..=128 => { @@ -242,7 +242,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U1024_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } 129..=256 => { @@ -253,7 +253,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U2048_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } 257..=512 => { @@ -264,7 +264,7 @@ unsafe impl GlobalAlloc for GrandAllocator { assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U4096_GRAND_ALLOC.push(&mut pool[index+1]); - vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); + serial_vprintln!("GA: Freeing ({}, {}, {})", index, diff, spacing); }); } _ => { @@ -284,6 +284,6 @@ pub static ALLOCATOR: GrandAllocator = GrandAllocator {}; /// /// Returns a borrow for the Global Allocator pub fn allocator() -> &'static crate::mem::alloc::GrandAllocator { - vprintln!("AL: Getting global allocator!"); + serial_vprintln!("AL: Getting global allocator!"); &crate::mem::alloc::ALLOCATOR } diff --git a/src/panic_wait.rs b/src/panic_wait.rs index 53998a0..a8d0962 100644 --- a/src/panic_wait.rs +++ b/src/panic_wait.rs @@ -2,7 +2,7 @@ //! //! A panic handler that infinitely waits -use crate::{cpu, println}; +use crate::{cpu, serial_println}; use core::panic::PanicInfo; /// # Prevent Double Faulting @@ -34,7 +34,7 @@ fn panic(info: &PanicInfo) -> ! { _ => ("???", 0, 0), }; - println!( + serial_println!( "Kernel panic!\n\nPanic Location:\n\tFile: '{}', line {}, column {}\n\n{}", location, line, diff --git a/src/print.rs b/src/print.rs index 2fefd91..56fd6c5 100644 --- a/src/print.rs +++ b/src/print.rs @@ -6,7 +6,7 @@ use crate::uart::UART_WRITER; use core::fmt; #[doc(hidden)] -pub fn _print(args: fmt::Arguments) { +pub fn _serial_print(args: fmt::Arguments) { UART_WRITER.write_fmt(args).unwrap(); } @@ -14,18 +14,18 @@ pub fn _print(args: fmt::Arguments) { /// /// Print formatted arguments without a newline #[macro_export] -macro_rules! print { - ($($arg:tt)*) => ($crate::print::_print(format_args!($($arg)*))); +macro_rules! serial_print { + ($($arg:tt)*) => ($crate::print::_serial_print(format_args!($($arg)*))); } /// # Print with newline /// /// Print formatted arguments with a newline #[macro_export] -macro_rules! println { +macro_rules! serial_println { () => ($crate::print!("\n")); ($($arg:tt)*) => ({ - $crate::print::_print(format_args_nl!($($arg)*)); + $crate::print::_serial_print(format_args_nl!($($arg)*)); }) } @@ -33,10 +33,10 @@ macro_rules! println { /// /// Print formatted arguments without a newline but only with `verbose` feature #[macro_export] -macro_rules! vprint { +macro_rules! serial_vprint { ($($arg:tt)*) => ({ #[cfg(feature="verbose")] - $crate::print::_print(format_args!($($arg)*)) + $crate::print::_serial_print(format_args!($($arg)*)) }); } @@ -44,13 +44,13 @@ macro_rules! vprint { /// /// Print formatted arguments with a newline but only with `verbose` feature #[macro_export] -macro_rules! vprintln { +macro_rules! serial_vprintln { () => ({ #[cfg(feature="verbose")] $crate::print!("\n") }); ($($arg:tt)*) => ({ #[cfg(feature="verbose")] - $crate::print::_print(format_args_nl!($($arg)*)); + $crate::print::_serial_print(format_args_nl!($($arg)*)); }) } diff --git a/src/util/fifo_queue.rs b/src/util/fifo_queue.rs index 42d63ac..6748ab4 100644 --- a/src/util/fifo_queue.rs +++ b/src/util/fifo_queue.rs @@ -3,7 +3,7 @@ //! Provides the FIFO queue structure for allocations use crate::sync::interface::Mutex; use crate::sync::NullLock; -use crate::vprintln; +use crate::serial_vprintln; use core::fmt; use core::fmt::{Debug, Formatter}; @@ -102,9 +102,9 @@ impl<'a, T: Sized, const COUNT: usize> QueueAllocator<'a, T, COUNT> { /// All of the internal elements point to the next /// one and the final element points to `None` pub fn init(&self) { - vprintln!("QA: Initializing Queue Allocator!"); + serial_vprintln!("QA: Initializing Queue Allocator!"); self.inner.lock(|queue| { - vprintln!("QA: Clearing internal references..."); + serial_vprintln!("QA: Clearing internal references..."); for idx in 2..COUNT { if idx != COUNT - 1 { queue[idx].next = Some(&mut queue[idx + 1] as *mut QueueItem<'a, T>); @@ -112,11 +112,11 @@ impl<'a, T: Sized, const COUNT: usize> QueueAllocator<'a, T, COUNT> { queue[idx].next = None; } } - vprintln!("QA: Initializing head and tail..."); + serial_vprintln!("QA: Initializing head and tail..."); queue[0].next = Some(&mut queue[2] as *mut QueueItem<'a, T>); queue[1].next = Some(&mut queue[COUNT - 1] as *mut QueueItem<'a, T>); }); - vprintln!("QA: Initialized Queue Allocator!"); + serial_vprintln!("QA: Initialized Queue Allocator!"); } /// # Allocate Data @@ -125,10 +125,10 @@ impl<'a, T: Sized, const COUNT: usize> QueueAllocator<'a, T, COUNT> { /// return it, otherwise return `None` #[allow(dead_code)] pub fn alloc(&self) -> Option<&mut QueueItem<'a, T>> { - vprintln!("QA: Allocating chunk!"); + serial_vprintln!("QA: Allocating chunk!"); return self.inner.lock(|pool| { if let Some(entry) = pool[0].next { - vprintln!("QA: Found chunk!"); + serial_vprintln!("QA: Found chunk!"); pool[0].next = unsafe { (*entry).next }; unsafe { (*entry).next = None; @@ -137,12 +137,12 @@ impl<'a, T: Sized, const COUNT: usize> QueueAllocator<'a, T, COUNT> { None => pool[1].next = None, _ => {} } - vprintln!("QA: \x1b[92mAllocated {:x}\x1b[0m", unsafe { + serial_vprintln!("QA: \x1b[92mAllocated {:x}\x1b[0m", unsafe { (*entry).ptr() as usize }); return Some(unsafe { &mut *entry as &mut QueueItem<'a, T> }); } else { - vprintln!("QA: No chunks available!"); + serial_vprintln!("QA: No chunks available!"); return None; } }); @@ -154,7 +154,7 @@ impl<'a, T: Sized, const COUNT: usize> QueueAllocator<'a, T, COUNT> { /// If there were no items, set it as the head. #[allow(dead_code)] pub fn free(&self, freed_item: &mut QueueItem<'a, T>) { - vprintln!("QA: Deallocating chunk!"); + serial_vprintln!("QA: Deallocating chunk!"); self.inner.lock(|pool| { freed_item.next = None; match pool[1].next { @@ -166,7 +166,7 @@ impl<'a, T: Sized, const COUNT: usize> QueueAllocator<'a, T, COUNT> { }, } pool[1].next = Some(freed_item as *mut QueueItem<'a, T>); - vprintln!( + serial_vprintln!( "QA: \x1b[91mDeallocated {:x}\x1b[0m", freed_item.ptr() as usize ); -- cgit v1.2.1