All local system calls are asynchronous (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 /* These are simple synchronous system calls, built on top of the kernel's async
27  * interface.  This version makes no assumptions about errno.  You usually don't
28  * want this. */
29 static inline long __ros_syscall(long _num, long _a0, long _a1, long _a2,
30                                  long _a3, long _a4, int *errno_loc)
31 {
32         int num_started;
33         struct syscall sysc = {0};
34         sysc.num = _num;
35         sysc.arg0 = _a0;
36         sysc.arg1 = _a1;
37         sysc.arg2 = _a2;
38         sysc.arg3 = _a3;
39         sysc.arg4 = _a4;
40         // TODO: arg5
41         num_started = __ros_arch_syscall(&sysc, 1, 0, 0, 0, 0);
42         while (!(sysc.flags & SC_DONE))
43                 cpu_relax();
44         if (errno_loc)
45                 *errno_loc = sysc.err;
46         return sysc.retval;
47 }
48
49 #include <errno.h>
50
51 /* This version knows about errno and will handle it. */
52 static inline long __ros_syscall_errno(long _num, long _a0, long _a1, long _a2,
53                                        long _a3, long _a4)
54 {
55         return __ros_syscall(_num, _a0, _a1, _a2, _a3, _a4, &errno);
56 }
57
58 /* Convenience wrapper for __ros_syscall */
59 #define ros_syscall(which,a0,a1,a2,a3,a4) \
60    __ros_syscall_errno(which, (long)(a0), (long)(a1), (long)(a2), (long)(a3), \
61                        (long)(a4))
62
63 #endif /* ifndef ROS_KERNEL */
64
65 #endif /* !ROS_INCLUDE_SYSCALL_H */