syscalls: start trying to add nanosleep syscall

This commit is contained in:
2025-09-02 00:15:29 +03:00
parent a459751453
commit 5b922ea773
4 changed files with 38 additions and 1 deletions
+28
View File
@@ -7,6 +7,10 @@
#include "../include/screen.h"
#include "../include/fat.h"
#include "../include/vfs.h"
#include "../include/isr.h"
#include "../include/task.h"
extern void switchProcess(Process* next);
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
@@ -299,6 +303,26 @@ uint32_t sys_brk(TrapFrame *tf)
return (uint32_t)current->brk;
}
typedef struct timespec {
int32_t tv_sec; // seconds
int32_t tv_nsec; // nanoseconds
} timespec;
uint32_t sys_nanosleep(TrapFrame *tf)
{
timespec* duration = (timespec*)tf->ebx;
size_t ms = duration->tv_sec * 1000 + duration->tv_nsec / 1000000;
//debug_log("waiting for 0x%X ms\n", ms);
size_t start_time = timer_ticks;
current->wake_up_time = timer_ticks + ms;
//debug_log("setting wake up time to %X (current time is %X)\n", current->wake_up_time, timer_ticks);
//TODO: find a way to call the scheduler from here without fucking shit up
return 0;
}
void handle_syscall(TrapFrame *tf)
{
/*
@@ -347,6 +371,10 @@ void handle_syscall(TrapFrame *tf)
case 0x2d://brk
tf->eax = sys_brk(tf);
break;
case 0xa2://nanosleep
tf->eax = sys_nanosleep(tf);
break;
default:
debug_log("unknown syscall: %X\n", tf->eax);