KarxOS/src/main.rs

73 lines
1.5 KiB
Rust

#![allow(non_snake_case)]
#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
#![feature(abi_x86_interrupt)]
#![feature(alloc_error_handler)]
mod gdt;
mod interrupts;
mod shell;
mod vga_buffer;
mod memory;
mod allocator;
use core::panic::PanicInfo;
use bootloader::BootInfo;
extern crate alloc;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("{}", info);
loop {}
}
#[alloc_error_handler]
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
panic!("allocation error: {:?}", layout)
}
fn init() {
gdt::init_gdt();
interrupts::init();
}
#[no_mangle]
pub extern "C" fn _start(boot_info: &'static BootInfo) {
use crate::vga_buffer::{change_color, Color};
init();
print!("[ ");
change_color(Color::Green, Color::Black);
print!("OK");
change_color(Color::White, Color::Black);
println!(" ] Initialized GDT and interrupts");
print!("Welcome to ");
change_color(Color::Blue, Color::Black);
println!("KarxOS!");
change_color(Color::White, Color::Black);
// First prompt, future prompts will be handled by shell::evaluate
print!(">>> ");
#[cfg(test)]
test_main();
loop {
// Halt CPU so that usage isn't 100% all the time
x86_64::instructions::hlt();
}
}
#[cfg(test)]
fn test_runner(tests: &[&dyn Fn()]) {
println!("Running {} tests", tests.len());
for test in tests {
test();
}
}