124 lines
3.6 KiB
Rust
124 lines
3.6 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
|
|
use kernel::{
|
|
memory::VirtAddr,
|
|
sync::LazyLock,
|
|
x86_64::{gdt::GlobalDescriptorTable, idt::InterruptDescriptorTable},
|
|
};
|
|
|
|
#[panic_handler]
|
|
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
|
kernel::serial_println!("[PANIC] {}", _info);
|
|
kernel::x86_64::halt_loop()
|
|
}
|
|
|
|
static IDT: LazyLock<InterruptDescriptorTable> =
|
|
LazyLock::new(InterruptDescriptorTable::new_default);
|
|
|
|
static GDT: LazyLock<GlobalDescriptorTable> = LazyLock::new(GlobalDescriptorTable::new);
|
|
|
|
/// Entry point for the kernel
|
|
#[unsafe(no_mangle)]
|
|
extern "C" fn _start() -> ! {
|
|
kernel::serial_println!("Hello, world!");
|
|
assert!(limine_requests::LIMINE_BASE_REVISION.is_supported());
|
|
|
|
_ = kernel::memory::HHDM_BASE
|
|
.try_insert(
|
|
limine_requests::HHDM_REQUEST
|
|
.offset()
|
|
.expect("HHDM offset not provided by bootloader"),
|
|
)
|
|
.expect("HHDM offset already set");
|
|
|
|
kernel::boot::init_boot_info(
|
|
limine_requests::HHDM_REQUEST
|
|
.offset()
|
|
.expect("HHDM offset not provided by bootloader"),
|
|
limine_requests::MEMMAP_REQUEST
|
|
.entries()
|
|
.iter()
|
|
.map(|&&e| e.into()),
|
|
);
|
|
|
|
kernel::serial_println!(
|
|
"HHDM offset: 0x{:#x}",
|
|
kernel::memory::HHDM_BASE.get().unwrap()
|
|
);
|
|
|
|
kernel::serial_println!(
|
|
"Memory map: {:#?}",
|
|
limine_requests::MEMMAP_REQUEST.entries()
|
|
);
|
|
|
|
GDT.load();
|
|
IDT.load();
|
|
|
|
kernel::serial_println!("entry point: 0x{:x}", _start as *const () as usize);
|
|
kernel::serial_println!(
|
|
"entry point phy: {:?}",
|
|
kernel::x86_64::paging::get_physical_addr(VirtAddr(_start as *const () as u64))
|
|
);
|
|
|
|
let pmm = kernel::memory::PhysicalMemoryAllocator::from_memory_map(
|
|
kernel::boot::BOOT_INFO
|
|
.get()
|
|
.expect("Boot info not initialized")
|
|
.memory_map,
|
|
);
|
|
|
|
kernel::serial_println!("PMM: {pmm:#?}");
|
|
|
|
let fb = limine_requests::FRAMEBUFFER_REQUEST
|
|
.framebuffers()
|
|
.first()
|
|
.expect("No framebuffer found");
|
|
|
|
kernel::serial_println!("Framebuffer: {fb:#?}");
|
|
|
|
for y in 0..fb.height {
|
|
for x in 0..fb.width {
|
|
let r = (x * 255 / fb.width) as u8;
|
|
let b = (y * 255 / fb.height) as u8;
|
|
// SAFETY: We have exclusive access to the framebuffer.
|
|
unsafe {
|
|
fb.draw_pixel(x, y, kernel::limine::Color([r, 0, b]));
|
|
}
|
|
}
|
|
}
|
|
|
|
kernel::x86_64::halt_loop()
|
|
}
|
|
|
|
mod limine_requests {
|
|
use kernel::limine::{
|
|
BaseRevision, FramebufferRequest, REQUESTS_END_MARKER, REQUESTS_START_MARKER,
|
|
RequestsEndMarker, RequestsStartMarker,
|
|
};
|
|
|
|
#[used]
|
|
#[unsafe(link_section = ".limine_requests_start")]
|
|
static LIMINE_REQUESTS_START: RequestsStartMarker = REQUESTS_START_MARKER;
|
|
|
|
#[used]
|
|
#[unsafe(link_section = ".limine_requests")]
|
|
pub static LIMINE_BASE_REVISION: BaseRevision = BaseRevision::from_revision(6);
|
|
|
|
#[used]
|
|
#[unsafe(link_section = ".limine_requests")]
|
|
pub static FRAMEBUFFER_REQUEST: FramebufferRequest = FramebufferRequest::new();
|
|
|
|
#[used]
|
|
#[unsafe(link_section = ".limine_requests")]
|
|
pub static HHDM_REQUEST: kernel::limine::HhdmRequest = kernel::limine::HhdmRequest::new();
|
|
|
|
#[used]
|
|
#[unsafe(link_section = ".limine_requests")]
|
|
pub static MEMMAP_REQUEST: kernel::limine::MemMapRequest = kernel::limine::MemMapRequest::new();
|
|
|
|
#[used]
|
|
#[unsafe(link_section = ".limine_requests_end")]
|
|
static LIMINE_REQUESTS_END: RequestsEndMarker = REQUESTS_END_MARKER;
|
|
}
|