diff --git a/kernel/kernel/Syscall.cpp b/kernel/kernel/Syscall.cpp index b7157903..8030512e 100644 --- a/kernel/kernel/Syscall.cpp +++ b/kernel/kernel/Syscall.cpp @@ -106,6 +106,12 @@ namespace Kernel return ret.value()->pid(); } + long sys_sleep(unsigned int seconds) + { + PIT::sleep(seconds * 1000); + return 0; + } + extern "C" long sys_fork_trampoline(); extern "C" long cpp_syscall_handler(int syscall, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5) @@ -162,6 +168,9 @@ namespace Kernel case SYS_FORK: ret = sys_fork_trampoline(); break; + case SYS_SLEEP: + ret = sys_sleep((unsigned int)arg1); + break; default: Kernel::panic("Unknown syscall {}", syscall); } diff --git a/libc/include/sys/syscall.h b/libc/include/sys/syscall.h index 4fd4e125..1d9e67e6 100644 --- a/libc/include/sys/syscall.h +++ b/libc/include/sys/syscall.h @@ -18,6 +18,7 @@ __BEGIN_DECLS #define SYS_GET_TERMIOS 11 #define SYS_SET_TERMIOS 12 #define SYS_FORK 13 +#define SYS_SLEEP 14 __END_DECLS diff --git a/libc/unistd.cpp b/libc/unistd.cpp index 898bb1c1..9e6bc6fa 100644 --- a/libc/unistd.cpp +++ b/libc/unistd.cpp @@ -108,6 +108,12 @@ long syscall(long syscall, ...) ret = Kernel::syscall(SYS_FORK); break; } + case SYS_SLEEP: + { + unsigned int seconds = va_arg(args, unsigned int); + ret = Kernel::syscall(SYS_SLEEP, seconds); + break; + } default: puts("LibC: Unhandeled syscall"); ret = -ENOSYS; @@ -129,3 +135,8 @@ pid_t fork(void) { return syscall(SYS_FORK); } + +unsigned int sleep(unsigned int seconds) +{ + return syscall(SYS_SLEEP, seconds); +} \ No newline at end of file