Fix threadSwitch context

This commit is contained in:
Mathieu Maret 2021-11-02 21:57:57 +01:00
parent 84e104d83e
commit 7b60e1bdac
3 changed files with 43 additions and 4 deletions

27
core/syscall.c Normal file
View File

@ -0,0 +1,27 @@
#include "klibc.h"
#include "stdarg.h"
#include "syscall.h"
#include "thread.h"
int syscallExecute(int syscallId, const struct cpu_state *user_ctx){
int ret;
switch (syscallId) {
case SYSCALL_ID_EXIT:
uint status;
ret = syscallGet1arg(user_ctx, &status);
if(ret != 0)
break;
threadExit();
assert(0);
break;
case SYSCALL_ID_WRITE:
ret = printf("YOLO FROM USERSPACE\n");
break;
default:
printf("Unknon syscall id %d\n", syscallId);
ret = -ENOENT;
}
return ret;
}

9
core/syscall.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include "cpu_context.h"
#define SYSCALL_ID_EXIT 1
#define SYSCALL_ID_WRITE 2
int syscallExecute(int syscallId, const struct cpu_state *user_ctx);

View File

@ -132,10 +132,13 @@ struct cpu_state *threadSwitch(struct cpu_state *prevCpu)
disable_IRQs(flags);
nextThread = threadSelectNext();
if (nextThread != currentThread) {
currentThread->cpuState = prevCpu;
currentThread->state = READY;
currentThread = nextThread;
currentThread->state = RUNNING;
threadPrepareContext(nextThread);
}
restore_IRQs(flags);