Laurent Vivier | 382ae67 | 2020-03-16 09:56:17 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Update syscall_nr.h files from linux headers asm-generic/unistd.h |
| 4 | # |
| 5 | # This code is licensed under the GPL version 2 or later. See |
| 6 | # the COPYING file in the top-level directory. |
| 7 | # |
| 8 | |
| 9 | linux="$1" |
| 10 | output="$2" |
| 11 | |
| 12 | TMP=$(mktemp -d) |
| 13 | |
| 14 | if [ "$linux" = "" ] ; then |
| 15 | echo "Needs path to linux source tree" 1>&2 |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | if [ "$output" = "" ] ; then |
| 20 | output="$PWD" |
| 21 | fi |
| 22 | |
| 23 | upper() |
| 24 | { |
| 25 | echo "$1" | tr "[:lower:]" "[:upper:]" | tr "[:punct:]" "_" |
| 26 | } |
| 27 | |
| 28 | qemu_arch() |
| 29 | { |
| 30 | case "$1" in |
| 31 | arm64) |
| 32 | echo "aarch64" |
| 33 | ;; |
| 34 | *) |
| 35 | echo "$1" |
| 36 | ;; |
| 37 | esac |
| 38 | } |
| 39 | |
| 40 | read_includes() |
| 41 | { |
| 42 | arch=$1 |
| 43 | bits=$2 |
| 44 | |
| 45 | cpp -P -nostdinc -fdirectives-only \ |
| 46 | -D_UAPI_ASM_$(upper ${arch})_BITSPERLONG_H \ |
Song Gao | 1f630196 | 2022-06-24 11:10:40 +0800 | [diff] [blame] | 47 | -D__ASM_$(upper ${arch})_BITSPERLONG_H \ |
Laurent Vivier | 382ae67 | 2020-03-16 09:56:17 +0100 | [diff] [blame] | 48 | -D__BITS_PER_LONG=${bits} \ |
| 49 | -I${linux}/arch/${arch}/include/uapi/ \ |
| 50 | -I${linux}/include/uapi \ |
| 51 | -I${TMP} \ |
| 52 | "${linux}/arch/${arch}/include/uapi/asm/unistd.h" |
| 53 | } |
| 54 | |
| 55 | filter_defines() |
| 56 | { |
| 57 | grep -e "#define __NR_" -e "#define __NR3264" |
| 58 | } |
| 59 | |
| 60 | rename_defines() |
| 61 | { |
| 62 | sed "s/ __NR_/ TARGET_NR_/g;s/(__NR_/(TARGET_NR_/g" |
| 63 | } |
| 64 | |
| 65 | evaluate_values() |
| 66 | { |
| 67 | sed "s/#define TARGET_NR_/QEMU TARGET_NR_/" | \ |
| 68 | cpp -P -nostdinc | \ |
| 69 | sed "s/^QEMU /#define /" |
| 70 | } |
| 71 | |
| 72 | generate_syscall_nr() |
| 73 | { |
| 74 | arch=$1 |
| 75 | bits=$2 |
| 76 | file="$3" |
| 77 | guard="$(upper LINUX_USER_$(qemu_arch $arch)_$(basename "$file"))" |
| 78 | |
| 79 | (echo "/*" |
| 80 | echo " * This file contains the system call numbers." |
| 81 | echo " * Do not modify." |
| 82 | echo " * This file is generated by scripts/gensyscalls.sh" |
| 83 | echo " */" |
| 84 | echo "#ifndef ${guard}" |
| 85 | echo "#define ${guard}" |
| 86 | echo |
| 87 | read_includes $arch $bits | filter_defines | rename_defines | \ |
| 88 | evaluate_values | sort -n -k 3 |
| 89 | echo |
Laurent Vivier | 29fe502 | 2020-09-30 02:30:30 +0200 | [diff] [blame] | 90 | echo "#endif /* ${guard} */") > "$file" |
Laurent Vivier | 382ae67 | 2020-03-16 09:56:17 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | mkdir "$TMP/asm" |
| 94 | > "$TMP/asm/bitsperlong.h" |
| 95 | |
| 96 | generate_syscall_nr arm64 64 "$output/linux-user/aarch64/syscall_nr.h" |
| 97 | generate_syscall_nr nios2 32 "$output/linux-user/nios2/syscall_nr.h" |
| 98 | generate_syscall_nr openrisc 32 "$output/linux-user/openrisc/syscall_nr.h" |
| 99 | |
| 100 | generate_syscall_nr riscv 32 "$output/linux-user/riscv/syscall32_nr.h" |
| 101 | generate_syscall_nr riscv 64 "$output/linux-user/riscv/syscall64_nr.h" |
Taylor Simpson | d2a56bd | 2021-02-07 23:46:20 -0600 | [diff] [blame] | 102 | generate_syscall_nr hexagon 32 "$output/linux-user/hexagon/syscall_nr.h" |
Song Gao | 1f630196 | 2022-06-24 11:10:40 +0800 | [diff] [blame] | 103 | generate_syscall_nr loongarch 64 "$output/linux-user/loongarch64/syscall_nr.h" |
Laurent Vivier | 382ae67 | 2020-03-16 09:56:17 +0100 | [diff] [blame] | 104 | rm -fr "$TMP" |