parlib: Add a syscall lookup table (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 27 Jan 2017 06:39:13 +0000 (01:39 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 9 Feb 2017 17:31:08 +0000 (12:31 -0500)
This is a simple lookup table of strings, indexed by syscall number.
For instance:
[ 102 ] = "openat",

The table will rebuild whenever the kernel headers change, based on the
*repo's* header, not the one in your toolchain.  libparlib.a also
depends on this file, so basically everything will rebuild when we muck
with the syscall numbers.

Reinstall your kernel headers.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
.gitignore
kern/include/ros/bits/syscall.h
scripts/make_syscall_tbl.sh [new file with mode: 0755]
user/parlib/Makefile
user/parlib/include/parlib/parlib.h

index 5cc90e4..8d6d5a7 100644 (file)
@@ -22,6 +22,7 @@ kern/src/arch
 kern/src/build_info.*
 kern/src/error.c
 user/parlib/include/parlib/arch
 kern/src/build_info.*
 kern/src/error.c
 user/parlib/include/parlib/arch
+user/parlib/syscall_tbl.c
 Documentation/doxygen/rosdoc
 sim/
 sim
 Documentation/doxygen/rosdoc
 sim/
 sim
index a64bb35..6784879 100644 (file)
 #define SYS_mmap                                       18
 #define SYS_munmap                                     19
 #define SYS_mprotect                           20
 #define SYS_mmap                                       18
 #define SYS_munmap                                     19
 #define SYS_mprotect                           20
-/* // these are the other mmap related calls, some of which we'll implement
-#define SYS_mincore // can read page tables instead
-#define SYS_madvise
-#define SYS_mlock
-#define SYS_msync
-*/
 /* was SYS_brk                                         21 */
 #define SYS_shared_page_alloc          22
 #define SYS_shared_page_free           23
 /* was SYS_brk                                         21 */
 #define SYS_shared_page_alloc          22
 #define SYS_shared_page_free           23
diff --git a/scripts/make_syscall_tbl.sh b/scripts/make_syscall_tbl.sh
new file mode 100755 (executable)
index 0000000..e4232c4
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Barret Rhoden <brho@cs.berkeley.edu>
+# Builds a syscall table, an array of strings of syscall names.
+# Used by parlib.
+
+if [ $# -ne 2 ]
+then
+       echo "Need syscall.h and output file args!"
+       exit -1
+fi
+
+SYSLIST=$1
+SYSCALL_TBL=$2
+
+echo "// This was automatically generated with make_syscall_tbl.sh, do not edit" > $SYSCALL_TBL
+echo ""                                    >> $SYSCALL_TBL
+echo "const char *const __syscall_tbl[] =" >> $SYSCALL_TBL
+echo "{"                                   >> $SYSCALL_TBL
+
+# Read lines formatted as:
+#
+#  #define     SYS_foo         1
+#  #define     SYS_bar         3
+#
+# And output them as:
+#
+#  [ 1 ] = "foo",
+#  [ 3 ] = "bar",
+#
+# Here's the guts of it.  Get the #define SYS_'s, compress the whitespace, cut
+# to drop the #define, drop the SYS_, then awk it.
+
+cat $SYSLIST | grep "^#define SYS_" \
+             | sed 's/\s\+/\t/g' \
+             | cut -f 2- \
+             | sed 's/SYS_//' \
+             | awk '{printf "\t[ %s ] = \"%s\",\n", $2, $1}' \
+             >> $SYSCALL_TBL
+
+echo "};"                                 >> $SYSCALL_TBL
+echo ""                                   >> $SYSCALL_TBL
+echo "const int __syscall_tbl_sz = sizeof (__syscall_tbl) / sizeof (__syscall_tbl[0]);" >> $SYSCALL_TBL
index 34d9c2c..eb38f88 100644 (file)
@@ -1,2 +1,8 @@
+syscall_tbl.c: ../../kern/include/ros/bits/syscall.h | silent
+       @../../scripts/make_syscall_tbl.sh $< $@
+
+silent:
+       @:
+
 LIBNAME = parlib
 include ../Makefrag-user-lib
 LIBNAME = parlib
 include ../Makefrag-user-lib
index 8f32973..4009fb4 100644 (file)
@@ -26,6 +26,9 @@ enum {
        PG_RDWR   = 6,
 };
 
        PG_RDWR   = 6,
 };
 
+extern const char *const __syscall_tbl[];
+extern int __syscall_tbl_sz;
+
 int         sys_null(void);
 size_t      sys_getpcoreid(void);
 int         sys_proc_destroy(int pid, int exitcode);
 int         sys_null(void);
 size_t      sys_getpcoreid(void);
 int         sys_proc_destroy(int pid, int exitcode);