forked from pepper-org/pepperOS
62 lines
1.4 KiB
C
62 lines
1.4 KiB
C
/*
|
|
* @author xamidev <xamidev@riseup.net>
|
|
* @brief System call handling
|
|
* @license GPL-3.0-only
|
|
*/
|
|
|
|
#include "sched/scheduler.h"
|
|
#include <arch/x86.h>
|
|
#include <kernel.h>
|
|
#include <stddef.h>
|
|
#include <io/term/term.h>
|
|
|
|
void sys_write(unsigned int fd, const char* buf, size_t count)
|
|
{
|
|
switch (fd) {
|
|
case 1: //stdout
|
|
for (size_t i=0; i<count; i++) {
|
|
internal_putc(buf[i], NULL);
|
|
}
|
|
break;
|
|
|
|
case 2: //stderr
|
|
break;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* 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:
|
|
* <regs> - 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;
|
|
default:
|
|
regs->rax = 0xbad515ca11;
|
|
break;
|
|
}
|
|
|
|
return regs;
|
|
} |