mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
51 lines
1.3 KiB
Rust
51 lines
1.3 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
#![feature(custom_test_frameworks)]
|
|
#![test_runner(blog_os::test_runner)]
|
|
#![reexport_test_harness_main = "test_main"]
|
|
|
|
use blog_os::println;
|
|
use bootloader::{entry_point, BootInfo};
|
|
use core::panic::PanicInfo;
|
|
|
|
entry_point!(kernel_main);
|
|
|
|
fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
|
use blog_os::memory;
|
|
use x86_64::{structures::paging::Page, VirtAddr};
|
|
|
|
println!("Hello World{}", "!");
|
|
blog_os::init();
|
|
|
|
let mut mapper = unsafe { memory::init(boot_info.physical_memory_offset) };
|
|
let mut frame_allocator = memory::init_frame_allocator(&boot_info.memory_map);
|
|
|
|
// map a previously unmapped page
|
|
let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000));
|
|
memory::create_example_mapping(page, &mut mapper, &mut frame_allocator);
|
|
|
|
// write the string `New!` to the screen through the new mapping
|
|
let page_ptr: *mut u64 = page.start_address().as_mut_ptr();
|
|
unsafe { page_ptr.offset(400).write_volatile(0x_f021_f077_f065_f04e) };
|
|
|
|
#[cfg(test)]
|
|
test_main();
|
|
|
|
println!("It did not crash!");
|
|
blog_os::hlt_loop();
|
|
}
|
|
|
|
/// This function is called on panic.
|
|
#[cfg(not(test))]
|
|
#[panic_handler]
|
|
fn panic(info: &PanicInfo) -> ! {
|
|
println!("{}", info);
|
|
blog_os::hlt_loop();
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[panic_handler]
|
|
fn panic(info: &PanicInfo) -> ! {
|
|
blog_os::test_panic_handler(info)
|
|
}
|