From patchwork Thu Mar 19 09:26:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 11446937 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69E27913 for ; Thu, 19 Mar 2020 09:32:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A60220663 for ; Thu, 19 Mar 2020 09:32:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A60220663 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErXZ-00005N-Ct for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 Mar 2020 05:32:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40950) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErRy-0005Qy-Ch for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jErRw-0004Eo-Nm for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:50 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:45001) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jErRw-0004Do-Em for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:48 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1McZfZ-1jrDXZ1i3h-00cvwS; Thu, 19 Mar 2020 10:26:40 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v3 13/16] scripts: add a script to generate syscall_nr.h Date: Thu, 19 Mar 2020 10:26:24 +0100 Message-Id: <20200319092627.51487-14-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200319092627.51487-1-laurent@vivier.eu> References: <20200319092627.51487-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Rp7DTZxyicnOGYcM/nv6nXaG3JxPR13mUSyaTMRB0KqTStKZjst rAdaw50n4C4gnX632iKNa8VqNMasvE+1BNtmrXhVOWLnDfWMPVx5ivHFi6ugngF0+Z1RxQC beaYNEep0IHLeeqGGwpckgpATttv7YfXAMa7O5SkBf/rBvwnSULU6Lco44KYw0G7JdfHqYr AR09bd880ekqaH2OpBp4w== X-UI-Out-Filterresults: notjunk:1;V03:K0:zDboJhKwmc4=:EMsJ2EWn2hHr0tAkcg7pTk WYTBa5FbfXMol5wzoPgUqaCbzCyey9dNe+6m1OOcaJdXp7uXeeoijRyRxN4HWZFYJ6TBfW8ca PX81dd+xnaqHdEL4JAVh4eSAevhXHn/CLExHT4pbm95apUc6QAZVsySb4KeCn/9AwiQA/4yD2 V9GX25nw0JdeDZ3GLNCTBSVZ+LGHiY0M5rIe/PFIwqpjJROKfxhvtTqawNjpefgmTWHvyll/x VuOMNvnI7rkGqyFb0UdF9oSePI1BDM3/chzUGpvItGeCB2pYE7/ymsYn3JrVvFNN98lUvHZTb Tgopw4UcmaGtFMgR2Uz5o8zR0+0nH5EAY+il1QjuZ9ZkE72FsNpsn9+9CU3BoqBA8KhVN0hjJ ide+yR4Uzc+Vt6t8Y3jIjlLuKLwIuK5X4hOy/SUP+2YBQb+Bgjmfi+gv8zoh9TrHxcgMaUt+L HfrPVk/zpW7jKBJdnfHv3q4MN9bRKJ+P7bSTOiJD8XNjuNZ6ST8ms04ZL/6/X3268Gy/ORWsb wx5oplgh4h7fwAa0w9XS5N7+Mu5KcwkPjg3suEfAE/1ILnL3cpu7uoiHBeqK9MraLNOG0bEDU aoxUcVNvnZcIkrJ2rs8j7gyQyxS6J+iXfHzsxwcoqwtrqAXsRC5yple+AEFOIY0nMkR79Pdax IyHDWhTMkCr2Fau3ngjITfRLqFNedhM/j6er8ftwtmxnXMTje+My6HOo9DFfQNBKFqDNkDREH 69Xx6eUZnISJA1EPuh3jMl4VAuyyZ6wTYzkRVlYIJqiBPzVJ0BDJrrqsKYMEbStWAi+ndnMMp p7c+CiPg3sNw6t4qiso9/97Vol5NwpTbJuAC4ycA3JMiIoI1pfVLOfo6891FPR5GWcS+77N X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.130 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , Taylor Simpson , Riku Voipio , Alistair Francis , Laurent Vivier Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This script is needed for targets based on asm-generic syscall numbers generation Signed-off-by: Laurent Vivier Reviewed-by: Alistair Francis Reviewed-by: Taylor Simpson Reviewed-by: Richard Henderson Message-Id: <20200316085620.309769-2-laurent@vivier.eu> [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"