-
Notifications
You must be signed in to change notification settings - Fork 0
/
syscall.c
49 lines (40 loc) · 1.13 KB
/
syscall.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdint.h>
#include "interrupts.h"
#include "keyboard.h"
#include "sys.h"
#include "syscall.h"
#include "tty.h"
#include "timer.h"
#include "rtc.h"
#define NB_SYSCALL 3
void *syscalls[NB_SYSCALL] = {
keyboard_getchar,
get_rtc_time,
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);
}