63 lines
1.1 KiB
Rust
63 lines
1.1 KiB
Rust
// #![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;
|
|
|
|
#[panic_handler]
|
|
fn panic(info: &PanicInfo) -> ! {
|
|
println!("{info}");
|
|
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);
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
fn test_runner(tests: &[&dyn Fn()]) {
|
|
serial_println!("Running {} test(s)", tests.len());
|
|
for test in tests {
|
|
test();
|
|
}
|
|
|
|
exit_qemu(QemuExitCode::Success);
|
|
}
|
|
|
|
#[test_case]
|
|
fn basic_test() {
|
|
serial_print!("Trivial test... ");
|
|
assert_eq!(5, 5);
|
|
serial_println!("[ok]");
|
|
}
|
|
|