#include #include #include #include #include #include #include typedef uint32_t (*syscall_func)(uint32_t, ...); uint32_t (*syscalls[])() = { [0] = (uint32_t(*)())halt_loop, // DEBUG! [1] = sys_exit, [2] = sys_fork, [3] = sys_read, [4] = sys_write, [5] = sys_exec, [6] = sys_get_pid, [7] = sys_malloc, [8] = sys_free }; void syscall_handler(struct regs *r) { cli(); if (r->eax >= sizeof(syscalls) / sizeof(*syscalls)) return; syscall_func location = (syscall_func)syscalls[r->eax]; if (!location) return; log("[SYSCALL] %d at [0x%x] with 0x%x 0x%x 0x%x 0x%x", r->eax, location, r->ebx, r->ecx, r->edx, r->esi, r->edi); r->eax = location(r->ebx, r->ecx, r->edx, r->esi, r->edi); sti(); } void syscalls_install() { isr_install_handler(0x80, syscall_handler); }