/* * @author xamidev * @brief System call handling * @license GPL-3.0-only */ #include "sched/scheduler.h" #include #include #include #include #include extern struct process* current_process; void sys_write(unsigned int fd, const char* buf, size_t count) { switch (fd) { case 1: //stdout for (size_t i=0; istatus = DEAD; DEBUG("exiting process PID=%u name=%s", current_process->pid, current_process->name); } /* * syscall_handler - System call dispatcher * @regs: CPU state * * This function is called from the interrupt dispatcher, * when an interrupt 0x80 is emitted from userland. * * It switches control to the syscall number provided * in %rax. * * We try to follow the System V convention here: * - syscall number in %rax * - args in %rdi, %rsi, %rdx, %r10, %r8, %r9 * - return value (if any) in %rax * * Return: * - CPU state after system call */ struct cpu_status* syscall_handler(struct cpu_status* regs) { DEBUG("Syscall %lx with (arg0=%lx arg1=%lx)", regs->rax, regs->rdi, regs->rsi); switch (regs->rax) { case 0: //sys_read break; case 1: //sys_write sys_write(regs->rdi, (char*)regs->rsi, regs->rdx); break; case 60: //sys_exit sys_exit(regs->rdi); break; default: regs->rax = 0xbad515ca11; break; } return regs; }