2024-05-25 19:20:33 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "interrupts.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "sys.h"
|
|
|
|
#include "syscall.h"
|
|
|
|
#include "tty.h"
|
|
|
|
#include "timer.h"
|
2024-05-25 23:17:10 +03:00
|
|
|
#include "rtc.h"
|
2024-05-25 19:20:33 +03:00
|
|
|
|
2024-05-25 23:17:10 +03:00
|
|
|
#define NB_SYSCALL 3
|
2024-05-25 19:20:33 +03:00
|
|
|
|
|
|
|
void *syscalls[NB_SYSCALL] = {
|
|
|
|
keyboard_getchar,
|
2024-05-25 23:17:10 +03:00
|
|
|
get_rtc_time,
|
2024-05-25 19:20:33 +03:00
|
|
|
|
|
|
|
sys_halt};
|
|
|
|
|
|
|
|
void syscall_handler(Stack *registers)
|
|
|
|
{
|
|
|
|
int sys_index = registers->eax;
|
|
|
|
|
|
|
|
if (sys_index >= NB_SYSCALL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void syscall_init(void)
|
|
|
|
{
|
|
|
|
isr_install_handler(128, syscall_handler);
|
|
|
|
}
|