From 8bd7b64a0bac01375058d0d236b24b65a8a07709 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Wed, 25 May 2022 14:38:15 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20=E5=A2=9E=E5=8A=A0=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E5=91=BD=E4=BB=A4reboot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/syscall/syscall.c | 16 +++++++++++++++- kernel/syscall/syscall_num.h | 1 + user/apps/shell/cmd.c | 6 +++++- user/libs/libsystem/syscall.h | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/kernel/syscall/syscall.c b/kernel/syscall/syscall.c index baeb638a8..bf2536981 100644 --- a/kernel/syscall/syscall.c +++ b/kernel/syscall/syscall.c @@ -442,6 +442,19 @@ uint64_t sys_sbrk(struct pt_regs *regs) return retval; } +/** + * @brief 重启计算机 + * + * @return + */ +uint64_t sys_reboot(struct pt_regs *regs) +{ + // 重启计算机 + io_out8(0x64, 0xfe); + + return 0; +} + ul sys_ahci_end_req(struct pt_regs *regs) { ahci_end_request(); @@ -469,5 +482,6 @@ system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] = [8] = sys_vfork, [9] = sys_brk, [10] = sys_sbrk, - [11 ... 254] = system_call_not_exists, + [11] = sys_reboot, + [12 ... 254] = system_call_not_exists, [255] = sys_ahci_end_req}; diff --git a/kernel/syscall/syscall_num.h b/kernel/syscall/syscall_num.h index 9e4f7eb17..13a180f59 100644 --- a/kernel/syscall/syscall_num.h +++ b/kernel/syscall/syscall_num.h @@ -20,5 +20,6 @@ #define SYS_VFORK 8 #define SYS_BRK 9 #define SYS_SBRK 10 +#define SYS_REBOOT 11 // 重启 #define SYS_AHCI_END_REQ 255 // AHCI DMA请求结束end_request的系统调用 \ No newline at end of file diff --git a/user/apps/shell/cmd.c b/user/apps/shell/cmd.c index 7c0ee9516..dee576609 100644 --- a/user/apps/shell/cmd.c +++ b/user/apps/shell/cmd.c @@ -2,6 +2,7 @@ #include #include #include +#include // 当前工作目录(在main_loop中初始化) char *shell_current_path = NULL; @@ -163,4 +164,7 @@ int shell_cmd_exec(int argc, char **argv) {} * @return int */ // todo: -int shell_cmd_reboot(int argc, char **argv) {} \ No newline at end of file +int shell_cmd_reboot(int argc, char **argv) +{ + return syscall_invoke(SYS_REBOOT, 0, 0, 0, 0, 0, 0, 0, 0); +} \ No newline at end of file diff --git a/user/libs/libsystem/syscall.h b/user/libs/libsystem/syscall.h index 51ffed683..75253ce22 100644 --- a/user/libs/libsystem/syscall.h +++ b/user/libs/libsystem/syscall.h @@ -14,6 +14,7 @@ #define SYS_VFORK 8 #define SYS_BRK 9 #define SYS_SBRK 10 +#define SYS_REBOOT 11 /** * @brief 用户态系统调用函数