basic process support and some syscalls
[lunaix-os.git] / lunaix-os / includes / lunaix / syscall.h
1 #ifndef __LUNAIX_SYSCALL_H
2 #define __LUNAIX_SYSCALL_H
3
4 #include <arch/x86/vectors.h>
5
6 #define __SYSCALL_fork    0x1
7 #define __SYSCALL_yield   0x2
8 #define __SYSCALL_exit    0x3
9 #define __SYSCALL_sbrk    0x4
10 #define __SYSCALL_brk     0x5
11
12 #define __SYSCALL_MAX     0x100
13
14 #ifndef __ASM__
15 void syscall_install();
16
17 static void* syscall(unsigned int callcode) {
18     asm volatile(
19         "int %0"
20         ::"i"(LUNAIX_SYS_CALL), "D"(callcode)
21         :"eax"
22     );
23 }
24
25 #define ___DOINT33(callcode, rettype)\
26     int v;    \
27     asm volatile (  \
28         "int %1\n"    \
29         :"=a"(v)    \
30         :"i"(LUNAIX_SYS_CALL), "a"(callcode));  \
31     return (rettype)v;     \
32
33 #define __LXSYSCALL(rettype, name) \
34     rettype name () { \
35         ___DOINT33(__SYSCALL_##name, rettype) \
36     }
37
38 #define __LXSYSCALL1(rettype, name, t1, p1) \
39     rettype name (t1 p1) { \
40         asm (""::"b"(p1)); \
41         ___DOINT33(__SYSCALL_##name, rettype) \
42     }
43
44 #define __LXSYSCALL2(rettype, name, t1, p1, t2, p2) \
45     rettype name (t1 p1, t2 p2) { \
46         asm ("\n"::"b"(p1), "c"(p2)); \
47         ___DOINT33(__SYSCALL_##name, rettype) \
48     }
49
50 #define __LXSYSCALL3(rettype, name, t1, p1, t2, p2, t3, p3) \
51     rettype name (t1 p1, t2 p2, t3 p3) { \
52         asm ("\n"::"b"(p1), "c"(p2), "d"(p3)); \
53         ___DOINT33(__SYSCALL_##name, rettype) \
54     }
55
56 #define __LXSYSCALL4(rettype, name, t1, p1, t2, p2, t3, p3, t4, p4) \
57     rettype name (t1 p1, t2 p2, t3 p3, t4 p4) { \
58         asm ("\n"::"b"(p1), "c"(p2), "d"(p3), "D"(p4)); \
59         ___DOINT33(__SYSCALL_##name, rettype) \
60     }
61 #endif
62 #endif /* __LUNAIX_SYSCALL_H */