diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2025-08-19 15:03:42 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2025-08-19 15:03:42 -0400 |
commit | 772717dc22e04b4d168d0f77bee6b6357118768c (patch) | |
tree | 9da95703c3376091904e295930104b51c280008d /arch/x86_64/syscall/syscall.c | |
parent | 7ee9347560768641096df68c545ac085a20233e4 (diff) | |
download | jove-kernel-772717dc22e04b4d168d0f77bee6b6357118768c.tar.gz jove-kernel-772717dc22e04b4d168d0f77bee6b6357118768c.tar.bz2 jove-kernel-772717dc22e04b4d168d0f77bee6b6357118768c.zip |
refactor KO_MEMORY_MAPPING invokemain
Diffstat (limited to 'arch/x86_64/syscall/syscall.c')
-rw-r--r-- | arch/x86_64/syscall/syscall.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/arch/x86_64/syscall/syscall.c b/arch/x86_64/syscall/syscall.c new file mode 100644 index 0000000..5582336 --- /dev/null +++ b/arch/x86_64/syscall/syscall.c @@ -0,0 +1,55 @@ +#include "arch/x86_64/processor.h" +#include "syscall/handles.h" +#include "print.h" +#include "lock.h" +#include "error.h" +#include <stddef.h> + +static inline int +s_invoke_release( + objdir_t *root_dir, + objdir_entry_t *target, + uint8_t *payload, + size_t payload_at, + int (*invoke)(objdir_t*, objdir_entry_t*, uint8_t*, size_t)) +{ + int e = invoke(root_dir, target, payload, payload_at); + mtx_release(&target->lock); + return e; +} + +int +_syscall_handler_arch(objdir_t *root_dir, objdir_entry_t *target, uint8_t *payload, size_t payload_at) +{ + switch(target->type) { + case KO_MEMORY_MAPPING: + return s_invoke_release(root_dir, target, payload, payload_at, syscall_handle_invoke_mapping); + default: + klogf("Missing implementation of invoke for type %i\n", target->type); + mtx_release(&target->lock); + return -KE_BADTYPE; + } +} + +__attribute__((naked)) +void _syscall_entry(void) +{ + __asm__ volatile(" \ + pushq %%r11; \ + pushq %%rcx; \ + swapgs; \ + movq %%gs:%c[tcb], %%rax; \ + movq %%rsp, %c[sp](%%rax); \ + movq %c[ksp](%%rax), %%rsp; \ + pushq %c[sp](%%rax); \ + callq _syscall_handler; \ + swapgs; \ + popq %%rsp; \ + popq %%rcx; \ + popq %%r11; \ + sysretq;" + :: + [tcb] "i"(offsetof(processor_t, tcb)), + [sp] "i"(offsetof(tcb_t, sp)), + [ksp] "i"(offsetof(tcb_t, ksp))); +} |