2022-09-29 17:17:43 +00:00
|
|
|
#include "sys/Syscall.h"
|
|
|
|
#include "io/Serial.h"
|
2022-10-13 19:55:51 +00:00
|
|
|
#include "memory/VMM.h"
|
2022-10-19 15:41:23 +00:00
|
|
|
#include "std/errno.h"
|
2022-10-13 20:13:04 +00:00
|
|
|
#include "std/string.h"
|
2022-09-29 17:17:43 +00:00
|
|
|
#include "thread/Scheduler.h"
|
|
|
|
|
|
|
|
void Syscall::entry(Context* context)
|
|
|
|
{
|
|
|
|
asm volatile("cli");
|
2022-10-13 19:55:51 +00:00
|
|
|
VMM::enter_syscall_context();
|
2022-09-29 17:17:43 +00:00
|
|
|
switch (context->rax)
|
|
|
|
{
|
2022-10-11 19:32:28 +00:00
|
|
|
case SYS_exit: sys_exit(context, (int)context->rdi); break;
|
|
|
|
case SYS_yield: sys_yield(context); break;
|
|
|
|
case SYS_sleep: sys_sleep(context, context->rdi); break;
|
|
|
|
case SYS_write: sys_write(context, (int)context->rdi, context->rsi, (const char*)context->rdx); break;
|
2022-10-02 15:01:46 +00:00
|
|
|
case SYS_paint: sys_paint(context, context->rdi, context->rsi, context->rdx, context->r10, context->r8); break;
|
2022-10-18 15:36:17 +00:00
|
|
|
case SYS_getprocid: sys_getprocid(context, (int)context->rdi); break;
|
2022-11-02 19:24:07 +00:00
|
|
|
case SYS_mmap: sys_mmap(context, (void*)context->rdi, context->rsi, (int)context->rdx, (int)context->r10, (off_t)context->r8); break;
|
2022-10-02 18:45:04 +00:00
|
|
|
case SYS_munmap: sys_munmap(context, (void*)context->rdi, context->rsi); break;
|
2022-10-27 05:52:57 +00:00
|
|
|
case SYS_open: sys_open(context, (const char*)context->rdi, (int)context->rsi, (mode_t)context->rdx); break;
|
2022-10-10 18:21:39 +00:00
|
|
|
case SYS_read: sys_read(context, (int)context->rdi, context->rsi, (char*)context->rdx); break;
|
|
|
|
case SYS_close: sys_close(context, (int)context->rdi); break;
|
2022-10-12 13:56:03 +00:00
|
|
|
case SYS_seek: sys_seek(context, (int)context->rdi, (long)context->rsi, (int)context->rdx); break;
|
2022-10-26 16:57:06 +00:00
|
|
|
case SYS_execv: sys_execv(context, (const char*)context->rdi, (char**)context->rsi); break;
|
2022-10-15 08:56:06 +00:00
|
|
|
case SYS_fcntl: sys_fcntl(context, (int)context->rdi, (int)context->rsi, context->rdx); break;
|
2022-10-15 10:57:14 +00:00
|
|
|
case SYS_mprotect: sys_mprotect(context, (void*)context->rdi, context->rsi, (int)context->rdx); break;
|
2022-10-30 08:07:59 +00:00
|
|
|
case SYS_clock_gettime: sys_clock_gettime(context, (int)context->rdi, (struct timespec*)context->rsi); break;
|
2022-10-28 15:11:35 +00:00
|
|
|
case SYS_mkdir: sys_mkdir(context, (const char*)context->rdi, (mode_t)context->rsi); break;
|
2022-10-17 16:43:35 +00:00
|
|
|
case SYS_fork: sys_fork(context); break;
|
2022-10-18 19:30:52 +00:00
|
|
|
case SYS_waitpid: sys_waitpid(context, (long)context->rdi, (int*)context->rsi, (int)context->rdx); break;
|
2022-10-20 17:03:24 +00:00
|
|
|
case SYS_access: sys_access(context, (const char*)context->rdi, (int)context->rsi); break;
|
2022-10-21 16:31:09 +00:00
|
|
|
case SYS_fstat: sys_fstat(context, (int)context->rdi, (struct stat*)context->rsi); break;
|
2022-10-28 15:06:33 +00:00
|
|
|
case SYS_stat: sys_stat(context, (const char*)context->rdi, (struct stat*)context->rsi); break;
|
2022-10-22 12:26:29 +00:00
|
|
|
case SYS_pstat: sys_pstat(context, (long)context->rdi, (struct pstat*)context->rsi); break;
|
2022-10-23 12:03:46 +00:00
|
|
|
case SYS_getdents:
|
|
|
|
sys_getdents(context, (int)context->rdi, (struct luna_dirent*)context->rsi, (size_t)context->rdx);
|
|
|
|
break;
|
2022-10-25 16:58:06 +00:00
|
|
|
case SYS_dup2: sys_dup2(context, (int)context->rdi, (int)context->rsi); break;
|
2022-10-28 15:19:26 +00:00
|
|
|
case SYS_setuid: sys_setuid(context, (int)context->rdi, (int)context->rsi); break;
|
|
|
|
case SYS_setgid: sys_setgid(context, (int)context->rdi, (int)context->rsi); break;
|
2022-10-30 18:55:38 +00:00
|
|
|
case SYS_umask: sys_umask(context, (mode_t)context->rdi); break;
|
2022-10-08 12:18:25 +00:00
|
|
|
default: context->rax = -ENOSYS; break;
|
2022-09-29 17:17:43 +00:00
|
|
|
}
|
2022-10-13 19:55:51 +00:00
|
|
|
VMM::exit_syscall_context();
|
2022-10-21 16:31:09 +00:00
|
|
|
}
|