user_space #4

Merged
mathieu merged 40 commits from user_space into master 2021-11-04 16:17:36 +01:00
3 changed files with 43 additions and 4 deletions
Showing only changes of commit 7b60e1bdac - Show all commits

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();
currentThread->cpuState = prevCpu;
currentThread->state = READY;
currentThread = nextThread;
currentThread->state = RUNNING;
if (nextThread != currentThread) {
currentThread->cpuState = prevCpu;
currentThread->state = READY;
currentThread = nextThread;
currentThread->state = RUNNING;
threadPrepareContext(nextThread);
}
restore_IRQs(flags);