From da99da2b36d98daeee72fc4de5fb147c1f65b047 Mon Sep 17 00:00:00 2001 From: Matheus Date: Thu, 18 Aug 2022 20:42:03 -0300 Subject: [PATCH] arch_ctl syscall it controls architecture specific things such as the GSBASE in x86_64 --- src/arch/x86_64/arch_ctl.c | 29 +++++++++++++++++++++++++++++ src/arch/x86_64/syscall.asm | 4 +++- src/include/kernel/syscalls.h | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/arch/x86_64/arch_ctl.c diff --git a/src/arch/x86_64/arch_ctl.c b/src/arch/x86_64/arch_ctl.c new file mode 100644 index 00000000..e04370ca --- /dev/null +++ b/src/arch/x86_64/arch_ctl.c @@ -0,0 +1,29 @@ +#include +#include +#include + +#define ARCH_CTL_GSBASE 0 + + +syscallret syscall_arch_ctl(int func, void* arg){ + + syscallret retv; + + retv.errno = 0; + retv.ret = 0; + + switch(func){ + case ARCH_CTL_GSBASE: + wrmsr(MSR_KERNELGSBASE, (uint64_t)arg); + break; + default: + retv.errno = EINVAL; + + } + + if(retv.errno) + retv.ret = -1; + + return retv; + +} diff --git a/src/arch/x86_64/syscall.asm b/src/arch/x86_64/syscall.asm index 6a9ad127..9d18b207 100644 --- a/src/arch/x86_64/syscall.asm +++ b/src/arch/x86_64/syscall.asm @@ -3,12 +3,14 @@ section .rodata extern syscall_libc_log extern syscall_mmap -func_count equ 2 +extern syscall_arch_ctl +func_count equ 3 func_table: dq syscall_libc_log dq syscall_mmap + dq syscall_arch_ctl section .text global asm_syscall_entry diff --git a/src/include/kernel/syscalls.h b/src/include/kernel/syscalls.h index e1b93fdd..b40b9841 100644 --- a/src/include/kernel/syscalls.h +++ b/src/include/kernel/syscalls.h @@ -1,6 +1,9 @@ #ifndef _SYSCALLS_H_INCLUDE #define _SYSCALLS_H_INCLUDE +#include +#include + typedef struct { long ret; long errno;