//----------------------------------------------------------------------------// // 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 . // //----------------------------------------------------------------------------// #include #include #include #include #include #include static error_t (*syscallTable[255])(void*, void*, void*, void*, ISRFrame_t*) = {NULL}; // // Syscall handler that dispatches calls depending of code value // error_t _KeSyscallHandler(void *rdi, void *rsi, void *rdx, void *rcx, ISRFrame_t *regs) { if ((ulong)regs->cs >= (ulong)BtLoaderInfo.codeSegment) { DebugLog("System call code %ld from userspace (cs %#x)\n", regs->rax, regs->cs); } else { DebugLog("System call call code %ld from kernel (cs %#x)\n", regs->rax, regs->cs); } if (regs->rax > LATEST_SYSCALL_CODE) { return ENOSYS; } return syscallTable[(uchar)regs->rax](rdi, rsi, rdx, rcx, regs); } // // Syscalls // static error_t syscallStub(void *rdi, void *rsi, void *rdx, void *rcx, ISRFrame_t *regs) { return ENOSYS; } static error_t syscallPrint(void *id, void *string, void *rdx, void *rcx, ISRFrame_t *regs) { Buffer_t *buf = NULL; if (*(ulong*)id == 0) { buf = BStdOut; } return BPrintOnBuf(buf, (char*)string); } static error_t syscallFlush(void *id, void *rdi, void *rdx, void *rcx, ISRFrame_t *regs) { Buffer_t *buf = NULL; if (*(ulong*)id == 0) { buf = BStdOut; } return BFlushBuf(buf); } static error_t syscallKernelShell(void *rdi, void *rsi, void *rdx, void *rcx, ISRFrame_t *regs) { KeEnableIRQs(); ShStartShell(); //TODO : return from Shell KePauseIRQs(); return EOK; } // // Initializes the syscall table // void KeEnableSyscalls() { syscallTable[0] = syscallPrint; syscallTable[1] = syscallFlush; syscallTable[2] = syscallStub; syscallTable[3] = syscallStub; syscallTable[4] = syscallKernelShell; syscallTable[5] = syscallStub; }