Add 2 new syscalls (sys_version, sys_gettid)

This commit is contained in:
apio 2022-10-01 17:30:31 +02:00
parent 96f53922c9
commit ac6fdce737
4 changed files with 20 additions and 1 deletions

View File

@ -8,6 +8,8 @@
#define SYS_write 3 #define SYS_write 3
#define SYS_paint 4 #define SYS_paint 4
#define SYS_rand 5 #define SYS_rand 5
#define SYS_version 6
#define SYS_gettid 7
namespace Syscall namespace Syscall
{ {
@ -19,4 +21,6 @@ void sys_yield(Context* context);
void sys_sleep(Context* context, uint64_t ms); void sys_sleep(Context* context, uint64_t ms);
void sys_write(Context* context, const char* addr, size_t size); void sys_write(Context* context, const char* addr, size_t size);
void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h, uint64_t col); void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h, uint64_t col);
void sys_rand(Context* context); void sys_rand(Context* context);
void sys_version(Context* context, char* buffer, size_t max);
void sys_gettid(Context* context);

View File

@ -21,6 +21,8 @@ void Syscall::entry(Context* context)
break; break;
case SYS_paint: sys_paint(context, context->rdi, context->rsi, context->r10, context->r8, context->r9); break; case SYS_paint: sys_paint(context, context->rdi, context->rsi, context->r10, context->r8, context->r9); break;
case SYS_rand: sys_rand(context); break; case SYS_rand: sys_rand(context); break;
case SYS_version: sys_version(context, (char*)context->rdi, context->rsi); break;
case SYS_gettid: sys_gettid(context); break;
default: context->rax = -1; break; default: context->rax = -1; break;
} }
} }

View File

@ -18,4 +18,9 @@ void sys_sleep(Context* context, uint64_t ms)
task->task_sleep = ms; task->task_sleep = ms;
task->state = task->Sleeping; task->state = task->Sleeping;
Scheduler::task_yield(context); Scheduler::task_yield(context);
}
void sys_gettid(Context* context)
{
context->rax = Scheduler::current_task()->id;
} }

View File

@ -0,0 +1,8 @@
#include "config.h"
#include "interrupts/Context.h"
#include "std/stdio.h"
void sys_version(Context* context, char* buffer, size_t max)
{
context->rax = snprintf(buffer, max, "moon %s", moon_version());
}