Syscalls now can take six arguments (XCC)
[akaros.git] / kern / include / ros / syscall.h
1 #ifndef ROS_INCLUDE_SYSCALL_H
2 #define ROS_INCLUDE_SYSCALL_H
3
4 #include <arch/arch.h>
5 #include <ros/bits/syscall.h>
6 #include <ros/arch/syscall.h>
7
8 /* Flags for an individual syscall */
9 #define SC_DONE                                 0x0001
10
11 struct syscall {
12         unsigned int                            num;
13         long                                            retval;
14         int                                                     err;                    /* errno */
15         int                                                     flags;
16         long                                            arg0;
17         long                                            arg1;
18         long                                            arg2;
19         long                                            arg3;
20         long                                            arg4;
21         long                                            arg5;
22 };
23
24 #ifndef ROS_KERNEL
25
26 /* TODO: make variants of __ros_syscall() based on the number of args (0 - 6) */
27 /* These are simple synchronous system calls, built on top of the kernel's async
28  * interface.  This version makes no assumptions about errno.  You usually don't
29  * want this. */
30 static inline long __ros_syscall(unsigned int _num, long _a0, long _a1, long _a2,
31                                  long _a3, long _a4, long _a5, int *errno_loc)
32 {
33         int num_started;
34         struct syscall sysc = {0};
35         sysc.num = _num;
36         sysc.arg0 = _a0;
37         sysc.arg1 = _a1;
38         sysc.arg2 = _a2;
39         sysc.arg3 = _a3;
40         sysc.arg4 = _a4;
41         sysc.arg5 = _a5;
42         num_started = __ros_arch_syscall(&sysc, 1);
43         while (!(sysc.flags & SC_DONE))
44                 cpu_relax();
45         if (errno_loc)
46                 *errno_loc = sysc.err;
47         return sysc.retval;
48 }
49
50 #include <errno.h>
51
52 /* This version knows about errno and will handle it. */
53 static inline long __ros_syscall_errno(unsigned int _num, long _a0, long _a1,
54                                        long _a2, long _a3, long _a4, long _a5)
55 {
56         return __ros_syscall(_num, _a0, _a1, _a2, _a3, _a4, _a5, &errno);
57 }
58
59 /* Convenience wrapper for __ros_syscall */
60 #define ros_syscall(which, a0, a1, a2, a3, a4, a5) \
61    __ros_syscall_errno(which, (long)(a0), (long)(a1), (long)(a2), (long)(a3), \
62                        (long)(a4), (long)(a5))
63
64 #endif /* ifndef ROS_KERNEL */
65
66 #endif /* !ROS_INCLUDE_SYSCALL_H */