From 9f7b7bdd2d4d104d4de49766d9db6fbb826a4f98 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 8 Feb 2026 16:17:11 +0000 Subject: [PATCH] kernel: refactor syscall dispatch system --- CMakeLists.txt | 2 +- arch/x86_64/irq.c | 2 +- include/mango/syscall.h | 2 +- kernel/syscall.c => syscall/dispatch.c | 21 +-------------------- syscall/task.c | 13 +++++++++++++ syscall/vm-object.c | 13 +++++++++++++ 6 files changed, 30 insertions(+), 23 deletions(-) rename kernel/syscall.c => syscall/dispatch.c (56%) create mode 100644 syscall/task.c create mode 100644 syscall/vm-object.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 27684fc..a75ed5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(kernel_arch x86_64) set(kernel_name "Mango") set(kernel_exe_name "mango_kernel") -set(generic_src_dirs ds init kernel libc sched util vm) +set(generic_src_dirs ds init kernel libc sched util vm syscall) set(kernel_sources "") set(kernel_headers "") diff --git a/arch/x86_64/irq.c b/arch/x86_64/irq.c index 261f695..f18b445 100644 --- a/arch/x86_64/irq.c +++ b/arch/x86_64/irq.c @@ -206,7 +206,7 @@ void irq_dispatch(struct ml_cpu_context *regs) void syscall_dispatch(struct ml_cpu_context *regs) { unsigned int sysid = regs->rax; - virt_addr_t syscall_impl = syscall_get_func(sysid); + virt_addr_t syscall_impl = syscall_get_function(sysid); if (syscall_impl == 0) { regs->rax = KERN_UNSUPPORTED; diff --git a/include/mango/syscall.h b/include/mango/syscall.h index a645143..1dadb0c 100644 --- a/include/mango/syscall.h +++ b/include/mango/syscall.h @@ -15,6 +15,6 @@ extern kern_status_t sys_vm_object_create( enum vm_prot prot, kern_handle_t *out_handle); -extern virt_addr_t syscall_get_func(unsigned int sysid); +extern virt_addr_t syscall_get_function(unsigned int sysid); #endif diff --git a/kernel/syscall.c b/syscall/dispatch.c similarity index 56% rename from kernel/syscall.c rename to syscall/dispatch.c index 1f1c1eb..a07ab57 100644 --- a/kernel/syscall.c +++ b/syscall/dispatch.c @@ -2,25 +2,6 @@ #include #include -kern_status_t sys_exit(int status) -{ - printk("sys_exit(%d)", status); - while (1) { - ml_cpu_pause(); - } - return KERN_UNIMPLEMENTED; -} - -kern_status_t sys_vm_object_create( - const char *name, - size_t len, - enum vm_prot prot, - kern_handle_t *out_handle) -{ - printk("sys_vm_object_create()"); - return KERN_UNIMPLEMENTED; -} - #define SYSCALL_TABLE_ENTRY(id, p) [SYS_##id] = (virt_addr_t)(sys_##p) static const virt_addr_t syscall_table[] = { @@ -30,7 +11,7 @@ static const virt_addr_t syscall_table[] = { static const size_t syscall_table_count = sizeof syscall_table / sizeof syscall_table[0]; -virt_addr_t syscall_get_func(unsigned int sysid) +virt_addr_t syscall_get_function(unsigned int sysid) { if (sysid >= syscall_table_count) { return 0; diff --git a/syscall/task.c b/syscall/task.c new file mode 100644 index 0000000..72d35b8 --- /dev/null +++ b/syscall/task.c @@ -0,0 +1,13 @@ +#include +#include +#include + +extern kern_status_t sys_exit(int status) +{ + printk("sys_exit(%d)", status); + while (1) { + ml_cpu_pause(); + } + + return KERN_UNIMPLEMENTED; +} diff --git a/syscall/vm-object.c b/syscall/vm-object.c new file mode 100644 index 0000000..73c3d54 --- /dev/null +++ b/syscall/vm-object.c @@ -0,0 +1,13 @@ +#include +#include +#include + +kern_status_t sys_vm_object_create( + const char *name, + size_t len, + enum vm_prot prot, + kern_handle_t *out_handle) +{ + printk("sys_vm_object_create()"); + return KERN_UNIMPLEMENTED; +}