Skip to content

Commit

Permalink
feat: implement colors
Browse files Browse the repository at this point in the history
  • Loading branch information
marekvospel committed Oct 26, 2024
1 parent 82e85f8 commit 115746a
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 190 deletions.
2 changes: 1 addition & 1 deletion crates/allocator/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ unsafe impl<'a> GlobalAlloc for LinkedListAllocator {
last_node = Some(node);
}

panic!("Could not deallocate 0x{:x} {:?}", ptr as usize, layout);
// panic!("Could not deallocate 0x{:x} {:?}", ptr as usize, layout);
}
}

Expand Down
62 changes: 25 additions & 37 deletions crates/libkernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

extern crate alloc;

use core::{borrow::BorrowMut, ops::DerefMut};

use alloc::string::String;
use multiboot2::{BootInformation, BootInformationHeader};

use crate::font::{FramebufferLogger, Pixel};

pub mod font;
mod gdt;
mod memory;
mod serial;
pub mod text;

#[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
Expand All @@ -27,46 +27,17 @@ pub extern "C" fn rust_main(multiboot_info_addr: usize) {
unsafe { BootInformation::load(multiboot_info_addr as *const BootInformationHeader) }
.expect("Error while parsing multiboot header: ");

let framebuffer = boot_info.framebuffer_tag().unwrap().unwrap();

println!("{framebuffer:?}");

println!("Starting VOS...");

init(&boot_info);

let str = String::from("Hello world on heap!");
println!("{}", str);

let mut logger = unsafe { FramebufferLogger::new(framebuffer) };

logger.set_color(Pixel {
r: 100,
g: 100,
b: 100,
});
logger.write_char('[');

logger.set_color(Pixel { r: 0, g: 255, b: 0 });
logger.write_char('O');
logger.write_char('K');

logger.set_color(Pixel {
r: 100,
g: 100,
b: 100,
});
logger.write_char(']');

logger.set_color(Pixel {
r: 255,
g: 255,
b: 255,
});
let letters = " This is my 1st framebuffer message! aaaaaaaaaabbbcccc";
for letter in letters.chars() {
logger.write_char(letter);
}
println!(
"\x1b[90m[\x1b[92mOK\x1b[90m] \x1b[0mThis is my 1st framebuffer message! aaaaaaaaaabbbcccc",
);
println!("\x1b[38;2;25;180;209mPoznej markovu barvu");

loop {}
}
Expand All @@ -75,6 +46,23 @@ fn init(boot_info: &BootInformation) -> () {
gdt::init_gdt();
gdt::init_idt();
memory::init(boot_info);
let framebuffer = boot_info.framebuffer_tag().unwrap().unwrap();
unsafe { text::_init(framebuffer) };
}

pub(crate) fn _print(args: core::fmt::Arguments) {
use core::fmt::Write;

if let Some(ref mut logger) = *text::LOGGER.lock() {
logger
.write_fmt(args)
.expect("Printing to framebuffer failed");
}

serial::SERIAL1
.lock()
.write_fmt(args)
.expect("Printing to serial failed");
}

#[macro_export]
Expand All @@ -86,6 +74,6 @@ macro_rules! println {
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ({
$crate::serial::_print(format_args!($($arg)*));
$crate::_print(format_args!($($arg)*));
})
}
8 changes: 0 additions & 8 deletions crates/libkernel/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ lazy_static! {
};
}

pub(crate) fn _print(args: core::fmt::Arguments) {
use core::fmt::Write;
SERIAL1
.lock()
.write_fmt(args)
.expect("Printing to serial failed");
}

#[macro_export]
macro_rules! serial_println {
() => (print!("\n"));
Expand Down
144 changes: 0 additions & 144 deletions src/font/mod.rs

This file was deleted.

Loading

0 comments on commit 115746a

Please sign in to comment.