Move to single arch, add serial console, font rendering, panic handling, move graphics to multiple files, use a global mutex framebuffer & serialconsole

This commit is contained in:
csd4ni3l
2026-03-14 16:40:23 +01:00
parent 8308a7ae32
commit 7a938283f7
17 changed files with 205 additions and 24 deletions

View File

@@ -7,9 +7,14 @@ use limine::BaseRevision;
use limine::request::{FramebufferRequest, RequestsEndMarker, RequestsStartMarker};
pub mod driver;
pub mod arch;
use crate::driver::graphics::{circle_filled, circle_outline, rectangle_filled, rectangle_outline, rgb, triangle_outline};
use crate::driver::framebuffer::Framebuffer;
use spin::Mutex;
use crate::arch::serial::{SerialConsole, init_serial_console, with_serial_console};
use crate::driver::graphics::font_render::render_text;
use crate::driver::graphics::primitives::{circle_filled, circle_outline, rectangle_filled, rectangle_outline, triangle_outline};
use crate::driver::graphics::base::rgb;
use crate::driver::graphics::framebuffer::{Framebuffer, init_framebuffer, with_framebuffer};
/// Sets the base revision to the latest revision supported by the crate.
/// See specification for further info.
@@ -31,6 +36,27 @@ static _START_MARKER: RequestsStartMarker = RequestsStartMarker::new();
#[unsafe(link_section = ".requests_end_marker")]
static _END_MARKER: RequestsEndMarker = RequestsEndMarker::new();
// #[macro_export]
// macro_rules! print {
// ($($arg:tt)*) => (with_framebuffer(|mut fb|{
// with_serial_console(|serial_console| {
// serial_console.render_text(&mut fb, format_args!($($arg)*));
// });
// }));
// }
// #[macro_export]
// macro_rules! println {
// () => ($crate::print!("\n"));
// ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
// }
// #[doc(hidden)]
// pub fn _print(args: fmt::Arguments) {
// use core::fmt::Write;
// WRITER.lock().write_fmt(args).unwrap();
// }
#[unsafe(no_mangle)]
unsafe extern "C" fn kmain() -> ! {
// All limine requests must also be referenced in a called function, otherwise they may be
@@ -39,13 +65,18 @@ unsafe extern "C" fn kmain() -> ! {
if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() {
if let Some(limine_framebuffer) = framebuffer_response.framebuffers().next() {
let mut fb = Framebuffer::new(&limine_framebuffer);
rectangle_filled(&mut fb, 0, 0, limine_framebuffer.width() as usize, limine_framebuffer.height() as usize, rgb(253, 129, 0));
rectangle_filled(&mut fb, 700, 400, 200, 200, rgb(0, 0, 0));
rectangle_outline(&mut fb, 400, 400, 100, 100, rgb(0, 0, 0));
circle_filled(&mut fb, 200, 200, 100.0, rgb(0, 0, 0));
circle_outline(&mut fb, 400, 200, 100.0, rgb(0, 0, 0));
triangle_outline(&mut fb, 100, 400, 200, 400, 150, 600, rgb(0, 0, 0));
init_framebuffer(&limine_framebuffer);
with_framebuffer(|mut fb| {
let (width, height) = (fb.width.clone(), fb.height.clone());
init_serial_console(width / 2, height / 3);
rectangle_filled(&mut fb, 0, 0, width, height, rgb(253, 129, 0), true);
rectangle_filled(&mut fb, 700, 400, 200, 200, rgb(0, 0, 0), true);
rectangle_outline(&mut fb, 400, 400, 100, 100, rgb(0, 0, 0));
circle_filled(&mut fb, 200, 200, 100.0, rgb(0, 0, 0));
circle_outline(&mut fb, 400, 200, 100.0, rgb(0, 0, 0));
triangle_outline(&mut fb, 100, 400, 200, 400, 150, 600, rgb(0, 0, 0));
});
panic!("idk, test");
}
}
@@ -53,7 +84,20 @@ unsafe extern "C" fn kmain() -> ! {
}
#[panic_handler]
fn rust_panic(_info: &core::panic::PanicInfo) -> ! {
fn rust_panic(_info: &core::panic::PanicInfo) -> ! {
with_framebuffer(|mut fb|{
let (width, height) = (fb.width.clone(), fb.height.clone());
rectangle_filled(&mut fb, 0, 0, width, height, rgb(180, 0, 0), true);
with_serial_console(|serial_console| {
serial_console.clear(height / 3);
serial_console.render_text(&mut fb, "Kernel Panic! :C\n\n\n");
if let Some(message) = _info.message().as_str() {
serial_console.render_text(&mut fb, "Message:");
serial_console.render_text(&mut fb, message);
}
});
});
idle();
}