39 lines
1.8 KiB
C++
39 lines
1.8 KiB
C++
#include "sys/Syscall.h"
|
|
#include "errno.h"
|
|
#include "io/Serial.h"
|
|
#include "memory/VMM.h"
|
|
#include "std/string.h"
|
|
#include "thread/Scheduler.h"
|
|
|
|
void Syscall::entry(Context* context)
|
|
{
|
|
asm volatile("cli");
|
|
VMM::enter_syscall_context();
|
|
switch (context->rax)
|
|
{
|
|
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;
|
|
case SYS_paint: sys_paint(context, context->rdi, context->rsi, context->rdx, context->r10, context->r8); break;
|
|
case SYS_rand: sys_rand(context); break;
|
|
case SYS_gettid: sys_gettid(context); break;
|
|
case SYS_mmap: sys_mmap(context, (void*)context->rdi, context->rsi, (int)context->rdx); break;
|
|
case SYS_munmap: sys_munmap(context, (void*)context->rdi, context->rsi); break;
|
|
case SYS_open: sys_open(context, (const char*)context->rdi, (int)context->rsi); break;
|
|
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;
|
|
case SYS_seek: sys_seek(context, (int)context->rdi, (long)context->rsi, (int)context->rdx); break;
|
|
case SYS_exec: sys_exec(context, (const char*)context->rdi); break;
|
|
case SYS_fcntl: sys_fcntl(context, (int)context->rdi, (int)context->rsi, context->rdx); break;
|
|
default: context->rax = -ENOSYS; break;
|
|
}
|
|
VMM::exit_syscall_context();
|
|
}
|
|
|
|
char* Syscall::strdup_from_user(const char* user_string) // FIXME: This function is a little hacky.
|
|
{
|
|
uint64_t phys = VMM::get_physical((uint64_t)user_string);
|
|
if (phys == (uint64_t)-1) { return nullptr; }
|
|
return strdup((const char*)phys);
|
|
} |