[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v3 13/16] scripts: add a script to generate syscall_nr.h
From: |
Laurent Vivier |
Subject: |
[PULL v3 13/16] scripts: add a script to generate syscall_nr.h |
Date: |
Thu, 19 Mar 2020 10:26:24 +0100 |
This script is needed for targets based on asm-generic syscall numbers
generation
Signed-off-by: Laurent Vivier <address@hidden>
Reviewed-by: Alistair Francis <address@hidden>
Reviewed-by: Taylor Simpson <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Message-Id: <address@hidden>
[lv: added file in MAINTAINERS]
---
MAINTAINERS | 1 +
scripts/gensyscalls.sh | 102 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+)
create mode 100755 scripts/gensyscalls.sh
diff --git a/MAINTAINERS b/MAINTAINERS
index 36d0c6887a99..fa4abbc863c2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2448,6 +2448,7 @@ S: Maintained
F: linux-user/
F: default-configs/*-linux-user.mak
F: scripts/qemu-binfmt-conf.sh
+F: scripts/gensyscalls.sh
Tiny Code Generator (TCG)
-------------------------
diff --git a/scripts/gensyscalls.sh b/scripts/gensyscalls.sh
new file mode 100755
index 000000000000..b7b8456f6312
--- /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"
--
2.25.1
- [PULL v3 07/16] linux-user: do prlimit selectively, (continued)
- [PULL v3 07/16] linux-user: do prlimit selectively, Laurent Vivier, 2020/03/19
- [PULL v3 03/16] linux-user/i386: Emulate x86_64 vsyscalls, Laurent Vivier, 2020/03/19
- [PULL v3 09/16] linux-user: Update TASK_UNMAPPED_BASE for aarch64, Laurent Vivier, 2020/03/19
- [PULL v3 06/16] linux-user: Add AT_EXECFN auxval, Laurent Vivier, 2020/03/19
- [PULL v3 05/16] linux-user: Flush out implementation of gettimeofday, Laurent Vivier, 2020/03/19
- [PULL v3 01/16] target/i386: Renumber EXCP_SYSCALL, Laurent Vivier, 2020/03/19
- [PULL v3 08/16] linux-user: fix socket() strace, Laurent Vivier, 2020/03/19
- [PULL v3 11/16] linux-user/syscall: Add support for clock_gettime64/clock_settime64, Laurent Vivier, 2020/03/19
- [PULL v3 02/16] linux-user/i386: Split out gen_signal, Laurent Vivier, 2020/03/19
- [PULL v3 16/16] linux-user, openrisc: sync syscall numbers with kernel v5.5, Laurent Vivier, 2020/03/19
- [PULL v3 13/16] scripts: add a script to generate syscall_nr.h,
Laurent Vivier <=
- [PULL v3 12/16] linux-user/riscv: Update the syscall_nr's to the 5.5 kernel, Laurent Vivier, 2020/03/19
- [PULL v3 10/16] linux-user: Protect more syscalls, Laurent Vivier, 2020/03/19
- [PULL v3 14/16] linux-user, aarch64: sync syscall numbers with kernel v5.5, Laurent Vivier, 2020/03/19
- [PULL v3 15/16] linux-user, nios2: sync syscall numbers with kernel v5.5, Laurent Vivier, 2020/03/19
- Re: [PULL v3 00/16] Linux user for 5.0 patches, Peter Maydell, 2020/03/19