user_space #4
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);
|
disable_IRQs(flags);
|
||||||
|
|
||||||
nextThread = threadSelectNext();
|
nextThread = threadSelectNext();
|
||||||
currentThread->cpuState = prevCpu;
|
if (nextThread != currentThread) {
|
||||||
currentThread->state = READY;
|
currentThread->cpuState = prevCpu;
|
||||||
currentThread = nextThread;
|
currentThread->state = READY;
|
||||||
currentThread->state = RUNNING;
|
currentThread = nextThread;
|
||||||
|
currentThread->state = RUNNING;
|
||||||
|
threadPrepareContext(nextThread);
|
||||||
|
}
|
||||||
|
|
||||||
restore_IRQs(flags);
|
restore_IRQs(flags);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user