// Copyright 2015 Philipp Oppermann. See the README.md // file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. #![feature(lang_items)] #![feature(const_fn, unique)] #![feature(alloc, collections)] #![feature(asm)] #![feature(drop_types_in_const)] #![feature(heap_api)] #![no_std] extern crate rlibc; extern crate spin; extern crate multiboot2; #[macro_use] extern crate bitflags; extern crate x86; #[macro_use] extern crate once; extern crate hole_list_allocator; extern crate alloc; #[macro_use] extern crate collections; extern crate bit_field; #[macro_use] mod vga_buffer; mod memory; mod interrupts; #[no_mangle] pub extern "C" fn rust_main(multiboot_information_address: usize) { // ATTENTION: we have a very small stack and no guard page vga_buffer::clear_screen(); println!("Hello World{}", "!"); let boot_info = unsafe { multiboot2::load(multiboot_information_address) }; enable_nxe_bit(); enable_write_protect_bit(); // set up guard page and map the heap pages memory::init(boot_info); interrupts::init(); //println!("{:?}", unsafe { *(0xdeadbeaf as *mut u32) }); //unsafe { *(0xdeadbeaf as *mut u32) = 42 }; fn recursive() { recursive(); } recursive(); unsafe { *(0xdeadbeaf as *mut u32) = 42 }; unsafe { asm!("xor eax, eax; idiv eax" :::: "intel"); } println!("It did not crash!"); loop {} } fn enable_nxe_bit() { use x86::msr::{IA32_EFER, rdmsr, wrmsr}; let nxe_bit = 1 << 11; unsafe { let efer = rdmsr(IA32_EFER); wrmsr(IA32_EFER, efer | nxe_bit); } } fn enable_write_protect_bit() { use x86::controlregs::{cr0, cr0_write}; let wp_bit = 1 << 16; unsafe { cr0_write(cr0() | wp_bit) }; } #[cfg(not(test))] #[lang = "eh_personality"] extern "C" fn eh_personality() {} #[cfg(not(test))] #[lang = "panic_fmt"] extern "C" fn panic_fmt(fmt: core::fmt::Arguments, file: &str, line: u32) -> ! { use vga_buffer::print_error; unsafe { print_error(format_args!("\n\nPANIC in {} at line {}:", file, line)); print_error(format_args!(" {}", fmt)); } loop {} } #[no_mangle] pub extern "C" fn _Unwind_Resume() -> ! { loop {} }