Implement some basic syscall

This commit is contained in:
Mathieu Maret 2021-11-02 21:47:05 +01:00
parent 98db8b8962
commit 84e104d83e
6 changed files with 48 additions and 8 deletions

View File

@ -489,3 +489,34 @@ void cpu_context_update_kernel_tss(struct cpu_state *next_ctxt)
mode */ 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);
}

View File

@ -1,4 +1,4 @@
#include "syscall.h" #include "swintr.h"
#include "irq.h" #include "irq.h"
#include "idt.h" #include "idt.h"
@ -14,8 +14,3 @@ int syscallSetup(){
return ret; return ret;
} }
int syscall_execute(int syscallId, const struct cpu_state *user_ctx){
(void)syscallId;
(void)user_ctx;
return 0;
}

View File

@ -2,4 +2,5 @@
#define SYSCALL_INTR_NB 0x42 #define SYSCALL_INTR_NB 0x42
int syscallSetup(); int syscallSetup();

View File

@ -6,7 +6,7 @@
.text .text
/* The address of the real "C" syscall function */ /* 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 /** 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 */ mode in order to come back into the correct kernel stack */
@ -51,7 +51,7 @@ syscallHandler:
pushl %esp /* user_ctxt */ pushl %esp /* user_ctxt */
pushl %eax /* syscall ID */ pushl %eax /* syscall ID */
call syscall_execute call syscallExecute
/* Unallocate the stack used by the /* Unallocate the stack used by the
do_syscall arguments */ do_syscall arguments */
addl $8, %esp addl $8, %esp

View File

@ -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 */}) #define cpu_state_detect_kernel_stack_overflow(ctxt, stkbottom, stksize) ({/* nop */})
#endif #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);

View File

@ -28,6 +28,7 @@ void threadExit()
currentThread->state = EXITING; currentThread->state = EXITING;
currentThread = next; currentThread = next;
currentThread->state = RUNNING; currentThread->state = RUNNING;
threadPrepareContext(next);
cpu_context_exit_to(next->cpuState, (cpu_kstate_function_arg1_t *)threadDelete, cpu_context_exit_to(next->cpuState, (cpu_kstate_function_arg1_t *)threadDelete,
(uint32_t)current); (uint32_t)current);