#![no_main] #![feature(compiler_builtins_lib)] #![feature(custom_test_frameworks)] #![feature(abi_x86_interrupt)] #![feature(panic_info_message)] #![test_runner(crate::test_runner)] #![reexport_test_harness_main = "test_main"] #![no_std] mod interrupts; mod io; use core::fmt::Write; use io::vga_text::OStream; use io::{qemu, serial, vga_text}; #[cfg(test)] pub fn test_runner(tests: &[&dyn Fn(&mut OStream)]) { let mut stdout = OStream::new(); stdout.clear(); write!(&mut stdout, "running {} tests\n", tests.len()).unwrap(); for test in tests { test(&mut stdout) } } #[no_mangle] pub extern "C" fn _start() -> ! { interrupts::gdt::init(); interrupts::table::init(); if cfg!(test) { #[cfg(test)] test_main(); qemu::exit_qemu(qemu::QemuExitCode::Success); } fn _loop(i: u64) -> u64 { if i > 0b1010101001101101 { return i; } let n = i; let mut stdout = OStream::new(); write!(&mut stdout, "{:x}", &n as *const u64 as u64).unwrap(); _loop(i + 1) } _loop(0); x86_64::instructions::interrupts::int3(); let stdout = OStream::new(); stdout.clear(); panic!("panic! at the disco"); /// TODO: write test ///fn _loop(i: u64) -> u64 { /// if i > 0b1010101001101101 { /// return i; /// } /// let n = i; /// let mut stdout = OStream::new(); /// write!(&mut stdout, "{:x}", &n as *const u64 as u64).unwrap(); /// _loop(i + 1) ///} ///_loop(0); /// TODO: write test ///x86_64::instructions::interrupts::int3(); loop {} } #[panic_handler] #[no_mangle] pub extern "C" fn panic_handler(info: &core::panic::PanicInfo) -> ! { io::panic_screen::show(info.message()); if cfg!(test) { write!(serial::SerialStream::new(), "Testing failed\n").unwrap(); qemu::exit_qemu(qemu::QemuExitCode::Failed); } loop {} }