main.rs
1 #![no_std] 2 #![no_main] 3 #![feature(custom_test_frameworks)] 4 #![test_runner(blog_os::test_runner)] 5 #![reexport_test_harness_main = "test_main"] 6 7 extern crate alloc; 8 9 use core::panic::PanicInfo; 10 use blog_os::println; 11 use bootloader::{BootInfo, entry_point}; 12 use blog_os::task::{Task}; 13 use blog_os::task::keyboard; 14 use blog_os::task::executor::Executor; 15 16 entry_point!(kernel_main); 17 18 fn kernel_main(boot_info: &'static BootInfo) -> ! { 19 use blog_os::allocator; 20 use blog_os::memory::{self, BootInfoFrameAllocator}; 21 use x86_64::VirtAddr; 22 23 println!("Hello World{}", "!"); 24 blog_os::init(); 25 26 let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset); 27 let mut mapper = unsafe { memory::init(phys_mem_offset) }; 28 let mut frame_allocator = unsafe { 29 BootInfoFrameAllocator::init(&boot_info.memory_map) 30 }; 31 32 allocator::init_heap(&mut mapper, &mut frame_allocator) 33 .expect("heap initialization failed"); 34 35 #[cfg(test)] 36 test_main(); 37 38 let mut executor = Executor::new(); 39 executor.spawn(Task::new(example_task())); 40 executor.spawn(Task::new(keyboard::print_keypresses())); 41 executor.run(); 42 } 43 44 async fn async_number() -> u32 { 45 42 46 } 47 48 async fn example_task() { 49 let number = async_number().await; 50 println!("async number: {}", number); 51 } 52 53 #[cfg(not(test))] 54 #[panic_handler] 55 fn panic(info: &PanicInfo) -> ! { 56 println!("{}", info); 57 blog_os::hlt_loop(); 58 } 59 60 #[cfg(test)] 61 #[panic_handler] 62 fn panic(info: &PanicInfo) -> ! { 63 blog_os::test_panic_handler(info) 64 }