1 Commits

Author SHA1 Message Date
bf3923acd0 chore: Pin the nightly version (#5)
Signed-off-by: Noah Knegt <git@noahknegt.com>
Co-authored-by: Noah Knegt <git@noahkengt.com>
Reviewed-on: #5
2025-07-30 23:02:43 +02:00
10 changed files with 59 additions and 72 deletions

View File

@@ -9,15 +9,11 @@ fn main() {
// create an UEFI disk image (optional)
let uefi_path = out_dir.join("uefi.img");
bootloader::UefiBoot::new(&kernel)
.create_disk_image(&uefi_path)
.unwrap();
bootloader::UefiBoot::new(&kernel).create_disk_image(&uefi_path).unwrap();
// create a BIOS disk image
let bios_path = out_dir.join("bios.img");
bootloader::BiosBoot::new(&kernel)
.create_disk_image(&bios_path)
.unwrap();
bootloader::BiosBoot::new(&kernel).create_disk_image(&bios_path).unwrap();
// pass the disk image paths as env variables to the `main.rs`
println!("cargo:rustc-env=UEFI_PATH={}", uefi_path.display());

View File

@@ -1,13 +0,0 @@
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn add_test() {
assert_eq!(add(1, 2), 3);
}
}

View File

@@ -1,30 +0,0 @@
#![cfg_attr(not(test), no_std)]
use bootloader_api::BootInfo;
mod logging;
mod adder;
pub fn main(boot_info: &'static mut BootInfo) -> ! {
let info = boot_info.framebuffer.as_ref().unwrap().info();
let buffer = boot_info.framebuffer.as_mut().unwrap().buffer_mut();
logging::init_logger(buffer, info);
log::info!("Hello World from KERNEL");
log::debug!("ADDING 1 & 6, result == {}", adder::add(1, 6));
// Endless loop as the kernel must stay running
#[allow(clippy::empty_loop)]
loop {}
}
#[cfg(not(test))]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
logging::force_unlock();
log::error!("{info}");
#[allow(clippy::empty_loop)]
loop {}
}

View File

@@ -2,7 +2,7 @@ use bootloader_api::info::{FrameBufferInfo, PixelFormat};
use core::{fmt, ptr};
use font_constants::BACKUP_CHAR;
use noto_sans_mono_bitmap::{
FontWeight, RasterHeight, RasterizedChar, get_raster, get_raster_width,
get_raster, get_raster_width, FontWeight, RasterHeight, RasterizedChar,
};
/// Additional vertical space between lines
@@ -130,7 +130,7 @@ impl FrameBufferWriter {
// set a supported (but invalid) pixel format before panicking to avoid a double
// panic; it might not be readable though
self.info.pixel_format = PixelFormat::Rgb;
panic!("pixel format {other:?} not supported in logger")
panic!("pixel format {:?} not supported in logger", other)
}
};
let bytes_per_pixel = self.info.bytes_per_pixel;

View File

@@ -11,21 +11,21 @@ static LOGGER: OnceCell<LockedLogger> = OnceCell::uninit();
/// A logger instance protected by a spinlock.
struct LockedLogger {
framebuffer: Option<Spinlock<framebuffer::FrameBufferWriter>>,
serial: Option<Spinlock<serial::SerialPort>>,
serial: Option<Spinlock<serial::SerialPort>>
}
impl LockedLogger {
/// Create a new instance that logs to the given framebuffer.
pub fn new(framebuffer: &'static mut [u8], info: FrameBufferInfo) -> Self {
let framebuffer = Some(Spinlock::new(framebuffer::FrameBufferWriter::new(
framebuffer,
info,
)));
pub fn new(
framebuffer: &'static mut [u8],
info: FrameBufferInfo,
) -> Self {
let framebuffer = Some(Spinlock::new(framebuffer::FrameBufferWriter::new(framebuffer, info)));
let serial = Some(Spinlock::new(unsafe { serial::SerialPort::init() }));
LockedLogger {
framebuffer,
serial,
serial
}
}
@@ -65,8 +65,16 @@ impl log::Log for LockedLogger {
}
/// Initialize a text-based logger using the given pixel-based framebuffer as output.
pub fn init_logger(framebuffer: &'static mut [u8], info: FrameBufferInfo) {
let logger = LOGGER.get_or_init(move || LockedLogger::new(framebuffer, info));
pub fn init_logger(
framebuffer: &'static mut [u8],
info: FrameBufferInfo,
) {
let logger = LOGGER.get_or_init(move || {
LockedLogger::new(
framebuffer,
info,
)
});
log::set_logger(logger).expect("logger already set");
#[cfg(debug_assertions)]
log::set_max_level(log::LevelFilter::Debug);
@@ -74,9 +82,14 @@ pub fn init_logger(framebuffer: &'static mut [u8], info: FrameBufferInfo) {
#[cfg(not(debug_assertions))]
log::set_max_level(log::LevelFilter::Info);
log::debug!("Framebuffer info: {info:?}");
log::debug!("Framebuffer info: {:?}", info);
}
pub fn force_unlock() {
unsafe { LOGGER.get().map(|l| l.force_unlock()) };
unsafe {
LOGGER
.get()
.map(|l| l.force_unlock())
};
}

View File

@@ -1,5 +1,4 @@
pub mod logger;
mod framebuffer;
mod serial;

View File

@@ -3,13 +3,35 @@
use bootloader_api::{
config::{BootloaderConfig, Mapping},
entry_point,
entry_point, BootInfo
};
static BOOTLOADER_CONFIG: BootloaderConfig = {
mod logger;
pub static BOOTLOADER_CONFIG: BootloaderConfig = {
let mut config = BootloaderConfig::new_default();
config.mappings.physical_memory = Some(Mapping::Dynamic);
config
};
entry_point!(kernel::main, config = &BOOTLOADER_CONFIG);
entry_point!(kernel_main);
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
let info = boot_info.framebuffer.as_ref().unwrap().info();
let buffer = boot_info.framebuffer.as_mut().unwrap().buffer_mut();
logger::init_logger(buffer, info);
log::info!("Hello World from KERNEL");
// Endless loop as the kernel must stay running
loop {}
}
#[panic_handler]
#[cfg(not(test))]
fn panic(info: &core::panic::PanicInfo) -> ! {
logger::force_unlock();
log::error!("{}", info);
loop {}
}

View File

@@ -1,5 +1,7 @@
[toolchain]
channel = "nightly"
# The nightly version that was build on 24-07-2025 is the last known working version,
# the c-int-width definition for rust targets has changed from a string to a u16
channel = "nightly-2025-07-24"
targets = [
"x86_64-unknown-none"
]

View File

@@ -4,18 +4,16 @@ fn main() {
// read env variables that were set in build script
let uefi_path = env!("UEFI_PATH");
let bios_path = env!("BIOS_PATH");
// choose whether to start the UEFI or BIOS image
let uefi = true;
let mut cmd = std::process::Command::new("qemu-system-x86_64");
if uefi {
cmd.arg("-bios").arg(ovmf_prebuilt::ovmf_pure_efi());
cmd.arg("-drive")
.arg(format!("format=raw,file={uefi_path}"));
cmd.arg("-drive").arg(format!("format=raw,file={uefi_path}"));
} else {
cmd.arg("-drive")
.arg(format!("format=raw,file={bios_path}"));
cmd.arg("-drive").arg(format!("format=raw,file={bios_path}"));
}
let mut child = cmd.spawn().unwrap();
child.wait().unwrap();