UnnamedOS
syscall.h
1 #ifndef SYSCALL_H
2 #define SYSCALL_H
3 
4 #include <stdint.h>
5 
6 #ifndef SHOULD_DEFINE_SYSCALLS
7 #define SYSCALL_0(id, name, return_type) \
8  return_type name()
9 #define SYSCALL_1(id, name, return_type, type1) \
10  return_type name(type1 ebx)
11 #define SYSCALL_2(id, name, return_type, type1, type2) \
12  return_type name(type1 ebx, type2 ecx)
13 #define SYSCALL_3(id, name, return_type, type1, type2, type3) \
14  return_type name(type1 ebx, type2 ecx, type3 edx)
15 #define SYSCALL_4(id, name, return_type, type1, type2, type3, type4) \
16  return_type name(type1 ebx, type2 ecx, type3 edx, type4 esi)
17 #define SYSCALL_5(id, name, return_type, type1, type2, type3, type4, type5) \
18  return_type name(type1 ebx, type2 ecx, type3 edx, type4 esi, type5 edi)
19 #endif
20 
21 #define SYSCALL_NUMBER 32
22 
23 enum {
24  SYSCALL_EXIT, SYSCALL_GETPID, SYSCALL_IO_PUTCHAR, SYSCALL_IO_ATTR
25 } syscall_ids;
26 
27 // sys_exit does not actually return anything, but we cannot declare a void variable :/
28 SYSCALL_1(SYSCALL_EXIT, sys_exit, uint32_t, uint32_t);
29 SYSCALL_0(SYSCALL_GETPID, sys_getpid, uint32_t);
30 SYSCALL_1(SYSCALL_IO_PUTCHAR, sys_io_putchar, uint16_t, uint8_t);
31 SYSCALL_1(SYSCALL_IO_ATTR, sys_io_attr, uint8_t, uint8_t);
32 
33 #undef SHOULD_DEFINE_SYSCALLS
34 #undef SYSCALL_0
35 #undef SYSCALL_1
36 #undef SYSCALL_2
37 #undef SYSCALL_3
38 #undef SYSCALL_4
39 #undef SYSCALL_5
40 
41 #endif