From ffa5a3c2dd4eb887821699ba434cbb6eb93b23b8 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 19 May 2025 01:01:11 -0400 Subject: kernel: syscall: Add SYS_reboot syscall Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/reboot.c | 10 ++++++++++ sys/include/sys/reboot.h | 4 +++- sys/include/sys/syscall.h | 1 + sys/kern/kern_syscall.c | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sys/arch/amd64/amd64/reboot.c b/sys/arch/amd64/amd64/reboot.c index 64db09e..d47a352 100644 --- a/sys/arch/amd64/amd64/reboot.c +++ b/sys/arch/amd64/amd64/reboot.c @@ -50,3 +50,13 @@ cpu_reboot(int method) outb(0x64, 0xFE); } } + +/* + * arg0: Method bits + */ +scret_t +sys_reboot(struct syscall_args *scargs) +{ + cpu_reboot(scargs->arg0); + __builtin_unreachable(); +} diff --git a/sys/include/sys/reboot.h b/sys/include/sys/reboot.h index eeb55f8..846073d 100644 --- a/sys/include/sys/reboot.h +++ b/sys/include/sys/reboot.h @@ -32,13 +32,15 @@ #include #include +#include -#if defined(_KERNEL) #define REBOOT_RESET 0x00000000 #define REBOOT_HALT BIT(0) /* Halt instead of rebooting */ #define REBOOT_POWEROFF BIT(1) /* Power off (needs REBOOT_HALT set too) */ void cpu_reboot(int method); +#if defined(_KERNEL) +scret_t sys_reboot(struct syscall_args *scargs); #endif /* _KERNEL */ #endif /* _SYS_REBOOT_H_ */ diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h index 16c4b17..2223a96 100644 --- a/sys/include/sys/syscall.h +++ b/sys/include/sys/syscall.h @@ -47,6 +47,7 @@ #define SYS_sysctl 6 #define SYS_write 7 #define SYS_spawn 8 +#define SYS_reboot 9 #if defined(_KERNEL) /* Syscall return value and arg type */ diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c index bc61fa6..249a04a 100644 --- a/sys/kern/kern_syscall.c +++ b/sys/kern/kern_syscall.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,7 @@ scret_t(*g_sctab[])(struct syscall_args *) = { sys_sysctl, /* SYS_sysctl */ sys_write, /* SYS_write */ sys_spawn, /* SYS_spawn */ + sys_reboot, /* SYS_reboot */ }; const size_t MAX_SYSCALLS = NELEM(g_sctab); -- cgit v1.2.3