1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-22 08:06:17 +04:00

Let halt quit QEMU with zero exit code

This commit is contained in:
Jiajie Chen 2020-05-11 12:13:49 +08:00
parent 0bd8e58a47
commit 14f74aaaeb
2 changed files with 8 additions and 4 deletions

View File

@ -6,11 +6,15 @@ use x86_64::registers::control::{Cr0, Cr0Flags};
/// Exit qemu
/// See: https://wiki.osdev.org/Shutdown
/// Must run qemu with `-device isa-debug-exit`
/// The error code is `value written to 0x501` *2 +1, so it should be odd
/// The error code is `value written to 0x501` *2 +1, so it should be odd when non-zero
pub unsafe fn exit_in_qemu(error_code: u8) -> ! {
use x86_64::instructions::port::Port;
assert_eq!(error_code & 1, 1, "error code should be odd");
Port::new(0x501).write((error_code - 1) / 2);
if error_code == 0 {
Port::new(0xB004).write(0x2000 as u16);
} else {
assert_eq!(error_code & 1, 1, "error code should be odd");
Port::new(0x501).write((error_code - 1) / 2);
}
unreachable!()
}

View File

@ -122,7 +122,7 @@ impl Syscall<'_> {
// we will skip verifying magic
if cmd == LINUX_REBOOT_CMD_HALT {
unsafe {
cpu::exit_in_qemu(1);
cpu::exit_in_qemu(0);
}
} else if cmd == LINUX_REBOOT_CMD_RESTART {
unsafe {