-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyscall.c
58 lines (49 loc) · 1.31 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
50
51
52
53
54
55
56
57
58
#include <stdint.h>
#include "interrupts.h"
#include "keyboard.h"
#include "sys.h"
#include "syscall.h"
#include "tty.h"
#include "timer.h"
#include "rtc.h"
#include "shell.h"
#define NB_SYSCALL 7
void *syscalls[NB_SYSCALL] = {
keyboard_getchar,
get_rtc_time,
sys_halt,
terminal_printf,
delay,
terminal_clear,
shell_init
};
void syscall_handler(Stack *registers)
{
if ((registers->cs & 0x3) != 0x3) return;
int sys_index = registers->eax;
if (sys_index >= NB_SYSCALL) return;
void *function = syscalls[sys_index];
int ret;
asm volatile("sti");
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));
asm volatile("cli");
registers->eax = ret;
}
void syscall_init(void)
{
isr_install_handler(128, syscall_handler);
}