2021-11-02 21:57:57 +01:00
|
|
|
#include "klibc.h"
|
|
|
|
#include "stdarg.h"
|
|
|
|
#include "syscall.h"
|
|
|
|
#include "thread.h"
|
|
|
|
|
2021-11-05 23:02:23 +01:00
|
|
|
int syscallExecute(int syscallId, const struct cpu_state *userCtx){
|
2021-11-02 21:57:57 +01:00
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (syscallId) {
|
|
|
|
case SYSCALL_ID_EXIT:
|
|
|
|
uint status;
|
2021-11-05 23:02:23 +01:00
|
|
|
ret = syscallGet1arg(userCtx, &status);
|
2021-11-02 21:57:57 +01:00
|
|
|
if(ret != 0)
|
|
|
|
break;
|
|
|
|
threadExit();
|
|
|
|
assert(0);
|
|
|
|
break;
|
2021-11-05 23:02:23 +01:00
|
|
|
case SYSCALL_ID_YOLO:
|
2021-11-02 21:57:57 +01:00
|
|
|
ret = printf("YOLO FROM USERSPACE\n");
|
|
|
|
break;
|
2021-11-05 23:02:23 +01:00
|
|
|
case SYSCALL_ID_PUTC:
|
|
|
|
unsigned int c;
|
|
|
|
ret = syscallGet1arg(userCtx, &c);
|
|
|
|
putc(c);
|
|
|
|
break;
|
2021-11-02 21:57:57 +01:00
|
|
|
default:
|
|
|
|
printf("Unknon syscall id %d\n", syscallId);
|
|
|
|
ret = -ENOENT;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|