Added syscalls stub

This commit is contained in:
Alex 2022-10-12 04:34:37 +03:00
parent 127476ac64
commit a2da69d777
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
7 changed files with 94 additions and 1 deletions

View File

@ -0,0 +1,14 @@
#include <syscalls.hpp>
#include <cpu.hpp>
extern "C" __attribute__((naked, used, no_stack_protector)) void SystemCallHandlerStub()
{
}
extern "C" uint64_t SystemCallsHandler(SyscallsRegs *regs);
void InitializeSystemCalls()
{
}

View File

@ -0,0 +1,23 @@
#include <syscalls.hpp>
#include <cpu.hpp>
#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);
}

View File

@ -0,0 +1,13 @@
#include <syscalls.hpp>
#include <cpu.hpp>
#include "cpu/gdt.hpp"
using namespace CPU::x32;
extern "C" uint32_t SystemCallsHandler(SyscallsRegs *regs);
void InitializeSystemCalls()
{
}

View File

@ -1,5 +1,7 @@
#include <interrupts.hpp>
#include <syscalls.hpp>
#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

15
Core/SystemCalls.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <syscalls.hpp>
#include <debug.h>
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;
}

View File

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

25
include/syscalls.hpp Normal file
View File

@ -0,0 +1,25 @@
#ifndef __FENNIX_KERNEL_SYSCALLS_H__
#define __FENNIX_KERNEL_SYSCALLS_H__
#include <types.h>
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__