From 5f813d49a08cf3c3f8cf6c422cfb6587df575f62 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Sat, 26 Sep 2026 17:11:50 -0400 Subject: add docs for syscalls. make syscall code kind-of cleaner --- arch/x86_64/sys/serial.c | 39 -------------------------------- arch/x86_64/sys/syscall.c | 48 ++++++++++++++++------------------------ arch/x86_64/sys/syscall.h | 2 +- arch/x86_64/sys/syscall_serial.c | 33 +++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 69 deletions(-) delete mode 100644 arch/x86_64/sys/serial.c create mode 100644 arch/x86_64/sys/syscall_serial.c (limited to 'arch/x86_64/sys') diff --git a/arch/x86_64/sys/serial.c b/arch/x86_64/sys/serial.c deleted file mode 100644 index 12db6fd..0000000 --- a/arch/x86_64/sys/serial.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "jove.h" -#include "lib/printf.h" -#include "syscall.h" -#include "arch/x86_64/hal/serial_com.h" - -static int -s_syscall_serial_write( - jove_owned_obj_t *serial_com, - size_t payload_bytes, - void *payload_data) -{ - size_t bytes_needed = sizeof(struct syscall_generic_write); - CHECK_TOOSMALL(bytes_needed, payload_bytes, "Message is too small for this syscall!"); - - struct syscall_generic_write *payload = payload_data; - bytes_needed += payload->len * 2; - CHECK_TOOSMALL(bytes_needed, payload_bytes, "Message is too small for write buffer!"); - - return serial_com_write(serial_com, payload->data, payload->len); -} - -int -_syscall_handle_serial( - jove_owned_obj_t *pcb_obj, - jove_owned_obj_t *objdir, - jove_owned_obj_t *message_obj, - jove_owned_obj_t *target_obj, - struct syscall_header *header, - size_t bytes_left, - void *payload_data) -{ - switch(header->callid) { - case 0: - return s_syscall_serial_write(target_obj, bytes_left, payload_data); - default: - kprintf("syscall_serial: serial com object does not support syscall %i\n", header->callid); - return EOOB; - } -} diff --git a/arch/x86_64/sys/syscall.c b/arch/x86_64/sys/syscall.c index 53351e7..a694674 100644 --- a/arch/x86_64/sys/syscall.c +++ b/arch/x86_64/sys/syscall.c @@ -10,24 +10,17 @@ syscall_handle_t s_arch_handles[128] = { }; int -_syscall_handle_arch( - jove_owned_obj_t *pcb_obj, - jove_owned_obj_t *objdir, - jove_owned_obj_t *message_obj, - jove_owned_obj_t *target_obj, - struct syscall_header *header, - size_t bytes_left, - void *payload) +_syscall_handle_arch(syscall_context_t *ctx) { - uint8_t target_type = obj_gettype(target_obj) - 0x80; + 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(pcb_obj)), header->path, header->pathlen); - return EBADOBJ; + pcb_pid(obj_deref(ctx->pcb)), ctx->header->path, ctx->header->pathlen); + return -EBADOBJ; } - return call_handle(pcb_obj, objdir, message_obj, target_obj, header, bytes_left, payload); + return call_handle(ctx); } __attribute__((naked)) @@ -38,32 +31,29 @@ void _syscall_entry(void) movq %%gs:%c[pcb], %%rax; \ movq %%rsp, %%rdx; \ movq %c[ksp](%%rax), %%rsp; \ + pushq %%rcx; \ pushq %%rdx; \ pushq %%r11; \ - pushq %%rbx; \ - pushq %%rcx; \ pushq %%rbp; \ - pushq %%r12; \ - pushq %%r13; \ - pushq %%r14; \ - pushq %%r15; \ callq syscall_handler; \ swapgs; \ - popq %%r15; \ - popq %%r14; \ - popq %%r13; \ - popq %%r12; \ - popq %%rbp; \ - popq %%rcx; \ - popq %%rbx; \ - xorq %%rdx, %%rdx; \ + xorq %%r15, %%r15; \ + xorq %%r14, %%r14; \ + xorq %%r13, %%r13; \ + xorq %%r12, %%r12; \ + xorq %%r10, %%r10; \ + xorq %%r9, %%r9; \ + xorq %%r8, %%r8; \ xorq %%rsi, %%rsi; \ xorq %%rdi, %%rdi; \ - xorq %%r8, %%r8; \ - xorq %%r9, %%r9; \ - xorq %%r10, %%r10; \ + xorq %%rbp, %%rbp; \ + xorq %%rdx, %%rdx; \ + xorq %%rcx, %%rcx; \ + xorq %%rbx, %%rbx; \ + popq %%rbp; \ popq %%r11; \ popq %%rsp; \ + popq %%rcx; \ sysretq;" :: [pcb] "i"(offsetof(processor_t, pcb)), diff --git a/arch/x86_64/sys/syscall.h b/arch/x86_64/sys/syscall.h index 868ce0b..34f6a2a 100644 --- a/arch/x86_64/sys/syscall.h +++ b/arch/x86_64/sys/syscall.h @@ -3,7 +3,7 @@ #include "sys/syscall.h" -int _syscall_handle_serial(SYSCALL_FUNCTION_ARGS); +int _syscall_handle_serial(syscall_context_t *ctx); #define SYSCALL_SERIAL_COM_WRITE 0 diff --git a/arch/x86_64/sys/syscall_serial.c b/arch/x86_64/sys/syscall_serial.c new file mode 100644 index 0000000..786a78b --- /dev/null +++ b/arch/x86_64/sys/syscall_serial.c @@ -0,0 +1,33 @@ +#include "jove.h" +#include "lib/printf.h" +#include "sys/syscall.h" +#include "syscall.h" +#include "arch/x86_64/hal/serial_com.h" + +static int +s_syscall_serial_write( + jove_owned_obj_t *serial_com, + size_t payload_bytes, + void *payload_data) +{ + size_t bytes_needed = sizeof(struct syscall_generic_write); + CHECK_TOOSMALL(bytes_needed, payload_bytes, "Message is too small for this syscall!"); + + struct syscall_generic_write *payload = payload_data; + bytes_needed += payload->len * 2; + CHECK_TOOSMALL(bytes_needed, payload_bytes, "Message is too small for write buffer!"); + + return serial_com_write(serial_com, payload->data, payload->len); +} + +int +_syscall_handle_serial(syscall_context_t *ctx) +{ + switch(ctx->header->callid) { + case SYSCALL_SERIAL_COM_WRITE: + return s_syscall_serial_write(ctx->target.obj, ctx->bytes_left, ctx->payload); + default: + kprintf("syscall_serial: serial com object does not support syscall %i\n", ctx->header->callid); + return -EBADCALL; + } +} -- cgit v1.2.3