diff --git a/include/kernel/ke/syscall.h b/include/kernel/ke/syscall.h index 508546c..2cfc0b5 100644 --- a/include/kernel/ke/syscall.h +++ b/include/kernel/ke/syscall.h @@ -31,6 +31,10 @@ //----------------------------------------------------------------------------// +#define LATEST_SYSCALL_CODE 0 + +//----------------------------------------------------------------------------// + extern error_t KeSyscall(ulong code); extern void KeJumpToUserspace(ulong args, void *entryPoint, void *stackAddr); @@ -38,6 +42,8 @@ extern void KeJumpToUserspace(ulong args, void *entryPoint, void *stackAddr); error_t _KeSyscallHandler( ulong code, void *arg0, void *arg1, void *arg2, ISRFrame_t *regs ); +void KeEnableSyscalls(); + //----------------------------------------------------------------------------// #endif diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 0a3ef3c..531032f 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -77,6 +77,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) KeEnableIRQs(); KeEnableRTC(); KeEnablePIT(); + KeEnableSyscalls(); // Interrupt handlers MmActivatePageHandler(); diff --git a/kaleid/kernel/ke/syscall.c b/kaleid/kernel/ke/syscall.c index 249f66a..ebb2ef0 100644 --- a/kaleid/kernel/ke/syscall.c +++ b/kaleid/kernel/ke/syscall.c @@ -25,17 +25,49 @@ #include #include #include +#include #include -error_t _KeSyscallHandler( ulong code, void *arg0, void *arg1, void *arg2, +static error_t (*syscallTable[255])(void*, void*, void*, ISRFrame_t*) = {NULL}; + + +// +// Syscall handler that dispatches calls depending of code value +// +error_t _KeSyscallHandler( ulong code, void *rdi, void *rsi, void *rdx, ISRFrame_t *regs ) -{ - DebugLog("Got a system call code %ld from cs %#x\n", code, regs->cs); - - if ((ulong)regs->cs != (ulong)BtLoaderInfo.codeSegment) { - bprintf(BStdOut, "Got a system call from userspace code %d\n", code); - BStdOut->flusher(BStdOut); +{ + if ((ulong)regs->cs >= (ulong)BtLoaderInfo.codeSegment) { + DebugLog("System call code %ld from userspace (cs %#x)\n", + code, regs->cs); + } else { + DebugLog("System call call code %ld from kernel (cs %#x)\n", + code, regs->cs); } + if (code > LATEST_SYSCALL_CODE) { + return EINVAL; + } + + return syscallTable[(uchar)code](rdi, rsi, rdx, regs); + return EOK; } + +// +// Syscalls +// +static error_t syscallRead(void *rdi, void *rsi, void *rdx, ISRFrame_t *regs) +{ + DebugLog("syscallRead attempted\n"); + return EOK; +} + + +// +// Initializes the syscall table +// +void KeEnableSyscalls() +{ + syscallTable[0] = syscallRead; +}