aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gensyscalls.sh102
-rwxr-xr-xscripts/update-mips-syscall-args.sh57
-rwxr-xr-xscripts/update-syscalltbl.sh49
3 files changed, 208 insertions, 0 deletions
diff --git a/scripts/gensyscalls.sh b/scripts/gensyscalls.sh
new file mode 100755
index 0000000000..b7b8456f63
--- /dev/null
+++ b/scripts/gensyscalls.sh
@@ -0,0 +1,102 @@
+#!/bin/sh
+#
+# Update syscall_nr.h files from linux headers asm-generic/unistd.h
+#
+# This code is licensed under the GPL version 2 or later. See
+# the COPYING file in the top-level directory.
+#
+
+linux="$1"
+output="$2"
+
+TMP=$(mktemp -d)
+
+if [ "$linux" = "" ] ; then
+ echo "Needs path to linux source tree" 1>&2
+ exit 1
+fi
+
+if [ "$output" = "" ] ; then
+ output="$PWD"
+fi
+
+upper()
+{
+ echo "$1" | tr "[:lower:]" "[:upper:]" | tr "[:punct:]" "_"
+}
+
+qemu_arch()
+{
+ case "$1" in
+ arm64)
+ echo "aarch64"
+ ;;
+ *)
+ echo "$1"
+ ;;
+ esac
+}
+
+read_includes()
+{
+ arch=$1
+ bits=$2
+
+ cpp -P -nostdinc -fdirectives-only \
+ -D_UAPI_ASM_$(upper ${arch})_BITSPERLONG_H \
+ -D__BITS_PER_LONG=${bits} \
+ -I${linux}/arch/${arch}/include/uapi/ \
+ -I${linux}/include/uapi \
+ -I${TMP} \
+ "${linux}/arch/${arch}/include/uapi/asm/unistd.h"
+}
+
+filter_defines()
+{
+ grep -e "#define __NR_" -e "#define __NR3264"
+}
+
+rename_defines()
+{
+ sed "s/ __NR_/ TARGET_NR_/g;s/(__NR_/(TARGET_NR_/g"
+}
+
+evaluate_values()
+{
+ sed "s/#define TARGET_NR_/QEMU TARGET_NR_/" | \
+ cpp -P -nostdinc | \
+ sed "s/^QEMU /#define /"
+}
+
+generate_syscall_nr()
+{
+ arch=$1
+ bits=$2
+ file="$3"
+ guard="$(upper LINUX_USER_$(qemu_arch $arch)_$(basename "$file"))"
+
+ (echo "/*"
+ echo " * This file contains the system call numbers."
+ echo " * Do not modify."
+ echo " * This file is generated by scripts/gensyscalls.sh"
+ echo " */"
+ echo "#ifndef ${guard}"
+ echo "#define ${guard}"
+ echo
+ read_includes $arch $bits | filter_defines | rename_defines | \
+ evaluate_values | sort -n -k 3
+ echo
+ echo "#endif /* ${guard} */"
+ echo) > "$file"
+}
+
+mkdir "$TMP/asm"
+> "$TMP/asm/bitsperlong.h"
+
+generate_syscall_nr arm64 64 "$output/linux-user/aarch64/syscall_nr.h"
+generate_syscall_nr nios2 32 "$output/linux-user/nios2/syscall_nr.h"
+generate_syscall_nr openrisc 32 "$output/linux-user/openrisc/syscall_nr.h"
+
+generate_syscall_nr riscv 32 "$output/linux-user/riscv/syscall32_nr.h"
+generate_syscall_nr riscv 64 "$output/linux-user/riscv/syscall64_nr.h"
+rm -fr "$TMP"
diff --git a/scripts/update-mips-syscall-args.sh b/scripts/update-mips-syscall-args.sh
new file mode 100755
index 0000000000..4f0dda4b83
--- /dev/null
+++ b/scripts/update-mips-syscall-args.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+URL=https://raw.githubusercontent.com/strace/strace/master
+FILES="sysent.h sysent_shorthand_defs.h linux/mips/syscallent-compat.h \
+ linux/mips/syscallent-o32.h linux/syscallent-common-32.h \
+ linux/syscallent-common.h"
+
+output="$1"
+if [ "$output" = "" ] ; then
+ output="$PWD"
+fi
+
+INC=linux-user/mips/syscall-args-o32.c.inc
+
+TMP=$(mktemp -d)
+cd $TMP
+
+for file in $FILES; do
+ curl -O $URL/$file
+done
+
+> subcall32.h
+
+cat > gen_mips_o32.c <<EOF
+#include <stdio.h>
+
+#define LINUX_MIPSO32
+#define MAX_ARGS 7
+
+#include "sysent.h"
+#include "sysent_shorthand_defs.h"
+
+#define SEN(syscall_name) 0,0
+const struct_sysent sysent0[] = {
+#include "syscallent-o32.h"
+};
+
+int main(void)
+{
+ int i;
+
+ for (i = 4000; i < sizeof(sysent0) / sizeof(struct_sysent); i++) {
+ if (sysent0[i].sys_name == NULL) {
+ printf(" [% 4d] = MIPS_SYSCALL_NUMBER_UNUSED,\n", i - 4000);
+ } else {
+ printf(" [% 4d] = %d, /* %s */\n", i - 4000,
+ sysent0[i].nargs, sysent0[i].sys_name);
+ }
+ }
+
+ return 0;
+}
+EOF
+
+cc -o gen_mips_o32 gen_mips_o32.c && ./gen_mips_o32 > "$output/$INC"
+
+rm -fr "$TMP"
diff --git a/scripts/update-syscalltbl.sh b/scripts/update-syscalltbl.sh
new file mode 100755
index 0000000000..2d23e56800
--- /dev/null
+++ b/scripts/update-syscalltbl.sh
@@ -0,0 +1,49 @@
+TBL_LIST="\
+arch/alpha/kernel/syscalls/syscall.tbl,linux-user/alpha/syscall.tbl \
+arch/arm/tools/syscall.tbl,linux-user/arm/syscall.tbl \
+arch/m68k/kernel/syscalls/syscall.tbl,linux-user/m68k/syscall.tbl \
+arch/microblaze/kernel/syscalls/syscall.tbl,linux-user/microblaze/syscall.tbl \
+arch/mips/kernel/syscalls/syscall_n32.tbl,linux-user/mips64/syscall_n32.tbl \
+arch/mips/kernel/syscalls/syscall_n64.tbl,linux-user/mips64/syscall_n64.tbl \
+arch/mips/kernel/syscalls/syscall_o32.tbl,linux-user/mips/syscall_o32.tbl \
+arch/parisc/kernel/syscalls/syscall.tbl,linux-user/hppa/syscall.tbl \
+arch/powerpc/kernel/syscalls/syscall.tbl,linux-user/ppc/syscall.tbl \
+arch/s390/kernel/syscalls/syscall.tbl,linux-user/s390x/syscall.tbl \
+arch/sh/kernel/syscalls/syscall.tbl,linux-user/sh4/syscall.tbl \
+arch/sparc/kernel/syscalls/syscall.tbl,linux-user/sparc64/syscall.tbl \
+arch/sparc/kernel/syscalls/syscall.tbl,linux-user/sparc/syscall.tbl \
+arch/x86/entry/syscalls/syscall_32.tbl,linux-user/i386/syscall_32.tbl \
+arch/x86/entry/syscalls/syscall_64.tbl,linux-user/x86_64/syscall_64.tbl \
+arch/xtensa/kernel/syscalls/syscall.tbl,linux-user/xtensa/syscall.tbl\
+"
+
+linux="$1"
+output="$2"
+
+if [ -z "$linux" ] || ! [ -d "$linux" ]; then
+ cat << EOF
+usage: update-syscalltbl.sh LINUX_PATH [OUTPUT_PATH]
+
+LINUX_PATH Linux kernel directory to obtain the syscall.tbl from
+OUTPUT_PATH output directory, usually the qemu source tree (default: $PWD)
+EOF
+ exit 1
+fi
+
+if [ -z "$output" ]; then
+ output="$PWD"
+fi
+
+for entry in $TBL_LIST; do
+ OFS="$IFS"
+ IFS=,
+ set $entry
+ src=$1
+ dst=$2
+ IFS="$OFS"
+ if ! cp "$linux/$src" "$output/$dst" ; then
+ echo "Cannot copy $linux/$src to $output/$dst" 1>&2
+ exit 1
+ fi
+done
+