9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 1) #!/bin/sh
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 2) # SPDX-License-Identifier: GPL-2.0-only
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 3) #
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 4) # Generate a syscall table header.
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 5) #
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 6) # Each line of the syscall table should have the following format:
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 7) #
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 8) # NR ABI NAME [NATIVE] [COMPAT]
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 9) #
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 10) # NR syscall number
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 11) # ABI ABI name
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 12) # NAME syscall name
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 13) # NATIVE native entry point (optional)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 14) # COMPAT compat entry point (optional)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 15)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 16) set -e
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 17)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 18) usage() {
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 19) echo >&2 "usage: $0 [--abis ABIS] INFILE OUTFILE" >&2
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 20) echo >&2
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 21) echo >&2 " INFILE input syscall table"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 22) echo >&2 " OUTFILE output header file"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 23) echo >&2
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 24) echo >&2 "options:"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 25) echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 26) exit 1
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 27) }
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 28)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 29) # default unless specified by options
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 30) abis=
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 31)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 32) while [ $# -gt 0 ]
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 33) do
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 34) case $1 in
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 35) --abis)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 36) abis=$(echo "($2)" | tr ',' '|')
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 37) shift 2;;
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 38) -*)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 39) echo "$1: unknown option" >&2
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 40) usage;;
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 41) *)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 42) break;;
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 43) esac
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 44) done
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 45)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 46) if [ $# -ne 2 ]; then
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 47) usage
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 48) fi
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 49)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 50) infile="$1"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 51) outfile="$2"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 52)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 53) nxt=0
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 54)
c6a3a81d19b83 (Masahiro Yamada 2021-07-05 15:06:54 +0900 55) grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | {
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 56)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 57) while read nr abi name native compat ; do
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 58)
c6a3a81d19b83 (Masahiro Yamada 2021-07-05 15:06:54 +0900 59) if [ $nxt -gt $nr ]; then
c6a3a81d19b83 (Masahiro Yamada 2021-07-05 15:06:54 +0900 60) echo "error: $infile: syscall table is not sorted or duplicates the same syscall number" >&2
c6a3a81d19b83 (Masahiro Yamada 2021-07-05 15:06:54 +0900 61) exit 1
c6a3a81d19b83 (Masahiro Yamada 2021-07-05 15:06:54 +0900 62) fi
c6a3a81d19b83 (Masahiro Yamada 2021-07-05 15:06:54 +0900 63)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 64) while [ $nxt -lt $nr ]; do
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 65) echo "__SYSCALL($nxt, sys_ni_syscall)"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 66) nxt=$((nxt + 1))
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 67) done
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 68)
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 69) if [ -n "$compat" ]; then
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 70) echo "__SYSCALL_WITH_COMPAT($nr, $native, $compat)"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 71) elif [ -n "$native" ]; then
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 72) echo "__SYSCALL($nr, $native)"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 73) else
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 74) echo "__SYSCALL($nr, sys_ni_syscall)"
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 75) fi
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 76) nxt=$((nr + 1))
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 77) done
9df526b03c01a (Masahiro Yamada 2021-02-16 11:04:11 +0900 78) } > "$outfile"