Fix threadSwitch context
This commit is contained in:
parent
84e104d83e
commit
7b60e1bdac
27
core/syscall.c
Normal file
27
core/syscall.c
Normal 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
9
core/syscall.h
Normal 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);
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user