3 Commits

Author SHA1 Message Date
092004bab0 Add qemu serial output to stdio
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-08-02 19:12:56 +02:00
022ec27bd5 Update LICENSE information
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-08-02 19:12:30 +02:00
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
11 changed files with 69 additions and 77 deletions

20
LICENSE
View File

@@ -1,18 +1,18 @@
MIT License
Copyright (c) 2025 noah.knegt
Copyright (c) 2025 Noah Knegt <personal@noahknegt.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.

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

@@ -17,6 +17,9 @@ fn main() {
cmd.arg("-drive")
.arg(format!("format=raw,file={bios_path}"));
}
cmd.arg("-serial").arg("stdio");
let mut child = cmd.spawn().unwrap();
child.wait().unwrap();
}