From 670619e1618f60bca4ea2bb8612a06a3a2dd0ea9 Mon Sep 17 00:00:00 2001 From: jeebuscrossaint Date: Sat, 6 Jul 2024 00:18:36 -0400 Subject: [PATCH] Proper Qemu Test Exits --- Cargo.lock | 39 ++++++++++++++++++++++++++++++++++++++- Cargo.toml | 4 +++- src/main.rs | 20 +++++++++++++++++++- src/vga_buffer.rs | 2 +- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2016def..c21bbbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,18 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "bit_field" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "bootloader" version = "0.9.29" @@ -24,9 +36,16 @@ dependencies = [ "bootloader", "lazy_static", "spin 0.5.2", - "volatile", + "volatile 0.2.7", + "x86_64", ] +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" + [[package]] name = "spin" version = "0.5.2" @@ -44,3 +63,21 @@ name = "volatile" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6b06ad3ed06fef1713569d547cdbdb439eafed76341820fb0e0344f29a41945" + +[[package]] +name = "volatile" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793" + +[[package]] +name = "x86_64" +version = "0.14.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96cb6fd45bfeab6a5055c5bffdb08768bd0c069f1d946debe585bbb380a7c062" +dependencies = [ + "bit_field", + "bitflags", + "rustversion", + "volatile 0.4.6", +] diff --git a/Cargo.toml b/Cargo.toml index 54c6444..4747565 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" bootloader = "0.9" volatile = "0.2.6" spin = "0.5.2" +x86_64 = "0.14.2" #// DO NOTE THAT IN CARGO AS OF TO MY KNOWLEDGE 2019 AND EVEN NOW IN 2024 #// THERE IS A BUG IN CARGO WHERE THERE ARE "duplicate lang item" ERRORS @@ -25,4 +26,5 @@ version = "1.0" features = ["spin_no_std"] [package.metadata.bootimage] -test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"] \ No newline at end of file +test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"] +test-success-exit-code = 33 # (0x10 << 1) | 1 \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index c7ce8ef..41e0ae1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,11 +57,13 @@ pub extern "C" fn _start() -> ! { // ON CARGO TEST IN SOME CASES. TO FIX REMOVE/COMMENT OUT THE ' panic = "abort" ' // FOR A PROFILE IN THE CARGO.TOML FILE #[cfg(test)] -pub fn test_runner(tests: &[&dyn Fn()]) { +fn test_runner(tests: &[&dyn Fn()]) { println!("Running {} tests", tests.len()); for test in tests { test(); } + //new + exit_qemu(QemuExitCode::Success); } #[test_case] @@ -69,4 +71,20 @@ fn trivial_assertion() { print!("trivial assertion... "); assert_eq!(1, 1); println!("[ok]"); +} + +#[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); + port.write(exit_code as u32); + } } \ No newline at end of file diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 6cd701d..c402ef6 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -148,7 +148,7 @@ use lazy_static::lazy_static; lazy_static! { pub static ref WRITER: Mutex = Mutex::new(Writer { column_position: 0, - color_code: ColorCode::new(Color::Yellow, Color::Black), + color_code: ColorCode::new(Color::White, Color::Black), buffer: unsafe { &mut *(0xb8000 as *mut Buffer) }, }); }