This commit is contained in:
parent
ebca494958
commit
d718473886
5 changed files with 36 additions and 22 deletions
|
@ -56,19 +56,18 @@ extern "C" fn early_main(temp_loader_struct: *const LoaderStruct) -> ! {
|
|||
unsafe {
|
||||
ALLOC.lock().init(KERNEL_HEAP_START as usize, KERNEL_HEAP_INITIAL_SIZE);
|
||||
}
|
||||
{
|
||||
let mut loader_struct = LOADER_STRUCT.lock();
|
||||
unsafe {
|
||||
temp_loader_struct.copy_to(&mut *loader_struct, 1);
|
||||
}
|
||||
assert_eq!(loader_struct.magic, LOADER_STRUCT_MAGIC);
|
||||
init_logger(loader_struct.vm != 0);
|
||||
info!("Starting kernel...");
|
||||
setup_gdt();
|
||||
setup_idt();
|
||||
setup_paging(&loader_struct, loader_struct.phys_kernel_start, loader_struct.phys_heap_start);
|
||||
RSDP_ADDRESS.store(loader_struct.rsdp_address, Ordering::SeqCst);
|
||||
let mut loader_struct = LOADER_STRUCT.lock();
|
||||
unsafe {
|
||||
temp_loader_struct.copy_to(&mut *loader_struct, 1);
|
||||
}
|
||||
assert_eq!(loader_struct.magic, LOADER_STRUCT_MAGIC);
|
||||
init_logger(loader_struct.vm != 0);
|
||||
info!("Starting kernel...");
|
||||
setup_gdt();
|
||||
setup_idt();
|
||||
setup_paging(&loader_struct, loader_struct.phys_kernel_start, loader_struct.phys_heap_start);
|
||||
setup_display(loader_struct.framebuffer);
|
||||
RSDP_ADDRESS.store(loader_struct.rsdp_address, Ordering::SeqCst);
|
||||
disable_pic();
|
||||
let early_acpi_tables;
|
||||
unsafe {
|
||||
|
@ -81,8 +80,6 @@ extern "C" fn early_main(temp_loader_struct: *const LoaderStruct) -> ! {
|
|||
}
|
||||
fn main() {
|
||||
info!("Starting main kernel task");
|
||||
let loader_struct = LOADER_STRUCT.lock();
|
||||
setup_display(loader_struct.framebuffer);
|
||||
let mut status = unsafe { AcpiInitializeSubsystem() };
|
||||
assert_eq!(status, AE_OK);
|
||||
status = unsafe { AcpiInitializeTables(null_mut(), 0, 0) };
|
||||
|
@ -99,7 +96,7 @@ fn panic(info: &PanicInfo) -> ! {
|
|||
cli();
|
||||
LOCKS_HELD.fetch_add(1, Ordering::SeqCst);
|
||||
error!("{}", info);
|
||||
let str = format!("PANIC at {}: {}\n", info.location().unwrap(), info.message().as_str().unwrap());
|
||||
let str = format!("{}", info);
|
||||
display_print(&str);
|
||||
loop {
|
||||
hlt();
|
||||
|
|
|
@ -13,7 +13,11 @@ use embedded_graphics::{
|
|||
use kernel_common::loader_struct::FramebufferInfo;
|
||||
use spin::Mutex;
|
||||
|
||||
use crate::{cpu::paging::map_physical, misc::draw_target::FramebufferTarget, sys::sync::Spinlock};
|
||||
use crate::{
|
||||
cpu::paging::map_physical,
|
||||
misc::draw_target::FramebufferTarget,
|
||||
sys::{sync::Spinlock, task::MULTITASKING_ENABLED},
|
||||
};
|
||||
|
||||
static FRAMEBUFFER: Mutex<Option<FramebufferTarget>> = Mutex::new(None);
|
||||
static FRAMEBUFFER_LOCK: Spinlock = Spinlock::new();
|
||||
|
@ -53,7 +57,9 @@ pub fn display_print(str: &str) {
|
|||
if FRAMEBUFFER_ADDR.load(Ordering::SeqCst) == null_mut() {
|
||||
return;
|
||||
}
|
||||
FRAMEBUFFER_LOCK.lock();
|
||||
if MULTITASKING_ENABLED.load(Ordering::SeqCst) {
|
||||
FRAMEBUFFER_LOCK.lock();
|
||||
}
|
||||
let mut current_x = CURRENT_X.load(Ordering::SeqCst);
|
||||
let mut current_y = CURRENT_Y.load(Ordering::SeqCst);
|
||||
let width = WIDTH.load(Ordering::SeqCst);
|
||||
|
@ -78,7 +84,9 @@ pub fn display_print(str: &str) {
|
|||
CURRENT_X.store(current_x, Ordering::SeqCst);
|
||||
CURRENT_Y.store(current_y, Ordering::SeqCst);
|
||||
copy_to_fb();
|
||||
FRAMEBUFFER_LOCK.unlock();
|
||||
if MULTITASKING_ENABLED.load(Ordering::SeqCst) {
|
||||
FRAMEBUFFER_LOCK.unlock();
|
||||
}
|
||||
}
|
||||
pub fn setup_display(info: FramebufferInfo) {
|
||||
let addr = unsafe { map_physical(info.address, info.height * info.stride * 4, true) };
|
||||
|
|
|
@ -4,6 +4,8 @@ use alloc::{collections::vec_deque::VecDeque, sync::Arc};
|
|||
use kernel_common::instructions::{cli, sti};
|
||||
use spin::Mutex;
|
||||
|
||||
use crate::sys::task::MULTITASKING_ENABLED;
|
||||
|
||||
use super::{
|
||||
scheduler::{schedule_task, yield_task, SCHEDULER_LOCK},
|
||||
task::{Task, TaskState, CURRENT_TASK, CURRENT_TASK_LOCK},
|
||||
|
@ -27,6 +29,7 @@ impl Spinlock {
|
|||
Self { locked: AtomicBool::new(false) }
|
||||
}
|
||||
pub fn lock(&self) {
|
||||
assert!(MULTITASKING_ENABLED.load(Ordering::SeqCst));
|
||||
cli();
|
||||
while !self.locked.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst).is_ok() {}
|
||||
LOCKS_HELD.fetch_add(1, Ordering::SeqCst);
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
use core::sync::atomic::Ordering;
|
||||
|
||||
use kernel_common::loader_struct::FramebufferInfo;
|
||||
use uefi::{
|
||||
boot::{get_handle_for_protocol, open_protocol_exclusive, ScopedProtocol},
|
||||
proto::console::gop::{GraphicsOutput, PixelFormat},
|
||||
};
|
||||
|
||||
use crate::BOOT_SERVICES_ACTIVE;
|
||||
|
||||
pub fn setup_display() -> FramebufferInfo {
|
||||
let gop_handle = get_handle_for_protocol::<GraphicsOutput>().unwrap();
|
||||
let mut gop: ScopedProtocol<GraphicsOutput> = open_protocol_exclusive(gop_handle).unwrap();
|
||||
|
@ -22,11 +26,13 @@ pub fn setup_display() -> FramebufferInfo {
|
|||
best_mode = Some(i);
|
||||
}
|
||||
}
|
||||
gop.set_mode(&best_mode.unwrap()).unwrap();
|
||||
let best_mode = best_mode.unwrap();
|
||||
BOOT_SERVICES_ACTIVE.store(false, Ordering::SeqCst);
|
||||
gop.set_mode(&best_mode).unwrap();
|
||||
FramebufferInfo {
|
||||
address: gop.frame_buffer().as_mut_ptr() as u64,
|
||||
width: best_width as u64,
|
||||
height: best_height as u64,
|
||||
stride: best_mode.unwrap().info().stride() as u64,
|
||||
stride: best_mode.info().stride() as u64,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ mod paging;
|
|||
|
||||
#[global_allocator]
|
||||
static ALLOC: Bump<[u8; 8 * 1024 * 1024]> = Bump::uninit();
|
||||
static BOOT_SERVICES_ACTIVE: AtomicBool = AtomicBool::new(true);
|
||||
static BOOT_SERVICES_ACTIVE: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
const KERNEL: &[u8] = include_bytes!("../../target/x86_64-unknown-none/release/kernel");
|
||||
|
||||
|
@ -48,6 +48,7 @@ fn main() -> Status {
|
|||
init_logger(features.has_hypervisor());
|
||||
info!("Starting bootloader...");
|
||||
uefi::helpers::init().unwrap();
|
||||
BOOT_SERVICES_ACTIVE.store(true, Ordering::SeqCst);
|
||||
assert!(features.has_rdrand());
|
||||
let extended_features = cpuid.get_extended_feature_info().unwrap();
|
||||
assert!(extended_features.has_smap());
|
||||
|
@ -65,7 +66,6 @@ fn main() -> Status {
|
|||
}
|
||||
});
|
||||
assert_ne!(rsdp.load(Ordering::SeqCst), 0, "RSDP not found");
|
||||
BOOT_SERVICES_ACTIVE.store(false, Ordering::SeqCst);
|
||||
let framebuffer_info = setup_display();
|
||||
let memory_map = unsafe { exit_boot_services(MemoryType::LOADER_DATA) };
|
||||
let pml4 = setup_paging(&memory_map, heap_start);
|
||||
|
|
Loading…
Add table
Reference in a new issue