Removed messy debug logging, added print_oneshot!()

This commit is contained in:
2025-03-06 20:11:54 +00:00
parent 4bf31e653b
commit 1d192adde0
11 changed files with 216 additions and 50 deletions
+34 -25
View File
@@ -1,5 +1,6 @@
#![no_std]
#![feature(abi_x86_interrupt)]
#![feature(impl_trait_in_bindings)]
#![warn(
clippy::correctness,
clippy::nursery,
@@ -14,8 +15,6 @@
extern crate alloc;
use crate::{
// TODO: Fix nesting under `arch`. A lot of code does not NEED to run on
// x86_64. Note that the panic handler does.
arch::x86_64::{
cpu::apic::enable_apic,
drivers::{
@@ -26,34 +25,29 @@ use crate::{
allocation::{
heap_alloc::init_heap, page_alloc::FoundryOSFrameAllocator,
},
init_page_table,
init_page_table, mapping,
units::MemoryUnits,
},
},
prelude::*,
};
use arch::x86_64::memory::mapping;
use alloc::{boxed::Box, format};
use core::arch::asm;
use limine::BaseRevision;
use std::unwind::UNWINDER;
use x86_64::VirtAddr;
pub mod arch;
/// Commonly used re-exports.
pub mod prelude;
pub mod resources;
#[allow(unused)] // We aren't using much of this right now.
// We aren't using much of this right now.
#[allow(unused)]
pub mod std;
mod step;
pub mod util;
pub mod prelude {
pub use crate::{
debug, debugln, eprint, eprintln, print, print_log, println,
println_log, serial_print, serial_println,
std::debug::_debug,
std::io::{_print, _print_err, _print_log, _serial_write},
};
}
/// Sets the base revision to the latest revision supported by the crate.
/// See specification for further info.
/// Be sure to mark all limine requests with #[used], otherwise they may be
@@ -73,12 +67,25 @@ pub fn hcf() -> ! {
}
}
#[derive(Debug)]
pub struct NoError {}
impl core::fmt::Display for NoError {
fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Ok(())
}
}
pub struct NoTags;
impl core::error::Error for NoError {}
/// Panicking before this is initialised is unwise. We should probably extract
/// very early init into it's own function because Stack Traces may require
/// allocations etc.
pub fn boot() -> Result<(), &'static str> {
pub fn boot() -> Result<(), Box<dyn core::error::Error>> {
if !BASE_REVISION.is_supported() {
return Err("Base revision not supported");
return Err("Base revision not supported.".into());
}
use arch::x86_64::{gdt, interrupts};
@@ -116,22 +123,22 @@ pub fn boot() -> Result<(), &'static str> {
FoundryOSFrameAllocator::init(memory_map);
let available_bytes =
FRAME_ALLOCATOR.get().unwrap().lock().available_memory();
debugln!(
" => Available Memory: {}",
MemoryUnits::from_bytes(available_bytes as usize)
);
debugln!("[Success]");
// Allocations should be all fine past this point.
debugln!(" Initialising Heap... ");
if unsafe { init_heap() }.is_err() {
return Err("Failed to initialise heap: error");
match unsafe { init_heap() } {
Ok(_) => debugln!(" [Success]"),
Err(why) => return Err(format!("{:?}", why).into()),
}
debugln!(" [Success]");
// debug!(" Enabling PICs... ");
// interrupts::enable_pic();
// debugln!("[Success]");
debug!(" Enabling PICs... ");
interrupts::enable_pic();
debugln!("[Success]");
debug!(" Disabling PICs... ");
interrupts::disable_pic();
@@ -145,7 +152,9 @@ pub fn boot() -> Result<(), &'static str> {
x86_64::instructions::interrupts::enable();
debugln!("[Success]");
UNWINDER.lock(); // Initialises the Unwinder once and only once :fingers_crossed:.
// Initialises the Unwinder once and only once because this makes a heap
// allocation.
UNWINDER.lock();
Ok(())
}