Skip to content

Commit

Permalink
use crate qemu-exit to leave the vm
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Sep 14, 2024
1 parent 5dff4fb commit 30b6ba8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 11 additions & 19 deletions src/arch/x86/processor.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion test.ps1
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 30b6ba8

Please sign in to comment.