Browse Source

:new: 增加重启命令reboot

fslongjin 2 years ago
parent
commit
8bd7b64a0b
4 changed files with 22 additions and 2 deletions
  1. 15 1
      kernel/syscall/syscall.c
  2. 1 0
      kernel/syscall/syscall_num.h
  3. 5 1
      user/apps/shell/cmd.c
  4. 1 0
      user/libs/libsystem/syscall.h

+ 15 - 1
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};

+ 1 - 0
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的系统调用

+ 5 - 1
user/apps/shell/cmd.c

@@ -2,6 +2,7 @@
 #include <libc/string.h>
 #include <libc/stdio.h>
 #include <libc/stddef.h>
+#include <libsystem/syscall.h>
 
 // 当前工作目录(在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) {}
+int shell_cmd_reboot(int argc, char **argv)
+{
+    return syscall_invoke(SYS_REBOOT, 0, 0, 0, 0, 0, 0, 0, 0);
+}

+ 1 - 0
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 用户态系统调用函数