syscalls: start trying to add nanosleep syscall
This commit is contained in:
@@ -70,6 +70,7 @@ typedef struct Process
|
|||||||
void* brk;
|
void* brk;
|
||||||
|
|
||||||
uint32_t kstack_top;
|
uint32_t kstack_top;
|
||||||
|
size_t wake_up_time;//wake up time in ticks of the processor, gets set by nanosleep syscall
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
extern Process* current;
|
extern Process* current;
|
||||||
|
|||||||
+1
-1
@@ -153,7 +153,7 @@ void init_apic_timer()
|
|||||||
lapic_write(APIC_REGISTER_TIMER_DIV, 0x3);
|
lapic_write(APIC_REGISTER_TIMER_DIV, 0x3);
|
||||||
|
|
||||||
// Prepare the PIT to sleep for 10ms (10000µs)
|
// Prepare the PIT to sleep for 10ms (10000µs)
|
||||||
init_pit_timer_apic(1000);
|
init_pit_timer_apic(10000);
|
||||||
|
|
||||||
__asm__ __volatile__ ("sti");
|
__asm__ __volatile__ ("sti");
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
#include "../include/screen.h"
|
#include "../include/screen.h"
|
||||||
#include "../include/fat.h"
|
#include "../include/fat.h"
|
||||||
#include "../include/vfs.h"
|
#include "../include/vfs.h"
|
||||||
|
#include "../include/isr.h"
|
||||||
|
#include "../include/task.h"
|
||||||
|
|
||||||
|
extern void switchProcess(Process* next);
|
||||||
|
|
||||||
#define STDIN_FILENO 0
|
#define STDIN_FILENO 0
|
||||||
#define STDOUT_FILENO 1
|
#define STDOUT_FILENO 1
|
||||||
@@ -299,6 +303,26 @@ uint32_t sys_brk(TrapFrame *tf)
|
|||||||
return (uint32_t)current->brk;
|
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)
|
void handle_syscall(TrapFrame *tf)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -347,6 +371,10 @@ void handle_syscall(TrapFrame *tf)
|
|||||||
case 0x2d://brk
|
case 0x2d://brk
|
||||||
tf->eax = sys_brk(tf);
|
tf->eax = sys_brk(tf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0xa2://nanosleep
|
||||||
|
tf->eax = sys_nanosleep(tf);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
debug_log("unknown syscall: %X\n", tf->eax);
|
debug_log("unknown syscall: %X\n", tf->eax);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "../include/string.h"
|
#include "../include/string.h"
|
||||||
#include "../include/liballoc.h"
|
#include "../include/liballoc.h"
|
||||||
#include "../include/gdt.h"
|
#include "../include/gdt.h"
|
||||||
|
#include "../include/isr.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@@ -67,6 +68,8 @@ Process* task_create(uint32_t func, uint32_t user_esp, uint32_t ring, uint32_t*
|
|||||||
p->context->eip = (uint32_t)trapret;
|
p->context->eip = (uint32_t)trapret;
|
||||||
p->kesp = (uint32_t)sp;
|
p->kesp = (uint32_t)sp;
|
||||||
|
|
||||||
|
p->wake_up_time = 0;
|
||||||
|
|
||||||
p->next = 0;
|
p->next = 0;
|
||||||
|
|
||||||
if (!queue) {
|
if (!queue) {
|
||||||
@@ -133,6 +136,11 @@ void schedule() {
|
|||||||
current = queue; // Start search from the beginning
|
current = queue; // Start search from the beginning
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(current->wake_up_time > timer_ticks)
|
||||||
|
{
|
||||||
|
current = queue;
|
||||||
|
}
|
||||||
|
|
||||||
// Find the next ready process to run
|
// Find the next ready process to run
|
||||||
Process* next = current ? current->next : NULL;
|
Process* next = current ? current->next : NULL;
|
||||||
if (!next) next = queue;
|
if (!next) next = queue;
|
||||||
|
|||||||
Reference in New Issue
Block a user