64 lines
1.8 KiB
C
64 lines
1.8 KiB
C
#include "syscall.h"
|
|
#include "keyboard.h"
|
|
#include "klibc.h"
|
|
#include "process.h"
|
|
#include "stdarg.h"
|
|
#include "thread.h"
|
|
#include "types.h"
|
|
#include "uaddrspace.h"
|
|
|
|
int syscallExecute(int syscallId, const struct cpu_state *userCtx)
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
switch (syscallId) {
|
|
case SYSCALL_ID_EXIT: {
|
|
uint status;
|
|
ret = syscallGet1arg(userCtx, &status);
|
|
if (ret != 0)
|
|
break;
|
|
threadExit();
|
|
assert(0);
|
|
break;
|
|
}
|
|
case SYSCALL_ID_HELO:
|
|
ret = printf("HELLO FROM USERSPACE\n");
|
|
break;
|
|
case SYSCALL_ID_PUTC: {
|
|
unsigned int c;
|
|
ret = syscallGet1arg(userCtx, &c);
|
|
putc(c);
|
|
break;
|
|
}
|
|
case SYSCALL_ID_READ:
|
|
ret = keyboardRead();
|
|
break;
|
|
case SYSCALL_ID_TEST: {
|
|
unsigned int arg1, arg2, arg3, arg4, arg5;
|
|
ret = syscallGet5args(userCtx, &arg1, &arg2, &arg3, &arg4, &arg5);
|
|
printf("Got 5args from userspace %d %d %d %d %d\n", arg1, arg2, arg3, arg4, arg5);
|
|
break;
|
|
}
|
|
case SYSCALL_ID_BRK:{
|
|
|
|
struct uAddrSpace *as;
|
|
uaddr_t newHeapTop;
|
|
|
|
as = processGetAddrSpace(getCurrentThread()->process);
|
|
ret = syscallGet1arg(userCtx, (unsigned int *)&newHeapTop);
|
|
if (ret != 0)
|
|
break;
|
|
threadChangeCurrentContext(uAddrSpaceGetMMUContext(as));
|
|
//TODO : what if *newHeapTop raise page fault?
|
|
ret = sysBrk(as, newHeapTop);
|
|
threadChangeCurrentContext(NULL);
|
|
break;
|
|
}
|
|
default:
|
|
printf("Unknon syscall id %d\n", syscallId);
|
|
ret = -ENOENT;
|
|
}
|
|
return ret;
|
|
}
|