Kernel: Add SYS_SLEEP

This commit is contained in:
Bananymous 2023-05-28 22:34:48 +03:00
parent 282bf24f65
commit 0c316ebfb2
3 changed files with 21 additions and 0 deletions

View File

@ -106,6 +106,12 @@ namespace Kernel
return ret.value()->pid(); 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 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) 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: case SYS_FORK:
ret = sys_fork_trampoline(); ret = sys_fork_trampoline();
break; break;
case SYS_SLEEP:
ret = sys_sleep((unsigned int)arg1);
break;
default: default:
Kernel::panic("Unknown syscall {}", syscall); Kernel::panic("Unknown syscall {}", syscall);
} }

View File

@ -18,6 +18,7 @@ __BEGIN_DECLS
#define SYS_GET_TERMIOS 11 #define SYS_GET_TERMIOS 11
#define SYS_SET_TERMIOS 12 #define SYS_SET_TERMIOS 12
#define SYS_FORK 13 #define SYS_FORK 13
#define SYS_SLEEP 14
__END_DECLS __END_DECLS

View File

@ -108,6 +108,12 @@ long syscall(long syscall, ...)
ret = Kernel::syscall(SYS_FORK); ret = Kernel::syscall(SYS_FORK);
break; break;
} }
case SYS_SLEEP:
{
unsigned int seconds = va_arg(args, unsigned int);
ret = Kernel::syscall(SYS_SLEEP, seconds);
break;
}
default: default:
puts("LibC: Unhandeled syscall"); puts("LibC: Unhandeled syscall");
ret = -ENOSYS; ret = -ENOSYS;
@ -129,3 +135,8 @@ pid_t fork(void)
{ {
return syscall(SYS_FORK); return syscall(SYS_FORK);
} }
unsigned int sleep(unsigned int seconds)
{
return syscall(SYS_SLEEP, seconds);
}