mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 08:06:17 +04:00
Merge branch 'master' of github.com:rcore-os/rCore
This commit is contained in:
commit
17b55552d1
@ -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!()
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -327,8 +327,10 @@ impl Syscall<'_> {
|
||||
pub fn sys_nanosleep(&mut self, req: *const TimeSpec) -> SysResult {
|
||||
let time = unsafe { *self.vm().check_read_ptr(req)? };
|
||||
info!("nanosleep: time: {:#?}", time);
|
||||
// TODO: handle spurious wakeup
|
||||
thread::sleep(time.to_duration());
|
||||
if !time.is_zero() {
|
||||
// TODO: handle spurious wakeup
|
||||
thread::sleep(time.to_duration());
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
|
@ -169,6 +169,8 @@ impl Into<Timespec> for TimeSpec {
|
||||
sec: self.sec as i64,
|
||||
nsec: self.nsec as i32,
|
||||
}
|
||||
pub fn is_zero(&self) -> bool {
|
||||
self.sec == 0 && self.nsec == 0
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user