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"
|
2025-01-31 17:38:38 +02:00
|
|
|
#include "shell.h"
|
|
|
|
#define NB_SYSCALL 7
|
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,
|
2025-01-31 17:38:38 +02:00
|
|
|
sys_halt,
|
|
|
|
terminal_printf,
|
|
|
|
delay,
|
|
|
|
terminal_clear,
|
|
|
|
shell_init
|
|
|
|
};
|
2024-05-25 19:20:33 +03:00
|
|
|
|
|
|
|
void syscall_handler(Stack *registers)
|
|
|
|
{
|
2025-01-31 17:38:38 +02:00
|
|
|
if ((registers->cs & 0x3) != 0x3) return;
|
|
|
|
|
2024-05-25 19:20:33 +03:00
|
|
|
int sys_index = registers->eax;
|
2025-01-31 17:38:38 +02:00
|
|
|
if (sys_index >= NB_SYSCALL) return;
|
2024-05-25 19:20:33 +03:00
|
|
|
|
|
|
|
void *function = syscalls[sys_index];
|
|
|
|
|
2025-01-31 17:38:38 +02:00
|
|
|
int ret;
|
|
|
|
asm volatile("sti");
|
|
|
|
asm volatile (" push %1; \
|
2024-05-25 19:20:33 +03:00
|
|
|
push %2; \
|
|
|
|
push %3; \
|
|
|
|
push %4; \
|
|
|
|
push %5; \
|
|
|
|
call *%6; \
|
|
|
|
pop %%ebx; \
|
|
|
|
pop %%ebx; \
|
|
|
|
pop %%ebx; \
|
|
|
|
pop %%ebx; \
|
|
|
|
pop %%ebx; \
|
2025-01-31 17:38:38 +02:00
|
|
|
" : "=a" (ret) :
|
|
|
|
"r" (registers->edi), "r" (registers->esi),
|
|
|
|
"r" (registers->edx), "r" (registers->ecx),
|
|
|
|
"r" (registers->ebx), "r" (function));
|
|
|
|
|
|
|
|
asm volatile("cli");
|
|
|
|
|
|
|
|
registers->eax = ret;
|
2024-05-25 19:20:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void syscall_init(void)
|
|
|
|
{
|
|
|
|
isr_install_handler(128, syscall_handler);
|
|
|
|
}
|