diff mbox series

[1/4] scripts: add a script to generate syscall_nr.h

Message ID 20200310110759.3331020-2-laurent@vivier.eu (mailing list archive)
State New, archived
Headers show
Series linux-user: generate syscall_nr.h from linux unistd.h | expand

Commit Message

Laurent Vivier March 10, 2020, 11:07 a.m. UTC
This script is needed for targets based on asm-generic syscall numbers generation

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 scripts/gensyscalls.sh | 94 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100755 scripts/gensyscalls.sh

Comments

Alistair Francis March 10, 2020, 5:25 p.m. UTC | #1
On Tue, Mar 10, 2020 at 4:08 AM Laurent Vivier <laurent@vivier.eu> wrote:
>
> This script is needed for targets based on asm-generic syscall numbers generation
>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  scripts/gensyscalls.sh | 94 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 94 insertions(+)
>  create mode 100755 scripts/gensyscalls.sh
>
> diff --git a/scripts/gensyscalls.sh b/scripts/gensyscalls.sh
> new file mode 100755
> index 000000000000..3b549a665d0f
> --- /dev/null
> +++ b/scripts/gensyscalls.sh
> @@ -0,0 +1,94 @@
> +#!/bin/sh
> +
> +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"
> +        ;;
> +    *)
> +        upper "$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 " */"
> +    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.24.1
>
>
Taylor Simpson March 11, 2020, 1:09 p.m. UTC | #2
Reviewed-by: Taylor Simpson <tsimpson@quicinc.com>

> -----Original Message-----
> From: Qemu-devel <qemu-devel-
> bounces+tsimpson=quicinc.com@nongnu.org> On Behalf Of Laurent Vivier
> Sent: Tuesday, March 10, 2020 6:08 AM
> To: qemu-devel@nongnu.org
> Cc: Marek Vasut <marex@denx.de>; Peter Maydell
> <peter.maydell@linaro.org>; Jia Liu <proljc@gmail.com>; Riku Voipio
> <riku.voipio@iki.fi>; Laurent Vivier <laurent@vivier.eu>; Alistair Francis
> <alistair.francis@wdc.com>
> Subject: [PATCH 1/4] scripts: add a script to generate syscall_nr.h
>
> This script is needed for targets based on asm-generic syscall numbers
> generation
>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
>  scripts/gensyscalls.sh | 94
> ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 94 insertions(+)
>  create mode 100755 scripts/gensyscalls.sh
>
> diff --git a/scripts/gensyscalls.sh b/scripts/gensyscalls.sh
> new file mode 100755
> index 000000000000..3b549a665d0f
> --- /dev/null
> +++ b/scripts/gensyscalls.sh
> @@ -0,0 +1,94 @@
> +#!/bin/sh
> +

Include the license

> +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"
> +        ;;
> +    *)
> +        upper "$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: <qemu>/scripts/gensyscalls.sh ${linux} ${output}"

> +    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.24.1
>
>
diff mbox series

Patch

diff --git a/scripts/gensyscalls.sh b/scripts/gensyscalls.sh
new file mode 100755
index 000000000000..3b549a665d0f
--- /dev/null
+++ b/scripts/gensyscalls.sh
@@ -0,0 +1,94 @@ 
+#!/bin/sh
+
+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"
+        ;;
+    *)
+        upper "$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 " */"
+    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"