os-k/kaleid/kernel/ke/syscall.c

74 lines
3.0 KiB
C

//----------------------------------------------------------------------------//
// OS on Kaleid //
// //
// Desc: System call & userspace related functions //
// //
// //
// Copyright © 2018-2021 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <libbuf.h>
#include <init/boot.h>
#include <ke/idt.h>
#include <ke/syscall.h>
#include <io/vga.h>
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 )
{
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;
}