diff options
-rw-r--r-- | kernel/include/comus/syscalls.h | 3 | ||||
-rw-r--r-- | kernel/syscall.c | 23 | ||||
-rw-r--r-- | user/include/unistd.h | 7 | ||||
-rw-r--r-- | user/lib/syscall.S | 1 | ||||
-rw-r--r-- | user/poweroff.c | 6 |
5 files changed, 32 insertions, 8 deletions
diff --git a/kernel/include/comus/syscalls.h b/kernel/include/comus/syscalls.h index 3b9ea70..0105104 100644 --- a/kernel/include/comus/syscalls.h +++ b/kernel/include/comus/syscalls.h @@ -27,9 +27,10 @@ #define SYS_sleep 14 #define SYS_brk 15 #define SYS_sbrk 16 +#define SYS_poweroff 17 // UPDATE THIS DEFINITION IF MORE SYSCALLS ARE ADDED! -#define N_SYSCALLS 17 +#define N_SYSCALLS 18 // interrupt vector entry for system calls #define VEC_SYSCALL 0x80 diff --git a/kernel/syscall.c b/kernel/syscall.c index 12db401..00e6afb 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -1,6 +1,6 @@ #include <comus/cpu.h> #include <comus/syscalls.h> -#include <comus/drivers/uart.h> +#include <comus/drivers/acpi.h> #include <comus/memory.h> #include <comus/procs.h> @@ -52,13 +52,22 @@ static int sys_write(void) return nbytes; } +static int sys_poweroff(void) +{ + acpi_shutdown(); + return 1; +} + static int (*syscall_tbl[N_SYSCALLS])(void) = { - [SYS_exit] = sys_exit, [SYS_waitpid] = NULL, [SYS_fork] = NULL, - [SYS_exec] = NULL, [SYS_open] = NULL, [SYS_close] = NULL, - [SYS_read] = NULL, [SYS_write] = sys_write, [SYS_getpid] = NULL, - [SYS_getppid] = NULL, [SYS_gettime] = NULL, [SYS_getprio] = NULL, - [SYS_setprio] = NULL, [SYS_kill] = NULL, [SYS_sleep] = NULL, - [SYS_brk] = NULL, [SYS_sbrk] = NULL, + [SYS_exit] = sys_exit, [SYS_waitpid] = NULL, + [SYS_fork] = NULL, [SYS_exec] = NULL, + [SYS_open] = NULL, [SYS_close] = NULL, + [SYS_read] = NULL, [SYS_write] = sys_write, + [SYS_getpid] = NULL, [SYS_getppid] = NULL, + [SYS_gettime] = NULL, [SYS_getprio] = NULL, + [SYS_setprio] = NULL, [SYS_kill] = NULL, + [SYS_sleep] = NULL, [SYS_brk] = NULL, + [SYS_sbrk] = NULL, [SYS_poweroff] = sys_poweroff, }; void syscall_handler(struct cpu_regs *regs) diff --git a/user/include/unistd.h b/user/include/unistd.h index a815914..bbacdbe 100644 --- a/user/include/unistd.h +++ b/user/include/unistd.h @@ -162,4 +162,11 @@ extern void *brk(const void *addr); */ extern void *sbrk(intptr_t increment); +/** + * Poweroff the system. + * + * @return 1 on failure + */ +extern int poweroff(void); + #endif /* unistd.h */ diff --git a/user/lib/syscall.S b/user/lib/syscall.S index fc1ab93..c5a23b5 100644 --- a/user/lib/syscall.S +++ b/user/lib/syscall.S @@ -24,3 +24,4 @@ SYSCALL kill SYS_kill SYSCALL sleep SYS_sleep SYSCALL brk SYS_brk SYSCALL sbrk SYS_sbrk +SYSCALL poweroff SYS_poweroff diff --git a/user/poweroff.c b/user/poweroff.c new file mode 100644 index 0000000..f51a86f --- /dev/null +++ b/user/poweroff.c @@ -0,0 +1,6 @@ +#include <unistd.h> + +int main(void) +{ + return poweroff(); +} |