diff --git a/Cargo.lock b/Cargo.lock index 08f66c5..02f2ba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,7 @@ version = "0.1.0" dependencies = [ "bootloader", "cfg-if", + "qemu-exit", "spinning_top", "x86", ] @@ -52,6 +53,12 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "qemu-exit" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bb0fd6580eeed0103c054e3fba2c2618ff476943762f28a645b63b8692b21c9" + [[package]] name = "raw-cpuid" version = "10.7.0" diff --git a/Cargo.toml b/Cargo.toml index ae0c388..efb7d95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,13 +16,13 @@ run-command = ["qemu-system-x86_64", "-display", "none", "-smp", "1", "-m", "256 run-args = [] [features] -default = ["qemu_exit"] +default = ["qemu-exit"] vga = [] -qemu_exit = [] [dependencies] spinning_top = "0.3.0" cfg-if = "1.0" +qemu-exit = { version = "3.0", optional = true } [target.'cfg(target_arch = "x86_64")'.dependencies] bootloader = "0.9.29" diff --git a/src/arch/x86/processor.rs b/src/arch/x86/processor.rs index ab3fcb0..84b6c68 100644 --- a/src/arch/x86/processor.rs +++ b/src/arch/x86/processor.rs @@ -1,28 +1,20 @@ +#[cfg(feature = "qemu-exit")] +use qemu_exit::QEMUExit; use x86::controlregs::*; -#[cfg(feature = "qemu_exit")] -use x86::io; - -pub(crate) fn halt() { - unsafe { - x86::halt(); - } -} - -#[cfg(feature = "qemu_exit")] -fn qemu_exit(success: bool) { - let code = if success { 3 >> 1 } else { 0 }; - unsafe { - io::outl(0xf4, code); - } -} #[allow(unused_variables)] #[no_mangle] pub extern "C" fn shutdown(error_code: i32) -> ! { - #[cfg(feature = "qemu_exit")] - qemu_exit(error_code == 0); + #[cfg(feature = "qemu-exit")] + { + // shutdown, works like Qemu's shutdown command + let qemu_exit_handle = qemu_exit::X86::new(0xf4, 5); + qemu_exit_handle.exit_success(); + } + + #[cfg(not(feature = "qemu-exit"))] loop { - halt(); + x86::halt(); } } diff --git a/test.ps1 b/test.ps1 index 7672864..ccd6aa0 100644 --- a/test.ps1 +++ b/test.ps1 @@ -1,5 +1,5 @@ Invoke-Command -Script { cargo run } -ErrorAction SilentlyContinue -IF( $LASTEXITCODE -EQ 3 ) { +IF( $LASTEXITCODE -EQ 5 ) { Write-Output "eduOS-rs runs succesfully within Qemu" Exit 0 } else { diff --git a/test.sh b/test.sh index ecd350c..6377065 100755 --- a/test.sh +++ b/test.sh @@ -1,6 +1,6 @@ #!/bin/bash cargo run -if [ $? -eq 3 ]; then +if [ $? -eq 5 ]; then echo "eduOS-rs runs succesfully within Qemu" exit 0 else