#include "arch/x86_64/hal/obj.h" #include "arch/x86_64/hal/process.h" #include "arch/x86_64/hal/smp.h" #include "lib/printf.h" #include "syscall.h" syscall_handle_t s_arch_handles[128] = { [JOVE_OBJ_SERIAL_COM-0x80] = _syscall_handle_serial }; int _syscall_handle_arch(syscall_context_t *ctx) { uint8_t target_type = obj_gettype(ctx->target.obj) - 0x80; syscall_handle_t call_handle = s_arch_handles[target_type]; if(call_handle == NULL) { kprintf("syscall: Process %i tried to call syscall on object %P which doesn't support syscalls!\n", pcb_pid(obj_deref(ctx->pcb)), ctx->header->path, ctx->header->pathlen); return -EBADOBJ; } return call_handle(ctx); } __attribute__((naked)) void _syscall_entry(void) { asm volatile(" \ swapgs; \ movq %%gs:%c[pcb], %%rax; \ movq %%rsp, %%rdx; \ movq %c[ksp](%%rax), %%rsp; \ pushq %%rdx; \ pushq %%r11; \ pushq %%rcx; \ pushq %%rbp; \ callq syscall_handler; \ swapgs; \ xorq %%r10, %%r10; \ xorq %%r9, %%r9; \ xorq %%r8, %%r8; \ xorq %%rsi, %%rsi; \ xorq %%rdi, %%rdi; \ xorq %%rdx, %%rdx; \ popq %%rbp; \ popq %%rcx; \ popq %%r11; \ popq %%rsp; \ sysretq" :: [pcb] "i"(offsetof(processor_t, pcb)), [ksp] "i"(offsetof(pcb_t, ksp))); }