os/syscall.c

53 lines
1.2 KiB
C
Raw Normal View History

2024-05-21 18:41:16 +03:00
#include <stdint.h>
2024-05-22 00:15:05 +03:00
2024-05-21 18:41:16 +03:00
#include "interrupts.h"
2024-05-22 00:15:05 +03:00
#include "keyboard.h"
#include "sys.h"
2024-05-21 18:41:16 +03:00
#include "syscall.h"
#include "tty.h"
2024-05-22 00:15:05 +03:00
#define NB_SYSCALL 8
void *syscalls[NB_SYSCALL] = {
terminal_writestring,
keyboard_getchar,
terminal_printc,
terminal_clear,
terminal_putchar,
terminal_putentryat,
keyboard_clear_buffer,
sys_halt};
2024-05-21 18:41:16 +03:00
void syscall_handler(Stack *registers)
{
int sys_index = registers->eax;
2024-05-22 00:15:05 +03:00
if (sys_index >= NB_SYSCALL)
2024-05-21 18:41:16 +03:00
return;
2024-05-22 00:15:05 +03:00
void *function = syscalls[sys_index];
int ret;
asm volatile(" push %1; \
push %2; \
push %3; \
push %4; \
push %5; \
call *%6; \
pop %%ebx; \
pop %%ebx; \
pop %%ebx; \
pop %%ebx; \
pop %%ebx; \
" : "=a"(ret) : "r"(registers->edi), "r"(registers->esi),
"r"(registers->edx), "r"(registers->ecx),
"r"(registers->ebx), "r"(function));
registers->eax = ret;
2024-05-21 18:41:16 +03:00
}
void syscall_init(void)
{
isr_install_handler(128, syscall_handler);
2024-05-23 20:59:18 +03:00
}