From 84e104d83ef7a9c2929cab98b2658eb9860883cf Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Tue, 2 Nov 2021 21:47:05 +0100 Subject: [PATCH] Implement some basic syscall --- arch/x86/cpu_context.c | 31 +++++++++++++++++++++++++++++ core/syscall.c => arch/x86/swintr.c | 7 +------ core/syscall.h => arch/x86/swintr.h | 1 + arch/x86/syscall_wrappers.S | 4 ++-- core/cpu_context.h | 12 +++++++++++ core/thread.c | 1 + 6 files changed, 48 insertions(+), 8 deletions(-) rename core/syscall.c => arch/x86/swintr.c (63%) rename core/syscall.h => arch/x86/swintr.h (98%) diff --git a/arch/x86/cpu_context.c b/arch/x86/cpu_context.c index 48697f9..b7a6fd6 100644 --- a/arch/x86/cpu_context.c +++ b/arch/x86/cpu_context.c @@ -489,3 +489,34 @@ void cpu_context_update_kernel_tss(struct cpu_state *next_ctxt) mode */ } } + + +inline +int syscallGet3args(const struct cpu_state *user_ctxt, + /* out */unsigned int *arg1, + /* out */unsigned int *arg2, + /* out */unsigned int *arg3) +{ + *arg1 = user_ctxt->ebx; + *arg2 = user_ctxt->ecx; + *arg3 = user_ctxt->edx; + return 0; +} + + +int syscallGet1arg(const struct cpu_state *user_ctxt, + /* out */unsigned int *arg1) +{ + unsigned int unused; + return syscallGet3args(user_ctxt, arg1, & unused, & unused); +} + + +int _syscallGet2args(const struct cpu_state *user_ctxt, + /* out */unsigned int *arg1, + /* out */unsigned int *arg2) +{ + unsigned int unused; + return syscallGet3args(user_ctxt, arg1, arg2, & unused); +} + diff --git a/core/syscall.c b/arch/x86/swintr.c similarity index 63% rename from core/syscall.c rename to arch/x86/swintr.c index 87976a0..d16d3e8 100644 --- a/core/syscall.c +++ b/arch/x86/swintr.c @@ -1,4 +1,4 @@ -#include "syscall.h" +#include "swintr.h" #include "irq.h" #include "idt.h" @@ -14,8 +14,3 @@ int syscallSetup(){ return ret; } -int syscall_execute(int syscallId, const struct cpu_state *user_ctx){ - (void)syscallId; - (void)user_ctx; - return 0; -} diff --git a/core/syscall.h b/arch/x86/swintr.h similarity index 98% rename from core/syscall.h rename to arch/x86/swintr.h index 2b4a2be..2da6c00 100644 --- a/core/syscall.h +++ b/arch/x86/swintr.h @@ -2,4 +2,5 @@ #define SYSCALL_INTR_NB 0x42 + int syscallSetup(); diff --git a/arch/x86/syscall_wrappers.S b/arch/x86/syscall_wrappers.S index 06d2a9f..53e58cb 100644 --- a/arch/x86/syscall_wrappers.S +++ b/arch/x86/syscall_wrappers.S @@ -6,7 +6,7 @@ .text /* The address of the real "C" syscall function */ -.extern syscall_execute +.extern syscallExecute /** Update the kernel TSS in case we are switching to a thread in user mode in order to come back into the correct kernel stack */ @@ -51,7 +51,7 @@ syscallHandler: pushl %esp /* user_ctxt */ pushl %eax /* syscall ID */ - call syscall_execute + call syscallExecute /* Unallocate the stack used by the do_syscall arguments */ addl $8, %esp diff --git a/core/cpu_context.h b/core/cpu_context.h index e17c31b..840179f 100644 --- a/core/cpu_context.h +++ b/core/cpu_context.h @@ -200,3 +200,15 @@ void cpu_state_detect_kernel_stack_overflow(const struct cpu_state *ctxt, */}) #define cpu_state_detect_kernel_stack_overflow(ctxt, stkbottom, stksize) ({/* nop */}) #endif + +int syscallGet3args(const struct cpu_state *user_ctxt, + /* out */ unsigned int *arg1, + /* out */ unsigned int *arg2, + /* out */ unsigned int *arg3); + +int syscallGet1arg(const struct cpu_state *user_ctxt, + /* out */ unsigned int *arg1); + +int syscallGet2args(const struct cpu_state *user_ctxt, + /* out */ unsigned int *arg1, + /* out */ unsigned int *arg2); diff --git a/core/thread.c b/core/thread.c index 9fe7b24..fa31335 100644 --- a/core/thread.c +++ b/core/thread.c @@ -28,6 +28,7 @@ void threadExit() currentThread->state = EXITING; currentThread = next; currentThread->state = RUNNING; + threadPrepareContext(next); cpu_context_exit_to(next->cpuState, (cpu_kstate_function_arg1_t *)threadDelete, (uint32_t)current);