#![no_main] #![feature(compiler_builtins_lib)] #![feature(custom_test_frameworks)] #![feature(abi_x86_interrupt)] #![feature(panic_info_message)] #![test_runner(crate::testing::serial_test_runner)] #![reexport_test_harness_main = "test_main"] #![no_std] pub mod interrupts; pub mod io; pub mod testing; use core::fmt::Write; pub use io::qemu::{exit_qemu, QemuExitCode}; pub use io::vga_text::OStream; pub use io::{qemu, serial, vga_text}; #[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); } 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) -> ! { let mut stderr = OStream::new(); stderr.set_state(vga_text::CharState::from_colors( vga_text::Color::LightRed, vga_text::Color::Red, )); stderr.clear(); stderr.print(b"uff-os"); stderr.set_row(10); stderr.set_state(vga_text::CharState::from_colors( vga_text::Color::White, vga_text::Color::Red, )); stderr.print_centered(b""); stderr.set_row(14); stderr.set_state(vga_text::CharState::from_colors( vga_text::Color::Cyan, vga_text::Color::Red, )); stderr.set_centered(true); write!( &mut stderr, "{:?}", info.message() .unwrap_or(&format_args!("no panic information obtainable")) ); stderr.set_centered(false); if cfg!(test) { write!(serial::SerialStream::new(), "Testing failed\n").unwrap(); qemu::exit_qemu(qemu::QemuExitCode::Failed); } loop {} }