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