Syscall table

This commit is contained in:
Adrien Bourmault 2021-03-08 16:27:54 +01:00
parent 8d61c9b5e0
commit c6e568990f
Signed by: neox
GPG Key ID: 6EB408FE0ACEC664
3 changed files with 46 additions and 7 deletions

View File

@ -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

View File

@ -77,6 +77,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
KeEnableIRQs();
KeEnableRTC();
KeEnablePIT();
KeEnableSyscalls();
// Interrupt handlers
MmActivatePageHandler();

View File

@ -25,17 +25,49 @@
#include <libbuf.h>
#include <init/boot.h>
#include <ke/idt.h>
#include <ke/syscall.h>
#include <io/vga.h>
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;
}