From 8fbf7b5a5adb976b58dbd7d1c87a1bac9335710d Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 7 Dec 2022 01:43:26 +0100 Subject: [PATCH] Added basic logging support --- Cargo.lock | 1 - ableos/src/kmain.rs | 4 ++-- kernel/Cargo.toml | 3 +-- kernel/src/allocator.rs | 4 ---- kernel/src/arch/mod.rs | 2 +- kernel/src/arch/x86_64/allocator.rs | 11 ++++------- kernel/src/arch/x86_64/mod.rs | 24 ++++++++++++++++-------- kernel/src/debug.rs | 1 + kernel/src/lib.rs | 3 ++- 9 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 kernel/src/debug.rs diff --git a/Cargo.lock b/Cargo.lock index 568f700d4..c423b49f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -585,7 +585,6 @@ dependencies = [ "crossbeam-queue", "limine", "linked_list_allocator", - "log", "slab", "spin 0.9.4", "tracing", diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index d09f9166d..c4bf576a5 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -15,7 +15,7 @@ use crate::relib::network::socket::{SimpleSock, Socket}; use crate::{boot_conf::KernelConfig, scratchpad, systeminfo::RELEASE_TYPE}; // use crate::{boot_conf::KernelConfig, scratchpad, systeminfo::RELEASE_TYPE, TERM}; use crate::{filesystem, graphics_limine, hardware}; -use kernel::KERNEL_VERSION; +use kernel::VERSION; use limine::LimineSmpInfo; use limine::{LimineFramebufferRequest, LimineSmpRequest}; @@ -151,7 +151,7 @@ pub fn cpu_socket_startup() { } pub fn log_version_data() { - info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); + info!("{} v{}", RELEASE_TYPE, VERSION); info!( "Brand String: {}", master().unwrap().brand_string().unwrap() diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 36458c5f4..33baa9937 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -5,11 +5,10 @@ version = "0.2.0" [dependencies] linked_list_allocator = "0.9" -log = "0.4.14" slab = { version = "0.4", default-features = false } spin = "0.9" versioning = { git = "https://git.ablecorp.us/able/aos_userland" } -tracing = { version = "0.1.37", default-features = false, features = ["attributes"] } +tracing = { version = "0.1", default-features = false, features = ["attributes"] } [dependencies.crossbeam-queue] version = "0.3" diff --git a/kernel/src/allocator.rs b/kernel/src/allocator.rs index a4d48cc29..670b1a046 100644 --- a/kernel/src/allocator.rs +++ b/kernel/src/allocator.rs @@ -1,7 +1,5 @@ //! Memory allocator -use log::trace; - /// pub const HEAP_START: usize = 0x_4444_4444_0000; @@ -16,7 +14,5 @@ pub const HEAP_SIZE: usize = HEAP_BASE * HEAP_MULTIPLIER; #[alloc_error_handler] fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { - trace!("allocation error: {:?}", layout); loop {} - // panic!("allocation error: {:?}", layout) } diff --git a/kernel/src/arch/mod.rs b/kernel/src/arch/mod.rs index 60d76d5a9..c1a5e1bd9 100644 --- a/kernel/src/arch/mod.rs +++ b/kernel/src/arch/mod.rs @@ -5,7 +5,7 @@ macro_rules! arch_cond { #[cfg(target_arch = $str)] pub mod $arch; #[cfg(target_arch = $str)] - pub use ::$arch::*; + pub use self::$arch::*; )*}; } diff --git a/kernel/src/arch/x86_64/allocator.rs b/kernel/src/arch/x86_64/allocator.rs index 2f77f39e2..d92cb45b6 100644 --- a/kernel/src/arch/x86_64/allocator.rs +++ b/kernel/src/arch/x86_64/allocator.rs @@ -12,13 +12,10 @@ use crate::allocator::{HEAP_SIZE, HEAP_START}; static ALLOCATOR: LockedHeap = LockedHeap::empty(); pub unsafe fn init_alloc() -> Result<(), MapToError> { - let page_range = { - let heap_start = VirtAddr::new(HEAP_START as u64); - let heap_end = heap_start + HEAP_SIZE - 1u64; - let heap_start_page = Page::containing_address(heap_start); - let heap_end_page = Page::containing_address(heap_end); - Page::range_inclusive(heap_start_page, heap_end_page) - }; + let page_range = Page::range_inclusive( + Page::containing_address(VirtAddr::new(HEAP_START as u64)), + Page::containing_address(VirtAddr::new(HEAP_START as u64) + HEAP_SIZE - 1u64), + ); let mut frame_allocator = super::memory::FRAME_ALLOC .get() diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index c4e7f777b..222af1d81 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -1,14 +1,23 @@ use limine::{LimineHhdmRequest, LimineMmapRequest}; +use spin::Mutex; +use uart_16550::SerialPort; use x86_64::VirtAddr; mod allocator; mod memory; +static SERIAL_CONSOLE: Mutex = Mutex::new(unsafe { SerialPort::new(0x3f8) }); + #[no_mangle] unsafe extern "C" fn _kernel_start() -> ! { static HDHM_REQ: LimineHhdmRequest = LimineHhdmRequest::new(0); static MMAP_REQ: LimineMmapRequest = LimineMmapRequest::new(0); + let _ = serial_fmt(format_args!( + "Initialising AbleOS Kernel {}\r\n", + crate::VERSION + )); + memory::init_pt(VirtAddr::new( HDHM_REQ .get_response() @@ -26,14 +35,13 @@ unsafe extern "C" fn _kernel_start() -> ! { ); allocator::init_alloc().expect("tried to initialise allocator"); - - unsafe { - use uart_16550::SerialPort; - use core::fmt::Write; - let mut sp = SerialPort::new(0x3F8); - sp.init(); - sp.write_str("Hello from AbleOS x86_64 entrypoint!"); - } + SERIAL_CONSOLE.lock().init(); crate::kmain::kmain() } + +/// Format args to serial console +pub fn serial_fmt(args: core::fmt::Arguments<'_>) -> core::fmt::Result { + use core::fmt::Write; + SERIAL_CONSOLE.lock().write_fmt(args) +} diff --git a/kernel/src/debug.rs b/kernel/src/debug.rs new file mode 100644 index 000000000..981558fe2 --- /dev/null +++ b/kernel/src/debug.rs @@ -0,0 +1 @@ +// TODO: Tracing Subscriber serial print implementation diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 8a4a0df53..a96c0cce6 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -7,13 +7,14 @@ extern crate alloc; pub mod allocator; pub mod arch; +pub mod debug; pub mod kmain; pub mod task; use versioning::Version; /// Kernel's version -pub const KERNEL_VERSION: Version = Version { +pub const VERSION: Version = Version { major: 0, minor: 2, patch: 0,