From 93a29060e5eb58b2919d98bb8e286694707b41bc Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 23 Nov 2021 06:01:42 -0600 Subject: [PATCH] b --- ableos/src/arch/x86_64/mod.rs | 34 +++++++++++++++++++++++++++------- ableos/src/kmain.rs | 20 +++----------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/ableos/src/arch/x86_64/mod.rs b/ableos/src/arch/x86_64/mod.rs index 2944251f..79a63a44 100644 --- a/ableos/src/arch/x86_64/mod.rs +++ b/ableos/src/arch/x86_64/mod.rs @@ -1,15 +1,35 @@ -use x86_64::instructions::hlt; -use bootloader::BootInfo; +use x86_64::{ + instructions::hlt, + {structures::paging::Page, VirtAddr}, +}; + +use bootloader::{entry_point, BootInfo}; + pub mod drivers; pub mod gdt; pub mod init; pub mod interrupts; pub mod memory; -// #[no_mangle] -// pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! { -// crate::kmain::kernel_main(boot_info); -// // sloop(); -// } + +entry_point![start]; +#[no_mangle] +pub fn start(boot_info: &'static BootInfo) -> ! { + let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset); + + let mut mapper = unsafe { memory::init(phys_mem_offset) }; + let mut frame_allocator = + unsafe { memory::BootInfoFrameAllocator::init(&boot_info.memory_map) }; + + let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000)); + memory::create_example_mapping(page, &mut mapper, &mut frame_allocator); + + let page_ptr: *mut u64 = page.start_address().as_mut_ptr(); + unsafe { page_ptr.offset(400).write_volatile(0xf021_f077_f065_804e) }; + + crate::kmain::kernel_main(); + + // sloop(); +} #[allow(unused)] pub fn shutdown() -> ! { diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 085e4bbb..be6186d7 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -12,10 +12,8 @@ use crate::{ relib::math::rand::{linearshift::LinearShiftRegister, prand::PRand, RAND_HANDLE, RNG}, serial_print, serial_println, }; -use bootloader::{entry_point, BootInfo}; -use lazy_static::lazy_static; -use x86_64::{structures::paging::Page, VirtAddr}; +use lazy_static::lazy_static; #[no_mangle] #[allow(unconditional_recursion)] @@ -30,9 +28,9 @@ lazy_static! { pub static ref KEY_BUFFER_POINTER: u8 = 0; } // Defines the entry point -entry_point![kernel_main]; + #[no_mangle] -pub fn kernel_main(boot_info: &'static BootInfo) -> ! { +pub fn kernel_main() -> ! { init::init(); GraphicsBuffer::draw(); @@ -62,18 +60,6 @@ pub fn kernel_main(boot_info: &'static BootInfo) -> ! { // x.dump_flags(); } - let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset); - - let mut mapper = unsafe { memory::init(phys_mem_offset) }; - let mut frame_allocator = - unsafe { memory::BootInfoFrameAllocator::init(&boot_info.memory_map) }; - - let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000)); - memory::create_example_mapping(page, &mut mapper, &mut frame_allocator); - - let page_ptr: *mut u64 = page.start_address().as_mut_ptr(); - unsafe { page_ptr.offset(400).write_volatile(0xf021_f077_f065_804e) }; - // stack_overflow(); // crate::arch::shutdown(); sloop()