This commit is contained in:
FantasyPvP
2023-11-10 00:16:33 +00:00
parent 2d30f16b9d
commit 3510210b99
+28 -32
View File
@@ -4,59 +4,55 @@
#![test_runner(CrystalOS::test_runner)] #![test_runner(CrystalOS::test_runner)]
#![reexport_test_harness_main = "test_main"] #![reexport_test_harness_main = "test_main"]
use bootloader::{entry_point, BootInfo};
use core::panic::PanicInfo; use core::panic::PanicInfo;
use CrystalOS::{println, print, println_log, print_log, kernel, printerr}; use CrystalOS::kernel::tasks::{executor::Executor, Task};
use CrystalOS::kernel::tasks::{Task, executor::Executor}; use CrystalOS::{kernel, print, print_log, printerr, println, println_log};
use bootloader::{BootInfo, entry_point};
extern crate alloc; extern crate alloc;
use CrystalOS::user::bin::shell; use CrystalOS::user::bin::shell;
#[cfg(not(test))] #[cfg(not(test))]
#[panic_handler] #[panic_handler]
fn panic(_info: &PanicInfo) -> ! { fn panic(_info: &PanicInfo) -> ! {
kernel::render::RENDERER.lock().terminal_mode_force(); kernel::render::RENDERER.lock().terminal_mode_force();
printerr!("{}", _info); printerr!("{}", _info);
CrystalOS::hlt(); CrystalOS::hlt();
} }
#[cfg(test)] #[cfg(test)]
#[panic_handler] #[panic_handler]
fn panic(info: &PanicInfo) -> ! { fn panic(info: &PanicInfo) -> ! {
CrystalOS::test_panic_handler(info) CrystalOS::test_panic_handler(info)
} }
// some comment
entry_point!(main); entry_point!(main);
fn main(boot_info: &'static BootInfo) -> ! { fn main(boot_info: &'static BootInfo) -> ! {
use CrystalOS::kernel::allocator; use x86_64::VirtAddr;
use CrystalOS::kernel::memory; use CrystalOS::kernel::allocator;
use CrystalOS::kernel::memory::BootInfoFrameAllocator; use CrystalOS::kernel::memory;
use x86_64::VirtAddr; use CrystalOS::kernel::memory::BootInfoFrameAllocator;
CrystalOS::init();
let physical_memory_offset = VirtAddr::new(boot_info.physical_memory_offset);
let mut mapper = unsafe { memory::init(physical_memory_offset) };
let mut frame_allocator = unsafe {
BootInfoFrameAllocator::init(&boot_info.memory_map)
};
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialisation failed"); CrystalOS::init();
let mut executor = Executor::new(); let physical_memory_offset = VirtAddr::new(boot_info.physical_memory_offset);
let mut mapper = unsafe { memory::init(physical_memory_offset) };
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };
executor.spawn(Task::new(shell::command_handler())); allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialisation failed");
let mut executor = Executor::new();
loop { executor.spawn(Task::new(shell::command_handler()));
executor.try_run();
}
#[cfg(test)]
test_main();
loop {} loop {
executor.try_run();
}
#[cfg(test)]
test_main();
loop {}
} }