// #![feature(abi_x86_interrupt, asm)] #![no_std] #![no_main] #![feature(custom_test_frameworks)] #![test_runner(crate::test_runner)] #![reexport_test_harness_main = "test_main"] #[macro_use] mod vga_buffer; #[macro_use] mod serial; use core::panic::PanicInfo; #[cfg(not(test))] #[panic_handler] fn panic(info: &PanicInfo) -> ! { println!("{info}"); loop {} } #[cfg(test)] #[panic_handler] fn panic(info: &PanicInfo) -> ! { serial_println!("[failed]\n"); serial_println!("Error: {}", info); exit_qemu(QemuExitCode::Failed); loop {} } #[no_mangle] pub extern "C" fn _start() -> ! { #[cfg(test)] test_main(); println!("Gamarjoba, munde!"); loop {} } #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u32)] pub enum QemuExitCode { Success = 0x10, Failed = 0x11, } pub fn exit_qemu(exit_code: QemuExitCode) { use x86_64::instructions::port::Port; unsafe { let mut port = Port::new(0xf4); // isa-debug-exit port, see Cargo.toml port.write(exit_code as u32); } } pub trait TestFunction { fn run(&self) -> (); } impl TestFunction for T where T: Fn(), { fn run(&self) { serial_print!("{}...\t", core::any::type_name::()); self(); serial_println!("[ok]"); } } #[cfg(test)] fn test_runner(tests: &[&dyn TestFunction]) { serial_println!("Running {} test(s)", tests.len()); for test in tests { test.run(); } exit_qemu(QemuExitCode::Success); } #[test_case] fn basic_test() { assert_eq!(5, 5); } #[test_case] fn basic_test2() { assert_eq!(4, 4); }