2019-09-23 16:12:07 -04:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
2019-09-24 13:38:25 -04:00
|
|
|
#![feature(custom_test_frameworks)]
|
|
|
|
#![test_runner(blog_os::test_runner)]
|
|
|
|
#![reexport_test_harness_main = "test_main"]
|
2019-09-23 16:12:07 -04:00
|
|
|
|
|
|
|
use core::panic::PanicInfo;
|
|
|
|
|
2019-09-24 13:38:25 -04:00
|
|
|
use blog_os::println;
|
2019-10-01 13:53:03 -04:00
|
|
|
use bootloader::{entry_point, BootInfo};
|
2019-09-24 10:20:27 -04:00
|
|
|
|
2019-09-23 16:12:07 -04:00
|
|
|
/// This function is called on panic.
|
2019-09-24 13:38:25 -04:00
|
|
|
#[cfg(not(test))]
|
2019-09-23 16:12:07 -04:00
|
|
|
#[panic_handler]
|
2019-09-24 10:20:27 -04:00
|
|
|
fn panic(info: &PanicInfo) -> ! {
|
|
|
|
println!("{}", info);
|
2019-09-25 15:32:02 -04:00
|
|
|
blog_os::hlt_loop();
|
2019-09-23 16:12:07 -04:00
|
|
|
}
|
|
|
|
|
2019-09-24 13:38:25 -04:00
|
|
|
#[cfg(test)]
|
|
|
|
#[panic_handler]
|
|
|
|
fn panic(info: &PanicInfo) -> ! {
|
|
|
|
blog_os::test_panic_handler(info)
|
|
|
|
}
|
|
|
|
|
2019-10-01 13:53:03 -04:00
|
|
|
entry_point!(kernel_main);
|
|
|
|
|
|
|
|
fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
|
|
|
use blog_os::memory;
|
|
|
|
use x86_64::{structures::paging::Page, VirtAddr};
|
2019-09-24 13:38:25 -04:00
|
|
|
|
2019-10-01 13:53:03 -04:00
|
|
|
println!("Hello World{}", "!");
|
2019-09-24 16:24:38 -04:00
|
|
|
blog_os::init();
|
|
|
|
|
2019-10-01 13:53:03 -04:00
|
|
|
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(0xdeadbeef000));
|
|
|
|
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(0x_f021_f077_f065_f04e);
|
|
|
|
}
|
|
|
|
|
2019-09-24 13:38:25 -04:00
|
|
|
#[cfg(test)]
|
|
|
|
test_main();
|
2019-09-23 16:31:22 -04:00
|
|
|
|
2019-09-24 16:59:20 -04:00
|
|
|
println!("It did not crash!");
|
2019-09-25 15:32:02 -04:00
|
|
|
blog_os::hlt_loop();
|
2019-09-23 16:12:07 -04:00
|
|
|
}
|