diff --git a/Architecture/aarch64/SystemCalls.cpp b/Architecture/aarch64/SystemCalls.cpp new file mode 100644 index 0000000..e8b0b0d --- /dev/null +++ b/Architecture/aarch64/SystemCalls.cpp @@ -0,0 +1,14 @@ +#include + +#include + +extern "C" __attribute__((naked, used, no_stack_protector)) void SystemCallHandlerStub() +{ + +} + +extern "C" uint64_t SystemCallsHandler(SyscallsRegs *regs); + +void InitializeSystemCalls() +{ +} diff --git a/Architecture/amd64/SystemCalls.cpp b/Architecture/amd64/SystemCalls.cpp new file mode 100644 index 0000000..35e79b6 --- /dev/null +++ b/Architecture/amd64/SystemCalls.cpp @@ -0,0 +1,23 @@ +#include + +#include + +#include "cpu/gdt.hpp" + +using namespace CPU::x64; + +extern "C" __attribute__((naked, used, no_stack_protector)) void SystemCallHandlerStub() +{ + asmv(".loop\n" + "jmp .loop\n"); +} + +extern "C" uint64_t SystemCallsHandler(SyscallsRegs *regs); + +void InitializeSystemCalls() +{ + wrmsr(MSR_EFER, rdmsr(MSR_EFER) | 1); + wrmsr(MSR_STAR, ((uint64_t)(GDT_KERNEL_CODE) << 32) | ((uint64_t)(GDT_KERNEL_DATA | 3) << 48)); + wrmsr(MSR_LSTAR, (uint64_t)SystemCallsHandler); + wrmsr(MSR_SYSCALL_MASK, 0); +} diff --git a/Architecture/i686/SystemCalls.cpp b/Architecture/i686/SystemCalls.cpp new file mode 100644 index 0000000..7f344a2 --- /dev/null +++ b/Architecture/i686/SystemCalls.cpp @@ -0,0 +1,13 @@ +#include + +#include + +#include "cpu/gdt.hpp" + +using namespace CPU::x32; + +extern "C" uint32_t SystemCallsHandler(SyscallsRegs *regs); + +void InitializeSystemCalls() +{ +} diff --git a/Core/Interrupts/IntManager.cpp b/Core/Interrupts/IntManager.cpp index 429f17b..cac18fb 100644 --- a/Core/Interrupts/IntManager.cpp +++ b/Core/Interrupts/IntManager.cpp @@ -1,5 +1,7 @@ #include +#include + #if defined(__amd64__) #include "../Architecture/amd64/cpu/gdt.hpp" #include "../Architecture/amd64/cpu/idt.hpp" @@ -26,6 +28,7 @@ namespace Interrupts #if defined(__amd64__) GlobalDescriptorTable::Init(0); InterruptDescriptorTable::Init(0); + InitializeSystemCalls(); #elif defined(__i386__) #elif defined(__aarch64__) #endif diff --git a/Core/SystemCalls.cpp b/Core/SystemCalls.cpp new file mode 100644 index 0000000..93ba66d --- /dev/null +++ b/Core/SystemCalls.cpp @@ -0,0 +1,15 @@ +#include + +#include + +extern "C" uint64_t SystemCallsHandler(SyscallsRegs *regs) +{ +#if defined(__amd64__) + fixme("System call %ld", regs->rax); +#elif defined(__i386__) + fixme("System call %ld", regs->eax); +#elif defined(__aarch64__) + fixme("System call"); +#endif + return 0; +} diff --git a/include/cpu.hpp b/include/cpu.hpp index d23a813..c782572 100644 --- a/include/cpu.hpp +++ b/include/cpu.hpp @@ -1007,7 +1007,7 @@ namespace CPU uint64_t raw; } RFLAGS; - typedef struct _TrapFrame + typedef struct TrapFrame { // uint64_t gs; // General-purpose Segment // uint64_t fs; // General-purpose Segment diff --git a/include/syscalls.hpp b/include/syscalls.hpp new file mode 100644 index 0000000..3b3d6dd --- /dev/null +++ b/include/syscalls.hpp @@ -0,0 +1,25 @@ +#ifndef __FENNIX_KERNEL_SYSCALLS_H__ +#define __FENNIX_KERNEL_SYSCALLS_H__ + +#include + +typedef struct SyscallsRegs +{ +#if defined(__amd64__) + uint64_t r15, r14, r13, r12, r11, r10, r9, r8; + uint64_t rbp, rdi, rsi, rdx, rcx, rbx, rax; + uint64_t int_num, error_code, rip, cs, rflags, rsp, ss; +#elif defined(__i386__) + uint64_t r15, r14, r13, r12, r11, r10, r9, r8; + uint64_t ebp, edi, esi, edx, ecx, ebx, eax; + uint64_t int_num, error_code, eip, cs, eflags, esp, ss; +#elif defined(__aarch64__) +#endif +} SyscallsRegs; + +/** + * @brief Initialize syscalls for the current CPU. (Function is available on x32, x64 & aarch64) + */ +void InitializeSystemCalls(); + +#endif // !__FENNIX_KERNEL_SYSCALLS_H__