-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathkernel_syscalls.c
73 lines (61 loc) · 1.62 KB
/
kernel_syscalls.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "kernel_syscalls.h"
#include "drivers/keyboard.h"
#include "kernel_filesystem.h"
#include "kernel_stdio.h"
#include "stdlib/syscalls.h"
uint32_t sys_write_to_screen(char* s) {
fprintf(SCREEN, s);
return 0;
}
uint32_t sys_count_files() {
struct file_t* file = get_first_file();
uint32_t count = 0;
while (file) {
count++;
file = file->next_sibling;
}
return count;
}
uint32_t sys_list_files(struct file_t* buffer) {
struct file_t* file = get_first_file();
while (file) {
*buffer = *file;
buffer++;
file = file->next_sibling;
}
return 0;
}
uint32_t sys_register_input_handler(InputHandler handler) {
set_input_handler(handler);
return 0;
}
char* syscall_name(Syscall syscall) {
switch (syscall) {
case (WRITE_TO_SCREEN):
return "WRITE_TO_SCREEN";
case (COUNT_FILES):
return "COUNT_FILES";
case (LIST_FILES):
return "LIST_FILES";
case (REGISTER_INPUT_HANDLER):
return "REGISTER_INPUT_HANDLER";
}
}
uint32_t handle_syscall(struct cpu_state* cpu) {
Syscall syscall = (Syscall) cpu->eax;
fprintf(LOG, "--------------------\nSYSCALL (%i - %s)\n", syscall, syscall_name(syscall));
switch (syscall) {
case (WRITE_TO_SCREEN):
return sys_write_to_screen((char*) cpu->ebx);
case (COUNT_FILES):
return sys_count_files();
case (LIST_FILES):
return sys_list_files((struct file_t *) cpu->ebx);
case (REGISTER_INPUT_HANDLER):
return sys_register_input_handler((InputHandler) cpu->ebx);
default:
fprintf(LOG, "Unknown syscall: %x\n", syscall);
while(1){}
}
fprintf(LOG, "--------------------\n");
}