#![no_std] #![no_main] #![feature(custom_test_frameworks)] #![test_runner(bottleos::test_runner)] #![reexport_test_harness_main = "test_main"] extern crate alloc; use alloc::{boxed::Box, rc::Rc, vec, vec::Vec}; use bootloader::{entry_point, BootInfo}; use bottleos::kprintln; use core::panic::PanicInfo; entry_point!(kernel_main); fn kernel_main(boot_info: &'static BootInfo) -> ! { use bottleos::allocator; use bottleos::memory::{self, BootInfoFrameAllocator}; use x86_64::VirtAddr; kprintln!("Hello kernel world!"); bottleos::init(); 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 { BootInfoFrameAllocator::init(&boot_info.memory_map) }; allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed"); let heap_value = Box::new(41); kprintln!("heap_value at {:p}", heap_value); let mut vec = Vec::new(); for i in 0..500 { vec.push(i); } kprintln!("vec at {:p}", vec.as_slice()); let reference_counted = Rc::new(vec![1, 2, 3]); let cloned_reference = reference_counted.clone(); kprintln!( "current reference count is {}", Rc::strong_count(&cloned_reference) ); core::mem::drop(reference_counted); kprintln!( "reference count is {} now", Rc::strong_count(&cloned_reference) ); #[cfg(test)] test_main(); kprintln!("Kernel did not crash. Phew."); bottleos::hlt_loop(); } #[cfg(not(test))] #[panic_handler] fn panic(info: &PanicInfo) -> ! { kprintln!("{}", info); bottleos::hlt_loop(); } #[cfg(test)] #[panic_handler] fn panic(info: &PanicInfo) -> ! { bottleos::test_panic_handler(info) }