Syscalls now can take six arguments (XCC)
[akaros.git] / kern / include / ros / syscall.h
index 29bfbad..abb4d06 100644 (file)
@@ -1,67 +1,66 @@
 #ifndef ROS_INCLUDE_SYSCALL_H
 #define ROS_INCLUDE_SYSCALL_H
 
-/* system call numbers.  need to #def them for use in assembly. */
-#define SYS_null                                        1
-#define SYS_cache_buster                        2
-#define SYS_cache_invalidate            3
-#define SYS_reboot                                      4
-#define SYS_cputs                                       5
-#define SYS_cgetc                                       6
-#define SYS_getcpuid                            7
-#define SYS_getvcoreid                          8
-#define SYS_getpid                                      9
-#define SYS_proc_create                                10
-#define SYS_proc_run                           11
-#define SYS_proc_destroy                       12
-#define SYS_yield                                      13
-#define SYS_run_binary                         14
-#define SYS_fork                                       15
-#define SYS_exec                                       16
-#define SYS_trywait                                    17
-#define SYS_mmap                                       18
-#define SYS_brk                                                19
-#define SYS_shared_page_alloc          20
-#define SYS_shared_page_free           21
-/*
-#define SYS_mincore // can read page tables instead
-#define SYS_madvise
-#define SYS_mlock
-#define SYS_msync
-*/
-#define SYS_resource_req                       22
-/* Platform specific syscalls */
-#define SYS_serial_read                                23
-#define SYS_serial_write                       24
-#define SYS_eth_read                           25
-#define SYS_eth_write                          26
-#define SYS_frontend                           27
-#define SYS_mprotect                           28
-#define SYS_munmap                                     29
+#include <arch/arch.h>
+#include <ros/bits/syscall.h>
+#include <ros/arch/syscall.h>
 
-#define SYS_read                               100
-#define SYS_write                              101
-#define SYS_open                               102
-#define SYS_close                              103
-#define SYS_fstat                              104
-#define SYS_stat                               105
-#define SYS_lstat                              106
-#define SYS_fcntl                              107
-#define SYS_access                             108
-#define SYS_umask                              109
-#define SYS_chmod                              110
-#define SYS_lseek                              111
-#define SYS_link                               112
-#define SYS_unlink                             113
-#define SYS_chdir                              114
-#define SYS_getcwd                             115
-#define SYS_gettimeofday                       116
+/* Flags for an individual syscall */
+#define SC_DONE                                        0x0001
 
-/* For Buster Measurement Flags */
-#define BUSTER_SHARED                  0x0001
-#define BUSTER_STRIDED                 0x0002
-#define BUSTER_LOCKED                  0x0004
-#define BUSTER_PRINT_TICKS             0x0008
-#define BUSTER_JUST_LOCKS              0x0010 // unimplemented
+struct syscall {
+       unsigned int                            num;
+       long                                            retval;
+       int                                                     err;                    /* errno */
+       int                                                     flags;
+       long                                            arg0;
+       long                                            arg1;
+       long                                            arg2;
+       long                                            arg3;
+       long                                            arg4;
+       long                                            arg5;
+};
+
+#ifndef ROS_KERNEL
+
+/* TODO: make variants of __ros_syscall() based on the number of args (0 - 6) */
+/* These are simple synchronous system calls, built on top of the kernel's async
+ * interface.  This version makes no assumptions about errno.  You usually don't
+ * want this. */
+static inline long __ros_syscall(unsigned int _num, long _a0, long _a1, long _a2,
+                                 long _a3, long _a4, long _a5, int *errno_loc)
+{
+       int num_started;
+       struct syscall sysc = {0};
+       sysc.num = _num;
+       sysc.arg0 = _a0;
+       sysc.arg1 = _a1;
+       sysc.arg2 = _a2;
+       sysc.arg3 = _a3;
+       sysc.arg4 = _a4;
+       sysc.arg5 = _a5;
+       num_started = __ros_arch_syscall(&sysc, 1);
+       while (!(sysc.flags & SC_DONE))
+               cpu_relax();
+       if (errno_loc)
+               *errno_loc = sysc.err;
+       return sysc.retval;
+}
+
+#include <errno.h>
+
+/* This version knows about errno and will handle it. */
+static inline long __ros_syscall_errno(unsigned int _num, long _a0, long _a1,
+                                       long _a2, long _a3, long _a4, long _a5)
+{
+       return __ros_syscall(_num, _a0, _a1, _a2, _a3, _a4, _a5, &errno);
+}
+
+/* Convenience wrapper for __ros_syscall */
+#define ros_syscall(which, a0, a1, a2, a3, a4, a5) \
+   __ros_syscall_errno(which, (long)(a0), (long)(a1), (long)(a2), (long)(a3), \
+                       (long)(a4), (long)(a5))
+
+#endif /* ifndef ROS_KERNEL */
 
 #endif /* !ROS_INCLUDE_SYSCALL_H */