Skip to content

Commit 087e18b

Browse files
author
Jiajie Chen
committed
Implement reboot in sys_reboot
1 parent e77e09a commit 087e18b

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

kernel/src/arch/aarch64/cpu.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ pub fn id() -> usize {
1111
pub unsafe fn exit_in_qemu(_error_code: u8) -> ! {
1212
unimplemented!()
1313
}
14+
15+
pub unsafe fn reboot() -> ! {
16+
unimplemented!()
17+
}

kernel/src/arch/mipsel/cpu.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ pub unsafe fn exit_in_qemu(error_code: u8) -> ! {
3131
/* nothing to do */
3232
loop {}
3333
}
34+
35+
pub unsafe fn reboot() -> ! {
36+
/* nothing to do */
37+
loop {}
38+
}

kernel/src/arch/riscv32/cpu.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ pub fn halt() {
2121
pub unsafe fn exit_in_qemu(error_code: u8) -> ! {
2222
super::sbi::shutdown()
2323
}
24+
25+
pub unsafe fn reboot() -> ! {
26+
super::sbi::shutdown()
27+
}

kernel/src/arch/x86_64/cpu.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ pub unsafe fn exit_in_qemu(error_code: u8) -> ! {
1414
unreachable!()
1515
}
1616

17+
pub unsafe fn reboot() -> ! {
18+
use x86_64::instructions::port::Port;
19+
Port::new(0x64).write(0xfeu8);
20+
unreachable!()
21+
}
22+
1723
pub fn id() -> usize {
1824
CpuId::new()
1925
.get_feature_info()

kernel/src/syscall/misc.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ impl Syscall<'_> {
122122
unsafe {
123123
cpu::exit_in_qemu(1);
124124
}
125+
} else if cmd == LINUX_REBOOT_CMD_RESTART {
126+
unsafe {
127+
cpu::reboot();
128+
}
125129
}
126130
Ok(0)
127131
}
@@ -188,7 +192,14 @@ impl Syscall<'_> {
188192
}
189193
}
190194

191-
const LINUX_REBOOT_CMD_HALT: u32 = 0xcdef0123;
195+
const LINUX_REBOOT_CMD_RESTART: u32 = 0x01234567;
196+
const LINUX_REBOOT_CMD_HALT: u32 = 0xCDEF0123;
197+
const LINUX_REBOOT_CMD_CAD_ON: u32 = 0x89ABCDEF;
198+
const LINUX_REBOOT_CMD_CAD_OFF: u32 = 0x00000000;
199+
const LINUX_REBOOT_CMD_POWER_OFF: u32 = 0x4321FEDC;
200+
const LINUX_REBOOT_CMD_RESTART2: u32 = 0xA1B2C3D4;
201+
const LINUX_REBOOT_CMD_SW_SUSPEND: u32 = 0xD000FCE2;
202+
const LINUX_REBOOT_CMD_KEXEC: u32 = 0x45584543;
192203

193204
#[repr(C)]
194205
#[derive(Debug, Default)]

0 commit comments

Comments
 (0)